Exemple #1
0
 /**
  *		Callback looks up and substitutes a shortcode
  */
 function doCode($matches)
 {
     // print_a($matches);
     if (in_array($matches[0], $this->ignoreCodes)) {
         return $matches[0];
     }
     // XXX remove all globals, $sc_style removed
     global $pref, $e107cache, $menu_pref, $parm, $sql;
     $parmArray = false;
     if ($this->eVars) {
         if ($this->eVars->isVar($matches[1])) {
             return $this->eVars->{$matches}[1];
         }
     }
     if (strpos($matches[1], E_NL) !== false) {
         return $matches[0];
     }
     if (preg_match('/^([A-Z_]*):(.*)/', $matches[1], $newMatch)) {
         $code = $newMatch[1];
         $parmStr = trim($newMatch[2]);
         $debugParm = $parmStr;
         parse_str($parmStr, $parm);
         $parmArray = true;
     } elseif (strpos($matches[1], '=')) {
         list($code, $parm) = explode('=', $matches[1], 2);
     } else {
         $code = $matches[1];
         $parm = '';
     }
     //look for the $sc_mode
     if (strpos($code, '|')) {
         list($code, $sc_mode) = explode("|", $code, 2);
         $code = trim($code);
         $sc_mode = trim($sc_mode);
     } else {
         $sc_mode = '';
     }
     if ($parmArray == false) {
         $parm = trim($parm);
         $parm = str_replace(array('[[', ']]'), array('{', '}'), $parm);
     }
     if (E107_DBG_BBSC || E107_DBG_SC || E107_DBG_TIMEDETAILS) {
         $sql->db_Mark_Time("SC {$code}");
     }
     if (E107_DBG_SC) {
         $dbg = "<strong>";
         $dbg .= '{';
         $dbg .= $code;
         $dbg .= $parm ? '=' . htmlentities($parm) : "";
         $dbg .= '}';
         $dbg .= "</strong>";
         //	echo $dbg;
         return $dbg;
         //	trigger_error('starting shortcode {'.$code.'}', E_USER_ERROR);    // no longer useful - use ?[debug=bbsc]
     }
     $scCode = '';
     $scFile = '';
     $_path = '';
     $ret = '';
     $_method = 'sc_' . strtolower($code);
     if (is_object($this->addedCodes) && method_exists($this->addedCodes, $_method)) {
         $ret = $this->addedCodes->{$_method}($parm, $sc_mode);
         if (E107_DBG_BBSC || E107_DBG_SC || E107_DBG_TIMEDETAILS) {
             $_class = get_class($this->addedCodes);
             // "(class loaded)"; // debug.
             $_function = $_method;
             $_path = "(already loaded)";
         }
     } elseif (is_array($this->addedCodes) && array_key_exists($code, $this->addedCodes)) {
         $scCode = $this->addedCodes[$code];
         //	$_path = print_a($this->backTrace,true);
         //XXX $_path = print_a($this,true);
     } elseif (array_key_exists($code, $this->scList)) {
         $scCode = $this->scList[$code];
         $_path = "(loaded earlier)";
         // debug.
     } else {
         //.sc file not yet loaded, or shortcode is new function type
         if ($this->parseSCFiles == true) {
             if (array_key_exists($code, $this->registered_codes)) {
                 //shortcode is registered, let's proceed.
                 if (isset($this->registered_codes[$code]['perms'])) {
                     if (!check_class($this->registered_codes[$code]['perms'])) {
                         return '';
                     }
                 }
                 switch ($this->registered_codes[$code]['type']) {
                     case 'class':
                         //It is batch shortcode.  Load the class and call the method
                         $_class = $this->registered_codes[$code]['class'];
                         $_method = 'sc_' . strtolower($code);
                         if (!$this->isScClass($_class)) {
                             if (!class_exists($_class) && $this->registered_codes[$code]['path']) {
                                 include_once $this->registered_codes[$code]['path'];
                             }
                             $this->initShortcodeClass($_class, false);
                             if (!$this->isScClass($_class)) {
                                 return '';
                             }
                             // egister passed eVars object on init - call it manually?
                             // $this->callScFunc($_class, 'setVars', $this->var);
                         }
                         // FIXME - register passed eVars object - BAD solution - called on EVERY sc method call
                         // XXX - removal candidate - I really think it should be done manually (outside the parser)
                         // via e107::getScBatch(name)->setParserVars($eVars);
                         // $this->callScFunc($_class, 'setParserVars', $this->eVars);
                         $wrapper = $this->callScFunc($_class, 'wrapper', null);
                         $ret = $this->callScFuncA($_class, $_method, array($parm, $sc_mode));
                         /*if (method_exists($this->scClasses[$_class], $_method))
                         		{
                         			$ret = $this->scClasses[$_class]->$_method($parm, $sc_mode);
                         		}
                         		else
                         		{
                         			echo $_class.'::'.$_method.' NOT FOUND!<br />';
                         		}*/
                         break;
                     case 'override':
                     case 'func':
                     case 'plugin':
                         //It is a function, so include the file and call the function
                         $_function = $this->registered_codes[$code]['function'];
                         if (!function_exists($_function) && $this->registered_codes[$code]['path']) {
                             include_once $this->registered_codes[$code]['path'] . strtolower($code) . '.php';
                         }
                         if (function_exists($_function)) {
                             $ret = call_user_func($_function, $parm, $sc_mode);
                         }
                         break;
                     case 'plugin_legacy':
                         $scFile = e_PLUGIN . strtolower($this->registered_codes[$code]['path']) . '/' . strtolower($code) . '.sc';
                         break;
                         // case 'override':
                         // $scFile = e_CORE.'override/shortcodes/'.strtolower($code).'.sc';
                         // break;
                     // case 'override':
                     // $scFile = e_CORE.'override/shortcodes/'.strtolower($code).'.sc';
                     // break;
                     case 'theme':
                         $scFile = THEME . strtolower($code) . '.sc';
                         break;
                 }
             } else {
                 // Code is not registered, let's look for .sc or .php file
                 // .php file takes precedence over .sc file
                 if (is_readable(e_CORE . 'shortcodes/single/' . strtolower($code) . '.php')) {
                     $_function = strtolower($code) . '_shortcode';
                     $_class = strtolower($code);
                     $_path = e_CORE . 'shortcodes/single/' . strtolower($code) . '.php';
                     include_once e_CORE . 'shortcodes/single/' . strtolower($code) . '.php';
                     if (class_exists($_class, false)) {
                         // SecretR - fix array(parm, sc_mode) causing parm to become an array, see issue 424
                         $ret = call_user_func(array($_class, $_function), $parm, $sc_mode);
                     } elseif (function_exists($_function)) {
                         $ret = call_user_func($_function, $parm, $sc_mode);
                     }
                 } else {
                     $scFile = e_CORE . 'shortcodes/single/' . strtolower($code) . '.sc';
                     $_path = $scFile;
                 }
             }
             if ($scFile && file_exists($scFile)) {
                 $scCode = file_get_contents($scFile);
                 $this->scList[$code] = $scCode;
                 $_path = $scFile;
             } else {
                 //	$ret = 'Missing!';
                 $_path .= " MISSING!";
             }
         }
         if (!isset($scCode)) {
             if (E107_DBG_BBSC) {
                 trigger_error('shortcode not found:{' . $code . '}', E_USER_ERROR);
             }
             return $matches[0];
         }
         if (E107_DBG_SC && $scFile) {
             //	echo (isset($scFile)) ? "<br />sc_file= ".str_replace(e_CORE.'shortcodes/single/', '', $scFile).'<br />' : '';
             //	echo "<br />sc= <b>$code</b>";
         }
     }
     if ($scCode) {
         $ret = @eval($scCode);
         if ($ret === false && E107_DEBUG_LEVEL > 0) {
             $string = print_a($scCode, true);
             e107::getMessage()->addDebug('Could not parse Shortcode ' . $scFile . ' :: {' . $code . '} ' . $string);
         }
     }
     if (isset($ret) && ($ret != '' || is_numeric($ret))) {
         // Wrapper support - see contact_template.php
         if (isset($this->wrappers[$code]) && !empty($this->wrappers[$code])) {
             list($pre, $post) = explode("{---}", $this->wrappers[$code], 2);
             $ret = $pre . $ret . $post;
         } else {
             //if $sc_mode exists, we need it to parse $sc_style
             if ($sc_mode) {
                 $code = $code . '|' . $sc_mode;
             }
             if (is_array($this->sc_style) && array_key_exists($code, $this->sc_style)) {
                 $pre = $post = '';
                 // old way - pre/post keys
                 if (is_array($this->sc_style[$code])) {
                     if (isset($this->sc_style[$code]['pre'])) {
                         $pre = $this->sc_style[$code]['pre'];
                     }
                     if (isset($this->sc_style[$code]['post'])) {
                         $post = $this->sc_style[$code]['post'];
                     }
                 } else {
                     list($pre, $post) = explode("{---}", $this->sc_style[$code], 2);
                 }
                 $ret = $pre . $ret . $post;
             }
         }
     }
     if (E107_DBG_SC || E107_DBG_TIMEDETAILS) {
         $sql->db_Mark_Time("(After SC {$code})");
     }
     if (E107_DBG_BBSC || E107_DBG_SC || E107_DBG_TIMEDETAILS) {
         global $db_debug;
         $other = array();
         if ($_class) {
             $other['class'] = $_class;
         }
         if (vartrue($_function)) {
             $other['function'] = $_function;
         }
         if (vartrue($_path)) {
             $other['path'] = str_replace('../', '', $_path);
         }
         if ($this->debug_legacy) {
             $other = $this->debug_legacy;
         }
         $info = isset($this->registered_codes[$code]) ? print_a($this->registered_codes[$code], true) : print_a($other, true);
         $tmp = isset($debugParm) ? $debugParm : $parm;
         $db_debug->logCode(2, $code, $tmp, $info);
     }
     return isset($ret) ? $ret : '';
 }
