Exemple #1
0
 public function getTranslations($args)
 {
     $pageId = (int) $args['pageId'];
     $table = DBUtil::getTables();
     $translatedTable = $table['content_translatedcontent'];
     $translatedColumn = $table['content_translatedcontent_column'];
     $contentTable = $table['content_content'];
     $contentColumn = $table['content_content_column'];
     $cols = DBUtil::_getAllColumns('content_translatedcontent');
     $ca = DBUtil::getColumnsArray('content_translatedcontent');
     $sql = "\n            SELECT {$cols}\n            FROM {$translatedTable} t\n            LEFT JOIN {$contentTable} c\n            ON c.{$contentColumn['id']} = t.{$translatedColumn['contentId']}\n            WHERE c.{$contentColumn['pageId']} = {$pageId}";
     $dbresult = DBUtil::executeSQL($sql);
     $translations = DBUtil::marshallObjects($dbresult, $ca);
     return $translations;
 }
Exemple #2
0
 protected function contentUpgrade_4_1_2($oldVersion)
 {
     $dbtables = DBUtil::getTables();
     $searchableTable = $dbtables['content_searchable'];
     $searchableColumn = $dbtables['content_searchable_column'];
     // add new primary key field and a language field
     $sql = 'ALTER TABLE `' . $searchableTable . '` CHANGE `search_cid` `search_cid` INT(11) NOT NULL;';
     if (!DBUtil::executeSQL($sql)) {
         return LogUtil::registerError($this->__('Error! Could not update searchable table (1).'));
     }
     $sql = 'ALTER TABLE `' . $searchableTable . '` DROP PRIMARY KEY;';
     if (!DBUtil::executeSQL($sql)) {
         return LogUtil::registerError($this->__('Error! Could not update searchable table (2).'));
     }
     $sql = 'ALTER TABLE `' . $searchableTable . '` ADD `search_sid` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST;';
     if (!DBUtil::executeSQL($sql)) {
         return LogUtil::registerError($this->__('Error! Could not update searchable table (3).'));
     }
     $sql = 'ALTER TABLE `' . $searchableTable . '` ADD `search_language` VARCHAR(10) NOT NULL AFTER `search_text`;';
     if (!DBUtil::executeSQL($sql)) {
         return LogUtil::registerError($this->__('Error! Could not update searchable table (4).'));
     }
     // update existing searchable data setting the default language code
     $defaultLanguage = System::getVar('language_i18n');
     $sql = "UPDATE `{$searchableTable}` SET `search_language` = '{$defaultLanguage}';";
     if (!DBUtil::executeSQL($sql)) {
         return LogUtil::registerError($this->__('Error! Could not update searchable table (5).'));
     }
     // check if we need to insert searchable rows for existing translations
     $multilingual = System::getVar('multilingual');
     if ($multilingual) {
         // retrieve existing translation languages
         $contentTable = $dbtables['content_content'];
         $contentColumn = $dbtables['content_content_column'];
         $translatedTable = $dbtables['content_translatedcontent'];
         $translatedColumn = $dbtables['content_translatedcontent_column'];
         $sql = "\n                SELECT DISTINCT {$translatedColumn['language']}\n                FROM {$translatedTable} t";
         $dbresult = DBUtil::executeSQL($sql);
         $languages = DBUtil::marshallObjects($dbresult);
         $cols = DBUtil::_getAllColumns('content_content');
         $ca = DBUtil::getColumnsArray('content_content');
         $ca[] = 'translated';
         // iterate translations
         foreach ($languages as $language) {
             // exclude the default language, since a page could have been created using another default language
             if ($language == $defaultLanguage) {
                 continue;
             }
             // get all translations for this language
             $sql = "\n                    SELECT {$cols}, {$translatedColumn['data']} AS translated\n                    FROM {$contentTable} c\n                    LEFT JOIN {$translatedTable} t\n                    AND t.{$translatedColumn['language']} = '{$language}'";
             $dbresult = DBUtil::executeSQL($sql);
             $content = DBUtil::marshallObjects($dbresult, $ca);
             $view = Zikula_View::getInstance('Content');
             $contentApi = new Content_Api_Content(ServiceUtil::getManager());
             for ($i = 0, $cou = count($content); $i < $cou; ++$i) {
                 $c =& $content[$i];
                 $c['data'] = empty($c['data']) ? null : unserialize($c['data']);
                 $c['translated'] = empty($c['translated']) ? null : unserialize($c['translated']);
                 // set translation as plugin content
                 if (is_array($c['translated']) && is_array($c['data'])) {
                     $c['data'] = array_merge($c['data'], $c['translated']);
                 }
                 // get access to the content plugin
                 $contentPlugin = $contentApi->getContentPlugin($c, $view);
                 // check if content is translatable
                 if (!$contentPlugin || !$contentPlugin->isTranslatable()) {
                     continue;
                 }
                 // extract searchable text
                 $text = $contentPlugin->getSearchableText();
                 // insert into searchable table
                 $searchObj = array('contentId' => $c['id'], 'text' => $text, 'language' => $language);
                 DBUtil::insertObject($searchObj, 'content_searchable', 'searchableId');
             }
         }
     }
     return true;
 }
