当前位置: 首页>>代码示例>>PHP>>正文


PHP SpoonFile::getExtension方法代码示例

本文整理汇总了PHP中SpoonFile::getExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP SpoonFile::getExtension方法的具体用法?PHP SpoonFile::getExtension怎么用?PHP SpoonFile::getExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SpoonFile的用法示例。


在下文中一共展示了SpoonFile::getExtension方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: parse

 /**
  * Parse the correct messages into the template
  */
 protected function parse()
 {
     parent::parse();
     // grab the error-type from the parameters
     $errorType = $this->getParameter('type');
     // set correct headers
     switch ($errorType) {
         case 'module-not-allowed':
         case 'action-not-allowed':
             SpoonHTTP::setHeadersByCode(403);
             break;
         case 'not-found':
             SpoonHTTP::setHeadersByCode(404);
             break;
     }
     // querystring provided?
     if ($this->getParameter('querystring') !== null) {
         // split into file and parameters
         $chunks = explode('?', $this->getParameter('querystring'));
         // get extension
         $extension = SpoonFile::getExtension($chunks[0]);
         // if the file has an extension it is a non-existing-file
         if ($extension != '' && $extension != $chunks[0]) {
             // set correct headers
             SpoonHTTP::setHeadersByCode(404);
             // give a nice error, so we can detect which file is missing
             echo 'Requested file (' . htmlspecialchars($this->getParameter('querystring')) . ') not found.';
             // stop script execution
             exit;
         }
     }
     // assign the correct message into the template
     $this->tpl->assign('message', BL::err(SpoonFilter::toCamelCase(htmlspecialchars($errorType), '-')));
 }
开发者ID:nickmancol,项目名称:forkcms-rhcloud,代码行数:37,代码来源:index.php

示例2: isAllowedExtension

 /**
  * Checks if the extension is allowed.
  *
  * @return	bool
  * @param	array $extensions			The allowed extensions.
  * @param	string[optional] $error		The error message to set.
  */
 public function isAllowedExtension(array $extensions, $error = null)
 {
     // file has been uploaded
     if ($this->isFilled()) {
         // search for extension
         $return = in_array(strtolower(SpoonFile::getExtension($_FILES[$this->attributes['name']]['name'])), $extensions);
         // add error if needed
         if (!$return && $error !== null) {
             $this->setError($error);
         }
         // return
         return $return;
     } else {
         // add error if needed
         if ($error !== null) {
             $this->setError($error);
         }
         // return
         return false;
     }
 }
开发者ID:sunkangtaichi,项目名称:library,代码行数:28,代码来源:file.php

示例3: getTree

 /**
  * Get the filetree
  *
  * @param string $path The path to get the filetree for.
  * @param array[optional] $tree An array to hold the results.
  * @return array
  */
 private static function getTree($path, array $tree = array())
 {
     // paths that should be ignored
     $ignore = array(BACKEND_CACHE_PATH, BACKEND_CORE_PATH . '/js/ckeditor', BACKEND_CACHE_PATH, BACKEND_CORE_PATH . '/js/ckfinder', FRONTEND_CACHE_PATH);
     // get modules
     $modules = BackendModel::getModules();
     // get the folder listing
     $items = SpoonDirectory::getList($path, true, array('.svn', '.git'));
     // already in the modules?
     if (substr_count($path, '/modules/') > 0) {
         // get last chunk
         $start = strpos($path, '/modules') + 9;
         $end = strpos($path, '/', $start + 1);
         if ($end === false) {
             $moduleName = substr($path, $start);
         } else {
             $moduleName = substr($path, $start, $end - $start);
         }
         // don't go any deeper
         if (!in_array($moduleName, $modules)) {
             return $tree;
         }
     }
     foreach ($items as $item) {
         // if the path should be ignored, skip it
         if (in_array($path . '/' . $item, $ignore)) {
             continue;
         }
         // if the item is a directory we should index it also (recursive)
         if (is_dir($path . '/' . $item)) {
             $tree = self::getTree($path . '/' . $item, $tree);
         } else {
             // if the file has an extension that has to be processed add it into the tree
             if (in_array(SpoonFile::getExtension($item), array('js', 'php', 'tpl'))) {
                 $tree[] = $path . '/' . $item;
             }
         }
     }
     return $tree;
 }
开发者ID:naujasdizainas,项目名称:forkcms,代码行数:47,代码来源:model.php

