/**
  * Overrides xPDOObject::get to handle when retrieving the properties field
  * for an Element.
  *
  * {@inheritdoc}
  */
 public function get($k, $format = null, $formatTemplate = null)
 {
     $value = parent::get($k, $format, $formatTemplate);
     /* automatically translate lexicon descriptions */
     if ($k == 'properties' && !empty($value) && is_array($value) && is_object($this->xpdo) && $this->xpdo instanceof modX && $this->xpdo->lexicon) {
         foreach ($value as &$property) {
             if (!empty($property['lexicon'])) {
                 if (strpos($property['lexicon'], ':') !== false) {
                     $this->xpdo->lexicon->load('en:' . $property['lexicon']);
                 } else {
                     $this->xpdo->lexicon->load('en:core:' . $property['lexicon']);
                 }
                 $this->xpdo->lexicon->load($property['lexicon']);
             }
             $property['desc_trans'] = $this->xpdo->lexicon($property['desc']);
             $property['area'] = !empty($property['area']) ? $property['area'] : '';
             if (!empty($property['options'])) {
                 foreach ($property['options'] as &$option) {
                     if (empty($option['text']) && !empty($option['name'])) {
                         $option['text'] = $option['name'];
                         unset($option['name']);
                     }
                     if (empty($option['value']) && !empty($option[0])) {
                         $option['value'] = $option[0];
                         unset($option[0]);
                     }
                     $option['name'] = $this->xpdo->lexicon($option['text']);
                 }
             }
         }
     }
     return $value;
 }
 public function get($k, $format = null, $formatTemplate = null)
 {
     if ($k == 'badge') {
         $v = $this->getBadge();
     } else {
         $v = parent::get($k, $format, $formatTemplate);
     }
     return $v;
 }
示例#3
0
 public function getImageUrl($image = '')
 {
     if (empty($image)) {
         $image = parent::get('image');
     }
     if (!empty($image) && ($source = parent::get('source'))) {
         /** @var modMediaSource $source */
         if ($source = $this->xpdo->getObject('sources.modMediaSource', $source)) {
             $source->initialize();
             //$image = $source->getObjectUrl($image);
             $image = $source->getBasePath($image) . $image;
         }
     }
     return $image;
 }
 /**
  * Overrides xPDOObject::get() to replace path settings.
  *
  * {@inheritdoc}
  */
 public function get($k, $format = null, $formatTemplate = null)
 {
     $result = parent::get($k, $format, $formatTemplate);
     if ($k === 'path' && strpos($result, '{') !== false) {
         $replacements = array();
         foreach ($this->xpdo->config as $key => $value) {
             $_pos = strrpos($key, '_');
             if ($_pos > 0 && substr($key, $_pos + 1) === 'path') {
                 $replacements['{' . $key . '}'] = $value;
             }
         }
         $result = str_replace(array_keys($replacements), array_values($replacements), $result);
     }
     return $result;
 }
示例#5
0
 public function get($k, $format = null, $formatTemplate = null)
 {
     switch ($k) {
         case 'thumbnail':
             $value = $this->getPhpThumbUrl();
             if (empty($format)) {
                 $format = array();
             }
             $format['src'] = $this->xpdo->getOption('gallery.thumbs_prepend_site_url', null, false) ? $this->getSiteUrl() : '';
             $format['src'] .= $this->xpdo->getOption('gallery.files_url') . $this->get('filename');
             $url = $value . '&' . http_build_query($format, '', '&');
             if ($this->xpdo->getOption('xhtml_urls', null, false)) {
                 $value = str_replace('&', '&', $url);
                 $value = str_replace('&', '&', $value);
             } else {
                 $value = $url;
             }
             break;
         case 'image':
             if (empty($format)) {
                 $format = array();
             }
             $format['src'] = $this->xpdo->getOption('gallery.thumbs_prepend_site_url', null, false) ? $this->getSiteUrl() : '';
             $format['src'] .= $this->xpdo->getOption('gallery.files_url') . $this->get('filename');
             $value = $this->getPhpThumbUrl() . '&' . http_build_query($format, '', '&');
             $value = $this->xpdo->getOption('xhtml_urls', null, false) ? str_replace('&', '&', $value) : $value;
             break;
         case 'absoluteImage':
             $value = $this->getSiteUrl() . $this->xpdo->getOption('gallery.files_url') . $this->get('filename');
             break;
         case 'relativeImage':
             $value = ltrim($this->xpdo->getOption('gallery.files_url') . $this->get('filename'), '/');
             break;
         case 'filesize':
             $filename = $this->xpdo->getOption('gallery.files_path') . $this->get('filename');
             $value = @filesize($filename);
             $value = $this->formatFileSize($value);
             break;
         case 'image_path':
             $value = $this->xpdo->getOption('gallery.files_path') . $this->get('filename');
             break;
         default:
             $value = parent::get($k, $format, $formatTemplate);
             break;
     }
     return $value;
 }
 /**
  * @param null $cacheFlag
  *
  * @return bool
  */
 public function save($cacheFlag = null)
 {
     $save = parent::save($cacheFlag);
     $tags = parent::get('tags');
     if (is_array($tags)) {
         $id = $this->get('id');
         $table = $this->xpdo->getTableName('msResourceFileTag');
         $this->xpdo->exec("DELETE FROM {$table} WHERE `file_id` = {$id};");
         if (!empty($tags)) {
             $values = array();
             foreach ($tags as $tag) {
                 $tag = trim($tag);
                 if (!empty($tag)) {
                     $values[] = '(' . $id . ',"' . $tag . '")';
                 }
             }
             if (!empty($values)) {
                 $this->xpdo->exec("INSERT INTO {$table} (`file_id`,`tag`) VALUES " . implode(',', $values));
             }
         }
     }
     return $save;
 }
