Example #1
0
/**
 * Give an award.
 *
 * @param  AUTO_LINK			The award ID
 * @param  ID_TEXT			The content ID
 * @param  ?TIME				Time the award was given (NULL: now)
 */
function give_award($award_id, $content_id, $time = NULL)
{
    require_lang('awards');
    if (is_null($time)) {
        $time = time();
    }
    $awards = $GLOBALS['SITE_DB']->query_select('award_types', array('*'), array('id' => $award_id), '', 1);
    if (!array_key_exists(0, $awards)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    $award_title = get_translated_text($awards[0]['a_title']);
    log_it('GIVE_AWARD', strval($award_id), $award_title);
    require_code('hooks/systems/awards/' . filter_naughty_harsh($awards[0]['a_content_type']));
    $object = object_factory('Hook_awards_' . $awards[0]['a_content_type']);
    $info = $object->info();
    if (is_null($info)) {
        fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
    }
    if (array_key_exists('submitter_field', $info) && $awards[0]['a_content_type'] != 'author' && !is_null($info['submitter_field'])) {
        require_code('content');
        list($content_title, $member_id, , $content) = content_get_details($awards[0]['a_content_type'], $content_id);
        if (is_null($content)) {
            warn_exit(do_lang_tempcode('_MISSING_RESOURCE', escape_html($awards[0]['a_content_type'] . ':' . $content_id)));
        }
        // Lots of fiddling around to work out how to check permissions for this
        $permission_type_code = convert_ocportal_type_codes('award_hook', $awards[0]['a_content_type'], 'permissions_type_code');
        $module = convert_ocportal_type_codes('module', $awards[0]['a_content_type'], 'permissions_type_code');
        if ($module == '') {
            $module = $content_id;
        }
        $category_id = mixed();
        if (isset($info['category_field'])) {
            if (is_array($info['category_field'])) {
                $category_id = $content[$info['category_field'][1]];
            } else {
                $category_id = $content[$info['category_field']];
            }
        }
        if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'awards') && has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), $module) && ($permission_type_code == '' || is_null($category_id) || has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), $permission_type_code, is_integer($category_id) ? strval($category_id) : $category_id))) {
            syndicate_described_activity(is_null($member_id) || is_guest($member_id) ? 'awards:_ACTIVITY_GIVE_AWARD' : 'awards:ACTIVITY_GIVE_AWARD', $award_title, $content_title, '', '_SEARCH:awards:award:' . strval($award_id), '', '', 'awards', 1, NULL, false, $member_id);
        }
    } else {
        $member_id = NULL;
    }
    if (is_null($member_id)) {
        $member_id = $GLOBALS['FORUM_DRIVER']->get_guest_id();
    }
    if (!is_guest($member_id) && addon_installed('points')) {
        require_code('points2');
        system_gift_transfer(do_lang('_AWARD', get_translated_text($awards[0]['a_title'])), $awards[0]['a_points'], $member_id);
    }
    $GLOBALS['SITE_DB']->query_insert('award_archive', array('a_type_id' => $award_id, 'member_id' => $member_id, 'content_id' => $content_id, 'date_and_time' => $time));
    decache('main_awards');
    decache('main_multi_content');
}
Example #2
0
/**
 * Add comments to the specified resource.
 *
 * @param  boolean		Whether this resource allows comments (if not, this function does nothing - but it's nice to move out this common logic into the shared function)
 * @param  ID_TEXT		The type (download, etc) that this commenting is for
 * @param  ID_TEXT		The ID of the type that this commenting is for
 * @param  mixed			The URL to where the commenting will pass back to (to put into the comment topic header) (URLPATH or Tempcode)
 * @param  ?string		The title to where the commenting will pass back to (to put into the comment topic header) (NULL: don't know, but not first post so not important)
 * @param  ?string		The name of the forum to use (NULL: default comment forum)
 * @param  boolean		Whether to not require a captcha
 * @param  ?BINARY		Whether the post is validated (NULL: unknown, find whether it needs to be marked unvalidated initially). This only works with the OCF driver (hence is the last parameter).
 * @param  boolean		Whether to force allowance
 * @param  boolean		Whether to skip a success message
 * @param  boolean		Whether posts made should not be shared
 * @return boolean		Whether a hidden post has been made
 */
