Example #1
1
function ewiki_xpi_install($xpi_install_fn, $access, $jsi_access, $jsi_support)
{
    ewiki_xpi_load_registry($registry, $registry_hash);
    #-- load (possibly remote) .xpi file
    $xpi = ewiki_xpi_read($xpi_install_fn, "rb");
    if (!$xpi) {
        return "not a valid .xpi plugin (or wrong/inacceptable xpi plugin type/version)";
    }
    if (strlen($xpi["id"]) < 3) {
        return "missing .xpi header";
    }
    #-- it's a .jpi plugin
    if (($access || $jsi_access) && $xpi["type"] == "jpi") {
        #-- compile from JS (WikiScript) into sandboxed PHP
        if ($jsi_support) {
            $xpi["type"] = "page";
            js_compile($xpi["code"]);
            $xpi["code"] = NULL;
            $xpi["code"] = jsa_generate();
        } else {
            return "<b>ERROR</b>: cannot handle .jpi plugins without installed JavaScript interpreter";
        }
        if ($GLOBALS["js_err"]) {
            ewiki_log("failed compiling .jpi plugin '{$xpi['id']}'", 0);
            return "<b>ERROR</b>: broken .jpi plugin!";
        }
    } elseif (!$access) {
        return "<b>ERROR</b>: You don't have permission to install this type of plugin.<br /><br />";
    }
    #-- proceed with setup
    $xpi["state"] = 1;
    if (function_exists("php_check_syntax")) {
        if (!php_check_syntax($xpi["code"])) {
            return "<b>ERROR</b>: plugin code is broken";
        }
    }
    #-- create new database entry
    $new = ewiki_new_data($xpi["id"], EWIKI_DB_F_SYSTEM | EWIKI_DB_F_EXEC);
    $new["content"] = $xpi["code"];
    unset($xpi["code"]);
    #-- check for old version
    if ($access) {
        $old = ewiki_db::GET($new["id"]);
        if ($old["version"]) {
            $new["version"] = $old["version"] + 1;
            $o .= "(overwriting plugin [version {$old[version]}])<br />";
        }
    }
    #-- store plugin into database
    if (ewiki_db::WRITE($new)) {
        ewiki_log("successfully installed .xpi plugin '{$xpi['id']}'", 0);
        $o .= $xpi["type"] == "page" ? ewiki_link($xpi[id]) : "<b>{$xpi[id]}</b>";
        $o .= " plugin stored. ";
        #-- update .xpi registry
        $registry[$xpi["id"]] = $xpi;
        $registry_hash["content"] = serialize($registry);
        ewiki_data_update($registry_hash);
        $registry_hash["version"]++;
        ewiki_db::WRITE($registry_hash);
    } else {
        $o .= "<b>error</b> saving";
        ewiki_log("error installing .xpi/.jpi plugin '{$xpi['id']}'", 0);
    }
    return $o;
}
Example #2
0
function js_calc($expression)
{
    global $bc;
    ob_start();
    ob_implicit_flush(0);
    js_compile($expression);
    $r = jsi_expr($bc["."]);
    ob_end_clean();
    return $r;
}
Example #3
0
/**
 * Force a Javascript file to be cached (ordinarily we can rely on this to be automated by require_javascript/javascript_tempcode).
 *
 * @param  string			The javascript file required
 * @param  ?ID_TEXT		The name of the theme (NULL: current theme)
 * @param  ?boolean		Whether to minify (NULL: read from environment)
 * @return string			The path to the javascript file in the cache (blank: no file)
 */
