/** * 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'); }
/** * Send a "your content has been validated" notification out to the submitter of some content. Only call if this is true ;). * * @param ID_TEXT Content type * @param ID_TEXT Content ID */ function send_content_validated_notification($content_type, $content_id) { require_code('content'); list($content_title, $submitter_id, , , , $content_url_safe) = content_get_details($content_type, $content_id); if (!is_null($content_url_safe)) { require_code('notifications'); require_lang('unvalidated'); $subject = do_lang('CONTENT_VALIDATED_NOTIFICATION_MAIL_SUBJECT', $content_title, get_site_name()); $mail = do_lang('CONTENT_VALIDATED_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($content_title), array($content_url_safe->evaluate())); dispatch_notification('content_validated', NULL, $subject, $mail, array($submitter_id)); } }
/** * Convert a field value to something renderable. * * @param array The field details * @param mixed The raw value * @return mixed Rendered field (tempcode or string) */ function render_field_value($field, $ev) { if (is_object($ev)) { return $ev; } if ($ev == '') { return new ocp_tempcode(); } $type = preg_replace('#^choose\\_#', '', substr($field['cf_type'], 3)); // HACKHACK: imperfect content type naming schemes if ($type == 'forum_topic') { $type = 'topic'; } require_code('content'); list($title, , $info) = content_get_details($type, $ev); $page_link = str_replace('_WILD', $ev, $info['view_pagelink_pattern']); list($zone, $map) = page_link_decode($page_link); return hyperlink(build_url($map, $zone), $title, false, true); }
/** * Given a particular bit of feedback content, check if the user may access it. * * @param MEMBER User to check * @param ID_TEXT Content type * @param ID_TEXT Content ID * @return boolean Whether there is permission */ function may_view_content_behind_feedback_code($member_id, $content_type, $content_id) { require_code('content'); $permission_type_code = convert_ocportal_type_codes('feedback_type_code', $content_type, 'permissions_type_code'); $module = convert_ocportal_type_codes('feedback_type_code', $content_type, 'module'); if ($module == '') { $module = $content_id; } $category_id = mixed(); $award_hook = convert_ocportal_type_codes('feedback_type_code', $content_type, 'award_hook'); if ($award_hook != '') { require_code('hooks/systems/awards/' . $award_hook); $award_hook_ob = object_factory('Hook_awards_' . $award_hook); $info = $award_hook_ob->info(); if (isset($info['category_field'])) { $cma_hook = convert_ocportal_type_codes('award_hook', $award_hook, 'cma_hook'); list(, , , $content) = content_get_details($cma_hook, $content_id); if (!is_null($content)) { $category_field = $info['category_field']; if (is_array($category_field)) { $category_field = array_pop($category_field); $category_id = is_integer($content[$category_field]) ? strval($content[$category_field]) : $content[$category_field]; if ($award_hook == 'catalogue_entry') { $catalogue_name = $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'c_name', array('id' => $category_id)); if (!has_category_access($member_id, 'catalogues_catalogue', $catalogue_name)) { return false; } } } else { $category_id = is_integer($content[$category_field]) ? strval($content[$category_field]) : $content[$category_field]; } } } } // FUDGEFUDGE: Extra check for private topics $topic_id = NULL; if ($content_type == 'post' && get_forum_type() == 'ocf') { $post_rows = $GLOBALS['FORUM_DB']->query_select('f_posts', array('p_topic_id', 'p_intended_solely_for', 'p_poster'), array('id' => intval($content_id)), '', 1); if (!array_key_exists(0, $post_rows)) { return false; } if ($post_rows[0]['p_intended_solely_for'] !== NULL && ($post_rows[0]['p_intended_solely_for'] != $member_id && $post_rows[0]['p_poster'] != $member_id || is_guest($member_id))) { return false; } $topic_id = $post_rows[0]['p_topic_id']; } if ($content_type == 'topic' && get_forum_type() == 'ocf') { $topic_id = intval($content_id); } if (!is_null($topic_id)) { $topic_rows = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_forum_id', 't_pt_from', 't_pt_to'), array('id' => $topic_id), '', 1); if (!array_key_exists(0, $topic_rows)) { return false; } require_code('ocf_topics'); if ($topic_rows[0]['t_forum_id'] == NULL && ($topic_rows[0]['t_pt_from'] != $member_id && $topic_rows[0]['t_pt_to'] != $member_id && !ocf_has_special_pt_access($topic_id, $member_id) || is_guest($member_id))) { return false; } } return has_actual_page_access($member_id, $module) && ($permission_type_code == '' || is_null($category_id) || has_category_access($member_id, $permission_type_code, $category_id)); }
/** * Convert a field value to something renderable. * * @param array The field details * @param mixed The raw value * @return mixed Rendered field (tempcode or string) */ function render_field_value($field, $ev) { if (is_object($ev)) { return $ev; } if ($ev == '') { return new ocp_tempcode(); } require_code('content'); list($title) = content_get_details('catalogue_entry', $ev); return hyperlink(build_url(array('page' => 'catalogues', 'type' => 'entry', 'id' => $ev), get_module_zone('catalogues')), $title, false, true); }
function actualiser() { $title = get_page_title('REPORT_CONTENT'); // Test CAPTCHA if (addon_installed('captcha')) { require_code('captcha'); enforce_captcha(); } require_code('content'); $content_type = post_param('content_type'); // Equates to a content_meta_aware hook $content_id = post_param('content_id'); if (!is_null($GLOBALS['SITE_DB']->query_value_null_ok('reported_content', 'r_counts', array('r_session_id' => get_session_id(), 'r_content_type' => $content_type, 'r_content_id' => $content_id)))) { warn_exit(do_lang_tempcode('ALREADY_REPORTED_CONTENT')); } list($content_title, , $cma_info, $content_url) = content_get_details($content_type, $content_id); // Create reported post... $forum_id = $GLOBALS['FORUM_DRIVER']->forum_id_from_name(get_option('reported_posts_forum')); if (is_null($forum_id)) { warn_exit(do_lang_tempcode('ocf:NO_REPORTED_POST_FORUM')); } // See if post already reported... $post = post_param('post'); $anonymous = post_param_integer('anonymous', 0); $topic_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_topics t LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts p ON p.id=t.t_cache_first_post_id', 't.id', array('p.p_title' => $content_title, 't.t_forum_id' => $forum_id)); require_code('ocf_topics_action'); require_code('ocf_topics_action2'); require_code('ocf_posts_action'); require_code('ocf_posts_action2'); if (!is_null($topic_id)) { // Already a topic $new_topic = false; } else { $topic_id = ocf_make_topic($forum_id, '', '', 1, 1, 0, 0, 0, NULL, NULL, false); $new_topic = true; } $topic_title = do_lang('REPORTED_CONTENT_TITLE', $content_title); $post_id = ocf_make_post($topic_id, $content_title, $post, 0, $new_topic, 1, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, true, $forum_id, true, $topic_title, 0, NULL, $anonymous == 1); decache('main_staff_checklist'); // Add to reported_content table $GLOBALS['SITE_DB']->query_insert('reported_content', array('r_session_id' => get_session_id(), 'r_content_type' => $content_type, 'r_content_id' => $content_id, 'r_counts' => 1)); // If hit threshold, mark down r_counts and unvalidate the content $count = $GLOBALS['SITE_DB']->query_value('reported_content', 'COUNT(*)', array('r_content_type' => $content_type, 'r_content_id' => $content_id, 'r_counts' => 1)); if ($count >= intval(get_option('reported_times'))) { // Mark as unvalidated if (isset($cma_info['validated_field']) && strpos($cma_info['table'], '(') === false) { $db = $GLOBALS[substr($cma_info['table'], 0, 2) == 'f_' ? 'FORUM_DB' : 'SITE_DB']; $db->query_update($cma_info['table'], array($cma_info['validated_field'] => 0), array($cma_info['id_field'] => $cma_info['id_field_numeric'] ? intval($content_id) : $content_id)); } $GLOBALS['SITE_DB']->query_update('reported_content', array('r_counts' => 0), array('r_content_type' => $content_type, 'r_content_id' => $content_id)); } // Done $_url = post_param('url', '', true); if ($_url != '') { $content_url = make_string_tempcode($_url); } require_code('templates_redirect_screen'); return redirect_screen($title, $content_url, do_lang_tempcode('SUCCESS')); }