示例#7
0
 public function get($k, $format = null, $formatTemplate = null)
 {
     switch ($k) {
         case 'thumbnail':
             $value = $this->getPhpThumbUrl();
             if (empty($format)) {
                 $format = array();
             }
             $filename = $this->get('filename');
             if ($this->get('absolute_filename')) {
                 $format['src'] = $filename;
             } else {
                 $format['src'] = $this->getSiteUrl();
                 $format['src'] .= $this->xpdo->call('galAlbum', 'getFilesUrl', array(&$this->xpdo)) . $filename;
             }
             $ms = $this->getMediaSource();
             if ($ms->getBaseUrl() != '/') {
                 $format['src'] = $ms->getBaseUrl() . $this->xpdo->call('galAlbum', 'getFilesUrl', array(&$this->xpdo)) . $filename;
             }
             $url = $value . '&' . http_build_query($format, '', '&');
             if ($this->xpdo->getOption('xhtml_urls', null, false)) {
                 $value = str_replace('&', '&', $url);
                 $value = str_replace('&', '&', $value);
             } else {
                 $value = $url;
             }
             break;
         case 'image':
             if (empty($format)) {
                 $format = array();
             }
             $filename = $this->get('filename');
             if ($this->get('absolute_filename')) {
                 $format['src'] = $filename;
             } else {
                 $format['src'] = $this->getSiteUrl();
                 $format['src'] .= $this->xpdo->call('galAlbum', 'getFilesUrl', array(&$this->xpdo)) . $filename;
             }
             $ms = $this->getMediaSource();
             if ($ms->getBaseUrl() != '/') {
                 $format['src'] = $ms->getBaseUrl() . $this->xpdo->call('galAlbum', 'getFilesUrl', array(&$this->xpdo)) . $filename;
             }
             $value = $this->getPhpThumbUrl() . '&' . http_build_query($format, '', '&');
             $value = $this->xpdo->getOption('xhtml_urls', null, false) ? str_replace('&', '&', $value) : $value;
             break;
         case 'absoluteImage':
             $siteUrl = $this->getSiteUrl();
             $value = $siteUrl . $this->xpdo->call('galAlbum', 'getFilesUrl', array(&$this->xpdo)) . $this->get('filename');
             // $ms = $this->getMediaSource();
             // if($ms->getBaseUrl() != '/') {
             //     $value = $ms->getBaseUrl().$this->xpdo->call('galAlbum','getFilesUrl',array(&$this->xpdo)).$filename;
             // }
             break;
         case 'relativeImage':
             $baseUrl = $this->getOption('base_url');
             $path = $this->xpdo->call('galAlbum', 'getFilesUrl', array(&$this->xpdo)) . $this->get('filename');
             if ($baseUrl == '/') {
                 $value = ltrim($path, '/');
             } else {
                 $value = str_replace($baseUrl, '', $path);
             }
             // $ms = $this->getMediaSource(); // for absolute + relative the link NEEDS the http:// domain
             // if($ms->getBaseUrl() != '/') {
             //     $value = $ms->getBaseUrl().$this->xpdo->call('galAlbum','getFilesUrl',array(&$this->xpdo)).$baseUrl;
             // }
             break;
         case 'filesize':
             $filename = $this->xpdo->call('galAlbum', 'getFilesPath', array(&$this->xpdo)) . $this->get('filename');
             $value = @filesize($filename);
             $value = $this->formatFileSize($value);
             break;
         case 'image_path':
             $value = $this->xpdo->call('galAlbum', 'getFilesPath', array(&$this->xpdo)) . $this->get('filename');
             break;
         case 'base_url':
             $ms = $this->getMediaSource();
             $value = '';
             if ($ms->getBaseUrl() != '/') {
                 $value = $ms->getBaseUrl();
             }
             break;
         default:
             $value = parent::get($k, $format, $formatTemplate);
             break;
     }
     return $value;
 }