function javascript_enforce($j, $theme = NULL, $minify = NULL)
{
    if (get_param_integer('keep_textonly', 0) == 1) {
        return '';
    }
    if ($minify === NULL) {
        $minify = get_param_integer('keep_no_minify', 0) == 0;
    }
    global $SITE_INFO;
    // Make sure the Javascript exists
    if ($theme === NULL) {
        $theme = filter_naughty($GLOBALS['FORUM_DRIVER']->get_theme());
    }
    $dir = get_custom_file_base() . '/themes/' . $theme . '/templates_cached/' . filter_naughty(user_lang());
    if (!isset($SITE_INFO['no_disk_sanity_checks']) || $SITE_INFO['no_disk_sanity_checks'] == '0') {
        if (!is_dir($dir)) {
            if (@mkdir($dir, 0777) === false) {
                warn_exit(do_lang_tempcode('WRITE_ERROR_DIRECTORY_REPAIR', escape_html($dir)));
            }
            fix_permissions($dir, 0777);
            sync_file($dir);
        }
    }
    $js_cache_path = $dir . '/' . filter_naughty_harsh($j);
    if (!$minify) {
        $js_cache_path .= '_non_minified';
    }
    if (get_option('enable_https', true) == '1' && function_exists('is_page_https') && function_exists('get_zone_name') && (tacit_https() || is_page_https(get_zone_name(), get_page_name()))) {
        $js_cache_path .= '_ssl';
    }
    if (is_mobile()) {
        $js_cache_path .= '_mobile';
    }
    $js_cache_path .= '.js';
    global $CACHE_TEMPLATES;
    $support_smart_decaching = !isset($SITE_INFO['disable_smart_decaching']) || $SITE_INFO['disable_smart_decaching'] == '0';
    $is_cached = ($CACHE_TEMPLATES || !running_script('index')) && @(filesize($js_cache_path) != 0) && !is_browser_decacheing() && !in_safe_mode();
    if ($support_smart_decaching || !$is_cached) {
        $found = find_template_place(strtoupper($j), '', $theme, '.tpl', 'templates');
        if ($found === NULL) {
            return '';
        }
        $theme = $found[0];
        $fullpath = get_custom_file_base() . '/themes/' . $theme . $found[1] . strtoupper($j) . '.tpl';
        if (!is_file($fullpath)) {
            $fullpath = get_file_base() . '/themes/' . $theme . $found[1] . strtoupper($j) . '.tpl';
        }
        $globals_custom = str_replace('default/templates/JAVASCRIPT.tpl', filter_naughty($GLOBALS['FORUM_DRIVER']->get_theme()) . '/templates_custom/JAVASCRIPT_CUSTOM_GLOBALS.tpl', $fullpath);
    }
    if ($support_smart_decaching && (@(filemtime($js_cache_path) < filemtime($fullpath)) && @filemtime($fullpath) < time() || @filemtime(get_file_base() . '/info.php') > @filemtime($js_cache_path) || is_file($globals_custom) && @filemtime($globals_custom) > @filemtime($js_cache_path)) || !$is_cached) {
        require_code('css_and_js');
        js_compile($j, $js_cache_path, $minify);
    }
    if (@filesize($js_cache_path) == 0) {
        return '';
    }
    return $js_cache_path;
}
Example #4
0
/*
Javascript Compilier
*/
echo "Including Libraries...";
include "lib.php";
include "../../lib/jsoncheck.php";
echo "Updating Version File...";
$v = update_versions();
echo "Generating HTML...";
$html = gen_html(file_get_contents("../../../html/ajaxanimator.htm"));
file_put_contents("../../../build/index.htm", $html);
echo "Generating NoHotlink HTML...";
//crap! another typo
file_put_contents("../../../build/nohotlink.htm", nohotlink($html));
echo "Compressing Javascript...";
$js = js_compile("../../../html/ajaxanimator.htm", array("../js/misc/files.js" => "../js/misc/alt/files.js"));
file_put_contents("../../../build/ajaxanimator-all.js", $js);
exec("dos2unix ../../../build/ajaxanimator-all.js");
echo "Compressing CSS...";
$css = css_compile("../../../html/ajaxanimator.htm");
file_put_contents("../../../build/ajaxanimator-all.css", str_replace("../", "http://ajaxanimator.googlecode.com/svn-history/r444/trunk/ajaxanimator/", $css));
exec("dos2unix ../../../build/ajaxanimator-all.css");
//echo "Archiving Release...";
//file_put_contents("../../../build/archive/ajaxanimator-all-$v.js",$js);
//exec("dos2unix ../../../build/archive/ajaxanimator-all-$v.js");
//file_put_contents("../../../build/archive/ajaxanimator-all-$v.css",$css);
//exec("dos2unix ../../../build/archive/ajaxanimator-all-$v.js");
//file_put_contents("../../../build/archive/ajaxanimator-$v.htm", //crap! i had a typo here!!!
//str_replace("ajaxanimator-all.css","ajaxanimator-all-$v.css",
//str_replace("ajaxanimator-all.js","ajaxanimator-all-$v.js",$html)));
echo "DONE";