Commit 446f5da0 authored by Malcolm Blaney's avatar Malcolm Blaney

Added new_page parameter to Copy method in module interface so that

Reader and Post modules can add notify table entries for new modules.
Added new helper function Published to the Base class. Added database
name to file created by Backup function for multiple installs.
parent 2c28b42c
......@@ -109,7 +109,7 @@ class Banking extends Base {
'</form>';
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
// Copy is called when a new user is created (assuming a Banking module
// has been added to admin's default page). A new user needs a unique
// banking reference created for them, which is done here.
......
......@@ -203,7 +203,7 @@ class Browser extends Base {
return $content;
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......
......@@ -371,7 +371,7 @@ class Cart extends Base {
return '<div id="cart-title">Shop'.$edit.'</div>'.$content;
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......
......@@ -142,7 +142,7 @@ class Comment extends Base {
return '<div class="comments-title">Comments'.$edit.'</div>'.$content.$form;
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
$mysqli = connect_db();
$query = 'INSERT INTO comment_settings (user, box_id, locked) SELECT "'.
$this->owner.'", "'.$id.'", locked FROM comment_settings WHERE user="'.
......
......@@ -123,7 +123,7 @@ class Contact extends Base {
return '<div class="editable">'.$this->PlainContent($id).'</div>';
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
$content = $this->PlainContent($old_id, $old_owner);
$this->Insert($id, $content);
$this->CopyStyle($id, $old_owner, $old_id);
......
......@@ -112,7 +112,7 @@ class Detail extends Base {
return $content;
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......
......@@ -105,7 +105,7 @@ class Gift extends Base {
return $content;
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......
......@@ -147,7 +147,7 @@ class Graph extends Base {
return $content;
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......
......@@ -41,7 +41,7 @@ class Grid extends Base {
return "";
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......
......@@ -85,7 +85,7 @@ class Invoice extends Base {
'<div class="user-details"></div>';
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......
......@@ -198,7 +198,7 @@ class Manager extends Base {
'</form>';
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......
......@@ -276,7 +276,7 @@ class Organiser extends Base {
return $content;
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......
......@@ -266,7 +266,7 @@ class Payment extends Base {
return $content;
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......
......@@ -63,7 +63,7 @@ class Player extends Base {
return '<div class="editable">'.$this->PlainContent($id).'</div>';
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
$content = "";
$mysqli = connect_db();
$query = 'SELECT content FROM player WHERE user="'.$old_owner.
......
......@@ -137,7 +137,7 @@ class Post extends Base {
return $this->Substitute("post-format", $patterns, $replacements);
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
$title = "";
$feed = "";
$description = "";
......@@ -167,6 +167,7 @@ class Post extends Base {
$this->Insert($id, $author, $feed, $title, $description, $category,
$enclosure, $permalink, true);
$this->CopyStyle($id, $old_owner, $old_id);
$this->Notify($id, "post", "feed", $new_page, $this->Published($new_page));
}
public function Cron() {
......@@ -352,37 +353,25 @@ class Post extends Base {
if (!$mysqli->query($query)) {
$this->Log("Post->SetContent 3: ".$mysqli->error);
}
$mysqli->close();
// Note that modules need to decide what notifications they want to give.
// Not bothering with add or edit notifications here, instead just
// pushing all changes into the main page feed when the page is published.
$published_page = 0;
$query = 'SELECT published FROM published WHERE user = "'.$this->owner.
'" AND page = "'.$feed.'"';
if ($result = $mysqli->query($query)) {
if ($published = $result->fetch_assoc()) {
$published_page = (int)$published['published'];
}
$result->close();
}
else {
$this->Log("Post->SetContent 4: ".$mysqli->error);
}
$mysqli->close();
$published = $this->Published($feed);
// Only time Notify is not called is when the given value is set to false.
if (!isset($_POST["notify"]) || $_POST["notify"] === true) {
$this->Notify($id, "post", "feed", $feed, $published_page);
$this->Notify($id, "post", "feed", $feed, $published);
}
// If the page is published and the reader module is installed, let it
// know that this feed has been updated.
if ($published_page) {
if ($published == 1) {
$reader = new Module($this->user, $this->owner, "reader", $this->config);
if ($reader->IsInstalled()) {
$page = "rss/index.php?page=".$feed;
$url = "http://".$_SERVER['SERVER_NAME']."/";
$url .= $this->owner == "admin" ? $page : $this->owner."/".$page;
$reader->Factory("UpdateFeed", $url);
$xml_url = "http://".$_SERVER['SERVER_NAME']."/";
$xml_url .= $this->owner == "admin" ? $page : $this->owner."/".$page;
$reader->Factory("UpdateFeed", array($xml_url, $feed));
}
}
}
......
......@@ -365,7 +365,7 @@ class Purchase extends Base {
return $content;
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......
This diff is collapsed.
......@@ -188,7 +188,7 @@ class Roster extends Base {
'<div class="roster-role-dialog hidden"></div>';
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......
......@@ -63,7 +63,7 @@ class Slider extends Base {
return '<div class="editable">'.$this->PlainContent($id).'</div>';
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
$content = "";
$mysqli = connect_db();
$query = 'SELECT content FROM slider WHERE user="'.$old_owner.
......
......@@ -202,7 +202,7 @@ class Stock extends Base {
'</form>';
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......
......@@ -165,7 +165,7 @@ class Summary extends Base {
'</div>';
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
// Copy is called when a new user is created (assuming a Summary module
// has been added to admin's default page). The Summary module depends
// on both the Purchase and Payment modules, and they need to be told
......
......@@ -63,7 +63,7 @@ class Turner extends Base {
return '<div class="editable">'.$this->PlainContent($id).'</div>';
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
$content = "";
$mysqli = connect_db();
$query = 'SELECT content FROM turner WHERE user="'.$old_owner.
......
......@@ -91,7 +91,7 @@ class Writer extends Base {
'Recipients coming soon!</div>';
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......
......@@ -21,52 +21,86 @@ function copy_page($current_page, $current_owner, $new_page, $new_owner,
$config = new Config();
$mysqli = connect_db();
// Set the same user permissions as the permission_page which may not be
// the same as the current page. (ie in the case of creating a new post
// we want permissions from the page containing the writer module, not the
// default posts page.)
if ($permission_page === "") {
$permission_page = $current_page;
}
$query = 'INSERT INTO user_permission (user,page,visitor,edit,copy,view) '.
'SELECT "'.$new_owner.'", "'.$new_page.'", visitor, edit, copy, view '.
'FROM user_permission WHERE user = "'.$current_owner.'" '.
'AND page = "'.$permission_page.'"';
if (!$mysqli->query($query)) {
error_log("copy_page 1: ".$mysqli->error);
}
// Set the same group permissions as the permission page.
$query = 'INSERT INTO group_permission (user,page,name,edit,copy,view) '.
'SELECT "'.$new_owner.'", "'.$new_page.'", name, edit, copy, view '.
'FROM group_permission WHERE user = "'.$current_owner.'" '.
'AND page = "'.$permission_page.'"';
if (!$mysqli->query($query)) {
error_log("copy_page 2: ".$mysqli->error);
}
// Set published the same as the permission page.
$query = 'INSERT INTO published (user, page, published) SELECT '.
'"'.$new_owner.'", "'.$new_page.'", published FROM published WHERE '.
'user = "'.$current_owner.'" AND page = "'.$permission_page.'"';
if (!$mysqli->query($query)) {
error_log("copy_page 3: ".$mysqli->error);
}
// Get the first new unused id for calling each module's Copy method, but the
// modules table itself will auto-increment new id's when modules are added.
$id = 0;
$query = 'SELECT MAX(box_id) AS box_id FROM modules WHERE user="'.
$new_owner.'"';
$query = 'SELECT MAX(box_id) AS box_id FROM modules WHERE '.
'user = "'.$new_owner.'"';
if ($result = $mysqli->query($query)) {
if ($module_list = $result->fetch_assoc()) {
$id = (int)$module_list['box_id'] + 1;
$id = (int)$module_list["box_id"] + 1;
}
$result->close();
}
else {
error_log('copy_page 1: '.$mysqli->error);
error_log("copy_page 4: ".$mysqli->error);
}
// Note that the current owner and page are still used here because the
// old box_id's are required by the Copy method.
$query = 'SELECT box_id, label FROM modules WHERE user="'.$current_owner.
'" AND page="'.$current_page.'" AND deleted="0" ORDER BY box_id';
$query = 'SELECT box_id, label FROM modules WHERE '.
'user = "'.$current_owner.'" AND page = "'.$current_page.'" '.
'AND deleted = 0 ORDER BY box_id';
if ($result = $mysqli->query($query)) {
while ($module_list = $result->fetch_assoc()) {
$label = $module_list['label'];
$label = $module_list["label"];
$module = new Module($user, $new_owner, $label, $config);
$module->Copy($id++, $current_owner, $module_list['box_id']);
$module->Copy($id++, $new_page, $current_owner, $module_list["box_id"]);
}
$result->close();
}
else {
error_log('copy_page 2: '.$mysqli->error);
error_log("copy_page 5: ".$mysqli->error);
}
$query = 'INSERT INTO modules (user, page, label, class, box_order, '.
'placement, deleted) SELECT "'.$new_owner.'", "'.$new_page.
'", label, class, box_order, placement, deleted FROM modules '.
'WHERE user="'.$current_owner.'" AND page="'.$current_page.
'" AND deleted="0" ORDER BY box_id';
'placement, deleted) SELECT "'.$new_owner.'", "'.$new_page.'", '.
'label, class, box_order, placement, deleted FROM modules '.
'WHERE user = "'.$current_owner.'" AND page = "'.$current_page.'" '.
'AND deleted = 0 ORDER BY box_id';
if (!$mysqli->query($query)) {
error_log('copy_page 3: '.$mysqli->error);
error_log("copy_page 6: ".$mysqli->error);
}
// Also copy to modules_history.
$query = 'INSERT INTO modules_history (user, page, label, class, box_order, '.
'placement, action, modified_by, timestamp) SELECT "'.$new_owner.'", "'.
$new_page.'", label, class, box_order, placement, "add", "'.
$user->name.'", "'.time().'" FROM modules WHERE user="'.$current_owner.
'" AND page="'.$current_page.'" AND deleted="0" ORDER BY box_id';
'placement, action, modified_by, timestamp) SELECT "'.$new_owner.'", '.
'"'.$new_page.'", label, class, box_order, placement, "add", '.
'"'.$user->name.'", '.time().' FROM modules WHERE '.
'user = "'.$current_owner.'" AND page = "'.$current_page.'" '.
'AND deleted = 0 ORDER BY box_id';
if (!$mysqli->query($query)) {
error_log('copy_page 4: '.$mysqli->error);
error_log("copy_page 7: ".$mysqli->error);
}
if ($order != -1) {
......@@ -74,11 +108,12 @@ function copy_page($current_page, $current_owner, $new_page, $new_owner,
// modules on the page with box_order >= $order in the same placement.
$query = 'REPLACE INTO modules (user, page, box_id, label, class, '.
'box_order, placement, deleted) SELECT user, page, box_id, label, '.
'class, box_order + 1, placement, deleted FROM modules WHERE user = "'.
$new_owner.'" AND page = "'.$new_page.'" AND box_order >= '.$order.
' AND placement = "'.$placement.'" AND deleted = "0"';
'class, box_order + 1, placement, deleted FROM modules WHERE '.
'user = "'.$new_owner.'" AND page = "'.$new_page.'" AND '.
'box_order >= '.$order.' AND placement = "'.$placement.'" AND '.
'deleted = 0';
if (!$mysqli->query($query)) {
error_log('copy_page 5: '.$mysqli->error);
error_log("copy_page 8: ".$mysqli->error);
}
}
......@@ -89,10 +124,10 @@ function copy_page($current_page, $current_owner, $new_page, $new_owner,
// Also copy the page style rules for the new page.
$query = 'INSERT INTO page_style (user, name, media, selector, property, '.
'value) SELECT "'.$new_owner.'", "'.$new_page.'", media, selector, '.
'property, value FROM page_style WHERE user="'.$current_owner.
'" AND name="'.$current_page.'"';
'property, value FROM page_style WHERE user = "'.$current_owner.'" '.
'AND name = "'.$current_page.'"';
if (!$mysqli->query($query)) {
error_log('copy_page 6: '.$mysqli->error);
error_log("copy_page 9: ".$mysqli->error);
}
if ($new_owner == "admin") {
......@@ -102,43 +137,11 @@ function copy_page($current_page, $current_owner, $new_page, $new_owner,
write_page_style($new_owner, "../".$new_owner."/".$new_page.".css");
}
// Set the same user permissions as the permission_page which may not be
// the same as the current page. (ie in the case of creating a new post
// we want permissions from the page containing the writer module, not the
// default posts page.)
if ($permission_page === "") {
$permission_page = $current_page;
}
$query = 'INSERT INTO user_permission (user,page,visitor,edit,copy,view) '.
'SELECT "'.$new_owner.'", "'.$new_page.'", visitor, edit, copy, view '.
'FROM user_permission WHERE user="'.$current_owner.'" '.
'AND page="'.$permission_page.'"';
if (!$mysqli->query($query)) {
error_log('copy_page 7: '.$mysqli->error);
}
// Set the same group permissions as the permission page.
$query = 'INSERT INTO group_permission (user,page,name,edit,copy,view) '.
'SELECT "'.$new_owner.'", "'.$new_page.'", name, edit, copy, view '.
'FROM group_permission WHERE user="'.$current_owner.'" '.
'AND page="'.$permission_page.'"';
if (!$mysqli->query($query)) {
error_log('copy_page 8: '.$mysqli->error);
}
// Set published the same as the permission page.
$query = 'INSERT INTO published (user, page, published) SELECT "'.
$new_owner.'", "'.$new_page.'", published FROM published WHERE user="'.
$current_owner.'" AND page="'.$permission_page.'"';
if (!$mysqli->query($query)) {
error_log('copy_page 9: '.$mysqli->error);
}
$mysqli->close();
// Return the page name for redirect.
$url = $config->FancyUrl() ? "/".$new_page : "/index.php?page=".$new_page;
return $new_owner == "admin" ? $url : '/'.$new_owner.$url;
return $new_owner == "admin" ? $url : "/".$new_owner.$url;
}
?>
......@@ -174,7 +174,7 @@ function new_user($user, $owner, $config,
$id = 1;
while ($module_list = $result->fetch_assoc()) {
$module = new Module($user, $user->name, $module_list['label'], $config);
$module->Copy($id++, "admin", $module_list['box_id']);
$module->Copy($id++, "index", "admin", $module_list['box_id']);
// Also borrow the first module found to access Substitute method of
// the base class to get system email settings.
if ($sender == "") {
......
......@@ -61,9 +61,9 @@ class Module {
return $this->instance->Content($id);
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
if ($this->instance == null) return;
return $this->instance->Copy($id, $old_owner, $old_id);
return $this->instance->Copy($id, $new_page, $old_owner, $old_id);
}
public function Cron() {
......
......@@ -350,7 +350,7 @@ class Account extends Base {
return "";
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......
......@@ -39,7 +39,7 @@ abstract class Base {
// Content is called by page.php when the page is initially constructed.
abstract public function Content($id);
abstract public function Copy($id, $old_owner, $old_id);
abstract public function Copy($id, $new_page, $old_owner, $old_id);
// Cron is called by cron.php, use it in conjunction with Run below.
abstract public function Cron();
......@@ -299,14 +299,17 @@ abstract class Base {
$mysqli->close();
}
protected function Notify($id, $label, $action, $feed,
$public = 1, $update_timestamp = false) {
protected function Notify($id, $label, $action, $feed, $public = 1,
$update_timestamp = false, $user = "") {
$mysqli = connect_db();
$update_timestamp_query = "";
if ($update_timestamp) {
$update_timestamp_query = ', timestamp = '.time();
}
$query = 'INSERT INTO notify VALUES ("'.$this->owner.'", "'.$feed.'", '.
if ($user == "") {
$user = $this->owner;
}
$query = 'INSERT INTO notify VALUES ("'.$user.'", "'.$feed.'", '.
$id.', "'.$label.'", "'.$action.'", '.time().', '.$public.') '.
'ON DUPLICATE KEY UPDATE public = '.$public.$update_timestamp_query;
if (!$mysqli->query($query)) {
......@@ -315,6 +318,24 @@ abstract class Base {
$mysqli->close();
}
protected function Published($page) {
$published_page = 0;
$mysqli = connect_db();
$query = 'SELECT published FROM published WHERE user = "'.$this->owner.'"'.
' AND page = "'.$page.'"';
if ($result = $mysqli->query($query)) {
if ($published = $result->fetch_assoc()) {
$published_page = (int)$published["published"];
}
$result->close();
}
else {
$this->Log("Base->Published: ".$mysqli->error);
}
$mysqli->close();
return $published_page;
}
protected function RemoveNotify($id) {
$mysqli = connect_db();
$query = 'DELETE FROM notify WHERE user = "'.$this->owner.'"'.
......
......@@ -162,7 +162,7 @@ class Control extends Base {
return $content;
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......@@ -300,13 +300,13 @@ class Control extends Base {
// First check for todays date.
$date = date("Y-m-d");
$file = $path."backup-".$date.".sql.gz";
$file = $path.$db_name."-backup-".$date.".sql.gz";
if (file_exists($file)) return $file;
// Otherwise check recent dates before creating a new backup.
for ($i = 1; $i < 5; $i++) {
$date = date("Y-m-d", strtotime("-".$i." days"));
$recent = $path."backup-".$date.".sql.gz";
$recent = $path.$db_name."-backup-".$date.".sql.gz";
if (file_exists($recent)) return $recent;
}
......
......@@ -161,26 +161,14 @@ class Extended extends Base {
$this->Log('Extended->Callback 7: '.$mysqli->error);
}
$object["content"] = "";
$query = 'SELECT published FROM published WHERE user="'.$this->owner.
'" AND page="'.$page.'"';
if ($result = $mysqli->query($query)) {
if ($published = $result->fetch_assoc()) {
if ($published["published"] == "1") {
$object["content"] = '<div id="published-page">'.
'This page is published: <button>public</button></div>'.
'<div id="unpublished-page" class="hidden">'.
'This page is <b>not</b> published: <button>private</button>'.
'</div>';
}
}
$result->close();
if ($this->Published($page) == 1) {
$object["content"] = '<div id="published-page">'.
'This page is published: <button>public</button></div>'.
'<div id="unpublished-page" class="hidden">'.
'This page is <b>not</b> published: <button>private</button>'.
'</div>';
}
else {
$this->Log('Extended->Callback 8: '.$mysqli->error);
}
if ($object["content"] === "") {
$object["content"] = '<div id="published-page" class="hidden">'.
'This page is published: <button>public</button></div>'.
'<div id="unpublished-page">This page is <b>not</b> '.
......@@ -252,7 +240,7 @@ class Extended extends Base {
'</div>';
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......
......@@ -149,7 +149,7 @@ class Login extends Base {
'<p class="login-message">'.$message.'</p></div>';
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
$content = "";
$mysqli = connect_db();
$query = 'SELECT content FROM login WHERE user="'.$old_owner.
......
......@@ -90,7 +90,7 @@ class More extends Base {
'</div>';
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......
......@@ -87,7 +87,7 @@ class Notification extends Base {
date('g:i:sa \o\n D F j, Y', $timestamp)));
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......
......@@ -60,7 +60,7 @@ class Simple extends Base {
return '<div class="editable">'.$this->PlainContent($id).'</div>';
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
$content = "";
$mysqli = connect_db();
$query = 'SELECT content FROM simple_module WHERE user="'.$old_owner.
......
......@@ -45,7 +45,7 @@ class Skeleton extends Base {
return "";
}
public function Copy($id, $old_owner, $old_id) {
public function Copy($id, $new_page, $old_owner, $old_id) {
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment