예제 #1
0
 private function moveFilesUnderCorrectResource(&$md, $field)
 {
     $matches = array();
     preg_match_all('~' . $this->uploadURL . '0/(?<file>[^ "\\)]+)~', $md, $matches);
     $path = $this->uploadPath . '0/';
     $correctPath = $this->uploadPath . $this->resource->id . '/';
     if (!is_dir($correctPath)) {
         mkdir($correctPath);
     }
     $files = $matches['file'];
     if (!empty($files)) {
         $files = array_map('trim', $files);
         $files = array_keys(array_flip($files));
         $files = array_filter($files);
         foreach ($files as $file) {
             rename($path . $file, $correctPath . $file);
         }
         $md = str_replace($this->uploadURL . '0/', $this->uploadURL . $this->resource->id . '/', $md);
         if (strpos($field, 'tv')) {
             $tvID = str_replace('tv', '', $field);
             $content = str_replace($this->uploadURL . '0/', $this->uploadURL . $this->resource->id . '/', $this->resource->getTVValue($tvID));
             $this->resource->setTVValue($tvID, $content);
         } else {
             if ($field == 'ta') {
                 $field = 'content';
             }
             $content = str_replace($this->uploadURL . '0/', $this->uploadURL . $this->resource->id . '/', $this->resource->get($field));
             $this->resource->set($field, $content);
             $this->resource->save();
         }
     }
 }
예제 #2
0
파일: Alpacka.php 프로젝트: modmore/alpacka
 /**
  * Parses a path by replacing placeholders with dynamic values. This supports the following placeholders:
  * - [[+year]]
  * - [[+month]]
  * - [[+date]]
  * - [[+day]]
  * - [[+user]]
  * - [[+username]]
  * - [[++assets_url]]
  * - [[++site_url]]
  * - [[++base_url]]
  * - [[+<any resource field>]]
  * - [[+tv.<any template variable name>]]
  *
  * In $this->setResource, support is also added for the following through $this->setPathVariables:
  * - [[+parent_alias]]
  * - [[+ultimate_parent]]
  * - [[+ultimate_parent_alias]]
  *
  * @param $path
  * @return mixed
  */
 public function parsePathVariables($path)
 {
     $path = str_replace('[[+year]]', date('Y'), $path);
     $path = str_replace('[[+month]]', date('m'), $path);
     $path = str_replace('[[+date]]', date('d'), $path);
     $path = str_replace('[[+day]]', date('d'), $path);
     $path = str_replace('[[+user]]', $this->modx->getUser()->get('id'), $path);
     $path = str_replace('[[+username]]', $this->modx->getUser()->get('username'), $path);
     $path = str_replace('[[++assets_url]]', $this->getOption('assets_url', null, 'assets/'), $path);
     $path = str_replace('[[++site_url]]', $this->getOption('site_url', null, ''), $path);
     $path = str_replace('[[++base_url]]', $this->getOption('base_url', null, ''), $path);
     foreach ($this->pathVariables as $key => $value) {
         $path = str_replace('[[+' . $key . ']]', $value, $path);
     }
     if ($this->resource) {
         $path = str_replace('[[+resource]]', $this->resource->get('id'), $path);
         // Match all placeholders in the string so we can replace it with the proper values.
         if (preg_match_all('/\\[\\[\\+(.*?)\\]\\]/', $path, $matches) && !empty($matches[1])) {
             foreach ($matches[1] as $key) {
                 $ph = '[[+' . $key . ']]';
                 if (substr($key, 0, 3) == 'tv.') {
                     $tvName = substr($key, 3);
                     $tvValue = $this->resource->getTVValue($tvName);
                     $path = str_replace($ph, $tvValue, $path);
                 } elseif (array_key_exists($key, $this->resource->_fieldMeta)) {
                     $path = str_replace($ph, $this->resource->get($key), $path);
                 } else {
                     $this->modx->log(\modX::LOG_LEVEL_WARN, "Unknown placeholder '{$key}' in redactor path {$path}", '', __METHOD__, __FILE__, __LINE__);
                 }
             }
         }
     }
     /**
      * Prevent changing double slashes in a protocol (e.g. http://) to a single slash, while cleaning up other
      * duplicate slashes in the path.
      */
     $path = str_replace('://', '__:_/_/__', $path);
     $path = str_replace('//', '/', $path);
     $path = str_replace('__:_/_/__', '://', $path);
     return $path;
 }
