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');
 }
 /**
  *	This function will do the actual work of creating a thumbnail image.
  *
  *	@param $width	The maximum width of the thumbnail.
  *	@param $height	The maximum height of the thumbnail.
  *	@param $cache	(optional) Indicate if the thumbnails should be cached. By default, caching is turned off.
  *	@param $crop	(optional) Indicate if the thumbnails should be cropped to the exact size. By default, false.
  *
  *	@internal
  */
 function &_createThumbnail($width, $height, $cache = true, $crop = false)
 {
     // Check if the GD library is loaded.
     if (!extension_loaded('gd')) {
         $this->_error('YD_gd_not_installed');
     }
     // Width and height should be positive integer
     if ($width < 1 || $height < 1) {
         $this->_error();
     }
     // Get the cache filename
     $cacheFName = YD_DIR_TEMP . '/' . $this->_createThumbnailName($width, $height);
     // Check if caching is enabled
     if ($cache === true) {
         // Output the cached version if any
         if (is_file($cacheFName)) {
             // Create a new image for the cache file
             $img = new YDFSImage($cacheFName);
             // Set the content type
             header('Content-type: ' . $img->getMimeType());
             // Output the image
             readfile($cacheFName);
             die;
         }
     }
     // Check the extension
     $img_type = $this->isImage();
     // Open the source image
     if ($img_type == 'gif') {
         if (!function_exists('imagecreatefromgif')) {
             $this->_error();
         }
         $src_img = imagecreatefromgif($this->getAbsolutePath());
     } elseif ($img_type == 'png') {
         $src_img = imagecreatefrompng($this->getAbsolutePath());
     } else {
         $src_img = imagecreatefromjpeg($this->getAbsolutePath());
     }
     // Get the current image size
     $ori_width = imageSX($src_img);
     $ori_height = imageSY($src_img);
     // Calculate the new image size
     if ($crop) {
         if ($ori_width > $ori_height) {
             $thumb_w = ceil($ori_width * ($height / $ori_height));
             $thumb_h = $height;
         }
         if ($ori_width < $ori_height) {
             $thumb_w = $width;
             $thumb_h = ceil($ori_height * ($width / $ori_width));
         }
     } else {
         if ($ori_width > $ori_height) {
             $thumb_w = $width;
             $thumb_h = ceil($ori_height * ($width / $ori_width));
         }
         if ($ori_width < $ori_height) {
             $thumb_w = ceil($ori_width * ($height / $ori_height));
             $thumb_h = $height;
         }
     }
     if ($ori_width == $ori_height) {
         $thumb_w = $width;
         $thumb_h = $height;
     }
     if (($width >= $ori_width || $height >= $ori_height) && (!$crop || $crop && YDConfig::get('YD_FS_CROP') != YD_FS_CROP_ENLARGED)) {
         if ($width >= $ori_width && $height < $ori_height) {
             $thumb_w = ceil($ori_width * ($height / $ori_height));
             $thumb_h = $height;
         } else {
             if ($width < $ori_width && $height >= $ori_height) {
                 $thumb_w = $width;
                 $thumb_h = ceil($ori_height * ($width / $ori_width));
             } else {
                 $thumb_w = $ori_width;
                 $thumb_h = $ori_height;
             }
         }
     }
     // Resample the image
     $dst_img = imagecreatetruecolor($thumb_w, $thumb_h);
     if ($img_type == 'png') {
         imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $ori_width, $ori_height);
     } else {
         imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $ori_width, $ori_height);
     }
     if ($crop && ($width != $thumb_w || $height != $thumb_h)) {
         $x = ceil(abs($thumb_w - $width) / 2);
         $y = ceil(abs($thumb_h - $height) / 2);
         $default = true;
         if ($ori_width < $width || $ori_height < $height) {
             switch (YDConfig::get('YD_FS_CROP', YD_FS_CROP_ENLARGED)) {
                 case YD_FS_CROP_UNCHANGED:
                     if ($ori_width < $width && $ori_height < $height) {
                         $crp_img = $dst_img;
                         $default = false;
                     } else {
                         if ($ori_width < $width) {
                             $x = 0;
                             $width = $ori_width;
                         } else {
                             if ($ori_height < $height) {
                                 $y = 0;
                                 $height = $ori_height;
                             }
                         }
                     }
                     break;
                 case YD_FS_CROP_ENLARGED:
                 case YD_FS_CROP_BORDERED:
                     break;
             }
         }
         if ($default) {
             $crp_img = imagecreatetruecolor($width, $height);
             if ($img_type == 'png') {
                 imagecopyresized($crp_img, $dst_img, 0, 0, $x, $y, $width, $height, $width, $height);
             } else {
                 imagecopyresampled($crp_img, $dst_img, 0, 0, $x, $y, $width, $height, $width, $height);
             }
         }
         $dst_img = $crp_img;
     }
     // Get the resulting image
     ob_start();
     if ($img_type == 'gif') {
         if (!function_exists('imagegif')) {
             imagepng($dst_img);
         } else {
             imagegif($dst_img);
         }
     } elseif ($img_type == 'png') {
         imagepng($dst_img);
     } else {
         imagejpeg($dst_img);
     }
     $image_data = ob_get_contents();
     ob_end_clean();
     // Destroy the images
     imagedestroy($dst_img);
     imagedestroy($src_img);
     // Save the cache if needed
     if ($cache == true) {
         $f = new YDFSFile($cacheFName, true);
         $f->setContents($image_data);
     }
     // Return the image data
     return $image_data;
 }
 /**
  *  This function saves the XML to a file.
  *
  *  @param $path    The path to the file. If it doesn't exist, the function will try
  *                  to create it. The file will be emptied before adding the contents.
  *  @param $pretty  (Optional) Saves the "pretty" version of the XML - with indentation.
  */
 function save($path, $pretty = true)
 {
     include_once YD_DIR_HOME_CLS . '/YDFileSystem.php';
     $file = new YDFSFile($path, true);
     $file->setContents($this->toString($pretty));
 }
 function downloadFile($file)
 {
     YDUpdateLog::info('Downloading: ' . YDUpdateTools::shortPath($file));
     $url = new YDUrl(YDConfig::get('chkoutUrl') . $file);
     $data = $url->getContents(false);
     if (strpos($data, 'Index of') === false) {
         $f = new YDFSFile(YDUpdateTools::tempPath($file), true);
         $f->setContents($data);
     }
 }
 /**
  *  This function returns the string or the file with the database dump
  *
  *  @param $file        Returns a YDFile or a string
  *  @param $separator   Separator to use in the end of each insert statement
  *
  *  @returns            A YDFile object or a string with the contents
  */
 function backup($file = false, $separator = ";")
 {
     // add two new lines to separator
     $separator .= "\n\n";
     // initialize string to record all queries
     $content = '';
     // get tables
     $tables = $this->_getTables();
     // cycle tables to retrieve structure and data
     foreach ($tables as $table) {
         // drop table
         $content .= $this->_getTableDrop($table, $separator);
         // get table structure information
         $content .= $this->_getTableStructure($table, $separator);
         // get table data
         $content .= $this->_getTableData($table, $separator);
     }
     // return the content if we don't want to download
     if ($file == false) {
         return $content;
     }
     // include filesystem functions
     include_once dirname(__FILE__) . '/../../YDClasses/YDFileSystem.php';
     // create file object
     $file = new YDFSFile($this->filepath, true);
     // put content into file
     $file->setContents($content);
     // return file
     return $file;
 }
 /**
  *  This function returns the string or the file with the database dump
  *
  *  @param $file        Returns a YDFile or a string
  *  @param $separator   Separator to use in the end of each insert statement
  *
  *  @returns            A YDFile object or a string with the contents
  */
 function backup($file = false, $separator = ";")
 {
     // add two new lines to separator
     $separator .= "\n\n";
     // initialize string to record all queries
     $content = '';
     // get tables
     $tables = $this->_getTables();
     // add header if we want comments
     if ($this->useComments) {
         $content .= "\n--\n-- " . YD_FW_NAMEVERS . " mySQL backup addon v" . $this->_version . "\n--";
         $content .= "\n-- Host : " . $this->dbinstance->getHost() . ", Database : " . $this->dbinstance->getDatabase() . "\n--";
         $content .= "\n-- Server : " . $this->dbinstance->getServerVersion() . "\n--";
     }
     // cycle tables to retrieve structure and data
     foreach ($tables as $table) {
         // drop table
         if ($this->useDrops) {
             $content .= $this->_getTableDrop($table, $separator);
         }
         // get table structure information
         if ($this->useStructure) {
             $content .= $this->_getTableStructure($table, $separator);
         }
         // get table data
         if ($this->useData) {
             $content .= $this->_getTableData($table, $separator);
         }
     }
     // return the content if we don't want to download
     if ($file == false) {
         return $content;
     }
     // create file object
     $file = new YDFSFile($this->filepath, true);
     // put content into file
     $file->setContents($content);
     // return file
     return $file;
 }
 /**
  *	This function will do the actual work of creating a thumbnail image.
  *
  *	@param $width	The maximum width of the thumbnail.
  *	@param $height	The maximum height of the thumbnail.
  *	@param $cache	(optional) Indicate if the thumbnails should be cached. By default, caching is turned off.
  *
  *	@internal
  */
 function &_createThumbnail($width, $height, $cache = true)
 {
     // Check if the GD library is loaded.
     if (!extension_loaded('gd')) {
         $this->_error('YD_gd_not_installed');
     }
     // Width and height should be positive integer
     if ($width < 1 || $width < 1) {
         $this->_error();
     }
     // Get the cache filename
     $cacheFName = YD_DIR_TEMP . '/' . $this->_createThumbnailName($width, $height);
     // Check if caching is enabled
     if ($cache === true) {
         // Output the cached version if any
         if (is_file($cacheFName)) {
             // Create a new image for the cache file
             $img = new YDFSImage($cacheFName);
             // Set the content type
             header('Content-type: ' . $img->getMimeType());
             // Output the image
             readfile($cacheFName);
             die;
         }
     }
     // Check the extension
     $img_type = $this->isImage();
     // Open the source image
     if ($img_type == 'gif') {
         if (!function_exists('imagecreatefromgif')) {
             $this->_error();
         }
         $src_img = imagecreatefromgif($this->getAbsolutePath());
     } elseif ($img_type == 'png') {
         $src_img = imagecreatefrompng($this->getAbsolutePath());
     } else {
         $src_img = imagecreatefromjpeg($this->getAbsolutePath());
     }
     // Get the current image size
     $ori_width = imageSX($src_img);
     $ori_heigth = imageSY($src_img);
     // Calculate the new image size
     if ($width >= $ori_width || $height >= $ori_heigth) {
         $thumb_w = $ori_width;
         $thumb_h = $ori_heigth;
     } else {
         if ($ori_width > $ori_heigth) {
             $thumb_w = $width;
             $thumb_h = $ori_heigth * ($width / $ori_width);
         }
         if ($ori_width < $ori_heigth) {
             $thumb_w = $ori_width * ($height / $ori_heigth);
             $thumb_h = $height;
         }
         if ($ori_width == $ori_heigth) {
             $thumb_w = $width;
             $thumb_h = $height;
         }
     }
     // Resample the image
     $dst_img = imagecreatetruecolor($thumb_w, $thumb_h);
     if ($img_type == 'png') {
         imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $ori_width, $ori_heigth);
     } else {
         imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $ori_width, $ori_heigth);
     }
     // Get the resulting image
     ob_start();
     if ($img_type == 'gif') {
         if (!function_exists('imagegif')) {
             imagepng($dst_img);
         } else {
             imagegif($dst_img);
         }
     } elseif ($img_type == 'png') {
         imagepng($dst_img);
     } else {
         imagejpeg($dst_img);
     }
     $image_data = ob_get_contents();
     ob_end_clean();
     // Destroy the images
     imagedestroy($dst_img);
     imagedestroy($src_img);
     // Save the cache if needed
     if ($cache == true) {
         $f = new YDFSFile($cacheFName, true);
         $f->setContents($image_data);
     }
     // Return the image data
     return $image_data;
 }
 function saveConfig($values)
 {
     // Construct the new config text
     $cfg = '<?php' . "\n\n";
     $cfg .= '    // Do not edit this file manually!' . "\n";
     $cfg .= '    // Only edit this file using the admin tools!' . "\n\n";
     // Loop over the config values
     foreach ($values as $key => $val) {
         // Ignore items starting with an underscore
         if (substr($key, 0, 1) != '_') {
             // Escape strings
             $key = str_replace("'", "\\'", $key);
             $val = str_replace("'", "\\'", $val);
             // Fix boolean values
             if ($key == 'email_new_comment') {
                 $val = $val == 'on' ? true : false;
             }
             // Don't enclose numeric values with quotes
             if (is_bool($val)) {
                 $val = $val ? 'true' : 'false';
                 $cfg .= "    YDConfig::set( '" . $key . "', " . $val . " );\n";
             } elseif (is_numeric($val)) {
                 $cfg .= "    YDConfig::set( '" . $key . "', " . $val . " );\n";
             } else {
                 $cfg .= "    YDConfig::set( '" . $key . "', '" . $val . "' );\n";
             }
         }
     }
     $cfg .= "\n" . '?>';
     // Open the config file
     $file = new YDFSFile(dirname(__FILE__) . '/../include/config.php');
     $file->setContents($cfg);
 }