function actualise_post_comment($allow_comments, $content_type, $content_id, $content_url, $content_title, $forum = NULL, $avoid_captcha = false, $validated = NULL, $explicit_allow = false, $no_success_message = false, $private = false)
{
    if (!$explicit_allow) {
        if (get_option('is_on_comments') == '0' || !$allow_comments) {
            return false;
        }
        if (!has_specific_permission(get_member(), 'comment', get_page_name())) {
            return false;
        }
    }
    if (running_script('preview')) {
        return false;
    }
    $forum_tie = get_option('is_on_strong_forum_tie') == '1';
    if (addon_installed('captcha')) {
        if (array_key_exists('post', $_POST) && $_POST['post'] != '' && !$avoid_captcha) {
            require_code('captcha');
            enforce_captcha();
        }
    }
    $post_title = post_param('title', NULL);
    if (is_null($post_title) && !$forum_tie) {
        return false;
    }
    $post = post_param('post', NULL);
    if ($post == do_lang('POST_WARNING')) {
        $post = '';
    }
    if ($post == do_lang('THREADED_REPLY_NOTICE', do_lang('POST_WARNING'))) {
        $post = '';
    }
    if ($post == '' && $post_title !== '') {
        $post = $post_title;
        $post_title = '';
    }
    if ($post === '') {
        warn_exit(do_lang_tempcode('NO_PARAMETER_SENT', 'post'));
    }
    if (is_null($post)) {
        $post = '';
    }
    $email = trim(post_param('email', ''));
    if ($email != '') {
        $body = '> ' . str_replace(chr(10), chr(10) . '> ', $post);
        if (substr($body, -2) == '> ') {
            $body = substr($body, 0, strlen($body) - 2);
        }
        if (get_page_name() != 'tickets') {
            $post .= '[staff_note]';
        }
        $post .= "\n\n" . '[email subject="Re: ' . comcode_escape($post_title) . ' [' . get_site_name() . ']" body="' . comcode_escape($body) . '"]' . $email . '[/email]' . "\n\n";
        if (get_page_name() != 'tickets') {
            $post .= '[/staff_note]';
        }
    }
    $content_title = strip_comcode($content_title);
    if (is_null($forum)) {
        $forum = get_option('comments_forum_name');
    }
    $content_url_flat = is_object($content_url) ? $content_url->evaluate() : $content_url;
    $_parent_id = post_param('parent_id', '');
    $parent_id = $_parent_id == '' ? NULL : intval($_parent_id);
    $poster_name_if_guest = post_param('poster_name_if_guest', '');
    list($topic_id, $is_hidden) = $GLOBALS['FORUM_DRIVER']->make_post_forum_topic($forum, $content_type . '_' . $content_id, get_member(), $post_title, $post, $content_title, do_lang('COMMENT'), $content_url_flat, NULL, NULL, $validated, $explicit_allow ? 1 : NULL, $explicit_allow, $poster_name_if_guest, $parent_id, false, !$private && $post != '' ? 'comment_posted' : NULL, !$private && $post != '' ? $content_type . '_' . $content_id : NULL);
    if (!is_null($topic_id)) {
        if (!is_integer($forum)) {
            $forum_id = $GLOBALS['FORUM_DRIVER']->forum_id_from_name($forum);
        } else {
            $forum_id = (int) $forum;
        }
        if (get_forum_type() == 'ocf' && !is_null($GLOBALS['LAST_POST_ID'])) {
            $extra_review_ratings = array();
            global $REVIEWS_STRUCTURE;
            if (array_key_exists($content_type, $REVIEWS_STRUCTURE)) {
                $reviews_rating_criteria = $REVIEWS_STRUCTURE[$content_type];
            } else {
                $reviews_rating_criteria[] = '';
            }
            foreach ($reviews_rating_criteria as $rating_type) {
                // Has there actually been any rating?
                $rating = post_param_integer('review_rating__' . fix_id($rating_type), NULL);
                if (!is_null($rating)) {
                    if ($rating > 10 || $rating < 1) {
                        log_hack_attack_and_exit('VOTE_CHEAT');
                    }
                    $GLOBALS['SITE_DB']->query_insert('review_supplement', array('r_topic_id' => $GLOBALS['LAST_TOPIC_ID'], 'r_post_id' => $GLOBALS['LAST_POST_ID'], 'r_rating_type' => $rating_type, 'r_rating_for_type' => $content_type, 'r_rating_for_id' => $content_id, 'r_rating' => $rating));
                }
            }
        }
    }
    if (!$private && $post != '') {
        list(, $submitter, , $safe_content_url, $cma_info) = get_details_behind_feedback_code($content_type, $content_id);
        $content_type_title = $content_type;
        if (!is_null($cma_info) && isset($cma_info['content_type_label'])) {
            $content_type_title = do_lang($cma_info['content_type_label']);
        }
        // Notification
        require_code('notifications');
        $username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
        $subject = do_lang('NEW_COMMENT_SUBJECT', get_site_name(), $content_title == '' ? ocp_mb_strtolower($content_type_title) : $content_title, array($post_title, $username), get_site_default_lang());
        $username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
        $message_raw = do_lang('NEW_COMMENT_BODY', comcode_escape(get_site_name()), comcode_escape($content_title == '' ? ocp_mb_strtolower($content_type_title) : $content_title), array($post_title == '' ? do_lang('NO_SUBJECT') : $post_title, post_param('post'), comcode_escape($content_url_flat), comcode_escape($username)), get_site_default_lang());
        dispatch_notification('comment_posted', $content_type . '_' . $content_id, $subject, $message_raw);
        // Is the user gonna automatically enable notifications for this?
        if (get_forum_type() == 'ocf') {
            $auto_monitor_contrib_content = $GLOBALS['OCF_DRIVER']->get_member_row_field(get_member(), 'm_auto_monitor_contrib_content');
            if ($auto_monitor_contrib_content == 1) {
                enable_notifications('comment_posted', $content_type . '_' . $content_id);
            }
        }
        // Activity
        $real_content_type = convert_ocportal_type_codes('feedback_type_code', $content_type, 'cma_hook');
        if (may_view_content_behind_feedback_code($GLOBALS['FORUM_DRIVER']->get_guest_id(), $real_content_type, $content_id)) {
            if (is_null($submitter)) {
                $submitter = $GLOBALS['FORUM_DRIVER']->get_guest_id();
            }
            $activity_type = is_null($submitter) || is_guest($submitter) ? '_ADDED_COMMENT_ON' : 'ADDED_COMMENT_ON';
            if ($content_title == '') {
                syndicate_described_activity($activity_type . '_UNTITLED', ocp_mb_strtolower($content_type_title), $content_type_title, '', url_to_pagelink(is_object($safe_content_url) ? $safe_content_url->evaluate() : $safe_content_url), '', '', convert_ocportal_type_codes('feedback_type_code', $content_type, 'addon_name'), 1, NULL, false, $submitter);
            } else {
                syndicate_described_activity($activity_type, $content_title, ocp_mb_strtolower($content_type_title), $content_type_title, url_to_pagelink(is_object($safe_content_url) ? $safe_content_url->evaluate() : $safe_content_url), '', '', convert_ocportal_type_codes('feedback_type_code', $content_type, 'addon_name'), 1, NULL, false, $submitter);
            }
        }
    }
    if ($post != '' && $forum_tie && !$no_success_message) {
        require_code('site2');
        assign_refresh($GLOBALS['FORUM_DRIVER']->topic_url($GLOBALS['FORUM_DRIVER']->find_topic_id_for_topic_identifier($forum, $content_type . '_' . $content_id), $forum), 0.0);
    }
    if ($post != '' && !$no_success_message) {
        attach_message(do_lang_tempcode('SUCCESS'));
    }
    return $is_hidden;
}
Example #3
0
/**
 * Try and make a spacer post look nicer on OCF than it automatically would.
 *
 * @param  ID_TEXT		Content type.
 * @param  ID_TEXT		Content ID.
 * @return array			A pair: better description (may be NULL), better post (may be NULL).
 */
