예제 #1
0
 function Compile($template)
 {
     // Initialization
     $this->tag_stack = array();
     $this->literal_stack = array();
     $this->capture_stack = array();
     $this->errors = array();
     $this->defines = array();
     // Convert to Unix newline characters
     $template = string_format_lf($template);
     // Strip comment sections
     $template = preg_replace('~{\\*.*?\\*}~msi', '', $template);
     // Create regular expression
     $regex = '~(' . COMPILER_DELIMITER_START . '([/*$a-z"]+.*?)' . COMPILER_DELIMITER_END . ')~msi';
     // Compile the code
     set_error_handler(array(&$this, 'ErrorHandler'));
     $compiled = preg_replace_callback($regex, array(&$this, 'CompileTag'), $template);
     restore_error_handler();
     // Check for unclosed tag(s)
     foreach ($this->tag_stack as $unclosed_tag) {
         $this->errors[] = 'Unclosed {' . $unclosed_tag . '} tag at end of template';
     }
     // Check for unclosed literal sections
     foreach ($this->literal_stack as $unclosed_tag) {
         $this->errors[] = 'Unclosed {' . $unclosed_tag . '} tag at end of template';
     }
     // Code cleanup
     //$compiled = preg_replace("~\n+~", "\n", trim($compiled));
     return count($this->errors) ? false : $compiled;
 }
예제 #2
0
 function _format_incoming($string)
 {
     if (is_array($string)) {
         return array_map(array('TextDB', '_format_incoming'), $string);
     }
     $string = string_format_lf($string, STRING_LF_UNIX);
     return str_replace(array(STRING_LF_UNIX, '|'), array('\\n', '!@@!'), $string);
 }
예제 #3
0
function write_config($settings)
{
    global $C;
    if (!file_exists(FILE_HISTORY)) {
        file_create(FILE_HISTORY);
    }
    unset($settings['r']);
    $settings['domain'] = preg_replace('~^www\\.~i', '', $_SERVER['HTTP_HOST']);
    $C = array_merge($C, $settings);
    check_image_resizer();
    $C['base_url'] = preg_replace('~/$~', '', $C['base_url']);
    $fp = fopen(DIR_LIB . '/config.php', 'r+');
    flock($fp, LOCK_EX);
    fwrite($fp, "<?php\nglobal \$C;\n\$C = array();\n");
    foreach ($C as $key => $val) {
        $val = str_replace(array('\\"', '\\.'), array('"', '.'), addslashes($val));
        fwrite($fp, "\$C['{$key}'] = '{$val}';\n");
    }
    fwrite($fp, "?>");
    ftruncate($fp, ftell($fp));
    flock($fp, LOCK_UN);
    fclose($fp);
    $in_settings = "\$C = array('cookie_domain' => '{$C['cookie_domain']}',\n" . "'domain' => '{$C['domain']}',\n" . "'keyphrase' => '{$C['keyphrase']}',\n" . "'flag_filter_no_image' => '{$C['flag_filter_no_image']}');";
    $out_settings = "\$C = array('domain' => '{$C['cookie_domain']}',\n" . "'keyphrase' => '{$C['keyphrase']}',\n" . "'distrib_forces' => '{$C['distrib_forces']}',\n" . "'distrib_main' => '{$C['distrib_main']}',\n" . "'distrib_primary' => '{$C['distrib_primary']}',\n" . "'distrib_secondary' => '{$C['distrib_secondary']}',\n" . "'count_clicks' => '{$C['count_clicks']}',\n" . "'fast_click' => '{$C['fast_click']}',\n" . "'trades_satisfied_url' => '{$C['trades_satisfied_url']}',\n" . "'flag_filter_no_image' => '{$C['flag_filter_no_image']}');";
    $img_settings = "\$C = array('dir_base' => '" . DIR_BASE . "',\n" . "'domain' => '{$C['cookie_domain']}',\n" . "'keyphrase' => '{$C['keyphrase']}');";
    // Write settings to in.php
    $in = string_format_lf(file_get_contents(FILE_IN_PHP));
    $in = preg_replace('~/\\*#<CONFIG>\\*/(.*?)/\\*#</CONFIG>\\*/~msi', "/*#<CONFIG>*/\n" . $in_settings . "\n/*#</CONFIG>*/", $in);
    if (version_compare(PHP_VERSION, '5.1.0', '>=')) {
        $timezone = date_default_timezone_get();
        $in = preg_replace('~/?/?date_default_timezone_set\\(\'.*?\'\\);~', "date_default_timezone_set('{$timezone}');", $in);
        $in = str_replace('//date_default_timezone_set($timezone);', 'date_default_timezone_set($timezone);', $in);
        $in = str_replace('//$timezone = date_default_timezone_get();', '$timezone = date_default_timezone_get();', $in);
    }
    file_write(FILE_IN_PHP, $in, null);
    // Write settings to out.php
    $out = string_format_lf(file_get_contents(FILE_OUT_PHP));
    $out = preg_replace('~/\\*#<CONFIG>\\*/(.*?)/\\*#</CONFIG>\\*/~msi', "/*#<CONFIG>*/\n" . $out_settings . "\n/*#</CONFIG>*/", $out);
    file_write(FILE_OUT_PHP, $out, null);
    // Write settings to image.php
    $img = string_format_lf(file_get_contents(FILE_IMAGE_PHP));
    $img = preg_replace('~/\\*#<CONFIG>\\*/(.*?)/\\*#</CONFIG>\\*/~msi', "/*#<CONFIG>*/\n" . $img_settings . "\n/*#</CONFIG>*/", $img);
    file_write(FILE_IMAGE_PHP, $img, null);
}
예제 #4
0
파일: dirdb.php 프로젝트: hackingman/TradeX
 function _format_incoming($string)
 {
     $string = string_format_lf($string, STRING_LF_UNIX);
     return str_replace(array(STRING_LF_UNIX, '|'), array('\\n', '!@@!'), $string);
 }
