Example #1
0
 static function renderTag($input, $params, $parser, $frame)
 {
     global $extr;
     try {
         $darr = array_diff_key($params, self::$allowedAttr);
         if (!empty($darr)) {
             throw new Exception('Engine.php: unknown attribute(s) "' . implode('", "', array_keys($darr)) . '"');
         }
         if (!array_key_exists('output', $params)) {
             $params['output'] = 'text';
         }
         if (!in_array($params['output'], Engine::$allowedOutput)) {
             throw new Exception('Engine.php: unknown value "' . $params['output'] . '" for attribute "output"');
         }
         $wiki = array_key_exists('wiki', $params) || strcmp($params['output'], 'wiki') == 0;
         $sha1 = $extr->hashtxt($extr->R_DTS . $input . serialize($params));
         $name = array_key_exists('name', $params) ? $params['name'] : (array_key_exists('label', $params) ? $params['label'] : $sha1);
         $direct = !array_key_exists('iframe', $params);
         if ($wiki && (!$direct || array_key_exists('echo', $params))) {
             throw new Exception('Engine.php: You can not use output="wiki" and use "echo" or "iframe"');
         }
         $params['geshi'] = $extr->options['usegeshi'] && array_key_exists('echo', $params) && strcmp($params['echo'], 'nogeshi');
         $workhorse = array_key_exists('engine', $params) ? Engine::engineIndex($params['engine']) : 0;
         Engine::check($extr->engine[$workhorse]->banned, $input);
         $params['engine'] = $extr->engine[$workhorse]->name;
         $params['sha1'] = $sha1;
         $params['input'] = trim($input);
         if (array_key_exists('name', $params) && !$direct) {
             $params['name'] = rawurlencode($parser->getTitle() . '_' . $params['name']);
             file_put_contents(R_DIR . $params['name'] . '.param', serialize($params));
         }
         $fn = $extr->engine[$workhorse]->render($params);
         if (array_key_exists('iframe', $params)) {
             $iframe = Engine::makeStyle($params['iframe'], array('width' => '100%', 'height' => '250px'));
             $ret = '<iframe name="' . $name . '" style="' . $iframe . '" src="' . $extr->engine[$workhorse]->url($fn) . '">Sorry, your browser does not support &lt;iframe...&gt;... &lt;/iframe&gt; !</iframe>';
         } else {
             $ret = file_get_contents($fn);
         }
         if ($wiki) {
             $ret = $parser->recursiveTagParse($ret, $frame);
         }
         $category = array_key_exists('category', $params) ? $params['category'] : $extr->engine[$workhorse]->category;
         if (!empty($category)) {
             $ret .= $parser->recursiveTagParse(sprintf('[[Category:%s]]', $category), $frame);
         }
         if ($extr->engine[$workhorse]->security > 0) {
             Engine::checkJavaScriptAndPHP($extr->engine[$workhorse], $ret);
         }
         if ($params['geshi']) {
             $ret = Engine::highlightSyntax($extr->engine[$workhorse]->lang, $ret, $parser, $frame);
         }
         return $ret;
     } catch (Exception $e) {
         $extr->exception_log($e);
         return '<pre style="color:red">' . htmlentities($e->getMessage()) . '</pre>in<pre>' . htmlentities($input) . '</pre>';
     }
 }