示例4: validateForm

 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // get the status
         $status = SpoonFilter::getPostValue('status', array('active', 'draft'), 'active');
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         $this->frm->getField('text')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('publish_on_date')->isValid(BL::err('DateIsInvalid'));
         $this->frm->getField('publish_on_time')->isValid(BL::err('TimeIsInvalid'));
         $this->frm->getField('category_id')->isFilled(BL::err('FieldIsRequired'));
         // validate meta
         $this->meta->validate();
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['revision_id'] = $this->record['revision_id'];
             // this is used to let our model know the status (active, archive, draft) of the edited item
             $item['meta_id'] = $this->meta->save();
             $item['category_id'] = (int) $this->frm->getField('category_id')->getValue();
             $item['user_id'] = $this->frm->getField('user_id')->getValue();
             $item['language'] = BL::getWorkingLanguage();
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['introduction'] = $this->frm->getField('introduction')->getValue();
             $item['text'] = $this->frm->getField('text')->getValue();
             $item['publish_on'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('publish_on_date'), $this->frm->getField('publish_on_time')));
             $item['edited_on'] = BackendModel::getUTCDate();
             $item['hidden'] = $this->frm->getField('hidden')->getValue();
             $item['allow_comments'] = $this->frm->getField('allow_comments')->getChecked() ? 'Y' : 'N';
             $item['status'] = $status;
             if ($this->imageIsAllowed) {
                 $item['image'] = $this->record['image'];
                 // the image path
                 $imagePath = FRONTEND_FILES_PATH . '/blog/images';
                 // if the image should be deleted
                 if ($this->frm->getField('delete_image')->isChecked()) {
                     // delete the image
                     SpoonFile::delete($imagePath . '/source/' . $item['image']);
                     // reset the name
                     $item['image'] = null;
                 }
                 // new image given?
                 if ($this->frm->getField('image')->isFilled()) {
                     // delete the old image
                     SpoonFile::delete($imagePath . '/source/' . $this->record['image']);
                     // build the image name
                     $item['image'] = $this->meta->getURL() . '.' . $this->frm->getField('image')->getExtension();
                     // upload the image
                     $this->frm->getField('image')->moveFile($imagePath . '/source/' . $item['image']);
                 } elseif ($item['image'] != null) {
                     // get the old file extension
                     $imageExtension = SpoonFile::getExtension($imagePath . '/source/' . $item['image']);
                     // get the new image name
                     $newName = $this->meta->getURL() . '.' . $imageExtension;
                     // only change the name if there is a difference
                     if ($newName != $item['image']) {
                         // move the old file to the new name
                         SpoonFile::move($imagePath . '/source/' . $item['image'], $imagePath . '/source/' . $newName);
                         // assign the new name to the database
                         $item['image'] = $newName;
                     }
                 }
             } else {
                 $item['image'] = null;
             }
             // update the item
             $item['revision_id'] = BackendBlogModel::update($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item));
             // recalculate comment count so the new revision has the correct count
             BackendBlogModel::reCalculateCommentCount(array($this->id));
             // save the tags
             BackendTagsModel::saveTags($item['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             // active
             if ($item['status'] == 'active') {
                 // edit search index
                 BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['title'], 'text' => $item['text']));
                 // ping
                 if (BackendModel::getModuleSetting($this->URL->getModule(), 'ping_services', false)) {
                     BackendModel::ping(SITE_URL . BackendModel::getURLForBlock($this->URL->getModule(), 'detail') . '/' . $this->meta->getURL());
                 }
                 // build URL
                 $redirectUrl = BackendModel::createURLForAction('index') . '&report=edited&var=' . urlencode($item['title']) . '&id=' . $this->id . '&highlight=row-' . $item['revision_id'];
             } elseif ($item['status'] == 'draft') {
                 // everything is saved, so redirect to the edit action
                 $redirectUrl = BackendModel::createURLForAction('edit') . '&report=saved-as-draft&var=' . urlencode($item['title']) . '&id=' . $item['id'] . '&draft=' . $item['revision_id'] . '&highlight=row-' . $item['revision_id'];
             }
             // append to redirect URL
             if ($this->categoryId != null) {
                 $redirectUrl .= '&category=' . $this->categoryId;
             }
             // everything is saved, so redirect to the overview
             $this->redirect($redirectUrl);
//.........这里部分代码省略.........
开发者ID:naujasdizainas,项目名称:forkcms,代码行数:101,代码来源:edit.php

