/**
  * Event handler: Called before at the beginning, if a comment form gets sent (and received).
  */
 function CommentFormSent(&$params)
 {
     $ItemCache =& get_ItemCache();
     $comment_Item =& $ItemCache->get_by_ID($params['comment_item_ID'], false);
     if (!$comment_Item) {
         // Incorrect item
         return false;
     }
     $item_Blog =& $comment_Item->get_Blog();
     $apply_rendering = $this->get_coll_setting('coll_apply_comment_rendering', $item_Blog);
     if ($item_Blog->get_setting('allow_html_comment') && $this->is_renderer_enabled($apply_rendering, $params['renderers'])) {
         // Do escape html entities only when html is allowed for content and plugin is enabled
         $content =& $params['comment'];
         $content = $this->escape_code($content);
     }
 }
示例#2
0
 /**
  * Event handler: Called before at the beginning, if a comment form gets sent (and received).
  */
 function CommentFormSent(&$params)
 {
     $ItemCache =& get_ItemCache();
     $comment_Item =& $ItemCache->get_by_ID($params['comment_item_ID'], false);
     if (!$comment_Item) {
         // Incorrect item
         return false;
     }
     $item_Blog =& $comment_Item->get_Blog();
     $apply_rendering = $this->get_coll_setting('coll_apply_comment_rendering', $item_Blog);
     if ($this->is_renderer_enabled($apply_rendering, $params['renderers'])) {
         // render code blocks in comment
         $params['content'] =& $params['comment'];
         $this->FilterItemContents($params);
     }
 }
示例#3
0
/**
 * Create sample comments and display a process of creating
 *
 * @param integer Blog ID
 * @param integer Number of comments
 * @param integer Number of posts
 */