示例#8
0
 /**
  * Overrides xPDOObject::get to provide formatting for certain fields
  *
  * @param string $k
  * @param string $format
  * @param string $formatTemplate
  * @return mixed|string
  */
 public function get($k, $format = '', $formatTemplate = '')
 {
     $v = parent::get($k, $format, $formatTemplate);
     if ($this->xpdo->context->key != 'mgr') {
         switch ($k) {
             case 'gender_formatted':
                 switch ($this->get('gender')) {
                     case 'm':
                         $v = $this->xpdo->lexicon('discuss.male');
                         break;
                     case 'f':
                         $v = $this->xpdo->lexicon('discuss.female');
                         break;
                     default:
                         $v = '';
                         break;
                 }
                 break;
             case 'age':
                 $v = strtotime($this->get('birthdate'));
                 $v = floor((time() - $v) / 60 / 60 / 24 / 365);
                 $v = !empty($v) ? $v : '';
                 break;
             case 'ip':
                 if (!$this->xpdo->hasPermission('discuss.track_ip')) {
                     $v = '';
                 }
                 break;
             case 'last_active':
                 if (!$this->get('show_online') && !$this->isAdmin()) {
                     $v = '';
                 } elseif (!empty($v) && $v != '-001-11-30 00:00:00') {
                     $v = strftime($this->xpdo->discuss->dateFormat, strtotime($v));
                 } else {
                     $v = '';
                 }
                 break;
             case 'email':
                 if (!$this->get('show_email') && !$this->isAdmin()) {
                     $v = '';
                 }
                 break;
             case 'name':
                 if ($this->get('use_display_name')) {
                     $v = $this->get('display_name');
                 }
                 if (empty($v)) {
                     $v = $this->get('username');
                 }
                 break;
             case 'posts_formatted':
                 $v = $this->get('posts');
                 $v = number_format($v);
                 break;
         }
     }
     return $v;
 }
示例#9
0
 /**
  * Always ensure that the title strips any HTML/MODX tags
  * @param string $k
  * @param string|null $format
  * @param string|null $formatTemplate
  * @return mixed
  */
 public function get($k, $format = null, $formatTemplate = null)
 {
     $v = parent::get($k, $format, $formatTemplate);
     switch ($k) {
         case 'title':
             $v = html_entity_decode($v);
             $v = $this->xpdo->discuss->stripAllTags($v);
             $v = strip_tags($v, '<span>');
             $v = preg_replace('@\\[\\[(.[^\\[\\[]*?)\\]\\]@si', '', $v);
             break;
         default:
             break;
     }
     return $v;
 }
 public function getWeight($data = array())
 {
     $weight = parent::get('weight');
     if (!empty($this->xpdo->getWeight)) {
         return $weight;
     }
     $this->xpdo->getWeight = true;
     if (empty($data)) {
         $data = $this->toArray();
     }
     /** @var miniShop2 $miniShop2 */
     $miniShop2 = $this->xpdo->getService('minishop2');
     $params = array('product' => $this, 'data' => $data, 'weight' => $weight);
     $response = $miniShop2->invokeEvent('msOnGetProductWeight', $params);
     if ($response['success']) {
         $weight = $params['weight'] = $response['data']['weight'];
     }
     /* @var modSnippet $snippet */
     // Deprecated. Leaved for backward compatibility.
     if ($setting = $this->xpdo->getOption('ms2_weight_snippet', null, false, true)) {
         if ($snippet = $this->xpdo->getObject('modSnippet', array('name' => $setting))) {
             $snippet->setCacheable(false);
             $weight = $snippet->process($params);
         }
     }
     //--
     $this->xpdo->getWeight = false;
     return $weight;
 }
示例#11
0
 /**
  * Always ensure that the title strips any HTML/MODX tags
  * @param string $k
  * @param string|null $format
  * @param string|null $formatTemplate
  * @return mixed
  */
 public function get($k, $format = null, $formatTemplate = null)
 {
     $v = parent::get($k, $format, $formatTemplate);
     switch ($k) {
         case 'title':
             $v = htmlspecialchars($v, ENT_QUOTES, 'UTF-8');
             break;
         default:
             break;
     }
     return $v;
 }