Exemplo n.º 1
0
 function raiseException($errorNum, $errorString)
 {
     //die('HTTP Exception: ' . $errorNum  .  "\n " . $errorString);
     if ($GLOBALS['HTTP_Exception_errorHandler'] != null) {
         call_user_func($GLOBALS['HTTP_Exception_errorHandler'], $errorNum, $errorString);
     } else {
         $errorMessageText = $errorNum . ' ' . $errorString;
         $errorMessage = 'Error: ' . $errorMessageText;
         if (!isset($GLOBALS['HTTP_ERROR_FORMATTING_HTML']) || $GLOBALS['HTTP_ERROR_FORMATTING_HTML'] == true) {
             $errorMessage = "<p><pre>" . $errorMessage . "</pre></p>";
         }
         //log error to file
         if (isset($GLOBALS['HTTP_Exception_log']) && $GLOBALS['HTTP_Exception_log'] != null) {
             require_once PHP_HTTP_TOOLS_INCLUDE_PATH . 'php_file_utilities.php';
             $logItem = "\n" . date('Y-m-d H:i:s') . ' HTTP Error ' . $errorMessageText;
             php_file_utilities::putDataToFile($GLOBALS['HTTP_Exception_log'], $logItem, 'a');
         }
         switch ($GLOBALS['HTTP_Exception_mode']) {
             case HTTP_ONERROR_CONTINUE:
                 return;
                 break;
             case HTTP_ONERROR_DIE:
                 die($errorMessage);
                 break;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Serializes and caches the specified DOMIT! document
  * @param string The name of the xml file to be saved
  * @param Object A reference to the document to be saved
  * @param string The write attributes for the saved document ('w' or 'wb')
  */
 function toCache($xmlFileName, &$doc, $writeAttributes = 'w')
 {
     require_once DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php';
     require_once DOMIT_INCLUDE_PATH . 'php_file_utilities.php';
     $name = DOMIT_Utilities::removeExtension($xmlFileName) . '.' . DOMIT_FILE_EXTENSION_CACHE;
     php_file_utilities::putDataToFile($name, serialize($doc), $writeAttributes);
     return file_exists($name) && is_writable($name);
 }
Exemplo n.º 3
0
 /**
  * Gets data from an url and caches a copy of the data
  * @param string The url for the data
  * @param string The cache file path
  * @return string The contents of the url
  */
 function fromURL($url, $cacheFile)
 {
     $fileContents = '';
     $_filename = strtolower($url);
     //if it's not a url or it's not from our cache dir don't let it through
     if (substr($_filename, 0, 7) !== 'http://' && substr($_filename, 0, 6) !== 'rss://' && substr($_filename, 0, 8) !== 'https://' && substr($_filename, 0, strlen($this->cacheDir)) !== strtolower($this->cacheDir)) {
         $GLOBALS['log']->debug('RSS - ILLEGAL PATH - ' . $_filename);
         return '';
     }
     // make sure they don't hop out of our cache dir
     $url = str_replace('..', '', $url);
     if ($this->httpConnection != null) {
         $response = $this->httpConnection->get($url);
         $fileContents = $response->getResponse();
     } else {
         $fileContents = $this->fromFile($url);
     }
     //if file is empty, might need to establish an
     //http connection to get the data
     if ($fileContents == '') {
         $this->establishConnection($url);
         $response = $this->httpConnection->get($url);
         if ($response) {
             $fileContents = $response->getResponse();
         }
     }
     // R. Rangel 3/16/2005
     // strip out everything before the "<rss " tag just in case..
     if (strstr($fileContents, "<rss ")) {
         $fileContents = stristr($fileContents, '<rss ');
     }
     if ($fileContents != '') {
         require_once PHP_TEXT_CACHE_INCLUDE_PATH . 'php_file_utilities.php';
         php_file_utilities::putDataToFile($cacheFile, $fileContents, 'w');
     }
     return $fileContents;
 }
 /**
  * Saves text to a file
  * @param string The file path
  * @param string The text to be saved
  * @return boolean True if the save is successful
  */
 function saveTextToFile($filename, $text)
 {
     if (function_exists('file_put_contents')) {
         file_put_contents($filename, $text);
     } else {
         require_once DOMIT_INCLUDE_PATH . 'php_file_utilities.php';
         php_file_utilities::putDataToFile($filename, $text, 'w');
     }
     return file_exists($filename) && is_writable($filename);
 }
 /**
  * Gets data from an url and caches a copy of the data
  * @param string The url for the data
  * @param string The cache file path
  * @return string The contents of the url
  */
 function fromURL($url, $cacheFile)
 {
     $fileContents = '';
     if ($this->httpConnection != null) {
         $response = $this->httpConnection->get($url);
         $fileContents = $response->getResponse();
     } else {
         $fileContents = $this->fromFile($url);
     }
     //if file is empty, might need to establish an
     //http connection to get the data
     if ($fileContents == '') {
         $this->establishConnection($url);
         $response = $this->httpConnection->get($url);
         if ($response) {
             $fileContents = $response->getResponse();
         }
     }
     // R. Rangel 3/16/2005
     // strip out everything before the "<rss " tag just in case..
     if (strstr($fileContents, "<rss ")) {
         $fileContents = stristr($fileContents, '<rss ');
     }
     if ($fileContents != '') {
         require_once PHP_TEXT_CACHE_INCLUDE_PATH . 'php_file_utilities.php';
         php_file_utilities::putDataToFile($cacheFile, $fileContents, 'w');
     }
     return $fileContents;
 }
Exemplo n.º 6
0
 /**
  * Gets data from an url and caches a copy of the data
  * @param string The url for the data
  * @param string The cache file path
  * @return string The contents of the url
  */
 function fromURL($url, $cacheFile)
 {
     $fileContents = '';
     if ($this->httpConnection != null) {
         $response =& $this->httpConnection->get($url);
         if ($response != null) {
             $fileContents = $response->getResponse();
         }
     } else {
         if ($this->doUseHTTPClient) {
             $this->establishConnection($url);
             $response =& $this->httpConnection->get($url);
             if ($response != null) {
                 $fileContents = $response->getResponse();
             }
         } else {
             $fileContents = $this->fromFile($url);
         }
     }
     //if file is empty, might need to establish an
     //http connection to get the data
     if ($fileContents == '' && !$this->doUseHTTPClient) {
         $this->establishConnection($url);
         $response =& $this->httpConnection->get($url);
         if ($response != null) {
             $fileContents = $response->getResponse();
         }
     }
     if ($fileContents != '') {
         require_once PHP_TEXT_CACHE_INCLUDE_PATH . 'php_file_utilities.php';
         php_file_utilities::putDataToFile($cacheFile, $fileContents, 'w');
     }
     return $fileContents;
 }