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


PHP modResource::cleanAlias方法代码示例

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


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

示例1: process

 /**
  * @return array|string
  */
 public function process()
 {
     if (!($data = $this->handleFile())) {
         return $this->failure($this->modx->lexicon('ms2gallery_err_gallery_ns'));
     }
     $properties = $this->mediaSource->getProperties();
     $tmp = explode('.', $data['name']);
     $extension = strtolower(end($tmp));
     $image_extensions = $allowed_extensions = array();
     if (!empty($properties['imageExtensions']['value'])) {
         $image_extensions = array_map('trim', explode(',', strtolower($properties['imageExtensions']['value'])));
     }
     if (!empty($properties['allowedFileTypes']['value'])) {
         $allowed_extensions = array_map('trim', explode(',', strtolower($properties['allowedFileTypes']['value'])));
     }
     if (!empty($allowed_extensions) && !in_array($extension, $allowed_extensions)) {
         return $this->failure($this->modx->lexicon('ms2gallery_err_gallery_ext'));
     } else {
         if (in_array($extension, $image_extensions)) {
             $type = 'image';
         } else {
             $type = $extension;
         }
     }
     $hash = sha1($data['stream']);
     if ($this->modx->getCount('msResourceFile', array('resource_id' => $this->resource->id, 'hash' => $hash, 'parent' => 0))) {
         return $this->failure($this->modx->lexicon('ms2gallery_err_gallery_exists'));
     }
     $filename = !empty($properties['imageNameType']) && $properties['imageNameType']['value'] == 'friendly' ? $this->resource->cleanAlias($data['name']) : $hash . '.' . $extension;
     $rank = isset($properties['imageUploadDir']) && empty($properties['imageUploadDir']['value']) ? 0 : $this->modx->getCount('msResourceFile', array('parent' => 0, 'resource_id' => $this->resource->id));
     /* @var msResourceFile $product_file */
     $product_file = $this->modx->newObject('msResourceFile', array('resource_id' => $this->resource->id, 'parent' => 0, 'name' => $data['name'], 'file' => $filename, 'path' => $this->resource->id . '/', 'source' => $this->mediaSource->get('id'), 'type' => $type, 'rank' => $rank, 'createdon' => date('Y-m-d H:i:s'), 'createdby' => $this->modx->user->id, 'active' => 1, 'hash' => $hash, 'properties' => $data['properties']));
     $this->mediaSource->createContainer($product_file->path, '/');
     $file = $this->mediaSource->createObject($product_file->get('path'), $product_file->get('file'), $data['stream']);
     if ($file) {
         $url = $this->mediaSource->getObjectUrl($product_file->get('path') . $product_file->get('file'));
         $product_file->set('url', $url);
         $product_file->save();
         if (empty($rank)) {
             $imagesTable = $this->modx->getTableName('msResourceFile');
             $sql = "UPDATE {$imagesTable} SET rank = rank + 1 WHERE resource_id ='" . $this->resource->id . "' AND id !='" . $product_file->get('id') . "'";
             $this->modx->exec($sql);
         }
         $generate = $product_file->generateThumbnails($this->mediaSource);
         if ($generate !== true) {
             $this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not generate thumbnails for image with id = ' . $product_file->get('id') . '. ' . $generate);
             return $this->failure($this->modx->lexicon('ms2gallery_err_gallery_thumb'));
         } else {
             return $this->success();
         }
     } else {
         return $this->failure($this->modx->lexicon('ms2gallery_err_gallery_save') . ': ' . print_r($this->mediaSource->getErrors(), 1));
     }
 }
开发者ID:sin4end,项目名称:ms2Gallery,代码行数:57,代码来源:upload.class.php

