Beispiel #1
0
    /**
     * modify a news entry (incl. delete) via ajax
     *
     * @author Frank Schummertz
     * @param 'sid'   int the story id
     * @param 'page'   int the story page
     * @return string HTML string
     */
    public function modify()
    {
        $this->checkAjaxToken();

        $sid = $this->request->getPost()->get('sid');
        $page = $this->request->getPost()->get('page', 1);

        // Get the news article
        $item = ModUtil::apiFunc('News', 'User', 'get', array('sid' => $sid));
        if ($item == false) {
            throw new Zikula_Exception_NotFound($this->__('Error! No such article found.'));
        }

        // Security check
        $this->throwForbiddenUnless(SecurityUtil::checkPermission('News::', "{$item['cr_uid']}::$sid", ACCESS_EDIT));

        // Get the format types. 'home' string is bits 0-1, 'body' is bits 2-3.
        $item['hometextcontenttype'] = ($item['format_type'] % 4);
        $item['bodytextcontenttype'] = (($item['format_type'] / 4) % 4);

        // Set the publishing date options.
        if (!isset($item['to'])) {
            if (DateUtil::getDatetimeDiff_AsField($item['from'], $item['cr_date'], 6) >= 0 && is_null($item['to'])) {
                $item['unlimited'] = 1;
                $item['tonolimit'] = 1;
            } elseif (DateUtil::getDatetimeDiff_AsField($item['from'], $item['cr_date'], 6) < 0 && is_null($item['to'])) {
                $item['unlimited'] = 0;
                $item['tonolimit'] = 1;
            }
        } else {
            $item['unlimited'] = 0;
            $item['tonolimit'] = 0;
        }

        Zikula_AbstractController::configureView();
        $this->view->setCaching(false);

        $modvars = $this->getVars();

        if ($modvars['enablecategorization']) {
            $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('News', 'news');
            $this->view->assign('catregistry', $catregistry);
        }
        
        $this->view->assign('accessadd', 0);
        if (SecurityUtil::checkPermission('News::', '::', ACCESS_ADD)) {
            $this->view->assign('accessadd', 1);
            $this->view->assign('accesspicupload', 1);
            $this->view->assign('accesspubdetails', 1);
        } else {
            $this->view->assign('accesspicupload', SecurityUtil::checkPermission('News:pictureupload:', '::', ACCESS_ADD));
            $this->view->assign('accesspubdetails', SecurityUtil::checkPermission('News:publicationdetails:', '::', ACCESS_ADD));
        }

        // Assign the item to the template
        $this->view->assign('item', $item);

        // Assign the current page
        $this->view->assign('page', $page);

        // Assign the default languagecode
        $this->view->assign('lang', ZLanguage::getLanguageCode());

        // Assign the content format
        $formattedcontent = ModUtil::apiFunc('News', 'User', 'isformatted', array('func' => 'modify'));
        $this->view->assign('formattedcontent', $formattedcontent);

        //lock the page so others cannot edit it
        if (ModUtil::available('PageLock')) {
            $returnUrl = ModUtil::url('News', 'admin', 'view');
            ModUtil::apiFunc('PageLock', 'user', 'pageLock',
                            array('lockName' => "Newsnews{$item['sid']}",
                                'returnUrl' => $returnUrl));
        }

        // Return the output that has been generated by this function
        return new Zikula_Response_Ajax(array('result' => $this->view->fetch('ajax/modify.tpl')));
    }