예제 #5
0
function string_remove_blank_lines($string, $sort = true)
{
    $string = string_format_lf($string);
    $lines = array();
    foreach (explode(STRING_LF_UNIX, $string) as $line) {
        if (!string_is_empty($line)) {
            $lines[] = $line;
        }
    }
    if ($sort) {
        sort($lines);
    }
    return join(STRING_LF_UNIX, $lines);
}
예제 #6
0
파일: xhr.php 프로젝트: hackingman/TradeX
function _xSiteTemplatesReplace()
{
    global $compiler;
    $v =& Validator::Get();
    $v->Register(is_array($_REQUEST['templates']), VT_NOT_FALSE, 'You must select at least one template for this action');
    $v->Register($_REQUEST['search'], VT_NOT_EMPTY, 'The Search For field is required');
    if (is_array($_REQUEST['templates'])) {
        $templates = array();
        foreach ($_REQUEST['templates'] as $template) {
            $template = file_sanitize($template, 'tpl,css', 'tpl');
            $filename = DIR_TEMPLATES . "/{$template}";
            $templates[$template] = $filename;
            $v->Register($filename, VT_FILE_IS_WRITEABLE, "The template file {$template} has incorrect permissions; change to 666 then try again");
        }
    }
    if (!$v->Validate()) {
        return JSON::Warning(array(JSON_KEY_MESSAGE => 'Search and replace could not be executed; please fix the following items', JSON_KEY_WARNINGS => $v->GetErrors()));
    }
    require_once 'compiler.php';
    $search = string_format_lf($_REQUEST['search']);
    $replace = string_format_lf($_REQUEST['replace']);
    $replacements = 0;
    foreach ($templates as $template => $filename) {
        $template_code = file_get_contents($filename);
        $new_code = str_replace($search, $replace, $template_code);
        // Changes have been made
        if ($new_code != $template_code && ($code = $compiler->Compile($new_code)) !== false) {
            file_write($filename, $new_code);
            file_write(DIR_COMPILED . "/{$template}", $code);
            $replacements++;
        }
    }
    JSON::Success(array(JSON_KEY_MESSAGE => 'Search and replace has been completed.  Templates updated: ' . format_int_to_string($replacements), JSON_KEY_DIALOG => _xIncludeCapture('site-templates-replace.php')));
}