/**
  *  This function will move the uploaded file to the specified directory.
  *
  *  @param $dir (optional) The directory to move the file to. Defaults to the current directory.
  *  @param $fname (optional) File name to use. Prevents e.g. the file hits the FS with unwanted chars in it
  *  @param $retainExt (optional) Retain file name extension or not
  *  @returns  Boolean indicating if the move was succesful or not.
  */
 function moveUpload($dir = '.', $fname = '', $retainExt = false)
 {
     if (filesize($_FILES[$this->_form . '_' . $this->_name]['tmp_name']) == 0) {
         return false;
     }
     // Fetch extension if it is to be retained, set empty if otherwise
     $retainExt and $ext = '.' . YDPath::getExtension($_FILES[$this->_form . '_' . $this->_name]['name']) or $ext = '';
     // Create (new) file name
     $fname = $fname == '' ? $_FILES[$this->_form . '_' . $this->_name]['name'] : $fname . $ext;
     // Compile path
     $path = realpath($dir) . '/' . $fname;
     // Move file to temp location
     // plz point out in the docs this dir is _temporary_, as it is automatically made 0777!
     $result = move_uploaded_file($_FILES[$this->_form . '_' . $this->_name]['tmp_name'], $path);
     @chmod(realpath($dir), 0700);
     @chmod($path, 0700);
     // Provide an interface to some more useful information on the file
     $this->fileo = new YDFSFile($path);
     return $result;
 }
 function actionC()
 {
     $this->addHeader('Copying files...');
     $this->setSourceDirectory('new_files');
     $this->setTargetDirectory(YDPath::join($this->_target_dir, $this->target_dir));
     $res = $this->copyDirectory('sub', false);
     $res2 = $this->copyDirectory('sub2');
     $res3 = $this->copyFileByPattern('*.*');
     $res4 = $this->deleteDirectory('sub3');
     $res5 = $this->deleteFileByPattern('*.bmp');
     $res6 = $this->createDirectory('sub4');
     $res7 = $this->deleteDirectory('sub4');
     $results = array_merge($res, $res2, $res3, $res4, $res5, $res6, $res7);
     $this->addText(YDInstaller::getReport($results));
     $this->addSeparator();
     $this->addNavButtons('Continue');
     $this->setField('installed', true);
     if ($this->isValid()) {
         $this->goTo('D');
     }
     $this->display();
 }
 function actionDefault()
 {
     YDDebugUtil::dump(YDPath::getDirectorySeparator(), 'getDirectorySeparator()');
     YDDebugUtil::dump(YDPath::getPathSeparator(), 'getPathSeparator()');
     YDDebugUtil::dump(YDPath::getVolumeSeparator(), 'getVolumeSeparator()');
     YDDebugUtil::dump(YDPath::changeExtension(__FILE__, '.tpl'), 'changeExtension( __FILE__, ".tpl" )');
     YDDebugUtil::dump(YDPath::getDirectoryName(__FILE__), 'getDirectoryName( __FILE__ )');
     YDDebugUtil::dump(YDPath::getExtension(__FILE__), 'getExtension( __FILE__ )');
     YDDebugUtil::dump(YDPath::getFileName(__FILE__), 'getFileName( __FILE__ )');
     YDDebugUtil::dump(YDPath::getFileNameWithoutExtension(__FILE__), 'getFileNameWithoutExtension( __FILE__ )');
     YDDebugUtil::dump(YDPath::getFilePath(__FILE__), 'getFilePath( __FILE__ )');
     YDDebugUtil::dump(YDPath::getFilePathWithoutExtension(__FILE__), 'getFilePathWithoutExtension( __FILE__ )');
     YDDebugUtil::dump(YDPath::getFullPath(__FILE__), 'getFullPath( __FILE__ )');
     YDDebugUtil::dump(YDPath::getTempFileName(), 'getTempFileName()');
     YDDebugUtil::dump(YDPath::getTempPath(), 'getTempPath()');
     YDDebugUtil::dump(YDPath::hasExtension(__FILE__), 'hasExtension( __FILE__ )');
     YDDebugUtil::dump(YDPath::hasExtension(YDPath::getFileNameWithoutExtension(__FILE__)), 'hasExtension( YDPath::getFileNameWithoutExtension( __FILE__ ) )');
     YDDebugUtil::dump(YDPath::isAbsolute(__FILE__), 'isAbsolute( __FILE__ )');
     YDDebugUtil::dump(YDPath::isAbsolute(YDPath::getFileName(__FILE__)), 'isAbsolute( getFileName( __FILE__ ) )');
     YDDebugUtil::dump(YDPath::join(__FILE__), 'join( __FILE__ )');
     YDDebugUtil::dump(YDPath::join(YDPath::getTempPath(), YDPath::getFileName(__FILE__)), 'join( getTempPath(), getFileName( __FILE__ ) )');
     YDDebugUtil::dump(YDPath::join(YDPath::getTempPath(), __FILE__), 'join( getTempPath(), __FILE__ )');
 }
 /**
  *	This rule checks if a file upload has the right file extension (case insensitive). 
  *
  *	@param $val			The value to test.
  *	@param $opts		The file extension it should match (can also be an array of extensions).
  *	@param $formelement	(not required)
  */
 function extension($val, $opts, $formelement = null)
 {
     include_once YD_DIR_HOME_CLS . '/YDFileSystem.php';
     if (!is_array($opts)) {
         $opts = array($opts);
     }
     $ext = YDPath::getExtension($val['name']);
     return YDValidateRules::i_in_array($ext, $opts);
 }
 *  @addtogroup YDFramework Core
 */