示例5: addAttachment

 /**
  * Adds an attachment to the headers.
  *
  * @param	string $filename				The path to (including the filename for) the attachment.
  * @param	string[optional] $newName		The new name of the attachment.
  * @param	string[optional] $disposition	The disposition of the attachment. Can be 'attachment' or 'inline'.
  * @param	string[optional] $encoding		The attachment encoding (only base64 for now).
  */
 public function addAttachment($filename, $newName = null, $disposition = 'attachment', $encoding = 'base64')
 {
     // check input
     if (!SpoonFile::exists($filename)) {
         throw new SpoonEmailException('File not found.');
     }
     // no name was found in the input
     if (empty($newName)) {
         // use the source file's base name
         $newName = basename($filename);
     }
     // store file extension
     $extension = SpoonFile::getExtension($newName);
     // store attachment disposition
     $disposition = SpoonFilter::getValue($disposition, array('attachment', 'inline'), 'attachment');
     // store type according to disposition
     if ($disposition === 'attachment') {
         $extension = 'default';
     }
     // store file info
     $this->attachments[] = array('file' => $filename, 'name' => $newName, 'encoding' => $encoding, 'type' => $this->getAttachmentContentType($extension), 'disposition' => $disposition, 'data' => chunk_split(base64_encode(SpoonFile::getContent($filename))));
 }
开发者ID:richsage,项目名称:forkcms,代码行数:30,代码来源:email.php

示例6: parseToFile

 /**
  * Saves the image to a file (quality is only used for jpg images).
  *
  * @return	bool						True if the image was saved, false if not.
  * @param	string $filename			The path where the image should be saved.
  * @param	int[optional] $quality		The quality to use (only applies on jpg-images).
  * @param	int[optional] $chmod		Mode that should be applied on the file.
  */
 public function parseToFile($filename, $quality = 100, $chmod = 0666)
 {
     // redefine vars
     $filename = (string) $filename;
     $quality = (int) $quality;
     //
     if (@is_writable(dirname($filename)) !== true) {
         // does the folder exist? if not, try to create
         if (!SpoonDirectory::create(dirname($filename))) {
             if ($this->strict) {
                 throw new SpoonThumbnailException('The destination-path should be writable.');
             }
             return false;
         }
     }
     // get extension
     $extension = SpoonFile::getExtension($filename);
     // invalid quality
     if (!SpoonFilter::isBetween(1, 100, $quality)) {
         // strict?
         if ($this->strict) {
             throw new SpoonThumbnailException('The quality should be between 1 - 100');
         }
         return false;
     }
     // invalid extension
     if (SpoonFilter::getValue($extension, array('gif', 'jpeg', 'jpg', 'png'), '') == '') {
         if ($this->strict) {
             throw new SpoonThumbnailException('Only gif, jpeg, jpg or png are allowed types.');
         }
         return false;
     }
     // get current dimensions
     $imageProperties = @getimagesize($this->filename);
     // validate imageProperties
     if ($imageProperties === false) {
         // strict?
         if ($this->strict) {
             throw new SpoonThumbnailException('The sourcefile "' . $this->filename . '" could not be found.');
         }
         return false;
     }
     // set current dimensions
     $currentWidth = (int) $imageProperties[0];
     $currentHeight = (int) $imageProperties[1];
     $currentType = (int) $imageProperties[2];
     $currentMime = (string) $imageProperties['mime'];
     // file is the same?
     if ($currentType == IMAGETYPE_GIF && $extension == 'gif' || $currentType == IMAGETYPE_JPEG && in_array($extension, array('jpg', 'jpeg')) || $currentType == IMAGETYPE_PNG && $extension == 'png') {
         if ($currentWidth == $this->width && $currentHeight == $this->height) {
             return SpoonDirectory::copy($this->filename, $filename, true, true, $chmod);
         }
     }
     // resize image
     $this->resizeImage($currentWidth, $currentHeight, $currentType, $currentMime);
     // output to file
     switch (strtolower($extension)) {
         case 'gif':
             $return = @imagegif($this->image, $filename);
             break;
         case 'jpeg':
         case 'jpg':
             $return = @imagejpeg($this->image, $filename, $quality);
             break;
         case 'png':
             $return = @imagepng($this->image, $filename);
             break;
     }
     // chmod
     @chmod($filename, $chmod);
     // cleanup memory
     @imagedestroy($this->image);
     // return success
     return (bool) $return;
 }
开发者ID:sunkangtaichi,项目名称:library,代码行数:83,代码来源:thumbnail.php

