Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close #316: Support template specific configuration and i18n #341

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 60 additions & 10 deletions cmsimple/adminfuncs.php
Expand Up @@ -336,11 +336,6 @@ function XH_settingsView()
. $tx['filetype'][$i] . '</a></li>' . "\n";
}

foreach (array('stylesheet', 'template') as $i) {
$o .= '<li><a href="' . $sn . '?file=' . $i . '&amp;action=edit">'
. utf8_ucfirst($tx['action']['edit']) . ' '
. $tx['filetype'][$i] . '</a></li>' . "\n";
}
foreach (array('log') as $i) {
$o .= '<li><a href="' . $sn . '?file=' . $i . '&amp;action=view">'
. utf8_ucfirst($tx['action']['view']) . ' '
Expand All @@ -352,6 +347,7 @@ function XH_settingsView()
$o .= XH_backupsView();
$o .= '<h4>' . $tx['settings']['more'] . '</h4>' . "\n"
. '<ul>' . "\n"
. '<li><a href="' . $sn . '?xh_template">' . $tx['editmenu']['template'] . '</a></li>'
. '<li><a href="' . $sn . '?&validate">' . $tx['editmenu']['validate'] . '</a></li>'
. '<li><a href="' . $sn . '?&xh_pagedata">' .$tx['editmenu']['pagedata'] . '</a></li>'
. '<li><a href="' . $sn . '?&xh_change_password">' . $tx['editmenu']['change_password'] . '</a></li>'
Expand Down Expand Up @@ -486,6 +482,63 @@ function XH_pluginsView()
return $o;
}


/**
* Returns the template menu array
*
* @return array
*
* @since 1.8
*/
function XH_templateMenu()
{
global $pth, $tx, $sn;

$templateMenu = array();
if (file_exists($pth['file']['template_config'])) {
$templateMenu[] = array(
'label' => utf8_ucfirst($tx['editmenu']['configuration']),
'url' => $sn . '?file=template_config&action=array'
);
}
if (file_exists($pth['file']['template_language'])) {
$templateMenu[] = array(
'label' => utf8_ucfirst($tx['editmenu']['language']),
'url' => $sn . '?file=template_language&action=array'
);
}
$templateMenu[] = array(
'label' => utf8_ucfirst($tx['editmenu']['code']),
'url' => $sn . '?file=template&action=edit'
);
$templateMenu[] = array(
'label' => utf8_ucfirst($tx['editmenu']['stylesheet']),
'url' => $sn . '?file=stylesheet&action=edit'
);
return $templateMenu;
}


/**
* Returns the template view.
*
* @return string HTML
*
* @since 1.8
*/
function XH_templateView()
{
global $tx;

$o = '<h1>' . $tx['editmenu']['template'] . '</h1><ul>';
foreach (XH_templateMenu() as $item) {
$o .= XH_adminMenuItem($item, 0);
}
$o .= '</ul>';
return $o;
}


/**
* Creates the menu of a plugin (add row, add tab), constructed as a table.
* This is an object implemented with a procedural interface.
Expand Down Expand Up @@ -603,11 +656,8 @@ function XH_adminMenu(array $plugins = array())
),
array(
'label' => utf8_ucfirst($tx['editmenu']['template']),
'url' => $sn . '?file=template&action=edit'
),
array(
'label' => utf8_ucfirst($tx['editmenu']['stylesheet']),
'url' => $sn . '?file=stylesheet&action=edit'
'url' => $sn . '?&xh_template',
'children' => XH_templateMenu()
),
array(
'label' => utf8_ucfirst($tx['editmenu']['log']),
Expand Down
16 changes: 13 additions & 3 deletions cmsimple/classes/Controller.php
Expand Up @@ -22,7 +22,7 @@ class Controller
*/
public function initTemplatePaths()
{
global $pth, $cf, $tx;
global $pth, $cf, $tx, $sl;

$pth['folder']['templates'] = $pth['folder']['base'] . 'templates/';
$template = $tx['subsite']['template'] == ''
Expand All @@ -31,9 +31,15 @@ public function initTemplatePaths()
$pth['folder']['template'] = $pth['folder']['templates'] . $template . '/';
$pth['file']['template'] = $pth['folder']['template'] . 'template.htm';
$pth['file']['stylesheet'] = $pth['folder']['template'] . 'stylesheet.css';
$pth['folder']['template_config'] = $pth['folder']['template'] . 'config/';
$pth['file']['template_config'] = $pth['folder']['template_config'] . 'config.php';
$pth['folder']['template_language'] = $pth['folder']['template'] . 'languages/';
$pth['file']['template_language'] = $pth['folder']['template_language'] . $sl . '.php';
$pth['folder']['menubuttons'] = $pth['folder']['template'] . 'menu/';
$pth['folder']['templateimages'] = $pth['folder']['template'] . 'images/';
$pth['folder']['templateflags'] = $pth['folder']['template'] . 'flags/';

XH_createLanguageFile($pth['file']['template_language']);
}

