From feed586bcbe5c960d52f9bc007016bbe695c8bdf Mon Sep 17 00:00:00 2001 From: mcfly Date: Thu, 8 Jan 2009 21:47:44 +0000 Subject: [PATCH] Converting related core shortcodes to use batch class->method functionality. --- .../shortcode/batch/siteinfo_shortcodes.php | 46 +++++++ e107_files/shortcode/sitebutton.sc | 3 - e107_files/shortcode/sitecontactinfo.sc | 1 - e107_files/shortcode/sitedescription.sc | 1 - e107_files/shortcode/sitedisclaimer.sc | 3 - e107_files/shortcode/sitename.sc | 2 - e107_files/shortcode/sitetag.sc | 1 - e107_handlers/e_parse_class.php | 120 +++++++++--------- e107_handlers/shortcode_handler.php | 16 ++- 9 files changed, 121 insertions(+), 72 deletions(-) create mode 100644 e107_files/shortcode/batch/siteinfo_shortcodes.php delete mode 100644 e107_files/shortcode/sitebutton.sc delete mode 100644 e107_files/shortcode/sitecontactinfo.sc delete mode 100644 e107_files/shortcode/sitedescription.sc delete mode 100644 e107_files/shortcode/sitedisclaimer.sc delete mode 100644 e107_files/shortcode/sitename.sc delete mode 100644 e107_files/shortcode/sitetag.sc diff --git a/e107_files/shortcode/batch/siteinfo_shortcodes.php b/e107_files/shortcode/batch/siteinfo_shortcodes.php new file mode 100644 index 000000000..4c6f5c1ab --- /dev/null +++ b/e107_files/shortcode/batch/siteinfo_shortcodes.php @@ -0,0 +1,46 @@ +tp->replaceConstants($_POST['sitebutton']) : (strstr(SITEBUTTON, 'http:') ? SITEBUTTON : e_IMAGE.SITEBUTTON); + return "\"".SITENAME."\""; + } + + function get_sitedisclaimer() + { + $e107 = e107::getInstance(); + return $e107->tp->toHtml(SITEDISCLAIMER, true, 'constants defs'); + } + + function get_sitename($parm) + { + return ($parm == 'link') ? "".SITENAME."" : SITENAME; + } + + function get_sitedescription() + { + global $pref; + return SITEDESCRIPTION.(defined('THEME_DESCRIPTION') && $pref['displaythemeinfo'] ? THEME_DESCRIPTION : ''); + } + + function get_sitetag() + { + return SITETAG; + } + +} +?> \ No newline at end of file diff --git a/e107_files/shortcode/sitebutton.sc b/e107_files/shortcode/sitebutton.sc deleted file mode 100644 index ddba3411e..000000000 --- a/e107_files/shortcode/sitebutton.sc +++ /dev/null @@ -1,3 +0,0 @@ -global $tp; -$path = ($_POST['sitebutton'] && $_POST['ajax_used']) ? $tp->replaceConstants($_POST['sitebutton']) : (strstr(SITEBUTTON, "http:") ? SITEBUTTON : e_IMAGE.SITEBUTTON); -return "\"".SITENAME."\""; diff --git a/e107_files/shortcode/sitecontactinfo.sc b/e107_files/shortcode/sitecontactinfo.sc deleted file mode 100644 index 127cf1a7c..000000000 --- a/e107_files/shortcode/sitecontactinfo.sc +++ /dev/null @@ -1 +0,0 @@ -return SITECONTACTINFO; \ No newline at end of file diff --git a/e107_files/shortcode/sitedescription.sc b/e107_files/shortcode/sitedescription.sc deleted file mode 100644 index 5e39b97fb..000000000 --- a/e107_files/shortcode/sitedescription.sc +++ /dev/null @@ -1 +0,0 @@ -return SITEDESCRIPTION.(defined("THEME_DESCRIPTION") && $pref['displaythemeinfo'] ? THEME_DESCRIPTION : ""); diff --git a/e107_files/shortcode/sitedisclaimer.sc b/e107_files/shortcode/sitedisclaimer.sc deleted file mode 100644 index 3702ab35b..000000000 --- a/e107_files/shortcode/sitedisclaimer.sc +++ /dev/null @@ -1,3 +0,0 @@ -global $tp; -$ret = $tp->toHtml(SITEDISCLAIMER,TRUE,"constants defs"); -return $ret; \ No newline at end of file diff --git a/e107_files/shortcode/sitename.sc b/e107_files/shortcode/sitename.sc deleted file mode 100644 index 4865fc7af..000000000 --- a/e107_files/shortcode/sitename.sc +++ /dev/null @@ -1,2 +0,0 @@ -return ($parm == "link") ? "".SITENAME."" : SITENAME; - diff --git a/e107_files/shortcode/sitetag.sc b/e107_files/shortcode/sitetag.sc deleted file mode 100644 index 050d8a898..000000000 --- a/e107_files/shortcode/sitetag.sc +++ /dev/null @@ -1 +0,0 @@ -return SITETAG; \ No newline at end of file diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index cec6e7298..727af4fc2 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -9,9 +9,9 @@ * Text processing and parsing functions * * $Source: /cvs_backup/e107_0.8/e107_handlers/e_parse_class.php,v $ -* $Revision: 1.48 $ -* $Date: 2009-01-03 22:32:54 $ -* $Author: e107steved $ +* $Revision: 1.49 $ +* $Date: 2009-01-08 21:47:44 $ +* $Author: mcfly_e107 $ * */ if (!defined('e107_INIT')) { exit; } @@ -107,10 +107,10 @@ class e_parse // Individual modifiers change the current context var $e_Modifiers = array( - 'emotes_off' => array('emotes_on' => FALSE), - 'emotes_on' => array('emotes_on' => TRUE), - 'no_hook' => array('hook' => FALSE), - 'do_hook' => array('hook' => TRUE), + 'emotes_off' => array('emotes_on' => FALSE), + 'emotes_on' => array('emotes_on' => TRUE), + 'no_hook' => array('hook' => FALSE), + 'do_hook' => array('hook' => TRUE), 'scripts_off' => array('scripts' => FALSE), // New for 0.8 'scripts_on' => array('scripts' => TRUE), // New for 0.8 'no_make_clickable' => array('link_click' => FALSE), @@ -131,7 +131,7 @@ class e_parse 'defs_off' => array('defs' => FALSE), // Decode constant if exists 'defs_on' => array('defs' => TRUE), - 'dobreak' => array('nobreak' => TRUE), + 'dobreak' => array('nobreak' => TRUE), 'nobreak' => array('nobreak' => FALSE), 'lb_nl' => array('retain_nl' => TRUE), // Line break using \n 'lb_br' => array('retain_nl' => FALSE), // Line break using
@@ -270,12 +270,16 @@ class e_parse // Initialise the shortcode handler - has to be done when $prefs valid, so can't be done in constructor ATM - function sch_load() + function sch_load($noCore=false) { if (!is_object($this->e_sc)) { require_once(e_HANDLER."shortcode_handler.php"); $this->e_sc = new e_shortcode; + if(!$noCore) + { + $this->e_sc->loadCoreShortcodes(); + } } } @@ -291,16 +295,16 @@ class e_parse * $mod: the 'no_html' and 'no_php' modifiers blanket prevent html and php posting regardless of posting permissions. (used in logging) */ global $pref; - if (is_array($data)) + if (is_array($data)) { - foreach ($data as $key => $var) + foreach ($data as $key => $var) { $ret[$key] = $this -> toDB($var, $nostrip, $no_encode, $mod, $original_author); } - } - else + } + else { - if (MAGIC_QUOTES_GPC == true && $nostrip == false) + if (MAGIC_QUOTES_GPC == true && $nostrip == false) { $data = stripslashes($data); } @@ -317,8 +321,8 @@ class e_parse $search = array('$', '"', "'", '\\', ' toDB($text, false, false, $mod, $original_author); return $this -> toHTML($text, true, $extra); } - function parseTemplate($text, $parseSCFiles = TRUE, $extraCodes = "") + function parseTemplate($text, $parseSCFiles = TRUE, $extraCodes = "") { $this->sch_load(); return $this->e_sc->parseCodes($text, $parseSCFiles, $extraCodes); @@ -385,19 +389,19 @@ class e_parse if (!ctype_digit($width)) return $str; // Don't wrap if non-numeric width if ($width < 6) return $str; // Trap stupid wrap counts, as well - + // Transform protected element lists into arrays $nobreak = explode(" ", strtolower($nobreak)); - + // Variable setup $intag = false; $innbk = array(); $drain = ""; - + // List of characters it is "safe" to insert line-breaks at // It is not necessary to add < and > as they are automatically implied $lbrks = "/?!%)-}]\\\"':;&"; - + // Is $str a UTF8 string? if ($utf || strtolower(CHARSET) == 'utf-8') { // 0x1680, 0x180e, 0x2000-0x200a, 0x2028, 0x205f, 0x3000 are 'non-ASCII' Unicode UCS-4 codepoints - see http://www.unicode.org/Public/UNIDATA/UnicodeData.txt @@ -419,8 +423,8 @@ class e_parse $utf8 = ''; $whiteSpace = '#(\s+)#'; // For non-utf-8, can use a simple match string } - - + + // Start of the serious stuff - split into HTML tags and text between $content = preg_split('#(<.*?>)#mis', $str, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); foreach($content as $value) @@ -435,7 +439,7 @@ class e_parse if ($lvalue[0] != "/") { // Collect the tag name preg_match("/^(\w*?)(\s|$)/", $lvalue, $t); - + // If this is a protected element, activate the associated protection flag if (in_array($t[1], $nobreak)) array_unshift($innbk, $t[1]); } @@ -549,7 +553,7 @@ class e_parse $drain .= $value; } // Return contents of the drain - return $drain; + return $drain; } @@ -846,7 +850,7 @@ class e_parse if ($proc_funcs) { // Do the 'normal' processing - in principle, as previously - but think about the order. - + // Split out and ignore any scripts and style blocks. With just two choices we can match the closing tag in the regex $subcon = preg_split('#((?:]+>.*?|tyle[^>]+>.*?))#mis', $full_text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); foreach ($subcon as $sub_blk) @@ -866,18 +870,18 @@ class e_parse else { // Do 'normal' processing on a chunk - - + + // Could put tag stripping in here - + /* // Line break compression - filter white space after HTML tags if (!$opts['nobreak']) { $sub_blk = preg_replace("#>\s*[\r]*\n[\r]*#", ">", $sub_blk); } -*/ - +*/ + // Link substitution // Convert URL's to clickable links, unless modifiers or prefs override if ($opts['link_click']) @@ -904,8 +908,8 @@ class e_parse $sub_blk = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1".LAN_EMAIL_SUBS."", $sub_blk); } } - - + + // Convert emoticons to graphical icons, if enabled if ($opts['emotes']) { @@ -924,9 +928,9 @@ class e_parse { $sub_blk = preg_replace("#[\r]*\n[\r]*#", E_NL, $sub_blk); } - - - + + + // Entity conversion // Restore entity form of quotes and such to single characters, except for text destined for tag attributes or JS. if ($opts['value']) @@ -970,9 +974,9 @@ class e_parse { $sub_blk = $this->replaceConstants($sub_blk, ($opts['constants'] == 'abs' ? 'full' : '')); } - - - + + + // profanity filter if ($pref['profanity_filter']) { @@ -983,15 +987,15 @@ class e_parse } $sub_blk = $this->e_pf->filterProfanities($sub_blk); } - - + + // Shortcodes // Optional short-code conversion if ($opts['parse_sc']) { $sub_blk = $this->parseTemplate($sub_blk, TRUE); } - + //Run any hooked in parsers @@ -1010,7 +1014,7 @@ class e_parse $sub_blk = $this->e_hook[$hook]->$hook($sub_blk,$opts['context']); } } - + if(isset($pref['e_tohtml_list']) && is_array($pref['e_tohtml_list'])) { foreach($pref['e_tohtml_list'] as $hook) @@ -1033,8 +1037,8 @@ class e_parse $sub_blk = $this -> textclean($sub_blk, $wrap); } - - + + // Search highlighting if ($opts['emotes']) // Why?? { @@ -1043,7 +1047,7 @@ class e_parse $sub_blk = $this -> e_highlight($sub_blk, $this -> e_query); } } - + $nl_replace = '
'; // Default replaces all \n with
for HTML display if ($opts['nobreak']) @@ -1056,7 +1060,7 @@ class e_parse } $sub_blk = str_replace(E_NL, $nl_replace, $sub_blk); - + $ret_parser .= $sub_blk; } // End of 'normal' processing for a block of text @@ -1073,7 +1077,7 @@ class e_parse - function toAttribute($text) + function toAttribute($text) { $text = str_replace("&","&",$text); // URLs posted without HTML access may have an & in them. $text = htmlspecialchars($text, ENT_QUOTES, CHARSET); // Xhtml compliance. @@ -1081,8 +1085,8 @@ class e_parse { $text = $this->replaceConstants($text); return $text; - } - else + } + else { return ''; } @@ -1090,7 +1094,7 @@ class e_parse // Convert text blocks which are to be embedded within JS - function toJS($stringarray) + function toJS($stringarray) { $search = array("\r\n","\r","
","'"); $replace = array("\\n","","\\n","\'"); @@ -1169,13 +1173,13 @@ class e_parse SITEURL.$THEMES_DIRECTORY, SITEURL.$DOWNLOADS_DIRECTORY); $search = array("{e_BASE}","{e_IMAGE_ABS}","{e_THEME_ABS}","{e_IMAGE}","{e_PLUGIN}","{e_FILE}","{e_THEME}","{e_DOWNLOAD}"); - if (ADMIN) + if (ADMIN) { $replace_relative[] = $ADMIN_DIRECTORY; $replace_absolute[] = SITEURL.$ADMIN_DIRECTORY; $search[] = "{e_ADMIN}"; } - if ($all) + if ($all) { if (USER) { // Can only replace with valid number for logged in users @@ -1249,12 +1253,12 @@ class e_parse } - function e_highlight($text, $match) + function e_highlight($text, $match) { preg_match_all("#<[^>]+>#", $text, $tags); $text = preg_replace("#<[^>]+>#", "<|>", $text); $text = preg_replace("#(\b".$match."\b)#i", "\\1", $text); - foreach ($tags[0] as $tag) + foreach ($tags[0] as $tag) { $text = preg_replace("#<\|>#", $tag, $text, 1); } diff --git a/e107_handlers/shortcode_handler.php b/e107_handlers/shortcode_handler.php index a7e25f9c6..1b31de05e 100644 --- a/e107_handlers/shortcode_handler.php +++ b/e107_handlers/shortcode_handler.php @@ -12,8 +12,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_handlers/shortcode_handler.php,v $ -| $Revision: 1.17 $ -| $Date: 2009-01-08 20:16:47 $ +| $Revision: 1.18 $ +| $Date: 2009-01-08 21:47:44 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -56,7 +56,7 @@ class e_shortcode var $registered_codes = array(); // Shortcodes added by plugins var $scClasses = array(); // Batch shortcode classes - function e_shortcode() + function e_shortcode($noload=false) { global $pref, $register_sc; @@ -97,6 +97,16 @@ class e_shortcode } } } + + } + + function loadCoreShortcodes() + { + $coreBatchList = array('siteinfo_shortcodes.php'); + foreach($coreBatchList as $cb) + { + include_once(e_FILE.'shortcode/batch/'.$cb); + } } function isRegistered($code)