
<?php /** * getImageList * * Copyright 2009-2010 by Bruno Perner <[email protected]> * * getImageList is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) any * later version. * * getImageList is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with * getImageList; if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * @package migx */ /** * getImageList * * get Images from TV with custom-input-type imageList for MODx Revolution 2.0. * * @version 1.2 * @author Bruno Perner <[email protected]> * @copyright Copyright © 2009-2010 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License * version 2 or (at your option) any later version. * @package migx */ /*example: <ul>[[!getImageList? &tvname=`myTV`&tpl=`@CODE:<li>[[+idx]]<img src="[[+imageURL]]"/><p>[[+imageAlt]]</p></li>`]]</ul>*/ /* get default properties */ $docids = $modx->getOption('docids', $scriptProperties, $modx->resource->get('id')); $docids = explode(',', $docids); foreach($docids as $docid) { // initialise vars, if using property sets get those $tvname = $modx->getOption('tvname', $scriptProperties, ''); $tpl = $modx->getOption('tpl', $scriptProperties, ''); $outputvalue = $modx->getOption('value', $scriptProperties, ''); $limit = $modx->getOption('limit', $scriptProperties, '0'); $offset = $modx->getOption('offset', $scriptProperties, 0); $totalVar = $modx->getOption('totalVar', $scriptProperties, 'total'); $randomize = $modx->getOption('randomize', $scriptProperties, false); $preselectLimit = $modx->getOption('preselectLimit', $scriptProperties, 0); // when random preselect important images /* if (empty($tpl)) { return 'empty property: &tpl'; } */ if (!empty($tvname)) { if ($tv = $modx->getObject('modTemplateVar', array('name' => $tvname))) { $outputvalue = $tv->renderOutput($docid); /* * get inputTvs */ $properties = $tv->get('input_properties'); $properties = isset($properties['formtabs']) ? $properties : $tv->getProperties(); $formtabs = $modx->fromJSON($properties['formtabs']); $inputTvs = array(); if (is_array($formtabs)) { foreach ($formtabs as $tab) { if (isset($tab['fields'])) { foreach ($tab['fields'] as $field) { if (isset($field['inputTV'])) { $inputTvs[$field['field']] = $field['inputTV']; } } } } } } } if (empty($outputvalue)) { return ''; } $items = $modx->fromJSON($outputvalue); $modx->setPlaceholder($totalVar, count($items)); $output = ''; if (substr($tpl, 0, 6) == "@FILE:") { $template = file_get_contents($modx->config['base_path'] . substr($tpl, 6)); } else if (substr($tpl, 0, 6) == "@CODE:") { $template = substr($tpl, 6); } else if ($chunk = $modx->getObject('modChunk', array('name' => $tpl), true)) { $template = $chunk->getContent(); } else { $template = false; } if (count($items) > 0) { $items = $offset > 0 ? array_slice($items, $offset) : $items; $count = count($items); $limit = ($limit == 0 || $limit > $count) ? $count : $limit; $preselectLimit = $preselectLimit > $count ? $count : $preselectLimit; //preselect important items if ($randomize && $preselectLimit > 0) { $tempitems = array(); for ($i = 0; $i < $preselectLimit; $i++) { $tempitems[] = $items[$i]; unset($items[$i]); } shuffle($items); $items = array_merge($tempitems, $items); } $tempitems = array(); for ($i = 0; $i < $limit; $i++) { $tempitems[] = $items[$i]; } $items = $tempitems; if ($randomize) { shuffle($items); } $idx = 0; $output = ""; foreach ($items as $key => $item) { $fields = array(); foreach ($item as $field => $value) { if (isset($inputTvs[$field])) { if ($tv = $modx->getObject('modTemplateVar', array('name' => $inputTvs[$field]))) { $tv->set('default_text', $value); $fields[$field] = $tv->renderOutput($docid); } } else { $fields[$field] = $value; } } $fields['_alt'] = $idx % 2; $idx++; $fields['_first'] = $idx == 1 ? true : ''; $fields['_last'] = $idx == $limit ? true : ''; $fields['idx'] = $idx; $fields['docid'] = $docid; if ($template) { $chunk = $modx->newObject('modChunk'); $chunk->setCacheable(false); $chunk->setContent($template); $output .= $chunk->process($fields); } else { $output .= '<pre>' . print_r($fields, 1) . '</pre>'; } } $return .= $output; } } return $return;
[[!getImageList? &tvname=`myMIGXtv` &tpl=`myItemTpl` &docid=`[[+id]]`]]
Hi,
Re my previous post (#70), I have solved issue 2 with a bit of CSS, although the second caption is still positioned a line down for some reason...
Still can’t get images to show up... :-(
Cheers - Zaphodx

[[*myMIGXtv]]
<div class="migxCell1">
<div class="migxThumb1"><a><img src="[[+image]]" height="100%" width="100%" alt="[[+title]]" /></a></div>
<div class="migxTextCell1">
<div class="migxHead1">[[+title]]</div>
<div class="migxCaption1">[[+description]]</div>
</div>
<div class="clearSpanCell0"></div>
</div><img src="[[*image]]"/>
This discussion is closed to further replies. Keep calm and carry on.