예제 #3
0
    /**
     * @param modManagerController $controller
     * @param modResource $resource
     */
    public function loadManagerFiles(modManagerController $controller, modResource $resource)
    {
        $modx23 = (int) $this->systemVersion();
        $cssUrl = $this->config['cssUrl'] . 'mgr/';
        $jsUrl = $this->config['jsUrl'] . 'mgr/';
        $properties = $resource->getProperties('ms2gallery');
        if (empty($properties['media_source'])) {
            if (!($source_id = $resource->getTVValue('ms2Gallery'))) {
                /** @var modContextSetting $setting */
                $setting = $this->modx->getObject('modContextSetting', array('key' => 'ms2gallery_source_default', 'context_key' => $resource->get('context_key')));
                $source_id = !empty($setting) ? $setting->get('value') : $this->modx->getOption('ms2gallery_source_default');
            }
            $resource->setProperties(array('media_source' => $source_id), 'ms2gallery');
            $resource->save();
        } else {
            $source_id = $properties['media_source'];
        }
        if (empty($source_id)) {
            $source_id = $this->modx->getOption('ms2gallery_source_default');
        }
        $resource->set('media_source', $source_id);
        $controller->addLexiconTopic('ms2gallery:default');
        $controller->addJavascript($jsUrl . 'ms2gallery.js');
        $controller->addLastJavascript($jsUrl . 'misc/ms2.combo.js');
        $controller->addLastJavascript($jsUrl . 'misc/ms2.utils.js');
        $controller->addLastJavascript($jsUrl . 'misc/plupload/plupload.full.js');
        $controller->addLastJavascript($jsUrl . 'misc/ext.ddview.js');
        $controller->addLastJavascript($jsUrl . 'gallery.view.js');
        $controller->addLastJavascript($jsUrl . 'gallery.window.js');
        $controller->addLastJavascript($jsUrl . 'gallery.toolbar.js');
        $controller->addLastJavascript($jsUrl . 'gallery.panel.js');
        $controller->addCss($cssUrl . 'main.css');
        if (!$modx23) {
            $controller->addCss($cssUrl . 'font-awesome.min.css');
        }
        $source_config = array();
        /** @var modMediaSource $source */
        if ($source = $this->modx->getObject('modMediaSource', $source_id)) {
            $tmp = $source->getProperties();
            foreach ($tmp as $v) {
                $source_config[$v['name']] = $v['value'];
            }
        }
        $controller->addHtml('
		<script type="text/javascript">
			MODx.modx23 = ' . $modx23 . ';
			ms2Gallery.config = ' . $this->modx->toJSON($this->config) . ';
			ms2Gallery.config.media_source = ' . $this->modx->toJSON($source_config) . ';
		</script>');
        if ($this->modx->getOption('ms2gallery_new_tab_mode', null, true)) {
            $controller->addLastJavascript($jsUrl . 'tab.js');
        } else {
            $insert = '
				tabs.add({
					xtype: "ms2gallery-page",
					id: "ms2gallery-page",
					title: _("ms2gallery"),
					record: {
						id: ' . $resource->get('id') . ',
						source: ' . $source_id . ',
					}
				});
			';
            if ($this->modx->getCount('modPlugin', array('name' => 'AjaxManager', 'disabled' => false))) {
                $controller->addHtml('
				<script type="text/javascript">
					Ext.onReady(function() {
						window.setTimeout(function() {
							var tabs = Ext.getCmp("modx-resource-tabs");
							if (tabs) {
								' . $insert . '
							}
						}, 10);
					});
				</script>');
            } else {
                $controller->addHtml('
				<script type="text/javascript">
					Ext.ComponentMgr.onAvailable("modx-resource-tabs", function() {
						var tabs = this;
						tabs.on("beforerender", function() {
							' . $insert . '
						});
					});
				</script>');
            }
        }
    }
예제 #4
0
 /**
  * Create index of resource
  *
  * @param modResource $resource
  */
 public function Index(modResource $resource)
 {
     $words = array();
     $intro = '';
     foreach ($this->fields as $field => $weight) {
         $text = strpos($field, 'tv_') !== false ? $resource->getTVValue(substr($field, 3)) : $resource->get($field);
         $forms = $this->mSearch2->getBaseForms($text);
         $intro .= $this->modx->stripTags(is_array($text) ? $this->mSearch2->implode_r(' ', $text) : $text) . ' ';
         foreach ($forms as $form) {
             if (array_key_exists($form, $words)) {
                 $words[$form] += $weight;
             } else {
                 $words[$form] = $weight;
             }
         }
     }
     $tword = $this->modx->getTableName('mseWord');
     $tintro = $this->modx->getTableName('mseIntro');
     $resource_id = $resource->get('id');
     $intro = str_replace(array("\n", "\r\n", "\r"), ' ', $intro);
     $intro = preg_replace('/\\s+/', ' ', str_replace(array('\'', '"', '«', '»', '`'), '', $intro));
     $sql = "INSERT INTO {$tintro} (`resource`, `intro`) VALUES ('{$resource_id}', '{$intro}') ON DUPLICATE KEY UPDATE `intro` = '{$intro}';";
     $sql .= "DELETE FROM {$tword} WHERE `resource` = '{$resource_id}';";
     $sql .= "INSERT INTO {$tword} (`resource`, `word`, `weight`) VALUES ";
     if (!empty($words)) {
         $rows = array();
         foreach ($words as $word => $weight) {
             $rows[] = '(' . $resource_id . ', "' . $word . '", ' . $weight . ')';
         }
         if (!empty($rows)) {
             $sql .= implode(',', $rows);
         }
     }
     $sql .= " ON DUPLICATE KEY UPDATE `resource` = '{$resource_id}';";
     $q = $this->modx->prepare($sql);
     if (!$q->execute()) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, '[mSearch2] Could not save search index of resource ' . $resource_id . ': ' . print_r($q->errorInfo(), 1));
     }
 }