function actionDefault()
 {
     // Get the file object for the current file
     $file = new YDFSFile(__FILE__);
     // Dump the object
     echo __FILE__;
     YDDebugUtil::dump($file);
     // Dump the object
     echo '<br>Basename: ' . $file->getBasename();
     echo '<br>Extension: ' . $file->getExtension();
     echo '<br>Path: ' . $file->getPath();
     echo '<br>LastModified: ' . $file->getLastModified();
     echo '<br>File size: ' . $file->getSize();
     // Get the contents
     YDDebugUtil::dump($file->getContents(), '$file->getContents()');
     // Get the partial contents
     YDDebugUtil::dump($file->getContents(2, 3), '$file->getContents( 2, 3 )');
     // Create a dummy file
     $file = new YDFSFile('dummy.txt', true);
     // Set the initial contents
     $file->setContents('initial contents');
     // Update the contents
     $file->setContents('new contents');
     // Get the contents
     YDDebugUtil::dump($file->getContents(), '$file->getContents() after update');
     // Append the contents
     $file->setContents(YD_CRLF . 'appended contents', true);
     // Get the contents
     YDDebugUtil::dump($file->getContents(), '$file->getContents() after append');
     // Delete the file
     $file->delete();
     // Get the file object for the current file
     $file = new YDFSFile('nofile.php');
 }
 function actionRestore()
 {
     // Include filesystem functions
     YDInclude('YDFileSystem.php');
     // Create file object
     $file = new YDFSFile($this->dump->getFilePath());
     // Restore the database dump
     $this->dump->restore($file->getContents());
     // Show the properties of the database backup
     YDDebugUtil::dump($file->getContents(), $this->dump->getFilePath());
 }
 function actionShowLog()
 {
     $file = new YDFSFile(YDConfig::get('YD_LOG_FILE'));
     $data = $file->getContents();
     if (substr($data, 0, 5) == '<?xml') {
         header('Content-type: text/xml');
     } else {
         header('Content-type: text/plain');
     }
     echo $data;
     die;
 }
 function actionDefault()
 {
     // The original data
     $file = new YDFSFile('bbcode.txt');
     $data = $file->getContents();
     // The converter
     $conv = new YDBBCode();
     // Show the converted data
     echo '<pre>' . htmlentities($data) . '</pre>';
     echo '<pre>' . htmlentities($conv->toHtml($data)) . '</pre>';
     echo '<p>' . $conv->toHtml($data, true, false) . '</p>';
 }
 function actionStandaloneTimer()
 {
     // Instantiate the timer
     $timer = new YDTimer();
     // The original data
     $timer->addMarker('Reading file');
     $file = new YDFSFile('bbcode.txt');
     $data = $file->getContents();
     $timer->addMarker('Finished reading file');
     // The converter
     $timer->addMarker('YDBBCode object');
     $conv = new YDBBCode();
     // Show the converted data
     $timer->addMarker('Conversion to BBCode');
     echo '<pre>' . htmlentities($data) . '</pre>';
     echo '<pre>' . htmlentities($conv->toHtml($data)) . '</pre>';
     echo '<p>' . $conv->toHtml($data, true, false) . '</p>';
     // Get the report
     $report = $timer->getReport();
     // Dump the contents of the report
     YDDebugUtil::dump($report, 'Timing report');
 }
 /**
  *	Adds an attachment to a message.
  *
  *	@param $file		The file path.
  *	@param $c_type		(optional) The content type of the image or file.
  *	@param $name		(optional) The suggested file name for the data.
  */
 function addAttachment($file, $c_type = 'application/octet-stream', $name = '')
 {
     if (!YDObjectUtil::isSubClass($file, 'YDFSFile')) {
         $file = new YDFSFile($file);
     }
     $data = $file->getContents();
     if (empty($name)) {
         $name = $file->getBaseName();
     }
     $this->_msg->addAttachment($data, $name, $c_type);
 }
 /**
  *	Function to get the contents of the URL. It will get the contents using Gzip compression if possible in
  *	order to save bandwidth. It uses the HTTP Client class from Simon Willison to do the dirty work.
  *
  *	More information about the HTTP client class can be found on: http://scripts.incutio.com/httpclient/
  *
  *	If it fails to retrieve the data, it will raise a fatal error.
  *
  *	By default, it will cache the downloaded data based on the etag and last-modified headers. The cache files
  *	are stored in the temp directory of the Yellow Duck framework and have the extension "wch". You can delete
  *	these automatically as they will be recreated on the fly if needed.
  *
  *	For configuring the cache, there are two configuration variables you can redefine if needed:
  *	YD_HTTP_CACHE_TIMEOUT: the lifetime of the cache in seconds (default: 3600).
  *	YD_HTTP_CACHE_USEHEAD: if a HEAD HTTP request should be used to verify the cache validity (default: 1).
  *
  *	@param $cache	(optional) Indicate if the web content should be cached or not. By default, caching is
  *					turned on.
  *  @param $fail    (optional) Whether to fail or not if the contents cannot be downloaded. Defaults to true.
  *
  *	@returns	Returns the contents of the URL.
  */
 function getContents($cache = true, $fail = true)
 {
     // Check if caching is enabled
     $cacheFName = null;
     // Check the cache
     if ($cache == true) {
         // Include the filesystem library
         include_once YD_DIR_HOME_CLS . '/YDFileSystem.php';
         // Check if we need to use the HTTP HEAD function
         if (YDConfig::get('YD_HTTP_CACHE_USEHEAD') == 1) {
             // Get the headers
             $headers = $this->getHeaders();
             // Check if we have etag or last modified
             if (isset($headers['etag']) || isset($headers['last-modified'])) {
                 $cacheFName = $this->getUrl();
                 if (isset($headers['etag'])) {
                     $cacheFName .= $headers['etag'];
                 }
                 if (isset($headers['last-modified'])) {
                     $cacheFName .= $headers['last-modified'];
                 }
                 if (isset($headers['content-length'])) {
                     $cacheFName .= $headers['content-length'];
                 }
                 $cacheFName = YD_TMP_PRE . 'W_' . md5($cacheFName) . '.wch';
                 $cacheFName = YD_DIR_TEMP . '/' . $cacheFName;
             }
         }
         // If the cache filename is null, use the default one
         if ($cacheFName == null) {
             $cacheFName = YD_DIR_TEMP . '/' . YD_TMP_PRE . 'W_' . md5($this->getUrl()) . '.wch';
         }
         // Use the cache file if any
         if (is_file($cacheFName)) {
             $file = new YDFSFile($cacheFName);
             $cacheValidTime = $file->getLastModified() + YDConfig::get('YD_HTTP_CACHE_TIMEOUT');
             if (time() < $cacheValidTime) {
                 return $file->getContents();
             }
         }
     }
     // Create a new HTTP client
     $client = $this->_getHttpClient();
     // Now send the request
     $result = @$client->doRequest();
     // Check if there was a result
     if ($result == false) {
         if ($fail) {
             trigger_error('Failed to retrieve the data from the url "' . $this->getUrl() . '". ' . $client->getError(), YD_ERROR);
         } else {
             return false;
         }
     } else {
         $data = @$client->getContent();
     }
     // Check if caching is enabled
     if ($cache == true) {
         // Save the cached data
         if ($cacheFName != null) {
             $dir = new YDFSDirectory(YD_DIR_TEMP);
             $dir->createFile($cacheFName, $data);
         }
     }
     // Return the data
     return $data;
 }
 /**
  *  This function loads any type of content based on the YD_XML constants.
  *
  *  @param $mixed   A string, file, url or array for loading when instantiating
  *                  the object. Default: empty.
  *  @param $type    The type of the $mixed input. Must be one of the following:
  *                  YD_XML_FILE, YD_XML_URL, YD_XML_STRING or YD_XML_ARRAY.
  */
 function load($mixed, $type = YD_XML_FILE)
 {
     if (empty($mixed)) {
         trigger_error('No file, string, array or url specified', YD_ERROR);
     }
     switch ($type) {
         case YD_XML_URL:
             include_once YD_DIR_HOME_CLS . '/YDUrl.php';
             $url = new YDUrl($mixed);
             $contents = $url->getContents(false);
             break;
         case YD_XML_FILE:
             include_once YD_DIR_HOME_CLS . '/YDFileSystem.php';
             $file = new YDFSFile($mixed);
             $contents = $file->getContents();
             break;
         case YD_XML_STRING:
             $contents = $mixed;
             break;
         case YD_XML_ARRAY:
             $this->loadArray($mixed);
             return;
         default:
             trigger_error('Type of input unknown.', YD_ERROR);
     }
     $this->reset();
     $this->parseXML($contents);
 }