Commit 5e2f3e6d authored by Ruslan Kabalin's avatar Ruslan Kabalin

Add Additional HTML page to Configure Site menu (bug #1073625)

This allow admin to embed something without modifying the template, e.g.
Google Analytics snippet.

Change-Id: I030b4d1c682708fdf988e9a4a0dea836b4f285b9
Signed-off-by: default avatarRuslan Kabalin <r.kabalin@lancaster.ac.uk>
parent dc3688e6
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2012 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage admin
* @author Ruslan Kabalin
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2012 Lancaster University
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'configsite/additionalhtml');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'additionalhtml');
require(dirname(dirname(dirname(__FILE__))).'/init.php');
require_once('pieforms/pieform.php');
define('TITLE', get_string('additionalhtml', 'admin'));
define('DEFAULTPAGE', 'additionalhtmlhead');
$additionalhtmlitemnames = site_content_additional_html_items();
$additionalhtmlitems = get_records_select_assoc(
'site_content',
'name IN (' . join(',', array_fill(0, count($additionalhtmlitemnames), '?')) . ')',
$additionalhtmlitemnames
);
$additionalhtmloptions = array();
$additionalhtmlcontent = array();
foreach ($additionalhtmlitemnames as $itemname) {
$additionalhtmloptions[$itemname] = get_string($additionalhtmlitems[$itemname]->name, 'admin');
$additionalhtmlcontent[$itemname] = $additionalhtmlitems[$itemname]->content;
}
$form = pieform(array(
'name' => 'editadditionalhtmlcontent',
'jsform' => true,
'jssuccesscallback' => 'contentSaved',
'elements' => array(
'contentname' => array(
'type' => 'select',
'title' => get_string('additionalhtmllocation', 'admin'),
'defaultvalue' => DEFAULTPAGE,
'options' => $additionalhtmloptions
),
'contenthtml' => array(
'name' => 'contenthtml',
'type' => 'textarea',
'rows' => 25,
'cols' => 100,
'title' => get_string('additionalhtmlcontent', 'admin'),
'defaultvalue' => $additionalhtmlcontent[DEFAULTPAGE],
'rules' => array(
'maxlength' => 65536,
)
),
'submit' => array(
'type' => 'submit',
'value' => get_string('savechanges', 'admin')
),
)
));
function editadditionalhtmlcontent_submit(Pieform $form, $values) {
global $USER;
$data = new StdClass;
$data->name = $values['contentname'];
$data->content = $values['contenthtml'];
$data->mtime = db_format_timestamp(time());
$data->mauthor = $USER->get('id');
try {
update_record('site_content', $data, 'name');
}
catch (SQLException $e) {
$form->reply(PIEFORM_ERR, get_string('savefailed', 'admin'));
}
$form->reply(PIEFORM_OK, get_string('additionalhtmlsaved', 'admin'));
}
$smarty = smarty(array('adminsitehtmlcontent'), array(), array('admin' => array('discardcontentedits')));
$smarty->assign('contenteditform', $form);
$smarty->assign('PAGEHEADING', TITLE);
$smarty->display('admin/site/additionalhtml.tpl');
......@@ -34,7 +34,7 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$contentname = param_alpha('contentname');
if (!$contentitem = get_record('site_content', 'name', $contentname)) {
json_reply('local', get_string('loadsitecontentfailed', 'admin'));
json_reply('local', get_string('loadsitecontentfailed', 'admin', get_string($contentname, 'admin')));
}
$data = array(
......
/**
* Automatically populates the WYSIWYG box on the site pages screen
* with the content of the appropriate page
* @source: http://gitorious.org/mahara/mahara
*
* @licstart
* Copyright (C) 2012 Catalyst IT Ltd
* Copyright (C) 2012 Lancaster University
*
* The JavaScript code in this page is free software: you can
* redistribute it and/or modify it under the terms of the GNU
* General Public License (GNU GPL) as published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version. The code is distributed WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
*
* As additional permission under GNU GPL version 3 section 7, you
* may distribute non-source (e.g., minimized or compacted) forms of
* that code without the copy of the GNU GPL normally required by
* section 4, provided you include this license notice and a URL
* through which recipients can access the Corresponding Source.
* @licend
*/
var oldPageContent = '';
var oldPageName = 'additionalhtmlhead';
var checkOldContent = false;
function updateText() {
if (checkOldContent && oldPageContent != $('editadditionalhtmlcontent_contenthtml').value && !confirm(get_string('discardcontentedits', 'admin'))) {
$('editadditionalhtmlcontent_contentname').value = oldPageName;
return;
}
checkOldContent = true;
sendjsonrequest(
'editchangecontent.json.php',
{'contentname' : $('editadditionalhtmlcontent_contentname').value},
'POST',
function(data) {
if (!data.error) {
$('editadditionalhtmlcontent_contenthtml').value = data.content;
oldPageContent = $('editadditionalhtmlcontent_contenthtml').value;
oldPageName = $('editadditionalhtmlcontent_contentname').value;
}
}
);
}
function connectElements() {
connect('editadditionalhtmlcontent_contentname', 'onchange', updateText);
}
/* Pieform callback*/
function contentSaved(form, data) {
connectElements();
oldPageContent = $('editadditionalhtmlcontent_contenthtml').value;
formSuccess(form, data);
}
addLoadEvent(function() {
connectElements();
updateText();
});
......@@ -426,6 +426,18 @@ $string['sitepageloaded'] = 'Site page loaded';
$string['termsandconditions'] = 'Terms and conditions';
$string['uploadcopyright'] = 'Upload copyright statement';
// Additional html content
$string['additionalhtml'] = 'Additional HTML';
$string['additionalhtmlcontent'] = 'Content';
$string['additionalhtmldescription'] = 'Edit HTML content that you want to add to every page. This allows you to embed counters and services like Google Analytics. You can define HTML that will be added before the closing HEAD tag for the page, immediately after the BODY tag has been opened, or immediately before the BODY tag is closed.';
$string['additionalhtmlfooter'] = 'Before BODY is closed';
$string['additionalhtmlhead'] = 'Within HEAD';
$string['additionalhtmllocation'] = 'Location';
$string['additionalhtmlsaved'] = 'Content saved';
$string['additionalhtmltopofbody'] = 'When BODY is opened';
$string['discardcontentedits'] = 'Discard your changes?';
$string['loadsitecontentfailed'] = 'Unable to load any content for %s';
// Links and resources menu editor
$string['sitefile'] = 'Site file';
$string['adminpublicdirname'] = 'public'; // Name of the directory in which to store public admin files
......
......@@ -3213,5 +3213,18 @@ function xmldb_core_upgrade($oldversion=0) {
add_field($table, $field);
}
if ($oldversion < 2013071200) {
$additionalhtmlitems = site_content_additional_html_items();
$now = db_format_timestamp(time());
foreach ($additionalhtmlitems as $name) {
$page = new stdClass();
$page->name = $name;
$page->ctime = $now;
$page->mtime = $now;
$page->content = '';
insert_record('site_content', $page);
}
}
return $status;
}
......@@ -535,6 +535,7 @@ function upgrade_plugin($upgrade) {
function core_postinst() {
$status = true;
$pages = site_content_pages();
$additionalhtmlitems = site_content_additional_html_items();
$now = db_format_timestamp(time());
foreach ($pages as $name) {
$page = new stdClass();
......@@ -542,7 +543,17 @@ function core_postinst() {
$page->ctime = $now;
$page->mtime = $now;
$page->content = get_string($page->name . 'defaultcontent', 'install');
if (!insert_record('site_content',$page)) {
if (!insert_record('site_content', $page)) {
$status = false;
}
}
foreach ($additionalhtmlitems as $name) {
$page = new stdClass();
$page->name = $name;
$page->ctime = $now;
$page->mtime = $now;
$page->content = '';
if (!insert_record('site_content', $page)) {
$status = false;
}
}
......
......@@ -32,7 +32,7 @@ $config = new StdClass;
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2013062600;
$config->version = 2013071200;
$config->release = '1.8.0dev';
$config->minupgradefrom = 2008040200;
$config->minupgraderelease = '1.0.0 (release tag 1.0.0_RELEASE)';
......
......@@ -659,6 +659,20 @@ EOF;
. '</a>');
}
// Define additional html content
if (get_config('installed')) {
$additionalhtmlitemnames = site_content_additional_html_items();
$additionalhtmlitems = get_records_select_array(
'site_content',
'name IN (' . join(',', array_fill(0, count($additionalhtmlitemnames), '?')) . ')',
$additionalhtmlitemnames
);
if ($additionalhtmlitems) {
foreach ($additionalhtmlitems as $item) {
$smarty->assign(strtoupper($item->name), $item->content);
}
}
}
return $smarty;
}
......@@ -1897,6 +1911,12 @@ function admin_nav() {
'title' => get_string('Files', 'artefact.file'),
'weight' => 80,
),
'configsite/additionalhtml' => array(
'path' => 'configsite/additionalhtml',
'url' => 'admin/site/additionalhtml.php',
'title' => get_string('additionalhtml', 'admin'),
'weight' => 90
),
'configusers' => array(
'path' => 'configusers',
'url' => 'admin/users/search.php',
......@@ -2628,6 +2648,14 @@ function site_content_pages() {
return array('about', 'home', 'loggedouthome', 'privacy', 'termsandconditions');
}
/**
* Returns the list of additional html itmes (site content pages)
* @return array of names
*/
function site_content_additional_html_items() {
return array('additionalhtmlhead', 'additionalhtmltopofbody', 'additionalhtmlfooter');
}
function get_site_page_content($pagename) {
if ($pagedata = get_record('site_content', 'name', $pagename)) {
return $pagedata->content;
......
......@@ -6,6 +6,7 @@
<!--[if (gt IE 9)|!(IE)]><!--><html{if $LANGDIRECTION == 'rtl'} dir="rtl"{/if}><!--<![endif]-->
{include file="header/head.tpl"}
<body class="no-js">
{if $ADDITIONALHTMLTOPOFBODY}{$ADDITIONALHTMLTOPOFBODY|clean_html|safe}{/if}
{if $USERMASQUERADING || !$PRODUCTIONMODE || $SITECLOSED || $SITETOP}<div class="sitemessages">{/if}
{if $USERMASQUERADING}<div class="sitemessage"><img src="{theme_url filename='images/failure.png'}" alt="">{$masqueradedetails} {$becomeyouagain|safe}</div>{/if}
{if !$PRODUCTIONMODE}<div class="sitemessage center">{str tag=notproductionsite section=error}</div>{/if}
......
......@@ -38,5 +38,6 @@
<!-- Responsive design -->
<script type="text/javascript" src="{$WWWROOT}js/rd-nav.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{if $ADDITIONALHTMLHEAD}{$ADDITIONALHTMLHEAD|clean_html|safe}{/if}
</head>
{dynamic}{flush}{/dynamic}
{include file="header.tpl"}
<p>{str tag=additionalhtmldescription section=admin}</p>
{$contenteditform|safe}
{include file="footer.tpl"}
......@@ -38,5 +38,6 @@
</div><!-- footer -->
</div><!-- footer-wrap -->
</div><!-- container -->
{if $ADDITIONALHTMLFOOTER}{$ADDITIONALHTMLFOOTER|clean_html|safe}{/if}
</body>
</html>
......@@ -6,6 +6,7 @@
<!--[if (gt IE 9)|!(IE)]><!--><html{if $LANGDIRECTION == 'rtl'} dir="rtl"{/if}><!--<![endif]-->
{include file="header/head.tpl"}
<body>
{if $ADDITIONALHTMLTOPOFBODY}{$ADDITIONALHTMLTOPOFBODY|clean_html|safe}{/if}
{if $USERMASQUERADING || !$PRODUCTIONMODE || $SITECLOSED || $SITETOP}<div class="sitemessages">{/if}
{if $USERMASQUERADING}<div class="sitemessage"><img src="{theme_url filename='images/failure.png'}" alt="">{$masqueradedetails} {$becomeyouagain|safe}</div>{/if}
{if !$PRODUCTIONMODE}<div class="sitemessage center">{str tag=notproductionsite section=error}</div>{/if}
......
......@@ -35,5 +35,6 @@
<script type="text/javascript" src="{$WWWROOT}js/css.js"></script>
<link rel="shortcut icon" href="{$WWWROOT}favicon.ico" type="image/vnd.microsoft.icon">
<link rel="image_src" href="{$sitelogo}">
{if $ADDITIONALHTMLHEAD}{$ADDITIONALHTMLHEAD|clean_html|safe}{/if}
</head>
{dynamic}{flush}{/dynamic}
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