コード例 #1
0
 function actionAdd()
 {
     // We return to the default action
     $action = 'default';
     // Process the form
     if ($this->form->validate()) {
         // Move the uploaded file
         $file = $this->form->getElement('image');
         if ($file->isUploaded()) {
             // Get the new filename
             $filename = YDStringUtil::stripSpecialCharacters($file->getBaseName());
             // Move the upload
             $file->moveUpload($this->dir_rel, $filename);
             // Check if it's an image
             $fileObj = new YDFSFile($this->dir_rel . $file->getBaseName());
             if (!$fileObj->isImage()) {
                 @unlink($this->dir_rel . $file->getBaseName());
             }
             // Create the thumbnails
             $thumb = new YDFSImage($this->dir_rel . $file->getBaseName());
             $thumb->_createThumbnail(100, 100, true);
             $thumb->_createThumbnail(48, 48, true);
         }
         // Get the name of the action
         $action = $this->form->getValue('action');
     }
     // Redirect to the list view
     $destination = YD_SELF_SCRIPT . '?do=' . $action;
     if (isset($_GET['field'])) {
         $destination .= '&field=' . $_GET['field'];
     }
     $this->redirect($destination);
 }
コード例 #2
0
 function actionAdd()
 {
     // We return to the default action
     $action = 'default';
     // Process the form
     if ($this->form->validate()) {
         // Move the uploaded file
         $file = $this->form->getElement('image');
         if ($file->isUploaded()) {
             // Get the new filename
             $filename = YDStringUtil::stripSpecialCharacters($file->getBaseName());
             // Move the upload
             if (!is_dir($this->dir_rel)) {
                 @mkdir($this->dir_rel);
             }
             $file->moveUpload($this->dir_rel, $filename);
             // Check if it's an image
             $fileObj = new YDFSFile($this->dir_rel . $file->getBaseName());
             if (!$fileObj->isImage()) {
                 @unlink($this->dir_rel . $file->getBaseName());
             }
             // Delete the thumbnails
             @unlink($this->dir_rel . 's_' . $file->getBaseName());
             @unlink($this->dir_rel . 'm_' . $file->getBaseName());
         }
     }
     // Redirect to the list view
     $this->redirect(YD_SELF_SCRIPT . '?id=' . $this->item['id']);
 }
コード例 #3
0
 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());
 }
コード例 #4
0
 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;
 }
コード例 #5
0
 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>';
 }
コード例 #6
0
 function actionAdd()
 {
     // We return to the default action
     $action = 'default';
     // Process the form
     if ($this->form->validate()) {
         // Move the uploaded file
         $file = $this->form->getElement('image');
         if ($file->isUploaded()) {
             // Get the new filename
             $filename = YDStringUtil::stripSpecialCharacters($file->getBaseName());
             // Move the upload
             if (!is_dir($this->dir_rel)) {
                 @mkdir($this->dir_rel);
             }
             @$file->moveUpload($this->dir_rel, $filename);
             // Convert it to an object
             $fileObj = new YDFSFile($this->dir_rel . $file->getBaseName());
             // Check if it's a ZIP file
             if (strtolower($fileObj->getExtension() == 'zip')) {
                 // Include the unzip library
                 include YD_DIR_HOME . '/3rdparty/zip/unzip.lib.php';
                 // Convert it to a ZIP object
                 $zip = new SimpleUnzip($fileObj->getAbsolutePath());
                 // Get the directory as a path
                 $dir = new YDFSDirectory($this->dir_rel);
                 // Extract the images
                 foreach ($zip->Entries as $entry) {
                     // Save it as a filee
                     $entryFile = $dir->createFile($entry->Name, $entry->Data);
                     // Delete it if it's not an image
                     if (!$entryFile->isImage()) {
                         @unlink($entryFile->getAbsolutePath());
                     } else {
                         $entryFile = $this->weblog->resizeUploadedImage($entryFile);
                     }
                 }
             }
             // Check if it's an image
             if (!$fileObj->isImage()) {
                 @unlink($fileObj->getAbsolutePath());
             } else {
                 $fileObj = $this->weblog->resizeUploadedImage($fileObj);
             }
             // Delete the thumbnails
             @unlink($this->dir_rel . 's_' . $file->getBaseName());
             @unlink($this->dir_rel . 'm_' . $file->getBaseName());
         }
     }
     // Redirect to the list view
     $this->redirect(YD_SELF_SCRIPT . '?id=' . $this->item['id']);
 }
コード例 #7
0
 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');
 }
コード例 #8
0
 /**
  *	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;
 }
コード例 #9
0
 /**
  *  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));
 }
コード例 #10
0
 function actionDownload2()
 {
     $file = new YDFSFile(__FILE__);
     $file->download('download_test.php');
 }
コード例 #11
0
 /**
  *  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;
 }
コード例 #12
0
 function actionDownload()
 {
     $file = new YDFSFile(__FILE__);
     $file->download();
 }
コード例 #13
0
 function actionDownloadInline()
 {
     $file = new YDFSFile(__FILE__);
     $file->download('download_test.txt', true);
 }
コード例 #14
0
 /**
  *	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);
     }
     if (empty($name)) {
         $name = $file->getBaseName();
     }
     $this->_msg->AddAttachment($file->getAbsolutePath(), $name, 'base64', $c_type);
 }
コード例 #15
0
 /**
  *	This function will create a new file in the current directory, and will write the specified contents to the
  *	file. Once finished, it will return a new YDFSFile object pointing to the file. All directory paths are 
  *	relative to the current directory.
  *
  *	@param $filename	The filename of the new file.
  *	@param $contents	The contents of the new file.
  *
  *	@returns	YDFSFile or YDFSImage object pointing to the new file.
  */
 function createFile($filename, $contents)
 {
     // Set the directory of this object as the working directory
     chdir($this->getPath());
     // Create the new file
     $fp = fopen($filename, 'wb');
     // Save the contents to the file
     $result = fwrite($fp, $contents);
     // Check for errors
     if ($result == false) {
         trigger_error('Failed writing to the file "' . $file . '" in the directory called "' . $this->getPath() . '".', YD_ERROR);
     }
     // Close the file
     fclose($fp);
     // Create the YDFSFile object
     $obj = new YDFSFile($filename);
     // Check if it's an image
     if ($obj->isImage()) {
         $obj = new YDFSImage($filename);
     }
     // Return the file object
     return $obj;
 }
コード例 #16
0
 /**
  *	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);
 }
コード例 #17
0
 /**
  *  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;
 }
コード例 #18
0
 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);
     }
 }
コード例 #19
0
 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);
 }