/** * Standard modular run function. * * @param array A map of parameters. * @return tempcode The result of execution. */ function run($map) { require_code('downloads'); require_css('downloads'); require_lang('downloads'); $zone = array_key_exists('zone', $map) ? $map['zone'] : get_module_zone('downloads'); global $NON_CANONICAL_PARAMS; $NON_CANONICAL_PARAMS[] = 'max'; $max = get_param_integer('max', 10); if ($max < 1) { $max = 1; } $start = get_param_integer('start', 0); $rows = $GLOBALS['SITE_DB']->query_select('download_downloads', array('*'), array('validated' => 1), 'ORDER BY num_downloads DESC', $max, $start); $content = new ocp_tempcode(); foreach ($rows as $i => $row) { if ($i != 0) { $content->attach(do_template('BLOCK_SEPARATOR')); } $content->attach(get_download_html($row, true, true, $zone)); } $page_num = intval(floor(floatval($start) / floatval($max))) + 1; $count = $GLOBALS['SITE_DB']->query_value('download_downloads', 'COUNT(*)', array('validated' => 1)); $num_pages = intval(ceil(floatval($count) / floatval($max))); if ($num_pages == 0) { $page_num = 0; } $previous_url = $start == 0 ? new ocp_tempcode() : build_url(array('page' => '_SELF', 'start' => $start - $max), '_SELF'); $next_url = $page_num == $num_pages ? new ocp_tempcode() : build_url(array('page' => '_SELF', 'start' => $start + $max), '_SELF'); $browse = do_template('NEXT_BROWSER_BROWSE_NEXT', array('_GUID' => '15ca70ec400629f67edefa869fb1f1a8', 'NEXT_LINK' => $next_url, 'PREVIOUS_LINK' => $previous_url, 'PAGE_NUM' => integer_format($page_num), 'NUM_PAGES' => integer_format($num_pages))); return do_template('BLOCK_MAIN_DOWNLOAD_TEASE', array('_GUID' => 'a164e33c0b4ace4bae945c39f2f00ca9', 'CONTENT' => $content, 'BROWSE' => $browse)); }
/** * Standard modular run function. * * @param array A map of parameters. * @return tempcode The result of execution. */ function run($map) { require_code('downloads'); require_css('downloads'); require_lang('downloads'); require_code('ocfiltering'); $number = array_key_exists('param', $map) ? intval($map['param']) : 10; $filter = array_key_exists('filter', $map) ? $map['filter'] : '*'; $zone = array_key_exists('zone', $map) ? $map['zone'] : get_module_zone('downloads'); $sql_filter = ocfilter_to_sqlfragment($filter, 'p.category_id', 'download_categories', 'parent_id', 'p.category_id', 'id'); // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set) $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'download_downloads p WHERE validated=1 AND (' . $sql_filter . ') ORDER BY add_date DESC', $number); $title = do_lang_tempcode('RECENT', make_string_tempcode(integer_format($number)), do_lang_tempcode('SECTION_DOWNLOADS')); if (array_key_exists('title', $map) && $map['title'] != '') { $title = protect_from_escaping(escape_html($map['title'])); } $out = new ocp_tempcode(); foreach ($rows as $i => $row) { if ($i != 0) { $out->attach(do_template('BLOCK_SEPARATOR')); } $out->attach(get_download_html($row, true, true, $zone)); } if ($out->is_empty()) { if (has_actual_page_access(NULL, 'cms_downloads', NULL, NULL) && has_submit_permission('mid', get_member(), get_ip_address(), 'cms_downloads')) { $submit_url = build_url(array('page' => 'cms_downloads', 'type' => 'ad', 'redirect' => SELF_REDIRECT), get_module_zone('cms_downloads')); } else { $submit_url = new ocp_tempcode(); } return do_template('BLOCK_NO_ENTRIES', array('_GUID' => '74399763a51102bdd6e6d92c2c11354f', 'HIGH' => false, 'TITLE' => $title, 'MESSAGE' => do_lang_tempcode('NO_DOWNLOADS_YET'), 'ADD_NAME' => do_lang_tempcode('ADD_DOWNLOAD'), 'SUBMIT_URL' => $submit_url)); } return do_template('BLOCK_MAIN_RECENT_DOWNLOADS', array('_GUID' => '257fa1b83d1b6fe3acbceb2b618e6d7f', 'TITLE' => $title, 'CONTENT' => $out, 'NUMBER' => integer_format($number))); }
/** * Get tempcode to view the downloads in a download category. * * @param AUTO_LINK The download category ID * @param AUTO_LINK The virtual root * @param ?string Force an order (NULL: don't) * @return tempcode The UI */ function get_category_downloads($category_id, $root, $order = NULL) { $max = get_param_integer('max', 30); $start = get_param_integer('start', 0); // How many might there have been? (So we know how to browse pages nicely) $map = array('category_id' => $category_id); if (!has_specific_permission(get_member(), 'see_unvalidated')) { $map['validated'] = 1; } $max_rows = $GLOBALS['SITE_DB']->query_value('download_downloads', 'COUNT(*)', $map); // Quick security check if (is_null($order)) { $order = get_param('order', NULL); if (is_null($order)) { if ($max_rows < 1000) { $order = 't.text_original ASC'; } else { $order = 'num_downloads DESC'; } } } if (strtoupper($order) != strtoupper('t.text_original ASC') && strtoupper($order) != strtoupper('t.text_original DESC') && strtoupper($order) != strtoupper('file_size ASC') && strtoupper($order) != strtoupper('file_size DESC') && strtoupper($order) != strtoupper('num_downloads DESC') && strtoupper($order) != strtoupper('add_date ASC') && strtoupper($order) != strtoupper('add_date DESC')) { log_hack_attack_and_exit('ORDERBY_HACK'); } global $NON_CANONICAL_PARAMS; $NON_CANONICAL_PARAMS[] = 'order'; // Fetch $rows = $GLOBALS['SITE_DB']->query_select('download_downloads d LEFT JOIN ' . get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND d.name=t.id', array('d.*', 'text_original'), $map, 'ORDER BY ' . $order, $max, $start); $out = new ocp_tempcode(); foreach ($rows as $myrow) { if ($GLOBALS['RECORD_LANG_STRINGS_CONTENT'] || is_null($myrow['text_original'])) { $myrow['text_original'] = get_translated_text($myrow['description']); } $out->attach(get_download_html($myrow, true, false)); $out->attach(do_template('BLOCK_SEPARATOR', array('_GUID' => 'ea7sddsdsfds5bsddsdsdsc586e6e6536'))); } if ($out->is_empty()) { return $out; } require_code('templates_results_browser'); $out->attach(results_browser(do_lang_tempcode('SECTION_DOWNLOADS'), $category_id, $start, 'start', $max, 'max', $max_rows, $root, 'misc')); return $out; }
/** * The UI to view a download index. * * @return tempcode The UI */ function show_all_downloads() { $title = get_page_title('SECTION_DOWNLOADS'); $id = get_param('id', strval(db_get_first_id())); require_code('ocfiltering'); $sql_filter = ocfilter_to_sqlfragment(is_numeric($id) ? $id . '*' : $id, 'p.category_id', 'download_categories', 'parent_id', 'p.category_id', 'id'); // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set) if ($GLOBALS['SITE_DB']->query_value('download_downloads', 'COUNT(*)') > 1000) { warn_exit(do_lang_tempcode('TOO_MANY_TO_CHOOSE_FROM')); } $cats = array(); $rows = $GLOBALS['SITE_DB']->query('SELECT p.*,text_original FROM ' . get_table_prefix() . 'download_downloads p LEFT JOIN ' . get_table_prefix() . 'translate t ON t.id=p.name AND ' . db_string_equal_to('language', user_lang()) . ' WHERE validated=1 AND (' . $sql_filter . ') ORDER BY text_original ASC'); foreach ($rows as $row) { if ($GLOBALS['RECORD_LANG_STRINGS_CONTENT'] || is_null($row['text_original'])) { $row['text_original'] = get_translated_text($row['name']); } $letter = strtoupper(substr($row['text_original'], 0, 1)); if (!has_category_access(get_member(), 'downloads', strval($row['category_id']))) { continue; } if (!array_key_exists($letter, $cats)) { $cats[$letter] = array(); } $cats[$letter][] = $row; } unset($rows); $subcats = array(); foreach ($cats as $letter => $rows) { if (!is_string($letter)) { $letter = strval($letter); } // Numbers come out as numbers not strings, even if they went in as strings- darned PHP $has_download = false; $data = array(); $data['CAT_TITLE'] = $letter; $data['LETTER'] = $letter; $out = new ocp_tempcode(); foreach ($rows as $myrow) { $out->attach(get_download_html($myrow)); $has_download = true; } $data['DOWNLOADS'] = $out; $subcats[] = $data; } if (is_numeric($id) && has_actual_page_access(NULL, 'cms_downloads', NULL, array('downloads', $id), 'submit_midrange_content')) { $submit_url = build_url(array('page' => 'cms_downloads', 'type' => 'ad', 'cat' => $id), get_module_zone('cms_downloads')); } else { $submit_url = new ocp_tempcode(); } if (is_numeric($id) && has_actual_page_access(NULL, 'cms_downloads', NULL, array('downloads', $id), 'submit_cat_midrange_content')) { $add_cat_url = build_url(array('page' => 'cms_downloads', 'type' => 'ac', 'parent_id' => $id), get_module_zone('cms_downloads')); } else { $add_cat_url = new ocp_tempcode(); } if (is_numeric($id) && has_actual_page_access(NULL, 'cms_downloads', NULL, array('downloads', $id), 'edit_cat_midrange_content')) { $edit_cat_url = build_url(array('page' => 'cms_downloads', 'type' => '_ec', 'id' => $id), get_module_zone('cms_downloads')); } else { $edit_cat_url = new ocp_tempcode(); } return do_template('DOWNLOAD_ALL_SCREEN', array('TITLE' => $title, 'SUBMIT_URL' => $submit_url, 'ADD_CAT_URL' => $add_cat_url, 'EDIT_CAT_URL' => $edit_cat_url, 'SUB_CATEGORIES' => $subcats)); }
/** * Standard modular run function for rendering a search result. * * @param array The data row stored when we retrieved the result * @return tempcode The output */ function render($row) { global $SEARCH__CONTENT_BITS; $highlight_bits = is_null($SEARCH__CONTENT_BITS) ? array() : $SEARCH__CONTENT_BITS; if (array_key_exists(0, $highlight_bits)) { $pos = strpos($row['download_data_mash'], $highlight_bits[0]) - 1000; } else { $pos = 0; } $mash_portion = substr($row['download_data_mash'], $pos, 10000); $_text_summary = trim(preg_replace('#\\s+#', ' ', $mash_portion)); if ($_text_summary === false) { $_text_summary = ''; } global $LAX_COMCODE; $LAX_COMCODE = true; $text_summary_h = comcode_to_tempcode($_text_summary, NULL, false, 60, NULL, NULL, false, false, false, false, false, $highlight_bits); $LAX_COMCODE = false; $text_summary = generate_text_summary($text_summary_h->evaluate(), $highlight_bits); return get_download_html($row, true, true, NULL, $text_summary); }
/** * Standard modular run function for award hooks. Renders a content box for an award/randomisation. * * @param array The database row for the content * @param ID_TEXT The zone to display in * @return tempcode Results */ function run($row, $zone) { require_code('downloads'); return get_download_html($row, true, true, $zone); }
/** * The UI to view an author. * * @return tempcode The UI */ function show_author() { $author = get_param('id', NULL); if (is_null($author)) { if (is_guest()) { global $EXTRA_HEAD; $EXTRA_HEAD->attach('<meta name="robots" content="noindex" />'); // XHTMLXHTML warn_exit(do_lang_tempcode('USER_NO_EXIST')); } $author = $GLOBALS['FORUM_DRIVER']->get_username(get_member()); } if (is_null($author) || $author == '') { warn_exit(do_lang_tempcode('INTERNAL_ERROR')); } // Really don't want to have to search on this if (addon_installed('awards')) { require_code('awards'); $awards = find_awards_for('author', $author); } else { $awards = array(); } $title = get_page_title('_AUTHOR', true, array(escape_html($author)), NULL, $awards); seo_meta_load_for('authors', $author); $rows = $GLOBALS['SITE_DB']->query_select('authors', array('url', 'description', 'skills'), array('author' => $author), '', 1); if (!array_key_exists(0, $rows)) { if (has_actual_page_access(get_member(), 'cms_authors') && has_edit_author_permission(get_member(), $author)) { $GLOBALS['HTTP_STATUS_CODE'] = '404'; if (!headers_sent()) { if (!browser_matches('ie') && strpos(ocp_srv('SERVER_SOFTWARE'), 'IIS') === false) { header('HTTP/1.0 404 Not Found'); } } $_author_add_url = build_url(array('page' => 'cms_authors', 'type' => '_ad', 'author' => $author), get_module_zone('cms_authors')); $author_add_url = $_author_add_url->evaluate(); $message = do_lang_tempcode('NO_SUCH_AUTHOR_CONFIGURE_ONE', escape_html($author), escape_html($author_add_url)); attach_message($message, 'inform'); } else { $message = do_lang_tempcode('NO_SUCH_AUTHOR', escape_html($author)); } $details = array('author' => $author, 'url' => '', 'forum_handle' => $GLOBALS['FORUM_DRIVER']->get_member_from_username($author), 'description' => NULL, 'skills' => NULL); //return inform_screen($title,$message); } else { $details = $rows[0]; } // Links associated with the mapping between the author and a forum member $handle = get_author_id_from_name($author); if (!is_null($handle)) { $forum_details = do_template('AUTHOR_SCREEN_POTENTIAL_ACTION_ENTRY', array('ACTION' => hyperlink($GLOBALS['FORUM_DRIVER']->member_profile_url($handle, true, true), do_lang_tempcode('AUTHOR_PROFILE'), false, false, '', NULL, NULL, 'me'))); if (addon_installed('points')) { $give_points_url = build_url(array('page' => 'points', 'type' => 'member', 'id' => $handle), get_module_zone('points')); $point_details = do_template('AUTHOR_SCREEN_POTENTIAL_ACTION_ENTRY', array('ACTION' => hyperlink($give_points_url, do_lang_tempcode('AUTHOR_POINTS')))); } else { $point_details = new ocp_tempcode(); } } else { $forum_details = new ocp_tempcode(); $point_details = new ocp_tempcode(); } // Homepage $url = $details['url']; if (strlen($url) > 0) { $url_details = do_template('AUTHOR_SCREEN_POTENTIAL_ACTION_ENTRY', array('ACTION' => hyperlink($url, do_lang_tempcode('AUTHOR_HOMEPAGE'), false, false, '', NULL, NULL, 'me'))); } else { $url_details = new ocp_tempcode(); } // (Self?) description $description = is_null($details['description']) ? new ocp_tempcode() : get_translated_tempcode($details['description']); // Skills $skills = is_null($details['skills']) ? new ocp_tempcode() : get_translated_tempcode($details['skills']); // Edit link, for staff if (has_edit_author_permission(get_member(), $author)) { $edit_author_url = build_url(array('page' => 'cms_authors', 'type' => '_ad', 'author' => $author), get_module_zone('cms_authors')); $staff_details = do_template('AUTHOR_SCREEN_POTENTIAL_ACTION_ENTRY', array('ACTION' => hyperlink($edit_author_url, do_lang_tempcode('DEFINE_AUTHOR'), false))); } else { $staff_details = new ocp_tempcode(); } // Search link if (addon_installed('search')) { $search_url = build_url(array('page' => 'search', 'author' => $author), get_module_zone('search')); $search_details = do_template('AUTHOR_SCREEN_POTENTIAL_ACTION_ENTRY', array('ACTION' => hyperlink($search_url, do_lang_tempcode('SEARCH'), false))); } else { $search_details = new ocp_tempcode(); } // Downloads $downloads_released = new ocp_tempcode(); if (addon_installed('downloads')) { require_code('downloads'); require_lang('downloads'); $count = $GLOBALS['SITE_DB']->query_value('download_downloads', 'COUNT(*)', array('author' => $author, 'validated' => 1)); if ($count > 50) { $downloads_released = paragraph(do_lang_tempcode('TOO_MANY_TO_CHOOSE_FROM')); } else { $rows = $GLOBALS['SITE_DB']->query_select('download_downloads', array('*'), array('author' => $author, 'validated' => 1)); require_code('downloads'); foreach ($rows as $i => $myrow) { if ($i != 0) { $downloads_released->attach(do_template('BLOCK_SEPARATOR', array('_GUID' => 'ea789367b15bsddsdsdsc586e6e6536'))); } if (has_category_access(get_member(), 'downloads', strval($myrow['category_id']))) { $downloads_released->attach(get_download_html($myrow)); } } } } // News $news_released = new ocp_tempcode(); if (addon_installed('news')) { require_lang('news'); $count = $GLOBALS['SITE_DB']->query_value('news', 'COUNT(*)', array('author' => $author, 'validated' => 1)); if ($count > 50) { $news_released = paragraph(do_lang_tempcode('TOO_MANY_TO_CHOOSE_FROM')); } else { $rows = $GLOBALS['SITE_DB']->query_select('news', array('*'), array('author' => $author, 'validated' => 1)); foreach ($rows as $i => $row) { if (has_category_access(get_member(), 'news', strval($row['news_category']))) { $url = build_url(array('page' => 'news', 'type' => 'view', 'id' => $row['id']), get_module_zone('news')); $_title = get_translated_tempcode($row['title']); $title_plain = get_translated_text($row['title']); $seo_bits = seo_meta_get_for('news', strval($row['id'])); $map = array('ID' => strval($row['id']), 'TAGS' => get_loaded_tags('news', explode(',', $seo_bits[0])), 'SUBMITTER' => strval($row['submitter']), 'DATE' => get_timezoned_date($row['date_and_time']), 'DATE_RAW' => strval($row['date_and_time']), 'URL' => $url, 'TITLE_PLAIN' => $title_plain, 'TITLE' => $_title); if (get_option('is_on_comments') == '1' && !has_no_forum() && $row['allow_comments'] >= 1) { $map['COMMENT_COUNT'] = '1'; } $tpl = do_template('NEWS_BRIEF', $map); $news_released->attach($tpl); } } } } // Edit link $edit_url = new ocp_tempcode(); if (has_edit_author_permission(get_member(), $author)) { $edit_url = build_url(array('page' => 'cms_authors', 'type' => '_ad', 'id' => $author), 'cms'); } return do_template('AUTHOR_SCREEN', array('_GUID' => 'ea789367b15bc90fc28d1c586e6e6536', 'TAGS' => get_loaded_tags(), 'TITLE' => $title, 'EDIT_URL' => $edit_url, 'AUTHOR' => $author, 'NEWS_RELEASED' => $news_released, 'DOWNLOADS_RELEASED' => $downloads_released, 'STAFF_DETAILS' => $staff_details, 'POINT_DETAILS' => $point_details, 'SEARCH_DETAILS' => $search_details, 'URL_DETAILS' => $url_details, 'FORUM_DETAILS' => $forum_details, 'SKILLS' => $skills, 'DESCRIPTION' => $description)); }