<?php
 set_include_path( dirname(__FILE__). '/services' . PATH_SEPARATOR . dirname(__FILE__). '/services/vo' . PATH_SEPARATOR . get_include_path() ); class SimpleGalleryRender { private $content, $structure, $config; private $service = null; private $parent = null; function __construct($parent) { $this->content = $parent->getContent(); $this->structure = $parent->getStructure(); $this->config = $parent->getConfig(); $this->parent = $parent; } function renderModule($id) { if (is_null($this->service)) $this->service = new SimpleGalleryModuleService(); $data = array('structure' => null, 'data' => null); $moduleVO = ModuleVO::findById($id, $this->content); $xmlfilename = ''; $checkDom = new DOMDocument(); $checkDom->loadXML($moduleVO->data); $node = $checkDom->getElementsByTagName("galleryData"); if ($node) { $file = $node->item(0)->nodeValue; if (strlen($file) > 0) $xmlfilename = MOTO_ROOT_DIR . '/' . $file; } if ($xmlfilename == '' || !file_exists($xmlfilename)) { return ''; } $responceVO = $this->service->getSimpleGalleryModuleStructure($moduleVO->data); if (!is_null($responceVO->result) && is_array($responceVO->result->properties)) { foreach($responceVO->result->properties as $property) { $data['structure'][$property->id]['type'] = $property->type; $data['structure'][$property->id]['name'] = $property->name; } } $responceVO = $this->service->getSimpleGalleryModuleData($moduleVO->data); if (!is_null($responceVO->result) && is_array($responceVO->result)) { foreach($responceVO->result as $newsVO) { $news = array(); $news['id'] = $newsVO->id; $news['order'] = $newsVO->order; foreach($newsVO->properties as $property) { $news['data'][] = array( 'type' => $data['structure'][$property->propertyType]['type'], 'name' => $data['structure'][$property->propertyType]['name'], 'value' => $property->value ); } $data['data'][$news['id']] = $news; } } return $this->renderHtml($data); } function renderHtml($data) { $html = ''; $html .= '<div class="simpleGallery">'; if (isset($data['data']) && is_array($data['data'])) foreach($data['data'] as $news) { $html .= $this->_renderHtml($news); } $html .= '</div>' . "\n\n"; return $html; } function _renderHtml($obj) { $data = array( 'thumbnail_alt' => '', 'thumbnail_title' => '', 'preview_alt' => '', 'preview_title' => '', ); if (isset($obj['data']) && is_array($obj['data'])) foreach($obj['data'] as $row) { switch($row['type']) { case 'image': case 'media': $info = MotoUtil::responseVOToArray(MediaLibraryService::getStaticMediaLibraryItemInfo($row['value'])); if (isset($info['type'])) { switch($info['type']) { case 'image': $row['value'] = rtrim(MOTO_ROOT_URL, '/') . '/' . $row['value']; break; case 'youtube': $row['value'] = $info['thumbnail']; break; default: return ''; } } else { return ''; } $data[strtolower($row['name']) . '_alt'] = (isset($info['alt']) && $info['alt'] != '' ? $info['alt'] : ''); $data[strtolower($row['name']) . '_title'] = (isset($info['title']) && $info['title'] != '' ? $info['title'] : ''); break; case 'htmlText': $row['value'] = $this->parent->clearHtmlTextMobile($row['value'], array('class'=>'htmlText')); break; } $data[strtolower($row['name'])] = $row['value']; } $tmpl = "\n" . '<a href="%preview%" title="%preview_title%"><img src="%thumbnail%" alt="%thumbnail_alt%" title="%thumbnail_title%" /></a>'; if (!isset($data['thumbnail'])) $tmpl = "\n" . '<img src="%preview%" alt="%preview_alt%" title="%preview_title%"/>'; elseif (!isset($data['preview'])) $tmpl = "\n" . '<img src="%thumbnail%" alt="%thumbnail_alt%" title="%thumbnail_title%"/>'; $html = $this->render($tmpl, $data); $html = str_replace(' title=""', '', $html); return $html; } function render($tmpl, $data) { $vars = explode(',', '%' . implode("%,%", array_keys($data)) . '%'); $values = array_values($data); return str_replace($vars, $values, $tmpl); } } 