Beispiel #2
0
    /**
     * Display the data to the containing Content page
     */
    public function display()
    {
        // Parameters for category related items properties like topicimage
        $lang = ZLanguage::getLanguageCode();
        $topicProperty = ModUtil::getVar('News', 'topicproperty');
        $topicField = empty($topicProperty) ? 'Main' : $topicProperty;

        // work out the parameters for the News api call
        $apiargs = array();
        switch ($this->show)
        {
            case 3: // non index page articles
                $apiargs['displayonindex'] = 0;
                break;
            case 2: // index page articles
                $apiargs['displayonindex'] = 1;
                break;
            // all - doesn't need displayonindex
        }
        $apiargs['numitems'] = $this->limit; // Nr of articles to obtain
        $apiargs['status'] = (int) $this->status; // Published status
        // Handle the sorting order
        switch ($this->orderoptions)
        {
            case 2:
                $apiargs['order'] = 'weight';
                break;
            case 3:
                $apiargs['order'] = 'random';
                break;
            case 1:
                $apiargs['order'] = 'counter';
                break;
            case 0:
            default:
            // Use News module setting, so don't set apiargs[order]
        }

        $enablecategorization = ModUtil::getVar('News', 'enablecategorization');

        // Make a category filter only if categorization is enabled in News module
        if ($enablecategorization && $this->categories != null) {
            // Get the registrered categories for the News module
            $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('News', 'news');
            $apiargs['catregistry'] = $catregistry;
            $apiargs['category'] = $this->categories;
        }

        // Limit the shown articles in days using DateUtil
        if ((int) $this->dayslimit > 0 && $vars['order'] == 0) {
            $apiargs['from'] = DateUtil::getDatetime_NextDay(-$this->dayslimit);
            $apiargs['to'] = DateUtil::getDatetime();
        }

        // Apply datefiltering
        $apiargs['filterbydate'] = true;

        // call the News api and get the requested articles with the above arguments
        $items = ModUtil::apiFunc('News', 'user', 'getall', $apiargs);

        // UserUtil is not automatically loaded, so load it now if needed and set anonymous
        if ($this->dispuname) {
            $anonymous = System::getVar('anonymous');
        }

        // check for an empty return
        if (!empty($items)) {
            // loop through the items and prepare for display
            foreach (array_keys($items) as $k)
            {
                // Get specific information from the article. It was a choice not to use the pnuserapi functions
                // GetArticleInfo, GetArticleLinks and getArticlesPreformat because of speed etc.
                // --- Check for Topic related properties like topicimage, topicsearchurl etc.
                if ($enablecategorization && !empty($items[$k]['__CATEGORIES__']) && isset($items[$k]['__CATEGORIES__'][$topicField])) {
                    $items[$k]['topicid'] = $items[$k]['__CATEGORIES__'][$topicField]['id'];
                    $items[$k]['topicname'] = isset($items[$k]['__CATEGORIES__'][$topicField]['display_name'][$lang]) ? $items[$k]['__CATEGORIES__'][$topicField]['display_name'][$lang] : $items[$k]['__CATEGORIES__'][$topicField]['name'];
                    // set the topic image if topic_image category property exists
                    $items[$k]['topicimage'] = (isset($items[$k]['__CATEGORIES__'][$topicField]['__ATTRIBUTES__']) && isset($items[$k]['__CATEGORIES__'][$topicField]['__ATTRIBUTES__']['topic_image'])) ? $items[$k]['__CATEGORIES__'][$topicField]['__ATTRIBUTES__']['topic_image'] : '';
                    // set the topic description if exists
                    $items[$k]['topictext'] = isset($items[$k]['__CATEGORIES__'][$topicField]['display_desc'][$lang]) ? $items[$k]['__CATEGORIES__'][$topicField]['display_desc'][$lang] : '';
                    // set the path of the topic
                    $items[$k]['topicpath'] = isset($items[$k]['__CATEGORIES__'][$topicField]['path_relative']) ? $items[$k]['__CATEGORIES__'][$topicField]['path_relative'] : '';
                    // set the url to search for this topic
                    if (System::getVar('shorturls', false)) {
                        $items[$k]['topicsearchurl'] = DataUtil::formatForDisplay(ModUtil::url('News', 'user', 'view', array('prop' => $topicField, 'cat' => $items[$k]['topicpath'])));
                    } else {
                        $items[$k]['topicsearchurl'] = DataUtil::formatForDisplay(ModUtil::url('News', 'user', 'view', array('prop' => $topicField, 'cat' => $items[$k]['topicid'])));
                    }
                } else {
                    $items[$k]['topicid'] = null;
                    $items[$k]['topicname'] = '';
                    $items[$k]['topicimage'] = '';
                    $items[$k]['topictext'] = '';
                    $items[$k]['topicpath'] = '';
                    $items[$k]['topicsearchurl'] = '';
                }

                // Optional new image if the difference in days from the publishing date and now < the specified limit
                $items[$k]['dispnewimage'] = ($this->dispnewimage && DateUtil::getDatetimeDiff_AsField($items[$k]['from'], DateUtil::getDatetime(), 3) < (int) $this->newimagelimit);
                // Wrap the title if needed
                $items[$k]['titlewrapped'] = false;
                if ((int) $this->maxtitlelength > 0 && strlen($items[$k]['title']) > (int) $this->maxtitlelength) {
                    // wrap the title
                    $items[$k]['title'] = substr($items[$k]['title'], 0, (int) $this->maxtitlelength);
                    $items[$k]['titlewrapped'] = true;
                    //$items[$k]['title'] .= $this->titlewraptext;
                }
                // Get the user information from the author id
                if ($this->dispuname) {
                    if ($items[$k]['cr_uid'] == 0) {
                        $items[$k]['uname'] = $anonymous;
                        $items[$k]['aid_name'] = $anonymous;
                    } else {
                        $user = UserUtil::getVars($items[$k]['cr_uid']);
                        $items[$k]['uname'] = $user['uname'];
                        $items[$k]['aid_name'] = $user['uname'];
                    }
                }
                // Get the optional commentcount if EZComments is available
                if ($this->dispcomments && ModUtil::available('EZComments')) {
                    $items[$k]['comments'] = ModUtil::apiFunc('EZComments', 'user', 'countitems', array('mod' => 'News', 'objectid' => $items[$k]['sid'], 'status' => 0));
                }
                // Optional display of the hometext (frontpage teaser)
                if ($this->disphometext) {
                    if ($this->maxhometextlength > 0 && strlen(strip_tags($items[$k]['hometext'])) > (int) $this->maxhometextlength) {
                        $items[$k]['hometextwrapped'] = true;
                    }
                }
                $items[$k]['readperm'] = (SecurityUtil::checkPermission('News::', "$items[$k][cr_uid]::$items[$k][sid]", ACCESS_READ));
            }
            if ($this->dispuname || $this->dispdate || $this->dispreads || $this->dispcomments) {
                $this->view->assign('dispinfo', true);
                $this->view->assign('dispuname', $this->dispuname);
                $this->view->assign('dispdate', $this->dispdate);
                $this->view->assign('dispreads', $this->dispreads);
                $this->view->assign('dispcomments', $this->dispcomments);
                $this->view->assign('dispsplitchar', $this->dispsplitchar);
            } else {
                $this->view->assign('dispinfo', false);
            }
            if ($this->dispnewimage) {
                $this->view->assign('newimageset', $this->newimageset);
                $this->view->assign('newimagesrc', $this->newimagesrc);
            }
            $this->view->assign('disphometext', $this->disphometext);
            if ($this->disphometext) {
                $this->view->assign('hometextwraptext', $this->hometextwraptext);
                $this->view->assign('maxhometextlength', $this->maxhometextlength);
            }
            $this->view->assign('titlewraptext', $this->titlewraptext);
        }
        $this->view->assign('News', ModUtil::getVar('News'));
        $this->view->assign('dateformat', $this->dateformat);
        $this->view->assign('linktosubmit', $this->linktosubmit);
        $this->view->assign('stories', $items);
        $this->view->assign('title', $this->title);
        $this->view->assign('displayStoryImage', $this->displayStoryImage);
        $this->view->assign('useshorturls', System::getVar('shorturls', false));

        return $this->view->fetch($this->getTemplate());
    }
