Exemplo n.º 1
0
/**
 * this function will output the URL to a given compressed and cached js file.
 * NOTE: if you use the util package, it will automatically insert the javascript/ subdir
 * 
 * @param string $pParams[ipackage] package the javascript file is in. this will default to: 'util'. e.g.: wiki
 * @param string $pParams[ifile] subdir and filename of the file you wish to pack and cache. e.g.: libs/jsfile.js
 * @param string $pParams[defer] includes defer='defer'
 * @param object $gBitSmarty 
 * @access public
 * @return URL to cached javascript file
 */
function smarty_function_jspack($pParams, &$gBitSmarty)
{
    // make sure we have a file to pack
    if (empty($pParams['ifile'])) {
        die;
    }
    if (empty($pParams['ipackage'])) {
        $pParams['ipackage'] = 'util';
    }
    // get the full path to the file we want to pack - insert javasscript/ into path when we're getting stuff in util
    $jsfile = constant(strtoupper($pParams['ipackage']) . '_PKG_PATH') . ($pParams['ipackage'] == 'util' ? 'javascript/' : '') . $pParams['ifile'];
    if (is_file($jsfile)) {
        // get a name for the cache file we're going to store
        $cachefile = $pParams['ipackage'] . '_' . str_replace('/', '_', $pParams['ifile']);
        require_once KERNEL_PKG_PATH . 'BitCache.php';
        $bitCache = new BitCache('javascript', TRUE);
        // if the file hasn't been packed and cached yet, we do that now.
        if (!$bitCache->isCached($cachefile, filemtime($jsfile))) {
            /*
             * params of the constructor :
             * $script:       the JavaScript to pack, string.
             * $encoding:     level of encoding, int or string :
             *                0,10,62,95 or 'None', 'Numeric', 'Normal', 'High ASCII'.
             *                default: 62.
             * $fastDecode:   include the fast decoder in the packed result, boolean.
             *                default : true.
             * $specialChars: if you have flagged your private and local variables
             *                in the script, boolean.
             *                default: false.
             */
            require_once UTIL_PKG_PATH . 'javascript/class.JavaScriptPacker.php';
            $packer = new JavaScriptPacker(file_get_contents($jsfile), 'Normal', TRUE, FALSE);
            $bitCache->writeCacheFile($cachefile, $packer->pack());
        }
        $defer = !empty($pParams['defer']) ? " defer='" . $pParams['defer'] . "'" : "";
        return '<script' . $defer . ' type="text/javascript" src="' . $bitCache->getCacheUrl($cachefile) . '"></script>';
    } else {
        return "<!-- " . tra('not a valid file: ') . $pParams['ifile'] . " -->";
    }
}
Exemplo n.º 2
0
/**
 * Smarty {include_js} function plugin
 *
 * Type:     function
 * Name:     include_js
 * Input:
 *        - file      (required) - fully qualified file to a javascript file
 *		  - nopack	  (optional) - do not pack
 */
function smarty_function_include_js($params, &$gBitSmarty)
{
    global $gBitSystem;
    $pack = TRUE;
    foreach ($params as $key => $val) {
        switch ($key) {
            case 'file':
                $file = $val;
                break;
            case 'nopack':
                $pack = FALSE;
            default:
                break;
        }
    }
    if (is_file($file)) {
        // pack it
        if ($pack && $gBitSystem->isFeatureActive('themes_packed_js_css') && shell_exec('which java')) {
            // start up caching engine - pretend we are themes package
            $BitCache = new BitCache('themes', TRUE);
            // get a name for the cache file we're going to store
            $cachefile = md5($file) . '.js';
            // if the file hasn't been packed and cached yet, we do that now.
            if (!$BitCache->isCached($cachefile, filemtime($file))) {
                // pack and cache it
                $cachedata = shell_exec('java -jar ' . UTIL_PKG_PATH . 'yui/yuicompressor-2.4.2.jar --type js ' . $file);
                $BitCache->writeCacheFile($cachefile, $cachedata);
            }
            // update the file path with new path
            $file = $BitCache->getCacheFile($cachefile);
        }
        // get file text
        $text = fread(fopen($file, 'r'), filesize($file));
    } else {
        // dump a comment to the page
        $text = "if( typeof( console ) != undefined ){ console.log( 'There was an error trying to include js file: " . $file . ", it could not be found. Please check the file path.' ); }";
    }
    return $text;
}
Exemplo n.º 3
0
<?php

