Esempio n. 1
0
    /**
     * get a specific item
     *
     * @param $args['pageid'] id of example item to get
     *
     * @return mixed item array, or false on failure
     */
    public function get($args)
    {
        // Argument check
        if ((!isset($args['pageid']) || !is_numeric($args['pageid'])) &&
                !isset($args['title'])) {
            return LogUtil::registerArgsError();
        }

        // define the permission filter to apply
        $permFilter   = array();
        $permFilter[] = array('component_left'  => 'Pages',
                'instance_left'   => 'title',
                'instance_right'  => 'pageid',
                'level'           => ACCESS_READ);

        if (isset($args['pageid']) && is_numeric($args['pageid'])) {
            $item = DBUtil::selectObjectByID('pages', $args['pageid'], 'pageid', '', $permFilter);
        } else {
            $item = DBUtil::selectObjectByID('pages', $args['title'], 'urltitle', '', $permFilter);
        }

        // need to do this here as the category expansion code can't know the
        // root category which we need to build the relative path component
        if ($item && isset($args['catregistry']) && $args['catregistry']) {
            ObjectUtil::postProcessExpandedObjectCategories($item, $args['catregistry']);
        }

        if (ModUtil::getVar('Pages', 'enablecategorization') && !empty($item['__CATEGORIES__'])) {
            if (!CategoryUtil::hasCategoryAccess($item['__CATEGORIES__'], 'Pages')) {
                return false;
            }
        }

        return $item;
    }
Esempio n. 2
0
    /**
     * get a specific item
     * @author Mark West
     * @param $args['sid'] id of news item to get
     * @return mixed item array, or false on failure
     */
    public function get($args)
    {
        // optional arguments
        if (isset($args['objectid'])) {
            $args['sid'] = $args['objectid'];
        }

        // Argument check
        if ((!isset($args['sid']) || !is_numeric($args['sid'])) &&
                !isset($args['title'])) {
            return LogUtil::registerArgsError();
        }

        // Check for caching of the DBUtil calls (needed for AJAX editing)
        if (!isset($args['SQLcache'])) {
            $args['SQLcache'] = true;
        }

        // form a date using some ofif present...
        // step 1 - convert month name into
        if (isset($args['monthname']) && !empty($args['monthname'])) {
            $months = explode(' ', $this->__('Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'));
            $keys = array_flip($months);
            $args['monthnum'] = $keys[ucfirst($args['monthname'])] + 1;
        }

        // step 2 - convert to a timestamp and back to a db format
        if (isset($args['year']) && !empty($args['year']) && isset($args['monthnum']) &&
                !empty($args['monthnum']) && isset($args['day']) && !empty($args['day'])) {
            // use PHP strftime directly, since DateUtil translates dateformat strings, which is not ok in this case
            $timestring = strftime('%Y-%m-%d', mktime(0, 0, 0, $args['monthnum'], $args['day'], $args['year']));
        }

        $permFilter = array();
        $permFilter[] = array('realm' => 0,
                'component_left'   => 'News',
                'component_middle' => '',
                'component_right'  => '',
                'instance_left'    => 'cr_uid',
                'instance_middle'  => '',
                'instance_right'   => 'sid',
                'level'            => ACCESS_READ);

        if (isset($args['sid']) && is_numeric($args['sid'])) {
            $item = DBUtil::selectObjectByID('news', $args['sid'], 'sid', null, $permFilter, null, $args['SQLcache']);
        } elseif (isset($timestring)) {
            $tables = DBUtil::getTables();
            $col = $tables['news_column'];
            $where = "{$col['urltitle']} = '".DataUtil::formatForStore($args['title'])."' AND {$col['from']} LIKE '{$timestring}%'";
            $item = DBUtil::selectObject('news', $where, null, $permFilter, null, $args['SQLcache']);
        } else {
            $item = DBUtil::selectObjectByID('news', $args['title'], 'urltitle', null, $permFilter, null, $args['SQLcache']);
        }

        if (empty($item))
            return false;

        // Sanity check for the published status if required
        if (isset($args['status'])) {
            if ($item['published_status'] != $args['status']) {
                return false;
            }
        }
        
        // process the relative paths of the categories
        if ($this->getVar('enablecategorization') && !empty($item['__CATEGORIES__'])) {
            static $registeredCats;
            if (!isset($registeredCats)) {
                $registeredCats  = CategoryRegistryUtil::getRegisteredModuleCategories('News', 'news');
            }
            ObjectUtil::postProcessExpandedObjectCategories($item['__CATEGORIES__'], $registeredCats);
            if (!CategoryUtil::hasCategoryAccess($item['__CATEGORIES__'], 'News')) {
                return false;
            }
        }

        return $item;
    }