From 6e11caca4a708b125167bb27b20d4c009842e691 Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Sun, 21 Nov 2004 17:05:40 +0000 Subject: [PATCH] apply some coding rules --- include/xorg.page.inc.php | 205 +++++++++++++++++++++++------------- include/xorg/smarty.plugins.inc.php | 108 +++++++++++++++++++ 2 files changed, 239 insertions(+), 74 deletions(-) create mode 100644 include/xorg/smarty.plugins.inc.php diff --git a/include/xorg.page.inc.php b/include/xorg.page.inc.php index 65b547e..4b0cb2e 100644 --- a/include/xorg.page.inc.php +++ b/include/xorg.page.inc.php @@ -18,67 +18,51 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: xorg.page.inc.php,v 1.48 2004-11-04 17:23:25 x2000habouzit Exp $ + $Id: xorg.page.inc.php,v 1.49 2004-11-21 17:05:40 x2000habouzit Exp $ ***************************************************************************/ -require("diogenes.core.page.inc.php"); +require_once("diogenes.core.page.inc.php"); -function block_dynamic($param, $content, &$smarty) { - if(isset($param['on']) xor empty($param['on'])) - return $content; -} - -function function_implode($params) { - $sep = ' '; - if(isset($params['sep'])) { - $sep = $params['sep']; - unset($params['sep']); - } - foreach($params as $key=>$val) - if(empty($params[$key])) - unset($params[$key]); - - return stripslashes(implode($sep,$params)); -} - -function function_dyn($params) { - return stripslashes(implode(' ',$params)); -} - -function escape_html(&$string) { - if(is_string($string)) { - $transtbl = Array('<' => '<', '>' => '>', '"' => '"'); - return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};)/", "&" , strtr($string, $transtbl)); - } else { - return $string; - } -} - -function triple_quote_to_gettext($tpl_source, &$smarty) { - return preg_replace('/"""(.*?)"""/se', 'gettext(stripslashes(\'\\1\'))',$tpl_source); -} +// {{{ class XorgPage -class XorgPage extends DiogenesCorePage { +/** + * This class is the Core template compiler + * + * @category XOrgCore + * @package XOrgCore + * @author Jeremy Lainé + * @version $Id: xorg.page.inc.php,v 1.49 2004-11-21 17:05:40 x2000habouzit Exp $ + * @access public + * @see DiogenesCorePage + */ +class XorgPage extends DiogenesCorePage +{ + // {{{ properties + var $_page_type; var $_tpl; - function XorgPage($tpl, $type=SKINNED) { - global $site_dev,$globals; + // }}} + // {{{ function XorgPage() + + function XorgPage($tpl, $type=SKINNED) + { + global $site_dev, $globals; $this->setLang(); - $this->template_dir = $globals->spoolroot."/templates/"; - $this->compile_dir = $globals->spoolroot."/templates_c/"; - $this->plugins_dir[]= $globals->spoolroot."/plugins/"; - $this->config_dir = $globals->spoolroot."/configs/"; - $this->cache_dir = $globals->spoolroot."/cache/"; - $this->use_sub_dirs = false; + $this->template_dir = $globals->spoolroot."/templates/"; + $this->compile_dir = $globals->spoolroot."/templates_c/"; + $this->plugins_dir[] = $globals->spoolroot."/plugins/"; + $this->config_dir = $globals->spoolroot."/configs/"; + $this->cache_dir = $globals->spoolroot."/cache/"; + $this->use_sub_dirs = false; $this->config_overwrite = false; $this->compile_check = !empty($site_dev); $this->caching = ($type == SKINNED); - if($type == SKINNED) { + if ($type == SKINNED) { $this->register_modifier('escape_html', 'escape_html'); $this->default_modifiers = Array('escape_html'); } @@ -87,6 +71,7 @@ class XorgPage extends DiogenesCorePage { $this->_tpl = $tpl; $this->DiogenesCorePage(); + require_once('xorg/smarty.plugins.inc.php'); $this->register_block('dynamic', 'block_dynamic', false); $this->register_function('dyn', 'function_dyn', false); $this->register_function('implode', 'function_implode'); @@ -100,11 +85,15 @@ class XorgPage extends DiogenesCorePage { $this->doAuth(); } - function changeTpl($tpl, $type=SKINNED) { + // }}} + // {{{ function changeTpl() + + function changeTpl($tpl, $type=SKINNED) + { $this->_tpl = $tpl; $this->_page_type = $type; $this->caching = ($type == SKINNED); - if($type == SKINNED) { + if ($type == SKINNED) { $this->register_modifier('escape_html', 'escape_html'); $this->default_modifiers = Array('escape_html'); } @@ -113,7 +102,11 @@ class XorgPage extends DiogenesCorePage { $this->assign('xorg_tpl', $tpl); } - function setLang($lang=null) { + // }}} + // {{{ function setLang() + + function setLang($lang=null) + { global $globals; $locale = empty($lang) ? 'fr_FR' : '$lang'; setlocale(LC_MESSAGES, $locale); @@ -123,14 +116,20 @@ class XorgPage extends DiogenesCorePage { textdomain('xorg'); } - function run($append_to_id="") { + // }}} + // {{{ function run() + + function run($append_to_id="") + { global $baseurl, $site_dev, $globals, $TIME_BEGIN; - if($this->_page_type == NO_SKIN) + if ($this->_page_type == NO_SKIN) { $this->display($this->_tpl); - else { - if(isset($_SESSION['suid'])) $this->caching=false; + } else { + if (isset($_SESSION['suid'])) { + $this->caching=false; + } $id = $this->make_id($append_to_id); - if($site_dev) { + if ($site_dev) { $this->assign('db_trace', $globals->db->trace_format($this, 'database-debug.tpl')); $this->assign('validate', urlencode($baseurl.'/valid.html')); @@ -141,9 +140,9 @@ class XorgPage extends DiogenesCorePage { fclose($fd); exec($globals->spoolroot."/scripts/xhtml/validate.pl ".$this->cache_dir."valid.html", $val); - foreach($val as $h) - if(preg_match("/^X-W3C-Validator-Errors: (\d+)$/", $h, $m)) { - if($m[1]) { + foreach ($val as $h) { + if (preg_match("/^X-W3C-Validator-Errors: (\d+)$/", $h, $m)) { + if ($m[1]) { echo str_replace("@HOOK@", "$total_time{$m[1]} ERREUR(S) !!!
", $result); } else { @@ -151,13 +150,19 @@ class XorgPage extends DiogenesCorePage { } exit; } - } else + } + } else { $this->display('skin/'.$_SESSION['skin'], $id); + } } exit; } - function failure() { + // }}} + // {{{ function failure() + + function failure() + { $this->_page_type = SKINNED; $this->_tpl = 'failure.tpl'; $this->assign('xorg_tpl', 'failure.tpl'); @@ -165,60 +170,83 @@ class XorgPage extends DiogenesCorePage { $this->run(); } - function xorg_is_cached($append_to_id="") { - if($this->_page_type == NO_SKIN) + // }}} + // {{{ function xorg_is_cached() + + function xorg_is_cached($append_to_id="") + { + if ($this->_page_type == NO_SKIN) { return parent::is_cached($this->_tpl); - else + } else { return parent::is_cached('skin/'.$_SESSION['skin'], $this->make_id($append_to_id)); + } } - function xorg_clear_cache($tpl) { - if($this->_page_type == NO_SKIN) + // }}} + // {{{ function xorg_clear_cache() + + function xorg_clear_cache($tpl) + { + if ($this->_page_type == NO_SKIN) { return parent::clear_cache($tpl); - else + } else { return parent::clear_cache(null, $tpl); + } } - function make_id($append_to_id="") { - if($this->_page_type == NO_SKIN) + // }}} + // {{{ function make_id() + + function make_id($append_to_id="") + { + if ($this->_page_type == NO_SKIN) { return null; + } $ret = $this->_tpl; - if($append_to_id) + if ($append_to_id) { $ret.="-$append_to_id"; + } $auth_trans = Array(AUTH_PUBLIC => 'public', AUTH_COOKIE => 'cookie', AUTH_MDP => 'passwd'); $ret .= '-'.$auth_trans[empty($_SESSION['auth']) ? AUTH_PUBLIC : $_SESSION['auth']]; - $ret .= '-'.(empty($_SESSION['perms']) ? PERMS_EXT : $_SESSION['perms']); return $ret; } + // }}} + // {{{ function doAuth() + function doAuth() { } + + // }}} + // {{{ function mysql_assign() function mysql_assign($sql_query,$var_name,$var_nb_name='',$var_found_rows='') { global $globals; //lorsqu'on désire obtenir found_rows il faut désactiver la trace du résultat $switch_trace = false; - if(!empty($var_found_rows) && $globals->db->_trace==1) { + if (!empty($var_found_rows) && $globals->db->_trace==1) { $switch_trace = true; $globals->db->trace_off(); } $sql = $globals->db->query($sql_query); - if(mysql_errno()) + if (mysql_errno()) { return(mysql_error($sql)); + } $array = Array(); - while($array[] = mysql_fetch_assoc($sql)); + while ($array[] = mysql_fetch_assoc($sql)); array_pop($array); mysql_free_result($sql); $this->assign_by_ref($var_name,$array); - if(!empty($var_nb_name)) + if (!empty($var_nb_name)) { $this->assign($var_nb_name, count($array)); + } - if(!empty($var_found_rows)) { + if (!empty($var_found_rows)) { $n_res = $globals->db->query('SELECT FOUND_ROWS()'); $r = mysql_fetch_row($n_res); $this->assign($var_found_rows, $r[0]); @@ -233,52 +261,81 @@ class XorgPage extends DiogenesCorePage { return 0; } + // }}} + } +// }}} +// {{{ class XOrgAuth /** Une classe pour les pages nécessitant l'authentification. * (equivalent de controlauthentification.inc.php) */ class XorgAuth extends XorgPage { + // {{{ function XorgAuth() + function XorgAuth($tpl, $type=SKINNED) { $this->XorgPage($tpl, $type); } + // }}} + // {{{ function doAuth() + function doAuth() { $_SESSION['session']->doAuth($this); } + + // }}} } +// }}} +// {{{ class XorgCookie /** Une classe pour les pages nécessitant l'authentification permanente. * (equivalent de controlpermanent.inc.php) */ class XorgCookie extends XorgPage { + // {{{ function XorgCookie() + function XorgCookie($tpl, $type=SKINNED) { $this->XorgPage($tpl, $type); } + + // }}} + // {{{ function doAuth() function doAuth() { $_SESSION['session']->doAuthCookie($this); } + + // }}} } +// }}} +// {{{ class XorgAdmin /** Une classe pour les pages réservées aux admins (authentifiés!). */ class XorgAdmin extends XorgAuth { + // {{{ function XorgAdmin() + function XorgAdmin($tpl, $type=SKINNED) { $this->XorgAuth($tpl, $type); check_perms(); } + + // }}} } +// }}} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker: ?> diff --git a/include/xorg/smarty.plugins.inc.php b/include/xorg/smarty.plugins.inc.php new file mode 100644 index 0000000..6ed207e --- /dev/null +++ b/include/xorg/smarty.plugins.inc.php @@ -0,0 +1,108 @@ +$val) { + if(empty($params[$key])) { + unset($params[$key]); + } + } + + return stripslashes(implode($sep,$params)); +} + +// }}} +// {{{ function function_dyn() + +/** + * smarty function, woking like {dynamic} block + * + * @deprecated since 0.9.0 + */ +function function_dyn($params) +{ + return stripslashes(implode(' ',$params)); +} + +// }}} +// {{{ function escape_html () + +/** + * default smarty plugin, used to auto-escape dangerous html. + * + * < --> < + * > --> > + * " --> " + * & not followed by some entity --> & + */ +function escape_html(&$string) +{ + if(is_string($string)) { + $transtbl = Array('<' => '<', '>' => '>', '"' => '"'); + return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};)/", "&" , strtr($string, $transtbl)); + } else { + return $string; + } +} + +// }}} +// {{{ function triple_quote_to_gettext() + +/** + * compilation plugin used for i18n purposes. + * + * Not used. + */ +function triple_quote_to_gettext($tpl_source, &$smarty) +{ + return preg_replace('/"""(.*?)"""/se', 'gettext(stripslashes(\'\\1\'))',$tpl_source); +} + +// }}} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker: +?> -- 2.1.4