Пример #1
0
function data_blog($data, $params)
{
    // No change in the parameters with Clyde
    global $gLibertySystem, $gBitSmarty, $gBitSystem, $gBitUser;
    $display_result = "";
    if ($gBitSystem->isPackageActive('blogs') && $gBitUser->hasPermission('p_blogs_view')) {
        // The next 2 lines allow access to the $pluginParams given above and may be removed when no longer needed
        $pluginParams = $gLibertySystem->mPlugins[PLUGIN_GUID_DATABLOG];
        require_once BLOGS_PKG_PATH . 'BitBlog.php';
        require_once LIBERTY_PKG_PATH . 'lookup_content_inc.php';
        $module_params = $params;
        if (isset($module_params['id'])) {
            $gBitSmarty->assign('blog_id', $module_params['id']);
        }
        $blogPost = new BitBlogPost();
        $sortOptions = array("publish_date_desc", "publish_date_asc", "last_modified_asc", "last_modified_desc", "created_asc", "created_desc", "random");
        if (!empty($module_params['sort_mode']) && in_array($module_params['sort_mode'], $sortOptions)) {
            $sort_mode = $module_params['sort_mode'];
        } else {
            $sort_mode = 'publish_date_desc';
        }
        $getHash = array();
        if (isset($module_params['user'])) {
            $getHash['user'] = $module_params['user'];
        }
        if (isset($module_params['id'])) {
            $getHash['blog_id'] = $module_params['id'];
        }
        if (isset($module_params['group_id'])) {
            $getHash['group_id'] = $module_params['group_id'];
        }
        if (isset($module_params['role_id'])) {
            $getHash['role_id'] = $module_params['role_id'];
        }
        // handle draft posts
        $getHash['enforce_status'] = TRUE;
        // @TODO enable lists that include draft posts
        // the current tpl configuration doesnt allow us to support draft lists right now
        // there is an object reference problem in liberty::service_content_body_inc.tpl
        // if the object reference problem in the above mentions tpl is patched then use this if to enable drafts
        // if ( !empty( $module_params['status'] ) && $module_params['status'] = "draft" && isset( $gBitUser->mUserId ) ){
        if (FALSE) {
            // if we are getting drafts then get future posts too
            $getHash['show_future'] = TRUE;
            $getHash['min_status_id'] = -6;
            $getHash['max_status_id'] = -4;
            $getHash['min_owner_status_id'] = -6;
            // limit by user
            $getHash['user_id'] = $gBitUser->mUserId;
        } else {
            $getHash['min_owner_status_id'] = 0;
        }
        $getHash['sort_mode'] = $sort_mode;
        $getHash['parse_data'] = TRUE;
        $getHash['max_records'] = empty($module_params['max']) ? 1 : $module_params['max'];
        $getHash['load_num_comments'] = TRUE;
        $getHash['page'] = !empty($module_params['page']) ? $module_params['page'] : 1;
        $getHash['offset'] = !empty($module_params['offset']) ? $module_params['offset'] : 0;
        $blogPosts = $blogPost->getList($getHash);
        $display_format = empty($module_params['format']) ? 'simple_title_list' : $module_params['format'];
        switch ($display_format) {
            case 'full':
                $display_result = '<div class="blogs">';
                if ($gBitSystem->isPackageActive('rss')) {
                    if (isset($module_params['user'])) {
                        $rssUser = new BitUser();
                        $rssUser->load(false, $module_params['user']);
                        $rssUserId = $rssUser->getField('user_id');
                    }
                    $rssPath = BLOGS_PKG_URL . 'blogs_rss.php?' . (isset($module_params['id']) ? 'blog_id=' . $module_params['id'] : "") . (isset($module_params['id']) && isset($rssUserId) ? "&" : "") . (isset($rssUserId) ? 'user_id=' . $rssUserId : "") . (isset($rssUserId) && isset($module_params['group_id']) ? "&" : "") . (isset($module_params['group_id']) ? 'group_id=' . $module_params['group_id'] : "") . (isset($rssUserId) && isset($module_params['role_id']) ? "&" : "") . (isset($module_params['role_id']) ? 'role_id=' . $module_params['role_id'] : "");
                    // something like this would be better, calling smarty directly so translation can also be called -wjames5
                    // $rssIcon = smarty_function_biticon( array('ipackage'=>"rss", 'iname'="rss-16x16", 'iexplain'=>"RSS feed"), &$gBitSmarty );
                    $display_result .= '<div class="floaticon"><a title="RSS feed" href="' . $rssPath . '"><img src="' . BIT_ROOT_URL . 'rss/icons/rss-16x16.png" alt="RSS feed" title="RSS feed" class="icon" /></a></div>';
                }
                $gBitSmarty->assign('showDescriptionsOnly', TRUE);
                foreach ($blogPosts['data'] as $aPost) {
                    $gBitSmarty->assign('aPost', $aPost);
                    $display_result .= $gBitSmarty->fetch('bitpackage:blogs/blog_list_post.tpl');
                }
                $display_result .= '</div>';
                $display_result = eregi_replace("\n", "", $display_result);
                break;
            case 'list':
            default:
                $display_result = "<ul>";
                foreach ($blogPosts['data'] as $post) {
                    $link = $blogPost->getDisplayLink($post['title'], $post);
                    $display_result .= "<li>{$link}</li>\n";
                }
                $display_result .= "</ul>\n";
                break;
        }
    } else {
        $display_result = '<div class=error>' . tra('Blogs Package Deactivated.') . '</div>';
    }
    return $display_result;
}
Пример #2
0
 /**
  * store Any method named Store inherently implies data will be written to the database
  * @param pParamHash be sure to pass by reference in case we need to make modifcations to the hash
  * This is the ONLY method that should be called in order to store( create or update )an suggestion!
  * It is very smart and will figure out what to do for you. It should be considered a black box.
  * 
  * @param array $pParamHash hash of values that will be used to store the page
  * @access public
  * @return boolean TRUE on success, FALSE on failure - mErrors will contain reason for failure
  */
 function store(&$pParamHash)
 {
     if ($this->verify($pParamHash) && LibertyMime::store($pParamHash)) {
         $this->mDb->StartTrans();
         $table = BIT_DB_PREFIX . "suggestion_data";
         if ($this->mSuggestionId) {
             $locId = array("suggestion_id" => $pParamHash['suggestion_id']);
             $result = $this->mDb->associateUpdate($table, $pParamHash['suggestion_store'], $locId);
         } else {
             $pParamHash['suggestion_store']['content_id'] = $pParamHash['content_id'];
             if (@$this->verifyId($pParamHash['suggestion_id'])) {
                 // if pParamHash['suggestion_id'] is set, some is requesting a particular suggestion_id. Use with caution!
                 $pParamHash['suggestion_store']['suggestion_id'] = $pParamHash['suggestion_id'];
             } else {
                 $pParamHash['suggestion_store']['suggestion_id'] = $this->mDb->GenID('suggestion_data_id_seq');
             }
             $this->mSuggestionId = $pParamHash['suggestion_id'] = $pParamHash['suggestion_store']['suggestion_id'];
             if ($result = $this->mDb->associateInsert($table, $pParamHash['suggestion_store'])) {
                 // send an email notification to subscribers
                 // load up creator user in case user_id was forced and is not the same as gBitUser
                 $user = new BitUser($pParamHash['user_id']);
                 $user->load();
                 $userName = $user->getDisplayName();
                 $userEmail = $user->getField('email');
                 // Draft the message body:
                 $body = "/----- " . tra('A new suggestion was submitted.') . " -----/\n\n" . "Submitted by: \n" . $userName . "\n" . $userEmail . "\n\n" . "Title: \n" . $pParamHash['title'] . "\n\n" . "Megawatt Hours / Year: \n" . $pParamHash['suggestion_store']['mwh'] . "\n\n" . "Description: \n" . $pParamHash['edit'] . "\n\n" . "Sources: \n" . $pParamHash['suggestion_store']['sources'];
                 $msgHash = array('subject' => tra('New Suggestion') . ': ' . $pParamHash['title'], 'alt_message' => $body);
                 global $gSwitchboardSystem;
                 // register the sender to be able to access it
                 $gSwitchboardSystem->registerSender(SUGGESTION_PKG_TITLE, 'new suggestion');
                 // fire a notification
                 $gSwitchboardSystem->sendEvent(SUGGESTION_PKG_TITLE, 'new suggestion', $pParamHash['content_id'], $msgHash);
                 // cheating by accessing directly - remove the sender because access should be restricted
                 unset($gSwitchboardSystem->mSenders[SUGGESTION_PKG_TITLE]);
             }
         }
         // $this->storeRefs( $pParamHash );
         $this->mDb->CompleteTrans();
         $this->load();
     } else {
         $this->mErrors['store'] = 'Failed to save this suggestion.';
     }
     return count($this->mErrors) == 0;
 }