/**
 * help_format_tikiwiki_inc
 *
 * @author   Christian Fowler>
 * @version  $Revision$
 * @package  liberty
 * @subpackage functions
 */
/**
 * required setup
 */
global $gBitSystem, $gBitSmarty;
require_once KERNEL_PKG_PATH . 'BitCache.php';
$cache = new BitCache('liberty/help');
// only regenerate this thing if it's not cached yet
$cacheFile = 'tikiwiki';
if ($cache->isCached($cacheFile, filemtime(__FILE__))) {
    $examples = unserialize($cache->readCacheFile($cacheFile));
} else {
    // help for generic options
    $tikiwiki = array('Emphasis' => array('Headings' => array('data' => "! heading 1\n!! heading 2\n!!! heading 3", 'note' => "Number of ! correponds to heading level."), 'Italics' => array('data' => "''text''", 'note' => "Two single quotes not one double quote"), 'Underline' => array('data' => "===text==="), 'Coloured Background' => array('data' => "++yellow:text++"), 'Coloured Text' => array('data' => "~~red:text~~"), 'Bold' => array('data' => "__text__"), 'Centered Text' => array('data' => "::text::"), 'Combined' => array('data' => "::__~~red:++yellow:text++~~__::", 'note' => "When you combine options make sure you open and close in the opposite order analogous to: {[(text)]}")), 'Lists' => array('Unordered Lists' => array('data' => "* First item\n** First subitem\n** Second subitem\n* Second item"), 'Ordered Lists' => array('data' => "# First item\n## First subitem\n## Second subitem\n# Second item"), 'Definition Lists' => array('data' => ";Term: Definition")), 'Links' => array('Wiki Links' => array('data' => "((Wiki Page))", 'result' => '<a href="#">Wiki Page</a>'), 'Wiki Links + Description' => array('data' => "((Wiki Page|Page Description))", 'result' => '<a href="#">Page Description</a>'), 'Wiki Links + Anchor + Description' => array('data' => "((Wiki Page#Anchor|Page Description))", 'result' => '<a href="#">Page Description</a>'), 'External Link' => array('data' => "[http://www.example.com]"), 'External Link + Description' => array('data' => "[http://www.example.com|Description]"), 'External Link + Anchor + Description' => array('data' => "[http://www.example.com/Page#Anchor|Description]")), 'Miscellaneous' => array('Horizontal Rule' => array('data' => '---'), 'Highlighted Bar' => array('data' => '-=text=-'), 'Highlighted Box' => array('data' => "^text\nmore text^"), 'As is Text' => array('data' => "~np~~~yellow:yellow~~\nand\n__bold__ text~/np~", 'note' => "This text will not be parsed"), 'Pre Parsed' => array('data' => "~pp~~~yellow:yellow~~\nand\n__bold__ text~/pp~", 'note' => "This text will be treated like code and will not be altered and will be displayed using a monospace font. The same can be achieved by using &lt;pre&gt;text&lt;/pre&gt;."), 'Monospaced Text' => array('data' => "-+text+-"), 'Right to Left' => array('data' => "{r2l}this text is from\nright to left\n{l2r}and back to\nleft to right.")), 'Simple Tables' => array('Simple Table' => array('data' => "|| Row1-Col1 | Row1-Col2\nRow2-Col1 | Row2-Col2 ||"), 'With Headers' => array('data' => "||~ Header1 | Header2\nRow1-Col1 | Row1-Col2\nRow2-Col1 | Row2-Col2 ||")));
    if ($gBitSystem->getConfig('wiki_tables') == 'old') {
        $tikiwiki['Simple Tables'] = array('Tables' => array('data' => "|| Row1-Col1 | Row1-Col2 || Row2-Col1 | Row2-Col2 ||"));
    }
    foreach (array_keys($tikiwiki) as $section) {
        foreach ($tikiwiki[$section] as $title => $example) {
            if (empty($example['result'])) {
                $example['format_guid'] = 'tikiwiki';
                $tikiwiki[$section][$title]['result'] = LibertyContent::parseData($example);