EOT; ob_start(); ob_implicit_flush(false); include($fileName); $contents = ob_get_clean(); if($getId == 1) { if (preg_match('/###(.*?)###/', $contents, $match) === 1) { $GLOBALS['themeId'] = $match[1]; } else { $GLOBALS['themeId'] = "missing"; } } else { $contents = str_replace($type.'_files', $baseUrl.$type."_files", $contents); $contents = str_replace('rw_common', $baseUrl."rw_common", $contents); $contents = str_replace('resources', $baseUrl."resources", $contents); return $contents; } } function isSecure() { return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443; } function getBasePath() { $whitelist = array('127.0.0.1','::1'); $isLocal = in_array($_SERVER['REMOTE_ADDR'], $whitelist); $baseUrl = 'https://onelittledesigner.com/rapidweaver-stack/timed-content/' . '/'; $baseUrl = str_replace('//', '/', $baseUrl); $baseUrl = str_replace(':/', '://', $baseUrl); $thisPath = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,strpos( $_SERVER["SERVER_PROTOCOL"],'/'))).'://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; $testPath = getRelativePath($baseUrl.'themer.php'); if(!file_exists($testPath)){ //Base Url was input incorrectly, using base website domain instead //$baseUrl = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,strpos( $_SERVER["SERVER_PROTOCOL"],'/'))).'://' . $_SERVER['SERVER_NAME'] . '/'; } if($isLocal){ $baseUrl = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,strpos( $_SERVER["SERVER_PROTOCOL"],'/'))).'://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . '/'; $thisPath = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,strpos( $_SERVER["SERVER_PROTOCOL"],'/'))).'://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI']; } return $baseUrl; } function getRelativePath($to) { $whitelist = array('127.0.0.1','::1'); $isLocal = in_array($_SERVER['REMOTE_ADDR'], $whitelist); if($isLocal){ $from = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,strpos( $_SERVER["SERVER_PROTOCOL"],'/'))).'://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI']; } else if(isSecure()){ $from = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,strpos( $_SERVER["SERVER_PROTOCOL"],'/'))).'s://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; } else { $from = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,strpos( $_SERVER["SERVER_PROTOCOL"],'/'))).'://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; } $from = str_replace('www.', '', $from); $to = str_replace('www.', '', $to); // some compatibility fixes for Windows paths $from = is_dir($from) ? rtrim($from, '\/') . '/' : $from; $to = is_dir($to) ? rtrim($to, '\/') . '/' : $to; $from = str_replace('\\', '/', $from); $to = str_replace('\\', '/', $to); $from = explode('/', $from); $to = explode('/', $to); $relPath = $to; foreach($from as $depth => $dir) { // find first non-matching dir if($dir === $to[$depth]) { // ignore this directory array_shift($relPath); } else { // get number of remaining dirs to $from $remaining = count($from) - $depth; if($remaining > 1) { // add traversals up to first matching dir $padLength = (count($relPath) + $remaining - 1) * -1; $relPath = array_pad($relPath, $padLength, '..'); break; } else { $relPath[0] = './' . $relPath[0]; } } } return implode('/', $relPath); } function removeDuplicateLines($array,$match) { $count = 1; foreach($array as $key=>$line) { if (strpos($line, $match) !== false) { if($count>1) { unset($array[$key]); } $count ++; } } return $array; } function fixScriptPaths($scripts) { $lines = explode("\n", $scripts); $lines = preg_replace('/\s\s+/', ' ', $lines); $uniqueLines = array_unique($lines); $uniqueLines = removeDuplicateLines($uniqueLines,"stacks.css"); $uniqueLines = removeDuplicateLines($uniqueLines,"font-awesome.min.css"); //$uniqueLines = removeDuplicateLines($uniqueLines,"files/jquery-"); $scripts = implode("\n", $uniqueLines); return $scripts; } // // VARIABLES // $pageTitle = 'Examples | My Website'; $baseUrl = getBasePath(); $themerPath = getRelativePath($baseUrl.'themer.php'); // // INDEX // ?> EOT; echo fixScriptPaths($scripts); echo ""; } else { $themerPreview = 0; includeFileContent($baseUrl,$themerPath,"themer",0,1); //$isIndexFile = 1; $scripts .= includeFileContent($baseUrl,$themerPath,"themer","head",0); $scripts .= << EOT; echo fixScriptPaths($scripts); } ?> Examples | My Website