Exemple #3
0
    /**
     * Get a list of pages
     *
     * This function returns an array of pages depending on the various parameters. The most
     * interesting parameter may be "filter" which contains all the restrictions on the list.
     * The filter data is passed to contentGetPageListRestrictions() which is where you
     * will find the documentation.
     *
     * @param filter array See contentGetPageListRestrictions().
     * @param orderBy string Field for "order by" in SQL query
     * @param orderDir string Direction for "order by" in SQL query (desc/asc) default: asc
     * @param pageIndex int Zero based page index for browsing page by page.
     * @param pageSize int Number of pages to show on each "page".
     * @param language string Three letter language identifier used for translating content.
     * @param translate bool Enable translation.
     * @param makeTree bool Enable conversion of page list to recursive tree structure.
     * @param includeContent bool Enable inclusion of content items.
     * @param includeCategories bool Enable inclusion of secondary category data.
     * @param includeLanguages bool Enable inclusion of list of translated languages (array('dan','eng')).
     * @param editing bool Passed to content plugins to enable "edit" display (as opposed to normal user display).
     *
     * @return array Array of pages (each of which is an associative array).
     */
    public function getPages($args)
    {
        $filter = isset($args['filter']) ? $args['filter'] : array();
        $orderBy = !empty($args['orderBy']) ? $args['orderBy'] : 'cr_date';
        $orderDir = !empty($args['orderDir']) ? $args['orderDir'] : 'asc';
        $pageIndex = isset($args['pageIndex']) ? $args['pageIndex'] : 0;
        $pageSize = isset($args['pageSize']) ? $args['pageSize'] : 0;
        $language = (array_key_exists('language', $args) ? $args['language'] : ZLanguage::getLanguageCode());
        $translate = (array_key_exists('translate', $args) ? $args['translate'] : true);
        $makeTree = (array_key_exists('makeTree', $args) ? $args['makeTree'] : false);
        $includeLayout = (array_key_exists('includeLayout', $args) ? $args['includeLayout'] : true);
        $includeContent = (array_key_exists('includeContent', $args) ? $args['includeContent'] : false);
        $expandContent = (array_key_exists('expandContent', $args) ? $args['expandContent'] : true);
        $includeCategories = (array_key_exists('includeCategories', $args) ? $args['includeCategories'] : false);
        $includeVersionNo = (array_key_exists('includeVersionNo', $args) ? $args['includeVersionNo'] : false);
        $editing = (array_key_exists('editing', $args) ? $args['editing'] : false);

        $dbtables = DBUtil::getTables();
        $pageTable = $dbtables['content_page'];
        $pageColumn = $dbtables['content_page_column'];
        //$pageCategoryTable = $dbtables['content_pagecategory'];
        //$pageCategoryColumn = $dbtables['content_pagecategory_column'];
        $translatedTable = $dbtables['content_translatedpage'];
        $translatedColumn = $dbtables['content_translatedpage_column'];
        $userTable = $dbtables['users'];
        $userColumn = $dbtables['users_column'];

        $restrictions = array();
        $join = '';

        $this->contentGetPageListRestrictions($filter, $restrictions, $join);

        if (count($restrictions) > 0) {
            $where = 'WHERE ' . join(' AND ', $restrictions);
        } else {
            $where = '';
        }

        if (!empty($orderBy)) {
            $orderBy = ' ORDER BY ' . DataUtil::formatForStore($orderBy);
            $orderBy .= $orderDir == 'desc' ? ' DESC' : ' ASC';
        }

        $language = DataUtil::formatForStore($language);

        $cols = DBUtil::_getAllColumns('content_page');
        $ca   = DBUtil::getColumnsArray('content_page');
        $ca[] = 'translatedTitle';
        $ca[] = 'translatedMetaDescription';
        $ca[] = 'translatedMetaKeywords';
        $ca[] = 'uname';

        $sql = "
            SELECT DISTINCT
            $cols,
            $translatedColumn[title],
            $translatedColumn[metadescription],
            $translatedColumn[metakeywords],
            $userColumn[uname]
            FROM $pageTable
            LEFT JOIN $translatedTable t
            ON t.$translatedColumn[pageId] = $pageColumn[id]
            AND t.$translatedColumn[language] = '$language'
            LEFT JOIN $userTable usr
            ON usr.$userColumn[uid] = $pageColumn[lu_uid]
            $join
            $where
            $orderBy";

        if ($pageSize > 0) {
            $dbresult = DBUtil::executeSQL($sql, $pageSize * $pageIndex, $pageSize);
        } else {
            $dbresult = DBUtil::executeSQL($sql);
        }

        $pages = DBUtil::marshallObjects($dbresult, $ca);

        if (isset($filter['expandedPageIds']) && is_array($filter['expandedPageIds'])) {
            $expandedPageIdsMap = $filter['expandedPageIds'];
        } else {
            $expandedPageIdsMap = null;
        }

        for ($i = 0, $cou = count($pages); $i < $cou; ++$i) {
            $p = &$pages[$i];
            $p['translated'] = array('title' => $p['translatedTitle'], 'metadescription' => $p['translatedMetaDescription'], 'metakeywords' => $p['translatedMetaKeywords']);
            if ($includeLayout) {
                $p['layoutData'] = ModUtil::apiFunc('Content', 'Layout', 'getLayout',
                                                    array('layout' => $p['layout']));
                $p['layoutTemplate'] = $p['layoutData']['template'];
                $p['layoutEditTemplate'] = $p['layoutData']['editTemplate'];
                $p['titleintemplate'] = $p['layoutData']['plugin']->titleInTemplate;
            } else {
                $p['layoutData'] = array();
                $p['layoutTemplate'] = $p['layoutEditTemplate'] = '';
            }
            if ($includeCategories) {
                $p['categories'] = $this->contentGetPageCategories($p['id']);
            }
            if ($includeVersionNo) {
                $p['versionNo'] = ModUtil::apiFunc('Content', 'History', 'getPageVersionNo', array('pageId' => $p['id']));
            }

            if (!empty($p['translatedTitle'])) {
                if ($translate) {
                    $p = array_merge($p, $p['translated']);
                }
                $p['isTranslated'] = true;
            } else {
                $p['isTranslated'] = false;
            }

            // create page variables that represent the Online and Menu status, much like the old db fields
            $now = DateUtil::getDatetime();
            $p['isOnline'] = $p['active'] && (DateUtil::getDatetimeDiff_AsField($p['activeFrom'], $now, 6) >= 0 || $p['activeFrom'] == null) && (DateUtil::getDatetimeDiff_AsField($p['activeTo'], $now, 6) < 0 || $p['activeTo'] == null);
            $p['isInMenu'] = $p['isOnline'] && $p['inMenu'];

            $content = null;
            if ($includeContent) {
                $content = ModUtil::apiFunc('Content', 'Content', 'getPageContent', array(
                            'pageId' => $p['id'],
                            'editing' => $editing,
                            'translate' => $translate,
                            'expandContent' => $expandContent));
                if ($content === false) {
                    return false;
                }
            }

            $p['content'] = $content;

            if ($expandedPageIdsMap !== null) {
                if (!empty($expandedPageIdsMap[$p['id']])) {
                    $p['isExpanded'] = 1;
                } else {
                    $p['isExpanded'] = 0;
                }
            }
        }

        if ($makeTree && count($pages) > 0) {
            $i = 0;
            $pages = $this->contentMakePageTree($pages, $i, $pages[0]['level']);
        }

        return $pages;
    }
