function callback_wms_plugins($Buffer, $Tag, $SessionKey) { // Plugins Replacement is empty $Result = ""; // Check if Option is set if (isset($_SESSION[$SessionKey])) { // Loop though the Plugin (Pre-Processed) foreach ($_SESSION[$SessionKey] as $K => $V) { // Tag must be in a specified tag in the Attribute 'plugin' Not Case Sensitve if (preg_match('/(<(body|div|ul)(.{1,})(plugin="' . $K . '")(.{0,})>)/i', $Buffer)) { // Add the Plugin to Show $Result .= $V; } } } // Remove last 'EndOfLine' if (EndsWith(EOL, $Result)) { $Result = substr($Result, 0, -strlen(EOL)); } // return preg_replace( '/([\s]{1})([\t ]{1,})'.$Tag.'/i', "<HEIR>",$Buffer ); if ($Result != "") { return preg_replace('/([\\s]{1})([\\t ]{1,})' . $Tag . '\\s/i', "\$1{$Result}", $Buffer); } else { return preg_replace('/([\\s]{1})([\\t ]{1,})' . $Tag . '/i', "", $Buffer); } }
function ProcessDir($dir) { global $src, $dest, $totalDirs, $totalFiles, $totalYui; if (!file_exists($dest . substr($dir, strlen($src)))) { echo 'mkdir -> ' . $dest . substr($dir, strlen($src)) . "\n"; mkdir($dest . substr($dir, strlen($src))); } $dir .= EndsWith($dir, '/') ? '*' : '/*'; foreach (glob($dir) as $file) { if (is_dir($file)) { if (EndsWith($file, '_build')) { continue; } ++$totalDirs; ProcessDir($file); } else { if (EndsWith($file, '.zScript build ip') || EndsWith($file, '.gz') || EndsWith($file, '.bz2')) { continue; } else { if (EndsWith($file, '.js') && !EndsWith($file, '.min.js') || EndsWith($file, '.css')) { echo 'YUI Compressor -> ' . $dest . substr($file, strlen($src)) . "\n"; system('java -jar yuicompressor/yuicompressor-2.4.8.jar -o ' . $dest . substr($file, strlen($src)) . ' ' . $file); ++$totalYui; } else { copy($file, $dest . substr($file, strlen($src))); } } ++$totalFiles; } } }
function dlflv($url) { if (EndsWith($url, ".flv")) { return $url; } $html = cacheurl($url); preg_match('|"videoUrl","(.*?)"|is', $html, $matches); # $tmp_array['title'] = rep($matches[2]); return "http://video.sat1.de" . urldecode($matches[1]); }
/** * Load Data Objects */ function LoadDataObjects() { $path = 'libs/DataObjects/'; if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { if (EndsWith($file, ".php")) { require_once $path . $file; } } closedir($handle); } }
/** * Find a key in the given array return exploded position, false if key isn't found * * @version 1 * @author Rick de Man <*****@*****.**> * * @param array $Array * The array to look in for * @param string $Key * The Key to find in the provided array * @param string $Glue * The 'glue' for key location string * @param string $Result * Do not Use, will be over ruled * @return false if not found, string as location of the key */ function arraykeylocate($Array, $Key, $Glue = ',', $Result = '') { // Overrule the Result only when function depth is 1 if (GetFunctionDepth(2) == 1) { // Reset Result value $Result = ''; } // Check if array has been given if (is_array($Array)) { // Loop through the array, Find the Key foreach ($Array as $K => $V) { // Check if the current Key is which we are looking for if ($K == $Key) { // Check if result is empty if ($Result == '') { // Return the Current KeyName return $K; } else { // Return the result + KeyName return $Result . $Glue . $K; } } } // Loop through the array, go deeper in the array foreach ($Array as $K => $V) { // Only allow Arrays if (is_array($V)) { // Check for Results for each level we can $Result2 = ArrayKeyLocate($Array[$K], $Key, $Glue, $Result == '' ? $K : $Result . ',' . $K); // If the String ends with the Search Key Start returning value(s) if (EndsWith($Glue . $Key, $Result2) !== false) { // Return The position return $Result2; } } } } // Return the result return $Result == '' ? false : $Result; }
function ProcessDir($dir) { global $src, $dest, $totalDirs, $totalFiles, $totalMinified; if (!file_exists($dest . substr($dir, strlen($src)))) { echo 'mkdir -> ' . $dest . substr($dir, strlen($src)) . "\n"; mkdir($dest . substr($dir, strlen($src))); } $dir .= EndsWith($dir, '/') ? '*' : '/*'; foreach (glob($dir) as $file) { if (is_dir($file)) { if (EndsWith($file, '_build')) { continue; } ++$totalDirs; ProcessDir($file); } else { if (EndsWith($file, '.zScript build ip') || EndsWith($file, '.gz') || EndsWith($file, '.bz2')) { continue; } else { if (EndsWith($file, '.js') && !EndsWith($file, '.min.js')) { echo 'UglifyJS -> ' . $dest . substr($file, strlen($src)) . "\n"; system('uglifyjs -o ' . $dest . substr($file, strlen($src)) . ' ' . $file); ++$totalMinified; } else { if (EndsWith($file, '.css')) { echo 'CleanCSS -> ' . $dest . substr($file, strlen($src)) . "\n"; system('cleancss --skip-rebase -o ' . $dest . substr($file, strlen($src)) . ' ' . $file); ++$totalMinified; } else { copy($file, $dest . substr($file, strlen($src))); } } } ++$totalFiles; } } }
/** * Dynamic File Loader * * @version 1 * @author Rick de Man <*****@*****.**> * * @param string $Folder * The Folder to look in * @param string $Ext * The extion too look for, Empty is for folders * @param Bool $ASC * Ascending or Descending * @return array */ function dynamicloader($Folder, $Ext, $ASC) { // The Results $Result = array(); // Check if Folder exists if (file_exists($Folder)) { // Scan the Folder if ($Handler = opendir($Folder)) { // Foreach file while (false !== ($File = readdir($Handler))) { // Retrieve File info $FileInfo = pathinfo($File); // Check if the File ends with $Ext, or $Ext = '' & Folder if (EndsWith($Ext, $File, true) || $Ext == '' && !isset($FileInfo['extension'])) { // Add the File to the Results $Result[] = str_replace('\\', '/', $Folder . $File); } } // Close the Folder Handler closedir($Handler); } // Asc or Desc if ($ASC) { sort($Result); } else { arsort($Result); } // Return the results return $Result; } else { // Return the results return $Result; } // Return the results return $Result; }
function run_test($file, $www) { // parse the test '$file' $section_text = parse_file($file); // setup environment if (EndsWith($www, '.php')) { $www = dirname($www); } if (!EndsWith($www, '/')) { $www .= '/'; } $phpfile = replace_extension($file, 'php'); $tested = trim($section_text['TEST']); $env = array('HTTP_CONTENT_ENCODING' => ''); $opts = array('http' => array('method' => "GET", 'header' => '')); if (!empty($section_text['ENV'])) { foreach (explode("\n", trim($section_text['ENV'])) as $e) { $e = explode('=', trim($e), 2); if (!empty($e[0]) && isset($e[1])) { $env[$e[0]] = $e[1]; } } } // Default ini settings $ini_settings = array(); // put additional INI settings here // Any special ini settings, these may overwrite the test defaults... if (array_key_exists('INI', $section_text)) { if (strpos($section_text['INI'], '{PWD}') !== false) { $section_text['INI'] = str_replace('{PWD}', dirname(realpath($file)), $section_text['INI']); } settings2array(preg_split("/[\n\r]+/", $section_text['INI']), $ini_settings); } // prepend custom ini settings if (count($ini_settings) > 0) { $section_text['FILE'] = get_ini_code($ini_settings) . $section_text['FILE']; } // skip this test ? try_skip($file, $www, $section_text); // redirect test ? try_redirect($file, $www, $section_text); // request .php script save_text($phpfile, $section_text['FILE']); if (array_key_exists('GET', $section_text)) { $query_string = trim($section_text['GET']); } else { $query_string = ''; } $env['QUERY_STRING'] = $query_string; if (array_key_exists('COOKIE', $section_text)) { $env['HTTP_COOKIE'] = trim($section_text['COOKIE']); $opts["http"]["header"] .= "Cookie: " . $env['HTTP_COOKIE'] . "\r\n"; } else { $env['HTTP_COOKIE'] = ''; } $args = isset($section_text['ARGS']) ? ' -- ' . $section_text['ARGS'] : ''; if (array_key_exists('POST_RAW', $section_text) && !empty($section_text['POST_RAW'])) { $post = trim($section_text['POST_RAW']); $raw_lines = explode("\n", $post); $request = ''; $started = false; foreach ($raw_lines as $line) { if (empty($env['CONTENT_TYPE']) && preg_match('/^Content-Type:(.*)/i', $line, $res)) { $env['CONTENT_TYPE'] = trim(str_replace("\r", '', $res[1])); continue; } if ($started) { $request .= "\n"; } $started = true; $request .= $line; } $env['CONTENT_LENGTH'] = strlen($request); $env['REQUEST_METHOD'] = 'POST'; $opts["http"]["method"] = "POST"; $opts["http"]["header"] .= "Content-type: " . $env['CONTENT_TYPE'] . "\r\n"; $opts["http"]["content"] = $request; if (empty($request)) { error("POST empty in '{$file}'"); } } else { if (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) { $post = trim($section_text['POST']); if (array_key_exists('GZIP_POST', $section_text) && function_exists('gzencode')) { $post = gzencode($post, 9, FORCE_GZIP); $env['HTTP_CONTENT_ENCODING'] = 'gzip'; } else { if (array_key_exists('DEFLATE_POST', $section_text) && function_exists('gzcompress')) { $post = gzcompress($post, 9); $env['HTTP_CONTENT_ENCODING'] = 'deflate'; } } //save_text($tmp_post, $post); $content_length = strlen($post); $env['REQUEST_METHOD'] = 'POST'; $env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; $env['CONTENT_LENGTH'] = $content_length; $opts["http"]["method"] = "POST"; $opts["http"]["header"] .= "Content-type: " . $env['CONTENT_TYPE'] . "\r\n"; $opts["http"]["header"] .= "Content-encoding: " . $env['HTTP_CONTENT_ENCODING'] . "\r\n"; $opts["http"]["header"] .= "Content-length: " . $content_length . "\r\n"; $opts["http"]["content"] = $post; } else { $env['REQUEST_METHOD'] = 'GET'; $env['CONTENT_TYPE'] = ''; $env['CONTENT_LENGTH'] = ''; } } $context = stream_context_create($opts); $out = _file_get_contents($www . $phpfile, false, $context, &$headers); if ($out === FALSE) { echo '<br/>'; error("See <a target='_blank' href='{$phpfile}'>{$phpfile}</a>, exception "); } if (StartsWith($out, "\r\nCompileError") || StartsWith($out, "\r\nCompileWarning")) { show_result("<span class='skip'>SKIP</span>", $file, ", Script generates <b>CompileError</b> or <b>CompileWarning</b>, so it cannot be compared with PHP. <a href='{$phpfile}' target='_blank'>Try the script</a><pre>{$out}</pre>"); } // perform clean try_clean($file, $www, $section_text); // compare .php response with expected output // Does the output match what is expected? $output = preg_replace("/\r\n/", "\n", trim($out)); $output = str_replace("string[binary](", "string(", $output); $failed_headers = false; if (isset($section_text['EXPECTHEADERS'])) { $want = array(); $wanted_headers = array(); $lines = preg_split("/[\n\r]+/", (string) $section_text['EXPECTHEADERS']); foreach ($lines as $line) { if (strpos($line, ':') !== false) { $line = explode(':', $line, 2); $want[trim($line[0])] = trim($line[1]); $wanted_headers[] = trim($line[0]) . ': ' . trim($line[1]); } } $org_headers = $headers; $headers = array(); $output_headers = array(); foreach ($want as $k => $v) { if (isset($org_headers[$k])) { $headers = $org_headers[$k]; $output_headers[] = $k . ': ' . $org_headers[$k]; } if (!isset($org_headers[$k]) || $org_headers[$k] != $v) { $failed_headers = true; } } ksort($wanted_headers); $wanted_headers = join("\n", $wanted_headers); ksort($output_headers); $output_headers = join("\n", $output_headers); } if (isset($section_text['EXPECTF']) || isset($section_text['EXPECTREGEX'])) { if (isset($section_text['EXPECTF'])) { $wanted = trim($section_text['EXPECTF']); } else { $wanted = trim($section_text['EXPECTREGEX']); } $wanted_re = preg_replace('/\\r\\n/', "\n", $wanted); if (isset($section_text['EXPECTF'])) { // do preg_quote, but miss out any %r delimited sections $temp = ""; $r = "%r"; $startOffset = 0; $length = strlen($wanted_re); while ($startOffset < $length) { $start = strpos($wanted_re, $r, $startOffset); if ($start !== false) { // we have found a start tag $end = strpos($wanted_re, $r, $start + 2); if ($end === false) { // unbalanced tag, ignore it. $end = $start = $length; } } else { // no more %r sections $start = $end = $length; } // quote a non re portion of the string $temp = $temp . preg_quote(substr($wanted_re, $startOffset, $start - $startOffset), '/'); // add the re unquoted. if ($end > $start) { $temp = $temp . '(' . substr($wanted_re, $start + 2, $end - $start - 2) . ')'; } $startOffset = $end + 2; } $wanted_re = $temp; $wanted_re = str_replace(array('%binary_string_optional%'), version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? 'string' : 'binary string', $wanted_re); $wanted_re = str_replace(array('%unicode_string_optional%'), version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? 'string' : 'Unicode string', $wanted_re); $wanted_re = str_replace(array('%unicode\\|string%', '%string\\|unicode%'), version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? 'string' : 'unicode', $wanted_re); $wanted_re = str_replace(array('%u\\|b%', '%b\\|u%'), version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? '' : 'u', $wanted_re); // Stick to basics $wanted_re = str_replace('%e', '\\' . '\\', $wanted_re); $wanted_re = str_replace('%s', '[^\\r\\n]+', $wanted_re); $wanted_re = str_replace('%S', '[^\\r\\n]*', $wanted_re); $wanted_re = str_replace('%a', '.+', $wanted_re); $wanted_re = str_replace('%A', '.*', $wanted_re); $wanted_re = str_replace('%w', '\\s*', $wanted_re); $wanted_re = str_replace('%i', '[+-]?\\d+', $wanted_re); $wanted_re = str_replace('%d', '\\d+', $wanted_re); $wanted_re = str_replace('%x', '[0-9a-fA-F]+', $wanted_re); $wanted_re = str_replace('%f', '[+-]?\\.?\\d+\\.?\\d*(?:[Ee][+-]?\\d+)?', $wanted_re); $wanted_re = str_replace('%c', '.', $wanted_re); // %f allows two points "-.0.0" but that is the best *simple* expression } /* DEBUG YOUR REGEX HERE var_dump($wanted_re); print(str_repeat('=', 80) . "\n"); var_dump($output); */ if (preg_match("/^{$wanted_re}\$/s", $output)) { @unlink($phpfile); show_result("<span class='pass'>PASS</span>", "{$file}", ''); } } else { $wanted = (string) trim($section_text['EXPECT']); $wanted = preg_replace('/\\r\\n/', "\n", $wanted); // compare and leave on success if (!strcmp($output, $wanted)) { @unlink($phpfile); show_result("<span class='pass'>PASS</span>", $file, ''); } $wanted_re = null; } // Test failed so we need to report details. if ($failed_headers) { $passed = false; $wanted = (string) $wanted_headers . "\n--HEADERS--\n" . (string) $wanted; $output = (string) $output_headers . "\n--HEADERS--\n" . (string) $output; if (isset($wanted_re)) { $wanted_re = preg_quote($wanted_headers . "\n--HEADERS--\n", '/') . $wanted_re; } } // write .exp if (file_put_contents($file . '.exp', (string) $wanted, FILE_BINARY) === false) { error("Cannot create expected test output '{$file}.exp'"); } // write .out if (file_put_contents($file . '.out', (string) $output, FILE_BINARY) === false) { error("Cannot create test output - '{$file}.out'"); } // write .diff $diff = generate_diff($wanted, $wanted_re, $output); if (file_put_contents($file . '.diff', (string) $diff, FILE_BINARY) === false) { error("Cannot create test diff - '{$file}.diff'"); } $resultid = "result_" . strlen($phpfile) . '_' . crc32($phpfile); $sourceid = "source_" . strlen($phpfile) . '_' . crc32($phpfile); show_result("<span class='fail'>FAIL</span>", $file, ", <a href='{$phpfile}' target='_blank'>Try the script</a>" . ", <a href='#' onclick='\$(\"#{$sourceid}\").slideToggle();return false;'>source</a>" . ", <a href='#' onclick='\$(\"#{$resultid}\").slideToggle();return false;'>details</a>" . "<div id='{$sourceid}' style='display:none;background:#eee;border:1px dashed #888;'><pre>" . htmlspecialchars(trim(_file_get_contents($file, false, null, &$dummyheaders))) . "</pre></div>" . "<div id='{$resultid}' style='display:none;'><table border='1'><tr><td><b>Output</b><br/><pre style='background:#fee;font-size:8px;'>" . htmlspecialchars($output) . "</pre></td><td><b>Expected</b><br/><pre style='background:#efe;font-size:8px;'>" . htmlspecialchars($wanted) . "</pre></td></tr></table></div>"); // write .sh //if (strpos($log_format, 'S') !== false && file_put_contents($sh_filename, b"#!/bin/sh{$cmd}", FILE_BINARY) === false) { //error("Cannot create test shell script - $sh_filename"); //} //chmod($sh_filename, 0755); /*foreach ($restype as $type) { $PHP_FAILED_TESTS[$type.'ED'][] = array ( 'name' => $file, 'test_name' => (is_array($IN_REDIRECT) ? $IN_REDIRECT['via'] : '') . $tested . " [$tested_file]", 'output' => $output_filename, 'diff' => $diff_filename, 'info' => $info, ); }*/ }