示例2: checkFriendlyAlias

 /**
  * Friendly URL alias checks
  * @return mixed|string
  */
 public function checkFriendlyAlias()
 {
     $this->isSiteStart = $this->object->get('id') == $this->workingContext->getOption('site_start') || $this->object->get('id') == $this->modx->getOption('site_start');
     $pageTitle = $this->getProperty('pagetitle', null);
     $alias = $this->getProperty('alias');
     if ($this->workingContext->getOption('friendly_urls', false) && (!$this->getProperty('reloadOnly', false) || (!empty($pageTitle) || $this->isSiteStart))) {
         /* auto assign alias */
         if (empty($alias) && ($this->isSiteStart || $this->workingContext->getOption('automatic_alias', false))) {
             if (empty($pageTitle)) {
                 $alias = 'index';
             } else {
                 $alias = $this->object->cleanAlias($pageTitle);
             }
         }
         if (empty($alias)) {
             $this->addFieldError('alias', $this->modx->lexicon('field_required'));
         }
         /* check for duplicate alias */
         $duplicateContext = $this->workingContext->getOption('global_duplicate_uri_check', false) ? '' : $this->getProperty('context_key');
         $aliasPath = $this->object->getAliasPath($alias, $this->getProperties());
         $duplicateId = $this->object->isDuplicateAlias($aliasPath, $duplicateContext);
         if (!empty($duplicateId)) {
             $err = $this->modx->lexicon('duplicate_uri_found', array('id' => $duplicateId, 'uri' => $aliasPath));
             $this->addFieldError('uri', $err);
             $uriOverride = $this->getProperty('uri_override', null);
             if ($uriOverride == null || $uriOverride !== 1) {
                 $this->addFieldError('alias', $err);
             }
         }
         $this->setProperty('alias', $alias);
     }
     return $alias;
 }
开发者ID:semencov-com,项目名称:affiliate,代码行数:37,代码来源:update.class.php

示例3: prepareAlias

 /**
  * Clean and prepare the alias, automatically generating it if the option is set
  * @return string
  */
 public function prepareAlias()
 {
     $alias = '';
     /* friendly url alias checks */
     $pageTitle = $this->getProperty('pagetitle');
     if ($this->workingContext->getOption('friendly_urls', false) && (!$this->getProperty('reloadOnly', false) || !empty($pageTitle))) {
         $alias = $this->getProperty('alias');
         /* auto assign alias */
         if (empty($alias) && $this->workingContext->getOption('automatic_alias', false)) {
             $alias = $this->object->cleanAlias($pageTitle);
         }
         if (empty($alias)) {
             $this->addFieldError('alias', $this->modx->lexicon('field_required'));
         } else {
             $duplicateContext = $this->workingContext->getOption('global_duplicate_uri_check', false) ? '' : $this->getProperty('context_key');
             $aliasPath = $this->object->getAliasPath($alias, $this->getProperties());
             $duplicateId = $this->object->isDuplicateAlias($aliasPath, $duplicateContext);
             if ($duplicateId) {
                 $err = $this->modx->lexicon('duplicate_uri_found', array('id' => $duplicateId, 'uri' => $aliasPath));
                 $this->addFieldError('uri', $err);
                 if ($this->getProperty('uri_override', 0) !== 1) {
                     $this->addFieldError('alias', $err);
                 }
             }
         }
         $this->setProperty('alias', $alias);
     }
     return $alias;
 }
开发者ID:e-gob,项目名称:apps.gob.cl,代码行数:33,代码来源:create.class.php

示例4: prepareAlias

 /**
  * Clean and prepare the alias, automatically generating it if the option is set
  * @return string
  */
 public function prepareAlias()
 {
     // The user submitted alias & page title
     $alias = $this->getProperty('alias');
     $pageTitle = $this->getProperty('pagetitle');
     $autoGenerated = false;
     // If we don't have an alias passed, and automatic_alias is enabled, we generate one from the pagetitle.
     if (empty($alias) && $this->workingContext->getOption('automatic_alias', false)) {
         $alias = $this->object->cleanAlias($pageTitle);
         $autoGenerated = true;
     }
     $friendlyUrlsEnabled = $this->workingContext->getOption('friendly_urls', false) && (!$this->getProperty('reloadOnly', false) || !empty($pageTitle));
     // Check for duplicates
     $duplicateContext = $this->workingContext->getOption('global_duplicate_uri_check', false) ? '' : $this->getProperty('context_key');
     $aliasPath = $this->object->getAliasPath($alias, $this->getProperties());
     $duplicateId = $this->object->isDuplicateAlias($aliasPath, $duplicateContext);
     // We have a duplicate!
     if ($duplicateId) {
         // If friendly urls is enabled, we throw an error about the alias
         if ($friendlyUrlsEnabled) {
             $err = $this->modx->lexicon('duplicate_uri_found', array('id' => $duplicateId, 'uri' => $aliasPath));
             $this->addFieldError('uri', $err);
             if ($this->getProperty('uri_override', 0) !== 1) {
                 $this->addFieldError('alias', $err);
             }
         } elseif ($autoGenerated) {
             $alias = '';
         }
     }
     // If the alias is empty yet friendly urls is enabled, add an error to the alias field
     if (empty($alias) && $friendlyUrlsEnabled) {
         $this->addFieldError('alias', $this->modx->lexicon('field_required'));
     }
     // Set the new alias and return it, too.
     $this->setProperty('alias', $alias);
     return $alias;
 }