function tool_create_sample_comments($blog_ID, $num_comments, $num_posts)
{
    global $DB, $posttypes_specialtypes, $localtimenow, $Hit, $Messages, $Debuglog;
    $BlogCache =& get_BlogCache();
    $selected_Blog = $BlogCache->get_by_ID($blog_ID, false, false);
    if ($selected_Blog == NULL) {
        // Incorrect blog ID, Exit here
        return;
    }
    echo T_('Creating of the sample comments...');
    evo_flush();
    /**
     * Disable log queries because it increases the memory and stops the process with error "Allowed memory size of X bytes exhausted..."
     */
    $DB->log_queries = false;
    $curr_orderby = $selected_Blog->get_setting('orderby');
    if ($curr_orderby == 'RAND') {
        $curr_orderby .= '()';
    } else {
        $curr_orderby = 'post_' . $curr_orderby;
    }
    $curr_orderdir = $selected_Blog->get_setting('orderdir');
    // find the $num_posts latest posts in blog
    $SQL = new SQL();
    $SQL->SELECT('post_ID');
    $SQL->FROM('T_items__item');
    $SQL->FROM_add('INNER JOIN T_categories ON post_main_cat_ID = cat_ID');
    $SQL->WHERE('cat_blog_ID = ' . $DB->quote($blog_ID));
    $SQL->WHERE_and('post_status = ' . $DB->quote('published'));
    // Set condition to not create sample comments for special posts
    $SQL->WHERE_and('post_ptyp_ID NOT IN ( ' . $DB->quote($posttypes_specialtypes) . ' )');
    $SQL->ORDER_BY($curr_orderby . ' ' . $curr_orderdir . ', post_ID ' . $curr_orderdir);
    $SQL->LIMIT($num_posts);
    $items_result = $DB->get_results($SQL->get(), ARRAY_A, 'Find the x latest posts in blog');
    $count = 1;
    $fix_content = 'This is an auto generated comment for testing the moderation features.
					http://www.test.com/test_comment_';
    // go through on selected items
    foreach ($items_result as $row) {
        $item_ID = $row['post_ID'];
        $ItemCache =& get_ItemCache();
        $commented_Item =& $ItemCache->get_by_ID($item_ID);
        // create $num_comments comments for each item
        for ($i = 0; $i < $num_comments; $i++) {
            $author = 'Test ' . $count;
            $email = 'test_' . $count . '@test.com';
            $url = 'http://www.test-' . rand(1, 3) . '.com/test_comment_' . $count;
            $content = $fix_content . $count;
            for ($j = 0; $j < 50; $j++) {
                // create 50 random word
                $length = rand(1, 15);
                $word = generate_random_key($length, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
                $content = $content . ' ' . $word;
            }
            // create and save a new comment
            $Comment = new Comment();
            $Comment->set_Item($commented_Item);
            $Comment->set('status', 'draft');
            $Comment->set('author', $author);
            $Comment->set('author_email', $email);
            $Comment->set('author_url', $url);
            $Comment->set('content', $content);
            $Comment->set('date', date('Y-m-d H:i:s', $localtimenow));
            $Comment->set('author_IP', $Hit->IP);
            $Comment->dbsave();
            $count++;
            if ($count % 100 == 0) {
                // Display a process of creating by one dot for 100 comments
                echo ' .';
                evo_flush();
            }
            // Clear all debug messages, To avoid an error about full memory
            $Debuglog->clear('all');
        }
    }
    echo ' OK.';
    $Messages->add(sprintf(T_('Created %d comments.'), $count - 1), 'success');
}
示例#4
0
        } else {
            // not confirmed, Check for restrictions:
            if (!$edited_ItemTag->check_delete(sprintf(T_('Cannot delete tag "%s"'), '<b>' . $edited_ItemTag->dget('name') . '</b>'), array(), true)) {
                // There are restrictions:
                $action = 'list';
            }
        }
        break;
    case 'unlink':
        // Unlink tag from the post:
        // Check that this action request is not a CSRF hacked request:
        $Session->assert_received_crumb('tag');
        // Check that current user has permission to edit tags:
        $current_User->check_perm('options', 'edit', true);
        $item_ID = param('item_ID', 'integer', 0, true);
        $ItemCache =& get_ItemCache();
        $edited_Item =& $ItemCache->get_by_ID($item_ID);
        // Check permission based on DB status:
        $current_User->check_perm('item_post!CURSTATUS', 'edit', true, $edited_Item);
        $result = $DB->query('DELETE FROM T_items__itemtag
			WHERE itag_itm_ID = ' . $DB->quote($edited_Item->ID) . '
			  AND itag_tag_ID = ' . $DB->quote($edited_ItemTag->ID));
        if ($result) {
            $Messages->add(sprintf(T_('Tag "%s" has been unlinked from the post "%s".'), '<b>' . $edited_ItemTag->dget('name') . '</b>', '<b>' . $edited_Item->dget('title') . '</b>'), 'success');
        }
        // Redirect so that a reload doesn't write to the DB twice:
        header_redirect($admin_url . '?ctrl=itemtags&tag_ID=' . $edited_ItemTag->ID . '&action=edit', 303);
        // Will EXIT
        // We have EXITed already at this point!!
        break;
    case 'merge_confirm':
示例#5
0
/**
 * Shutdown function: save HIT and update session!
 *
 * This is registered in _main.inc.php with register_shutdown_function()
 * This is called by PHP at the end of the script.
 *
 * NOTE: before PHP 4.1 nothing can be echoed here any more, but the minimum PHP requirement for b2evo is PHP 4.3
 */
function shutdown()
{
    /**
     * @var Hit
     */
    global $Hit;
    /**
     * @var Session
     */
    global $Session;
    global $Settings;
    global $Debuglog;
    global $Timer;
    global $shutdown_count_item_views;
    // Try forking a background process and let the parent return as fast as possbile.
    if (is_callable('pcntl_fork') && function_exists('posix_kill') && defined('STDIN')) {
        if ($pid = pcntl_fork()) {
            return;
        }
        // Parent
        function shutdown_kill()
        {
            posix_kill(posix_getpid(), SIGHUP);
        }
        if (ob_get_level()) {
            // Discard the output buffer and close
            ob_end_clean();
        }
        fclose(STDIN);
        // Close all of the standard
        fclose(STDOUT);
        // file descriptors as we
        fclose(STDERR);
        // are running as a daemon.
        register_shutdown_function('shutdown_kill');
        if (posix_setsid() < 0) {
            return;
        }
        if ($pid = pcntl_fork()) {
            return;
        }
        // Parent
        // Now running as a daemon. This process will even survive
        // an apachectl stop.
    }
    $Timer->resume('shutdown');
    // echo '*** SHUTDOWN FUNC KICKING IN ***';
    // fp> do we need special processing if we are in CLI mode?  probably earlier actually
    // if( ! $is_cli )
    // Note: it might be useful at some point to do special processing if the script has been aborted or has timed out
    // connection_aborted()
    // connection_status()
    if (!empty($shutdown_count_item_views)) {
        // Increment view counts for Items:
        $ItemCache =& get_ItemCache();
        foreach ($shutdown_count_item_views as $item_ID) {
            // asimo> Inserted the $item_ID != 0 check, because another way comes unexpected error on preview page
            if (!empty($item_ID) && ($Item = $ItemCache->get_by_ID($item_ID, false))) {
                $Item->count_view(array('allow_multiple_counts_per_page' => false));
            }
        }
    }
    // Save the current HIT:
    $Hit->log();
    // Update the SESSION:
    $Session->dbsave();
    // Get updates here instead of slowing down normal display of the dashboard
    load_funcs('dashboard/model/_dashboard.funcs.php');
    b2evonet_get_updates();
    // Auto pruning of old HITS, old SESSIONS and potentially MORE analytics data:
    if ($Settings->get('auto_prune_stats_mode') == 'page') {
        // Autopruning is requested
        load_class('sessions/model/_hitlist.class.php', 'Hitlist');
        Hitlist::dbprune();
        // will prune once per day, according to Settings
    }
    // Calling debug_info() here will produce complete data but it will be after </html> hence invalid.
    // Then again, it's for debug only, so it shouldn't matter that much.
    debug_info();
    // Update the SESSION again, at the very end:
    // (e.g. "Debuglogs" may have been removed in debug_info())
    $Session->dbsave();
    $Timer->pause('shutdown');
}
示例#6
0
    /**
     * Trigger event AfterCommentUpdate after calling parent method.
     *
     * @return boolean true on success
     */
    function dbupdate()
    {
        global $Plugins, $DB;
        $dbchanges = $this->dbchanges;
        if (count($dbchanges)) {
            $this->set_last_touched_date();
        }
        $DB->begin();
        if (($r = parent::dbupdate()) !== false) {
            $update_item_last_touched_date = false;
            if (isset($dbchanges['comment_content']) || isset($dbchanges['comment_renderers'])) {
                // Content is updated
                $this->delete_prerendered_content();
                $update_item_last_touched_date = true;
            }
            if ($this->check_publish_status_changed()) {
                // Comment is updated into/out some public status
                $update_item_last_touched_date = true;
            }
            if (!empty($this->previous_item_ID)) {
                // Comment is moved from another post
                $ItemCache =& get_ItemCache();
                $ItemCache->clear();
                if ($previous_Item =& $ItemCache->get_by_ID($this->previous_item_ID, false, false)) {
                    // Update last touched date of previous item
                    $previous_Item->update_last_touched_date(false);
                }
                // Also update new post
                $update_item_last_touched_date = true;
                // Also move all child comments to new post
                $child_comment_IDs = $this->get_child_comment_IDs();
                if (count($child_comment_IDs)) {
                    $DB->query('UPDATE T_comments
						  SET comment_item_ID = ' . $DB->quote($this->item_ID) . '
						WHERE comment_ID IN ( ' . $DB->quote($child_comment_IDs) . ' )');
                }
            }
            $this->update_last_touched_date($update_item_last_touched_date);
            $DB->commit();
            $Plugins->trigger_event('AfterCommentUpdate', $params = array('Comment' => &$this, 'dbchanges' => $dbchanges));
        } else {
            $DB->rollback();
        }
        return $r;
    }
示例#7
0
/**
 * Display the edited items results table
 *
 * @param array Params
 */
function items_edited_results_block($params = array())
{
    // Make sure we are not missing any param:
    $params = array_merge(array('edited_User' => NULL, 'results_param_prefix' => 'actv_postedit_', 'results_title' => T_('Posts edited by the user'), 'results_no_text' => T_('User has not edited any posts')), $params);
    if (!is_logged_in()) {
        // Only logged in users can access to this function
        return;
    }
    global $current_User;
    if (!$current_User->check_perm('users', 'edit')) {
        // Check minimum permission:
        return;
    }
    $edited_User = $params['edited_User'];
    if (!$edited_User) {
        // No defined User, probably the function is calling from AJAX request
        $user_ID = param('user_ID', 'integer', 0);
        if (empty($user_ID)) {
            // Bad request, Exit here
            return;
        }
        $UserCache =& get_UserCache();
        if (($edited_User =& $UserCache->get_by_ID($user_ID, false)) === false) {
            // Bad request, Exit here
            return;
        }
    }
    global $DB;
    param('user_tab', 'string', '', true);
    param('user_ID', 'integer', 0, true);
    $edited_versions_SQL = new SQL();
    $edited_versions_SQL->SELECT('DISTINCT( iver_itm_ID )');
    $edited_versions_SQL->FROM('T_items__version');
    $edited_versions_SQL->WHERE('iver_edit_user_ID = ' . $DB->quote($edited_User->ID));
    $SQL = new SQL();
    $SQL->SELECT('*');
    $SQL->FROM('T_items__item ');
    $SQL->WHERE('( ( post_lastedit_user_ID = ' . $DB->quote($edited_User->ID) . ' ) OR ( post_ID IN ( ' . $edited_versions_SQL->get() . ' ) ) )');
    $SQL->WHERE_and('post_creator_user_ID != ' . $DB->quote($edited_User->ID));
    // Create result set:
    $edited_items_Results = new Results($SQL->get(), $params['results_param_prefix'], 'D');
    $edited_items_Results->Cache =& get_ItemCache();
    $edited_items_Results->title = $params['results_title'];
    $edited_items_Results->no_results_text = $params['results_no_text'];
    // Get a count of the post which current user can delete
    $deleted_posts_edited_count = count($edited_User->get_deleted_posts('edited'));
    if ($edited_items_Results->total_rows > 0 && $deleted_posts_edited_count > 0) {
        // Display actino icon to delete all records if at least one record exists & current user can delete at least one item created by user
        $edited_items_Results->global_icon(sprintf(T_('Delete all post edited by %s'), $edited_User->login), 'delete', '?ctrl=user&amp;user_tab=activity&amp;action=delete_all_posts_edited&amp;user_ID=' . $edited_User->ID . '&amp;' . url_crumb('user'), ' ' . T_('Delete all'), 3, 4);
    }
    // Initialize Results object
    items_results($edited_items_Results, array('field_prefix' => 'post_', 'display_ord' => false, 'display_history' => false));
    if (is_ajax_content()) {
        // init results param by template name
        if (!isset($params['skin_type']) || !isset($params['skin_name'])) {
            debug_die('Invalid ajax results request!');
        }
        $edited_items_Results->init_params_by_skin($params['skin_type'], $params['skin_name']);
    }
    $display_params = array('before' => '<div class="results" style="margin-top:25px" id="edited_posts_result">');
    $edited_items_Results->display($display_params);
    if (!is_ajax_content()) {
        // Create this hidden div to get a function name for AJAX request
        echo '<div id="' . $params['results_param_prefix'] . 'ajax_callback" style="display:none">' . __FUNCTION__ . '</div>';
    }
}
示例#8
0
/**
 * Get all links where file is used
 *
 * @param integer File ID
 * @param array Params
 * @return string The links to that posts, comments and users where the file is used
 */
function get_file_links($file_ID, $params = array())
{
    global $DB, $current_User, $baseurl, $admin_url;
    $params = array_merge(array('separator' => '<br />', 'post_prefix' => T_('Post') . ' - ', 'comment_prefix' => T_('Comment on') . ' - ', 'user_prefix' => T_('Profile picture') . ' - '), $params);
    // Create result array
    $attached_to = array();
    // Get all links with posts and comments
    $links_SQL = new SQL();
    $links_SQL->SELECT('link_itm_ID, link_cmt_ID');
    $links_SQL->FROM('T_links');
    $links_SQL->WHERE('link_file_ID = ' . $DB->quote($file_ID));
    $links = $DB->get_results($links_SQL->get());
    if (!empty($links)) {
        // File is linked with some posts or comments
        $ItemCache =& get_ItemCache();
        $CommentCache =& get_CommentCache();
        foreach ($links as $link) {
            if (!empty($link->link_itm_ID)) {
                // File is linked to a post
                if ($Item =& $ItemCache->get_by_ID($link->link_itm_ID, false)) {
                    $Blog = $Item->get_Blog();
                    if ($current_User->check_perm('item_post!CURSTATUS', 'view', false, $Item)) {
                        // Current user can edit the linked post
                        $attached_to[] = $params['post_prefix'] . '<a href="' . url_add_param($admin_url, 'ctrl=items&amp;blog=' . $Blog->ID . '&amp;p=' . $link->link_itm_ID) . '">' . $Item->get('title') . '</a>';
                    } else {
                        // No access to edit the linked post
                        $attached_to[] = $params['post_prefix'] . $Item->get('title');
                    }
                }
            }
            if (!empty($link->link_cmt_ID)) {
                // File is linked to a comment
                if ($Comment =& $CommentCache->get_by_ID($link->link_cmt_ID, false)) {
                    $Item = $Comment->get_Item();
                    if ($current_User->check_perm('comment!CURSTATUS', 'moderate', false, $Comment)) {
                        // Current user can edit the linked Comment
                        $attached_to[] = $params['comment_prefix'] . '<a href="' . url_add_param($admin_url, 'ctrl=comments&amp;action=edit&amp;comment_ID=' . $link->link_cmt_ID) . '">' . $Item->get('title') . '</a>';
                    } else {
                        // No access to edit the linked Comment
                        $attached_to[] = $params['comment_prefix'] . $Item->get('title');
                    }
                }
            }
        }
    }
    // Get all links with profile pictures
    $profile_links_SQL = new SQL();
    $profile_links_SQL->SELECT('user_ID, user_login');
    $profile_links_SQL->FROM('T_users');
    $profile_links_SQL->WHERE('user_avatar_file_ID = ' . $DB->quote($file_ID));
    $profile_links = $DB->get_results($profile_links_SQL->get());
    if (!empty($profile_links)) {
        foreach ($profile_links as $link) {
            if ($current_User->ID != $link->user_ID && !$current_User->check_perm('users', 'view')) {
                // No permission to view other users in admin form
                $attached_to[] = $params['user_prefix'] . '<a href="' . url_add_param($baseurl, 'disp=user&amp;user_ID=' . $link->user_ID) . '">' . $link->user_login . '</a>';
            } else {
                // Build a link to display a user in admin form
                $attached_to[] = $params['user_prefix'] . '<a href="?ctrl=user&amp;user_tab=profile&amp;user_ID=' . $link->user_ID . '">' . $link->user_login . '</a>';
            }
        }
    }
    return implode($params['separator'], $attached_to);
}
/**
 * Recreate all item slugs (change title-[0-9] canonical slugs to a slug generated from current title). Old slugs will still work, but redirect to the new one.
 */
function dbm_recreate_itemslugs()
{
    global $Messages;
    $ItemCache = get_ItemCache();
    $ItemCache->load_where('( post_title != "" ) AND ( post_urltitle = "title" OR post_urltitle LIKE "title-%" )');
    $items = $ItemCache->get_ID_array();
    $count_slugs = 0;
    foreach ($items as $item_ID) {
        $Item = $ItemCache->get_by_ID($item_ID);
        $prev_urltitle = $Item->get('urltitle');
        $item_title = $Item->get('title');
        // check if post title is not empty and urltitle was auto generated ( equals title or title-[0-9]+ )
        // Note: urltitle will be auto generated on this form (title-[0-9]+), if post title wass empty and, urltitle was not set
        // Note: Even if a post title was set to 'title' on purpose it's possible, that this tool will change the post urltitle
        if (!empty($item_title) && ($prev_urltitle == 'title' || preg_match('#^title-[0-9]+$#', $prev_urltitle))) {
            // set urltitle empty, so the item update function will regenerate the item slug
            $Item->set('urltitle', '');
            $result = $Item->dbupdate(false, true, false);
            if ($result && $prev_urltitle != $Item->get('urltitle')) {
                // update was successful, and item urltitle was changed
                $count_slugs++;
            }
        }
    }
    $Messages->add(sprintf('Created %d new URL slugs.', $count_slugs), 'success');
}
示例#10
0
 /**
  * Get the posts of this user which current user can delete
  *
  * @param string Type of the deleted posts
  *               'created'        - the posts created by this user
  *               'edited'         - the posts edited by this user
  *               'created|edited' - the posts created OR edited by this user
  * @return array Items
  */
 function get_deleted_posts($type)
 {
     global $DB, $current_User;
     $ItemCache =& get_ItemCache();
     $ItemCache->ID_array = array();
     switch ($type) {
         case 'created':
             $user_Items = $ItemCache->load_where('post_creator_user_ID = ' . $DB->quote($this->ID));
             break;
         case 'edited':
             $user_Items = $ItemCache->load_where('post_lastedit_user_ID = ' . $DB->quote($this->ID));
             break;
         case 'created|edited':
             $user_Items = $ItemCache->load_where('post_lastedit_user_ID = ' . $DB->quote($this->ID) . ' OR post_creator_user_ID = ' . $DB->quote($this->ID));
             break;
     }
     $deleted_Items = array();
     foreach ($user_Items as $user_Item) {
         if ($current_User->check_perm('item_post!CURSTATUS', 'delete', false, $user_Item)) {
             // Current user has a permission to delete this item
             $deleted_Items[] = $user_Item;
         }
     }
     return $deleted_Items;
 }
示例#11
0
 /**
  * Display the widget!
  *
  * @param array MUST contain at least the basic display params
  */
 function display($params)
 {
     /**
      * @var Blog
      */
     global $Blog;
     global $disp;
     $this->init_display($params);
     // Default link class
     $link_class = $this->disp_params['link_default_class'];
     switch ($this->disp_params['link_type']) {
         case 'search':
             $url = $Blog->get('searchurl');
             $text = T_('Search');
             // Is this the current display?
             if ($disp == 'search') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'arcdir':
             $url = $Blog->get('arcdirurl');
             $text = T_('Archives');
             if ($disp == 'arcdir') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'catdir':
             $url = $Blog->get('catdirurl');
             $text = T_('Categories');
             if ($disp == 'catdir') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'postidx':
             $url = $Blog->get('postidxurl');
             $text = T_('Post index');
             if ($disp == 'postidx') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'mediaidx':
             $url = $Blog->get('mediaidxurl');
             $text = T_('Photo index');
             if ($disp == 'mediaidx') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'sitemap':
             $url = $Blog->get('sitemapurl');
             $text = T_('Site map');
             if ($disp == 'sitemap') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'latestcomments':
             if (!$Blog->get_setting('comments_latest')) {
                 // This page is disabled
                 return false;
             }
             $url = $Blog->get('lastcommentsurl');
             $text = T_('Latest comments');
             if ($disp == 'comments') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'owneruserinfo':
             $url = url_add_param($Blog->get('userurl'), 'user_ID=' . $Blog->owner_user_ID);
             $text = T_('Owner details');
             // Is this the current display?
             global $User;
             if ($disp == 'user' && !empty($User) && $User->ID == $Blog->owner_user_ID) {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'ownercontact':
             if (!($url = $Blog->get_contact_url(true))) {
                 // user does not allow contact form:
                 return;
             }
             $text = T_('Contact');
             // Is this the current display?
             if ($disp == 'msgform') {
                 // Let's display the link as selected
                 // fp> I think it's interesting to select this link , even if the recipient ID is different from the owner
                 // odds are there is no other link to highlight in this case
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'login':
             if (is_logged_in()) {
                 return false;
             }
             $url = get_login_url('menu link');
             if (isset($this->BlockCache)) {
                 // Do NOT cache because some of these links are using a redirect_to param, which makes it page dependent.
                 // so this will be cached by the PageCache; there is no added benefit to cache it in the BlockCache
                 // (which could have been shared between several pages):
                 $this->BlockCache->abort_collect();
             }
             $text = T_('Log in');
             // Is this the current display?
             if ($disp == 'login') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'register':
             if (!($url = get_user_register_url(NULL, 'menu link'))) {
                 return false;
             }
             if (isset($this->BlockCache)) {
                 // Do NOT cache because some of these links are using a redirect_to param, which makes it page dependent.
                 // Note: also beware of the source param.
                 // so this will be cached by the PageCache; there is no added benefit to cache it in the BlockCache
                 // (which could have been shared between several pages):
                 $this->BlockCache->abort_collect();
             }
             $text = T_('Register');
             // Is this the current display?
             if ($disp == 'register') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'profile':
             if (!is_logged_in()) {
                 return false;
             }
             $url = get_user_profile_url();
             $text = T_('Edit profile');
             // Is this the current display?  (Edit my Profile)
             if (in_array($disp, array('profile', 'avatar', 'pwdchange', 'userprefs', 'subs'))) {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'avatar':
             if (!is_logged_in()) {
                 return false;
             }
             $url = get_user_avatar_url();
             $text = T_('Profile picture');
             // Note: we never highlight this, it will always highlight 'profile' instead
             break;
         case 'users':
             global $Settings;
             if (!is_logged_in() && !$Settings->get('allow_anonymous_user_list')) {
                 // Don't allow anonymous users to see users list
                 return false;
             }
             $url = $Blog->get('usersurl');
             $text = T_('User directory');
             // Is this the current display?
             // Note: If $user_ID is not set, it means we are viewing "My Profile" instead
             global $user_ID;
             if ($disp == 'users' || $disp == 'user' && !empty($user_ID)) {
                 // Let's display the link as selected
                 // Note: we also highlight this for any user profile that is displayed
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'item':
             $ItemCache =& get_ItemCache();
             /**
              * @var Item
              */
             $item_ID = (int) $this->disp_params['item_ID'];
             $disp_Item =& $ItemCache->get_by_ID($item_ID, false, false);
             if (empty($disp_Item)) {
                 // Item not found
                 return false;
             }
             $url = $disp_Item->get_permanent_url();
             $text = $disp_Item->title;
             // Is this the current item?
             global $Item;
             if (!empty($Item) && $disp_Item->ID == $Item->ID) {
                 // The current page is currently displaying the Item this link is pointing to
                 // Let's display it as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'url':
             $url = $this->disp_params['link_href'];
             $text = '[URL]';
             // should normally be overriden below...
             // Note: we never highlight this link
             break;
         case 'postnew':
             if (!check_item_perm_create()) {
                 // Don't allow users to create a new post
                 return false;
             }
             $url = url_add_param($Blog->get('url'), 'disp=edit');
             $text = T_('Write a new post');
             // Is this the current display?
             if ($disp == 'edit') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'myprofile':
             if (!is_logged_in()) {
                 // Don't show this link for not logged in users
                 return false;
             }
             $url = url_add_param($Blog->get('url'), 'disp=user');
             $text = T_('My profile');
             // Is this the current display?  (Edit my Profile)
             global $user_ID, $current_User;
             // If $user_ID is not set, it means we will fall back to the current user, so it's ok
             // If $user_ID is set, it means we are browsing the directory instead
             if ($disp == 'user' && empty($user_ID)) {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'home':
         default:
             $url = $Blog->get('url');
             $text = T_('Home');
     }
     // Override default link text?
     if (!empty($this->param_array['link_text'])) {
         // We have a custom link text:
         $text = $this->param_array['link_text'];
     }
     echo $this->disp_params['block_start'];
     echo $this->disp_params['list_start'];
     echo $this->disp_params['item_start'];
     echo '<a href="' . $url . '" class="' . $link_class . '">' . $text . '</a>';
     echo $this->disp_params['item_end'];
     echo $this->disp_params['list_end'];
     echo $this->disp_params['block_end'];
     return true;
 }
示例#12
0
$Form->hiddens_by_key(get_memorized('action' . ($creating ? ',tag_ID' : '')));
$Form->text_input('tag_name', $edited_ItemTag->get('name'), 50, T_('Tag'), '', array('maxlength' => 255, 'required' => true));
$Form->end_form(array(array('submit', 'submit', $creating ? T_('Record') : T_('Save Changes!'), 'SaveButton')));
// Item list with this tag:
if ($edited_ItemTag->ID > 0) {
    $SQL = new SQL();
    $SQL->SELECT('T_items__item.*, blog_shortname');
    $SQL->FROM('T_items__itemtag');
    $SQL->FROM_add('INNER JOIN T_items__item ON itag_itm_ID = post_ID');
    $SQL->FROM_add('INNER JOIN T_categories ON post_main_cat_ID = cat_ID');
    $SQL->FROM_add('INNER JOIN T_blogs ON cat_blog_ID = blog_ID');
    $SQL->WHERE('itag_tag_ID = ' . $DB->quote($edited_ItemTag->ID));
    // Create result set:
    $Results = new Results($SQL->get(), 'tagitem_', 'A');
    $Results->title = T_('Posts that have this tag') . ' (' . $Results->get_total_rows() . ')';
    $Results->Cache = get_ItemCache();
    $Results->cols[] = array('th' => T_('Post ID'), 'th_class' => 'shrinkwrap', 'td_class' => 'shrinkwrap', 'order' => 'post_ID', 'td' => '$post_ID$');
    $Results->cols[] = array('th' => T_('Collection'), 'order' => 'blog_shortname', 'td' => '$blog_shortname$');
    $Results->cols[] = array('th' => T_('Post title'), 'order' => 'post_title', 'td' => '<a href="@get_permanent_url()@">$post_title$</a>');
    function tagitem_edit_actions($Item)
    {
        global $current_User, $edited_ItemTag;
        // Display the edit icon if current user has the rights:
        $r = $Item->get_edit_link(array('before' => '', 'after' => ' ', 'text' => get_icon('edit'), 'title' => '#', 'class' => ''));
        if ($current_User->check_perm('item_post!CURSTATUS', 'edit', false, $Item)) {
            // Display the unlink icon if current user has the rights:
            $r .= action_icon(T_('Unlink this tag from post!'), 'unlink', regenerate_url('tag_ID,action,tag_filter', 'tag_ID=' . $edited_ItemTag->ID . '&amp;item_ID=' . $Item->ID . '&amp;action=unlink&amp;' . url_crumb('tag')), NULL, NULL, NULL, array('onclick' => 'return confirm(\'' . format_to_output(sprintf(TS_('Are you sure you want to remove the tag "%s" from "%s"?'), $edited_ItemTag->dget('name'), $Item->dget('title')) . '\');', 'htmlattr')));
        }
        return $r;
    }
    $Results->cols[] = array('th' => T_('Actions'), 'th_class' => 'shrinkwrap', 'td_class' => 'shrinkwrap', 'td' => '%tagitem_edit_actions( {Obj} )%');
示例#13
0
 /**
  * Update the DB based on previously recorded changes.
  *
  * @todo dh> this is very Item specific, and should get fixed probably.
  *
  * @return boolean true on success
  */
 function dbupdate()
 {
     global $DB, $Messages;
     $ItemCache =& get_ItemCache();
     $Item =& $ItemCache->get_by_id($this->itm_ID);
     $DB->begin();
     if ($Item->get('canonical_slug_ID') == $this->ID) {
         $Item->set('urltitle', $this->title);
         if (!$Item->dbupdate(true, false, false)) {
             $DB->rollback();
             return false;
         }
         $Messages->add(sprintf(T_('Warning: this change also changed the canonical slug of the post! (%s)'), $this->get_link_to_object()), 'warning');
     }
     parent::dbupdate();
     $DB->commit();
     return true;
 }
示例#14
0
/**
 * Parse extra params of goal hit (E.g. 'item_ID=123')
 *
 * @param string Value of extra params
 * @param string
 */
function stats_goal_hit_extra_params($ghit_params)
{
    if (preg_match('/^item_ID=([0-9]+)$/i', $ghit_params, $matches)) {
        // Parse item ID
        $ItemCache =& get_ItemCache();
        if ($Item =& $ItemCache->get_by_ID(intval($matches[1]), false, false)) {
            // Display a link to view with current item title
            global $current_User;
            if ($current_User->check_perm('item_post!CURSTATUS', 'edit', false, $Item)) {
                // Link to admin view
                return $Item->get_title(array('link_type' => 'admin_view'));
            } else {
                // Link to permament url (it is allowed for current post type)
                return $Item->get_title();
            }
        }
    }
    return htmlspecialchars($ghit_params);
}
    /**
     * Display the widget!
     *
     * @param array MUST contain at least the basic display params
     */
    function display($params)
    {
        global $localtimenow, $DB, $Blog;
        $this->init_display($params);
        $blog_ID = intval($this->disp_params['blog_ID']);
        if (empty($blog_ID)) {
            // Use current blog by default
            $blog_ID = $Blog->ID;
        }
        $BlogCache =& get_BlogCache();
        if (!$BlogCache->get_by_ID($blog_ID, false, false)) {
            // No blog exists
            return;
        }
        // Display photos:
        // TODO: permissions, complete statuses...
        // TODO: A FileList object based on ItemListLight but adding File data into the query?
        //          overriding ItemListLigth::query() for starters ;)
        // Init caches
        $FileCache =& get_FileCache();
        $ItemCache =& get_ItemCache();
        // Query list of files and posts fields:
        // Note: We use ItemQuery to get attachments from all posts which should be visible ( even in case of aggregate blogs )
        $ItemQuery = new ItemQuery($ItemCache->dbtablename, $ItemCache->dbprefix, $ItemCache->dbIDname);
        $ItemQuery->SELECT('post_ID, post_datestart, post_datemodified, post_main_cat_ID, post_urltitle, post_canonical_slug_ID,
									post_tiny_slug_ID, post_ityp_ID, post_title, post_excerpt, post_url, file_ID, file_type,
									file_title, file_root_type, file_root_ID, file_path, file_alt, file_desc, file_path_hash');
        $ItemQuery->FROM_add('INNER JOIN T_links ON post_ID = link_itm_ID');
        $ItemQuery->FROM_add('INNER JOIN T_files ON link_file_ID = file_ID');
        $ItemQuery->where_chapter($blog_ID);
        if ($this->disp_params['item_visibility'] == 'public') {
            // Get images only of the public items
            $ItemQuery->where_visibility(array('published'));
        } else {
            // Get image of all available posts for current user
            $ItemQuery->where_visibility(NULL);
        }
        $ItemQuery->WHERE_and('( file_type = "image" ) OR ( file_type IS NULL )');
        $ItemQuery->WHERE_and('post_datestart <= \'' . remove_seconds($localtimenow) . '\'');
        $ItemQuery->WHERE_and('link_position != "cover"');
        if (!empty($this->disp_params['item_type'])) {
            // Get items only with specified type
            $ItemQuery->WHERE_and('post_ityp_ID = ' . intval($this->disp_params['item_type']));
        }
        $ItemQuery->GROUP_BY('link_ID');
        // fp> TODO: because no way of getting images only, we get 4 times more data than requested and hope that 25% at least will be images :/
        // asimo> This was updated and we get images and those files where we don't know the file type yet. Now we get 2 times more data than requested.
        // Maybe it would be good to get only the requested amount of files, because after a very short period the file types will be set for all images.
        $ItemQuery->LIMIT(intval($this->disp_params['limit']) * 2);
        $ItemQuery->ORDER_BY(gen_order_clause($this->disp_params['order_by'], $this->disp_params['order_dir'], 'post_', 'post_ID ' . $this->disp_params['order_dir'] . ', link_ID'));
        // Init FileList with the above defined query
        $FileList = new DataObjectList2($FileCache);
        $FileList->sql = $ItemQuery->get();
        $FileList->query(false, false, false, 'Media index widget');
        $layout = $this->disp_params['thumb_layout'];
        $nb_cols = $this->disp_params['grid_nb_cols'];
        $count = 0;
        $r = '';
        /**
         * @var File
         */
        while ($File =& $FileList->get_next()) {
            if ($count >= $this->disp_params['limit']) {
                // We have enough images already!
                break;
            }
            if (!$File->is_image()) {
                // Skip anything that is not an image
                // Only images are selected or those files where we don't know the file type yet.
                // This check is only for those files where we don't know the filte type. The file type will be set during the check.
                continue;
            }
            if ($layout == 'grid') {
                // Grid layout
                if ($count % $nb_cols == 0) {
                    $r .= $this->disp_params['grid_colstart'];
                }
                $r .= $this->disp_params['grid_cellstart'];
            } elseif ($layout == 'flow') {
                // Flow block layout
                $r .= $this->disp_params['flow_block_start'];
            } else {
                // List layout
                $r .= $this->disp_params['item_start'];
            }
            // 1/ Hack a dirty permalink( will redirect to canonical):
            // $link = url_add_param( $Blog->get('url'), 'p='.$post_ID );
            // 2/ Hack a link to the right "page". Very daring!!
            // $link = url_add_param( $Blog->get('url'), 'paged='.$count );
            // 3/ Instantiate a light object in order to get permamnent url:
            $ItemLight = new ItemLight($FileList->get_row_by_idx($FileList->current_idx - 1));
            // index had already been incremented
            $r .= '<a href="' . $ItemLight->get_permanent_url() . '">';
            // Generate the IMG THUMBNAIL tag with all the alt, title and desc if available
            $r .= $File->get_thumb_imgtag($this->disp_params['thumb_size'], '', '', $ItemLight->title);
            $r .= '</a>';
            if ($this->disp_params['disp_image_title']) {
                // Dislay title of image or item
                $title = $File->get('title') ? $File->get('title') : $ItemLight->title;
                if (!empty($title)) {
                    $r .= '<span class="note">' . $title . '</span>';
                }
            }
            ++$count;
            if ($layout == 'grid') {
                // Grid layout
                $r .= $this->disp_params['grid_cellend'];
                if ($count % $nb_cols == 0) {
                    $r .= $this->disp_params['grid_colend'];
                }
            } elseif ($layout == 'flow') {
                // Flow block layout
                $r .= $this->disp_params['flow_block_end'];
            } else {
                // List layout
                $r .= $this->disp_params['item_end'];
            }
        }
        // Exit if no files found
        if (empty($r)) {
            return;
        }
        echo $this->disp_params['block_start'];
        // Display title if requested
        $this->disp_title();
        echo $this->disp_params['block_body_start'];
        if ($layout == 'grid') {
            // Grid layout
            echo $this->disp_params['grid_start'];
        } elseif ($layout == 'flow') {
            // Flow block layout
            echo $this->disp_params['flow_start'];
        } else {
            // List layout
            echo $this->disp_params['list_start'];
        }
        echo $r;
        if ($layout == 'grid') {
            // Grid layout
            if ($count && $count % $nb_cols != 0) {
                echo $this->disp_params['grid_colend'];
            }
            echo $this->disp_params['grid_end'];
        } elseif ($layout == 'flow') {
            // Flow block layout
            echo $this->disp_params['flow_end'];
        } else {
            // List layout
            echo $this->disp_params['list_end'];
        }
        echo $this->disp_params['block_body_end'];
        echo $this->disp_params['block_end'];
        return true;
    }
示例#16
0
 /**
  * Display the widget!
  *
  * @param array MUST contain at least the basic display params
  */
 function display($params)
 {
     /**
      * @var Blog
      */
     global $Blog;
     global $disp;
     $this->init_display($params);
     // Default link class
     $link_class = $this->disp_params['link_default_class'];
     $blog_ID = intval($this->disp_params['blog_ID']);
     if ($blog_ID > 0) {
         // Try to use blog from widget setting
         $BlogCache =& get_BlogCache();
         $current_Blog =& $BlogCache->get_by_ID($blog_ID, false, false);
     }
     if (empty($current_Blog)) {
         // Blog is not defined in setting or it doesn't exist in DB
         // Use current blog
         $current_Blog =& $Blog;
     }
     if (empty($current_Blog)) {
         // We cannot use this widget without a current collection:
         return false;
     }
     switch ($this->disp_params['link_type']) {
         case 'recentposts':
             $url = $current_Blog->get('recentpostsurl');
             if (is_same_url($url, $Blog->get('url'))) {
                 // This menu item has the same url as front page of blog
                 $EnabledWidgetCache =& get_EnabledWidgetCache();
                 $Widget_array =& $EnabledWidgetCache->get_by_coll_container($current_Blog->ID, NT_('Menu'));
                 if (!empty($Widget_array)) {
                     foreach ($Widget_array as $Widget) {
                         $Widget->init_display($params);
                         if (isset($Widget->param_array, $Widget->param_array['link_type']) && $Widget->param_array['link_type'] == 'home') {
                             // Don't display this menu if 'Blog home' menu item exists with the same url
                             return false;
                         }
                     }
                 }
             }
             $text = T_('Recently');
             if ($disp == 'posts') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'search':
             $url = $current_Blog->get('searchurl');
             $text = T_('Search');
             // Is this the current display?
             if ($disp == 'search') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'arcdir':
             $url = $current_Blog->get('arcdirurl');
             $text = T_('Archives');
             if ($disp == 'arcdir') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'catdir':
             $url = $current_Blog->get('catdirurl');
             $text = T_('Categories');
             if ($disp == 'catdir') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'tags':
             $url = $current_Blog->get('tagsurl');
             $text = T_('Tags');
             if ($disp == 'tags') {
                 // Let's display the link as selected:
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'postidx':
             $url = $current_Blog->get('postidxurl');
             $text = T_('Post index');
             if ($disp == 'postidx') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'mediaidx':
             $url = $current_Blog->get('mediaidxurl');
             $text = T_('Photo index');
             if ($disp == 'mediaidx') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'sitemap':
             $url = $current_Blog->get('sitemapurl');
             $text = T_('Site map');
             if ($disp == 'sitemap') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'latestcomments':
             if (!$current_Blog->get_setting('comments_latest')) {
                 // This page is disabled
                 return false;
             }
             $url = $current_Blog->get('lastcommentsurl');
             $text = T_('Latest comments');
             if ($disp == 'comments') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'owneruserinfo':
             $url = url_add_param($current_Blog->get('userurl'), 'user_ID=' . $current_Blog->owner_user_ID);
             $text = T_('Owner details');
             // Is this the current display?
             global $User;
             if ($disp == 'user' && !empty($User) && $User->ID == $current_Blog->owner_user_ID) {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'ownercontact':
             if (!($url = $current_Blog->get_contact_url(true))) {
                 // user does not allow contact form:
                 return;
             }
             $text = T_('Contact');
             // Is this the current display?
             if ($disp == 'msgform' || isset($_GET['disp']) && $_GET['disp'] == 'msgform') {
                 // Let's display the link as selected
                 // fp> I think it's interesting to select this link , even if the recipient ID is different from the owner
                 // odds are there is no other link to highlight in this case
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'login':
             if (is_logged_in()) {
                 // Don't display this link for already logged in users
                 return false;
             }
             global $Settings;
             $url = get_login_url('menu link', $Settings->get('redirect_to_after_login'), false, $current_Blog->ID);
             if (isset($this->BlockCache)) {
                 // Do NOT cache because some of these links are using a redirect_to param, which makes it page dependent.
                 // so this will be cached by the PageCache; there is no added benefit to cache it in the BlockCache
                 // (which could have been shared between several pages):
                 $this->BlockCache->abort_collect();
             }
             $text = T_('Log in');
             // Is this the current display?
             if ($disp == 'login') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'logout':
             if (!is_logged_in()) {
                 return false;
             }
             $url = get_user_logout_url($current_Blog->ID);
             $text = T_('Log out');
             break;
         case 'register':
             if (!($url = get_user_register_url(NULL, 'menu link', false, '&amp;', $current_Blog->ID))) {
                 return false;
             }
             if (isset($this->BlockCache)) {
                 // Do NOT cache because some of these links are using a redirect_to param, which makes it page dependent.
                 // Note: also beware of the source param.
                 // so this will be cached by the PageCache; there is no added benefit to cache it in the BlockCache
                 // (which could have been shared between several pages):
                 $this->BlockCache->abort_collect();
             }
             $text = T_('Register');
             // Is this the current display?
             if ($disp == 'register') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'profile':
             if (!is_logged_in()) {
                 return false;
             }
             $url = get_user_profile_url($current_Blog->ID);
             $text = T_('Edit profile');
             // Is this the current display?  (Edit my Profile)
             if (in_array($disp, array('profile', 'avatar', 'pwdchange', 'userprefs', 'subs'))) {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'avatar':
             if (!is_logged_in()) {
                 return false;
             }
             $url = get_user_avatar_url($current_Blog->ID);
             $text = T_('Profile picture');
             // Note: we never highlight this, it will always highlight 'profile' instead
             break;
         case 'users':
             global $Settings;
             if (!is_logged_in() && !$Settings->get('allow_anonymous_user_list')) {
                 // Don't allow anonymous users to see users list
                 return false;
             }
             $url = $current_Blog->get('usersurl');
             $text = T_('User directory');
             // Is this the current display?
             // Note: If $user_ID is not set, it means we are viewing "My Profile" instead
             global $user_ID;
             if ($disp == 'users' || $disp == 'user' && !empty($user_ID)) {
                 // Let's display the link as selected
                 // Note: we also highlight this for any user profile that is displayed
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'item':
             $ItemCache =& get_ItemCache();
             /**
              * @var Item
              */
             $item_ID = intval($this->disp_params['item_ID']);
             $disp_Item =& $ItemCache->get_by_ID($item_ID, false, false);
             if (empty($disp_Item)) {
                 // Item not found
                 return false;
             }
             $url = $disp_Item->get_permanent_url();
             $text = $disp_Item->title;
             // Is this the current item?
             global $Item;
             if (!empty($Item) && $disp_Item->ID == $Item->ID) {
                 // The current page is currently displaying the Item this link is pointing to
                 // Let's display it as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'url':
             if (empty($this->disp_params['link_href'])) {
                 // Don't display a link if url is empty
                 return false;
             }
             $url = $this->disp_params['link_href'];
             $text = '[URL]';
             // should normally be overriden below...
             // Note: we never highlight this link
             break;
         case 'postnew':
             if (!check_item_perm_create()) {
                 // Don't allow users to create a new post
                 return false;
             }
             $url = url_add_param($current_Blog->get('url'), 'disp=edit');
             $text = T_('Write a new post');
             // Is this the current display?
             if ($disp == 'edit') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'myprofile':
             if (!is_logged_in()) {
                 // Don't show this link for not logged in users
                 return false;
             }
             $url = $current_Blog->get('userurl');
             $text = T_('My profile');
             // Is this the current display?  (Edit my Profile)
             global $user_ID, $current_User;
             // If $user_ID is not set, it means we will fall back to the current user, so it's ok
             // If $user_ID is set, it means we are browsing the directory instead
             if ($disp == 'user' && empty($user_ID)) {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'admin':
             global $current_User;
             if (!(is_logged_in() && $current_User->check_perm('admin', 'restricted') && $current_User->check_status('can_access_admin'))) {
                 // Don't allow admin url for users who have no access to backoffice
                 return false;
             }
             global $admin_url;
             $url = $admin_url;
             $text = T_('Admin') . ' &raquo;';
             break;
         case 'home':
         default:
             $url = $current_Blog->get('url');
             $text = T_('Front Page');
             global $is_front;
             if ($disp == 'front' || !empty($is_front)) {
                 // Let's display the link as selected on front page
                 $link_class = $this->disp_params['link_selected_class'];
             }
     }
     // Override default link text?
     if (!empty($this->param_array['link_text'])) {
         // We have a custom link text:
         $text = $this->param_array['link_text'];
     }
     echo $this->disp_params['block_start'];
     echo $this->disp_params['block_body_start'];
     echo $this->disp_params['list_start'];
     if ($link_class == $this->disp_params['link_selected_class']) {
         echo $this->disp_params['item_selected_start'];
     } else {
         echo $this->disp_params['item_start'];
     }
     echo '<a href="' . $url . '" class="' . $link_class . '">' . $text . '</a>';
     if ($link_class == $this->disp_params['link_selected_class']) {
         echo $this->disp_params['item_selected_end'];
     } else {
         echo $this->disp_params['item_end'];
     }
     echo $this->disp_params['list_end'];
     echo $this->disp_params['block_body_end'];
     echo $this->disp_params['block_end'];
     return true;
 }
示例#17
0
 /**
  * Check if user must accept terms & conditions
  *
  * @return boolean
  */
 function must_accept_terms()
 {
     global $UserSettings, $Settings;
     if ($UserSettings->get('terms_accepted', $this->ID)) {
         // This user already accepted the terms:
         return false;
     }
     // Get ID of page with terms & conditions from global settings:
     $terms_page_ID = intval($Settings->get('site_terms'));
     $ItemCache =& get_ItemCache();
     if ($terms_page_ID && ($terms_Item =& $ItemCache->get_by_ID($terms_page_ID, false, false))) {
         // The post for terms is defined and user still must accept it:
         return true;
     } else {
         // No terms for this site:
         return false;
     }
 }
/**
 * Get a <td> class of a cell
 *
 * @param integer Post ID
 * @param integer $post_pst_ID
 * @param string Class name to make this cell editable
 * @return string
 */
function td_task_class($post_ID, $post_pst_ID, $editable_class)
{
    global $current_User;
    $ItemCache =& get_ItemCache();
    $Item =& $ItemCache->get_by_ID($post_ID);
    $class = 'nowrap tskst_' . $post_pst_ID;
    if ($current_User->check_perm('item_post!CURSTATUS', 'edit', false, $Item)) {
        // Current user can edit this item, Add a class to edit a priority by click from view list
        $class .= ' ' . $editable_class;
    }
    return $class;
}
示例#19
0
    /**
     * Render content of Item, Comment, Message
     *
     * @todo get rid of global $blog
     * 
     * @param string Content
     * @param object Blog
     * @param boolean Allow empty Blog
     * return boolean
     */
    function render_content(&$content, $item_Blog = NULL, $allow_null_blog = false)
    {
        global $ItemCache, $admin_url, $blog, $evo_charset;
        $regexp_modifier = '';
        if ($evo_charset == 'utf-8') {
            // Add this modifier to work with UTF-8 strings correctly
            $regexp_modifier = 'u';
        }
        // Regular links:
        $search = array('#\\[\\[((https?|mailto)://((?:[^<>{}\\s\\]]|,(?!\\s))+?))\\]\\]#i', '#\\[\\[((https?|mailto)://([^<>{}\\s\\]]+)) ([^\\n\\r]+?)\\]\\]#i', '#\\(\\(((https?|mailto)://((?:[^<>{}\\s\\]]|,(?!\\s))+?))\\)\\)#i', '#\\(\\(((https?|mailto)://([^<>{}\\s\\]]+)) ([^\\n\\r]+?)\\)\\)#i');
        $replace = array('<a href="$1">$1</a>', '<a href="$1">$4</a>', '<a href="$1">$1</a>', '<a href="$1">$4</a>');
        $content = replace_content_outcode($search, $replace, $content);
        /* QUESTION: fplanque, implementation of this planned? then use make_clickable() - or remove this comment
        	$ret = preg_replace("#([\n ])aim:([^,< \n\r]+)#i", "\\1<a href=\"aim:goim?screenname=\\2\\3&message=Hello\">\\2\\3</a>", $ret);
        
        	$ret = preg_replace("#([\n ])icq:([^,< \n\r]+)#i", "\\1<a href=\"http://wwp.icq.com/scripts/search.dll?to=\\2\\3\">\\2\\3</a>", $ret);
        
        	$ret = preg_replace("#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^,< \n\r]*)?)#i", "\\1<a href=\"http://www.\\2.\\3\\4\">www.\\2.\\3\\4</a>", $ret);
        
        	$ret = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([^,< \n\r]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret); */
        // To use function replace_special_chars()
        load_funcs('locales/_charset.funcs.php');
        // WIKIWORDS:
        $search_wikiwords = array();
        $replace_links = array();
        if ($this->get_coll_setting('link_without_brackets', $item_Blog, $allow_null_blog)) {
            // Create the links from standalone WikiWords
            // STANDALONE WIKIWORDS:
            $search = '/
					(?<= \\s | ^ )													# Lookbehind for whitespace
					([\\p{Lu}]+[\\p{Ll}0-9_]+([\\p{Lu}]+[\\p{L}0-9_]+)+)	# WikiWord or WikiWordLong
					(?= [\\.,:;!\\?] \\s | \\s | $ )											# Lookahead for whitespace or punctuation
				/x' . $regexp_modifier;
            // x = extended (spaces + comments allowed)
            if (preg_match_all($search, $content, $matches, PREG_SET_ORDER)) {
                // Construct array of wikiwords to look up in post urltitles
                $wikiwords = array();
                foreach ($matches as $match) {
                    // Convert the WikiWord to an urltitle
                    $WikiWord = $match[0];
                    $Wiki_Word = preg_replace('*([^\\p{Lu}_])([\\p{Lu}])*' . $regexp_modifier, '$1-$2', $WikiWord);
                    $wiki_word = evo_strtolower($Wiki_Word);
                    // echo '<br />Match: [', $WikiWord, '] -> [', $wiki_word, ']';
                    $wiki_word = replace_special_chars($wiki_word);
                    $wikiwords[$WikiWord] = $wiki_word;
                }
                // Lookup all urltitles at once in DB and preload cache:
                $ItemCache =& get_ItemCache();
                $ItemCache->load_urltitle_array($wikiwords);
                // Construct arrays for replacing wikiwords by links:
                foreach ($wikiwords as $WikiWord => $wiki_word) {
                    // WikiWord
                    $search_wikiwords[] = '/
						(?<= \\s | ^ ) 						# Lookbehind for whitespace or start
						(?<! <span\\ class="NonExistentWikiWord"> )
						' . $WikiWord . '							# Specific WikiWord to replace
						(?= [\\.,:;!\\?] \\s | \\s | $ )							# Lookahead for whitespace or end of string
						/sx';
                    // s = dot matches newlines, x = extended (spaces + comments allowed)
                    // Find matching Item:
                    if (($Item =& $ItemCache->get_by_urltitle($wiki_word, false)) !== false) {
                        // Item Found
                        $permalink = $Item->get_permanent_url();
                        // WikiWord
                        $replace_links[] = '<a href="' . $permalink . '">' . $Item->get('title') . '</a>';
                    } else {
                        // Item not found
                        $create_link = isset($blog) ? '<a href="' . $admin_url . '?ctrl=items&amp;action=new&amp;blog=' . $blog . '&amp;post_title=' . preg_replace('*([^\\p{Lu}_])([\\p{Lu}])*' . $regexp_modifier, '$1%20$2', $WikiWord) . '&amp;post_urltitle=' . $wiki_word . '" title="Create...">?</a>' : '';
                        // WikiWord
                        $replace_links[] = '<span class="NonExistentWikiWord">' . $WikiWord . $create_link . '</span>';
                    }
                }
            }
        }
        // BRACKETED WIKIWORDS:
        $search = '/
				(?<= \\(\\( | \\[\\[ )										# Lookbehind for (( or [[
				([\\p{L}0-9]+[\\p{L}0-9_\\-]*)									# Anything from Wikiword to WikiWordLong
				(?= ( \\s .*? )? ( \\)\\) | \\]\\] ) )			# Lookahead for )) or ]]
			/x' . $regexp_modifier;
        // x = extended (spaces + comments allowed)
        if (preg_match_all($search, $content, $matches, PREG_SET_ORDER)) {
            // Construct array of wikiwords to look up in post urltitles
            $wikiwords = array();
            foreach ($matches as $match) {
                // Convert the WikiWord to an urltitle
                $WikiWord = $match[0];
                if (preg_match('/^[\\p{Ll}0-9_\\-]+$/' . $regexp_modifier, $WikiWord)) {
                    // This WikiWord already matches a slug format
                    $Wiki_Word = $WikiWord;
                    $wiki_word = $Wiki_Word;
                } else {
                    // Convert WikiWord to slug format
                    $Wiki_Word = preg_replace(array('*([^\\p{Lu}_])([\\p{Lu}])*' . $regexp_modifier, '*([^0-9])([0-9])*' . $regexp_modifier), '$1-$2', $WikiWord);
                    $wiki_word = evo_strtolower($Wiki_Word);
                }
                // echo '<br />Match: [', $WikiWord, '] -> [', $wiki_word, ']';
                $wiki_word = replace_special_chars($wiki_word);
                $wikiwords[$WikiWord] = $wiki_word;
            }
            // Lookup all urltitles at once in DB and preload cache:
            $ChapterCache =& get_ChapterCache();
            $ChapterCache->load_urlname_array($wikiwords);
            $ItemCache =& get_ItemCache();
            $ItemCache->load_urltitle_array($wikiwords);
            // Construct arrays for replacing wikiwords by links:
            foreach ($wikiwords as $WikiWord => $wiki_word) {
                // [[WikiWord text]]
                $search_wikiwords[] = '*
					\\[\\[
					' . $WikiWord . '							# Specific WikiWord to replace
					\\s (.+?)
					\\]\\]
					*sx';
                // s = dot matches newlines, x = extended (spaces + comments allowed)
                // ((WikiWord text))
                $search_wikiwords[] = '*
					\\(\\(
					' . $WikiWord . '							# Specific WikiWord to replace
					\\s (.+?)
					\\)\\)
					*sx';
                // s = dot matches newlines, x = extended (spaces + comments allowed)
                // [[Wikiword]]
                $search_wikiwords[] = '*
					\\[\\[
					' . $WikiWord . '							# Specific WikiWord to replace
					\\]\\]
					*sx';
                // s = dot matches newlines, x = extended (spaces + comments allowed)
                // ((Wikiword))
                $search_wikiwords[] = '*
					\\(\\(
					' . $WikiWord . '							# Specific WikiWord to replace
					\\)\\)
					*sx';
                // s = dot matches newlines, x = extended (spaces + comments allowed)
                // Find matching Chapter or Item:
                $permalink = '';
                $link_text = preg_replace(array('*([^\\p{Lu}_])([\\p{Lu}])*' . $regexp_modifier, '*([^0-9])([0-9])*' . $regexp_modifier), '$1 $2', $WikiWord);
                $link_text = ucwords(str_replace('-', ' ', $link_text));
                if (($Chapter =& $ChapterCache->get_by_urlname($wiki_word, false)) !== false) {
                    // Chapter is found
                    $permalink = $Chapter->get_permanent_url();
                    $existing_link_text = $Chapter->get('name');
                } elseif (($Item =& $ItemCache->get_by_urltitle($wiki_word, false)) !== false) {
                    // Item is found
                    $permalink = $Item->get_permanent_url();
                    $existing_link_text = $Item->get('title');
                }
                if (!empty($permalink)) {
                    // Chapter or Item are found
                    // [[WikiWord text]]
                    $replace_links[] = '<a href="' . $permalink . '">$1</a>';
                    // ((WikiWord text))
                    $replace_links[] = '<a href="' . $permalink . '">$1</a>';
                    // [[Wikiword]]
                    $replace_links[] = '<a href="' . $permalink . '">' . $existing_link_text . '</a>';
                    // ((Wikiword))
                    $replace_links[] = '<a href="' . $permalink . '">' . $link_text . '</a>';
                } else {
                    // Chapter and Item are not found
                    $create_link = isset($blog) ? '<a href="' . $admin_url . '?ctrl=items&amp;action=new&amp;blog=' . $blog . '&amp;post_title=' . preg_replace('*([^\\p{Lu}_])([\\p{Lu}])*' . $regexp_modifier, '$1%20$2', $WikiWord) . '&amp;post_urltitle=' . $wiki_word . '" title="Create...">?</a>' : '';
                    // [[WikiWord text]]
                    $replace_links[] = '<span class="NonExistentWikiWord">$1' . $create_link . '</span>';
                    // ((WikiWord text))
                    $replace_links[] = '<span class="NonExistentWikiWord">$1' . $create_link . '</span>';
                    // [[Wikiword]]
                    $replace_links[] = '<span class="NonExistentWikiWord">' . $link_text . $create_link . '</span>';
                    // ((Wikiword))
                    $replace_links[] = '<span class="NonExistentWikiWord">' . $link_text . $create_link . '</span>';
                }
            }
        }
        // echo '<br />---';
        // pre_dump( $search_wikiwords );
        $content = replace_content_outcode($search_wikiwords, $replace_links, $content);
        return true;
    }
示例#20
0
 /**
  * Iterate through the given Chapter sub cats and items
  *
  * @param Object Chapter
  * @param array  Callback functions to display a Chapter and to display an Item
  * @param boolean Set true to iterate sub categories recursively, false otherwise
  * @param array Any additional params ( e.g. 'sorted', 'level', 'list_subs_start', etc. )
  * @return string the concatenated callbacks result
  */
 function iterate_through_category_children($Chapter, $callbacks, $recurse = false, $params = array())
 {
     $r = "";
     $cat_items = array();
     $has_sub_cats = !empty($Chapter->children);
     $params = array_merge(array('sorted' => false, 'level' => 0, 'max_level' => 0, 'subset_ID' => $Chapter->blog_ID), $params);
     if ($params['sorted'] && $has_sub_cats) {
         $Chapter->sort_children();
     }
     if (!empty($callbacks['posts'])) {
         $ItemCache =& get_ItemCache();
         $cat_items = $ItemCache->get_by_cat_ID($Chapter->ID, $params['sorted']);
     }
     if ($has_sub_cats || !empty($cat_items)) {
         // Display category or posts
         $cat_index = 0;
         $item_index = 0;
         $subcats_to_display = array();
         $chapter_children_ids = array_keys($Chapter->children);
         $has_more_children = isset($chapter_children_ids[$cat_index]);
         $has_more_items = isset($cat_items[$item_index]);
         $cat_order = $Chapter->get_subcat_ordering();
         // Set post params for post display
         $params['chapter_ID'] = $Chapter->ID;
         $params['cat_order'] = $cat_order;
         if (($has_more_children || $has_more_items) && isset($params['list_subs_start'])) {
             $r .= $params['list_subs_start'];
         }
         while ($has_more_children || $has_more_items) {
             $current_sub_Chapter = $has_more_children ? $Chapter->children[$chapter_children_ids[$cat_index]] : NULL;
             $current_Item = $has_more_items ? $cat_items[$item_index] : NULL;
             if ($current_Item != NULL && ($current_sub_Chapter == NULL || $this->compare_item_with_chapter($current_Item, $current_sub_Chapter, $cat_order) <= 0)) {
                 if (!empty($subcats_to_display)) {
                     if ($recurse) {
                         $r .= $this->recurse($callbacks, $params['subset_ID'], $subcats_to_display, $params['level'] + 1, $params['max_level'], $params);
                     } else {
                         // Display each category without recursion
                         foreach ($subcats_to_display as $sub_Chapter) {
                             // Display each category:
                             if (is_array($callbacks['line'])) {
                                 // object callback:
                                 $r .= $callbacks['line'][0]->{$callbacks['line'][1]}($sub_Chapter, 0, $params);
                                 // <li> Category  - or - <tr><td>Category</td></tr> ...
                             } else {
                                 $r .= $callbacks['line']($sub_Chapter, 0, $params);
                                 // <li> Category  - or - <tr><td>Category</td></tr> ...
                             }
                         }
                     }
                     $subcats_to_display = array();
                 }
                 if (is_array($callbacks['posts'])) {
                     // object callback:
                     $r .= $callbacks['posts'][0]->{$callbacks['posts'][1]}($current_Item, $params['level'] + 1, $params);
                 } else {
                     $r .= $callbacks['posts']($current_Item, $params['level'] + 1, $params);
                 }
                 $has_more_items = isset($cat_items[++$item_index]);
             } elseif ($current_sub_Chapter != NULL) {
                 $subcats_to_display[] = $current_sub_Chapter;
                 $has_more_children = isset($chapter_children_ids[++$cat_index]);
             }
         }
         if (!empty($subcats_to_display)) {
             // Display all subcats which were not displayed yet
             if ($recurse) {
                 $r .= $this->recurse($callbacks, $params['subset_ID'], $subcats_to_display, $params['level'] + 1, $params['max_level'], $params);
             } else {
                 // Display each category without recursion
                 foreach ($subcats_to_display as $sub_Chapter) {
                     // Display each category:
                     if (is_array($callbacks['line'])) {
                         // object callback:
                         $r .= $callbacks['line'][0]->{$callbacks['line'][1]}($sub_Chapter, 0, $params);
                         // <li> Category  - or - <tr><td>Category</td></tr> ...
                     } else {
                         $r .= $callbacks['line']($sub_Chapter, 0, $params);
                         // <li> Category  - or - <tr><td>Category</td></tr> ...
                     }
                 }
             }
         }
         if (($cat_index > 0 || $item_index > 0) && isset($params['list_subs_end'])) {
             $r .= $params['list_subs_end'];
         }
     } elseif (isset($callbacks['no_children'])) {
         // Display message when no children
         if (is_array($callbacks['no_children'])) {
             // object callback:
             $r .= $callbacks['no_children'][0]->{$callbacks['no_children'][1]}($Chapter, $params['level'] + 1);
             // </li>
         } else {
             $r .= $callbacks['no_children']($Chapter, $params['level'] + 1);
             // </li>
         }
     }
     return $r;
 }
    /**
     * Set the status of an event for a given Plugin.
     *
     * @return boolean True, if status has changed; false if not
     */
    function set_event_status($plugin_ID, $plugin_event, $enabled)
    {
        global $DB;
        $enabled = $enabled ? 1 : 0;
        $DB->query('
			UPDATE T_pluginevents
			   SET pevt_enabled = ' . $enabled . '
			 WHERE pevt_plug_ID = ' . $plugin_ID . '
			   AND pevt_event = "' . $plugin_event . '"');
        if ($DB->rows_affected) {
            $this->load_events();
            if (strpos($plugin_event, 'RenderItemAs') === 0) {
                // Clear pre-rendered content cache, if RenderItemAs* events have been added or removed:
                $DB->query('DELETE FROM T_items__prerendering WHERE 1=1');
                $ItemCache =& get_ItemCache();
                $ItemCache->clear();
                break;
            }
            return true;
        }
        return false;
    }
示例#22
0
/**
 * Delete the comments
 *
 * @param string Type of deleting:
 *               'recycle' - to move into recycle bin
 *               'delete' - to delete permanently
 * @param string sql query to get deletable comment ids
 */
function comment_mass_delete_process($mass_type, $deletable_comments_query)
{
    if ($mass_type != 'recycle' && $mass_type != 'delete') {
        // Incorrect action
        return;
    }
    global $DB, $cache_comments_has_replies, $user_post_read_statuses, $cache_postcats;
    /**
     * Disable log queries because it increases the memory and stops the process with error "Allowed memory size of X bytes exhausted..."
     */
    $DB->log_queries = false;
    $Form = new Form();
    $Form->begin_form('fform');
    $Form->begin_fieldset(T_('Mass deleting log'));
    echo T_('The comments are deleting...');
    evo_flush();
    $CommentCache =& get_CommentCache();
    $ItemCache =& get_ItemCache();
    $ChapterCache =& get_ChapterCache();
    // Get the comments by 1000 to avoid an exhausting of memory
    $deletable_comment_ids = $DB->get_col($deletable_comments_query . ' LIMIT 1000');
    while (!empty($deletable_comment_ids)) {
        // Get the first slice of the deletable comment ids list
        $ids = array_splice($deletable_comment_ids, 0, 100);
        // Make sure the CommentCache is empty
        $CommentCache->clear();
        // Load deletable comment ids
        $CommentCache->load_list($ids);
        while (($iterator_Comment =& $CommentCache->get_next()) != NULL) {
            // Delete all comments from CommentCache
            $iterator_Comment->dbdelete($mass_type == 'delete');
        }
        // Display progress dot
        echo ' .';
        evo_flush();
        if (empty($deletable_comment_ids)) {
            // Clear all caches to save memory
            $ItemCache->clear();
            $ChapterCache->clear();
            $cache_comments_has_replies = array();
            $user_post_read_statuses = array();
            $cache_postcats = array();
            // Get new portion of deletable comments
            $deletable_comment_ids = $DB->get_col($deletable_comments_query . ' LIMIT 1000');
        }
    }
    echo ' OK';
    $Form->end_form();
    // Clear a comment cache
    $CommentCache->clear();
}
示例#23
0
/**
 * Get array of latest comments
 *
 * @param array of params
 *			- Blog (object)
 *			- User (object)
 *			- limit (int) the number of comments to return
 *			- comment_ID (int) return specified comment or NULL to return all available
 *			- item_ID (int) return comments for specified item only
 * @return xmlrpcmsg
 */
function xmlrpc_get_comments($params, &$Blog)
{
    global $DB, $current_User;
    $params = array_merge(array('limit' => 0, 'comment_ID' => 0, 'item_ID' => 0, 'statuses' => '', 'types' => array('comment', 'trackback', 'pingback')), $params);
    $params['comment_ID'] = abs(intval($params['comment_ID']));
    $params['item_ID'] = abs(intval($params['item_ID']));
    if (empty($params['statuses'])) {
        // Return all except 'trash'
        $params['statuses'] = array('published', 'deprecated', 'draft');
    }
    if (!empty($params['comment_ID'])) {
        logIO('Getting comment #' . $params['comment_ID']);
        $filters = array('comment_ID' => $params['comment_ID'], 'types' => $params['types'], 'statuses' => $params['statuses']);
    } elseif (!empty($params['item_ID'])) {
        logIO('Getting comments to item #' . $params['item_ID']);
        $ItemCache =& get_ItemCache();
        $Item =& $ItemCache->get_by_ID($params['item_ID'], false, false);
        if (empty($Item)) {
            // Item not found
            return xmlrpcs_resperror(5, 'Requested post/Item (' . $params['item_ID'] . ') does not exist.');
        }
        if (!$Item->can_see_comments()) {
            // Cannot see comments
            return xmlrpcs_resperror(5, 'You are not allowed to view comments for this post/Item (' . $params['item_ID'] . ').');
        }
        $filters = array('post_ID' => $Item->ID, 'types' => $params['types'], 'statuses' => $params['statuses'], 'comments' => $params['limit'], 'order' => 'DESC');
    } else {
        logIO(sprintf('Trying to get latest comments (%s)', $params['limit'] ? $params['limit'] : 'all'));
        $filters = array('types' => $params['types'], 'statuses' => $params['statuses'], 'comments' => $params['limit'], 'order' => 'DESC');
    }
    //logIO( "Filters:\n".var_export($filters, true) );
    $CommentList = new CommentList2($Blog);
    // Filter list:
    $CommentList->set_filters($filters, false);
    // Get ready for display (runs the query):
    $CommentList->display_init();
    logIO('Comments found: ' . $CommentList->result_num_rows);
    $data = array();
    if ($CommentList->result_num_rows) {
        while ($Comment =& $CommentList->get_next()) {
            // Loop through comments:
            $Comment->get_Item();
            $data[] = array('dateCreated' => new xmlrpcval(datetime_to_iso8601($Comment->date, true), 'dateTime.iso8601'), 'date_created_gmt' => new xmlrpcval(datetime_to_iso8601($Comment->date, true), 'dateTime.iso8601'), 'user_id' => new xmlrpcval(intval($Comment->author_user_ID)), 'comment_id' => new xmlrpcval($Comment->ID), 'parent' => new xmlrpcval(intval($Comment->in_reply_to_cmt_ID)), 'status' => new xmlrpcval(wp_or_b2evo_comment_status($Comment->status, 'wp')), 'content' => new xmlrpcval($Comment->content), 'link' => new xmlrpcval($Comment->get_permanent_url()), 'post_id' => new xmlrpcval($Comment->Item->ID), 'post_title' => new xmlrpcval($Comment->Item->title), 'author' => new xmlrpcval($Comment->get_author_name()), 'author_url' => new xmlrpcval($Comment->get_author_url()), 'author_email' => new xmlrpcval($Comment->get_author_email()), 'author_ip' => new xmlrpcval($Comment->author_IP), 'type' => new xmlrpcval($Comment->type == 'comment' ? '' : $Comment->type));
        }
    }
    return $data;
}
示例#24
0
 /**
  * Get the parent Item
  *
  * @return object Item
  */
 function &get_parent_Item()
 {
     if (!empty($this->parent_Item)) {
         // Return the initialized parent Item:
         return $this->parent_Item;
     }
     if (empty($this->parent_ID)) {
         // No defined parent Item
         $this->parent_Item = NULL;
         return $this->parent_Item;
     }
     if ($this->get_type_setting('use_parent') == 'never') {
         // Parent Item is not allowed for current item type
         $this->parent_Item = NULL;
         return $this->parent_Item;
     }
     $ItemCache =& get_ItemCache();
     $this->parent_Item =& $ItemCache->get_by_ID($this->parent_ID, false, false);
     return $this->parent_Item;
 }
示例#25
0
 /**
  * Get the Item this comment relates to
  *
  * @return Item
  */
 function &get_Item()
 {
     if (!isset($this->Item)) {
         $ItemCache =& get_ItemCache();
         $this->Item =& $ItemCache->get_by_ID($this->item_ID, false);
     }
     return $this->Item;
 }
示例#26
0
/**
 * Get all links where file is used
 *
 * @param integer File ID
 * @param array Params
 * @return string The links to that posts, comments and users where the file is used
 */
function get_file_links($file_ID, $params = array())
{
    global $DB, $current_User, $baseurl, $admin_url;
    $params = array_merge(array('separator' => '<br />', 'post_prefix' => T_('Post') . ' - ', 'comment_prefix' => T_('Comment on') . ' - ', 'user_prefix' => T_('Profile picture') . ' - ', 'current_link_ID' => 0, 'current_before' => '<b>', 'current_after' => '</b>'), $params);
    // Create result array
    $attached_to = array();
    // Get all links with posts and comments
    $links_SQL = new SQL();
    $links_SQL->SELECT('link_ID, link_itm_ID, link_cmt_ID, link_usr_ID');
    $links_SQL->FROM('T_links');
    $links_SQL->WHERE('link_file_ID = ' . $DB->quote($file_ID));
    $links = $DB->get_results($links_SQL->get());
    if (!empty($links)) {
        // File is linked with some posts or comments
        $ItemCache =& get_ItemCache();
        $CommentCache =& get_CommentCache();
        $UserCache =& get_UserCache();
        $LinkCache =& get_LinkCache();
        foreach ($links as $link) {
            $link_object_ID = 0;
            $r = '';
            if ($params['current_link_ID'] == $link->link_ID) {
                $r .= $params['current_before'];
            }
            if (!empty($link->link_itm_ID)) {
                // File is linked to a post
                if ($Item =& $ItemCache->get_by_ID($link->link_itm_ID, false)) {
                    $Blog = $Item->get_Blog();
                    if ($current_User->check_perm('item_post!CURSTATUS', 'view', false, $Item)) {
                        // Current user can edit the linked post
                        $r .= $params['post_prefix'] . '<a href="' . url_add_param($admin_url, 'ctrl=items&amp;blog=' . $Blog->ID . '&amp;p=' . $link->link_itm_ID) . '">' . $Item->get('title') . '</a>';
                    } else {
                        // No access to edit the linked post
                        $r .= $params['post_prefix'] . $Item->get('title');
                    }
                    $link_object_ID = $link->link_itm_ID;
                }
            } elseif (!empty($link->link_cmt_ID)) {
                // File is linked to a comment
                if ($Comment =& $CommentCache->get_by_ID($link->link_cmt_ID, false)) {
                    $Item = $Comment->get_Item();
                    if ($current_User->check_perm('comment!CURSTATUS', 'moderate', false, $Comment)) {
                        // Current user can edit the linked Comment
                        $r .= $params['comment_prefix'] . '<a href="' . url_add_param($admin_url, 'ctrl=comments&amp;action=edit&amp;comment_ID=' . $link->link_cmt_ID) . '">' . $Item->get('title') . '</a>';
                    } else {
                        // No access to edit the linked Comment
                        $r .= $params['comment_prefix'] . $Item->get('title');
                    }
                    $link_object_ID = $link->link_cmt_ID;
                }
            } elseif (!empty($link->link_usr_ID)) {
                // File is linked to user
                if ($User =& $UserCache->get_by_ID($link->link_usr_ID, false)) {
                    if ($current_User->ID != $User->ID && !$current_User->check_perm('users', 'view')) {
                        // No permission to view other users in admin form
                        $r .= $params['user_prefix'] . '<a href="' . url_add_param($baseurl, 'disp=user&amp;user_ID=' . $User->ID) . '">' . $User->login . '</a>';
                    } else {
                        // Build a link to display a user in admin form
                        $r .= $params['user_prefix'] . '<a href="?ctrl=user&amp;user_tab=profile&amp;user_ID=' . $User->ID . '">' . $User->login . '</a>';
                    }
                    $link_object_ID = $link->link_usr_ID;
                }
            }
            if (!empty($link_object_ID)) {
                // Action icon to unlink file from object
                if (($edited_Link =& $LinkCache->get_by_ID($link->link_ID, false, false)) !== false && ($LinkOwner =& $edited_Link->get_LinkOwner()) !== false && $LinkOwner->check_perm('edit', false)) {
                    // Allow to unlink only if current user has an permission
                    $r .= ' ' . action_icon(T_('Delete this link!'), 'unlink', $admin_url . '?ctrl=links&amp;link_ID=' . $link->link_ID . '&amp;link_type=item&amp;link_object_ID=' . $link->link_usr_ID . '&amp;action=unlink&amp;redirect_to=' . rawurlencode(regenerate_url('blog', '', '', '&')) . '&amp;' . url_crumb('link'), NULL, NULL, NULL, array('onclick' => 'return confirm(\'' . TS_('Are you sure want to unlink this file?') . '\');'));
                }
            }
            if ($params['current_link_ID'] == $link->link_ID) {
                $r .= $params['current_after'];
            }
            if (!empty($r)) {
                $attached_to[] = $r;
            }
        }
    }
    return implode($params['separator'], $attached_to);
}
示例#27
0
/**
 * Get name of cron job
 *
 * @param string Job key
 * @param string Job name
 * @param string|array Job params
 * @return string Default value of job name of Name from DB
 */
function cron_job_name($job_key, $job_name = '', $job_params = '')
{
    if (empty($job_name)) {
        // Get default name by key
        $job_name = get_cron_jobs_config('name', $job_key);
    }
    $job_params = is_string($job_params) ? unserialize($job_params) : $job_params;
    if (!empty($job_params)) {
        // Prepare job name with the specified params
        switch ($job_key) {
            case 'send-post-notifications':
                // Add item title to job name
                if (!empty($job_params['item_ID'])) {
                    $ItemCache =& get_ItemCache();
                    if ($Item = $ItemCache->get_by_ID($job_params['item_ID'], false, false)) {
                        $job_name = sprintf($job_name, $Item->get('title'));
                    }
                }
                break;
            case 'send-comment-notifications':
                // Add item title of the comment to job name
                if (!empty($job_params['comment_ID'])) {
                    $CommentCache =& get_CommentCache();
                    if ($Comment =& $CommentCache->get_by_ID($job_params['comment_ID'], false, false)) {
                        if ($Item = $Comment->get_Item()) {
                            $job_name = sprintf($job_name, $Item->get('title'));
                        }
                    }
                }
                break;
        }
    }
    return $job_name;
}
示例#28
0
 /**
  * Parse anchor links, Set absolute path for each link with relative anchor like <a href="#">
  *
  * @param string Content
  * @return string Content
  */
 function parse_anchor_links($content)
 {
     if (preg_match_all('/ href="#(c|p)([0-9]+)"/i', $content, $matches)) {
         $CommentCache =& get_CommentCache();
         $ItemCache =& get_ItemCache();
         foreach ($matches[0] as $m => $full_match) {
             $object_ID = $matches[2][$m];
             $new_url = '';
             switch ($matches[1][$m]) {
                 // Object type:
                 case 'p':
                     // Item
                     if ($Item =& $ItemCache->get_by_ID($object_ID, false, false)) {
                         // Replace anchor url with item permanent url
                         $new_url = $Item->get_permanent_url() . '#p' . $object_ID;
                     }
                     break;
                 case 'c':
                     // Comment
                     if ($Comment =& $CommentCache->get_by_ID($object_ID, false, false)) {
                         // Replace anchor url with comment permanent url
                         $new_url = $Comment->get_permanent_url();
                     }
                     break;
                 default:
                     // Incorrect object type, Skip this url
                     continue;
             }
             if (!empty($new_url)) {
                 // Replace relative anchor url with new absolute url
                 $content = str_replace($full_match, ' href="' . $new_url . '"', $content);
             }
         }
     }
     return $content;
 }
 function CommentFormSent(&$params)
 {
     $ItemCache =& get_ItemCache();
     $comment_Item =& $ItemCache->get_by_ID($params['comment_post_ID'], false);
     if (!$comment_Item) {
         // Incorrect item
         return false;
     }
     $item_Blog =& $comment_Item->get_Blog();
     if ($this->get_coll_setting('coll_apply_comment_rendering', $item_Blog)) {
         // render code blocks in comment
         $params['content'] =& $params['comment'];
         $this->FilterItemContents($params);
         if (empty($params['dont_remove_pre']) || !$params['dont_remove_pre']) {
             // remove <pre>
             $params['comment'] = preg_replace('#(<\\!--\\s*codeblock[^-]*?\\s*-->)<pre[^>]*><code>(.+?)</code></pre>(<\\!--\\s+/codeblock\\s*-->)#is', '$1<code>$2</code>$3', $params['comment']);
         }
     }
 }
示例#30
0
function search_result_block($params = array())
{
    global $Blog, $Session, $debug;
    $search_keywords = param('s', 'string', '', true);
    // Try to load existing search results from Session:
    $search_params = $Session->get('search_params');
    $search_result = $Session->get('search_result');
    $search_result_loaded = false;
    if (empty($search_params) || $search_params['search_keywords'] != $search_keywords || $search_params['search_blog'] != $Blog->ID || $search_result === NULL) {
        // We need to perform a new search:
        if ($debug) {
            echo '<p class="text-muted">Starting a new search...</p>';
        }
        // Flush first part of the page before starting search, which can be long...
        evo_flush();
        $search_params = array('search_keywords' => $search_keywords, 'search_blog' => $Blog->ID);
        // Perform new search:
        $search_result = perform_scored_search($search_keywords);
        // Save results into session:
        $Session->set('search_params', $search_params);
        $Session->set('search_result', $search_result);
        $search_result_loaded = true;
    } else {
        // We found the desired saved search results in the Session:
        if ($debug) {
            // Display counts
            echo '<div class="text-muted">';
            echo '<p>We found the desired saved search results in the Session:</p>';
            echo '<ul><li>' . sprintf('%d posts', $search_result[0]['nr_of_items']) . '</li>';
            echo '<li>' . sprintf('%d comments', $search_result[0]['nr_of_comments']) . '</li>';
            echo '<li>' . sprintf('%d chapters', $search_result[0]['nr_of_cats']) . '</li>';
            echo '<li>' . sprintf('%d tags', $search_result[0]['nr_of_tags']) . '</li></ul>';
            echo '</div>';
        }
        // Flush first part of the page before starting search, which can be long...
        evo_flush();
    }
    // Make sure we are not missing any display params:
    $params = array_merge(array('no_match_message' => '<p class="alert alert-info msg_nothing" style="margin: 2em 0">' . T_('Sorry, we could not find anything matching your request, please try to broaden your search.') . '<p>', 'title_suffix_post' => ' (' . T_('Post') . ')', 'title_suffix_comment' => ' (' . T_('Comment') . ')', 'title_suffix_category' => ' (' . T_('Category') . ')', 'title_suffix_tag' => ' (' . T_('Tag') . ')', 'block_start' => '', 'block_end' => '', 'pagination' => array(), 'use_editor' => false, 'author_format' => 'avatar_name', 'date_format' => locale_datefmt()), $params);
    $search_result = $Session->get('search_result');
    if (empty($search_result)) {
        echo $params['no_match_message'];
        return;
    }
    // Prepare pagination:
    $result_count = count($search_result);
    $result_per_page = $Blog->get_setting('search_per_page');
    if ($result_count > $result_per_page) {
        // We will have multiple search result pages:
        $current_page = param('page', 'integer', 1);
        $total_pages = ceil($result_count / $result_per_page);
        if ($current_page > $total_pages) {
            $current_page = $total_pages;
        }
        $page_params = array_merge(array('total' => $result_count, 'current_page' => $current_page, 'total_pages' => $total_pages, 'list_span' => 11), $params['pagination']);
        search_page_links($page_params);
    } else {
        // Only one page of results:
        $current_page = 1;
        $total_pages = 1;
    }
    // Set current page indexes:
    $from = ($current_page - 1) * $result_per_page;
    $to = $current_page < $total_pages ? $from + $result_per_page : $result_count;
    // Init caches
    $ItemCache =& get_ItemCache();
    $CommentCache =& get_CommentCache();
    $ChapterCache =& get_ChapterCache();
    if (!$search_result_loaded) {
        // Search result objects are not loaded into memory yet, load them
        // Group required object ids by type:
        $required_ids = array();
        for ($index = $from; $index < $to; $index++) {
            $row = $search_result[$index];
            if (isset($required_ids[$row['type']])) {
                $required_ids[$row['type']][] = $row['ID'];
            } else {
                $required_ids[$row['type']] = array($row['ID']);
            }
        }
        // Load each required object into the corresponding cache:
        foreach ($required_ids as $type => $object_ids) {
            switch ($type) {
                case 'item':
                    $ItemCache->load_list($object_ids);
                    break;
                case 'comment':
                    $CommentCache->load_list($object_ids);
                    break;
                case 'category':
                    $ChapterCache->load_list($object_ids);
                    break;
                    // TODO: we'll probably load "tag" objects once we support tag-synonyms.
                // TODO: we'll probably load "tag" objects once we support tag-synonyms.
                default:
                    // Not handled search result type
                    break;
            }
        }
    }
    // ----------- Display ------------
    echo $params['block_start'];
    // Memorize best scores:
    $max_percentage = $search_result[0]['percentage'];
    $max_score = $search_result[0]['score'];
    // Display results for current page:
    for ($index = $from; $index < $to; $index++) {
        $row = $search_result[$index];
        switch ($row['type']) {
            case 'item':
                // Prepare to display an Item:
                $Item = $ItemCache->get_by_ID($row['ID'], false);
                if (empty($Item)) {
                    // This Item was deleted, since the search process was executed
                    continue 2;
                    // skip from switch and skip to the next item in loop
                }
                $display_params = array('title' => $Item->get_title(array('link_type' => 'permalink')) . $params['title_suffix_post'], 'excerpt' => $Item->get_excerpt2(), 'chapter' => sprintf(T_('In %s'), $Item->get_chapter_links()));
                if ($params['use_editor']) {
                    // Get editor info to display:
                    $lastedit_User =& $Item->get_lastedit_User();
                    if (empty($lastedit_User)) {
                        // If editor is not defined yet then use author
                        $lastedit_User =& $Item->get_creator_User();
                    }
                    $display_params = array_merge(array('editor' => $lastedit_User->get_identity_link(array('link_text' => $params['author_format'])), 'lastedit_date' => mysql2date($params['date_format'], empty($Item->datemodified) ? $Item->datecreated : $Item->datemodified)), $display_params);
                } else {
                    // Get author info to display:
                    $creator_User =& $Item->get_creator_User();
                    $display_params = array_merge(array('author' => $creator_User->get_identity_link(array('link_text' => $params['author_format'])), 'creation_date' => mysql2date($params['date_format'], $Item->datecreated), 'lastedit_date' => mysql2date($params['date_format'], $Item->datemodified)), $display_params);
                }
                break;
            case 'comment':
                // Prepare to display a Comment:
                $Comment = $CommentCache->get_by_ID($row['ID'], false);
                if (empty($Comment) || $Comment->status == 'trash') {
                    // This Comment was deleted, since the search process was executed
                    continue 2;
                    // skip from switch and skip to the next item in loop
                }
                $display_params = array('title' => $Comment->get_permanent_link('#item#') . $params['title_suffix_comment'], 'excerpt' => excerpt($Comment->content), 'author' => $Comment->get_author(array('link_text' => $params['author_format'], 'thumb_size' => 'crop-top-15x15', 'thumb_class' => 'avatar_before_login')), 'creation_date' => mysql2date($params['date_format'], $Comment->date));
                break;
            case 'category':
                // Prepare to display a Category:
                $Chapter = $ChapterCache->get_by_ID($row['ID'], false);
                if (empty($Chapter)) {
                    // This Chapter was deleted, since the search process was executed
                    continue 2;
                    // skip from switch and skip to the next item in loop
                }
                $display_params = array('title' => '<a href="' . $Chapter->get_permanent_url() . '">' . $Chapter->get_name() . '</a>' . $params['title_suffix_category'], 'excerpt' => excerpt($Chapter->get('description')));
                break;
            case 'tag':
                // Prepare to display a Tag:
                list($tag_name, $post_count) = explode(':', $row['ID']);
                $display_params = array('title' => '<a href="' . url_add_param($Blog->gen_blogurl(), 'tag=' . $tag_name) . '">' . $tag_name . '</a>' . $params['title_suffix_tag'], 'excerpt' => sprintf(T_('%d posts are tagged with \'%s\''), $post_count, $tag_name));
                break;
            default:
                // Other type of result is not implemented
                // TODO: maybe find collections (especially in case of aggregation)? users? files?
                continue 2;
        }
        // Common display params for all types:
        $display_params['score'] = $row['score'];
        $display_params['percentage'] = isset($row['percentage']) ? $row['percentage'] : round($row['score'] * $max_percentage / $max_score);
        $display_params['scores_map'] = $row['scores_map'];
        $display_params['type'] = $row['type'];
        $display_params['best_result'] = $index == 0;
        $display_params['max_score'] = sprintf(floor($max_score) != $max_score ? '%.2f' : '%d', $max_score);
        $display_params['max_percentage'] = $max_percentage;
        // Display one search result:
        display_search_result(array_merge($params, $display_params));
    }
    echo $params['block_end'];
    // Display pagination:
    if ($result_count > $result_per_page) {
        search_page_links($page_params);
    }
}