/** * Implement a rating at the quantum level. * * @param ?integer Rating given (NULL: unrate) * @range 1 10 * @param ID_TEXT The page name the rating is on * @param MEMBER The member doing the rating * @param ID_TEXT The type (download, etc) that this rating is for * @param ID_TEXT The second level type (probably blank) * @param ID_TEXT The ID of the type that this rating is for * @param ?string The title to where the commenting will pass back to (to put into the comment topic header) (NULL: don't know) * @param mixed The URL to where the commenting will pass back to (to put into the comment topic header) (URLPATH or Tempcode) */ function actualise_specific_rating($rating, $page_name, $member_id, $content_type, $type, $content_id, $content_url, $content_title) { if (!is_null($rating)) { if ($rating > 10 || $rating < 1) { log_hack_attack_and_exit('VOTE_CHEAT'); } } $rating_for_type = $content_type . ($type == '' ? '' : '_' . $type); if (!has_specific_permission($member_id, 'rate', $page_name)) { return; } $already_rated = already_rated(array($rating_for_type), $content_id); if (!is_null($rating)) { if ($already_rated) { // Delete, in preparation for re-rating $GLOBALS['SITE_DB']->query_delete('rating', array('rating_for_type' => $rating_for_type, 'rating_for_id' => $content_id, 'rating_member' => $member_id, 'rating_ip' => get_ip_address())); } } list($_content_title, $submitter, , $safe_content_url, $cma_info) = get_details_behind_feedback_code($content_type, $content_id); if (is_null($content_title)) { $content_title = $_content_title; } if ($member_id === $submitter && !is_guest($member_id)) { return; } if (!is_null($rating)) { $GLOBALS['SITE_DB']->query_insert('rating', array('rating_for_type' => $rating_for_type, 'rating_for_id' => $content_id, 'rating_member' => $member_id, 'rating_ip' => get_ip_address(), 'rating_time' => time(), 'rating' => $rating)); } else { $GLOBALS['SITE_DB']->query_delete('rating', array('rating_for_type' => $rating_for_type, 'rating_for_id' => $content_id, 'rating_member' => $member_id, 'rating_ip' => get_ip_address())); } // Top rating / liked if ($rating === 10 && $type == '') { $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']); } // Special case. Would prefer not to hard-code, but important for usability if ($content_type == 'post' && $content_title == '' && get_forum_type() == 'ocf') { $content_title = do_lang('POST_IN', $GLOBALS['FORUM_DB']->query_value('f_topics', 't_cache_first_title', array('id' => $GLOBALS['FORUM_DB']->query_value('f_posts', 'p_topic_id', array('id' => intval($content_id)))))); } if (!is_null($submitter) && !is_guest($submitter)) { // Give points if ($member_id != $submitter) { if (addon_installed('points') && !$already_rated) { require_code('points2'); require_lang('points'); system_gift_transfer(do_lang('CONTENT_LIKED'), intval(get_option('points_if_liked')), $submitter); } } // Notification require_code('notifications'); $subject = do_lang('CONTENT_LIKED_NOTIFICATION_MAIL_SUBJECT', get_site_name(), $content_title == '' ? ocp_mb_strtolower($content_type_title) : $content_title); $rendered_award = ''; $award_hook = convert_ocportal_type_codes('feedback_type_code', $content_type, 'award_hook'); if ($award_hook != '') { require_code('hooks/systems/awards/' . $award_hook); $award_ob = object_factory('Hook_awards_' . $award_hook); $award_content_row = content_get_row($content_id, $award_ob->info()); if (!is_null($award_content_row)) { $rendered_award = preg_replace('#&keep_\\w+=[^&]*#', '', static_evaluate_tempcode($award_ob->run($award_content_row, '_SEARCH'))); } } $mail = do_lang('CONTENT_LIKED_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($content_title == '' ? ocp_mb_strtolower($content_type_title) : $content_title), array(comcode_escape(is_object($safe_content_url) ? $safe_content_url->evaluate() : $safe_content_url), $rendered_award, comcode_escape($GLOBALS['FORUM_DRIVER']->get_username(get_member())))); dispatch_notification('like', NULL, $subject, $mail, array($submitter)); } // Put on activity wall / whatever $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) ? '_ACTIVITY_LIKES' : 'ACTIVITY_LIKES'; 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); } } } // Enter them for a prize draw to win a free jet // NOT IMPLEMENTED- Anyone want to donate the jet? }
/** * Get meta details of a content item * * @param ID_TEXT Content type * @param ID_TEXT Content ID * @return array Tuple: title, submitter, content hook info, the content row, URL (for use within current browser session), URL (for use in emails / sharing) */ function content_get_details($content_type, $content_id) { require_code('hooks/systems/content_meta_aware/' . $content_type); $cma_ob = object_factory('Hook_content_meta_aware_' . $content_type); $cma_info = $cma_ob->info(); $db = $GLOBALS[substr($cma_info['table'], 0, 2) == 'f_' ? 'FORUM_DB' : 'SITE_DB']; $content_row = content_get_row($content_id, $cma_info); if (is_null($content_row)) { if ($content_type == 'comcode_page' && strpos($content_id, ':') !== false) { list($zone, $page) = explode(':', $content_id, 2); $members = $GLOBALS['FORUM_DRIVER']->member_group_query($GLOBALS['FORUM_DRIVER']->get_super_admin_groups(), 1); if (count($members) != 0) { $submitter_id = $GLOBALS['FORUM_DRIVER']->pname_id($members[key($members)]); } else { $submitter_id = db_get_first_id() + 1; // On OCF and most forums, this is the first admin member } $content_row = array('the_zone' => $zone, 'the_page' => $page, 'p_parent_page' => '', 'p_validated' => 1, 'p_edit_date' => NULL, 'p_add_date' => time(), 'p_submitter' => $submitter_id, 'p_show_as_edit' => 0); $content_url = build_url(array('page' => $page), $zone, NULL, false, false, false); $content_url_email_safe = build_url(array('page' => $page), $zone, NULL, false, false, true); return array($zone . ':' . $page, $submitter_id, $cma_info, $content_row, $content_url, $content_url_email_safe); } return array(NULL, NULL, NULL, NULL, NULL, NULL); } if (is_null($cma_info['title_field'])) { $content_title = do_lang($cma_info['content_type_label']); } else { if (strpos($cma_info['title_field'], 'CALL:') !== false) { $content_title = call_user_func(trim(substr($cma_info['title_field'], 5)), array('id' => $content_id)); } else { $_content_title = $content_row[$cma_info['title_field']]; $content_title = $cma_info['title_field_dereference'] ? get_translated_text($_content_title, $db) : $_content_title; if ($content_title == '') { $content_title = do_lang($cma_info['content_type_label']) . ' (#' . (is_string($content_id) ? $content_id : strval($content_id)) . ')'; if ($content_type == 'image' || $content_type == 'video') { require_lang('galleries'); $fullname = $GLOBALS['SITE_DB']->query_value_null_ok('galleries', 'fullname', array('name' => $content_row['cat'])); if (!is_null($fullname)) { $content_title = do_lang('VIEW_' . strtoupper($content_type) . '_IN', get_translated_text($fullname)); } } } } } if (isset($cma_info['submitter_field'])) { if (strpos($cma_info['submitter_field'], ':') !== false) { $bits = explode(':', $cma_info['submitter_field']); $matches = array(); if (preg_match('#' . $bits[1] . '#', $content_row[$bits[0]], $matches) != 0) { $submitter_id = intval($matches[1]); } else { $submitter_id = $GLOBALS['FORUM_DRIVER']->get_guest_id(); } } else { $submitter_id = $content_row[$cma_info['submitter_field']]; } } else { $submitter_id = $GLOBALS['FORUM_DRIVER']->get_guest_id(); } list($zone, $url_bits, $hash) = page_link_decode(str_replace('_WILD', $content_id, $cma_info['view_pagelink_pattern'])); $content_url = build_url($url_bits, $zone, NULL, false, false, false, $hash); $content_url_email_safe = build_url($url_bits, $zone, NULL, false, false, true, $hash); return array($content_title, $submitter_id, $cma_info, $content_row, $content_url, $content_url_email_safe); }
/** * Standard modular run function. * * @param array A map of parameters. * @return tempcode The result of execution. */ function run($map) { require_lang('awards'); require_code('awards'); if (array_key_exists('param', $map)) { $type_id = $map['param']; } else { if (addon_installed('downloads')) { $type_id = 'download'; } else { $hooks = find_all_hooks('systems', 'awards'); $type_id = key($hooks); } } $mode = array_key_exists('mode', $map) ? $map['mode'] : 'recent'; // recent|top|random|all $filter = array_key_exists('filter', $map) ? $map['filter'] : ''; $filter_b = array_key_exists('filter_b', $map) ? $map['filter_b'] : ''; $zone = array_key_exists('zone', $map) ? $map['zone'] : '_SEARCH'; $efficient = (array_key_exists('efficient', $map) ? $map['efficient'] : '1') == '1'; $title = array_key_exists('title', $map) ? $map['title'] : ''; $max = array_key_exists('max', $map) ? intval($map['max']) : 10; $days = array_key_exists('days', $map) && $map['days'] != '' ? intval($map['days']) : NULL; $lifetime = array_key_exists('lifetime', $map) && $map['lifetime'] != '' ? intval($map['lifetime']) : NULL; $pinned = array_key_exists('pinned', $map) && $map['pinned'] != '' ? explode(',', $map['pinned']) : array(); if (!file_exists(get_file_base() . '/sources/hooks/systems/awards/' . filter_naughty_harsh($type_id) . '.php') && !file_exists(get_file_base() . '/sources_custom/hooks/systems/awards/' . filter_naughty_harsh($type_id) . '.php')) { return paragraph(do_lang_tempcode('NO_SUCH_CONTENT_TYPE', $type_id)); } require_code('hooks/systems/awards/' . filter_naughty_harsh($type_id), true); $object = object_factory('Hook_awards_' . $type_id); $info = $object->info($filter_b == '' ? NULL : $filter_b); if (is_null($info)) { warn_exit(do_lang_tempcode('IMPOSSIBLE_TYPE_USED')); } $submit_url = $info['add_url']; if (is_object($submit_url)) { $submit_url = $submit_url->evaluate(); } if (!has_actual_page_access(NULL, $info['cms_page'], NULL, NULL)) { $submit_url = ''; } // Get entries if (is_array($info['category_field'])) { $category_field_access = $info['category_field'][0]; $category_field_filter = $info['category_field'][1]; } else { $category_field_access = $info['category_field']; $category_field_filter = $info['category_field']; } if (array_key_exists('category_type', $info)) { if (is_array($info['category_type'])) { $category_type_access = $info['category_type'][0]; $category_type_filter = $info['category_type'][1]; } else { $category_type_access = $info['category_type']; $category_type_filter = $info['category_type']; } } else { $category_type_access = mixed(); $category_type_filter = mixed(); } $where = ''; $query = 'FROM ' . get_table_prefix() . $info['table'] . ' r'; if (!$GLOBALS['FORUM_DRIVER']->is_super_admin(get_member()) && !$efficient) { $_groups = $GLOBALS['FORUM_DRIVER']->get_members_groups(get_member(), false, true); $groups = ''; foreach ($_groups as $group) { if ($groups != '') { $groups .= ' OR '; } $groups .= 'a.group_id=' . strval((int) $group); } if (!is_null($category_field_access)) { if ($category_type_access === '!') { $query .= ' LEFT JOIN ' . get_table_prefix() . 'group_page_access a ON (r.' . $category_field_filter . '=a.page_name AND r.' . $category_field_access . '=a.zone_name AND (' . $groups . '))'; $query .= ' LEFT JOIN ' . get_table_prefix() . 'group_zone_access a2 ON (r.' . $category_field_access . '=a2.zone_name)'; } else { $query .= ' LEFT JOIN ' . get_table_prefix() . 'group_category_access a ON (' . db_string_equal_to('a.module_the_name', $category_type_access) . ' AND r.' . $category_field_access . '=a.category_name)'; } } if (!is_null($category_field_filter) && $category_field_filter != $category_field_access && $info['category_type'] !== '!') { $query .= ' LEFT JOIN ' . get_table_prefix() . 'group_category_access a2 ON (' . db_string_equal_to('a.module_the_name', $category_type_filter) . ' AND r.' . $category_field_filter . '=a2.category_name)'; } if (!is_null($category_field_access)) { if ($where != '') { $where .= ' AND '; } if ($info['category_type'] === '!') { $where .= '(a.group_id IS NULL) AND (' . str_replace('a.', 'a2.', $groups) . ') AND (a2.group_id IS NOT NULL)'; } else { $where .= '(' . $groups . ') AND (a.group_id IS NOT NULL)'; } } if (!is_null($category_field_filter) && $category_field_filter != $category_field_access && $info['category_type'] !== '!') { if ($where != '') { $where .= ' AND '; } $where .= '(' . str_replace('a.group_id', 'a2.group_id', $groups) . ') AND (a2.group_id IS NOT NULL)'; } if (array_key_exists('where', $info)) { if ($where != '') { $where .= ' AND '; } $where .= $info['where']; } } if (array_key_exists('validated_field', $info) && $info['validated_field'] != '') { if ($where != '') { $where .= ' AND '; } $where .= 'r.' . $info['validated_field'] . '=1'; } $x1 = ''; $x2 = ''; if ($filter != '' && !is_null($category_field_filter)) { $x1 = $this->build_filter($filter, $info, 'r.' . $category_field_filter); } if ($filter_b != '' && !is_null($category_field_access)) { $x2 = $this->build_filter($filter_b, $info, 'r.' . $category_field_access); } if (!is_null($days)) { if ($where != '') { $where .= ' AND '; } $where .= $info['date_field'] . '>=' . strval(time() - 60 * 60 * 24 * $days); } if (is_array($info['id_field'])) { $lifetime = NULL; } // Cannot join on this if (!is_null($lifetime)) { $block_cache_id = md5(serialize($map)); $query .= ' LEFT JOIN ' . $info['connection']->get_table_prefix() . 'feature_lifetime_monitor m ON m.content_id=r.' . $info['id_field'] . ' AND ' . db_string_equal_to('m.block_cache_id', $block_cache_id); if ($where != '') { $where .= ' AND '; } $where .= '(m.run_period IS NULL OR m.run_period<' . strval($lifetime * 60 * 60 * 24) . ')'; } if (array_key_exists('extra_select_sql', $info)) { $extra_select_sql = $info['extra_select_sql']; } else { $extra_select_sql = ''; } if (array_key_exists('extra_table_sql', $info)) { $query .= $info['extra_table_sql']; } if (array_key_exists('extra_where_sql', $info)) { if ($where != '') { $where .= ' AND '; } $where .= $info['extra_where_sql']; } if ($mode == 'all') { if (array_key_exists('title_field', $info) && strpos($info['title_field'], ':') === false) { $query .= ' LEFT JOIN ' . get_table_prefix() . 'translate t ON t.id=r.' . $info['title_field'] . ' AND ' . db_string_equal_to('t.language', user_lang()); } } if ($where . $x1 . $x2 != '') { if ($where == '') { $where = '1=1'; } $query .= ' WHERE ' . $where; if ($x1 != '') { $query .= ' AND (' . $x1 . ')'; } if ($x2 != '') { $query .= ' AND (' . $x2 . ')'; } } if ($mode == 'top' && array_key_exists('feedback_type', $info) && is_null($info['feedback_type'])) { $mode = 'all'; } switch ($mode) { case 'random': $cnt = $info['connection']->query_value_null_ok_full('SELECT COUNT(*) as cnt ' . $query); $rows = $info['connection']->query('SELECT r.*' . $extra_select_sql . ' ' . $query, $max, mt_rand(0, max(0, $cnt - $max))); break; case 'recent': if (array_key_exists('date_field', $info) && !is_null($info['date_field'])) { $rows = $info['connection']->query('SELECT r.*' . $extra_select_sql . ' ' . $query . ' ORDER BY r.' . $info['date_field'] . ' DESC', $max, NULL); break; } case 'views': if (array_key_exists('views_field', $info) && !is_null($info['views_field'])) { $rows = $info['connection']->query('SELECT r.*' . $extra_select_sql . ' ' . $query . ' ORDER BY r.' . $info['views_field'] . ' DESC', $max, NULL); break; } case 'top': if (array_key_exists('feedback_type', $info) && !is_null($info['feedback_type'])) { $select_rating = ',(SELECT AVG(rating) FROM ' . get_table_prefix() . 'rating WHERE ' . db_string_equal_to('rating_for_type', $info['feedback_type']) . ' AND rating_for_id=' . $info['id_field'] . ') AS compound_rating'; $rows = $info['connection']->query('SELECT r.*' . $extra_select_sql . $select_rating . ' ' . $query, $max, NULL, 'ORDER BY compound_rating DESC'); break; } case 'all': if (array_key_exists('title_field', $info) && strpos($info['title_field'], ':') === false) { if ($info['title_field_dereference']) { $rows = $info['connection']->query('SELECT r.*' . $extra_select_sql . ' ' . $query . ' ORDER BY t.text_original ASC', $max, NULL); } else { $rows = $info['connection']->query('SELECT r.*' . $extra_select_sql . ' ' . $query . ' ORDER BY r.' . $info['title_field'] . ' ASC', $max, NULL); } } else { $sql = 'SELECT r.*' . $extra_select_sql . ' ' . $query; if (is_string($info['id_field'])) { $sql .= ' ORDER BY r.' . $info['id_field'] . ' ASC'; } else { $sql .= ' ORDER BY '; foreach ($info['id_field'] as $i => $id_field) { if ($i != 0) { $sql .= ','; } $sql .= 'r.' . $id_field . ' ASC'; } } $rows = $info['connection']->query($sql, $max, NULL); } break; default: $rows = array(); } $pinned_order = array(); require_code('content'); // Add in requested pinned awards foreach ($pinned as $i => $p) { $awarded_rows = $GLOBALS['SITE_DB']->query_select('award_archive', array('*'), array('a_type_id' => intval($p)), 'ORDER BY date_and_time DESC', 1); if (!array_key_exists(0, $awarded_rows)) { continue; } $awarded_row = $awarded_rows[0]; $award_content_row = content_get_row($awarded_row['content_id'], $info); if (!is_null($award_content_row) && (!isset($info['validated_field']) || $award_content_row[$info['validated_field']] != 0)) { $pinned_order[$i] = $award_content_row; } } if (count($pinned_order) > 0) { if (count($rows) > 0) { //Bit inefficient I know, but it'll mean less rewriting of the later code -- Paul $old_rows = $rows; $rows = array(); $total_count = count($old_rows) + count($pinned_order); $used_ids = array(); /* * NOTE: If anything is pinned as the first element, it can't just be passed on directly because * next() will miss the first element of the $old rows array. It is necessary to assess the first * element of the array so if a pinned element must be first, tacking it on to the start of the * array then using the array's first element under either circumstance is the simplest answer. */ if (array_key_exists(0, $pinned_order)) { array_unshift($old_rows, $pinned_order[0]); } reset($old_rows); //Why is there no 'get number _then_ goto next element' function? $temp_row = current($old_rows); $rows[] = $temp_row; $used_ids[] = $temp_row[$info['id_field']]; $n_count = 1; //If duplicates exist, position in the new array needs to be maintained. //Carry on as it should be for ($t_count = 1; $t_count < $total_count; $t_count++) { if (array_key_exists($n_count, $pinned_order)) { if (!in_array($pinned_order[$n_count][$info['id_field']], $used_ids)) { $rows[] = $pinned_order[$n_count]; $used_ids[] = $pinned_order[$n_count][$info['id_field']]; $n_count++; } else { $temp_row = next($old_rows); if (!in_array($temp_row[$info['id_field']], $used_ids)) { $rows[] = $temp_row; $used_ids[] = $temp_row[$info['id_field']]; $n_count++; } } } else { $temp_row = next($old_rows); if (!in_array($temp_row[$info['id_field']], $used_ids)) { $rows[] = $temp_row; $used_ids[] = $temp_row[$info['id_field']]; $n_count++; } } } } else { switch ($mode) { case 'recent': if (array_key_exists('date_field', $info)) { global $M_SORT_KEY; $M_SORT_KEY = $info['date_field']; usort($pinned_order, 'multi_sort'); $rows = array_reverse($pinned_order); } break; case 'views': if (array_key_exists('views_field', $info)) { global $M_SORT_KEY; $M_SORT_KEY = $info['views_field']; usort($pinned_order, 'multi_sort'); $rows = array_reverse($pinned_order); } break; } } } // Sort out run periods if (!is_null($lifetime)) { $lifetime_monitor = list_to_map('content_id', $GLOBALS['SITE_DB']->query_select('feature_lifetime_monitor', array('content_id', 'run_period', 'last_update'), array('block_cache_id' => $block_cache_id, 'running_now' => 1))); } // Render $archive_url = $info['archive_url']; $view_url = array_key_exists('view_url', $info) ? $info['view_url'] : new ocp_tempcode(); $done_already = array(); // We need to keep track, in case those pulled up via awards would also come up naturally $rendered_content = array(); $content_data = array(); foreach ($rows as $row) { if (count($done_already) == $max) { break; } // Get content ID if (is_array($info['id_field'])) { $content_id = ''; foreach ($info['id_field'] as $f) { if ($content_id != '') { $content_id .= ':'; } $x = $row[$f]; if (!is_string($x)) { $x = strval($x); } $content_id .= $x; } } else { $content_id = $row[$info['id_field']]; if (!is_string($content_id)) { $content_id = strval($content_id); } } if (array_key_exists($content_id, $done_already)) { continue; } $done_already[$content_id] = 1; // Lifetime managing if (!is_null($lifetime)) { if (!array_key_exists($content_id, $lifetime_monitor)) { // Test to see if it is actually there in the past - we only loaded the "running now" ones for performance reasons. Any new ones coming will trigger extra queries to see if they've been used before, as a tradeoff to loading potentially 10's of thousands of rows. $lifetime_monitor += list_to_map('content_id', $GLOBALS['SITE_DB']->query_select('feature_lifetime_monitor', array('content_id', 'run_period', 'last_update'), array('block_cache_id' => $block_cache_id, 'content_id' => $content_id))); } if (array_key_exists($content_id, $lifetime_monitor)) { $GLOBALS['SITE_DB']->query_update('feature_lifetime_monitor', array('run_period' => $lifetime_monitor[$content_id]['run_period'] + (time() - $lifetime_monitor[$content_id]['last_update']), 'running_now' => 1, 'last_update' => time()), array('content_id' => $content_id, 'block_cache_id' => $block_cache_id)); unset($lifetime_monitor[$content_id]); } else { $GLOBALS['SITE_DB']->query_insert('feature_lifetime_monitor', array('content_id' => $content_id, 'block_cache_id' => $block_cache_id, 'run_period' => 0, 'running_now' => 1, 'last_update' => time())); } } // Render $rendered_content[] = $object->run($row, $zone); // Try and get a better submit url $submit_url = str_replace('%21', $content_id, $submit_url); $content_data[] = array('URL' => str_replace('%21', $content_id, $view_url->evaluate())); } // Sort out run periods of stuff gone if (!is_null($lifetime)) { foreach (array_keys($lifetime_monitor) as $content_id) { if (is_integer($content_id)) { $content_id = strval($content_id); } $GLOBALS['SITE_DB']->query_update('feature_lifetime_monitor', array('run_period' => $lifetime_monitor[$content_id]['run_period'] + (time() - $lifetime_monitor[$content_id]['last_update']), 'running_now' => 0, 'last_update' => time()), array('content_id' => $content_id, 'block_cache_id' => $block_cache_id)); } } if (array_key_exists('no_links', $map) && $map['no_links'] == '1') { $submit_url = ''; $archive_url = ''; } return do_template('BLOCK_MAIN_MULTI_CONTENT', array('TYPE' => $info['title'], 'TITLE' => $title, 'CONTENT' => $rendered_content, 'CONTENT_DATA' => $content_data, 'SUBMIT_URL' => $submit_url, 'ARCHIVE_URL' => $archive_url)); }
/** * Standard modular run function. * * @param array A map of parameters. * @return tempcode The result of execution. */ function run($map) { require_lang('awards'); require_code('awards'); $award = array_key_exists('param', $map) ? intval($map['param']) : db_get_first_id(); $zone = array_key_exists('zone', $map) ? $map['zone'] : '_SEARCH'; $_award_type_row = $GLOBALS['SITE_DB']->query_select('award_types', array('*'), array('id' => $award), '', 1); if (!array_key_exists(0, $_award_type_row)) { return do_lang_tempcode('MISSING_RESOURCE'); } $award_type_row = $_award_type_row[0]; $award_title = get_translated_text($award_type_row['a_title']); $award_description = get_translated_text($award_type_row['a_description']); if (!file_exists(get_file_base() . '/sources/hooks/systems/awards/' . filter_naughty_harsh($award_type_row['a_content_type']) . '.php') && !file_exists(get_file_base() . '/sources_custom/hooks/systems/awards/' . filter_naughty_harsh($award_type_row['a_content_type']) . '.php')) { return paragraph(do_lang_tempcode('NO_SUCH_CONTENT_TYPE', $award_type_row['a_content_type'])); } require_code('hooks/systems/awards/' . filter_naughty_harsh($award_type_row['a_content_type'])); $object = object_factory('Hook_awards_' . $award_type_row['a_content_type']); $info = $object->info(); if (is_null($info)) { return do_lang_tempcode('IMPOSSIBLE_TYPE_USED'); } $submit_url = $info['add_url']; if (is_object($submit_url)) { $submit_url = $submit_url->evaluate(); } if (!has_actual_page_access(NULL, $info['cms_page'], NULL, NULL)) { $submit_url = ''; } if (!has_category_access(get_member(), 'award', strval($award))) { $submit_url = ''; } if ($submit_url != '') { if (strpos($submit_url, '?') === false) { $submit_url .= '?'; } else { $submit_url .= '&'; } $submit_url .= 'award=' . strval($award); } require_code('content'); $sup = ''; do { $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'award_archive WHERE a_type_id=' . strval($award) . ' ' . $sup . ' ORDER BY date_and_time DESC', 1); if (!array_key_exists(0, $rows)) { return do_template('BLOCK_NO_ENTRIES', array('_GUID' => 'f32b50770fd6581c4a2c839a1ed25801', 'HIGH' => false, 'TITLE' => $award_title, 'MESSAGE' => do_lang_tempcode('NO_AWARD'), 'ADD_NAME' => do_lang_tempcode('ADD'), 'SUBMIT_URL' => str_replace('=!', '__ignore=1', $submit_url))); } $myrow = $rows[0]; $submit_url = str_replace('!', $myrow['content_id'], $submit_url); $award_content_row = content_get_row($myrow['content_id'], $info); $sup = ' AND date_and_time<' . strval($myrow['date_and_time']); } while (is_null($award_content_row)); $archive_url = build_url(array('page' => 'awards', 'type' => 'award', 'id' => $award), get_module_zone('awards')); $rendered_content = $object->run($award_content_row, $zone); if ($award_type_row['a_hide_awardee'] == 1 || is_guest($myrow['member_id'])) { $awardee = ''; $awardee_username = ''; $awardee_profile_url = ''; } else { $awardee = strval($myrow['member_id']); $awardee_username = $GLOBALS['FORUM_DRIVER']->get_username($myrow['member_id']); if (is_null($awardee_username)) { $awardee_username = do_lang('UNKNOWN'); } $awardee_profile_url = $GLOBALS['FORUM_DRIVER']->member_profile_url($myrow['member_id'], true, true); } return do_template('BLOCK_MAIN_AWARDS', array('_GUID' => '99f092e35db0c17f407f40ed55c42cfd', 'TITLE' => $award_title, 'TYPE' => $award_type_row['a_content_type'], 'DESCRIPTION' => $award_description, 'AWARDEE_PROFILE_URL' => $awardee_profile_url, 'AWARDEE' => $awardee, 'AWARDEE_USERNAME' => $awardee_username, 'RAW_AWARD_DATE' => strval($myrow['date_and_time']), 'AWARD_DATE' => get_timezoned_date($myrow['date_and_time']), 'CONTENT' => $rendered_content, 'SUBMIT_URL' => $submit_url, 'ARCHIVE_URL' => $archive_url)); }
/** * The UI to view the archive for an award type. * * @return tempcode The UI */ function award() { breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('CHOOSE')))); require_css('awards'); $id = get_param_integer('id'); $_award_type_row = $GLOBALS['SITE_DB']->query_select('award_types', array('*'), array('id' => $id), '', 1); if (!array_key_exists(0, $_award_type_row)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $award_type_row = $_award_type_row[0]; require_code('hooks/systems/awards/' . filter_naughty_harsh($award_type_row['a_content_type']), true); $object = object_factory('Hook_awards_' . $award_type_row['a_content_type']); $info = $object->info(); if (is_null($info)) { fatal_exit(do_lang_tempcode('INTERNAL_ERROR')); } global $NON_CANONICAL_PARAMS; $NON_CANONICAL_PARAMS[] = 'max'; $start = get_param_integer('start', 0); $max = get_param_integer('max', 20); $title = get_page_title('_AWARD', true, array(escape_html(get_translated_text($award_type_row['a_title'])))); $description = paragraph(get_translated_tempcode($award_type_row['a_description']), 'grdgdfghdfgodfs'); $rows = $GLOBALS['SITE_DB']->query_select('award_archive', array('*'), array('a_type_id' => $id), 'ORDER BY date_and_time DESC', $max, $start); $max_rows = $GLOBALS['SITE_DB']->query_value('award_archive', 'COUNT(*)', array('a_type_id' => $id)); $content = new ocp_tempcode(); foreach ($rows as $myrow) { require_code('content'); $award_content_row = content_get_row($myrow['content_id'], $info); if (!is_null($award_content_row)) { $rendered_content = $object->run($award_content_row, '_SEARCH'); if ($award_type_row['a_hide_awardee'] == 1 || is_guest($myrow['member_id'])) { $awardee = ''; $awardee_username = ''; $awardee_profile_url = ''; } else { $awardee = strval($myrow['member_id']); $awardee_username = $GLOBALS['FORUM_DRIVER']->get_username($myrow['member_id']); if (is_null($awardee_username)) { $awardee_username = do_lang('UNKNOWN'); } $awardee_profile_url = $GLOBALS['FORUM_DRIVER']->member_profile_url($myrow['member_id'], false, true); } $content->attach(do_template('AWARDED_CONTENT', array('_GUID' => '1a2a5b6e9b53a99e303b7ed17070cea9', 'AWARDEE_PROFILE_URL' => $awardee_profile_url, 'AWARDEE' => $awardee, 'AWARDEE_USERNAME' => $awardee_username, 'RAW_AWARD_DATE' => strval($myrow['date_and_time']), 'AWARD_DATE' => get_timezoned_date($myrow['date_and_time'], false, false, false, true), 'CONTENT' => $rendered_content))); $content->attach(do_template('BLOCK_SEPARATOR', array())); } } if ($content->is_empty()) { if (has_category_access(get_member(), 'award', strval($id))) { inform_exit(do_lang_tempcode('NO_ENTRIES_AWARDS', escape_html($info['title']))); } inform_exit(do_lang_tempcode('NO_ENTRIES')); } $page_num = intval(floor(floatval($start) / floatval($max))) + 1; $num_pages = intval(ceil(floatval($max_rows) / floatval($max))); $previous_url = $start == 0 ? new ocp_tempcode() : build_url(array('page' => '_SELF', 'start' => $start - $max == 0 ? NULL : $start - $max), '_SELF'); $next_url = count($rows) != $max ? new ocp_tempcode() : build_url(array('page' => '_SELF', 'start' => $start + $max), '_SELF'); $browse = do_template('NEXT_BROWSER_BROWSE_NEXT', array('_GUID' => '54690cd3d6ea1ee0722271ab428e6a31', 'NEXT_LINK' => $next_url, 'PREVIOUS_LINK' => $previous_url, 'PAGE_NUM' => integer_format($page_num), 'NUM_PAGES' => integer_format($num_pages))); $sub_title = do_lang_tempcode('AWARD_HISTORY'); return do_template('NEXT_BROWSER_SCREEN', array('_GUID' => 'b9cf3a37300aced490003f79d7bb4914', 'TITLE' => $title, 'SUB_TITLE' => $sub_title, 'DESCRIPTION' => $description, 'CONTENT' => $content, 'BROWSE' => $browse)); }