Beispiel #3
0
    /**
     * display block
     *
     * @author       Erik Spaan [espaan]
     * @param        array       $blockinfo     a blockinfo structure
     * @return       output      the rendered bock
     */
    public function display($blockinfo)
    {
        if (!SecurityUtil::checkPermission('Storiesextblock::', "$blockinfo[bid]::", ACCESS_OVERVIEW)) {
            return;
        }

        // Break out options from our content field
        $vars = BlockUtil::varsFromContent($blockinfo['content']);
        // Get the News categorization setting
        $enablecategorization = ModUtil::getVar('News', 'enablecategorization');
        $lang = ZLanguage::getLanguageCode();
        $topicProperty = ModUtil::getVar('News', 'topicproperty');
        $topicField = empty($topicProperty) ? 'Main' : $topicProperty;
        $catimagepath = ModUtil::getVar('News', 'catimagepath');

        // --- Setting of the Defaults
        if (!isset($vars['category'])) {
            $vars['category'] = null;
        }
        if (!isset($vars['show'])) {
            $vars['show'] = 1;
        }
        if (!isset($vars['status'])) {
            $vars['status'] = 0;
        }
        if (!isset($vars['order'])) {
            $vars['order'] = 0;
        }
        if (!isset($vars['limit'])) {
            $vars['limit'] = 5;
        }
        // Maximum article age in days
        if (!isset($vars['dayslimit'])) {
            $vars['dayslimit'] = 0;
        }
        // Maximum title length
        if (!isset($vars['maxtitlelength'])) {
            $vars['maxtitlelength'] = 0;
        }
        if (!isset($vars['titlewraptxt'])) {
            $vars['titlewraptxt'] = '...';
        }
        // Show 'No News' message instead of empty block
        if (!isset($vars['showemptyresult'])) {
            $vars['showemptyresult'] = 0;
        }
        // Override templates for the block and row display
        if (!isset($vars['blocktemplate'])) {
            $vars['blocktemplate'] = '';
        }
        if (!isset($vars['rowtemplate'])) {
            $vars['rowtemplate'] = '';
        }
        // Display optional article information
        $vars['dispuname'] = (!isset($vars['dispuname'])) ? false : !empty($vars['dispuname']);
        $vars['dispdate'] = (!isset($vars['dispdate'])) ? true : !empty($vars['dispdate']);
        if (!isset($vars['dateformat'])) {
            $vars['dateformat'] = '%x';
        }
        $vars['dispreads'] = (!isset($vars['dispreads'])) ? false : !empty($vars['dispreads']);
        $vars['dispcomments'] = (!isset($vars['dispcomments'])) ? false : !empty($vars['dispcomments']);
        if (!isset($vars['dispsplitchar'])) {
            $vars['dispsplitchar'] = ', ';
        }
        // Display (part of) the hometext of the article
        $vars['disphometext'] = (!isset($vars['disphometext'])) ? false : !empty($vars['disphometext']);
        if (!isset($vars['maxhometextlength'])) {
            $vars['maxhometextlength'] = 0;
        }
        if (!isset($vars['hometextwraptxt'])) {
            $vars['hometextwraptxt'] = '...';
        }
        // Display of a new story image
        $vars['dispnewimage'] = (!isset($vars['dispnewimage'])) ? false : !empty($vars['dispnewimage']);
        if (!isset($vars['newimagelimit'])) {
            $vars['newimagelimit'] = 3;
        }
        if (!isset($vars['newimageset'])) {
            $vars['newimageset'] = 'icons/extrasmall/';
        }
        if (!isset($vars['newimagesrc'])) {
            $vars['newimagesrc'] = 'favorites.png';
        }
        // display the items in a scrolling box, pausing, fading or marquee
        if (!isset($vars['scrolling'])) {
            $vars['scrolling'] = 1;
        }
        if (!isset($vars['scrollstyle'])) {
            $vars['scrollstyle'] = '%DIVID% {
width:inherit;
overflow:hidden;
position:relative;
padding:2px;
border:0px solid black;
background:transparent;
/* IE: Height + 2*padding + 2*border */
height:54px;
voice-family: "\"}\"";
voice-family:inherit;
/* regular height */
height:50px;
}
/* Opera browser */
html>body %DIVID% {
height:50px;
}';
        }
        if (!isset($vars['scrolldelay'])) {
            $vars['scrolldelay'] = 3000;
        }
        if (!isset($vars['scrollmspeed'])) {
            $vars['scrollmspeed'] = 2;
        }
        $scrollfilterduration = 1.0;

        // --- Work out the parameters for the News api call, fill the apiargs array with the necessary fields
        $apiargs = array();
        switch ($vars['show'])
        {
            case 3: // non index page articles
                $apiargs['displayonindex'] = 0;
                break;
            case 2: // index page articles
                $apiargs['displayonindex'] = 1;
                break;
            // all - doesn't need displayonindex
        }
        $apiargs['numitems'] = $vars['limit']; // Nr of articles to obtain
        $apiargs['status'] = $vars['status']; // Published status

        // Make a category filter only if categorization is enabled in News module
        if ($enablecategorization) {
            // Get the registrered categories for the News module
            $catregistry  = CategoryRegistryUtil::getRegisteredModuleCategories('News', 'news');
            $apiargs['catregistry'] = $catregistry;
            $apiargs['category'] = $vars['category'];
        }

        // Limit the shown articles in days using DateUtil
        if ((int)$vars['dayslimit'] > 0 && $vars['order'] == 0) {
            $apiargs['from'] = DateUtil::getDatetime_NextDay(-$vars['dayslimit']);
            $apiargs['to'] = DateUtil::getDatetime();
        }

        // Handle the sorting order
        switch ($vars['order'])
        {
            case 2:
                $apiargs['order'] = 'weight';
                break;
            case 3:
                $apiargs['order'] = 'random';
                break;
            case 1:
                $apiargs['order'] = 'counter';
                break;
            case 0:
            default:
            // Use News module setting, so don't set apiargs[order]
        }

        // Make sure datefiltering is done. Solves #12
        $apiargs['filterbydate'] = true;

        // Call the News api and get the requested articles with the above arguments
        $items = ModUtil::apiFunc('News', 'user', 'getall', $apiargs);

        // check for an empty return
        if (empty($items)) {
            if ($vars['showemptyresult']) {
                // Show empty result message instead of empty block if variable is set
                $blockinfo['content'] = $this->__('No articles.');
                return BlockUtil::themeBlock($blockinfo);
            } else {
                return;
            }
        }

        // UserUtil is not automatically loaded, so load it now if needed and set anonymous
        if ($vars['dispuname']) {
            $anonymous = System::getVar('anonymous');
        }

        // --- Select the configurable row template or the default. The row templates is cached with its sid (storyid)
        $storiesoutput = array();
        if (!empty($vars['rowtemplate'])) {
            $rowtemplate = $vars['rowtemplate'];
        } else {
            $rowtemplate = 'block/storiesext/row.tpl';
        }

        // --- loop through the items and prepare every News item for display
        foreach ($items as $item) {
            // Get specific information from the article. It was a choice not to use the pnuserapi functions
            // GetArticleInfo, GetArticleLinks and getArticlesPreformat because of speed etc.
            // --- Check for Topic related properties like topicimage, topicsearchurl etc.
            if ($enablecategorization && !empty($item['__CATEGORIES__']) && isset($item['__CATEGORIES__'][$topicField])) {
                $item['topicid'] = $item['__CATEGORIES__'][$topicField]['id'];
                $item['topicname'] = isset($item['__CATEGORIES__'][$topicField]['display_name'][$lang]) ? $item['__CATEGORIES__'][$topicField]['display_name'][$lang] : $item['__CATEGORIES__'][$topicField]['name'];
                // set the topic image if topic_image category property exists
                $item['topicimage'] = (isset($item['__CATEGORIES__'][$topicField]['__ATTRIBUTES__']) && isset($item['__CATEGORIES__'][$topicField]['__ATTRIBUTES__']['topic_image'])) ? $item['__CATEGORIES__'][$topicField]['__ATTRIBUTES__']['topic_image'] : '';
                // set the topic description if exists
                $item['topictext'] = isset($item['__CATEGORIES__'][$topicField]['display_desc'][$lang]) ? $item['__CATEGORIES__'][$topicField]['display_desc'][$lang] : '';
                // set the path of the topic
                $item['topicpath']  = $item['__CATEGORIES__'][$topicField]['path_relative'];
                // set the url to search for this topic
                if (System::getVar('shorturls', false)) {
                    $item['topicsearchurl'] = DataUtil::formatForDisplay(ModUtil::url('News', 'user', 'view', array('prop' => $topicField, 'cat' => $item['topicpath'])));
                } else {
                    $item['topicsearchurl'] = DataUtil::formatForDisplay(ModUtil::url('News', 'user', 'view', array('prop' => $topicField, 'cat' => $item['topicid'])));
                }
            } else {
                $item['topicid']    = null;
                $item['topicname']  = '';
                $item['topicimage'] = '';
                $item['topictext']  = '';
                $item['topicpath']  = '';
                $item['topicsearchurl'] = '';
            }
            // Optional new image if the difference in days from the publishing date and now < the limit
            $item['itemnewimage'] = ($vars['dispnewimage'] && DateUtil::getDatetimeDiff_AsField($item['from'], DateUtil::getDatetime(), 3) < (int)$vars['newimagelimit']);
            // Wrap the title if needed
            $item['titlewrapped'] = false;
            if ($vars['maxtitlelength'] > 0 && strlen($item['title']) > (int)$vars['maxtitlelength'])  {
                // wrap the title with wordwrap (instead of substr)
                $a = explode('[[[wrap]]]', wordwrap($item['title'], (int)$vars['maxtitlelength'], '[[[wrap]]]'));
                $item['title'] = $a[0];
                $item['titlewrapped'] = true;
            }
            if ($vars['dispuname']) {
                // Get the user information from the author id
                if ($item['cr_uid'] == 0) {
                    $this->view->assign('uname', $anonymous);
                    $this->view->assign('aid_name', $anonymous);
                } else {
                    $user = UserUtil::getVars($item['cr_uid']);
                    $this->view->assign('uname', $user['uname']);
                    $this->view->assign('aid_name', $user['name']);
                }
            }
            // Check for EZComments
            if ($vars['dispcomments'] && ModUtil::available('EZComments')) {
                $item['comments'] = ModUtil::apiFunc('EZComments', 'user', 'countitems', array('mod' => 'News', 'objectid' => $item['sid'], 'status' => 0));
            }
            if ($vars['disphometext']) {
                if ($vars['maxhometextlength'] > 0 && strlen(strip_tags($item['hometext'])) > (int)$vars['maxhometextlength']) {
                    $item['hometextwrapped'] = true;
                }
            }
            if ($vars['dispuname']||$vars['dispdate']||$vars['dispreads']||$vars['dispcomments']) {
                $this->view->assign('dispinfo', true);
            }
            $this->view->assign('readperm',(bool)SecurityUtil::checkPermission('News::', "$item[cr_uid]::$item[sid]", ACCESS_READ));
            $this->view->assign($vars);
            $this->view->assign($item);
            // Get the cached output per row
            $storiesoutput[] = $this->view->fetch($rowtemplate, $item['sid']);
        }

        // Turn of caching for the block display
        $this->view->setCaching(false);

        // Use the configured template if set, otherwise use the default static/scrolling ones.
        if (!empty($vars['blocktemplate'])) {
            $blocktemplate = $vars['blocktemplate'];
        } else {
            $blocktemplate = 'block/storiesext/main.tpl';
            if ((int)$vars['scrolling']>1) {
                switch ((int)$vars['scrolling']) {
                    case 2:
                        $blocktemplate = 'block/storiesext/scrollpause.tpl';
                        break;
                    case 3:
                        $blocktemplate = 'block/storiesext/scrollfade.tpl';
                        // Add the IE fading effect to the existing scrollstyle
                        $vars['scrollstyle'] .= '%DIVID% {filter: progid:DXImageTransform.Microsoft.GradientWipe(GradientSize=1.0 Duration=' . $scrollfilterduration . ')}';
                        break;
                    case 4:
                        $blocktemplate = 'block/storiesext/scrollmarquee.tpl';
                        $this->view->assign('scrollmspeed', $vars['scrollmspeed']);
                        break;
                }
                $this->view->assign('scrollstyle', $vars['scrollstyle']);
                $this->view->assign('scrolldelay', $vars['scrolldelay']);
            }
        }
        $this->view->assign('catimagepath', $catimagepath);
        $this->view->assign('bid', $blockinfo['bid']);
        $this->view->assign('stories', $storiesoutput);

        $blockinfo['content'] = $this->view->fetch($blocktemplate);

        return BlockUtil::themeBlock($blockinfo);
    }
