MODX Revolution PHP Cross Reference Content Management Systems

Source: /core/model/modx/processors/element/tv/renders/web/output/url.class.php - 60 lines - 2251 bytes - Summary - Text - Print

   1  <?php
   2  /**
   3   * @var modX $modx
   4   * @var array $params
   5   * @var string $value
   6   *
   7   * @package modx
   8   * @subpackage processors.element.tv.renders.mgr.output
   9   */
  10  class modTemplateVarOutputRenderUrl extends modTemplateVarOutputRender {
  11      public function process($value,array $params = array()) {
  12          if (empty($value)) return $value;
  13  
  14          $value= $this->tv->parseInput($value, "||", "array");
  15          $o = '';
  16  
  17          for ($i = 0; $i < count($value); $i++) {
  18              $s = is_array($value[$i]) ? $value[$i] : explode("==",$value[$i]);
  19              if (!isset($s[1])) $s[1] = $s[0];
  20              list($name,$url) = $s;
  21  
  22              if (!$url) $url = $name;
  23              if ((empty($name) || $name == $url) && $this->tv->get('type') == 'resourcelist') {
  24                  /** @var modResource $resource */
  25                  $resource = $this->modx->getObject('modResource',$url);
  26                  if ($resource) {
  27                      $name = $resource->get('pagetitle');
  28                  }
  29              }
  30  
  31              /* handle types that return IDs of resources */
  32              $rid =intval($url);
  33              if (!empty($rid)) {
  34                  $url = '[[~'.$rid.']]';
  35              }
  36  
  37              if ($url) {
  38                  if($o) $o.='<br />';
  39                  $attributes = '';
  40                  /* setup the link attributes */
  41                  $attr = array(
  42                      'href' => $url,
  43                      'title' => !empty($params['title']) ? htmlspecialchars($params['title']) : $name,
  44                      'class' => !empty($params['class']) ? $params['class'] : null,
  45                      'style' => !empty($params['style']) ? $params['style'] : null,
  46                      'target' => !empty($params['target']) ? $params['target'] : null,
  47                  );
  48                  foreach ($attr as $k => $v) $attributes .= ($v ? ' '.$k.'="'.$v.'"' : '');
  49                  if (!empty($params['attrib'])) {
  50                      $attributes .= ' '.$params['attrib']; /* add extra */
  51                  }
  52  
  53                  /* Output the link */
  54                  $o .= '<a'.rtrim($attributes).'>'. (!empty($params['text']) ? htmlspecialchars($params['text']) : $name) .'</a>';
  55              }
  56          }
  57          return $o;
  58      }
  59  }
  60  return 'modTemplateVarOutputRenderUrl';

title

Description

title

Description

title

Description

title

title

Body