开发者ID:ChrstnMgcn,项目名称:revolution,代码行数:41,代码来源:create.class.php

示例5: process

 /**
  * @return array|string
  */
 public function process()
 {
     if (!($data = $this->handleFile())) {
         return $this->failure($this->modx->lexicon('ms2gallery_err_gallery_ns'));
     }
     $properties = $this->mediaSource->getPropertyList();
     $pathinfo = $this->ms2Gallery->pathinfo($data['name']);
     $extension = strtolower($pathinfo['extension']);
     $filename = strtolower($pathinfo['filename']);
     $image_extensions = $allowed_extensions = array();
     if (!empty($properties['imageExtensions'])) {
         $image_extensions = array_map('trim', explode(',', strtolower($properties['imageExtensions'])));
     }
     if (!empty($properties['allowedFileTypes'])) {
         $allowed_extensions = array_map('trim', explode(',', strtolower($properties['allowedFileTypes'])));
     }
     if (!empty($allowed_extensions) && !in_array($extension, $allowed_extensions)) {
         return $this->failure($this->modx->lexicon('ms2gallery_err_wrong_ext'));
     } else {
         if (in_array($extension, $image_extensions)) {
             if (empty($data['properties']['height']) || empty($data['properties']['width'])) {
                 return $this->failure($this->modx->lexicon('ms2gallery_err_wrong_image'));
             }
             $type = 'image';
         } else {
             $type = $extension;
         }
     }
     if ($this->modx->getOption('ms2gallery_duplicate_check', null, true, true)) {
         if ($this->modx->getCount('msResourceFile', array('resource_id' => $this->resource->id, 'hash' => $data['hash'], 'parent' => 0))) {
             return $this->failure($this->modx->lexicon('ms2gallery_err_gallery_exists'));
         }
     }
     $filename = !empty($properties['imageNameType']) && $properties['imageNameType'] == 'friendly' ? $this->resource->cleanAlias($filename) : $data['hash'];
     $filename = str_replace(',', '', $filename) . '.' . $extension;
     $tmp_filename = $filename;
     $i = 1;
     while (true) {
         if (!($count = $this->modx->getCount('msResourceFile', array('resource_id' => $this->resource->id, 'file' => $tmp_filename, 'parent' => 0)))) {
             $filename = $tmp_filename;
             break;
         } else {
             $pcre = '#(-' . ($i - 1) . '|)\\.' . $extension . '$#';
             $tmp_filename = preg_replace($pcre, "-{$i}.{$extension}", $tmp_filename);
             $i++;
         }
     }
     $rank = isset($properties['imageUploadDir']) && empty($properties['imageUploadDir']) ? 0 : $this->modx->getCount('msResourceFile', array('parent' => 0, 'resource_id' => $this->resource->id));
     /* @var msResourceFile $uploaded_file */
     $uploaded_file = $this->modx->newObject('msResourceFile', array('resource_id' => $this->resource->id, 'parent' => 0, 'name' => preg_replace('#\\.' . $extension . '$#i', '', $data['name']), 'file' => $filename, 'path' => $this->resource->id . '/', 'source' => $this->mediaSource->get('id'), 'type' => $type, 'rank' => $rank, 'createdon' => date('Y-m-d H:i:s'), 'createdby' => $this->modx->user->id, 'active' => 1, 'hash' => $data['hash'], 'properties' => $data['properties']));
     $this->mediaSource->createContainer($uploaded_file->get('path'), '/');
     $this->mediaSource->errors = array();
     if ($this->mediaSource instanceof modFileMediaSource) {
         $upload = $this->mediaSource->createObject($uploaded_file->get('path'), $uploaded_file->get('file'), '');
         if ($upload) {
             copy($data['tmp_name'], urldecode($upload));
         }
     } else {
         $upload = $this->mediaSource->uploadObjectsToContainer($uploaded_file->get('path'), array($data));
     }
     unlink($data['tmp_name']);
     if ($upload) {
         $url = $this->mediaSource->getObjectUrl($uploaded_file->get('path') . $uploaded_file->get('file'));
         $uploaded_file->set('url', $url);
         $uploaded_file->save();
         if (empty($rank)) {
             $imagesTable = $this->modx->getTableName('msResourceFile');
             $sql = "UPDATE {$imagesTable} SET rank = rank + 1 WHERE resource_id ='" . $this->resource->id . "' AND id !='" . $uploaded_file->get('id') . "'";
             $this->modx->exec($sql);
         }
         $generate = $uploaded_file->generateThumbnails($this->mediaSource);
         if ($generate !== true) {
             $this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not generate thumbnails for image with id = ' . $uploaded_file->get('id') . '. ' . $generate);
             return $this->failure($this->modx->lexicon('ms2gallery_err_gallery_thumb'));
         } else {
             return $this->success('', $uploaded_file);
         }
     } else {
         return $this->failure($this->modx->lexicon('ms2gallery_err_gallery_save') . ': ' . print_r($this->mediaSource->getErrors(), 1));
     }
 }
