public function fromArray($config)
 {
     if (isset($config['pagetitle'])) {
         $this->pagetitle = $config['pagetitle'];
     } else {
         $this->config->error->addError('Resources - pagetitle is not set', true);
         return false;
     }
     if (isset($config['alias'])) {
         $this->alias = $config['alias'];
     } else {
         $this->alias = modResource::filterPathSegment($this->modx, $this->pagetitle);
     }
     if (isset($config['setAsHome'])) {
         $this->setAsHome = intval($config['setAsHome']);
     }
     if (isset($config['parent'])) {
         $this->parent = $config['parent'];
     }
     if (isset($config['suffix'])) {
         $this->suffix = $config['suffix'];
     }
     if (isset($config['context_key'])) {
         $this->context_key = $config['context_key'];
     }
     if (isset($config['template'])) {
         $this->template = $config['template'];
     }
     if (isset($config['class_key'])) {
         $this->class_key = $config['class_key'];
     }
     if (isset($config['content_type'])) {
         $this->content_type = $config['content_type'];
     }
     if (isset($config['longtitle'])) {
         $this->longtitle = $config['longtitle'];
     }
     if (isset($config['description'])) {
         $this->description = $config['description'];
     }
     if (isset($config['menutitle'])) {
         $this->menutitle = $config['menutitle'];
     }
     if (isset($config['published'])) {
         $this->published = intval($config['published']);
     }
     if (isset($config['isfolder'])) {
         $this->isfolder = intval($config['isfolder']);
     }
     if (isset($config['introtext'])) {
         $this->introtext = $config['introtext'];
     }
     if (isset($config['richtext'])) {
         $this->richtext = intval($config['richtext']);
     }
     if (isset($config['menuindex'])) {
         $this->menuindex = intval($config['menuindex']);
     }
     if (isset($config['searchable'])) {
         $this->searchable = intval($config['searchable']);
     }
     if (isset($config['cacheable'])) {
         $this->cacheable = intval($config['cacheable']);
     }
     if (isset($config['deleted'])) {
         $this->deleted = intval($config['deleted']);
     }
     if (isset($config['hidemenu'])) {
         $this->hidemenu = intval($config['hidemenu']);
     }
     if (isset($config['hide_children_in_tree'])) {
         $this->hide_children_in_tree = intval($config['hide_children_in_tree']);
     }
     if (isset($config['show_in_tree'])) {
         $this->show_in_tree = intval($config['show_in_tree']);
     }
     if (isset($config['link_attributes'])) {
         $this->link_attributes = $config['link_attributes'];
     }
     if (isset($config['tvs']) && is_array($config['tvs'])) {
         foreach ($config['tvs'] as $tv) {
             if (!isset($tv['name'])) {
                 $this->config->error->addError('Resources - TV - name is not set', true);
                 return false;
             }
             if (!isset($tv['value'])) {
                 $tv['value'] = '';
             }
             if (isset($tv['file'])) {
                 $file = $this->config->getPackagePath();
                 $file .= '/core/components/' . $this->config->getLowCaseName() . '/resources/' . $tv['file'];
                 if (file_exists($file)) {
                     $tv['value'] = file_get_contents($file);
                 }
             }
             $this->tvs[$tv['name']] = $tv;
         }
     }
     if (isset($config['others']) && is_array($config['others'])) {
         foreach ($config['others'] as $other) {
             if (!isset($other['name'])) {
                 $this->config->error->addError('Resources - Other - name is not set', true);
                 return false;
             }
             if (!isset($other['value'])) {
                 $other['value'] = '';
             }
             $this->others[] = $other;
         }
     }
     if (!isset($config['content']) && !isset($config['file'])) {
         $file = $this->config->getPackagePath();
         $file .= '/core/components/' . $this->config->getLowCaseName() . '/resources/' . $this->alias . $this->suffix;
         if (file_exists($file)) {
             $this->content = file_get_contents($file);
         }
     } else {
         if (isset($config['content'])) {
             $this->content = $config['content'];
         }
         if (isset($config['file'])) {
             $file = $this->config->getPackagePath();
             $file .= '/core/components/' . $this->config->getLowCaseName() . '/resources/' . $config['file'];
             if (file_exists($file)) {
                 $this->content = file_get_contents($file);
             }
         }
     }
     if (isset($config['properties'])) {
         $file = $this->config->getPackagePath();
         $file .= '/core/components/' . $this->config->getLowCaseName() . '/resources/' . $config['properties'];
         if (file_exists($file)) {
             $this->properties = file_get_contents($file);
         }
     }
     return true;
 }