/**
Expand Down Expand Up @@ -262,7 +268,7 @@ public function setBackendF()
{
global $function, $validate, $xh_do_validate, $settings, $xh_backups,
$xh_pagedata, $sysinfo, $phpinfo, $file, $userfiles, $images,
$downloads, $f, $xh_change_password, $xh_plugins;
$downloads, $f, $xh_change_password, $xh_plugins, $xh_template;

if ($function == 'save') {
$f = 'save';
Expand Down Expand Up @@ -292,6 +298,8 @@ public function setBackendF()
$f = 'change_password';
} elseif ($xh_plugins) {
$f = 'xh_plugins';
} elseif ($xh_template) {
$f = 'xh_template';
}
}

Expand Down Expand Up @@ -411,7 +419,9 @@ public function handleFileEdit()
'language' => 'XH\CoreLangFileEdit',
'content' => 'XH\CoreTextFileEdit',
'template' => 'XH\CoreTextFileEdit',
'stylesheet' => 'XH\CoreTextFileEdit'
'stylesheet' => 'XH\CoreTextFileEdit',
'template_config' => 'XH\TemplateConfigFileEdit',
'template_language' => 'XH\TemplateLangFileEdit'
);
$fileEditor = isset($map[$file])
? $this->makeFileEditor($map[$file])
Expand Down
2 changes: 1 addition & 1 deletion cmsimple/classes/PluginConfig.php
Expand Up @@ -118,6 +118,6 @@ private function loadConfig($pluginname)
if ($this->language) {
XH_createLanguageFile($pth['file']['plugin_language']);
}
$this->configs += XH_readConfiguration(true, $this->language);
$this->configs += XH_readConfiguration("plugin", $this->language);
}
}
53 changes: 53 additions & 0 deletions cmsimple/classes/TemplateArrayFileEdit.php
@@ -0,0 +1,53 @@
<?php

namespace XH;

/**
* The abstract base class for template config file editing.
*
* @author Peter Harteg <peter@harteg.dk>
* @author The CMSimple_XH developers <devs@cmsimple-xh.org>
* @copyright 1999-2009 Peter Harteg
* @copyright 2009-2017 The CMSimple_XH developers <http://cmsimple-xh.org/?The_Team>
* @license http://www.gnu.org/licenses/gpl-3.0.en.html GNU GPLv3
* @see http://cmsimple-xh.org/
* @since 1.8
*/
abstract class TemplateArrayFileEdit extends ArrayFileEdit
{
/**
* The name of the config array variable.
*
* @var string
*/
protected $varName = null;

/**
* Constructs an instance.
*/
public function __construct()
{
global $pth, $sl, $file;

$this->filename = $pth['file'][$file];
$this->metaLangFile = "{$pth['folder']['template']}languages/meta$sl.php";
parent::__construct();
}

/**
* Returns the the file contents as string for saving.
*
* @return string
*/
protected function asString()
{
$o = "<?php\n\n";
foreach ($this->cfg as $cat => $opts) {
foreach ($opts as $name => $opt) {
$opt = addcslashes($opt['val'], "\0..\37\"\$\\");
$o .= "\$$this->varName['$cat']['$name']=\"$opt\";\n";
}
}
return $o;
}
}
54 changes: 54 additions & 0 deletions cmsimple/classes/TemplateConfigFileEdit.php
@@ -0,0 +1,54 @@
<?php

namespace XH;