Exemple #4
0
 public function MostCommentsBlock_getall($args = array())
 {
     if (!isset($args['numitems']) || !is_numeric($args['numitems'])) {
         $args['numitems'] = -1;
     }
     // Security check
     if (!SecurityUtil::checkPermission('EZComments::', '::', ACCESS_OVERVIEW)) {
         return array();
     }
     // Get database setup
     $pntable = pnDBGetTables();
     $table = $pntable['EZComments'];
     $columns =& $pntable['EZComments_column'];
     // form where clause
     $whereclause = array();
     if (isset($args['mod'])) {
         $whereclause[] = "{$columns['modname']} = '" . DataUtil::formatForStore($args['mod']) . "'";
     }
     // create where clause
     $where = '';
     if (!empty($whereclause)) {
         $where = implode(' AND ', $whereclause) . ' and ';
     }
     $permFilter[] = array('component_left' => 'EZComments', 'component_middle' => '', 'component_right' => '', 'instance_left' => 'modname', 'instance_middle' => 'objectid', 'instance_right' => 'id', 'level' => ACCESS_READ);
     $cols = DBUtil::_getAllColumns('EZComments');
     // FIXME: don't need all
     $ca = DBUtil::getColumnsArray('EZComments');
     $ca[] = "count";
     $sql = "\n    SELECT DISTINCT\n           {$cols},\n           count(*) as count\n    FROM {$table}\n    where {$where} {$columns['status']} = 0\n    group by {$columns['modname']},{$columns['objectid']}\n    order by count desc\n    ";
     $dbresult = DBUtil::executeSQL($sql, 0, $args['numitems']);
     $items = DBUtil::marshallObjects($dbresult, $ca);
     // backwards compatibilty: modname -> mod
     foreach (array_keys($items) as $k) {
         $items[$k]['mod'] = $items[$k]['modname'];
     }
     // return the items
     return $items;
 }
Exemple #5
0
    public function getTranslations($args)
    {
        $pageId = (int) $args['pageId'];

        $table = DBUtil::getTables();
        $translatedTable = $table['content_translatedcontent'];
        $translatedColumn = $table['content_translatedcontent_column'];
        $contentTable = $table['content_content'];
        $contentColumn = $table['content_content_column'];

        $cols = DBUtil::_getAllColumns('content_translatedcontent');
        $ca = DBUtil::getColumnsArray('content_translatedcontent');

        $sql = "
            SELECT $cols
            FROM $translatedTable t
            LEFT JOIN $contentTable c
            ON c.$contentColumn[id] = t.$translatedColumn[contentId]
            WHERE c.$contentColumn[pageId] = $pageId";

        $dbresult = DBUtil::executeSQL($sql);

        $translations = DBUtil::marshallObjects($dbresult, $ca);

        return $translations;
    }