Ejemplo n.º 1
0
 public function output()
 {
     $outputValues = $this->getValues();
     switch ($this->getRequestType()) {
         case self::REQUEST_JSON:
             header('Content-Type: application/json');
             $iaUtil = $this->iaCore->factory('util');
             if (isset($outputValues[self::JSON_MAGIC_KEY]) && 1 == count($outputValues)) {
                 $outputValues = array_values($outputValues[self::JSON_MAGIC_KEY]);
             }
             echo $iaUtil->jsonEncode($outputValues);
             break;
         case self::REQUEST_HTML:
             header('Content-Type: text/html');
             $iaSmarty =& $this->iaSmarty;
             foreach ($outputValues as $key => $value) {
                 $iaSmarty->assign($key, $value);
             }
             // set page notifications
             $messages = $this->getMessages();
             $notifications = array();
             foreach (array(self::ERROR, self::SUCCESS, self::ALERT, self::SYSTEM) as $type) {
                 empty($messages[$type]) || ($notifications[$type] = is_array($messages[$type]) ? $messages[$type] : array($messages[$type]));
             }
             $pageName = $this->name();
             if (iaCore::ACCESS_ADMIN == $this->iaCore->getAccessType()) {
                 $adminActions = self::PAGE_ERROR == $pageName ? array() : $this->_getAdminToolbarActions();
                 $this->set('toolbarActions', $adminActions);
             }
             $iaSmarty->assign('member', iaUsers::hasIdentity() ? iaUsers::getIdentity(true) : array());
             // define smarty super global $core
             $core = array('actions' => $this->_setActions(), 'config' => $this->iaCore->getConfig(), 'customConfig' => $this->iaCore->getCustomConfig(), 'language' => $this->iaCore->languages[$this->language], 'languages' => $this->iaCore->languages, 'notifications' => $notifications, 'packages' => $this->iaCore->packagesData, 'page' => array('breadcrumb' => iaBreadcrumb::render(), 'info' => $this->getParams(), 'nonProtocolUrl' => $this->assetsUrl, 'name' => $pageName, 'title' => $this->get('caption', $this->get('title', 'Subrion CMS'))), 'providers' => iaUsers::getAuthProviders());
             if (iaCore::ACCESS_FRONT == $this->iaCore->getAccessType()) {
                 // get meta-description
                 $value = $this->get('description');
                 $metaDescription = empty($value) && iaLanguage::exists('page_metadescr_' . $pageName) ? iaLanguage::get('page_metadescr_' . $pageName) : $value;
                 $core['page']['meta-description'] = iaSanitize::html($metaDescription);
                 // get meta-keywords
                 $value = $this->get('keywords');
                 $metaKeywords = empty($value) && iaLanguage::exists('page_metakeyword_' . $pageName) ? iaLanguage::get('page_metakeyword_' . $pageName) : $value;
                 $core['page']['meta-keywords'] = iaSanitize::html($metaKeywords);
                 $this->_logStatistics();
                 header('X-Powered-CMS: Subrion CMS');
             }
             $iaSmarty->assignByRef('core', $core);
             $this->iaCore->startHook('phpCoreDisplayBeforeShowBody');
             $content = '';
             if ($this->get('body', self::NONE) != self::NONE) {
                 $content = $iaSmarty->fetch($this->_retrieveTemplatePath($this->get('body')));
             }
             if ($this->_layoutEnabled) {
                 $iaSmarty->assign('_content_', $content);
                 $content = $iaSmarty->fetch('layout' . self::TEMPLATE_FILENAME_EXT);
             }
             echo $content;
             break;
         case self::REQUEST_XML:
             header('Content-Type: text/xml');
             function htmldecode($text)
             {
                 $text = html_entity_decode($text);
                 $text = htmlspecialchars($text);
                 return $text;
             }
             function xmlEncode(array $array, &$parentObject)
             {
                 static $section;
                 foreach ($array as $key => $value) {
                     switch (true) {
                         case is_array($array[key($array)]):
                             if (!is_numeric($key)) {
                                 $node = $parentObject->addChild($key);
                                 xmlEncode($value, $node);
                             } else {
                                 $node = $parentObject->addChild($section);
                                 foreach ($value as $k => $v) {
                                     $node->addChild($k, htmldecode($v));
                                 }
                             }
                             break;
                         case is_array($value):
                             $section = $key;
                             xmlEncode($value, $parentObject);
                             break;
                         default:
                             $parentObject->addChild($key, htmldecode($value));
                     }
                 }
             }
             $xmlObject = new SimpleXMLElement('<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"></rss>');
             xmlEncode($outputValues, $xmlObject);
             echo $xmlObject->asXML();
             break;
         default:
             header('HTTP/1.1 501');
             exit;
     }
 }
Ejemplo n.º 2
0
 public function delete($id, $log = true)
 {
     $iaDb =& $this->iaDb;
     $row = $iaDb->row(iaDb::ALL_COLUMNS_SELECTION, iaDb::convertIds($id));
     $title = self::LANG_PATTERN_TITLE . $id;
     $title = iaLanguage::exists($title) ? iaLanguage::get($title) : $row['title'];
     $this->iaCore->startHook('beforeBlockDelete', array('block' => &$row));
     $result = parent::delete($id);
     if ($result) {
         $iaDb->delete('`object_type` = :object && `object` = :id', self::getPagesTable(), array('id' => $id, 'object' => 'blocks'));
         $iaDb->delete('`key` = :title OR `key` = :content', iaLanguage::getTable(), array('title' => self::LANG_PATTERN_TITLE . $id, 'content' => self::LANG_PATTERN_CONTENT . $id));
         if ($log) {
             $this->iaCore->factory('log')->write(iaLog::ACTION_DELETE, array('item' => 'block', 'name' => $title, 'id' => $id));
         }
     }
     $this->iaCore->startHook('afterBlockDelete', array('block' => &$row));
     return $result;
 }