/** * Initialize internal states for the most common skin displays. * * For more specific skins, this function may not be called and * equivalent code may be customized within the skin. * * @param string What are we going to display. Most of the time the global $disp should be passed. */ function skin_init($disp) { /** * @var Blog */ global $Blog; /** * @var Item */ global $Item; /** * @var Skin */ global $Skin; global $robots_index; global $seo_page_type; global $redir, $ReqURL, $ReqURI, $m, $w, $preview; global $Chapter; global $Debuglog; /** * @var ItemList2 */ global $MainList; /** * This will give more detail when $disp == 'posts'; otherwise it will have the same content as $disp * @var string */ global $disp_detail, $Settings; global $Timer; global $Messages, $PageCache; global $Session, $current_User; $Timer->resume('skin_init'); if (empty($disp_detail)) { $disp_detail = $disp; } $Debuglog->add('skin_init: $disp=' . $disp, 'skins'); // This is the main template; it may be used to display very different things. // Do inits depending on current $disp: switch ($disp) { case 'front': case 'posts': case 'single': case 'page': case 'terms': case 'download': case 'feedback-popup': // We need to load posts for this display: if ($disp == 'terms') { // Initialize the redirect param to know what page redirect after accepting of terms: param('redirect_to', 'url', ''); } // Note: even if we request the same post as $Item above, the following will do more restrictions (dates, etc.) // Init the MainList object: init_MainList($Blog->get_setting('posts_per_page')); // Init post navigation $post_navigation = $Skin->get_post_navigation(); if (empty($post_navigation)) { $post_navigation = $Blog->get_setting('post_navigation'); } if (!empty($MainList) && $MainList->single_post && ($single_Item =& mainlist_get_item())) { // If we are currently viewing a single post // We assume the current user will have read the entire post and all its current comments: $single_Item->update_read_timestamps(true, true); // Restart the items list: $MainList->restart(); } break; case 'search': // Searching post, comments and categories load_funcs('collections/_search.funcs.php'); // Check previous search keywords so it can be displayed in the search input box param('s', 'string', '', true); break; } // SEO stuff & redirects if necessary: $seo_page_type = NULL; switch ($disp) { // CONTENT PAGES: case 'single': case 'page': case 'terms': if ($disp == 'terms' && !$Item) { // Wrong post ID for terms page: global $disp; $disp = '404'; $Messages->add(sprintf(T_('Terms not found. (post ID #%s)'), get_param('p')), 'error'); break; } if (!$preview && empty($Item)) { // No Item, incorrect request and incorrect state of the application, a 404 redirect should have already happened //debug_die( 'Invalid page URL!' ); } if ($disp == 'single') { $seo_page_type = 'Single post page'; } else { $seo_page_type = '"Page" page'; } if (!$preview) { // Check if item has a goal to insert a hit into DB $Item->check_goal(); } // Check if the post has 'redirected' status: if (!$preview && $Item->status == 'redirected' && $redir == 'yes') { // $redir=no here allows to force a 'single post' URL for commenting // Redirect to the URL specified in the post: $Debuglog->add('Redirecting to post URL [' . $Item->url . '].'); header_redirect($Item->url, true, true); } // Check if we want to redirect to a canonical URL for the post // Please document encountered problems. if (!$preview && ($Blog->get_setting('canonical_item_urls') && $redir == 'yes' || $Blog->get_setting('relcanonical_item_urls'))) { // We want to redirect to the Item's canonical URL: $canonical_url = $Item->get_permanent_url('', '', '&'); if (preg_match('|[&?](page=\\d+)|', $ReqURI, $page_param)) { // A certain post page has been requested, keep only this param and discard all others: $canonical_url = url_add_param($canonical_url, $page_param[1], '&'); } if (preg_match('|[&?](mode=quote&[qcp]+=\\d+)|', $ReqURI, $page_param)) { // A quote of comment/post, keep only these params and discard all others: $canonical_url = url_add_param($canonical_url, $page_param[1], '&'); } if (!is_same_url($ReqURL, $canonical_url)) { // The requested URL does not look like the canonical URL for this post... // url difference was resolved $url_resolved = false; // Check if the difference is because of an allowed post navigation param if (preg_match('|[&?]cat=(\\d+)|', $ReqURI, $cat_param)) { // A category post navigation param is set $extended_url = ''; if ($post_navigation == 'same_category' && isset($cat_param[1])) { // navigatie through posts from the same category $category_ids = postcats_get_byID($Item->ID); if (in_array($cat_param[1], $category_ids)) { // cat param is one of this Item categories $extended_url = $Item->add_navigation_param($canonical_url, $post_navigation, $cat_param[1], '&'); // Set MainList navigation target to the requested category $MainList->nav_target = $cat_param[1]; } } $url_resolved = is_same_url($ReqURL, $extended_url); } if (preg_match('|[&?]tag=([^&A-Z]+)|', $ReqURI, $tag_param)) { // A tag post navigation param is set $extended_url = ''; if ($post_navigation == 'same_tag' && isset($tag_param[1])) { // navigatie through posts from the same tag $tag_names = $Item->get_tags(); if (in_array($tag_param[1], $tag_names)) { // tag param is one of this Item tags $extended_url = $Item->add_navigation_param($canonical_url, $post_navigation, $tag_param[1], '&'); // Set MainList navigation target to the requested tag $MainList->nav_target = $tag_param[1]; } } $url_resolved = is_same_url($ReqURL, $extended_url); } if (!$url_resolved && $Blog->get_setting('canonical_item_urls') && $redir == 'yes' && !$Item->check_cross_post_nav('auto', $Blog->ID)) { // REDIRECT TO THE CANONICAL URL: $Debuglog->add('Redirecting to canonical URL [' . $canonical_url . '].'); header_redirect($canonical_url, true); } else { // Use rel="canoncial": add_headline('<link rel="canonical" href="' . $canonical_url . '" />'); } // EXITED. } } if (!$MainList->result_num_rows) { // There is nothing to display for this page, don't index it! $robots_index = false; } break; case 'download': if (empty($Item)) { // No Item, incorrect request and incorrect state of the application, a 404 redirect should have already happened debug_die('Invalid page URL!'); } $download_link_ID = param('download', 'integer', 0); // Check if we can allow to download the selected file $LinkCache =& get_LinkCache(); if (!(($download_Link =& $LinkCache->get_by_ID($download_link_ID, false, false)) && ($LinkItem =& $download_Link->get_LinkOwner()) && ($LinkItem->Item && $LinkItem->Item->ID == $Item->ID) && ($download_File =& $download_Link->get_File()) && $download_File->exists())) { // Bad request, Redirect to Item permanent url $Messages->add(T_('The requested file is not available for download.'), 'error'); $canonical_url = $Item->get_permanent_url('', '', '&'); $Debuglog->add('Redirecting to canonical URL [' . $canonical_url . '].'); header_redirect($canonical_url, true); } // Save the downloading Link to the global vars $GLOBALS['download_Link'] =& $download_Link; // Save global $Item to $download_Item, because $Item can be rewritten by function get_featured_Item() in some skins $GLOBALS['download_Item'] =& $Item; init_ajax_forms('blog'); // auto requires jQuery // Initialize JavaScript to download file after X seconds add_js_headline(' jQuery( document ).ready( function () { jQuery( "#download_timer_js" ).show(); } ); var b2evo_download_timer = ' . intval($Blog->get_setting('download_delay')) . '; var downloadInterval = setInterval( function() { jQuery( "#download_timer" ).html( b2evo_download_timer ); if( b2evo_download_timer == 0 ) { // Stop timer and download a file clearInterval( downloadInterval ); jQuery( "#download_help_url" ).show(); } b2evo_download_timer--; }, 1000 );'); // Use meta tag to download file when JavaScript is NOT enabled add_headline('<meta http-equiv="refresh" content="' . intval($Blog->get_setting('download_delay')) . '; url=' . $download_Link->get_download_url(array('type' => 'action')) . '" />'); $seo_page_type = 'Download page'; if ($Blog->get_setting($disp . '_noindex')) { // We prefer robots not to index these pages: $robots_index = false; } break; case 'posts': init_ajax_forms('blog'); // auto requires jQuery // fp> if we add this here, we have to exetnd the inner if() // init_ratings_js( 'blog' ); // Get list of active filters: $active_filters = $MainList->get_active_filters(); if (!empty($active_filters)) { // The current page is being filtered... if (array_diff($active_filters, array('page')) == array()) { // This is just a follow "paged" page $disp_detail = 'posts-next'; $seo_page_type = 'Next page'; if ($Blog->get_setting('paged_noindex')) { // We prefer robots not to index category pages: $robots_index = false; } } elseif (array_diff($active_filters, array('cat_array', 'cat_modifier', 'cat_focus', 'posts', 'page')) == array()) { // This is a category page $disp_detail = 'posts-cat'; $seo_page_type = 'Category page'; if ($Blog->get_setting('chapter_noindex')) { // We prefer robots not to index category pages: $robots_index = false; } global $cat, $catsel; if (empty($catsel) && preg_match('~^[0-9]+$~', $cat)) { // We are on a single cat page: // NOTE: we must have selected EXACTLY ONE CATEGORY through the cat parameter // BUT: - this can resolve to including children // - selecting exactly one cat through catsel[] is NOT OK since not equivalent (will exclude children) // echo 'SINGLE CAT PAGE'; if ($Blog->get_setting('canonical_cat_urls') && $redir == 'yes' || $Blog->get_setting('relcanonical_cat_urls')) { // Check if the URL was canonical: if (!isset($Chapter)) { $ChapterCache =& get_ChapterCache(); /** * @var Chapter */ $Chapter =& $ChapterCache->get_by_ID($MainList->filters['cat_array'][0], false); } if ($Chapter) { if ($Chapter->parent_ID) { // This is a sub-category page (i-e: not a level 1 category) $disp_detail = 'posts-subcat'; } $canonical_url = $Chapter->get_permanent_url(NULL, NULL, $MainList->get_active_filter('page'), NULL, '&'); if (!is_same_url($ReqURL, $canonical_url)) { // fp> TODO: we're going to lose the additional params, it would be better to keep them... // fp> what additional params actually? if ($Blog->get_setting('canonical_cat_urls') && $redir == 'yes') { // REDIRECT TO THE CANONICAL URL: header_redirect($canonical_url, true); } else { // Use rel="canonical": add_headline('<link rel="canonical" href="' . $canonical_url . '" />'); } } } else { // If the requested chapter was not found display 404 page $Messages->add(T_('The requested chapter was not found')); global $disp; $disp = '404'; break; } } if ($post_navigation == 'same_category') { // Category is set and post navigation should go through the same category, set navigation target param $MainList->nav_target = $cat; } } } elseif (array_diff($active_filters, array('tags', 'posts', 'page')) == array()) { // This is a tag page $disp_detail = 'posts-tag'; $seo_page_type = 'Tag page'; if ($Blog->get_setting('tag_noindex')) { // We prefer robots not to index tag pages: $robots_index = false; } if ($Blog->get_setting('canonical_tag_urls') && $redir == 'yes' || $Blog->get_setting('relcanonical_tag_urls')) { // Check if the URL was canonical: $canonical_url = $Blog->gen_tag_url($MainList->get_active_filter('tags'), $MainList->get_active_filter('page'), '&'); if (!is_same_url($ReqURL, $canonical_url)) { if ($Blog->get_setting('canonical_tag_urls') && $redir == 'yes') { // REDIRECT TO THE CANONICAL URL: header_redirect($canonical_url, true); } else { // Use rel="canoncial": add_headline('<link rel="canonical" href="' . $canonical_url . '" />'); } } } $tag = $MainList->get_active_filter('tags'); if ($post_navigation == 'same_tag' && !empty($tag)) { // Tag is set and post navigation should go through the same tag, set navigation target param $MainList->nav_target = $tag; } } elseif (array_diff($active_filters, array('ymdhms', 'week', 'posts', 'page')) == array()) { // This is an archive page // echo 'archive page'; $disp_detail = 'posts-date'; $seo_page_type = 'Date archive page'; if ($Blog->get_setting('canonical_archive_urls') && $redir == 'yes' || $Blog->get_setting('relcanonical_archive_urls')) { // Check if the URL was canonical: $canonical_url = $Blog->gen_archive_url(substr($m, 0, 4), substr($m, 4, 2), substr($m, 6, 2), $w, '&', $MainList->get_active_filter('page')); if (!is_same_url($ReqURL, $canonical_url)) { if ($Blog->get_setting('canonical_archive_urls') && $redir == 'yes') { // REDIRECT TO THE CANONICAL URL: header_redirect($canonical_url, true); } else { // Use rel="canoncial": add_headline('<link rel="canonical" href="' . $canonical_url . '" />'); } } } if ($Blog->get_setting('archive_noindex')) { // We prefer robots not to index archive pages: $robots_index = false; } } else { // Other filtered pages: // pre_dump( $active_filters ); $disp_detail = 'posts-filtered'; $seo_page_type = 'Other filtered page'; if ($Blog->get_setting('filtered_noindex')) { // We prefer robots not to index other filtered pages: $robots_index = false; } } } elseif ($Blog->get_setting('front_disp') == 'posts') { // This is the default blog page only if the 'front_disp' is set to 'posts' $disp_detail = 'posts-default'; $seo_page_type = 'Default page'; if ($Blog->get_setting('default_noindex')) { // We prefer robots not to index archive pages: $robots_index = false; } } break; case 'search': $seo_page_type = 'Search page'; if ($Blog->get_setting('filtered_noindex')) { // We prefer robots not to index these pages: $robots_index = false; } break; // SPECIAL FEATURE PAGES: // SPECIAL FEATURE PAGES: case 'feedback-popup': $seo_page_type = 'Comment popup'; if ($Blog->get_setting($disp . '_noindex')) { // We prefer robots not to index these pages: $robots_index = false; } break; case 'arcdir': $seo_page_type = 'Date archive directory'; if ($Blog->get_setting($disp . '_noindex')) { // We prefer robots not to index these pages: $robots_index = false; } break; case 'catdir': $seo_page_type = 'Category directory'; if ($Blog->get_setting($disp . '_noindex')) { // We prefer robots not to index these pages: $robots_index = false; } break; case 'msgform': global $disp; // get expected message form type $msg_type = param('msg_type', 'string', ''); // initialize $recipient_User = NULL; $Comment = NULL; $allow_msgform = NULL; // get possible params $recipient_id = param('recipient_id', 'integer', 0, true); $comment_id = param('comment_id', 'integer', 0, true); $post_id = param('post_id', 'integer', 0, true); $subject = param('subject', 'string', ''); // try to init recipient_User if (!empty($recipient_id)) { $UserCache =& get_UserCache(); $recipient_User =& $UserCache->get_by_ID($recipient_id); } elseif (!empty($comment_id)) { // comment id is set, try to get comment author user $CommentCache =& get_CommentCache(); $Comment = $CommentCache->get_by_ID($comment_id, false); if ($Comment = $CommentCache->get_by_ID($comment_id, false)) { $recipient_User =& $Comment->get_author_User(); if (empty($recipient_User) && $Comment->allow_msgform && is_email($Comment->get_author_email())) { // set allow message form to email because comment author (not registered) accepts email $allow_msgform = 'email'; param('recipient_address', 'string', $Comment->get_author_email()); param('recipient_name', 'string', $Comment->get_author_name()); } } } else { // Recipient was not defined, try set the blog owner as recipient global $Blog; if (empty($Blog)) { // Blog is not set, this is an invalid request debug_die('Invalid send message request!'); } $recipient_User = $Blog->get_owner_User(); } if ($recipient_User) { // recipient User is set // get_msgform_possibility returns NULL (false), only if there is no messaging option between current_User and recipient user $allow_msgform = $recipient_User->get_msgform_possibility(); if ($msg_type == 'email' && $recipient_User->get_msgform_possibility(NULL, 'email') != 'email') { // User doesn't want to receive email messages, Restrict if this was requested by wrong url: $msg_type = ''; } if ($allow_msgform == 'login') { // user must login first to be able to send a message to this User $disp = 'login'; param('action', 'string', 'req_login'); // override redirect to param param('redirect_to', 'url', regenerate_url(), true, true); if (($msg_Blog =& get_setting_Blog('msg_blog_ID')) && $Blog->ID != $msg_Blog->ID) { // Redirect to special blog for messaging actions if it is defined in general settings header_redirect(url_add_param($msg_Blog->get('msgformurl', array('glue' => '&')), 'redirect_to=' . rawurlencode($redirect_to), '&')); } $Messages->add(T_('You must log in before you can contact this user')); } elseif ($allow_msgform == 'PM' && check_user_status('can_be_validated')) { // user is not activated if ($recipient_User->accepts_email()) { // recipient User accepts email allow to send email $allow_msgform = 'email'; $msg_type = 'email'; $activateinfo_link = 'href="' . get_activate_info_url(NULL, '&') . '"'; $Messages->add(sprintf(T_('You must activate your account before you can send a private message to %s. However you can send them an email if you\'d like. <a %s>More info »</a>'), $recipient_User->get('login'), $activateinfo_link), 'warning'); } else { // Redirect to the activate info page for not activated users $Messages->add(T_('You must activate your account before you can contact a user. <b>See below:</b>')); header_redirect(get_activate_info_url(), 302); // will have exited } } elseif ($msg_type == 'PM' && $allow_msgform == 'email') { // only email is allowed but user expect private message form if (!empty($current_User) && $recipient_id == $current_User->ID) { $Messages->add(T_('You cannot send a private message to yourself. However you can send yourself an email if you\'d like.'), 'warning'); } else { $Messages->add(sprintf(T_('You cannot send a private message to %s. However you can send them an email if you\'d like.'), $recipient_User->get('login')), 'warning'); } } elseif ($msg_type != 'email' && $allow_msgform == 'PM') { // private message form should be displayed, change display to create new individual thread with the given recipient user // check if creating new PM is allowed if (check_create_thread_limit(true)) { // thread limit reached header_redirect(); // exited here } global $edited_Thread, $edited_Message, $recipients_selected; // Load classes load_class('messaging/model/_thread.class.php', 'Thread'); load_class('messaging/model/_message.class.php', 'Message'); // Set global variable to auto define the FB autocomplete plugin field $recipients_selected = array(array('id' => $recipient_User->ID, 'title' => $recipient_User->login)); init_tokeninput_js('blog'); $disp = 'threads'; $edited_Thread = new Thread(); $edited_Message = new Message(); $edited_Message->Thread =& $edited_Thread; $edited_Thread->recipients = $recipient_User->login; param('action', 'string', 'new', true); param('thrdtype', 'string', 'individual', true); } if ($allow_msgform == 'email') { // set recippient user param set_param('recipient_id', $recipient_User->ID); } } if ($allow_msgform == NULL) { // should be Prevented by UI if (!empty($recipient_User)) { $Messages->add(sprintf(T_('The user "%s" does not want to be contacted through the message form.'), $recipient_User->get('login')), 'error'); } elseif (!empty($Comment)) { $Messages->add(T_('This commentator does not want to get contacted through the message form.'), 'error'); } $blogurl = $Blog->gen_blogurl(); // If it was a front page request or the front page is set to 'msgform' then we must not redirect to the front page because it is forbidden for the current User $redirect_to = is_front_page() || $Blog->get_setting('front_disp') == 'msgform' ? url_add_param($blogurl, 'disp=403', '&') : $blogurl; header_redirect($redirect_to, 302); // exited here } if ($allow_msgform == 'PM' || $allow_msgform == 'email') { // Some message form is available // Get the suggested subject for the email: if (empty($subject)) { // no subject provided by param: global $DB; if (!empty($comment_id)) { // fp>TODO there should be NO SQL in this file. Make a $ItemCache->get_by_comment_ID(). $row = $DB->get_row(' SELECT post_title FROM T_items__item, T_comments WHERE comment_ID = ' . $DB->quote($comment_id) . ' AND post_ID = comment_item_ID'); if ($row) { $subject = T_('Re:') . ' ' . sprintf(T_('Comment on %s'), $row->post_title); } } if (empty($subject) && !empty($post_id)) { // fp>TODO there should be NO SQL in this file. Use $ItemCache->get_by_ID. $row = $DB->get_row(' SELECT post_title FROM T_items__item WHERE post_ID = ' . $post_id); if ($row) { $subject = T_('Re:') . ' ' . $row->post_title; } } } if ($allow_msgform == 'PM' && isset($edited_Thread)) { $edited_Thread->title = $subject; } else { param('subject', 'string', $subject, true); } } if (($msg_Blog =& get_setting_Blog('msg_blog_ID')) && $Blog->ID != $msg_Blog->ID) { // Redirect to special blog for messaging actions if it is defined in general settings header_redirect($msg_Blog->get('msgformurl', array('glue' => '&'))); } $seo_page_type = 'Contact form'; if ($Blog->get_setting($disp . '_noindex')) { // We prefer robots not to index these pages: $robots_index = false; } break; case 'messages': case 'contacts': case 'threads': switch ($disp) { case 'messages': // Actions ONLY for disp=messages // fp> The correct place to get thrd_ID is here, because we want it in redirect_to in case we need to ask for login. $thrd_ID = param('thrd_ID', 'integer', '', true); if (!is_logged_in()) { // Redirect to the login page for anonymous users $Messages->add(T_('You must log in to read your messages.')); header_redirect(get_login_url('cannot see messages'), 302); // will have exited } // check if user status allow to view messages if (!$current_User->check_status('can_view_messages')) { // user status does not allow to view messages if ($current_User->check_status('can_be_validated')) { // user is logged in but his/her account is not activate yet $Messages->add(T_('You must activate your account before you can read & send messages. <b>See below:</b>')); header_redirect(get_activate_info_url(), 302); // will have exited } $Messages->add('You are not allowed to view Messages!'); header_redirect($Blog->gen_blogurl(), 302); // will have exited } // check if user permissions allow to view messages if (!$current_User->check_perm('perm_messaging', 'reply')) { // Redirect to the blog url for users without messaging permission $Messages->add('You are not allowed to view Messages!'); header_redirect($Blog->gen_blogurl(), 302); // will have exited } if (!empty($thrd_ID)) { // if this thread exists and current user is part of this thread update status because won't be any unread messages on this conversation // we need to mark this early to make sure the unread message count will be correct in the evobar mark_as_read_by_user($thrd_ID, $current_User->ID); } if (($unsaved_message_params = get_message_params_from_session()) !== NULL) { // set Message and Thread saved params from Session global $edited_Message, $action; load_class('messaging/model/_message.class.php', 'Message'); $edited_Message = new Message(); $edited_Message->text = $unsaved_message_params['message']; $edited_Message->original_text = $unsaved_message_params['message_original']; $edited_Message->set_renderers($unsaved_message_params['renderers']); $edited_Message->thread_ID = $thrd_ID; $action = $unsaved_message_params['action']; } break; case 'contacts': // Actions ONLY for disp=contacts if (!is_logged_in()) { // Redirect to the login page for anonymous users $Messages->add(T_('You must log in to manage your contacts.')); header_redirect(get_login_url('cannot see contacts'), 302); // will have exited } if (!$current_User->check_status('can_view_contacts')) { // user is logged in, but his status doesn't allow to view contacts if ($current_User->check_status('can_be_validated')) { // user is logged in but his/her account was not activated yet // Redirect to the account activation page $Messages->add(T_('You must activate your account before you can manage your contacts. <b>See below:</b>')); header_redirect(get_activate_info_url(), 302); // will have exited } // Redirect to the blog url for users without messaging permission $Messages->add('You are not allowed to view Contacts!'); $blogurl = $Blog->gen_blogurl(); // If it was a front page request or the front page is set to display 'contacts' then we must not redirect to the front page because it is forbidden for the current User $redirect_to = is_front_page() || $Blog->get_setting('front_disp') == 'contacts' ? url_add_param($blogurl, 'disp=403', '&') : $blogurl; header_redirect($redirect_to, 302); } if (has_cross_country_restriction('any') && empty($current_User->ctry_ID)) { // User may browse/contact other users only from the same country $Messages->add(T_('Please specify your country before attempting to contact other users.')); header_redirect(get_user_profile_url()); } // Get action parameter from request: $action = param_action(); if (!$current_User->check_perm('perm_messaging', 'reply')) { // Redirect to the blog url for users without messaging permission $Messages->add('You are not allowed to view Contacts!'); $blogurl = $Blog->gen_blogurl(); // If it was a front page request or the front page is set to display 'contacts' then we must not redirect to the front page because it is forbidden for the current User $redirect_to = is_front_page() || $Blog->get_setting('front_disp') == 'contacts' ? url_add_param($blogurl, 'disp=403', '&') : $blogurl; header_redirect($redirect_to, 302); // will have exited } switch ($action) { case 'add_user': // Add user to contacts list // Check that this action request is not a CSRF hacked request: $Session->assert_received_crumb('messaging_contacts'); $user_ID = param('user_ID', 'integer', 0); if ($user_ID > 0) { // Add user to contacts if (create_contacts_user($user_ID)) { // Add user to the group $group_ID = param('group_ID', 'string', ''); if ($result = create_contacts_group_users($group_ID, $user_ID, 'group_ID_combo')) { // User has been added to the group $Messages->add(sprintf(T_('User has been added to the «%s» group.'), $result['group_name']), 'success'); } else { // User has been added ONLY to the contacts list $Messages->add('User has been added to your contacts.', 'success'); } } header_redirect($Blog->get('userurl', array('url_suffix' => 'user_ID=' . $user_ID, 'glue' => '&'))); } break; case 'unblock': // Unblock user // Check that this action request is not a CSRF hacked request: $Session->assert_received_crumb('messaging_contacts'); $user_ID = param('user_ID', 'integer', 0); if ($user_ID > 0) { set_contact_blocked($user_ID, 0); $Messages->add(T_('Contact was unblocked.'), 'success'); } break; case 'remove_user': // Remove user from contacts group // Check that this action request is not a CSRF hacked request: $Session->assert_received_crumb('messaging_contacts'); $view = param('view', 'string', 'profile'); $user_ID = param('user_ID', 'integer', 0); $group_ID = param('group_ID', 'integer', 0); if ($user_ID > 0 && $group_ID > 0) { // Remove user from selected group if (remove_contacts_group_user($group_ID, $user_ID)) { // User has been removed from the group if ($view == 'contacts') { // Redirect to the contacts list header_redirect($Blog->get('contactsurl', array('glue' => '&'))); } else { // Redirect to the user profile page header_redirect($Blog->get('userurl', array('url_suffix' => 'user_ID=' . $user_ID, 'glue' => '&'))); } } } break; case 'add_group': // Add users to the group // Check that this action request is not a CSRF hacked request: $Session->assert_received_crumb('messaging_contacts'); $group = param('group', 'string', ''); $users = param('users', 'string', ''); if ($result = create_contacts_group_users($group, $users)) { // Users have been added to the group $Messages->add(sprintf(T_('%d contacts have been added to the «%s» group.'), $result['count_users'], $result['group_name']), 'success'); $redirect_to = $Blog->get('contactsurl', array('glue' => '&')); $item_ID = param('item_ID', 'integer', 0); if ($item_ID > 0) { $redirect_to = url_add_param($redirect_to, 'item_ID=' . $item_ID, '&'); } header_redirect($redirect_to); } break; case 'rename_group': // Rename the group // Check that this action request is not a CSRF hacked request: $Session->assert_received_crumb('messaging_contacts'); $group_ID = param('group_ID', 'integer', true); if (rename_contacts_group($group_ID)) { $item_ID = param('item_ID', 'integer', 0); $redirect_to = url_add_param($Blog->get('contactsurl', array('glue' => '&')), 'g=' . $group_ID, '&'); if ($item_ID > 0) { $redirect_to = url_add_param($redirect_to, 'item_ID=' . $item_ID, '&'); } $Messages->add(T_('The group has been renamed.'), 'success'); header_redirect($redirect_to); } break; case 'delete_group': // Delete the group // Check that this action request is not a CSRF hacked request: $Session->assert_received_crumb('messaging_contacts'); $group_ID = param('group_ID', 'integer', true); if (delete_contacts_group($group_ID)) { $item_ID = param('item_ID', 'integer', 0); $redirect_to = $Blog->get('contactsurl', array('glue' => '&')); if ($item_ID > 0) { $redirect_to = url_add_param($redirect_to, 'item_ID=' . $item_ID, '&'); } $Messages->add(T_('The group has been deleted.'), 'success'); header_redirect($redirect_to); } break; } modules_call_method('switch_contacts_actions', array('action' => $action)); break; case 'threads': // Actions ONLY for disp=threads if (!is_logged_in()) { // Redirect to the login page for anonymous users $Messages->add(T_('You must log in to read your messages.')); header_redirect(get_login_url('cannot see messages'), 302); // will have exited } if (!$current_User->check_status('can_view_threads')) { // user status does not allow to view threads if ($current_User->check_status('can_be_validated')) { // user is logged in but his/her account is not activate yet $Messages->add(T_('You must activate your account before you can read & send messages. <b>See below:</b>')); header_redirect(get_activate_info_url(), 302); // will have exited } $Messages->add('You are not allowed to view Messages!'); $blogurl = $Blog->gen_blogurl(); // If it was a front page request or the front page is set to display 'threads' then we must not redirect to the front page because it is forbidden for the current User $redirect_to = is_front_page() || $Blog->get_setting('front_disp') == 'threads' ? url_add_param($blogurl, 'disp=404', '&') : $blogurl; header_redirect($redirect_to, 302); // will have exited } if (!$current_User->check_perm('perm_messaging', 'reply')) { // Redirect to the blog url for users without messaging permission $Messages->add('You are not allowed to view Messages!'); $blogurl = $Blog->gen_blogurl(); // If it was a front page request or the front page is set to display 'threads' then we must not redirect to the front page because it is forbidden for the current User $redirect_to = is_front_page() || $Blog->get_setting('front_disp') == 'threads' ? url_add_param($blogurl, 'disp=403', '&') : $blogurl; header_redirect($redirect_to, 302); // will have exited } $action = param('action', 'string', 'view'); if ($action == 'new') { // Before new message form is displayed ... if (has_cross_country_restriction('contact') && empty($current_User->ctry_ID)) { // Cross country contact restriction is enabled, but user country is not set yet $Messages->add(T_('Please specify your country before attempting to contact other users.')); header_redirect(get_user_profile_url()); } elseif (check_create_thread_limit(true)) { // don't allow to create new thread, because the new thread limit was already reached set_param('action', 'view'); } } // Load classes load_class('messaging/model/_thread.class.php', 'Thread'); load_class('messaging/model/_message.class.php', 'Message'); // Get action parameter from request: $action = param_action('view'); switch ($action) { case 'new': // Check permission: $current_User->check_perm('perm_messaging', 'reply', true); global $edited_Thread, $edited_Message; $edited_Thread = new Thread(); $edited_Message = new Message(); $edited_Message->Thread =& $edited_Thread; modules_call_method('update_new_thread', array('Thread' => &$edited_Thread)); if (($unsaved_message_params = get_message_params_from_session()) !== NULL) { // set Message and Thread saved params from Session $edited_Message->text = $unsaved_message_params['message']; $edited_Message->original_text = $unsaved_message_params['message_original']; $edited_Message->set_renderers($unsaved_message_params['renderers']); $edited_Thread->title = $unsaved_message_params['subject']; $edited_Thread->recipients = $unsaved_message_params['thrd_recipients']; $edited_Message->Thread = $edited_Thread; global $thrd_recipients_array, $thrdtype, $action, $creating_success; $thrd_recipients_array = $unsaved_message_params['thrd_recipients_array']; $thrdtype = $unsaved_message_params['thrdtype']; $action = $unsaved_message_params['action']; $creating_success = !empty($unsaved_message_params['creating_success']) ? $unsaved_message_params['creating_success'] : false; } else { if (empty($edited_Thread->recipients)) { $edited_Thread->recipients = param('thrd_recipients', 'string', ''); } if (empty($edited_Thread->title)) { $edited_Thread->title = param('subject', 'string', ''); } } break; default: // Check permission: $current_User->check_perm('perm_messaging', 'reply', true); break; } break; } // Actions for disp = messages, contacts, threads: if (($msg_Blog =& get_setting_Blog('msg_blog_ID')) && $Blog->ID != $msg_Blog->ID) { // Redirect to special blog for messaging actions if it is defined in general settings $blog_url_params = array('glue' => '&'); if (!empty($thrd_ID)) { // Don't forget the important param on redirect $blog_url_params['url_suffix'] = 'thrd_ID=' . $thrd_ID; } header_redirect($msg_Blog->get($disp . 'url', $blog_url_params)); } // just in case some robot would be logged in: $seo_page_type = 'Messaging module'; $robots_index = false; // Display messages depending on user email status display_user_email_status_message(); break; case 'login': global $Plugins, $transmit_hashed_password; if (is_logged_in()) { // User is already logged in if ($current_User->check_status('can_be_validated')) { // account is not active yet, redirect to the account activation page $Messages->add(T_('You are logged in but your account is not activated. You will find instructions about activating your account below:')); header_redirect(get_activate_info_url(), 302); // will have exited } // User is already logged in, redirect to "redirect_to" page $Messages->add(T_('You are already logged in.'), 'note'); $redirect_to = param('redirect_to', 'url', NULL); if (empty($redirect_to)) { // If empty redirect to referer page $redirect_to = ''; } header_redirect($redirect_to, 302); // will have exited } if (($login_Blog =& get_setting_Blog('login_blog_ID')) && $Blog->ID != $login_Blog->ID) { // Redirect to special blog for login/register actions if it is defined in general settings header_redirect($login_Blog->get('loginurl', array('glue' => '&'))); } $seo_page_type = 'Login form'; $robots_index = false; break; case 'register': if (is_logged_in()) { // If user is logged in the register form should not be displayed. In this case redirect to the blog home page. $Messages->add(T_('You are already logged in.'), 'note'); header_redirect($Blog->gen_blogurl(), false); } if (($login_Blog =& get_setting_Blog('login_blog_ID')) && $Blog->ID != $login_Blog->ID) { // Redirect to special blog for login/register actions if it is defined in general settings header_redirect($login_Blog->get('registerurl', array('glue' => '&'))); } $seo_page_type = 'Register form'; $robots_index = false; // Check invitation code if it exists and registration is enabled global $display_invitation; $display_invitation = check_invitation_code(); break; case 'lostpassword': if (is_logged_in()) { // If user is logged in the lost password form should not be displayed. In this case redirect to the blog home page. $Messages->add(T_('You are already logged in.'), 'note'); header_redirect($Blog->gen_blogurl(), false); } if (($login_Blog =& get_setting_Blog('login_blog_ID')) && $Blog->ID != $login_Blog->ID) { // Redirect to special blog for login/register actions if it is defined in general settings header_redirect($login_Blog->get('lostpasswordurl', array('glue' => '&'))); } $seo_page_type = 'Lost password form'; $robots_index = false; break; case 'activateinfo': if (!is_logged_in()) { // Redirect to the login page for anonymous users $Messages->add(T_('You must log in before you can activate your account.')); header_redirect(get_login_url('cannot see messages'), 302); // will have exited } if (!$current_User->check_status('can_be_validated')) { // don't display activateinfo screen $after_email_validation = $Settings->get('after_email_validation'); if ($after_email_validation == 'return_to_original') { // we want to return to original page after account activation // check if Session 'validatemail.redirect_to' param is still set $redirect_to = $Session->get('core.validatemail.redirect_to'); if (empty($redirect_to)) { // Session param is empty try to get general redirect_to param $redirect_to = param('redirect_to', 'url', ''); } else { // cleanup validateemail.redirect_to param from session $Session->delete('core.validatemail.redirect_to'); } } else { // go to after email validation url which is set in the user general settings form $redirect_to = $after_email_validation; } if (empty($redirect_to) || preg_match('#disp=activateinfo#', $redirect_to)) { // redirect_to is pointing to the activate info display or is empty // redirect to referer page $redirect_to = ''; } if ($current_User->check_status('is_validated')) { $Messages->add(T_('Your account has already been activated.')); } header_redirect($redirect_to, 302); // will have exited } if (($login_Blog =& get_setting_Blog('login_blog_ID')) && $Blog->ID != $login_Blog->ID) { // Redirect to special blog for login/register actions if it is defined in general settings header_redirect($login_Blog->get('activateinfourl', array('glue' => '&'))); } break; case 'profile': case 'avatar': $action = param_action(); if ($action == 'crop' && is_logged_in()) { // Check data for crop action: global $current_User, $cropped_File; $file_ID = param('file_ID', 'integer'); if (!($cropped_File = $current_User->get_File_by_ID($file_ID, $error_code))) { // Current user cannot crop this file set_param('action', ''); } } case 'pwdchange': case 'userprefs': case 'subs': $seo_page_type = 'Special feature page'; if ($Blog->get_setting('special_noindex')) { // We prefer robots not to index these pages: $robots_index = false; } // Display messages depending on user email status display_user_email_status_message(); break; case 'users': if (!is_logged_in() && !$Settings->get('allow_anonymous_user_list')) { // Redirect to the login page if not logged in and allow anonymous user setting is OFF $Messages->add(T_('You must log in to view the user directory.')); header_redirect(get_login_url('cannot see user'), 302); // will have exited } if (is_logged_in() && !check_user_status('can_view_users')) { // user status doesn't permit to view users list if (check_user_status('can_be_validated')) { // user is logged in but his/her account is not active yet // Redirect to the account activation page $Messages->add(T_('You must activate your account before you can view the user directory. <b>See below:</b>')); header_redirect(get_activate_info_url(), 302); // will have exited } // set where to redirect $error_redirect_to = empty($Blog) ? $baseurl : $Blog->gen_blogurl(); $Messages->add(T_('Your account status currently does not permit to view the user directory.')); header_redirect($error_redirect_to, 302); // will have exited } if (has_cross_country_restriction('users', 'list') && empty($current_User->ctry_ID)) { // User may browse other users only from the same country $Messages->add(T_('Please specify your country before attempting to contact other users.')); header_redirect(get_user_profile_url()); } $seo_page_type = 'Users list'; $robots_index = false; break; case 'user': // get user_ID because we want it in redirect_to in case we need to ask for login. $user_ID = param('user_ID', 'integer', '', true); // set where to redirect in case of error $error_redirect_to = empty($Blog) ? $baseurl : $Blog->gen_blogurl(); if (!is_logged_in()) { // Redirect to the login page if not logged in and allow anonymous user setting is OFF $user_available_by_group_level = true; if (!empty($user_ID)) { $UserCache =& get_UserCache(); if ($User =& $UserCache->get_by_ID($user_ID, false)) { // If user exists we can check if the anonymous users have an access to view the user by group level limitation $User->get_Group(); $user_available_by_group_level = $User->Group->level >= $Settings->get('allow_anonymous_user_level_min') && $User->Group->level <= $Settings->get('allow_anonymous_user_level_max'); } } if (!$Settings->get('allow_anonymous_user_profiles') || !$user_available_by_group_level || empty($user_ID)) { // If this user is not available for anonymous users $Messages->add(T_('You must log in to view this user profile.')); header_redirect(get_login_url('cannot see user'), 302); // will have exited } } if (is_logged_in() && !check_user_status('can_view_user', $user_ID)) { // user is logged in, but his/her status doesn't permit to view user profile if (check_user_status('can_be_validated')) { // user is logged in but his/her account is not active yet // Redirect to the account activation page $Messages->add(T_('You must activate your account before you can view this user profile. <b>See below:</b>')); header_redirect(get_activate_info_url(), 302); // will have exited } $Messages->add(T_('Your account status currently does not permit to view this user profile.')); header_redirect($error_redirect_to, 302); // will have exited } if (!empty($user_ID)) { $UserCache =& get_UserCache(); $User =& $UserCache->get_by_ID($user_ID, false); if (empty($User)) { $Messages->add(T_('The requested user does not exist!')); header_redirect($error_redirect_to); // will have exited } if ($User->check_status('is_closed')) { $Messages->add(T_('The requested user account is closed!')); header_redirect($error_redirect_to); // will have exited } if (has_cross_country_restriction('any')) { if (empty($current_User->ctry_ID)) { // Current User country is not set $Messages->add(T_('Please specify your country before attempting to contact other users.')); header_redirect(get_user_profile_url()); // will have exited } if (has_cross_country_restriction('users', 'profile') && $current_User->ctry_ID !== $User->ctry_ID) { // Current user country is different then edited user country and cross country user browsing is not enabled. $Messages->add(T_('You don\'t have permission to view this user profile.')); header_redirect(url_add_param($error_redirect_to, 'disp=403', '&')); // will have exited } } } // Initialize users list from session cache in order to display prev/next links: // It is used to navigate between users load_class('users/model/_userlist.class.php', 'UserList'); global $UserList; $UserList = new UserList(); $UserList->memorize = false; $UserList->load_from_Request(); $seo_page_type = 'User display'; break; case 'edit': global $current_User, $post_ID; // Post ID, go from $_GET when we edit a post from Front-office // or from $_POST when we switch from Back-office $post_ID = param('p', 'integer', empty($post_ID) ? 0 : $post_ID, true); if (!is_logged_in()) { // Redirect to the login page if not logged in and allow anonymous user setting is OFF $redirect_to = url_add_param($Blog->gen_blogurl(), 'disp=edit'); $Messages->add(T_('You must log in to create & edit posts.')); header_redirect(get_login_url('cannot edit posts', $redirect_to), 302); // will have exited } if (!$current_User->check_status('can_edit_post')) { if ($current_User->check_status('can_be_validated')) { // user is logged in but his/her account was not activated yet // Redirect to the account activation page $Messages->add(T_('You must activate your account before you can create & edit posts. <b>See below:</b>')); header_redirect(get_activate_info_url(), 302); // will have exited } // Redirect to the blog url for users without messaging permission $Messages->add(T_('You are not allowed to create & edit posts!')); header_redirect($Blog->gen_blogurl(), 302); } // user logged in and the account was activated check_item_perm_edit($post_ID); if (!blog_has_cats($Blog->ID)) { // No categories are in this blog $error_message = T_('Since this blog has no categories, you cannot post into it.'); if ($current_User->check_perm('blog_cats', 'edit', false, $Blog->ID)) { // If current user has a permission to create a category global $admin_url; $error_message .= ' ' . sprintf(T_('You must <a %s>create categories</a> first.'), 'href="' . $admin_url . '?ctrl=chapters&blog=' . $Blog->ID . '"'); } $Messages->add($error_message, 'error'); header_redirect($Blog->gen_blogurl(), 302); } // Prepare the 'In-skin editing': init_inskin_editing(); break; case 'edit_comment': global $current_User, $edited_Comment, $comment_Item, $Item, $comment_title, $comment_content, $display_params; // comment ID $comment_ID = param('c', 'integer', 0, true); if (!is_logged_in()) { // Redirect to the login page if not logged in and allow anonymous user setting is OFF $redirect_to = url_add_param($Blog->gen_blogurl(), 'disp=edit_comment'); $Messages->add(T_('You must log in to edit comments.')); header_redirect(get_login_url('cannot edit comments', $redirect_to), 302); // will have exited } if (!$current_User->check_status('can_edit_comment')) { if ($current_User->check_status('can_be_validated')) { // user is logged in but his/her account was not activated yet // Redirect to the account activation page $Messages->add(T_('You must activate your account before you can edit comments. <b>See below:</b>')); header_redirect(get_activate_info_url(), 302); // will have exited } // Redirect to the blog url for users without messaging permission $Messages->add('You are not allowed to edit comments!'); header_redirect($Blog->gen_blogurl(), 302); } if (empty($comment_ID)) { // Can't edit a not exisiting comment $Messages->add('Invalid comment edit URL!'); global $disp; $disp = 404; break; } $CommentCache =& get_CommentCache(); $edited_Comment = $CommentCache->get_by_ID($comment_ID); $comment_Item = $edited_Comment->get_Item(); if (!$current_User->check_perm('comment!CURSTATUS', 'edit', false, $edited_Comment)) { // If User has no permission to edit comments with this comment status: $Messages->add('You are not allowed to edit the previously selected comment!'); header_redirect($Blog->gen_blogurl(), 302); } $comment_title = ''; $comment_content = htmlspecialchars_decode($edited_Comment->content); // Format content for editing, if we were not already in editing... $Plugins_admin =& get_Plugins_admin(); $comment_Item->load_Blog(); $params = array('object_type' => 'Comment', 'object_Blog' => &$comment_Item->Blog); $Plugins_admin->unfilter_contents($comment_title, $comment_content, $edited_Comment->get_renderers_validated(), $params); $Item = $comment_Item; $display_params = array(); break; case 'useritems': case 'usercomments': global $display_params, $viewed_User; // get user_ID because we want it in redirect_to in case we need to ask for login. $user_ID = param('user_ID', 'integer', true, true); if (empty($user_ID)) { bad_request_die(sprintf(T_('Parameter «%s» is required!'), 'user_ID')); } // set where to redirect in case of error $error_redirect_to = empty($Blog) ? $baseurl : $Blog->gen_blogurl(); if (!is_logged_in()) { // Redirect to the login page if not logged in and allow anonymous user setting is OFF $Messages->add(T_('You must log in to view this user profile.')); header_redirect(get_login_url('cannot see user'), 302); // will have exited } if (is_logged_in() && !check_user_status('can_view_user', $user_ID)) { // user is logged in, but his/her status doesn't permit to view user profile if (check_user_status('can_be_validated')) { // user is logged in but his/her account is not active yet // Redirect to the account activation page $Messages->add(T_('You must activate your account before you can view this user profile. <b>See below:</b>')); header_redirect(get_activate_info_url(), 302); // will have exited } $Messages->add(T_('Your account status currently does not permit to view this user profile.')); header_redirect($error_redirect_to, 302); // will have exited } if (!empty($user_ID)) { $UserCache =& get_UserCache(); $viewed_User = $UserCache->get_by_ID($user_ID, false); if (empty($viewed_User)) { $Messages->add(T_('The requested user does not exist!')); header_redirect($error_redirect_to); // will have exited } if ($viewed_User->check_status('is_closed')) { $Messages->add(T_('The requested user account is closed!')); header_redirect($error_redirect_to); // will have exited } } $display_params = !empty($Skin) ? $Skin->get_template('Results') : NULL; if ($disp == 'useritems') { // Init items list global $user_ItemList; $useritems_Blog = NULL; $user_ItemList = new ItemList2($useritems_Blog, NULL, NULL, NULL, 'ItemCache', 'useritems_'); $user_ItemList->load_from_Request(); $user_ItemList->set_filters(array('authors' => $user_ID), true, true); $user_ItemList->query(); } else { // Init comments list global $user_CommentList; $user_CommentList = new CommentList2(NULL, NULL, 'CommentCache', 'usercmts_'); $user_CommentList->load_from_Request(); $user_CommentList->set_filters(array('author_IDs' => $user_ID), true, true); $user_CommentList->query(); } break; case 'comments': if (!$Blog->get_setting('comments_latest')) { // If latest comments page is disabled - Display 404 page with error message $Messages->add(T_('This feature is disabled.'), 'error'); global $disp; $disp = '404'; } break; case 'closeaccount': global $current_User; if (!$Settings->get('account_close_enabled') || is_logged_in() && $current_User->check_perm('users', 'edit', false) || !is_logged_in() && !$Session->get('account_closing_success')) { // If an account closing page is disabled - Display 404 page with error message // Don't allow admins close own accounts from front office // Don't display this message for not logged in users, except of one case to display a bye message after account closing global $disp; $disp = '404'; } elseif ($Session->get('account_closing_success')) { // User has closed the account global $account_closing_success; $account_closing_success = $Session->get('account_closing_success'); // Unset this temp session var to don't display the message twice $Session->delete('account_closing_success'); if (is_logged_in()) { // log out current User logout(); } } break; case 'tags': $seo_page_type = 'Tags'; if ($Blog->get_setting($disp . '_noindex')) { // We prefer robots not to index these pages: $robots_index = false; } break; } $Debuglog->add('skin_init: $disp=' . $disp . ' / $disp_detail=' . $disp_detail . ' / $seo_page_type=' . $seo_page_type, 'skins'); // Make this switch block special only for 404 page switch ($disp) { case '404': // We have a 404 unresolved content error // How do we want do deal with it? skin_404_header(); // This MAY or MAY not have exited -- will exit on 30x redirect, otherwise will return here. // Just in case some dumb robot needs extra directives on this: $robots_index = false; break; } global $Hit, $check_browser_version; if ($check_browser_version && $Hit->get_browser_version() > 0 && $Hit->is_IE(9, '<')) { // Display info message if browser IE < 9 version and it is allowed by config var: global $debug; $Messages->add(T_('Your web browser is too old. For this site to work correctly, we recommend you use a more recent browser.'), 'note'); if ($debug) { $Messages->add('User Agent: ' . $Hit->get_user_agent(), 'note'); } } // dummy var for backward compatibility with versions < 2.4.1 -- prevents "Undefined variable" global $global_Cache, $credit_links; $credit_links = $global_Cache->get('creds'); $Timer->pause('skin_init'); // Check if user is logged in with a not active account, and display an error message if required check_allow_disp($disp); // initialize Blog enabled widgets, before displaying anything init_blog_widgets($Blog->ID); // Initialize displaying.... $Timer->start('Skin:display_init'); $Skin->display_init(); $Timer->pause('Skin:display_init'); // Send default headers: // See comments inside of this function: headers_content_mightcache('text/html'); // In most situations, you do NOT want to cache dynamic content! // Never allow Messages to be cached! if ($Messages->count() && !empty($PageCache)) { // Abort PageCache collect $PageCache->abort_collect(); } }
// Display number of votes for current link type if it is enabled by blog skin $voting_form_params['display_numbers'] = true; } } } display_voting_form($voting_form_params); } break; case 'comment': // Vote on comments $comment_ID = (int) $vote_ID; if (empty($comment_ID)) { // No comment ID break 2; } $CommentCache =& get_CommentCache(); $Comment = $CommentCache->get_by_ID($comment_ID, false); if (!$Comment) { // Incorrect comment ID break 2; } if ($current_User->ID == $Comment->author_user_ID) { // Do not allow users to vote on their own comments break 2; } $comment_Item =& $Comment->get_Item(); $comment_Item->load_Blog(); if (!$comment_Item->Blog->get_setting('allow_rating_comment_helpfulness')) { // If Users cannot vote break 2; }
/** * 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; }
/** * Display a comment corresponding the given comment id * * @param int comment id * @param string where to redirect after comment edit * @param boolean true to set the new redirect param, false otherwise */ function echo_comment($comment_ID, $redirect_to = NULL, $save_context = false) { global $current_User, $localtimenow; $CommentCache =& get_CommentCache(); /** * @var Comment */ $Comment = $CommentCache->get_by_ID($comment_ID); $Item =& $Comment->get_Item(); $Blog =& $Item->get_Blog(); $is_published = $Comment->get('status') == 'published'; $expiry_delay = $Item->get_setting('post_expiry_delay'); $is_expired = !empty($expiry_delay) && $localtimenow - mysql2timestamp($Comment->get('date')) > $expiry_delay; echo '<div id="c' . $comment_ID . '" class="bComment bComment'; // check if comment is expired if ($is_expired) { // comment is expired echo 'expired'; } else { // comment is not expired $Comment->status('raw'); } echo '">'; if ($current_User->check_perm('comment!CURSTATUS', 'moderate', false, $Comment)) { // User can moderate this comment echo '<div class="bSmallHead">'; echo '<div>'; echo '<div class="bSmallHeadRight">'; $Comment->permanent_link(array('before' => '', 'text' => '#text#')); echo '</div>'; echo '<span class="bDate">'; $Comment->date(); echo '</span>@<span class = "bTime">'; $Comment->time('H:i'); echo '</span>'; $Comment->author_email('', ' · Email: <span class="bEmail">', '</span>'); echo ' · <span class="bKarma">'; $Comment->spam_karma(T_('Spam Karma') . ': %s%', T_('No Spam Karma')); echo '</span>'; echo '</div>'; echo '<div style="padding-top:3px">'; if ($is_expired) { echo '<div class="bSmallHeadRight">'; echo '<span class="bExpired">' . T_('EXPIRED') . '</span>'; echo '</div>'; } $Comment->author_ip('IP: <span class="bIP">', '</span> · ', true); $Comment->ip_country('', ' · '); $Comment->author_url_with_actions('', true, true); echo '</div>'; echo '</div>'; echo '<div class="bCommentContent">'; $Comment->status('styled'); echo '<div class="bTitle">'; echo T_('In response to:') . ' <a href="?ctrl=items&blog=' . $Blog->ID . '&p=' . $Item->ID . '">' . $Item->dget('title') . '</a>'; echo '</div>'; echo '<div class="bCommentTitle">'; echo $Comment->get_title(); echo '</div>'; echo '<div class="bCommentText">'; $Comment->rating(); $Comment->avatar(); $Comment->content('htmlbody', 'true'); echo '</div>'; echo '</div>'; echo '<div class="CommentActionsArea">'; echo '<div class="floatleft">'; // Display edit button if current user has the rights: $Comment->edit_link(' ', ' ', get_icon('edit'), '#', 'roundbutton', '&', $save_context, $redirect_to); echo '<span class="roundbutton_group">'; // Display publish NOW button if current user has the rights: $link_params = array('class' => 'roundbutton_text', 'save_context' => $save_context, 'ajax_button' => true, 'redirect_to' => $redirect_to); $Comment->raise_link($link_params); // Display deprecate button if current user has the rights: $Comment->lower_link($link_params); $next_status_in_row = $Comment->get_next_status(false); if ($next_status_in_row && $next_status_in_row[0] != 'deprecated') { // Display deprecate button if current user has the rights: $Comment->deprecate_link('', '', get_icon('move_down_grey', 'imgtag', array('title' => '')), '#', 'roundbutton', '&', true, true); } // Display delete button if current user has the rights: $Comment->delete_link('', '', '#', '#', 'roundbutton_text', false, '&', $save_context, true, '#', $redirect_to); echo '</span>'; echo '</div>'; // Display Spam Voting system $Comment->vote_spam('', '', '&', $save_context, true); echo '<div class="clear"></div>'; echo '</div>'; } else { // No permissions to moderate of this comment, just preview echo '<div class="bSmallHead">'; echo '<div>'; echo '<div class="bSmallHeadRight">'; echo T_('Visibility') . ': '; echo '<span class="bStatus">'; $Comment->status(); echo '</span>'; echo '</div>'; echo '<span class="bDate">'; $Comment->date(); echo '</span>@<span class = "bTime">'; $Comment->time('H:i'); echo '</span>'; echo '</div>'; echo '</div>'; if ($is_published) { echo '<div class="bCommentContent">'; echo '<div class="bCommentTitle">'; echo $Comment->get_title(); echo '</div>'; echo '<div class="bCommentText">'; $Comment->rating(); $Comment->avatar(); $Comment->content(); echo '</div>'; echo '</div>'; } echo '<div class="clear"></div>'; } echo '</div>'; // end }
/** * Get current Comment for an XML-RPC request. * * @param xmlrpcmsg XML-RPC Message * @param integer idx of comment ID param * @return Comment or NULL */ function &xmlrpcs_get_Comment($m, $id_param) { global $xmlrpcs_errcode, $xmlrpcs_errmsg, $xmlrpcerruser; $id = $m->getParam($id_param); $id = $id->scalarval(); /** * @var CommentCache */ $CommentCache =& get_CommentCache(); /** * @var Comment */ $edited_Comment =& $CommentCache->get_by_ID($id, false, false); if (empty($edited_Comment)) { // Comment not found $xmlrpcs_errcode = $xmlrpcerruser + 9; $xmlrpcs_errmsg = 'Requested comment (' . $id . ') does not exist.'; $r = NULL; return $r; } logIO('Requested Comment: ' . $edited_Comment->ID . ' - ' . strmaxlen($edited_Comment->content, 30)); return $edited_Comment; }
/** * Delete comments of the user * * @return boolean True on success */ function delete_comments() { global $DB, $current_User; // If user has a huge amount of the comments it will takes many time to delete all comments set_max_execution_time(900); $DB->begin(); // Get the comments of this user which current user can delete $comments_IDs = $this->get_own_comments_IDs(); if (!count($comments_IDs)) { // User has no comments return false; } $CommentCache =& get_CommentCache(); $ItemCache =& get_ItemCache(); // If current user can moderate this user then it is allowed to delete all user data even if it wouldn't be allowed otherwise. $current_user_can_moderate = $current_User->can_moderate_user($this->ID); $result = false; foreach ($comments_IDs as $comment_ID) { $deleted_Comment =& $CommentCache->get_by_ID($comment_ID, false, false); if ($deleted_Comment && ($current_user_can_moderate || $current_User->check_perm('comment!CURSTATUS', 'delete', false, $deleted_Comment))) { // Current user has a permission to delete this comment // Delete from DB $result = $deleted_Comment->dbdelete(true, false); if (!$result) { break; } } // Clear a cache to avoid a memory allocation error $CommentCache->clear(); $ItemCache->clear(); } if ($result) { $DB->commit(); } else { $DB->rollback(); } return $result; }
/** * 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&blog=' . $Blog->ID . '&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&action=edit&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&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&user_tab=profile&user_ID=' . $link->user_ID . '">' . $link->user_login . '</a>'; } } } return implode($params['separator'], $attached_to); }
/** * 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 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); } }
/** * Get the latest Comment on this Item * * @param string the status of the latest comment * @return Comment */ function &get_latest_Comment($status = NULL) { global $DB; if (is_null($this->latest_Comment)) { $SQL = new SQL('Get the latest Comment on the Item'); $SQL->SELECT('comment_ID'); $SQL->FROM('T_comments'); $SQL->WHERE('comment_item_ID = ' . $DB->quote($this->ID)); $SQL->WHERE_and('comment_type != "meta"'); $SQL->ORDER_BY('comment_date DESC'); $SQL->LIMIT('1'); if ($status != NULL) { $SQL->WHERE_and('comment_status = ' . $DB->quote($status)); } if ($comment_ID = $DB->get_var($SQL->get())) { $CommentCache =& get_CommentCache(); $this->latest_Comment =& $CommentCache->get_by_ID($comment_ID); } } return $this->latest_Comment; }
/** * 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&blog=' . $Blog->ID . '&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&action=edit&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&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&user_tab=profile&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&link_ID=' . $link->link_ID . '&link_type=item&link_object_ID=' . $link->link_usr_ID . '&action=unlink&redirect_to=' . rawurlencode(regenerate_url('blog', '', '', '&')) . '&' . 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); }
/** * Display comments results table * * @param array Params */ function comments_results_block($params = array()) { // Make sure we are not missing any param: $params = array_merge(array('edited_User' => NULL, 'results_param_prefix' => 'actv_comment_', 'results_title' => T_('Comments posted by the user'), 'results_no_text' => T_('User has not posted any comment yet')), $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); $SQL = new SQL(); $SQL->SELECT('*'); $SQL->FROM('T_comments'); $SQL->WHERE('comment_author_ID = ' . $DB->quote($edited_User->ID)); // Create result set: $comments_Results = new Results($SQL->get(), $params['results_param_prefix'], 'D'); $comments_Results->Cache =& get_CommentCache(); $comments_Results->title = $params['results_title']; $comments_Results->no_results_text = $params['results_no_text']; // Get a count of the comments which current user can delete $deleted_comments_count = count($edited_User->get_deleted_comments()); if ($comments_Results->total_rows > 0 && $deleted_comments_count) { // Display action icon to delete all records if at least one record exists & current user can delete at least one comment posted by user $comments_Results->global_icon(sprintf(T_('Delete all comments posted by %s'), $edited_User->login), 'delete', '?ctrl=user&user_tab=activity&action=delete_all_comments&user_ID=' . $edited_User->ID . '&' . url_crumb('user'), ' ' . T_('Delete all'), 3, 4); } // Initialize Results object comments_results($comments_Results, array('field_prefix' => 'comment_', 'display_kind' => false, 'display_additional_columns' => true, 'plugin_table_name' => 'activity', 'display_spam' => 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!'); } $comments_Results->init_params_by_skin($params['skin_type'], $params['skin_name']); } $display_params = array('before' => '<div class="results" style="margin-top:25px" id="comments_result">'); $comments_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>'; } }
/** * Find and delete orphan comments with no matching Item */ function dbm_delete_orphan_comments() { global $Messages, $DB; // Get all comment with no matching Item $comments_SQL = new SQL(); $comments_SQL->SELECT('comment_ID'); $comments_SQL->FROM('T_comments'); $comments_SQL->FROM_add('LEFT JOIN T_items__item ON comment_item_ID = post_ID'); $comments_SQL->WHERE('post_ID IS NULL'); $comments = $DB->get_col($comments_SQL->get()); $num_deleted = 0; $CommentCache =& get_CommentCache(); foreach ($comments as $comment_ID) { if (($broken_Comment =& $CommentCache->get_by_ID($comment_ID, false, false)) !== false) { // Comment object is created if ($broken_Comment->dbdelete(true)) { // Comment is deleted successfully $num_deleted++; } } // Clear cache to save memory $CommentCache->clear(); } $Messages->add(sprintf(T_('%d comments have been deleted'), $num_deleted), 'success'); }
/** * Get the comments of this user which current user can delete * * @return array Comments */ function get_deleted_comments() { global $DB, $current_User; // Get the comments of the user $CommentCache =& get_CommentCache(); $CommentCache->ID_array = array(); $user_Comments = $CommentCache->load_where('comment_author_ID = ' . $DB->quote($this->ID)); $deleted_Comments = array(); foreach ($user_Comments as $user_Comment) { if ($current_User->check_perm('comment!CURSTATUS', 'delete', false, $user_Comment)) { // Current user has a permission to delete this comment $deleted_Comments[] = $user_Comment; } } return $deleted_Comments; }
/** * Display a comment corresponding the given comment id * * @param int comment id * @param string where to redirect after comment edit * @param boolean true to set the new redirect param, false otherwise * @param integer Comment index in the current list */ function echo_comment($comment_ID, $redirect_to = NULL, $save_context = false, $comment_index = NULL) { global $current_User, $localtimenow; $CommentCache =& get_CommentCache(); /** * @var Comment */ $Comment = $CommentCache->get_by_ID($comment_ID); $Item =& $Comment->get_Item(); $Blog =& $Item->get_Blog(); $is_published = $Comment->get('status') == 'published'; $expiry_delay = $Item->get_setting('comment_expiry_delay'); $is_expired = !empty($expiry_delay) && $localtimenow - mysql2timestamp($Comment->get('date')) > $expiry_delay; echo '<a name="c' . $comment_ID . '"></a>'; echo '<div id="comment_' . $comment_ID . '" class="bComment bComment'; // check if comment is expired if ($is_expired) { // comment is expired echo 'expired'; } elseif ($Comment->is_meta()) { // meta comment echo 'meta'; } else { // comment is not expired and not meta $Comment->status('raw'); } echo '">'; if ($current_User->check_perm('comment!CURSTATUS', 'moderate', false, $Comment) || $Comment->is_meta() && $current_User->check_perm('meta_comment', 'view', false, $Item)) { // User can moderate this comment OR Comment is meta and current user can view it echo '<div class="bSmallHead">'; echo '<div>'; if ($Comment->is_meta()) { // Display ID for each meta comment echo '<span class="badge badge-info">' . $comment_index . '</span> '; } echo '<div class="bSmallHeadRight">'; $Comment->permanent_link(array('before' => '', 'text' => $Comment->is_meta() ? T_('Meta link') : '#text#')); echo '</div>'; echo '<span class="bDate">'; $Comment->date(); echo '</span>@<span class = "bTime">'; $Comment->time('#short_time'); echo '</span>'; if ($Comment->is_meta()) { // Display only author for meta comment $Comment->author('', '', ' · ' . T_('Author') . ': ', ''); } else { // Display the detailed info for standard comment $Comment->author_email('', ' · Email: <span class="bEmail">', '</span>'); echo ' · <span class="bKarma">'; $Comment->spam_karma(T_('Spam Karma') . ': %s%', T_('No Spam Karma')); echo '</span>'; echo '</div>'; echo '<div style="padding-top:3px">'; if ($is_expired) { echo '<div class="bSmallHeadRight">'; echo '<span class="bExpired">' . T_('EXPIRED') . '</span>'; echo '</div>'; } $Comment->author_ip('IP: <span class="bIP">', '</span> · ', true, true); $Comment->ip_country('', ' · '); $Comment->author_url_with_actions('', true, true); } echo '</div>'; echo '</div>'; echo '<div class="bCommentContent">'; $Comment->format_status(array('template' => '<div class="floatright"><span class="note status_$status$"><span>$status_title$</span></span></div>')); if (!$Comment->is_meta()) { // Don't display the titles for meta comments echo '<div class="bCommentTitle">'; echo $Comment->get_title(); if (get_param('p') == '') { // Don't display this title on a post view page echo ' ' . T_('in response to') . ' <a href="?ctrl=items&blog=' . $Blog->ID . '&p=' . $Item->ID . '">' . $Item->dget('title') . '</a>'; } echo '</div>'; } echo '<div class="bCommentText">'; $Comment->rating(); $Comment->avatar('crop-top-80x80'); if ($current_User->check_perm('meta_comment', 'edit', false, $Comment)) { // Put the comment content into this container to edit by ajax echo '<div id="editable_comment_' . $Comment->ID . '" class="editable_comment_content">'; } $Comment->content('htmlbody', 'true'); if ($current_User->check_perm('meta_comment', 'edit', false, $Comment)) { // End of the container that is used to edit meta comment by ajax echo '</div>'; } echo '</div>'; echo '</div>'; echo '<div class="CommentActionsArea">'; echo '<div class="floatleft">'; // Display edit button if current user has the rights: $Comment->edit_link(' ', ' ', get_icon('edit_button') . ' ' . T_('Edit'), '#', button_class('text_primary') . ' w80px', '&', $save_context, $redirect_to); echo '<span class="' . button_class('group') . '">'; // Display publish NOW button if current user has the rights: $link_params = array('class' => button_class('text'), 'save_context' => $save_context, 'ajax_button' => true, 'redirect_to' => $redirect_to); $Comment->raise_link($link_params); // Display deprecate button if current user has the rights: $Comment->lower_link($link_params); $next_status_in_row = $Comment->get_next_status(false); if ($next_status_in_row && $next_status_in_row[0] != 'deprecated') { // Display deprecate button if current user has the rights: $Comment->deprecate_link('', '', get_icon('move_down_grey', 'imgtag', array('title' => '')), '#', button_class(), '&', true, true); } // Display delete button if current user has the rights: $Comment->delete_link('', '', '#', '#', button_class('text'), false, '&', $save_context, true, '#', $redirect_to); echo '</span>'; echo '</div>'; if (!$Comment->is_meta()) { // Display Spam Voting system $Comment->vote_spam('', '', '&', $save_context, true); } echo '<div class="clear"></div>'; echo '</div>'; } else { // No permissions to moderate of this comment, just preview echo '<div class="bSmallHead">'; echo '<div>'; echo '<div class="bSmallHeadRight">'; echo T_('Visibility') . ': '; echo '<span class="bStatus">'; $Comment->status(); echo '</span>'; echo '</div>'; echo '<span class="bDate">'; $Comment->date(); echo '</span>@<span class = "bTime">'; $Comment->time('#short_time'); echo '</span>'; echo '</div>'; echo '</div>'; if ($is_published) { echo '<div class="bCommentContent">'; echo '<div class="bCommentTitle">'; echo $Comment->get_title(); echo '</div>'; echo '<div class="bCommentText">'; $Comment->rating(); $Comment->avatar(); $Comment->content(); echo '</div>'; echo '</div>'; } echo '<div class="clear"></div>'; } echo '</div>'; // end }
/** * Get a link to object of system log * * @param string Object type * @param integer Object ID * @return string */ function syslog_object_link($object_type, $object_ID) { global $current_User, $admin_url; $link = ''; if (empty($object_ID)) { // Invalid object ID return 'Empty object ID'; } switch ($object_type) { case 'comment': // Link to comment $CommentCache =& get_CommentCache(); if (($Comment =& $CommentCache->get_by_ID($object_ID, false, false)) !== false) { if ($current_User->check_perm('comment!CURSTATUS', 'edit', false, $Comment)) { // Current user has permission to edit this comment $Item =& $Comment->get_Item(); $link = '<a href="' . $admin_url . '?ctrl=comments&action=edit&comment_ID=' . $Comment->ID . '">' . $Item->title . ' #' . $Comment->ID . '</a>'; } } else { // Comment was deleted or ID is incorrect $link = 'No comment'; } break; case 'item': // Link to item $ItemCache =& get_ItemCache(); if (($Item =& $ItemCache->get_by_ID($object_ID, false, false)) !== false) { if ($current_User->check_perm('item_post!CURSTATUS', 'edit', false, $Item)) { // Current user has permission to edit this item $link = '<a href="' . $Item->get_edit_url() . '">' . $Item->title . '</a>'; } } else { // Item was deleted or ID is incorrect $link = 'No item'; } break; case 'user': // Link to user if ($current_User->check_perm('users', 'view')) { // Current user has permission to view users $UserCache = get_UserCache(); if (($User =& $UserCache->get_by_ID($object_ID, false, false)) !== false) { // User exists $link = $User->get_identity_link(); } else { // User was deleted or ID is incorrect $link = 'No user'; } } break; case 'file': // Link to file $FileCache =& get_FileCache(); if (($File =& $FileCache->get_by_ID($object_ID, false, false)) !== false) { // File exists $link = $File->is_dir() ? '' : $File->get_view_link(); $link .= ' ' . $File->get_target_icon(); } else { // User was deleted or ID is incorrect $link = 'No file'; } break; } return $link; }