Commit 94ea3f78 authored by Mal's avatar Mal

New copy_page function used to create permalink pages for posts.

parent c0ef1196
<?php
// Dobrado Content Management System
// Copyright (C) 2011 Malcolm Blaney
// Copyright (C) 2012 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -15,12 +15,16 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
include "php/db.php";
include "php/config.php";
include "php/db.php";
include "php/module.php";
include "php/permission.php";
include "php/user.php";
include "php/page.php";
include "php/style.php";
include "php/write_style.php";
include "php/copy_page.php";
include "php/page.php";
session_start();
......
......@@ -89,7 +89,7 @@ class Post extends Base {
$title = $old_title;
$author = $old_author;
$category = $old_category;
$enclosure = $ols_enclosure;
$enclosure = $old_enclosure;
}
$time = time();
$permalink = $old_permalink;
......@@ -295,7 +295,8 @@ class Post extends Base {
$q = mysql_query('INSERT INTO published VALUES ("'.$this->owner.'","'.
$permalink.'","1")');
if (!$q) error_log('Post->Permalink 2: '.mysql_error());
// TODO: This new page will be unstyled? Need to copy a default page here.
copy_page($this->config->default_post(), $this->owner,
$permalink, $this->owner);
}
private function RemovePermalinkPage($id, $permalink = "") {
......
......@@ -38,6 +38,7 @@ class Writer extends Base {
}
public function Content($id) {
if (!can_edit_page()) return;
return '<textarea id="writer-content" rows="2" cols="80">'.
'Write a new post...'.
'</textarea>'.
......
......@@ -11,7 +11,6 @@ if (!this.dobrado.reader) {
dobrado.notify("feed", dobrado.reader.update);
});
// Put private functions here, and put module methods together last.
dobrado.reader.update = function() {
$.post("/php/request.php", { id: $(".reader").attr("id"),
request: "reader",
......
......@@ -63,6 +63,10 @@ class Config {
return "unavailable";
}
public function default_post() {
return "default";
}
}
?>
<?php
// Dobrado Content Management System
// Copyright (C) 2011 Malcolm Blaney
// Copyright (C) 2012 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -24,6 +24,8 @@ include "db.php";
include "module.php";
include "permission.php";
include "user.php";
include "write_style.php";
include "copy_page.php";
if (!can_edit_page()) return;
......
<?php
// Dobrado Content Management System
// Copyright (C) 2011 Malcolm Blaney
// Copyright (C) 2012 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -25,6 +25,7 @@ include "module.php";
include "permission.php";
include "user.php";
include "write_style.php";
include "copy_page.php";
$object = array();
......@@ -35,14 +36,14 @@ if (!can_copy_page()) {
}
$link = connect_db();
$page = mysql_real_escape_string($_POST['page']);
$owner = mysql_real_escape_string($_POST['owner']);
$new_page = mysql_real_escape_string($_POST['page']);
$new_owner = mysql_real_escape_string($_POST['owner']);
// If owner is empty, default to the current page owner.
if (empty($owner)) $owner = $_SESSION['owner'];
if (empty($new_owner)) $new_owner = $_SESSION['owner'];
if (!can_edit_page($owner."/".$page)) {
$object['error'] = 'Could not copy to page: "'.$owner.'/'.$page.'".<br/>'.
'Please make sure you have permission to edit that page.';
if (!can_edit_page($new_owner."/".$new_page)) {
$object['error'] = 'Could not copy to page: "'.$new_owner.'/'.$new_page.
'".<br/>Please make sure you have permission to edit that page.';
echo json_encode($object);
return;
}
......@@ -50,115 +51,8 @@ if (!can_edit_page($owner."/".$page)) {
$current_page = $_SESSION['page'];
$current_owner = $_SESSION['owner'];
$q = mysql_query('SELECT MAX(box_id) AS box_id FROM modules WHERE user="'.
$owner.'"');
if (!$q) error_log('copy 1: '.mysql_error());
$modules = mysql_fetch_assoc($q);
$id = $modules['box_id'] + 1;
$q = mysql_query('SELECT MAX(box_id) AS box_id FROM modules_history '.
'WHERE user="'.$owner.'"');
if (!$q) error_log('copy 2: '.mysql_error());
$modules_history = mysql_fetch_assoc($q);
if ($id <= $modules_history['box_id']) {
$id = $modules_history['box_id'] + 1;
}
$user = new User();
$config = new Config();
$q = mysql_query('SELECT box_id, box_order, placement, label FROM modules '.
'WHERE user="'.$current_owner.'" AND page="'.
$current_page.'"');
if (!$q) error_log('copy 3: '.mysql_error());
while ($modules = mysql_fetch_assoc($q)) {
$label = $modules['label'];
$module = new Module($user, $owner, $label, $config);
if ($module->CanAdd($page)) {
$order = $modules['box_order'];
$placement = $modules['placement'];
$q1 = mysql_query('INSERT INTO modules VALUES ("'.$owner.'","'.$page.
'","'.$id.'","'.$label.'","'.$order.'","'.$placement.
'")');
if (!$q1) error_log('copy 4: '.mysql_error());
$q1 = mysql_query('INSERT INTO modules_history VALUES ("'.$owner.'","'.
$page.'","'.$id.'","'.$label.'","'.$order.'","'.
$placement.'","add","'.$user->name.'","'.time().'")');
if (!$q1) error_log('copy 5: '.mysql_error());
$module->Copy($id, $current_owner, $modules['box_id']);
$id++;
}
}
// Write out a new style sheet after the modules have been copied.
if ($owner == "admin") write_box_style($owner, "../style.css");
else write_box_style($owner, "../".$owner."/style.css");
// Also copy the page style rules for the new page.
$q = mysql_query('SELECT media, selector, property, value FROM page_style '.
'WHERE user="'.$current_owner.'" AND name="'.$current_page.
'"');
if (!$q) error_log('copy 6: '.mysql_error());
$values = "";
while ($page_style = mysql_fetch_assoc($q)) {
if (!empty($values)) $values .= ',';
$values .= '("'.$owner.'","'.$page.'","'.
mysql_real_escape_string($page_style['media']).'","'.
mysql_real_escape_string($page_style['selector']).'","'.
mysql_real_escape_string($page_style['property']).'","'.
mysql_real_escape_string($page_style['value']).'")';
}
if (!empty($values)) {
$q = mysql_query('INSERT INTO page_style VALUES '.$values);
if (!$q) error_log('copy 7: '.mysql_error());
}
if ($owner == "admin") write_page_style($owner, "../".$page.".css");
else write_page_style($owner, "../".$owner."/".$page.".css");
// Set the same user permissions as the original page.
$q = mysql_query('SELECT visitor, edit, copy FROM user_permission WHERE '.
'user="'.$current_owner.'" AND page="'.$current_page.'"');
if (!$q) error_log('copy 6: '.mysql_error());
$values = "";
while ($user_permission = mysql_fetch_assoc($q)) {
if (!empty($values)) $values .= ',';
$values .= '("'.$owner.'","'.$page.'","'.$user_permission['visitor'].
'","'.$user_permission['edit'].'","'.$user_permission['copy'].'")';
}
if (!empty($values)) {
$q = mysql_query('INSERT INTO user_permission VALUES '.$values);
if (!$q) error_log('copy 6: '.mysql_error());
}
// Set the same group permissions as the original page.
$q = mysql_query('SELECT name, edit, copy FROM group_permission WHERE '.
'user="'.$current_owner.'" AND page="'.$current_page.'"');
if (!$q) error_log('copy 7: '.mysql_error());
$values = "";
while ($group_permission = mysql_fetch_assoc($q))
{
if (!empty($values)) $values .= ',';
$values .= '("'.$owner.'","'.$page.'","'.$group_permission['name'].
'","'.$group_permission['edit'].'","'.$group_permission['copy'].'")';
}
if (!empty($values)) {
$q = mysql_query('INSERT INTO group_permission VALUES '.$values);
if (!$q) error_log('copy 8: '.mysql_error());
}
// Set published the same as the original page.
$q = mysql_query('SELECT published FROM published WHERE user="'.
$current_owner.'" AND page="'.$current_page.'"');
if (!$q) error_log('copy 9: '.mysql_error());
if ($published = mysql_fetch_assoc($q)) {
$q = mysql_query('INSERT INTO published VALUES ("'.$owner.'","'.$page.
'","'.$published['published'].'")');
if (!$q) error_log('copy 10: '.mysql_error());
}
// Set the page name returned below for the redirect.
// Special case if owner is the 'admin' user.
$fancy = $config->fancy_url() ? "/" : "/?page=";
$object['name'] = $owner == "admin" ? $fancy.$page : '/'.$owner.$fancy.$page;
$object['name'] = copy_page($current_page, $current_owner,
$new_page, $new_owner);
echo json_encode($object);
?>
<?php
// Dobrado Content Management System
// Copyright (C) 2012 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Includes are in the calling files so that they're not re-included.
function copy_page($current_page, $current_owner, $new_page, $new_owner) {
$q = mysql_query('SELECT MAX(box_id) AS box_id FROM modules WHERE user="'.
$new_owner.'"');
if (!$q) error_log('copy_page 1: '.mysql_error());
$modules = mysql_fetch_assoc($q);
$id = $modules['box_id'] + 1;
$q = mysql_query('SELECT MAX(box_id) AS box_id FROM modules_history '.
'WHERE user="'.$new_owner.'"');
if (!$q) error_log('copy_page 2: '.mysql_error());
$modules_history = mysql_fetch_assoc($q);
if ($id <= $modules_history['box_id']) {
$id = $modules_history['box_id'] + 1;
}
$user = new User();
$config = new Config();
$q = mysql_query('SELECT box_id, box_order, placement, label FROM modules '.
'WHERE user="'.$current_owner.'" AND page="'.
$current_page.'"');
if (!$q) error_log('copy_page 3: '.mysql_error());
while ($modules = mysql_fetch_assoc($q)) {
$label = $modules['label'];
$module = new Module($user, $new_owner, $label, $config);
if ($module->CanAdd($new_page)) {
$order = $modules['box_order'];
$placement = $modules['placement'];
$q1 = mysql_query('INSERT INTO modules VALUES ("'.$new_owner.'","'.
$new_page.'","'.$id.'","'.$label.'","'.$order.'","'.
$placement.'")');
if (!$q1) error_log('copy_page 4: '.mysql_error());
$q1 = mysql_query('INSERT INTO modules_history VALUES ("'.$new_owner.
'","'.$new_page.'","'.$id.'","'.$label.'","'.$order.
'","'.$placement.'","add","'.$user->name.'","'.time().
'")');
if (!$q1) error_log('copy_page 5: '.mysql_error());
$module->Copy($id, $current_owner, $modules['box_id']);
$id++;
}
}
// Write out a new style sheet after the modules have been copied.
if ($new_owner == "admin") write_box_style($new_owner, "../style.css");
else write_box_style($new_owner, "../".$new_owner."/style.css");
// Also copy the page style rules for the new page.
$q = mysql_query('SELECT media, selector, property, value FROM page_style '.
'WHERE user="'.$current_owner.'" AND name="'.$current_page.
'"');
if (!$q) error_log('copy_page 6: '.mysql_error());
$values = "";
while ($page_style = mysql_fetch_assoc($q)) {
if (!empty($values)) $values .= ',';
$values .= '("'.$new_owner.'","'.$new_page.'","'.
mysql_real_escape_string($page_style['media']).'","'.
mysql_real_escape_string($page_style['selector']).'","'.
mysql_real_escape_string($page_style['property']).'","'.
mysql_real_escape_string($page_style['value']).'")';
}
if (!empty($values)) {
$q = mysql_query('INSERT INTO page_style VALUES '.$values);
if (!$q) error_log('copy_page 7: '.mysql_error());
}
if ($new_owner == "admin") {
write_page_style($new_owner, "../".$new_page.".css");
}
else {
write_page_style($new_owner, "../".$new_owner."/".$new_page.".css");
}
// Set the same user permissions as the original page.
$q = mysql_query('SELECT visitor, edit, copy FROM user_permission WHERE '.
'user="'.$current_owner.'" AND page="'.$current_page.'"');
if (!$q) error_log('copy_page 8: '.mysql_error());
$values = "";
while ($user_permission = mysql_fetch_assoc($q)) {
if (!empty($values)) $values .= ',';
$values .= '("'.$new_owner.'","'.$new_page.'","'.
$user_permission['visitor'].'","'.$user_permission['edit'].'","'.
$user_permission['copy'].'")';
}
if (!empty($values)) {
$q = mysql_query('INSERT INTO user_permission VALUES '.$values);
if (!$q) error_log('copy_page 9: '.mysql_error());
}
// Set the same group permissions as the original page.
$q = mysql_query('SELECT name, edit, copy FROM group_permission WHERE '.
'user="'.$current_owner.'" AND page="'.$current_page.'"');
if (!$q) error_log('copy_page 10: '.mysql_error());
$values = "";
while ($group_permission = mysql_fetch_assoc($q))
{
if (!empty($values)) $values .= ',';
$values .= '("'.$new_owner.'","'.$new_page.'","'.$group_permission['name'].
'","'.$group_permission['edit'].'","'.$group_permission['copy'].'")';
}
if (!empty($values)) {
$q = mysql_query('INSERT INTO group_permission VALUES '.$values);
if (!$q) error_log('copy_page 11: '.mysql_error());
}
// Set published the same as the original page.
$q = mysql_query('SELECT published FROM published WHERE user="'.
$current_owner.'" AND page="'.$current_page.'"');
if (!$q) error_log('copy_page 12: '.mysql_error());
if ($published = mysql_fetch_assoc($q)) {
$q = mysql_query('INSERT INTO published VALUES ("'.$new_owner.'","'.
$new_page.'","'.$published['published'].'")');
if (!$q) error_log('copy_page 13: '.mysql_error());
}
// Return the page name for redirect.
$url = $config->fancy_url() ? "/".$new_page : "/?page=".$new_page;
return $new_owner == "admin" ? $url : '/'.$new_owner.$url;
}
?>
<?php
// Dobrado Content Management System
// Copyright (C) 2011 Malcolm Blaney
// Copyright (C) 2012 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -15,11 +15,17 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
include "../php/db.php";
include "../php/config.php";
include "../php/db.php";
include "../php/module.php";
include "../php/permission.php";
include "../php/user.php";
include "../php/page.php";
include "../php/style.php";
include "../php/write_style.php";
include "../php/copy_page.php";
include "../php/page.php";
include "owner.php";
session_start();
......
......@@ -15,9 +15,6 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
include "module.php";
include "permission.php";
class Page {
public $name = "";
......
<?php
// Dobrado Content Management System
// Copyright (C) 2011 Malcolm Blaney
// Copyright (C) 2012 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -22,9 +22,11 @@ if (session_expired()) return;
include "config.php";
include "db.php";
include "module.php";
include "user.php";
include "permission.php";
include "user.php";
include "style.php";
include "write_style.php";
include "copy_page.php";
// Note that $link is required by mysql_real_escape_string.
$link = connect_db();
......
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