1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 20:58:30 +01:00
php-e107/e107_admin/eurl.php

322 lines
8.1 KiB
PHP
Raw Normal View History

<?php
/*
* e107 website system
*
2009-11-18 01:06:08 +00:00
* Copyright (C) 2008-2009 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* URL Management
*
* $Source: /cvs_backup/e107_0.8/e107_admin/eurl.php,v $
2010-02-10 18:18:01 +00:00
* $Revision$
* $Date$
* $Author$
*/
require_once('../class2.php');
if (!getperms('L'))
{
header('location:'.e_BASE.'index.php');
exit;
2008-12-02 00:40:28 +00:00
}
e107::includeLan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
2009-08-28 16:11:02 +00:00
$e_sub_cat = 'eurl';
require_once(e_ADMIN.'auth.php');
$urlc = new admin_eurl_config();
if (isset($_POST['update']))
{
if($urlc->update())
{
e107::getAdminLog()->logArrayDiffs(e107::getConfig('core')->getPref('url_config'), e107::getConfig('core_backup')->getPref('url_config'), 'EURL_01');
}
}
//var_dump($pref['url_config'], $e107->url->getUrl('pm', 'main', array('f'=>'box', 'box'=>2)));
$urlc->renderPage();
require_once(e_ADMIN.'footer.php');
class admin_eurl_config {
/**
* @var e_form
*/
protected $_frm;
/**
* @var e107plugin
*/
protected $_plug;
/**
* @var e_file
*/
protected $_fl;
/**
* @var e107
*/
protected $_api;
function __construct()
{
$this->_api = e107::getInstance();
$this->_frm = e107::getObject('e_form');
$this->_plug = e107::getObject('e107Plugin');
$this->_fl = e107::getFile();
}
function renderPage()
2008-12-02 00:40:28 +00:00
{
$emessage = e107::getMessage();
$empty = "
<tr>
<td colspan='2'>".LAN_EURL_EMPTY."</td>
</tr>
";
$text = "
<form action='".e_SELF."' method='post' id='urlconfig-form'>
<fieldset id='core-eurl-core'>
<legend>".LAN_EURL_CORECONFIG."</legend>
<table cellpadding='0' cellspacing='0' class='adminlist'>
<colgroup span='2'>
<col class='col-label' />
<col class='col-control' />
</colgroup>
<tbody>
";
$tmp = $this->render_sections('core');
if($tmp) $text .= $tmp;
else $text .= $empty;
$text .= "
</tbody>
</table>
</fieldset>
<fieldset id='core-eurl-plugin'>
<legend>".LAN_EURL_PLUGCONFIG."</legend>
<table cellpadding='0' cellspacing='0' class='adminlist'>
<colgroup span='2'>
<col class='col-label' />
<col class='col-control' />
</colgroup>
<tbody>
";
$tmp = $this->render_sections('plugin');
if($tmp) $text .= $tmp;
else $text .= $empty;
$text .= "
</tbody>
</table>
<div class='buttons-bar center'>
".$this->_frm->admin_button('update', LAN_UPDATE, 'update')."
</div>
</fieldset>
</form>
";
e107::getRender()->tablerender(PAGE_NAME, $emessage->render().$text);
}
function render_sections($id)
2008-12-02 00:40:28 +00:00
{
if($id == 'core')
2008-12-02 00:40:28 +00:00
{
$sections = $this->get_core_sections();
} else
2008-12-02 00:40:28 +00:00
{
$sections = $this->_plug->getall(1);
}
$ret = '';
foreach ($sections as $section)
2008-12-02 00:40:28 +00:00
{
if($id == 'core' && !is_readable(e_FILE.'e_url/core/'.$section['core_path'])) continue;
elseif($id == 'plugin' && !is_readable(e_PLUGIN.$section['plugin_path'].'/e_url')) continue;
$ret .= $this->render_section($id, $section);
}
return $ret;
}
function render_section($id, $section)
{
$this->normalize($id, $section);
$text .= "
<tr>
<td class='label'>{$section['name']}</td>
<td class='control'>
".$this->render_section_radio($id, $section)."
";
$text .= "
</td>
</tr>
";
return $text;
}
function render_section_radio($id, $section)
{
global $pref;
//DEFAULT
$checked_def = e107::findPref('url_config/'.$section['path']) ? '' : ' checked="checked"';
$def = "
<div class='field-spacer'>
<input type='radio' class='radio' id='{$section['path']}-default' name='cprofile[{$section['path']}]' value='0'{$checked_def} /><label for='{$section['path']}-default'>".LAN_EURL_DEFAULT."</label>
</div>
";
//CUSTOM - CENTRAL REPOSITORY
$udefined_id = $id.'-custom:'.$section['path'];
$udefined_path = e_FILE."e_url/custom/{$id}/{$section['path']}/";
$need_save = false; $checked = false;
$custom = '';
if(is_readable($udefined_path))
{
//Search the central url config repository - one config to rull them all
if($pref['url_config'][$section['path']])
{
$pref['url_config'][$section['path']] = $udefined_id;
$need_save = true;
}
$checked = $pref['url_config'][$section['path']] == $udefined_id ? ' checked="checked"' : '';
$custom = "
<input type='radio' class='radio' id='{$section['path']}-custom' name='cprofile[{$section['path']}]' value='{$udefined_id}'{$checked} /><label for='{$section['path']}-custom'>".LAN_EURL_UDEFINED."</label>
<a href='#{$section['path']}-custom-info' class='e-expandit' title='".LAN_EURL_INFOALT."'><img src='".e_IMAGE_ABS."admin_images/info_16.png' alt='' /></a>
<div class='e-hideme' id='{$section['path']}-custom-info'>
<div class='indent'>
".LAN_EURL_UDEFINED_INFO."<br />
<strong>".LAN_EURL_LOCATION."</strong> ".e_FILE_ABS."e_url/custom/{$id}/{$section['path']}/"."
</div>
</div>
";
}
//CUSTOM PROFILES - PLUGINS ONLY
$config_profiles = ''; $profile_id = '';
if($id == 'plugin')
$profile_path = e_PLUGIN."{$section['path']}/e_url/";
else
$profile_path = e_FILE."e_url/core/{$section['path']}/";
$config_profiles_array = $this->get_plug_profiles($profile_path);
//Search for custom url config released with the plugin
if($config_profiles_array)
{
2008-12-02 12:27:10 +00:00
foreach ($config_profiles_array as $config_profile => $profile_info) {
$profile_id = $id.'-profile:'.$config_profile;
$checked_profile = $pref['url_config'][$section['path']] == $profile_id ? ' checked="checked"' : '';
if($custom) $checked_profile = ' disabled="disabled"';
$config_profiles .= "
<input type='radio' class='radio' id='{$section['path']}-profile-{$config_profile}' name='cprofile[{$section['path']}]' value='{$profile_id}'{$checked_profile} /><label for='{$section['path']}-profile-{$config_profile}'>".LAN_EURL_PROFILE." [".varsettrue($profile_info['title'], $config_profile)."]</label>
<a href='#{$section['path']}-profile-{$config_profile}-info' class='e-expandit' title='".LAN_EURL_INFOALT."'><img class='icon action' src='".e_IMAGE_ABS."admin_images/info_16.png' alt='' /></a>
<div class='e-hideme' id='{$section['path']}-profile-{$config_profile}-info'>
<div class='indent'>
2008-12-02 12:27:10 +00:00
".(varsettrue($profile_info['title']) ? '<strong>'.$profile_info['title'].'</strong><br /><br />' : '')."
".varsettrue($profile_info['description'], LAN_EURL_PROFILE_INFO)."<br /><br />
<strong>".LAN_EURL_LOCATION."</strong> ".str_replace(array(e_PLUGIN, e_FILE), array(e_PLUGIN_ABS, e_FILE_ABS), $profile_path)."{$config_profile}/
</div>
</div>
";
}
}
$this->render_shutdown($need_save);
return $def.$config_profiles.$custom;
}
function get_plug_profiles($path)
{
2008-12-02 12:27:10 +00:00
$tmp = $this->_fl->get_dirs($path, '', array('CVS', '.svn'));
$ret = array();
foreach ($tmp as $s) {
$ret[$s] = $this->parse_config_xml($path.$s.'/profile.xml');
}
return $ret;
}
2008-12-02 12:27:10 +00:00
function parse_config_xml($path)
{
2009-11-05 09:15:19 +00:00
$xml = e107::getXml();
2008-12-02 12:27:10 +00:00
$parsed = $xml->loadXMLfile($path, true, true);
//Load Lan file if required
if($parsed && varsettrue($parsed['adminLan'])) {
include_lan($parsed['adminLan']);
}
return $parsed;
}
function render_shutdown($save)
{
global $pref;
2008-12-02 12:27:10 +00:00
if($save && !isset($_POST['update']))
{
if(save_prefs())
{
e107::getMessage()->add(LAN_EURL_AUTOSAVE);
}
}
}
function get_core_sections()
{
$core_def = array(
'core' => array("core_name" => LAN_EURL_CORE_MAIN, 'core_path' => 'core'),
'news' => array("core_name" => LAN_EURL_CORE_NEWS, 'core_path' => 'news'),
'download' => array("core_name" => LAN_EURL_CORE_DOWNLOADS, 'core_path' => 'download'),
'user' => array("core_name" => LAN_EURL_CORE_USERS, 'core_path' => 'user')
);
return $core_def;
}
function normalize($id, &$section)
{
$tmp = $section;
foreach ($tmp as $k => $v)
{
$section[str_replace($id.'_', '', $k)] = $v;
unset($section[$k]);
}
}
function update()
{
$core = e107::getConfig();
$core->setPosted('url_config', $_POST['cprofile']);
return $core->save();
}
}
/*
function headerjs()
{
$js = "
<script type='text/javascript'>
</script>";
return $js;
}*/
?>