Commit c4175eb8 authored by Malcolm Blaney's avatar Malcolm Blaney

Initial commit

parents
favicon.ico

1.12 KB

<?php
// Dobrado Content Management System
// Copyright (C) 2011 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/>.
include "php/db.php";
include "php/config.php";
include "php/user.php";
include "php/page.php";
include "php/style.php";
include "php/write_style.php";
session_start();
$config = new Config();
$user = new User($config);
// Need to create an object context here so that $this is defined.
$page = new Page($user, "admin", $config);
?>
CKEDITOR.plugins.add("extended",
{
init: function(editor) {
var pluginName = "extended";
editor.addCommand(pluginName,
{ exec: function() {
var content = { data: editor.getData() };
$.post("/php/request.php",
{ id: dobrado.current,
label: $(dobrado.current).data("label"),
content: JSON.stringify(content),
request: "extended",
mode: "box",
token: dobrado.token },
dobrado.extended.editor);
}
});
editor.ui.addButton("Extended",
{ label: "Extended Editor",
command: pluginName });
}
});
/*
Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
@import url("reset.css");
@import url("mainui.css");
@import url("panel.css");
@import url("toolbar.css");
@import url("menu.css");
@import url("richcombo.css");
@import url("elementspath.css");
@import url("icons.css");
@import url("presets.css");
/* Restore the container visibility */
html .cke_skin_kama
{
visibility: inherit;
}
html.cke_skin_kama_container
{
visibility: visible;
}
.cke_skin_kama a.cke_button_extended .cke_icon
{
background-image: url(/images/extended.png);
background-position: center;
}
if (!this.dobrado) {
var dobrado = {};
}
(function () {
var duplicate = new duplicateUpdateEvent();
// The currently selected box's id.
dobrado.current = "";
// Check if the editor should be loaded when a simple edit area is clicked.
dobrado.editMode = false;
// Keep track of the editor on the page.
dobrado.editor = null;
// Allows modules to check what javascript functions are available.
dobrado.loggedIn = true;
$(function() {
// A security token is sent with each request to the server.
dobrado.token = $(".dobrado-token").attr("id");
$(".sortable").sortable({
update: updateLayoutPosition,
connectWith: '.sortable',
placeholder: 'ui-sortable-placeholder',
opacity: 0.6
});
$(".sortable > *").css("cursor", "move");
$.post("/php/init.php", { token: dobrado.token }, function(response) {
if (!response) return;
var attributes = JSON.parse(response);
$(attributes).each(function() {
$(this.id).data("label", this.label);
});
});
$(".editable").each(function() {
$(this).click(dobrado.editModule);
});
// Use ckeditor's save button to update content.
// (This should be configurable in a future version of the editor)
hijackSaveButton();
});
function hijackSaveButton() {
CKEDITOR.plugins.registered['save'] =
{
init : function(editor) {
editor.addCommand('save',
{
modes: { wysiwyg:1, source:1 },
exec: function(editor) {
if (dobrado.current && editor.checkDirty()) {
$(dobrado.current + " .editable").html(editor.getData());
var content = { data: editor.getData() };
$.post("/php/content.php", {
id: dobrado.current,
label: $(dobrado.current).data("label"),
content: JSON.stringify(content),
token: dobrado.token
});
editor.resetDirty();
}
}
});
editor.ui.addButton( 'Save', { label: 'Save', command: 'save' });
}
};
}
/***
* Pacth for dialog-fix ckeditor problem [ by ticket #4727 ]
* http://dev.jqueryui.com/ticket/4727
*/
$.extend($.ui.dialog.overlay, { create: function(dialog) {
if (this.instances.length === 0) {
// prevent use of anchors and inputs
// we use a setTimeout in case the overlay is created from an
// event that we're going to be cancelling (see #2804)
setTimeout(function() {
// handle $(el).dialog().dialog('close') (see #4065)
if ($.ui.dialog.overlay.instances.length) {
$(document).bind($.ui.dialog.overlay.events, function(event) {
var parentDialog = $(event.target).parents('.ui-dialog');
if (parentDialog.length > 0) {
var parentDialogZIndex = parentDialog.css('zIndex') || 0;
return parentDialogZIndex > $.ui.dialog.overlay.maxZ;
}
var aboveOverlay = false;
$(event.target).parents().each(function() {
var currentZ = $(this).css('zIndex') || 0;
if (currentZ > $.ui.dialog.overlay.maxZ) {
aboveOverlay = true;
return;
}});
return aboveOverlay;
});
}
}, 1);
// allow closing by pressing the escape key
$(document).bind('keydown.dialog-overlay', function(event) {
(dialog.options.closeOnEscape && event.keyCode
&& event.keyCode == $.ui.keyCode.ESCAPE && dialog.close(event));
});
// handle window resize
$(window).bind('resize.dialog-overlay', $.ui.dialog.overlay.resize);
}
var $el = $('<div></div>').appendTo(document.body)
.addClass('ui-widget-overlay').css({
width: this.width(),
height: this.height()
});
(dialog.options.stackfix && $.fn.stackfix && $el.stackfix());
this.instances.push($el);
return $el;
}});
function duplicateUpdateEvent() {
var prev_id, prev_placement, prev_order;
this.check = function(id, placement, order) {
if (id === prev_id &&
placement === prev_placement &&
order === prev_order) {
return true;
}
else {
prev_id = id;
prev_placement = placement;
prev_order = order;
return false;
}
};
}
function updateLayoutPosition(event, ui) {
// This event fires twice when switching groups, so check for duplicate.
var id = "#" + $(ui.item).attr("id");
var placement = $(id).parent().attr("class").match(/^\S+/)[0];
var order = $(id).prevAll().length;
if (duplicate.check(id, placement, order)) {
return;
}
$.post("/php/layout.php", { id: id,
label: $(id).data("label"),
placement: placement,
box_order: order,
token: dobrado.token });
}
dobrado.editModule = function() {
if (!dobrado.editMode) return;
dobrado.closeEditor();
var exp = new RegExp("^dobrado-");
$(this).parents("div").each(function() {
if (exp.test($(this).attr("id"))) {
dobrado.current = "#" + $(this).attr("id");
return false;
}
});
// Copy some of the current module's style into the editor.
var css = "body { ";
var backgroundColor = $(dobrado.current).css("background-color");
if (backgroundColor) css += "background-color: " + backgroundColor + ";";
var color = $(dobrado.current).css("color");
if (color) css += " color: " + color + ";";
css += "}";
CKEDITOR.on("instanceCreated", function(e) { e.editor.addCss(css); });
dobrado.editor = CKEDITOR.replace($(this).get(0),
{ enterMode: CKEDITOR.ENTER_BR,
extraPlugins: "extended",
height: $(this).height(),
removePlugins: "elementspath",
resize_enabled: false,
scayt_autoStartup: false,
toolbar: [ [ 'Undo', 'Redo', '-', 'Bold', 'Italic', 'Underline',
'Strike', '-', 'Link', 'Unlink', '-', 'Extended' ] ]
});
};
dobrado.select = function() {
this.select();
};
dobrado.closeEditor = function() {
if (dobrado.editor) {
if (dobrado.current && dobrado.editor.checkDirty()) {
var content = { data: dobrado.editor.getData() };
$(dobrado.current + " .editable").html(content.data);
$.post("/php/content.php", { id: dobrado.current,
label: $(dobrado.current).data("label"),
content: JSON.stringify(content),
token: dobrado.token });
dobrado.current = "";
}
dobrado.editor.destroy();
dobrado.editor = null;
}
};
dobrado.removeModule = function(id, done) {
var label = $(id).data("label");
$(id).remove();
$.post("/php/remove.php", { id: id, label: label, token: dobrado.token },
function(response) {
if (response) {
var remove = JSON.parse(response);
if (remove.done) done();
}
});
};
})();
if (!this.dobrado) {
var dobrado = {};
}
(function () {
// The currently selected box's id.
dobrado.current = "";
// Allows modules to check what javascript functions are available.
dobrado.loggedIn = false;
$(function() {
// A security token is sent with each request to the server.
dobrado.token = $(".dobrado-token").attr("id");
// Use ckeditor's save button to update content.
// (This should be configurable in a future version of the editor)
hijackSaveButton();
});
function hijackSaveButton() {
CKEDITOR.plugins.registered['save'] =
{
init : function(editor) {
editor.addCommand('save',
{
modes: { wysiwyg:1, source:1 },
exec: function(editor) {
if (dobrado.current && editor.checkDirty()) {
$(dobrado.current + " .editable").html(editor.getData());
var content = { data: editor.getData() };
$.post("/php/content.php", {
id: dobrado.current,
label: $(dobrado.current).data("label"),
content: JSON.stringify(content),
token: dobrado.token
});
editor.resetDirty();
}
}
});
editor.ui.addButton( 'Save', { label: 'Save', command: 'save' });
}
};
}
/***
* Pacth for dialog-fix ckeditor problem [ by ticket #4727 ]
* http://dev.jqueryui.com/ticket/4727
*/
$.extend($.ui.dialog.overlay, { create: function(dialog) {
if (this.instances.length === 0) {
// prevent use of anchors and inputs
// we use a setTimeout in case the overlay is created from an
// event that we're going to be cancelling (see #2804)
setTimeout(function() {
// handle $(el).dialog().dialog('close') (see #4065)
if ($.ui.dialog.overlay.instances.length) {
$(document).bind($.ui.dialog.overlay.events, function(event) {
var parentDialog = $(event.target).parents('.ui-dialog');
if (parentDialog.length > 0) {
var parentDialogZIndex = parentDialog.css('zIndex') || 0;
return parentDialogZIndex > $.ui.dialog.overlay.maxZ;
}
var aboveOverlay = false;
$(event.target).parents().each(function() {
var currentZ = $(this).css('zIndex') || 0;
if (currentZ > $.ui.dialog.overlay.maxZ) {
aboveOverlay = true;
return;
}});
return aboveOverlay;
});
}
}, 1);
// allow closing by pressing the escape key
$(document).bind('keydown.dialog-overlay', function(event) {
(dialog.options.closeOnEscape && event.keyCode
&& event.keyCode == $.ui.keyCode.ESCAPE && dialog.close(event));
});
// handle window resize
$(window).bind('resize.dialog-overlay', $.ui.dialog.overlay.resize);
}
var $el = $('<div></div>').appendTo(document.body)
.addClass('ui-widget-overlay').css({
width: this.width(),
height: this.height()
});
(dialog.options.stackfix && $.fn.stackfix && $el.stackfix());
this.instances.push($el);
return $el;
}});
})();
This diff is collapsed.
if (!this.dobrado.extended) {
dobrado.extended = {};
}
(function() {
// Style rules that need to be saved when the style editor is closed.
var rules = {};
$(function() {
$(".extended").dialog({
autoOpen: false,
close: close,
modal: true,
position: ["center", "top"],
title: "Extended Editor",
width: 720,
height: 500
});
$("#extended-tabs").tabs();
$("#colorpicker").addClass("ui-widget-content").hide();
});
function close() {
if (!$.isEmptyObject(rules)) {
var url = "/php/page_style.php";
if (dobrado.current) {
url = "/php/box_style.php";
}
$.post(url, { style: JSON.stringify(rules),
token: dobrado.token });
rules = {};
}
// Need to remove the current style rules.
$(".style-editor").accordion("destroy");
var html = '<h3><a href="#">Add a new style group</a></h3>' +
'<div>' +
'<label for="extended-new-selector">Selector: </label>' +
'<input id="extended-new-selector">' +
'</div>';
$(".style-editor").html(html);
dobrado.closeEditor();
$(".extended").dialog("close");
}
dobrado.extended.updateStyleRuleComponents = function() {
var availableTags =
["azimuth", "background", "background-attachment", "background-color",
"background-image", "background-position", "background-repeat",
"border", "border-bottom", "border-bottom-color", "border-bottom-style",
"border-bottom-width", "border-collapse", "border-color",
"border-image", "border-left", "border-left-color", "border-left-style",
"border-left-width", "border-radius", "border-right",
"border-right-color", "border-right-style", "border-right-width",
"border-spacing", "border-style", "border-top", "border-top-color",
"border-top-style", "border-top-width", "border-width", "bottom",
"box-shadow", "caption-side", "clear", "clip", "color", "content",
"counter-increment", "counter-reset", "cue", "cue-after", "cue-before",
"cursor", "direction", "display", "elevation", "empty-cells", "filter",
"float", "font", "font-family", "font-size", "font-style",
"font-variant", "font-weight", "height", "left", "letter-spacing",
"line-height", "list-style", "list-style-image", "list-style-position",
"list-style-type", "margin", "margin-bottom", "margin-left",
"margin-right", "margin-top", "max-height", "max-width", "min-height",
"min-width", "orphans", "outline", "outline-color", "outline-style",
"outline-width", "overflow", "padding", "padding-bottom",
"padding-left", "padding-right", "padding-top", "page",
"page-break-after", "page-break-before", "page-break-inside", "pause",
"pause-after", "pause-before", "pitch", "pitch-range", "play-during",
"position", "quotes", "richness", "right", "size", "speak",
"speak-header", "speak-numeral", "speak-punctuation", "speech-rate",
"stress", "text-align", "text-decoration", "text-indent",
"text-transform", "top", "unicode-bidi", "vertical-align", "visibility",
"voice-family", "volume", "white-space", "widows", "width",
"word-spacing", "z-index"];
$(".style-property").autocomplete({
source: availableTags
});
$(".remove-style-rule").button({
icons: { primary: 'ui-icon-closethick' },
text: false
});
var color = RegExp("^#[a-f0-9]+$", "i");
// Initialise existing color fields.
$(".style-value").each(function() {
if (color.test($(this).val())) {
$.farbtastic("#colorpicker").linkTo(this);
$.farbtastic("#colorpicker").setColor($(this).val());
}
});
$(".style-value").click(function() {
if (color.test($(this).val())) {
$.farbtastic("#colorpicker").linkTo(this);
$("#colorpicker").show().position({
of: this,
my: "top",
at: "bottom",
collision: "none"
});
$(this).blur(function() {
$("#colorpicker").hide();
});
}
});
};
dobrado.extended.addNewSelector = function(event) {
if (event.keyCode !== 13) {
return;
}
event.preventDefault();
var selector = $(this).val();
selector = selector.replace(/>/g, "&gt;");
selector = selector.replace(/</g, "&lt;");
if (selector) {
var newStyleGroup = '<h3><a href="#">' + selector +
'</a></h3>' +
'<div class="style-group">' +
'<div class="style-rule">' +
'<button class="remove-style-rule">remove</button>' +
'<span class="ui-widget">' +
'<input class="style-property" value="property" size="15">' +
'</span>' +
'<input class="style-value" value="value" size="15">' +
'</div>' +
'<button class="new-style-rule">Add a new style rule</button>' +
'</div>';
$(this).val("");
$(".style-editor").accordion("destroy");
$(newStyleGroup).insertAfter($(this).parent());
$(".style-editor").accordion({ autoHeight: false });
$(".style-editor").accordion("activate", 1);
dobrado.extended.addStyleRuleEvents();
dobrado.extended.updateStyleRuleComponents();
}
};
dobrado.extended.addStyleRuleEvents = function() {
function save(selector, property, value) {
var current = {};
if (rules[selector]) {
current = rules[selector];
}
current[property] = value;
rules[selector] = current;
}
function customSelector(text) {
if (dobrado.current) {
return text === "General" ?
dobrado.current : dobrado.current + " " + text;
}
return text;
}
$(".remove-style-rule").live("click", function() {
var property =
$(this).next(".ui-widget").children(".style-property").val();
// Check if this style-group has a custom selector.
var custom = $(this).parents(".style-group").prev("h3").text();
var selector = customSelector(custom);
$(selector).css(property, "");
save(selector, property, "");
$(this).parent().remove();
});
$(".style-property").live("click", dobrado.select);
$(".style-value").live("click", dobrado.select).live("blur", function() {
var property =
$(this).prev(".ui-widget").children(".style-property").val();
// Check if this style-group has a custom selector.
var custom = $(this).parents(".style-group").prev("h3").text();
var selector = customSelector(custom);
$(selector).css(property, $(this).val());
save(selector, property, $(this).val());
}).live("keypress", function(event) {
if (event.keyCode !== 13) {
return;
}
event.preventDefault();
var property =
$(this).prev(".ui-widget").children(".style-property").val();
// Check if this style-group has a custom selector.
var custom = $(this).parents(".style-group").prev("h3").text();
var selector = customSelector(custom);
$(selector).css(property, $(this).val());
save(selector, property, $(this).val());
});
$(".new-style-rule").button().click(function() {
var newStyleRule = '<div class="style-rule">' +
'<button class="remove-style-rule">remove</button>' +
'<span class="ui-widget">' +
'<input class="style-property" value="property" size="15">' +
'</span>' +
'<input class="style-value" value="value" size="15">' +
'</div>';
$(newStyleRule).insertBefore($(this));
dobrado.extended.updateStyleRuleComponents();
});
};
dobrado.extended.editor = function(response) {
if (!response) return;
var extended = JSON.parse(response);
$("#extended-content").html(extended.content);
// The editor tab is displayed first.
var edit = $("#extended-content > div");
if (dobrado.editor) {
dobrado.editor.destroy();
}
dobrado.editor = CKEDITOR.replace(edit.get(0),
{ enterMode: CKEDITOR.ENTER_BR,
removePlugins: "elementspath",
resize_enabled: false,
scayt_autoStartup: false,
toolbar: [ [ 'Source', '-', 'Save', 'NewPage' ],
[ 'Undo', 'Redo', '-', 'SelectAll', 'RemoveFormat' ],
[ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea',
'Select', 'Button', 'ImageButton', 'HiddenField'],
[ 'Bold', 'Italic', 'Underline', 'Strike' ],
[ 'Subscript', 'Superscript'],
[ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent',
'Blockquote', 'CreateDiv'],
[ 'JustifyLeft', 'JustifyCenter', 'JustifyRight',
'JustifyBlock'],
[ 'Link', 'Unlink', 'Anchor'],
[ 'Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley',
'SpecialChar', 'PageBreak'],
[ 'Styles', 'Format', 'Font', 'FontSize'],
[ 'TextColor', 'BGColor'],
[ 'Maximize', 'ShowBlocks', '-', 'About'] ]
});
// The style tab.
$(".style-editor").append(extended.style);
$(".style-editor").accordion({ autoHeight: false });
dobrado.extended.addStyleRuleEvents();
dobrado.extended.updateStyleRuleComponents();
$("#extended-new-selector").keypress(dobrado.extended.addNewSelector);
// The history tab.
$("#extended-history").html(extended.history);
$(".extended").dialog("option", "title", "Extended Editor");
$(".extended").dialog("open");
};
})();
<?php
// Dobrado Content Management System
// Copyright (C) 2011 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/>.
session_start();
if (empty($_SESSION['token']) || empty($_POST['token']) ||
$_SESSION['token'] != $_POST['token']) return;
include "db.php";
include "module.php";
include "permission.php";
include "user.php";
if (!can_edit_page()) return;
$owner = $_SESSION['owner'];