示例7: validateForm

 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validation
         $fields = $this->frm->getFields();
         //			$fields['name']->isFilled(BL::err('FieldIsRequired'));
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             $item['meta_id'] = $this->meta->save();
             $item['company'] = $fields['company']->getValue();
             $item['name'] = $fields['name']->getValue();
             $item['firstname'] = $fields['firstname']->getValue();
             $item['email'] = $fields['email']->getValue();
             $item['address'] = $fields['address']->getValue();
             $item['zipcode'] = $fields['zipcode']->getValue();
             $item['city'] = $fields['city']->getValue();
             $item['country'] = $fields['country']->getValue();
             $item['phone'] = $fields['phone']->getValue();
             $item['fax'] = $fields['fax']->getValue();
             $item['website'] = str_replace("http://", "", $fields['website']->getValue());
             $item['zipcodes'] = $fields['zipcodes']->getValue();
             $item['remark'] = $fields['remark']->getValue();
             //$item['text'] = $fields['text']->getValue();
             //$item['assort'] = $fields['assort']->getValue();
             //$item['open'] = $fields['open']->getValue();
             //$item['closed'] = $fields['closed']->getValue();
             //$item['visit'] = $fields['visit']->getValue();
             //$item['size'] = $fields['size']->getValue();
             $item['language'] = BL::getWorkingLanguage();
             $item['hidden'] = $fields['hidden']->getValue();
             if ($item['country'] == '') {
                 $item['country'] = 'BE';
             }
             //--Create url
             $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($item['address'] . ', ' . $item['zipcode'] . ' ' . $item['city'] . ', ' . \SpoonLocale::getCountry($item['country'], BL::getWorkingLanguage())) . '&sensor=false';
             //--Get lat
             $geocode = json_decode(\SpoonHTTP::getContent($url));
             //--Sleep between the requests
             sleep(0.05);
             //--Check result
             $item['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null;
             $item['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null;
             $item['image'] = $this->record['image'];
             // the image path
             $imagePath = FRONTEND_FILES_PATH . '/Addresses/Images';
             // create folders if needed
             if (!\SpoonDirectory::exists($imagePath . '/Source')) {
                 \SpoonDirectory::create($imagePath . '/Source');
             }
             if (!\SpoonDirectory::exists($imagePath . '/128x128')) {
                 \SpoonDirectory::create($imagePath . '/128x128');
             }
             if (!\SpoonDirectory::exists($imagePath . '/400x300')) {
                 \SpoonDirectory::create($imagePath . '/400x300');
             }
             if (!\SpoonDirectory::exists($imagePath . '/800x')) {
                 \SpoonDirectory::create($imagePath . '/800x');
             }
             // if the image should be deleted
             if ($this->frm->getField('delete_image')->isChecked()) {
                 // delete the image
                 \SpoonFile::delete($imagePath . '/Source/' . $item['image']);
                 // reset the name
                 $item['image'] = null;
             }
             // new image given?
             if ($this->frm->getField('image')->isFilled()) {
                 // delete the old image
                 \SpoonFile::delete($imagePath . '/Source/' . $this->record['image']);
                 // build the image name
                 $item['image'] = $this->meta->getURL() . '.' . $this->frm->getField('image')->getExtension();
                 // upload the image & generate thumbnails
                 $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']);
             } elseif ($item['image'] != null) {
                 // get the old file extension
                 $imageExtension = \SpoonFile::getExtension($imagePath . '/Source/' . $item['image']);
                 // get the new image name
                 $newName = $this->meta->getURL() . '.' . $imageExtension;
                 // only change the name if there is a difference
                 if ($newName != $item['image']) {
                     // loop folders
                     foreach (BackendModel::getThumbnailFolders($imagePath, true) as $folder) {
                         // move the old file to the new name
                         \SpoonFile::move($folder['path'] . '/' . $item['image'], $folder['path'] . '/' . $newName);
                     }
                     // assign the new name to the database
                     $item['image'] = $newName;
                 }
             }
             BackendAddressesModel::update($this->id, $item);
             $item['id'] = $this->id;
             //--Add the languages
             foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) {
                 $itemLanguage = array();
                 $itemLanguage['id'] = $item['id'];
                 $itemLanguage['language'] = $language;
//.........这里部分代码省略.........
开发者ID:Comsa-Veurne,项目名称:modules,代码行数:101,代码来源:Edit.php

示例8: array

    private $attachments = array();
    /**
	 * BCC storage
	 *
	 * @var	array
	 */
    private $BCC = array();
    /**
	 * CC storage
	 *
	 * @var	array
	 */
    private $CC = array();
    /**
	 * Charset
	 *
	 * @var string
	 */
    private $charset = 'utf-8';
    /**
	 * Template compile directory
	 *
	 * @var string
	 */
    private $compileDirectory;
    /**
	 * Email content storage
开发者ID:ss23,项目名称:ECommerce,代码行数:27,代码来源:email.php


注:本文中的SpoonFile::getExtension方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。