/** * Instantiate output system */ public static function instance() { if (self::$instance === false) { self::$instance = new OutputSystem(); } return self::$instance; }
/** * Try to insert the includes for fancybox in the <head> section of the HTML * that is to be outputted to the browser. Inserts Jquery if not already * included. (This is just the default "thickboxIncludeCallback" function * adapted to Fancybox.) * * @param string $html */ function fancyboxIncludeCallback(&$html) { global $PIVOTX; // If we've set the hidden config option for 'never_jquery', just return without doing anything. if ($PIVOTX['config']->get('never_jquery') == 1) { debug("JQuery is disabled by the 'never_jquery' config option. FancyBox won't work."); return; } OutputSystem::instance()->enableCode('jquery'); // Is config option 'fancybox_profile' added and has an expected value? $fbprof = $PIVOTX['config']->get('fancybox_profile'); // default profile (downwards compatible) // for parms explanation -- see http://www.fancybox.net/api $fbparms = "\t\tjQuery(\"a.fancybox\").fancybox({ padding: 2, 'titlePosition': 'over', 'overlayShow': true, 'overlayOpacity': 0.25, 'opacity': true, 'speedIn': 100, 'speedOut': 100, 'changeSpeed': 100, 'showCloseButton': true });\n"; if ($fbprof == '') { // profile will be default = nr. 1 } elseif ($fbprof == 1) { // is the default } elseif ($fbprof == 2) { $fbparms = "\t\tjQuery(\"a.fancybox\").fancybox({ "; // title outside / elastic transition / diff.speed / cyclic // -- although FB specifies to use titlePosition outside their js only uses float for outside title build-up $fbparms .= "padding: 2, "; $fbparms .= "'titlePosition': 'float', "; $fbparms .= "'transitionIn': 'elastic', 'transitionOut': 'elastic', "; $fbparms .= "'easingIn': 'easeOutBack', 'easingOut': 'easeInBack', "; $fbparms .= "'overlayShow': true, 'overlayOpacity': 0.3, "; $fbparms .= "'opacity': true, 'speedIn': 300, 'speedOut': 300, 'changeSpeed': 300, "; $fbparms .= "'showCloseButton': true, 'cyclic': true "; $fbparms .= "});\n"; } elseif ($fbprof == 3) { $fbparms = "\t\tjQuery(\"a.fancybox\").fancybox({ "; // no padding / no close button / Image 1/n before title (over) / cyclic $fbparms .= "padding: 0, "; $fbparms .= "'titlePosition': 'over', "; $fbparms .= "'transitionIn': 'fade', 'transitionOut': 'fade', "; $fbparms .= "'overlayShow': true, 'overlayOpacity': 0.25, "; $fbparms .= "'opacity': true, 'speedIn': 100, 'speedOut': 100, 'changeSpeed': 100, "; $fbparms .= "'showCloseButton': false, 'cyclic': true, "; $fbparms .= "'titleFormat': function(title, currentArray, currentIndex, currentOpts) { return '<span id=\"fancybox-title-over\">"; $fbparms .= __("Image"); $fbparms .= " ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' ' + title : '') + '</span>';}"; $fbparms .= "});\n"; } elseif ($fbprof == 4) { $fbparms = "\t\tjQuery(\"a.fancybox\").fancybox({ "; // default profile according to fancybox.net (changed titlePosition outside to float) $fbparms .= "padding: 10, margin: 20,"; $fbparms .= "'titlePosition': 'float', "; $fbparms .= "'transitionIn': 'fade', 'transitionOut': 'fade', "; $fbparms .= "'overlayShow': true, 'overlayOpacity': 0.3, "; $fbparms .= "'opacity': false, 'speedIn': 300, 'speedOut': 300, 'changeSpeed': 300, "; $fbparms .= "'showCloseButton': true, 'cyclic': false, "; $fbparms .= "'titleFormat': null"; $fbparms .= "});\n"; } else { debug("Config option fancybox_profile has an incorrect value, profile set to default."); } // standard fancybox youtube profile $fbytube = "\t\tjQuery(\"a.fancytube\").fancybox({ "; $fbytube .= "padding: 0, autoScale: false, centerOnScroll: true, "; $fbytube .= "'transitionIn': 'none', 'transitionOut': 'none', "; $fbytube .= "'overlayShow': true, 'overlayOpacity': 0.7, "; $fbytube .= "'hideOnContentClick': true, "; // doesn't work for youtube (yet?) $fbytube .= "'titlePosition': 'outside', "; $fbytube .= "'showCloseButton': false "; $fbytube .= "});\n"; // standard fancybox text profile $fbtext = "\t\tjQuery(\"a.fancytext\").fancybox({ "; $fbtext .= "padding: 5, autoScale: true, centerOnScroll: true, "; $fbtext .= "'transitionIn': 'none', 'transitionOut': 'none', "; $fbtext .= "'overlayShow': true, 'overlayOpacity': 0.7, "; $fbtext .= "'titlePosition': 'outside', "; $fbtext .= "'showCloseButton': true, 'cyclic': false "; $fbtext .= "});\n"; // standard fancybox iframe profile $fbifram = "\t\tjQuery(\"a.fancyframe\").fancybox({ "; $fbifram .= "padding: 3, autoScale: false, centerOnScroll: true, "; $fbifram .= "'transitionIn': 'none', 'transitionOut': 'none', "; $fbifram .= "'overlayShow': true, 'overlayOpacity': 0.7, "; $fbifram .= "'width': '75%', 'height': '75%', "; $fbifram .= "'type': 'iframe', "; $fbifram .= "'titlePosition': 'outside', "; $fbifram .= "'showCloseButton': true "; $fbifram .= "});\n"; // standard fancybox swf/flash profile $fbflash = "\t\tjQuery(\"a.fancyflash\").fancybox({ "; $fbflash .= "padding: 0, autoScale: false, "; $fbflash .= "'transitionIn': 'none', 'transitionOut': 'none', "; $fbflash .= "'showCloseButton': true "; $fbflash .= "});\n"; // insert html comment within this script to fool markup validation $customjs = "\n<!--\n"; $customjs .= "\tjQuery(document).ready(function() {\n"; $customjs .= $fbparms; $customjs .= $fbytube; $customjs .= $fbtext; $customjs .= $fbifram; $customjs .= $fbflash; $customjs .= "\t});\n"; // insert html comment within this script to fool markup validation $customjs .= "\t// -->\n"; $path = $PIVOTX['paths']['extensions_url'] . "fancybox/"; OutputSystem::instance()->addCode('fancybox-stylehref', OutputSystem::LOC_HEADEND, 'link', array('href' => $path . 'jquery.fancybox-1.3.4.css', 'media' => 'screen', '_priority' => OutputSystem::PRI_NORMAL + 10)); OutputSystem::instance()->addCode('fancybox-stylehref-ie6', OutputSystem::LOC_HEADEND, 'link', array('href' => $path . 'jquery.fancybox_IE6_-1.3.4.css', 'media' => 'screen', '_ms-expression' => 'if lt IE 7', '_priority' => OutputSystem::PRI_NORMAL + 11)); OutputSystem::instance()->addCode('fancybox-stylehref-ie7', OutputSystem::LOC_HEADEND, 'link', array('href' => $path . 'jquery.fancybox_IE_-1.3.4.css', 'media' => 'screen', '_ms-expression' => 'if IE 7', '_priority' => OutputSystem::PRI_NORMAL + 11)); OutputSystem::instance()->addCode('fancybox-stylehref-ie8', OutputSystem::LOC_HEADEND, 'link', array('href' => $path . 'jquery.fancybox_IE_-1.3.4.css', 'media' => 'screen', '_ms-expression' => 'if IE 8', '_priority' => OutputSystem::PRI_NORMAL + 11)); // easing only needed for elastic transition if ($fbprof == 2) { OutputSystem::instance()->addCode('fancybox-js-easing', OutputSystem::LOC_HEADEND, 'script', array('src' => $path . 'jquery.easing-1.3.js', '_priority' => OutputSystem::PRI_NORMAL + 20)); } // only add mousewheel when fancybox_profile has been set to something if (!$fbprof == '') { OutputSystem::instance()->addCode('fancybox-js-mousewheel', OutputSystem::LOC_HEADEND, 'script', array('src' => $path . 'jquery.mousewheel-3.0.4.js', '_priority' => OutputSystem::PRI_NORMAL + 20)); } OutputSystem::instance()->addCode('fancybox-js-src', OutputSystem::LOC_HEADEND, 'script', array('src' => $path . 'jquery.fancybox-1.3.4.js', '_priority' => OutputSystem::PRI_NORMAL + 21)); OutputSystem::instance()->addCode('fancybox-js', OutputSystem::LOC_HEADEND, 'script', array('_priority' => OutputSystem::PRI_NORMAL + 22), $customjs); }
/** * Fetch a template and optionally rewrite */ public function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false) { $html = parent::fetch($resource_name, $cache_id, $compile_id, $display); if ($this->allow_rewrite) { $os = OutputSystem::instance(); $html = $os->rewriteHtml($html); } return $html; }
/** * Output the compiled HTML to the browser. * * We also takes this as an opportunity to add the 'generated by' meta-tag * to the header, as well as the autodiscovery links for the XML Feeds. * */ function output() { global $build, $PIVOTX, $timetaken; $html = $this->html; // If we don't use caching, we'll need to execute the after_parse hooks // here, and perhaps minify the JS and CSS files. if (!$PIVOTX['config']->get('smarty_cache')) { $PIVOTX['extensions']->executeHook('after_parse', $html); } // If debug is enabled, we add a line that states how long it took to render // the page, how many queries were done (if we're using mysql) and what template // was used. // If debug is enabled and the current user is logged in, we add the debugbar. if ($PIVOTX['config']->get('debug') == 1 && $PIVOTX['session']->isLoggedIn()) { $debugcode = $this->getDebugCode(); $html = str_replace('</body>', $debugcode . '</body>', $html); } // If the site doesn't link back to pivotx.net, we add a 'PivotX feels unloved' // comment to the HTML. if (!preg_match('#href=[\'"](http://(www.)?pivotx.net)#i', $html)) { $unloved = "\n<!-- PivotX feels unloved.. :-( -->\n"; $html = str_replace('</body>', $unloved . '</body>', $html); } if (true) { $os = OutputSystem::instance(); $html = $os->rewriteHtml($html); } // Process a hook, right before we output the HTML to the browser. $PIVOTX['extensions']->executeHook('before_output', $html); // Send HTML and XML templates with the correct mime-type. if (strpos(strtolower($this->maintemplate), ".xml") > 0) { header("content-type:text/xml; charset=utf-8"); } else { header('Content-Type: text/html; charset=utf-8'); } // Before we echo, make sure there's nothing in the buffer already.. ob_end_clean(); // Output the results to the browser.. echo $html; // Process the last hook, after we're done with everything else. $PIVOTX['extensions']->executeHook('after_execution', $dummy); }
/** * Add hashcash to a form * * 1. Disable the form by default * 2. Add <noscript>-warning * 3. Add hidden variable * 4. Add javascript (the actual hashcash) * * @return boolean */ function add_hashcash($page, $form_name = 'anonymous') { $hc = new pivotx_hashcash(); $hcid = $hc->get_current_name(); // 1 & 2 //$page = str_replace('<form', '<noscript><p class="pivotx-message">'.__('Please enable Javascript (and reload this page) to add any comments.').'</p></noscript>'."\n".'<form disabled="disabled" id="submit-'.$hcid.'"',$page); $page = str_replace('<form', '<noscript><p class="pivotx-message">' . __('Please enable Javascript (and reload this page) to add any comments.') . '</p></noscript>' . "\n" . '<form ', $page); $page = str_replace(' type="submit" name="post"', ' type="submit" name="post" id="submit-' . $hcid . '" disabled="disabled"', $page); // 3 $page = str_replace('</form>', '<input type="hidden" id="' . $hcid . '" name="' . $hcid . '" value="" /></form>', $page); // 4 $html = ''; $html .= <<<THEEND <!-- function enableform_{$hcid}() { el = document.getElementById("submit-{$hcid}"); if (el) { el.disabled = ''; } } THEEND; $html .= $hc->get_javascript($form_name, 'enableform_' . $hcid . '();'); $html .= '// -->' . "\n"; $hc->store_key(); OutputSystem::instance()->addCode('hashcash-' . $hcid, OutputSystem::LOC_HEADEND, 'script', array(), $html); // return $page; }
/** * Try to insert the includes for JQuery in the <head> section of the HTML * that is to be outputted to the browser * * @param string $html */ function jqueryIncludeCallback(&$html) { global $PIVOTX; // If we've set the hidden config option for 'never_jquery', just return without doing anything. if ($PIVOTX['config']->get('never_jquery') == 1) { return; } if (!preg_match("#<script [^>]*?/jquery[0-9_\\.-]*\\.(min.js|js)['\"][^>]*?" . ">\\s*</script>#i", $html)) { OutputSystem::instance()->verifyIfEnableCode('jquery', 'verifyJqueryInHtml'); } }
/** * Output a little bit of HTML */ public function render($params) { global $PIVOTX; $pivotx_url = $PIVOTX['paths']['pivotx_url']; $os = OutputSystem::instance(); $os->addCode('jquery_ui', OutputSystem::LOC_HEADEND, 'script', array('_priority' => OutputSystem::PRI_HIGH, ' src' => $PIVOTX['paths']['jquery_ui_url'])); $os->addCode('plupload_browserplus', OutputSystem::LOC_HEADEND, 'script', array('src' => 'http://bp.yahooapis.com/2.4.21/browserplus-min.js')); $os->addCode('plupload_full', OutputSystem::LOC_HEADEND, 'script', array('src' => $pivotx_url . 'includes/js/plupload/plupload.full.js')); if (is_array($params)) { $vars = $params; } else { $vars = array(); } switch ($vars['filters']) { case 'image': $vars['filters'] = array(array('title' => 'Image files', 'extensions' => 'jpeg,jpg,gif,png')); break; case 'document': $vars['filters'] = array(array('title' => 'Document files', 'extensions' => 'doc,docx,rtf,pdf')); break; case 'any': unset($vars['filters']); default: if (!is_array($vars['filters'])) { unset($vars['filters']); } break; } $vars['name'] = 'test-file-upload'; $vars['upload_path'] = getUploadFolderUrl(); $vars = $this->_completeTemplateVars($vars); $os->addTemplate('plupload_render', OutputSystem::LOC_BODYEND, 'inc_plupload_element.tpl', $vars); return ''; }