function ocf_display_spacer_post($linked_type, $linked_id)
{
    $new_description = mixed();
    $new_post = mixed();
    if (addon_installed('awards')) {
        require_code('content');
        $linked_type = convert_ocportal_type_codes('feedback_type_code', $linked_type, 'award_hook');
        if ($linked_type != '') {
            require_code('hooks/systems/awards/' . $linked_type);
            $award_ob = object_factory('Hook_awards_' . $linked_type);
            $award_info = $award_ob->info();
            $linked_rows = $GLOBALS['SITE_DB']->query_select($award_info['table'], array('*'), array($award_info['id_field'] => $award_info['id_is_string'] ? $linked_id : intval($linked_id)), '', 1);
            if (array_key_exists(0, $linked_rows)) {
                $new_post = $award_ob->run($linked_rows[0], '_SEARCH');
            }
            $new_description = do_lang('THIS_IS_COMMENT_TOPIC', get_site_name());
        }
    }
    return array($new_description, $new_post);
}
Example #4
0
 /**
  * Standard modular run function for RSS hooks.
  *
  * @param  string			A list of categories we accept from
  * @param  TIME			Cutoff time, before which we do not show results from
  * @param  string			Prefix that represents the template set we use
  * @set    RSS_ ATOM_
  * @param  string			The standard format of date to use for the syndication type represented in the prefix
  * @param  integer		The maximum number of entries to return, ordering by date
  * @return ?array			A pair: The main syndication section, and a title (NULL: error)
  */
 function run($full_title, $cutoff, $prefix, $date_string, $max)
 {
     require_code('content');
     // Check permissions (this is HARD, we have to tunnel through content_meta_aware hooks)
     $parts = explode('_', $full_title, 2);
     $hook = convert_ocportal_type_codes('feedback_type_code', $parts[0], 'cma_hook');
     if ($hook != '') {
         require_code('hooks/systems/content_meta_aware/' . filter_naughty_harsh($hook), true);
         $ob = object_factory('Hook_content_meta_aware_' . filter_naughty_harsh($hook), true);
         if (is_null($ob)) {
             return NULL;
         }
         $info = $ob->info();
         // Category access
         $permissions_field = $info['permissions_type_code'];
         if (!is_null($permissions_field)) {
             $cat = $GLOBALS['SITE_DB']->query_value_null_ok($info['table'], $info['parent_category_field'], array($info['id_field'] => $parts[1]));
             if (is_null($cat)) {
                 return NULL;
             }
             if (!has_category_access(get_member(), $permissions_field, $cat)) {
                 return NULL;
             }
         }
         // Page/Zone access
         if (!is_null($info['view_pagelink_pattern'])) {
             $view_pagelink_bits = explode(':', $info['view_pagelink_pattern']);
             $zone = $view_pagelink_bits[0];
             if ($zone == '_SEARCH') {
                 $zone = get_module_zone($view_pagelink_bits[1]);
             }
             if (!has_actual_page_access(get_member(), $view_pagelink_bits[1], $zone)) {
                 return NULL;
             }
         }
     } else {
         $zone = get_page_zone($parts[0], false);
         if (is_null($zone)) {
             return NULL;
         }
         if (!has_actual_page_access(get_member(), $parts[0], $zone)) {
             return NULL;
         }
     }
     $title = NULL;
     $content = new ocp_tempcode();
     // Comment posts
     $forum = get_param('forum', get_option('comments_forum_name'));
     $count = 0;
     $start = 0;
     do {
         $_comments = $GLOBALS['FORUM_DRIVER']->get_forum_topic_posts($GLOBALS['FORUM_DRIVER']->find_topic_id_for_topic_identifier($forum, $full_title), $count, min($max, 1000), $start);
         if (is_array($_comments)) {
             $_comments = array_reverse($_comments);
             foreach ($_comments as $i => $comment) {
                 if (is_null($comment)) {
                     continue;
                 }
                 if ($i + $start > $max) {
                     break 2;
                 }
                 $datetime_raw = $comment['date'];
                 if ($datetime_raw < $cutoff) {
                     break 2;
                 }
                 $if_comments = new ocp_tempcode();
                 $id = strval($comment['id']);
                 $author = $GLOBALS['FORUM_DRIVER']->get_username($comment['user']);
                 if (is_null($author)) {
                     $author = do_lang('UNKNOWN');
                 }
                 $news_date = date($date_string, $datetime_raw);
                 $edit_date = escape_html('');
                 $news_title = xmlentities($comment['title']);
                 if ($news_title != '' && is_null($title)) {
                     $title = $comment['title'];
                 }
                 $_summary = $comment['message'];
                 if (is_object($_summary)) {
                     $_summary = $_summary->evaluate();
                 }
                 $summary = xmlentities($_summary);
                 $news = escape_html('');
                 $category = '';
                 $category_raw = '';
                 $content->attach(do_template($prefix . 'ENTRY', array('VIEW_URL' => new ocp_tempcode(), 'SUMMARY' => $summary, 'EDIT_DATE' => $edit_date, 'IF_COMMENTS' => $if_comments, 'TITLE' => $news_title, 'CATEGORY_RAW' => $category_raw, 'CATEGORY' => $category, 'AUTHOR' => $author, 'ID' => $id, 'NEWS' => $news, 'DATE' => $news_date)));
             }
         }
         $start += 1000;
     } while (count($_comments) == 1000);
     $title = do_lang('COMMENTS');
     return array($content, $title);
 }