/**
* Editing of template config files.
*
* @author Peter Harteg <peter@harteg.dk>
* @author The CMSimple_XH developers <devs@cmsimple-xh.org>
* @copyright 1999-2009 Peter Harteg
* @copyright 2009-2017 The CMSimple_XH developers <http://cmsimple-xh.org/?The_Team>
* @license http://www.gnu.org/licenses/gpl-3.0.en.html GNU GPLv3
* @see http://cmsimple-xh.org/
* @since 1.8
*/
class TemplateConfigFileEdit extends TemplateArrayFileEdit
{
/**
* Constructs an instance.
*/
public function __construct()
{
global $pth, $tpl_cf, $tpl_tx, $tx;

parent::__construct();
$this->caption = utf8_ucfirst($tx['filetype']['template']) . ' '
. utf8_ucfirst($tx['filetype']['config']);
$this->varName = 'tpl_cf';
$this->params = array(
'form' => 'array',
'file' => 'template_config',
'action' => 'save'
);
$this->redir = '?file=template_config&action=array&xh_success=config';
$this->cfg = array();
$tpl_mcf = array();
$fn = "{$pth['folder']['template_config']}metaconfig.php";
if (is_readable($fn)) {
include $fn;
}
foreach ($tpl_cf as $cat => $opts) {
$this->cfg[$cat] = array();
foreach ($opts as $name => $val) {
$omcf = isset($tpl_mcf[$cat][$name]) ? $tpl_mcf[$cat][$name] : null;
$hint = isset($tpl_tx['help']["${cat}_$name"])
? $tpl_tx['help']["${cat}_$name"] : null;
$this->cfg[$cat][$name] = $this->option($omcf, $val, $hint);
}
if (empty($this->cfg[$cat])) {
unset($this->cfg[$cat]);
}
}
}
}
44 changes: 44 additions & 0 deletions cmsimple/classes/TemplateLangFileEdit.php
@@ -0,0 +1,44 @@
<?php

namespace XH;

/**
* Editing of core language files.
*
* @author Peter Harteg <peter@harteg.dk>
* @author The CMSimple_XH developers <devs@cmsimple-xh.org>
* @copyright 1999-2009 Peter Harteg
* @copyright 2009-2017 The CMSimple_XH developers <http://cmsimple-xh.org/?The_Team>
* @license http://www.gnu.org/licenses/gpl-3.0.en.html GNU GPLv3
* @see http://cmsimple-xh.org/
* @since 1.8
*/
class TemplateLangFileEdit extends TemplateArrayFileEdit
{
/**
* Constructs an instance.
*/
public function __construct()
{
global $tpl_tx, $tx;

parent::__construct();
$this->caption = utf8_ucfirst($tx['filetype']['template']) . ' '
. utf8_ucfirst($tx['filetype']['language']);
$this->varName = 'tpl_tx';
$this->params = array(
'form' => 'array',
'file' => 'template_language',
'action' => 'save'
);
$this->redir = '?file=template_language&action=array&xh_success=language';
$this->cfg = array();
foreach ($tpl_tx as $cat => $opts) {
$this->cfg[$cat] = array();
foreach ($opts as $name => $val) {
$co = array('val' => $val, 'type' => 'text', 'isAdvanced' => false);
$this->cfg[$cat][$name] = $co;
}
}
}
}
21 changes: 19 additions & 2 deletions cmsimple/cms.php
Expand Up @@ -358,7 +358,7 @@
*
* @see $plugin_tx
*/
$tx = XH_readConfiguration(false, true);
$tx = XH_readConfiguration("core", true);
if (!$tx) {
die("Language file {$pth['file']['language']} missing");
}
Expand Down Expand Up @@ -725,7 +725,8 @@
'action', 'admin', 'download', 'downloads', 'edit', 'file', 'function', 'images',
'login', 'logout', 'keycut', 'mailform', 'media', 'normal', 'phpinfo', 'print', 'search',
'selected', 'settings', 'sitemap', 'sysinfo', 'text', 'userfiles', 'validate', 'xhpages',
'xh_backups', 'xh_change_password', 'xh_do_validate', 'xh_pagedata', 'xh_plugins'
'xh_backups', 'xh_change_password', 'xh_do_validate', 'xh_pagedata', 'xh_plugins',
'xh_template'
);
foreach ($temp as $i) {
if (!isset($GLOBALS[$i])) {
Expand Down Expand Up @@ -1121,6 +1122,19 @@

XH_afterPluginLoading();

/**
* The configuration of the template
*
* @global array $tpl_cf
*/
$tpl_cf = XH_readConfiguration("template");

/**
* The localization of the template
*
* @global array $tpl_tx
*/
$tpl_tx = XH_readConfiguration("template", true);

switch ($f) {
case 'search':
Expand Down Expand Up @@ -1255,6 +1269,9 @@
case 'xh_plugins':
$o .= XH_pluginsView();
break;
case 'xh_template':
$o .= XH_templateView();
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmsimple/config.php
Expand Up @@ -4,7 +4,7 @@
$cf['security']['secret']="cf7c3ecb0495698c7f657d65";
$cf['security']['email']="";
$cf['security']['frame_options']="";
$cf['site']['template']="fhs-simple";
$cf['site']['template']="fhs-simple-config";
$cf['site']['timezone']="";
$cf['site']['compat']="true";
$cf['language']['default']="en";
Expand Down