예제 #2
0
 /**
  * Uses the modResource::filterPathSegment method if available for cleaning a file path.
  * When it is not available (pre MODX 2.3) it uses a fake resource to call its cleanAlias method
  *
  * @param $path
  * @return string
  */
 protected function filterPathSegment($path)
 {
     if ($this->_useResource === null) {
         $resource = $this->modx->newObject('modResource');
         if (method_exists($resource, 'filterPathSegment')) {
             $this->_useResource = false;
         } else {
             $this->_useResource = true;
             $this->_resource = $resource;
         }
     }
     $options = array('friendly_alias_lowercase_only' => false);
     if ($this->_useResource) {
         return $this->_resource->cleanAlias($path, $options);
     }
     return \modResource::filterPathSegment($this->modx, $path, $options);
 }
예제 #3
0
 /**
  * Prepare file name (prevent accidental overwrites)
  */
 private function prepareFiles($prefix)
 {
     $files = $_FILES;
     $fastuploadtv_translit = (bool) $this->modx->getOption('fastuploadtv.translit', null, false);
     $fat = $this->modx->getOption('friendly_alias_translit');
     $friendly_alias_translit = empty($fat) || $fat == 'none' ? false : true;
     foreach ($files as &$file) {
         $pathInfo = pathinfo($file['name']);
         $ext = $pathInfo['extension'];
         $filename = $this->getProperty('prefixFilename') == 'true' ? $prefix : $prefix . $pathInfo['filename'];
         $filename = $this->parsePlaceholders($filename);
         if ($fastuploadtv_translit) {
             $filename = modResource::filterPathSegment($this->modx, $filename);
             // cleanAlias (translate)
             if ($friendly_alias_translit) {
                 $filename = preg_replace('/[^A-Za-z0-9_-]/', '', $filename);
                 // restrict segment to alphanumeric characters only
             }
             $filename = preg_replace('/-{2,}/', '-', $filename);
             // remove double symbol "-"
             $filename = trim($filename, '-');
             // remove first symbol "-"
             $ext = strtolower($ext);
         }
         $file['name'] = $filename . '.' . $ext;
     }
     return $files;
 }
예제 #4
0
 /**
  * @param string $alias
  *
  * @return string
  */
 public function cleanAlias($alias = '')
 {
     return modResource::filterPathSegment($this->modx, $alias);
 }
예제 #5
0
     $modx->regClientStartupScript($js . 'FastUploadTV.js');
     $modx->regClientStartupScript($js . 'FastUploadTV.form.FastUploadTVField.js');
     break;
 case 'OnMODXInit':
     $mTypes = $modx->getOption('manipulatable_url_tv_output_types', null, 'image,file') . ',fastuploadtv';
     $modx->setOption('manipulatable_url_tv_output_types', $mTypes);
     break;
 case 'OnFileManagerUpload':
     if ((bool) $modx->getOption('fastuploadtv.translit', null, false)) {
         $fat = $modx->getOption('friendly_alias_translit');
         $friendly_alias_translit = empty($fat) || $fat == 'none' ? false : true;
         foreach ($files as $file) {
             if ($file['error'] == 0) {
                 $pathInfo = pathinfo($file['name']);
                 $oldPath = $directory . $file['name'];
                 $filename = modResource::filterPathSegment($modx, $pathInfo['filename']);
                 // cleanAlias (translate)
                 if ($friendly_alias_translit) {
                     $filename = preg_replace('/[^A-Za-z0-9_-]/', '', $filename);
                     // restrict segment to alphanumeric characters only
                 }
                 $filename = preg_replace('/-{2,}/', '-', $filename);
                 // remove double symbol "-"
                 $filename = trim($filename, '-');
                 // remove first symbol "-"
                 $newPath = $filename . '.' . strtolower($pathInfo['extension']);
                 $source->renameObject($oldPath, $newPath);
             }
         }
     }
     break;