function actionDefault()
 {
     // Test the formatting of filesizes
     $filesizes = array('1152921504606846977', '1125899906842625', '1099511627777', '75715455455', '1048577', '6543', '42');
     // Format the filesizes
     foreach ($filesizes as $filesize) {
         YDDebugUtil::dump(YDStringUtil::formatFileSize($filesize), 'Formatting filesize: ' . $filesize);
     }
     // Test the formatDate function
     YDDebugUtil::dump(YDStringUtil::formatDate(time(), 'date'), 'Formatting date - date');
     YDDebugUtil::dump(YDStringUtil::formatDate(time(), 'time'), 'Formatting date - time');
     YDDebugUtil::dump(YDStringUtil::formatDate(time(), 'datetime'), 'Formatting date - datetime');
     YDDebugUtil::dump(YDStringUtil::formatDate(time(), '%x'), 'Formatting date - %x');
     // Test the encode string function
     $string = 'Pieter Claerhout @ creo.com "générales obsolète"';
     YDDebugUtil::dump(YDStringUtil::encodeString($string), 'Encoding: ' . $string);
     // Test the truncate function
     YDDebugUtil::dump(YDStringUtil::truncate($string), 'Truncate (default): ' . $string);
     YDDebugUtil::dump(YDStringUtil::truncate($string, 20), 'Truncate (20): ' . $string);
     YDDebugUtil::dump(YDStringUtil::truncate($string, 20, ' [more]'), 'Truncate (20/more): ' . $string);
     YDDebugUtil::dump(YDStringUtil::truncate($string, 20, ' [more]', true), 'Truncate (20/more/true): ' . $string);
     // Test the normalizing of newlines
     $string = "line1\nline2\rline3\r\nline4";
     YDDebugUtil::dump(explode("\n", $string), 'Original string');
     YDDebugUtil::dump(explode(YD_CRLF, YDStringUtil::normalizeNewlines($string)), 'normalizeNewlines');
     // Test the normalizing of newlines
     $string = "  line1  \n  line2  \r  line3  \r\n  line4  ";
     YDDebugUtil::dump(YDStringUtil::removeWhiteSpace($string), 'removeWhiteSpace');
     // Test the normalizing of newlines
     $string = ' [pieter] ë @test.tpl ';
     YDDebugUtil::dump(YDStringUtil::stripSpecialCharacters($string), 'stripSpecialCharacters');
 }
Ejemplo n.º 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
             $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);
 }
 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']);
 }
 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']);
 }