开发者ID:Homchenkokostya,项目名称:ms2Gallery,代码行数:84,代码来源:upload.class.php

示例6: getResourceAlias

 /**
  * Calculate a resource alias from the imported file
  *
  * @param modResource $resource A reference to the new modResource object
  * @param string $alias A suggested alias
  * @param integer $parent The parent ID of the Resource
  * @param string $context The context of the Resource
  * @return string The formatted alias
  */
 public function getResourceAlias(&$resource, $alias, $parent, $context = 'web')
 {
     // auto assign alias
     if ($alias == '' && $this->modx->getOption('automatic_alias')) {
         $alias = strtolower(trim($resource->cleanAlias($resource->get('pagetitle'))));
     } else {
         $alias = $resource->cleanAlias($alias);
     }
     $resourceContext = $this->modx->getObject('modContext', $context);
     $resourceContext->prepare(true);
     $isHtml = true;
     $extension = '';
     $containerSuffix = $this->modx->getOption('container_suffix', null, '');
     /** @var modContentType $contentType */
     if ($contentType = $resource->getOne('ContentType')) {
         $extension = $contentType->getExtension();
         $isHtml = strpos($contentType->get('mime_type'), 'html') !== false;
     }
     if ($resource->get('isfolder') && $isHtml && !empty($containerSuffix)) {
         $extension = $containerSuffix;
     }
     $aliasPath = '';
     if ($this->modx->getOption('use_alias_path')) {
         $pathParentId = intval($parent);
         $parentResources = array();
         $currResource = $this->modx->getObject('modResource', $pathParentId);
         while ($currResource) {
             $parentAlias = $currResource->get('alias');
             if (empty($parentAlias)) {
                 $parentAlias = "{$pathParentId}";
             }
             $parentResources[] = "{$parentAlias}";
             $pathParentId = $currResource->get('parent');
             $currResource = $currResource->getOne('Parent');
         }
         $aliasPath = !empty($parentResources) ? implode('/', array_reverse($parentResources)) : '';
     }
     $fullAlias = $aliasPath . $alias . $extension;
     $iterations = 3;
     $origAlias = $alias;
     while ($duplicateId = $this->modx->findResource($fullAlias) && $iterations > 0) {
         $iterations--;
         $this->log($this->modx->lexicon('import_duplicate_alias_found', array('id' => $duplicateId, 'alias' => $fullAlias)));
         $alias = $origAlias . '-' . substr(uniqid(''), -3);
         $fullAlias = $aliasPath . $alias . $extension;
     }
     return $alias;
 }
开发者ID:gpsietzema,项目名称:revolution,代码行数:57,代码来源:modstaticimport.class.php

示例7: cleanAlias

 public function cleanAlias($name)
 {
     $res = new modResource($this->xpdo);
     $name = str_replace('/', '-', $name);
     return $res->cleanAlias($name);
 }
开发者ID:hansek,项目名称:Tagger,代码行数:6,代码来源:taggergroup.class.php


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