Beispiel #4
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;
    }
Beispiel #5
0
    /**
     * view items
     * @param int 'startnum' starting number for paged output
     * @author Mark West
     * @return string HTML string
     */
    public function view($args)
    {
        $this->throwForbiddenUnless(SecurityUtil::checkPermission('News::', '::', ACCESS_EDIT), LogUtil::getErrorMsgPermission());

        // initialize sort array - used to display sort classes and urls
        $sort = array();
        $fields = array('sid', 'weight', 'from'); // possible sort fields
        foreach ($fields as $field) {
            $sort['class'][$field] = 'z-order-unsorted'; // default values
        }

        $startnum = FormUtil::getPassedValue('startnum', isset($args['startnum']) ? $args['startnum'] : null, 'GETPOST');
        $news_status = FormUtil::getPassedValue('news_status', isset($args['news_status']) ? $args['news_status'] : null, 'GETPOST');
        $language = FormUtil::getPassedValue('news_language', isset($args['news_language']) ? $args['news_language'] : null, 'GETPOST');
        $purge = FormUtil::getPassedValue('purge', false, 'GET');
        $order = FormUtil::getPassedValue('order', isset($args['order']) ? $args['order'] : 'from', 'GETPOST');
        $original_sdir = FormUtil::getPassedValue('sdir', isset($args['sdir']) ? $args['sdir'] : 1, 'GETPOST');

        $this->view->assign('startnum', $startnum);
        $this->view->assign('order', $order);
        $this->view->assign('sdir', $original_sdir);
        $this->view->assign('selected_language', (isset($language)) ? $language : '');
        
        $sdir = $original_sdir ? 0 : 1; //if true change to false, if false change to true
        // change class for selected 'orderby' field to asc/desc
        if ($sdir == 0) {
            $sort['class'][$order] = 'z-order-desc';
            $orderdir = 'DESC';
        }
        if ($sdir == 1) {
            $sort['class'][$order] = 'z-order-asc';
            $orderdir = 'ASC';
        }
        $filtercats = FormUtil::getPassedValue('news', null, 'GETPOST');
        $filtercats_serialized = FormUtil::getPassedValue('filtercats_serialized', false, 'GET');
        $filtercats = $filtercats_serialized ? unserialize($filtercats_serialized) : $filtercats;
        $catsarray = News_Util::formatCategoryFilter($filtercats);

        // complete initialization of sort array, adding urls
        foreach ($fields as $field) {
            $sort['url'][$field] = ModUtil::url('News', 'admin', 'view', array(
                        'news_status' => $news_status,
                        'news_language' => $language,
                        'filtercats_serialized' => serialize($filtercats),
                        'order' => $field,
                        'sdir' => $sdir));
        }
        $this->view->assign('sort', $sort);

        $this->view->assign('filter_active', (!isset($language) && !isset($news_status) && empty($filtercats)) ? false : true);

        if ($purge) {
            if (ModUtil::apiFunc('News', 'admin', 'purgepermalinks')) {
                LogUtil::registerStatus($this->__('Done! Purged permalinks.'));
            } else {
                LogUtil::registerError($this->__('Error! Could not purge permalinks.'));
            }
            return $this->redirect(strpos(System::serverGetVar('HTTP_REFERER'), 'purge') ? ModUtil::url('News', 'admin', 'view') : System::serverGetVar('HTTP_REFERER'));
        }

        // clean the session preview data
        SessionUtil::delVar('newsitem');

        // get module vars for later use
        $modvars = $this->getVars();

        if ($modvars['enablecategorization']) {
            $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('News', 'news');
            $this->view->assign('catregistry', $catregistry);
        }

        $multilingual = System::getVar('multilingual', false);

        $now = DateUtil::getDatetime();
        $status = null;
        if (isset($news_status) && $news_status != '') {
            if ($news_status == 0) {
                $status = 0;
                $to = $now;
            } elseif ($news_status == 5) {
                // scheduled is actually the published status, but in the future
                $status = 0;
                $from = $now;
            } else {
                $status = $news_status;
            }
        }

        // Get all news stories
        $getallargs = array('startnum' => $startnum,
            'status' => $status,
            'numitems' => $modvars['itemsperadminpage'],
            'ignoreml' => true,
            'language' => $language,
            'order' => isset($order) ? $order : 'from',
            'orderdir' => isset($orderdir) ? $orderdir : 'DESC',
            'from' => isset($from) ? $from : null,
            'to' => isset($to) ? $to : null,
            'filterbydate' => false,
            'category' => null,
            'catfilter' => isset($catsarray) ? $catsarray : null,
            'catregistry' => isset($catregistry) ? $catregistry : null);
        $items = ModUtil::apiFunc('News', 'user', 'getall', $getallargs);
        $total_articles = ModUtil::apiFunc('News', 'user', 'countitems', $getallargs);

        // Set the possible status for later use
        $itemstatus = array(
            '' => $this->__('All'),
            News_Api_User::STATUS_PUBLISHED => $this->__('Published'),
            News_Api_User::STATUS_REJECTED => $this->__('Rejected'),
            News_Api_User::STATUS_PENDING => $this->__('Pending Review'),
            News_Api_User::STATUS_ARCHIVED => $this->__('Archived'),
            News_Api_User::STATUS_DRAFT => $this->__('Draft'),
            News_Api_User::STATUS_SCHEDULED => $this->__('Scheduled')
        );

        $newsitems = array();
        foreach ($items as $item)
        {
            $options = array();
            if (System::getVar('shorturls', false)) {
                $options[] = array('url' => ModUtil::url('News', 'user', 'display', array('sid' => $item['sid'], 'from' => $item['from'], 'urltitle' => $item['urltitle'])),
                    'image' => '14_layer_visible.png',
                    'title' => $this->__('View'));
            } else {
                $options[] = array('url' => ModUtil::url('News', 'user', 'display', array('sid' => $item['sid'])),
                    'image' => '14_layer_visible.png',
                    'title' => $this->__('View'));
            }

            if (SecurityUtil::checkPermission('News::', "{$item['cr_uid']}::{$item['sid']}", ACCESS_EDIT)) {
                if ($item['published_status'] == News_Api_User::STATUS_PENDING) {
                    $options[] = array('url' => ModUtil::url('News', 'admin', 'modify', array('sid' => $item['sid'])),
                        'image' => 'editcut.png',
                        'title' => $this->__('Review'));
                } else {
                    $options[] = array('url' => ModUtil::url('News', 'admin', 'modify', array('sid' => $item['sid'])),
                        'image' => 'xedit.png',
                        'title' => $this->__('Edit'));
                }

                if (($item['published_status'] != News_Api_User::STATUS_PENDING &&
                        (SecurityUtil::checkPermission('News::', "{$item['cr_uid']}::{$item['sid']}", ACCESS_DELETE))) ||
                        SecurityUtil::checkPermission('News::', "{$item['cr_uid']}::{$item['sid']}", ACCESS_ADMIN)) {
                    $options[] = array('url' => ModUtil::url('News', 'admin', 'delete', array('sid' => $item['sid'])),
                        'image' => '14_layer_deletelayer.png',
                        'title' => $this->__('Delete'));
                }
            }
            $item['options'] = $options;

            if (in_array($item['published_status'], array_keys($itemstatus))) {
                $item['status'] = $itemstatus[$item['published_status']];
            } else {
                $item['status'] = $this->__('Unknown');
            }

            $item['infuture'] = DateUtil::getDatetimeDiff_AsField($item['from'], DateUtil::getDatetime(), 6) < 0;
            $newsitems[] = $item;
        }

        // Assign the items to the template
        $this->view->assign('newsitems', $newsitems);
        $this->view->assign('total_articles', $total_articles);

        // Assign the current status filter and the possible ones
        $this->view->assign('news_status', $news_status);
        $this->view->assign('itemstatus', $itemstatus);
        $this->view->assign('order', $order);

        $selectedcategories = array();
        if (is_array($filtercats)) {
            $catsarray = $filtercats['__CATEGORIES__'];
            foreach ($catsarray as $propname => $propid) {
                if ($propid > 0) {
                    $selectedcategories[$propname] = $propid; // removes categories set to 'all'
                }
            }
        }
        $this->view->assign('selectedcategories', $selectedcategories);

        // Return the output that has been generated by this function
        return $this->view->fetch('admin/view.tpl');
    }