/** * Prepare a JSON encoded object and return a valid JSON encoded Image+ object * * @param $json JSON value to prepare * @param array $opts * @param modTemplateVar $tv * @return string */ public function prepareTvValue($json, $opts = array(), modTemplateVar $tv) { // Prepare value $decoded = json_decode($json); if (!$decoded) { // The variable does not contain an Image+ image object if ($json != '') { // Get Media Source /** @var modMediaSource $source */ if ($tv) { $source = $tv->getSource($this->modx->resource ? $this->modx->resource->get('context_key') : 'mgr'); } else { $source = $this->modx->getObject('modMediaSource', $this->modx->getOption('default_media_source')); } if (!($source && $source->getWorkingContext())) { $this->modx->log(xPDO::LOG_LEVEL_ERROR, 'Invalid Media Source', '', 'Image+'); return ''; } $source->setRequestProperties($_REQUEST); $source->initialize(); // The variable contains a value and has to be converted to an Image+ image object $imgPath = $source->getBasePath() . $json; if (file_exists($imgPath)) { $size = getimagesize($imgPath); } else { $this->modx->log(xPDO::LOG_LEVEL_INFO, 'The template variabe value does not contain an existing image', '', 'Image+'); } $json = json_encode(array('altTag' => '', 'crop' => array('height' => $size ? $size[1] : 0, 'width' => $size ? $size[0] : 0, 'x' => 0, 'y' => 0), 'sourceImg' => array('height' => $size ? $size[1] : 0, 'width' => $size ? $size[0] : 0, 'source' => $source->get('id'), 'src' => $json), 'targetHeight' => (int) $opts['targetHeight'], 'targetWidth' => (int) $opts['targetWidth'])); } } return $json; }
function __construct(modTemplateVar $tv, array $config = array()) { $corePath = dirname(dirname(dirname(__FILE__))) . '/'; $this->tv =& $tv; $this->modx =& $tv->xpdo; $this->config = array_merge($this->config, $config); $template = $this->getTemplate(); $xtype_template = str_replace('.tpl', '.xtype.tpl', $template); $this->tv->set('xtype_template', $corePath . 'templates/' . $xtype_template); $this->controller = new migxfeChunkie('@FILE ' . $template, $corePath . 'templates/'); $this->setReplaceonlyfields('tv.value'); }
function __construct(modTemplateVar $tv, array $config = array()) { $this->tv =& $tv; $this->modx =& $tv->xpdo; $this->config = array_merge($this->config, $config); $template = $this->getTemplate(); $templatesRoot = $this->getTemplateRoot(); $xtype_template = str_replace('.tpl', '.xtype.tpl', $template); $this->tv->set('xtype_template', $templatesRoot . $xtype_template); $this->controller = new migxangularChunkie('@FILE ' . $template, $templatesRoot); $this->setReplaceonlyfields('tv.value'); }
public function prepareQueryBeforeCount(xPDOQuery $c) { $c->leftJoin('modUser', 'CreatedBy'); if ($this->getTagsTV()) { $c->leftJoin('modTemplateVarResource', 'Tags', array('Tags.tmplvarid' => $this->tvTags->get('id'), 'Tags.contentid = Article.id')); } $parent = $this->getProperty('parent', null); if (!empty($parent)) { $c->where(array('parent' => $parent)); } $query = $this->getProperty('query', null); if (!empty($query)) { $queryWhere = array('pagetitle:LIKE' => '%' . $query . '%', 'OR:description:LIKE' => '%' . $query . '%', 'OR:introtext:LIKE' => '%' . $query . '%'); if ($this->tvTags) { $queryWhere['OR:Tags.value:LIKE'] = '%' . $query . '%'; } $c->where($queryWhere); } $filter = $this->getProperty('filter', ''); switch ($filter) { case 'published': $c->where(array('published' => 1, 'deleted' => 0)); break; case 'unpublished': $c->where(array('published' => 0, 'deleted' => 0)); break; case 'deleted': $c->where(array('deleted' => 1)); break; default: $c->where(array('deleted' => 0)); break; } $c->where(array('class_key' => 'Article')); return $c; }
public function getElementSources() { $c = $this->modx->newQuery('modContext'); $c->leftJoin('sources.modMediaSourceElement', 'SourceElements', array('SourceElements.object' => $this->tv->get('id'), 'SourceElements.object_class' => $this->tv->_class, 'SourceElements.context_key = modContext.key')); $c->leftJoin('sources.modMediaSource', 'Source', 'SourceElements.source = Source.id'); $c->select($this->modx->getSelectColumns('modContext', 'modContext')); $c->select($this->modx->getSelectColumns('sources.modMediaSourceElement', 'SourceElements')); $c->select($this->modx->getSelectColumns('sources.modMediaSource', 'Source', '', array('name'))); $c->where(array('key:!=' => 'mgr')); $c->sortby($this->modx->escape('rank'), 'ASC'); $c->sortby($this->modx->escape('key'), 'DESC'); $contexts = $this->modx->getCollection('modContext', $c); $list = array(); /** @var modContext $context */ foreach ($contexts as $context) { $source = $context->get('source'); $list[] = array($context->get('key'), !empty($source) ? $source : $this->modx->getOption('default_media_source', null, 1), $context->get('name')); } return $list; }
/** * @param string $expected * @param array $properties * @param null|string $content * @dataProvider providerProcess */ public function testProcess($expected, array $properties = array(), $content = null) { $result = $this->tv->process($properties, $content); $this->assertEquals($expected, $result); }
/** * @param modTemplateVar $tv * * @return array */ protected function _getAutoTags(modTemplateVar $tv) { $params = $tv->get('input_properties'); if (empty($params['parent_resources'])) { $params['parent_resources'] = ''; } /** @var xPDOQuery $c */ $c = $this->modx->newQuery('modTemplateVarResource'); $c->innerJoin('modTemplateVar', 'TemplateVar'); $c->innerJoin('modResource', 'Resource'); $c->where(array('tmplvarid' => $tv->get('id'))); if (!empty($params['parent_resources'])) { $ids = array(); $parents = explode(',', $params['parent_resources']); $currCtx = 'web'; $this->modx->switchContext('web'); foreach ($parents as $id) { /** @var modResource $r */ $r = $this->modx->getObject('modResource', $id); if ($r && $currCtx != $r->get('context_key')) { $this->modx->switchContext($r->get('context_key')); $currCtx = $r->get('context_key'); } if ($r) { $pids = $this->modx->getChildIds($id, 10, array('context' => $r->get('context_key'))); $ids = array_merge($ids, $pids); } $ids[] = $id; } $this->modx->switchContext('mgr'); $ids = array_unique($ids); $c->where(array('Resource.id:IN' => $ids)); } $tvs = $this->modx->getIterator('modTemplateVarResource', $c); $list = array(); /** @var modTemplateVarResource $tv */ foreach ($tvs as $tv) { $list = array_merge($list, explode(',', $tv->get('value'))); } return array_unique($list); }
/** * Prepare radio boxes. * * @param modTemplateVar $tv * @return modTemplateVar */ public function prepareRadio($tv) { $value = $tv->get('value'); $default = $tv->get('default_text'); // handles radio buttons $options = $tv->parseInputOptions($tv->processBindings($tv->get('elements'), $tv->get('name'))); $items = array(); $defaultIndex = ''; $i = 0; foreach ($options as $option) { $opt = explode("==", $option); if (!isset($opt[1])) { $opt[1] = $opt[0]; } /* set checked status */ $checked = strcmp($opt[1], $value) == 0 ? ' checked="checked"' : ''; /* set default value */ if (strcmp($opt[1], $default) == 0) { $defaultIndex = 'tv' . $tv->get('id') . '-' . $i; $tv->set('default_text', $defaultIndex); } if (is_string($opt[1])) { $opt[1] = str_replace('"', '"', $opt[1]); } $items[] = array('text' => htmlspecialchars($opt[0], ENT_COMPAT, 'UTF-8'), 'name' => 'tv' . $tv->get('id'), 'value' => $opt[1], 'checked' => $checked, 'idx' => $i); $i++; } $list = array(); foreach ($items as $item) { $list[] = $this->hm->getTpl('fields/radio.option', $item); } $tv->set('options', implode("\n", $list)); return $tv; }