Exemple #2
0
 /**
  *		Callback looks up and substitutes a shortcode
  */
 function doCode($matches)
 {
     global $pref, $e107cache, $menu_pref, $sc_style, $parm, $sql;
     if ($this->eVars) {
         if ($this->eVars->isVar($matches[1])) {
             return $this->eVars->{$matches}[1];
         }
     }
     if (strpos($matches[1], E_NL) !== false) {
         return $matches[0];
     }
     if (strpos($matches[1], '=')) {
         list($code, $parm) = explode('=', $matches[1], 2);
     } else {
         $code = $matches[1];
         $parm = '';
     }
     //look for the $sc_mode
     if (strpos($code, '|')) {
         list($code, $sc_mode) = explode("|", $code, 2);
         $code = trim($code);
         $sc_mode = trim($sc_mode);
     } else {
         $sc_mode = '';
     }
     $parm = trim($parm);
     $parm = str_replace(array('[[', ']]'), array('{', '}'), $parm);
     if (E107_DBG_BBSC || E107_DBG_SC || E107_DBG_TIMEDETAILS) {
         global $db_debug;
         $sql->db_Mark_Time("SC {$code}");
         $db_debug->logCode(2, $code, $parm, "");
     }
     if (E107_DBG_SC) {
         echo "<strong>";
         echo '{';
         echo $code;
         echo $parm ? '=' . htmlentities($parm) : "";
         echo '}';
         echo "</strong>";
         //	trigger_error('starting shortcode {'.$code.'}', E_USER_ERROR);    // no longer useful - use ?[debug=bbsc]
     }
     $scCode = '';
     $scFile = '';
     $ret = '';
     $_method = 'sc_' . strtolower($code);
     if (is_object($this->addedCodes) && method_exists($this->addedCodes, $_method)) {
         //It is class-based batch shortcode.  Class already loaded; call the method
         $ret = $this->addedCodes->{$_method}($parm, $sc_mode);
     } elseif (is_array($this->addedCodes) && array_key_exists($code, $this->addedCodes)) {
         // Its array-based shortcode. Load the code for evaluation later.
         $scCode = $this->addedCodes[$code];
     } elseif (array_key_exists($code, $this->scList)) {
         $scCode = $this->scList[$code];
     } else {
         //.sc file not yet loaded, or shortcode is new function type
         if ($this->parseSCFiles == true) {
             if (array_key_exists($code, $this->registered_codes)) {
                 //shortcode is registered, let's proceed.
                 if (isset($this->registered_codes[$code]['perms'])) {
                     if (!check_class($this->registered_codes[$code]['perms'])) {
                         return '';
                     }
                 }
                 switch ($this->registered_codes[$code]['type']) {
                     case 'class':
                         //It is batch shortcode.  Load the class and call the method
                         $_class = $this->registered_codes[$code]['class'];
                         $_method = 'sc_' . strtolower($code);
                         if (!$this->isScClass($_class)) {
                             if (!class_exists($_class) && $this->registered_codes[$code]['path']) {
                                 include_once $this->registered_codes[$code]['path'];
                             }
                             $this->initShortcodeClass($_class, false);
                             if (!$this->isScClass($_class)) {
                                 return '';
                             }
                             // egister passed eVars object on init - call it manually?
                             // $this->callScFunc($_class, 'setVars', $this->var);
                         }
                         // FIXME - register passed eVars object - BAD solution - called on EVERY sc method call
                         // XXX - removal candidate - I really think it should be done manually (outside the parser)
                         // via e107::getScBatch(name)->setParserVars($eVars);
                         // $this->callScFunc($_class, 'setParserVars', $this->eVars);
                         $ret = $this->callScFuncA($_class, $_method, array($parm, $sc_mode));
                         /*if (method_exists($this->scClasses[$_class], $_method))
                         		{
                         			$ret = $this->scClasses[$_class]->$_method($parm, $sc_mode);
                         		}
                         		else
                         		{
                         			echo $_class.'::'.$_method.' NOT FOUND!<br />';
                         		}*/
                         break;
                     case 'func':
                         //It is a function, so include the file and call the function
                         $_function = $this->registered_codes[$code]['function'];
                         if ($this->registered_codes[$code]['path']) {
                             include_once $this->registered_codes[$code]['path'] . strtolower($code) . '.php';
                         }
                         if (function_exists($_function)) {
                             $ret = call_user_func($_function, $parm, $sc_mode);
                         }
                         break;
                     case 'plugin':
                         $scFile = e_PLUGIN . strtolower($this->registered_codes[$code]['path']) . '/' . strtolower($code) . '.sc';
                         break;
                     case 'override':
                         $scFile = e_CORE . 'override/shortcodes/' . strtolower($code) . '.sc';
                         break;
                     case 'theme':
                         $scFile = THEME . strtolower($code) . '.sc';
                         break;
                 }
             } else {
                 // Code is not registered, let's look for .sc or .php file
                 // .php file takes precedence over .sc file
                 if (is_readable(e_CORE . 'shortcodes/single/' . strtolower($code) . '.php')) {
                     $_function = strtolower($code) . '_shortcode';
                     $_class = strtolower($code);
                     include_once e_CORE . 'shortcodes/single/' . strtolower($code) . '.php';
                     if (class_exists($_class, false)) {
                         $ret = call_user_func(array($_class, $_function), $parm);
                     } elseif (function_exists($_function)) {
                         $ret = call_user_func($_function, $parm);
                     }
                 } else {
                     $scFile = e_CORE . 'shortcodes/single/' . strtolower($code) . '.sc';
                 }
             }
             if ($scFile && file_exists($scFile)) {
                 $scCode = file_get_contents($scFile);
                 $this->scList[$code] = $scCode;
             }
         }
         if (!isset($scCode)) {
             if (E107_DBG_BBSC) {
                 trigger_error('shortcode not found:{' . $code . '}', E_USER_ERROR);
             }
             return $matches[0];
         }
         if (E107_DBG_SC && $scFile) {
             //	echo (isset($scFile)) ? "<br />sc_file= ".str_replace(e_CORE.'shortcodes/single/', '', $scFile).'<br />' : '';
             //	echo "<br />sc= <b>$code</b>";
         }
     }
     if ($scCode) {
         $ret = eval($scCode);
     }
     if (isset($ret) && ($ret != '' || is_numeric($ret))) {
         //if $sc_mode exists, we need it to parse $sc_style
         if ($sc_mode) {
             $code = $code . '|' . $sc_mode;
         }
         if (isset($sc_style) && is_array($sc_style) && array_key_exists($code, $sc_style)) {
             if (isset($sc_style[$code]['pre'])) {
                 $ret = $sc_style[$code]['pre'] . $ret;
             }
             if (isset($sc_style[$code]['post'])) {
                 $ret = $ret . $sc_style[$code]['post'];
             }
         }
     }
     if (E107_DBG_SC || E107_DBG_TIMEDETAILS) {
         $sql->db_Mark_Time("(After SC {$code})");
     }
     return isset($ret) ? $ret : '';
 }