Exemple #1
0
    /**
     * delete a News item
     *
     * @author Mark West
     * @param $args['sid'] ID of the item
     * @return bool true on success, false on failure
     */
    public function delete($args)
    {
        // Argument check
        if (!isset($args['sid']) || !is_numeric($args['sid'])) {
            return LogUtil::registerArgsError();
        }

        // Get the news story
        $item = ModUtil::apiFunc('News', 'user', 'get', array('sid' => $args['sid']));

        if ($item == false) {
            return LogUtil::registerError($this->__('Error! No such article found.'));
        }

        $this->throwForbiddenUnless(SecurityUtil::checkPermission('News::', $item['cr_uid'] . '::' . $item['sid'], ACCESS_DELETE), LogUtil::getErrorMsgPermission());

        if (!DBUtil::deleteObjectByID('news', $args['sid'], 'sid')) {
            return LogUtil::registerError($this->__('Error! Could not delete article.'));
        }

        // delete News images
        $modvars = $this->getVars();
        if ($modvars['picupload_enabled'] && $item['pictures'] > 0) {
            News_ImageUtil::deleteImagesBySID($modvars['picupload_uploaddir'], $item['sid'], $item['pictures']);
        }

        // Let the calling process know that we have finished successfully
        return true;
    }
Exemple #2
0
    /**
     * A function to handle bulk actions in the admin interface
     *
     * @param array 'articles' array of article ids to process
     * @param int 'bulkaction' the action to take
     * @return bool true
     */
    public function processbulkaction()
    {
        $this->checkCsrfToken();
        $this->throwForbiddenUnless(SecurityUtil::checkPermission('News::', '::', ACCESS_DELETE), LogUtil::getErrorMsgPermission());

        $articles = FormUtil::getPassedValue('news_selected_articles', array(), 'POST');
        $bulkaction = (int)FormUtil::getPassedValue('news_bulkaction_select', 0, 'POST');
        $cat_data = FormUtil::getPassedValue('news_bulkaction_categorydata', '', 'POST');

        if ($bulkaction >= 1 && $bulkaction <= 5) {
            $actionmap = array(
                // these indices are not constants, just unrelated integers
                1 => __('Delete'),
                2 => __('Archive'),
                3 => __('Publish'),
                4 => __('Reject'),
                5 => __('Change categories'));
            $updateresult = array(
                'successful' => array(),
                'failed' => array());

            switch ($bulkaction) {
                case 1: // delete

                    foreach ($articles as $article) {
                        if (DBUtil::deleteObjectByID('news', $article, 'sid')) {
                            // assume max pictures. if less, errors are supressed by @
                            News_ImageUtil::deleteImagesBySID($this->getVar('picupload_uploaddir'), $article, $this->getVar('picupload_maxpictures'));
                            $updateresult['successful'][] = $article;
                        } else {
                            $updateresult['failed'][] = $article;
                        }
                    }
                    break;
                case 5: // change categories
                    $obj = array();
                    $obj['__CATEGORIES__'] = json_decode($cat_data, true);
                    unset($obj['__CATEGORIES__']['submit']);
                    foreach ($articles as $article) {
                        $obj['sid'] = $article;
                        if (DBUtil::updateObject($obj, 'news', '', 'sid')) {
                            $updateresult['successful'][] = $article;
                        } else {
                            $updateresult['failed'][] = $article;
                        }
                    }
                    break;
                default: // archive, publish or reject
                    $statusmap = array(
                        2 => News_Api_User::STATUS_ARCHIVED,
                        3 => News_Api_User::STATUS_PUBLISHED,
                        4 => News_Api_User::STATUS_REJECTED
                    );
                    foreach ($articles as $article) {
                        $obj = array(
                            'sid' => $article,
                            'published_status' => $statusmap[$bulkaction]
                        );
                        if (DBUtil::updateObject($obj, 'news', '', 'sid')) {
                            $updateresult['successful'][] = $article;
                        } else {
                            $updateresult['failed'][] = $article;
                        }
                    }
            }
            $updateresult['successful']['list'] = implode(', ', $updateresult['successful']);
            $updateresult['failed']['list'] = implode(', ', $updateresult['failed']);
            LogUtil::registerStatus($this->__f('Processed Bulk Action. Action: %s.', $actionmap[$bulkaction]));
            if (!empty($updateresult['successful']['list'])) {
                LogUtil::registerStatus($this->__f('Success with articles: %s', $updateresult['successful']['list']));
            }
            if (!empty($updateresult['failed']['list'])) {
                LogUtil::registerError($this->__f('Failed with articles: %s', $updateresult['failed']['list']));
            }
        } else {
            LogUtil::registerError($this->__('Error! Wrong bulk action.'));
        }
        return $this->redirect(ModUtil::url('News', 'admin', 'view'));
    }