+
+ /**
+ * Returns the correct header for a status code
+ *
+ * @param $status_code
+ */
+ private static function _status($status_code)
+ {
+ if (strpos(php_sapi_name(), 'apache') !== false) {
+
+ header('HTTP/1.0 '.$status_code);
+ }
+ else {
+
+ header('Status: '.$status_code);
+ }
+ }
+
+ /**
+ * Get the content for a given URL (by a call to FullTextFeed)
+ *
+ * @param Url $url
+ * @return mixed
+ */
+ public static function getPageContent(Url $url)
+ {
+ // Saving and clearing context
+ $REAL = array();
+ foreach( $GLOBALS as $key => $value ) {
+ if( $key != 'GLOBALS' && $key != '_SESSION' && $key != 'HTTP_SESSION_VARS' ) {
+ $GLOBALS[$key] = array();
+ $REAL[$key] = $value;
+ }
+ }
+ // Saving and clearing session
+ if (isset($_SESSION)) {
+ $REAL_SESSION = array();
+ foreach( $_SESSION as $key => $value ) {
+ $REAL_SESSION[$key] = $value;
+ unset($_SESSION[$key]);
+ }
+ }
+
+ // Running code in different context
+ $scope = function() {
+ extract( func_get_arg(1) );
+ $_GET = $_REQUEST = array(
+ "url" => $url->getUrl(),
+ "max" => 5,
+ "links" => "preserve",
+ "exc" => "",
+ "format" => "json",
+ "submit" => "Create Feed"
+ );
+ ob_start();
+ require func_get_arg(0);
+ $json = ob_get_contents();
+ ob_end_clean();
+ return $json;
+ };
+
+ $json = $scope("inc/3rdparty/makefulltextfeed.php", array("url" => $url));
+
+ // Clearing and restoring context
+ foreach ($GLOBALS as $key => $value) {
+ if($key != "GLOBALS" && $key != "_SESSION" ) {
+ unset($GLOBALS[$key]);
+ }
+ }
+ foreach ($REAL as $key => $value) {
+ $GLOBALS[$key] = $value;
+ }
+
+ // Clearing and restoring session
+ if (isset($REAL_SESSION)) {
+ foreach($_SESSION as $key => $value) {
+ unset($_SESSION[$key]);
+ }
+
+ foreach($REAL_SESSION as $key => $value) {
+ $_SESSION[$key] = $value;
+ }
+ }
+
+ return json_decode($json, true);
+ }
+
+ /**
+ * Returns whether we handle an AJAX (XMLHttpRequest) request.
+ *
+ * @return boolean whether we handle an AJAX (XMLHttpRequest) request.
+ */
+ public static function isAjaxRequest()
+ {
+ return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest';
+ }
+
+ /*
+ * Empty cache folder
+ */
+ public static function emptyCache()
+ {
+ $files = new RecursiveIteratorIterator(
+ new RecursiveDirectoryIterator(CACHE, RecursiveDirectoryIterator::SKIP_DOTS),
+ RecursiveIteratorIterator::CHILD_FIRST
+ );
+
+ foreach ($files as $fileInfo) {
+ $todo = ($fileInfo->isDir() ? 'rmdir' : 'unlink');
+ $todo($fileInfo->getRealPath());
+ }
+
+ Tools::logm('empty cache');
+ Tools::redirect();
+ }
+
+ public static function generateToken()
+ {
+ if (ini_get('open_basedir') === '') {
+ if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
+ // alternative to /dev/urandom for Windows
+ $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
+ } else {
+ $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15);
+ }
+ }
+ else {
+ $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
+ }
+
+ return str_replace('+', '', $token);
+ }
+
+}