<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Api_PageTemplate extends vB_Api { public function fetchPageTemplateList($pagetemplateid) { $this->checkHasAdminPermission('canusesitebuilder'); $pagetemplateid = (int) $pagetemplateid; if ($pagetemplateid < 0) { $pagetemplateid = 0; } $db = vB::getDbAssertor(); $values = array('pagetemplateid' => $pagetemplateid); $result = $db->assertQuery('fetch_page_template_list', $values, 'title'); $phraseLib = vB_Library::instance('phrase'); $phrasestofetch = array(); foreach ($result AS $row) { $phrasestofetch[] = 'pagetemplate_' . $phraseLib->cleanGuidForPhrase($row['guid']) . '_title'; } $vbphrases = vB_Api::instanceInternal('phrase')->fetch(array_unique($phrasestofetch)); $pageTemplates = array(); foreach ($result AS $row) { $guidforphrase = $phraseLib->cleanGuidForPhrase($row['guid']); $phrasename = 'pagetemplate_' . $guidforphrase . '_title'; if (!empty($vbphrases[$phrasename])) { $row['title'] = $vbphrases[$phrasename]; } $pageTemplates[$row['pagetemplateid']] = $row; } foreach ($pageTemplates AS $k => $v) { $pageTemplates[$k]['widgetinstances'] = array(); } $widgets = $db->getRows('widget', array(), '', 'widgetid'); $widgetInstances = $db->getRows('widgetinstance', array(), array('displaysection', 'displayorder')); foreach ($widgetInstances AS $widgetInstance) { $pageTemplateId = $widgetInstance['pagetemplateid']; if (isset($pageTemplates[$pageTemplateId])) { $widgetInstance['title'] = ''; $pageTemplates[$pageTemplateId]['widgetinstances'][] = $widgetInstance; } } return array_values($pageTemplates); } } 