// Check if the framework is loaded
if (!defined('YD_FW_NAME')) {
    die('Yellow Duck Framework is not loaded.');
}
// Includes
include_once YD_DIR_HOME_CLS . '/YDFileSystem.php';
// The different log levels
@define('YD_LOG_DEBUG', 4);
@define('YD_LOG_INFO', 3);
@define('YD_LOG_WARNING', 2);
@define('YD_LOG_ERROR', 1);
// Configure the default for this class
YDConfig::set('YD_LOG_LEVEL', YD_LOG_INFO, false);
YDConfig::set('YD_LOG_FILE', YDPath::join(YD_DIR_TEMP, 'YDFramework2_log.xml'), false);
YDConfig::set('YD_LOG_FORMAT', 'XML', false);
YDConfig::set('YD_LOG_TEXTFORMAT', "%date% | %level% | %uri% | %basefile%:%line% | %function% | %message%", false);
YDConfig::set('YD_LOG_WRAPLINES', false, false);
YDConfig::set('YD_LOG_MAX_LINESIZE', 100, false);
/**
 *  This class defines the logging static functions.
 *
 *  @ingroup YDFramework
 */
class YDLog extends YDBase
{
    /**
     *	This adds a debug message to the logfile.
     *
     *	@param $text	The message to add to the logfile.
 /**
  *	This function will save the XML data to the specified file.
  *
  *	@remark
  *		The default format is "RSS2.0". If you specify no argument indicating the requested format, the "RSS2.0"
  *	format will be used.
  *
  *	@param $path	The path to save the XML data to.
  *	@param $format	(optional) The format in which the items should be converted.
  */
 function saveXml($path, $format = 'RSS2.0')
 {
     // Get the XML data
     $xml = $this->toXml($format);
     // Get the directory information
     $dir = new YDFSDirectory(YDPath::getDirectoryName($path));
     // Create the file
     $dir->createFile(YDPath::getFileName($path), $xml);
 }
 /**
  *	This function will recursively delete a directory. It will delete the directory and the complete
  *	contents of that directory! Be careful I would say!
  *
  *	@param $directory	Directory to be removed.
  *
  *	@return	Boolean indicating if the directory could be deleted or not.
  */
 function deleteDirectory($directory)
 {
     $directory = YDPath::join($this->getAbsolutePath(), $directory);
     if (!is_dir($directory)) {
         return false;
     }
     return YDFSDirectory::_delete($directory);
 }
 /**
  *	This rule checks if a file upload has the right file extension.
  *
  *	@param $val		The value to test.
  *	@param $opts	The file extension it should match (can also be an array of extensions).
  */
 function extension($val, $opts)
 {
     include_once dirname(__FILE__) . '/YDFileSystem.php';
     if (!is_array($opts)) {
         $opts = array($opts);
     }
     $ext = YDPath::getExtension($val['name']);
     return in_array($ext, $opts);
 }
 function installDbUpdate($file)
 {
     $update_name = YDPath::getFileNameWithoutExtension($file);
     YDUpdateLog::info('Performing database update: ' . $update_name);
     YDInclude(YDUpdateTools::realPath($file));
     $db = YDDatabaseTools::getConnection();
     $update_inst = new $update_name($db);
     $update_inst->update();
 }
 /**
  *	This function will get the name of the template.
  *
  *	@internal
  */
 function _getTemplateName($file = '')
 {
     if (file_exists($file)) {
         if ('.' . YDPath::getExtension($file) != YD_TPL_EXT) {
             trigger_error('The specified file ' . $file . ' is not a valid template file (wrong file extension)', YD_ERROR);
         }
         return realpath($file);
     }
     $this->template_dir = YDPath::getFullPath($this->template_dir);
     if (empty($file)) {
         $file = YDPath::getFileNameWithoutExtension(YD_SELF_FILE);
     }
     if (is_file(YDPath::join($this->template_dir, $file . YD_TPL_EXT))) {
         $tplName = $file . YD_TPL_EXT;
     } else {
         $tplName = $file;
     }
     if (!is_file(YDPath::join($this->template_dir, $tplName))) {
         trigger_error('Template not found: ' . $tplName, YD_ERROR);
     }
     return $tplName;
 }
 /**
  *  This function deletes a file or an array of files using a pattern
  *  from the target directory.
  *
  *  @param  $files  The file pattern or an array of file patterns
  *                  relative to the target directory.
  *
  *  @returns     An array with the results.
  */
 function deleteFileByPattern($files)
 {
     if (!is_array($files)) {
         $files = array($files);
     }
     $res = array();
     foreach ($files as $key => $pattern) {
         // Get the directory out of the pattern
         $pattern = str_replace('/', YDPath::getDirectorySeparator(), $pattern);
         $pattern = str_replace('\\', YDPath::getDirectorySeparator(), $pattern);
         $pos = strrpos($pattern, YDPath::getDirectorySeparator());
         $dir = '';
         if ($pos) {
             $dir = substr($pattern, 0, $pos + 1);
             $pattern = substr($pattern, $pos + 1, strlen($pattern) - $pos);
         }
         // Get the files based on the pattern
         $d = new YDFSDirectory(YDPath::join($this->_target_dir, $dir));
         $fs = $d->getContents($pattern, '', 'YDFSFile');
         // Delete the files
         foreach ($fs as $file) {
             $res = array_merge($res, $this->deleteFile(YDPath::join($dir, $file)));
         }
     }
     return $res;
 }