function smarty_function_get_remote($params, &$smarty) { // Default options $opts = array( 'default' => 'Not found', 'fix' => 'src|href|action' ); $opts = array_merge($opts, $params); // Make sure they passed a source url if (isset($opts['url'])) { $opts['url'] = $opts['url']; } else { die($opts['default']); } // Retrieve the remote file $content = @getRemoteFile($opts); // Make sure we actually got something if (!$content) die ($opts['default']); // Fix relative urls to point to the old site if ($opts['fix']) { $opts['patterns'][] = '/('.$opts['fix'].')=[\'"]([^(?:http)|\/].*)[\'"]/ie'; $opts['replacements'][] = '"${1}=\'".$domain."/".getAbsolutePath($base_url."/${2}")."\'"'; $opts['patterns'][] = '/('.$opts['fix'].')=[\'"](\/.*)[\'"]/ie'; $opts['replacements'][] = '"${1}=\'".$domain."${2}\'"'; } $content = fixUrls($content, $opts); // Output the contents to the template return $content; }
function doFile($harfile) { if (!$harfile) { return; } // If everything is ok we run it through PageSpeed. $output = array(); $return_var = 128; exec("./har_to_pagespeed text '{$harfile}'", $output, $return_var); if (0 === $return_var) { $len = count($output); $rules = array(); $curRule = -1; for ($i = 0; $i < $len; $i++) { $line = $output[$i]; $matches = array(); if (preg_match("/_(.*)_ \\(score=([0-9]+)/", $line, $matches)) { // don't need to worry about 0 vs false if ("Optimize images" != $matches[1]) { $curRule++; array_push($rules, array($matches[1], $matches[2], "")); } } else { if (-1 < $curRule) { $line = fixUrls($line); $rules[$curRule][2] .= $line . "<br>"; } } } displayRules($rules); } else { echo "There was an error parsing the HAR file. {$return_var}"; } }