function do_postchecks() { global $context, $txt, $settings, $boarddir, $smcFunc, $sourcedir; // If we have any setting changes add them to this array $updateArray = array(); // which screen do we come frm? if (!empty($_POST['tpadmin_form'])) { // get it $from = $_POST['tpadmin_form']; //news if ($from == 'news') { return 'news'; } elseif ($from == 'blockoverview') { checkSession('post'); isAllowedTo('tp_blocks'); $block = array(); foreach ($_POST as $what => $value) { if (substr($what, 5, 7) == 'tpblock') { // get the id $bid = substr($what, 12); if (!isset($block[$bid])) { $block[$bid] = array(); } if ($value != 'control' && !in_array($value, $block[$bid])) { $block[$bid][] = $value; } } } foreach ($block as $bl => $blo) { $request = $smcFunc['db_query']('', ' SELECT access FROM {db_prefix}tp_blocks WHERE id = {int:blockid}', array('blockid' => $bl)); if ($smcFunc['db_num_rows']($request) > 0) { $row = $smcFunc['db_fetch_assoc']($request); $smcFunc['db_free_result']($request); $request = $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_blocks SET access = {string:access} WHERE id = {int:blockid}', array('access' => implode(',', $blo), 'blockid' => $bl)); } } return 'blocks;overview'; } elseif (in_array($from, array('settings', 'frontpage', 'artsettings', 'panels'))) { checkSession('post'); isAllowedTo('tp_settings'); $w = array(); $ssi = array(); foreach ($_POST as $what => $value) { if (substr($what, 0, 3) == 'tp_') { $where = substr($what, 3); $clean = $value; // for frontpage, do some extra if ($from == 'frontpage') { if (substr($what, 0, 20) == 'tp_frontpage_visual_') { $w[] = substr($what, 20); unset($clean); } elseif (substr($what, 0, 21) == 'tp_frontpage_usorting') { $w[] = 'sort_' . $value; unset($clean); } elseif (substr($what, 0, 26) == 'tp_frontpage_sorting_order') { $w[] = 'sortorder_' . $value; unset($clean); } elseif (substr($what, 0, 11) == 'tp_ssiboard') { if ($value != 0) { $ssi[$value] = $value; } } } if ($from == 'settings' && $what == 'tp_frontpage_title') { $updateArray['frontpage_title'] = $clean; } else { if (isset($clean)) { $updateArray[$where] = $clean; } } } } // check the frontpage visual setting.. if ($from == 'frontpage') { $updateArray['frontpage_visual'] = implode(',', $w); $updateArray['SSI_board'] = implode(',', $ssi); } updateTPSettings($updateArray); return $from; } elseif ($from == 'categories') { checkSession('post'); isAllowedTo('tp_articles'); foreach ($_POST as $what => $value) { if (substr($what, 0, 3) == 'tp_') { // for frontpage, do some extra if ($from == 'categories') { if (substr($what, 0, 19) == 'tp_category_value2_') { $where = tp_sanitize(substr($what, 19)); //make sure parent are not its own parent $request = $smcFunc['db_query']('', ' SELECT value2 FROM {db_prefix}tp_variables WHERE id = {string:varid} LIMIT 1', array('varid' => $value)); $row = $smcFunc['db_fetch_assoc']($request); $smcFunc['db_free_result']($request); if ($row['value2'] == $where) { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET value2 = {string:val2} WHERE id = {string:varid} LIMIT 1', array('val2' => '0', 'varid' => $value)); } $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET value2 = {string:val2} WHERE id = {string:varid} LIMIT 1', array('val2' => $value, 'varid' => $where)); } } } } return $from; } elseif ($from == 'articles') { checkSession('post'); isAllowedTo('tp_articles'); foreach ($_POST as $what => $value) { if (substr($what, 0, 14) == 'tp_article_pos') { $where = tp_sanitize(substr($what, 14)); $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET parse = {int:parse} WHERE id = {int:artid} LIMIT 1', array('parse' => $value, 'artid' => $where)); } } if (isset($_POST['tpadmin_form_category']) && is_numeric($_POST['tpadmin_form_category'])) { return $from . ';cu=' . $_POST['tpadmin_form_category']; } else { return $from; } } elseif ($from == 'modules') { checkSession('post'); isAllowedTo('tp_settings'); foreach ($_POST as $what => $value) { if ($what == 'tp_show_download') { $updateArray['show_download'] = $value; } elseif (substr($what, 0, 14) == 'tpmodule_state') { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_modules SET active = {int:active} WHERE id = {int:modid}', array('active' => $value, 'modid' => substr($what, 14))); } } updateTPSettings($updateArray); return $from; } elseif ($from == 'menuitems') { checkSession('post'); isAllowedTo('tp_blocks'); $all = explode(',', $context['TPortal']['sitemap_items']); foreach ($_POST as $what => $value) { if (substr($what, 0, 8) == 'menu_pos') { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET subtype = {string:subtype} WHERE id = {int:varid}', array('subtype' => tp_sanitize($value), 'varid' => substr($what, 8))); } elseif (substr($what, 0, 8) == 'menu_sub') { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET value4 = {string:val4} WHERE id = {int:varid}', array('val4' => tp_sanitize($value), 'varid' => substr($what, 8))); } elseif (substr($what, 0, 15) == 'tp_menu_sitemap') { $new = substr($what, 15); if ($value == 0 && in_array($new, $all)) { foreach ($all as $key => $value) { if ($all[$key] == $new) { unset($all[$key]); } } } elseif ($value == 1 && !in_array($new, $all)) { $all[] = $new; } $updateArray['sitemap_items'] = implode(',', $all); } } updateTPSettings($updateArray); redirectexit('action=tpadmin;sa=menubox;mid=' . $_POST['tp_menuid']); } elseif ($from == 'menus') { checkSession('post'); isAllowedTo('tp_blocks'); foreach ($_POST as $what => $value) { if (substr($what, 0, 12) == 'tp_menu_name') { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET value1 = {string:val1} WHERE id = {int:varid}', array('val1' => tp_sanitize($value), 'varid' => substr($what, 12))); } } redirectexit('action=tpadmin;sa=menubox'); } elseif ($from == 'singlemenuedit') { checkSession('post'); isAllowedTo('tp_blocks'); $where = isset($_POST['tpadmin_form_id']) ? $_POST['tpadmin_form_id'] : 0; foreach ($_POST as $what => $value) { if ($what == 'tp_menu_name') { // make sure special charachters can't be done $value = preg_replace('~&#\\d+$~', '', $value); $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET value1 = {string:val1} WHERE id = {int:varid}', array('val1' => $value, 'varid' => $where)); } elseif ($what == 'tp_menu_newlink') { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET value2 = {string:var2} WHERE id = {int:varid}', array('var2' => $value, 'varid' => $where)); } elseif ($what == 'tp_menu_menuid') { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET subtype2 = {int:subtype2} WHERE id = {int:varid}', array('subtype2' => $value, 'varid' => $where)); } elseif ($what == 'tp_menu_type') { if ($value == 'cats') { $idtype = 'cats' . $_POST['tp_menu_category']; } elseif ($value == 'arti') { $idtype = 'arti' . $_POST['tp_menu_article']; } elseif ($value == 'link') { $idtype = $_POST['tp_menu_link']; } elseif ($value == 'head') { $idtype = 'head'; } elseif ($value == 'spac') { $idtype = 'spac'; } $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET value3 = {string:val3} WHERE id = {int:varid}', array('val3' => $idtype, 'varid' => $where)); } elseif ($what == 'tp_menu_sub') { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET value4 = {string:val4} WHERE id = {int:varid}', array('val4' => $value, 'varid' => $where)); } elseif (substr($what, 0, 15) == 'tp_menu_newlink') { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET value2 = WHERE id = {int:varid}', array('val2' => $value, 'varid' => $where)); } } redirectexit('action=tpadmin;linkedit=' . $where . ';' . $context['session_var'] . '=' . $context['session_id']); } elseif ($from == 'addcategory') { checkSession('post'); isAllowedTo('tp_articles'); $name = !empty($_POST['tp_cat_name']) ? $_POST['tp_cat_name'] : $txt['tp-noname']; $parent = !empty($_POST['tp_cat_parent']) ? $_POST['tp_cat_parent'] : '0'; $smcFunc['db_insert']('INSERT', '{db_prefix}tp_variables', array('value1' => 'string', 'value2' => 'string', 'value3' => 'string', 'type' => 'string', 'value4' => 'string', 'value5' => 'int', 'subtype' => 'string', 'value7' => 'string', 'value8' => 'string', 'subtype2' => 'int'), array(strip_tags($name), $parent, '', 'category', '', 0, '', 'catlayout=1|layout=1', 0, 0), array('id')); $go = $smcFunc['db_insert_id']('{db_prefix}tp_variables', 'id'); redirectexit('action=tpadmin;sa=categories;cu=' . $go); } elseif ($from == 'clist') { checkSession('post'); isAllowedTo('tp_articles'); $cats = array(); foreach ($_POST as $what => $value) { if (substr($what, 0, 8) == 'tp_clist') { $cats[] = $value; } } if (sizeof($cats) > 0) { $catnames = implode(',', $cats); } else { $catnames = ''; } $updateArray['cat_list'] = $catnames; updateTPSettings($updateArray); return $from; } elseif ($from == 'editcategory') { checkSession('post'); isAllowedTo('tp_articles'); $options = array(); $groups = array(); $where = $_POST['tpadmin_form_id']; foreach ($_POST as $what => $value) { if (substr($what, 0, 3) == 'tp_') { $clean = tp_sanitize($value); $param = substr($what, 12); if (in_array($param, array('value5', 'value6', 'value8'))) { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET ' . $param . ' = {string:val} WHERE id = {int:varid} LIMIT 1', array('val' => $value, 'varid' => $where)); } elseif ($param == 'value2') { //make sure parent are not its own parent $request = $smcFunc['db_query']('', ' SELECT value2 FROM {db_prefix}tp_variables WHERE id = {int:varid} LIMIT 1', array('varid' => $value)); $row = $smcFunc['db_fetch_assoc']($request); $smcFunc['db_free_result']($request); if ($row['value2'] == $where) { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET value2 = {string:val2} WHERE id = {int:varid} LIMIT 1', array('val2' => '0', 'varid' => $value)); } $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET value2 = {string:val2} WHERE id = {int:varid} LIMIT 1', array('val2' => $value, 'varid' => $where)); } elseif ($param == 'value1') { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET value1 = {string:val1} WHERE id = {int:varid} LIMIT 1', array('val1' => strip_tags($value), 'varid' => $where)); } elseif ($param == 'value4') { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET value4 = {string:val4} WHERE id = {int:varid} LIMIT 1', array('val4' => $value, 'varid' => $where)); } elseif ($param == 'value9') { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET value9 = {string:val9} WHERE id = {int:varid} LIMIT 1', array('val9' => $value, 'varid' => $where)); } elseif (substr($param, 0, 6) == 'group_') { $groups[] = substr($param, 6); } else { $options[] = $param . '=' . $value; } } } $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET value3 = {string:val3}, value7 = {string:val7} WHERE id = {int:varid} LIMIT 1', array('val3' => implode(',', $groups), 'val7' => implode('|', $options), 'varid' => $where)); $from = 'categories;cu=' . $where; return $from; } elseif ($from == 'strays') { checkSession('post'); isAllowedTo('tp_articles'); $ccats = array(); // check if we have some values foreach ($_POST as $what => $value) { if (substr($what, 0, 16) == 'tp_article_stray') { $ccats[] = substr($what, 16); } elseif ($what == 'tp_article_cat') { $straycat = $value; } elseif ($what == 'tp_article_new') { $straynewcat = $value; } } // update if (isset($straycat) && sizeof($ccats) > 0) { $category = $straycat; if ($category == 0 && !empty($straynewcat)) { $request = $smcFunc['db_insert']('INSERT', '{db_prefix}tp_variables', array('value1' => 'string', 'value2' => 'string', 'type' => 'string'), array(strip_tags($straynewcat), '0', 'category'), array('id')); $newcategory = $smcFunc['db_insert_id']('{db_prefix}tp_variables', 'id'); $smcFunc['db_free_result']($request); } $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET category = {int:cat} WHERE id IN ({array_int:artid})', array('cat' => !empty($newcategory) ? $newcategory : $category, 'artid' => $ccats)); } return $from; } elseif ($from == 'articons') { checkSession('post'); isAllowedTo('tp_articles'); // any icons sent? if (file_exists($_FILES['tp_article_newicon']['tmp_name'])) { TPuploadpicture('tp_article_newicon', '', '300', 'jpg,gif,png', 'tp-files/tp-articles/icons'); } if (file_exists($_FILES['tp_article_newillustration']['tmp_name'])) { $name = TPuploadpicture('tp_article_newillustration', '', '500', 'jpg,gif,png', 'tp-files/tp-articles/illustrations'); tp_createthumb('tp-files/tp-articles/illustrations/' . $name, 128, 128, 'tp-files/tp-articles/illustrations/s_' . $name); unlink('tp-files/tp-articles/illustrations/' . $name); } // how about deleted? foreach ($_POST as $what => $value) { if (substr($what, 0, 7) == 'articon') { unlink($boarddir . '/tp-files/tp-articles/icons/' . $value); } elseif (substr($what, 0, 15) == 'artillustration') { unlink($boarddir . '/tp-files/tp-articles/illustrations/' . $value); } } return $from; } elseif ($from == 'menuadd') { checkSession('post'); isAllowedTo('tp_blocks'); if (!empty($_POST['tp_menu_title'])) { $mtitle = strip_tags($_POST['tp_menu_title']); $smcFunc['db_insert']('INSERT', '{db_prefix}tp_variables', array('value1' => 'string', 'type' => 'string'), array($mtitle, 'menus'), array('id')); redirectexit('action=tpadmin;sa=menubox'); } } elseif ($from == 'menuaddsingle') { checkSession('post'); isAllowedTo('tp_blocks'); $mid = $_POST['tp_menu_menuid']; $mtitle = strip_tags($_POST['tp_menu_title']); if ($mtitle == '') { $mtitle = $txt['tp-no_title']; } $mtype = $_POST['tp_menu_type']; $mcat = isset($_POST['tp_menu_category']) ? $_POST['tp_menu_category'] : ''; $mart = isset($_POST['tp_menu_article']) ? $_POST['tp_menu_article'] : ''; $mlink = isset($_POST['tp_menu_link']) ? $_POST['tp_menu_link'] : ''; $mhead = isset($_POST['tp_menu_head']) ? $_POST['tp_menu_head'] : ''; $mnewlink = isset($_POST['tp_menu_newlink']) ? $_POST['tp_menu_newlink'] : '0'; if ($mtype == 'cats') { $mtype = 'cats' . $mcat; } elseif ($mtype == 'arti') { $mtype = 'arti' . $mart; } elseif ($mtype == 'head') { $mtype = 'head' . $mhead; } elseif ($mtype == 'spac') { $mtype = 'spac'; } else { $mtype = $mlink; } $msub = $_POST['tp_menu_sub']; $smcFunc['db_insert']('INSERT', '{db_prefix}tp_variables', array('value1' => 'string', 'value2' => 'string', 'value3' => 'string', 'type' => 'string', 'value4' => 'string', 'value5' => 'int', 'subtype2' => 'int'), array($mtitle, $mnewlink, $mtype, 'menubox', $msub, -1, $mid), array('id')); redirectexit('action=tpadmin;sa=menubox;mid=' . $mid); } elseif ($from == 'submission') { checkSession('post'); isAllowedTo('tp_articles'); $ccats = array(); // check if we have some values foreach ($_POST as $what => $value) { if (substr($what, 0, 21) == 'tp_article_submission') { $ccats[] = substr($what, 21); } elseif ($what == 'tp_article_cat') { $straycat = $value; } elseif ($what == 'tp_article_new') { $straynewcat = $value; } } // update if (isset($straycat) && sizeof($ccats) > 0) { $category = $straycat; if ($category == 0 && !empty($straynewcat)) { $request = $smcFunc['db_insert']('INSERT', '{db_prefix}tp_variables', array('value1' => 'string', 'value2' => 'string', 'type' => 'string'), array($straynewcat, '0', 'category'), array('id')); $newcategory = $smcFunc['db_insert_id']('{db_prefix}tp_variables', 'id'); $smcFunc['db_free_result']($request); } $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET approved = {int:approved}, category = {int:cat} WHERE id IN ({array_int:artid})', array('approved' => 1, 'cat' => !empty($newcategory) ? $newcategory : $category, 'artid' => $ccats)); $smcFunc['db_query']('', ' DELETE FROM {db_prefix}tp_variables WHERE type = {string:type} AND value5 IN ({array_int:val5})', array('type' => 'art_not_approved', 'val5' => $ccats)); } return $from; } elseif ($from == 'blocks') { checkSession('post'); isAllowedTo('tp_blocks'); foreach ($_POST as $what => $value) { if (substr($what, 0, 3) == 'pos') { $where = substr($what, 3); if (is_numeric($where)) { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_blocks SET pos = {int:pos} WHERE id = {int:blockid}', array('pos' => $value, 'blockid' => $where)); } } elseif (substr($what, 0, 6) == 'addpos') { $where = substr($what, 6); if (is_numeric($where)) { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_blocks SET pos = (pos + 11) WHERE id = {int:blockid}', array('blockid' => $where)); } } elseif (substr($what, 0, 6) == 'subpos') { $where = substr($what, 6); if (is_numeric($where)) { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_blocks SET pos = (pos - 11) WHERE id = {int:blockid}', array('blockid' => $where)); } } elseif (substr($what, 0, 4) == 'type') { $where = substr($what, 4); $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_blocks SET type = {int:type} WHERE id = {int:blockid}', array('type' => $value, 'blockid' => $where)); } elseif (substr($what, 0, 5) == 'title') { $where = strip_tags(substr($what, 5)); $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_blocks SET title = {string:title} WHERE id = {int:blockid}', array('title' => $value, 'blockid' => $where)); } elseif (substr($what, 0, 9) == 'blockbody') { $where = tp_sanitize(substr($what, 9)); $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_blocks SET body = {string:body} WHERE id = {int:blockid}', array('body' => $value, 'blockid' => $where)); } } redirectexit('action=tpadmin;sa=blocks'); } elseif ($from == 'addblock') { checkSession('post'); isAllowedTo('tp_blocks'); $title = empty($_POST['tp_addblocktitle']) ? '-no title-' : $_POST['tp_addblocktitle']; $panel = $_POST['tp_addblockpanel']; $type = $_POST['tp_addblock']; if (!is_numeric($type)) { if (substr($type, 0, 3) == 'mb_') { $request = $smcFunc['db_query']('', ' SELECT * FROM {db_prefix}tp_blocks WHERE id = {int:blockid}', array('blockid' => substr($type, 3))); if ($smcFunc['db_num_rows']($request) > 0) { $cp = $smcFunc['db_fetch_assoc']($request); $smcFunc['db_free_result']($request); } } else { $od = TPparseModfile(file_get_contents($boarddir . '/tp-files/tp-blockcodes/' . $type . '.blockcode'), array('code')); } } if (isset($od['code'])) { $body = tp_convertphp($od['code']); $type = 10; } else { $body = ''; } if (isset($cp)) { $smcFunc['db_insert']('INSERT', '{db_prefix}tp_blocks', array('type' => 'int', 'frame' => 'string', 'title' => 'string', 'body' => 'string', 'access' => 'string', 'bar' => 'int', 'pos' => 'int', 'off' => 'int', 'visible' => 'string', 'var1' => 'int', 'var2' => 'int', 'lang' => 'string', 'access2' => 'string', 'editgroups' => 'string'), array($cp['type'], $cp['frame'], $title, $cp['body'], $cp['access'], $panel, 0, 1, 1, $cp['var1'], $cp['var2'], $cp['lang'], $cp['access2'], $cp['editgroups']), array('id')); } else { $smcFunc['db_insert']('INSERT', '{db_prefix}tp_blocks', array('type' => 'int', 'frame' => 'string', 'title' => 'string', 'body' => 'string', 'access' => 'string', 'bar' => 'int', 'pos' => 'int', 'off' => 'int', 'visible' => 'string', 'var1' => 'int', 'var2' => 'int', 'lang' => 'string', 'access2' => 'string', 'editgroups' => 'string'), array($type, 'theme', $title, $body, '-1,0,1', $panel, 0, 1, 1, 0, 0, '', 'actio=allpages', ''), array('id')); } $where = $smcFunc['db_insert_id']('{db_prefix}tp_blocks', 'id'); if (!empty($where)) { redirectexit('action=tpadmin;blockedit=' . $where . ';sesc=' . $context['session_id']); } else { redirectexit('action=tpadmin;sa=blocks'); } } elseif ($from == 'blockedit') { checkSession('post'); isAllowedTo('tp_blocks'); $where = is_numeric($_POST['tpadmin_form_id']) ? $_POST['tpadmin_form_id'] : 0; $tpgroups = array(); $editgroups = array(); $access = array(); $lang = array(); foreach ($_POST as $what => $value) { if (substr($what, 0, 9) == 'tp_block_') { $setting = substr($what, 9); if ($setting == 'body') { // If we came from WYSIWYG then turn it back into BBC regardless. if (!empty($_REQUEST['tp_block_body_mode']) && isset($_REQUEST['tp_block_body'])) { require_once $sourcedir . '/Subs-Editor.php'; $_REQUEST['tp_block_body'] = html_to_bbc($_REQUEST['tp_block_body']); // We need to unhtml it now as it gets done shortly. $_REQUEST['tp_block_body'] = un_htmlspecialchars($_REQUEST['tp_block_body']); // We need this for everything else. $value = $_POST['tp_block_body'] = $_REQUEST['tp_block_body']; } // PHP block? if ($_POST['tp_block_type'] == 10) { $value = tp_convertphp($value); } $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_blocks SET ' . $setting . ' = {string:value} WHERE id = {int:blockid}', array('value' => $value, 'blockid' => $where)); } elseif ($setting == 'title') { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_blocks SET title = {string:title} WHERE id = {int:blockid}', array('title' => $value, 'blockid' => $where)); } elseif ($setting == 'body_mode' || $setting == 'body_choice' || $setting == 'body_pure') { $go = ''; } elseif ($setting == 'frame') { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_blocks SET frame = {string:val} WHERE id = {int:blockid}', array('val' => $value, 'blockid' => $where)); } else { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_blocks SET ' . $setting . ' = {raw:val} WHERE id = {int:blockid}', array('val' => $value, 'blockid' => $where)); } } elseif (substr($what, 0, 8) == 'tp_group') { $tpgroups[] = substr($what, 8); } elseif (substr($what, 0, 12) == 'tp_editgroup') { $editgroups[] = substr($what, 12); } elseif (substr($what, 0, 10) == 'actiontype') { $access[] = 'actio=' . $value; } elseif (substr($what, 0, 9) == 'boardtype') { $access[] = 'board=' . $value; } elseif (substr($what, 0, 11) == 'articletype') { $access[] = 'tpage=' . $value; } elseif (substr($what, 0, 12) == 'categorytype') { $access[] = 'tpcat=' . $value; } elseif (substr($what, 0, 8) == 'langtype') { $access[] = 'tlang=' . $value; } elseif (substr($what, 0, 9) == 'dlcattype') { $access[] = 'dlcat=' . $value; } elseif (substr($what, 0, 9) == 'tpmodtype') { $access[] = 'tpmod=' . $value; } elseif (substr($what, 0, 9) == 'custotype' && !empty($value)) { $items = explode(',', $value); foreach ($items as $iti => $it) { $access[] = 'actio=' . $it; } } elseif (substr($what, 0, 8) == 'tp_lang_') { if (substr($what, 8) != '') { $lang[] = substr($what, 8) . '|' . $value; } } elseif (substr($what, 0, 18) == 'tp_userbox_options') { if (!isset($userbox)) { $userbox = array(); } $userbox[] = $value; } elseif (substr($what, 0, 8) == 'tp_theme') { $theme = substr($what, 8); if (!isset($themebox)) { $themebox = array(); } // get the path too if (isset($_POST['tp_path' . $theme])) { $tpath = $_POST['tp_path' . $theme]; } else { $tpath = ''; } $themebox[] = $theme . '|' . $value . '|' . $tpath; } } // construct the access++ $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_blocks SET access2 = {string:acc2}, access = {string:acc}, lang = {string:lang}, editgroups = {string:editgrp} WHERE id = {int:blockid}', array('acc2' => implode(',', $access), 'acc' => implode(',', $tpgroups), 'lang' => implode('|', $lang), 'editgrp' => implode(',', $editgroups), 'blockid' => $where)); if (isset($userbox)) { $updateArray['userbox_options'] = implode(',', $userbox); } if (isset($themebox)) { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_blocks SET body = {string:body} WHERE id = {int:blockid}', array('body' => implode(',', $themebox), 'blockid' => $where)); } // anything from PHP block? if (isset($_POST['blockcode_overwrite'])) { // get the blockcode $newval = TPparseModfile(file_get_contents($boarddir . '/tp-files/tp-blockcodes/' . $_POST['tp_blockcode'] . '.blockcode'), array('code')); $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_blocks SET body = {string:body} WHERE id = {int:blockid}', array('body' => $newval['code'], 'blockid' => $where)); } // check if uploadad picture if (isset($_FILES['qup_blockbody']) && file_exists($_FILES['qup_blockbody']['tmp_name'])) { $name = TPuploadpicture('qup_blockbody', $context['user']['id'] . 'uid'); tp_createthumb('tp-images/' . $name, 50, 50, 'tp-images/thumbs/thumb_' . $name); } updateTPSettings($updateArray); redirectexit('action=tpadmin;blockedit=' . $where . ';' . $context['session_var'] . '=' . $context['session_id']); } elseif (substr($from, 0, 11) == 'editarticle') { checkSession('post'); isAllowedTo('tp_articles'); $new = false; $where = substr($from, 11); if (empty($where)) { // we need to create one first $smcFunc['db_insert']('INSERT', '{db_prefix}tp_articles', array('date' => 'int'), array(time()), array('id')); $where = $smcFunc['db_insert_id']('{db_prefix}tp_articles', 'id'); $new = true; $from = 'editarticle' . $where; } // check if uploads are there if (file_exists($_FILES['tp_article_illupload']['tmp_name'])) { $name = TPuploadpicture('tp_article_illupload', '', '180', 'jpg,gif,png', 'tp-files/tp-articles/illustrations'); tp_createthumb('tp-files/tp-articles/illustrations/' . $name, 128, 128, 'tp-files/tp-articles/illustrations/s_' . $name); $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET illustration = {string:ill} WHERE id = {int:artid} LIMIT 1', array('ill' => 's_' . $name, 'artid' => $where)); } // check if uploadad picture if (isset($_FILES['qup_tp_article_body']) && file_exists($_FILES['qup_tp_article_body']['tmp_name'])) { $name = TPuploadpicture('qup_tp_article_body', $context['user']['id'] . 'uid'); tp_createthumb('tp-images/' . $name, 50, 50, 'tp-images/thumbs/thumb_' . $name); } $options = array(); foreach ($_POST as $what => $value) { if (substr($what, 0, 11) == 'tp_article_' && !empty($where)) { $setting = substr($what, 11); if ($setting == 'authorid') { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET author_id = {int:auth} WHERE id = {int:artid} LIMIT 1', array('auth' => $value, 'artid' => $where)); } elseif ($setting == 'idtheme') { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET id_theme = {int:id_theme} WHERE id = {int:artid} LIMIT 1', array('id_theme' => $value, 'artid' => $where)); } elseif ($setting == 'subject') { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET subject = {string:subject} WHERE id = {int:artid} LIMIT 1', array('subject' => $value, 'artid' => $where)); } elseif ($setting == 'shortname') { $value = htmlspecialchars(str_replace(' ', '-', $value), ENT_QUOTES); $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET shortname = {string:shortname} WHERE id = {int:artid} LIMIT 1', array('shortname' => $value, 'artid' => $where)); } elseif ($setting == 'category') { // for the event, get the allowed $request = $smcFunc['db_query']('', ' SELECT value3 FROM {db_prefix}tp_variables WHERE id = {int:varid} LIMIT 1', array('varid' => $value)); if ($smcFunc['db_num_rows']($request) > 0) { $row = $smcFunc['db_fetch_assoc']($request); $allowed = $row['value3']; $smcFunc['db_free_result']($request); } $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET category = {int:cat} WHERE id = {int:artid} LIMIT 1', array('cat' => $value, 'artid' => $where)); } elseif (in_array($setting, array('body', 'intro'))) { // If we came from WYSIWYG then turn it back into BBC regardless. if (!empty($_REQUEST['tp_article_body_mode']) && isset($_REQUEST['tp_article_body'])) { require_once $sourcedir . '/Subs-Editor.php'; $_REQUEST['tp_article_body'] = html_to_bbc($_REQUEST['tp_article_body']); // We need to unhtml it now as it gets done shortly. $_REQUEST['tp_article_body'] = un_htmlspecialchars($_REQUEST['tp_article_body']); // We need this for everything else. if ($setting == 'body') { $value = $_POST['tp_article_body'] = $_REQUEST['tp_article_body']; } elseif ($settings == 'intro') { $value = $_POST['tp_article_intro'] = $_REQUEST['tp_article_intro']; } } // in case of HTML article we need to check it if (isset($_POST['tp_article_body_pure']) && isset($_POST['tp_article_body_choice'])) { if ($_POST['tp_article_body_choice'] == 0) { if ($setting == 'body') { $value = $_POST['tp_article_body_pure']; } elseif ($setting == 'intro') { $value = $_POST['tp_article_intro']; } } // save the choice too $request = $smcFunc['db_query']('', ' SELECT id FROM {db_prefix}tp_variables WHERE subtype2 = {int:sub2} AND type = {string:type} LIMIT 1', array('sub2' => $where, 'type' => 'editorchoice')); if ($smcFunc['db_num_rows']($request) > 0) { $row = $smcFunc['db_fetch_assoc']($request); $smcFunc['db_free_result']($request); $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET value1 = {string:val1} WHERE subtype2 = {int:sub2} AND type = {string:type}', array('val1' => $_POST['tp_article_body_choice'], 'sub2' => $where, 'type' => 'editorchoice')); } else { $smcFunc['db_insert']('INSERT', '{db_prefix}tp_variables', array('value1' => 'string', 'type' => 'string', 'subtype2' => 'int'), array($_POST['tp_article_body_choice'], 'editorchoice', $where), array('id')); } } $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET ' . $setting . ' = {string:val} WHERE id = {int:artid} LIMIT 1', array('val' => $value, 'artid' => $where)); } elseif (in_array($setting, array('day', 'month', 'year', 'minute', 'hour', 'timestamp'))) { $timestamp = mktime($_POST['tp_article_hour'], $_POST['tp_article_minute'], 0, $_POST['tp_article_month'], $_POST['tp_article_day'], $_POST['tp_article_year']); if (!isset($savedtime)) { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET date = {int:date} WHERE id = {int:artid} LIMIT 1', array('date' => $timestamp, 'artid' => $where)); } $savedtime = 1; } elseif (in_array($setting, array('pubstartday', 'pubstartmonth', 'pubstartyear', 'pubstartminute', 'pubstarthour', 'pub_start'))) { // are all zero? then skip if (empty($_POST['tp_article_pubstarthour']) && empty($_POST['tp_article_pubstartminute']) && empty($_POST['tp_article_pubstartmonth']) && empty($_POST['tp_article_pubstartday']) && empty($_POST['tp_article_pubstartyear'])) { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET pub_start = {int:start} WHERE id = {int:artid} LIMIT 1', array('start' => 0, 'artid' => $where)); } else { $timestamp = mktime($_POST['tp_article_pubstarthour'], $_POST['tp_article_pubstartminute'], 0, $_POST['tp_article_pubstartmonth'], $_POST['tp_article_pubstartday'], $_POST['tp_article_pubstartyear']); } if (!isset($pubstart)) { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET pub_start = {int:start} WHERE id = {int:artid} LIMIT 1', array('start' => $timestamp, 'artid' => $where)); } $pubstart = 1; } elseif (in_array($setting, array('pubendday', 'pubendmonth', 'pubendyear', 'pubendminute', 'pubendhour', 'pub_start'))) { // are all zero? then skip if (empty($_POST['tp_article_pubendhour']) && empty($_POST['tp_article_pubendminute']) && empty($_POST['tp_article_pubendmonth']) && empty($_POST['tp_article_pubendday']) && empty($_POST['tp_article_pubendyear'])) { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET pub_end = {int:end} WHERE id = {int:artid} LIMIT 1', array('end' => 0, 'artid' => $where)); } else { $timestamp = mktime($_POST['tp_article_pubendhour'], $_POST['tp_article_pubendminute'], 0, $_POST['tp_article_pubendmonth'], $_POST['tp_article_pubendday'], $_POST['tp_article_pubendyear']); } if (!isset($pubend)) { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET pub_end = {int:end} WHERE id = {int:artid} LIMIT 1', array('end' => $timestamp, 'artid' => $where)); } $pubend = 1; } elseif (substr($setting, 0, 8) == 'options_') { if (substr($setting, 0, 19) == 'options_lblockwidth' || substr($setting, 0, 19) == 'options_rblockwidth') { $options[] = substr($setting, 8) . $value; } else { $options[] = substr($setting, 8); } } elseif (in_array($setting, array('body_mode', 'intro_mode', 'illupload', 'body_pure', 'body_choice'))) { // ignore it continue; } elseif ($setting == 'approved') { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET approved = {int:approved} WHERE id = {int:artid} LIMIT 1', array('approved' => $value, 'artid' => $where)); if ($value == 1) { $smcFunc['db_query']('', ' DELETE FROM {db_prefix}tp_variables WHERE type = {string:type} AND value5 = {int:val5}', array('type' => 'art_not_approved', 'val5' => $where)); } elseif ($new) { $smcFunc['db_insert']('replace', '{db_prefix}tp_variables', array('type' => 'string', 'value5' => 'int'), array('art_not_approved', $where), array('id')); } } else { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET ' . $setting . ' = {string:val} WHERE id = {int:artid} LIMIT 1', array('val' => $value, 'artid' => $where)); } } } // if this was a new article if ($_POST['tp_article_approved'] == 1 && $_POST['tp_article_off'] == 0) { tp_recordevent($timestamp, $_POST['tp_article_authorid'], 'tp-createdarticle', 'page=' . $where, 'Creation of new article.', isset($allowed) ? $allowed : 0, $where); } $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET options = {string:opt} WHERE id = {int:artid} LIMIT 1', array('opt' => implode(',', $options), 'artid' => $where)); } } else { return; } }
function TPortalDLManager() { global $txt, $scripturl, $boarddir, $boardurl, $context, $settings, $smcFunc; // assume its the frontpage initially $context['TPortal']['dlaction'] = 'main'; // is even the manager active? if (!$context['TPortal']['show_download']) { fatal_error($txt['tp-dlmanageroff']); } $context['TPortal']['upshrinkpanel'] = ''; // add visual options to thsi section $context['TPortal']['dl_visual'] = array(); $dl_visual = explode(',', $context['TPortal']['dl_visual_options']); $dv = array('left', 'right', 'center', 'lower', 'top', 'bottom'); foreach ($dv as $v => $val) { if ($context['TPortal'][$val . 'panel'] == 1) { if (in_array($val, $dl_visual)) { $context['TPortal'][$val . 'panel'] = '1'; } else { $context['TPortal'][$val . 'panel'] = '0'; } } $context['TPortal']['dl_visual'][$val] = true; } if (in_array('top', $dl_visual)) { $context['TPortal']['showtop'] = '1'; } else { $context['TPortal']['showtop'] = '0'; } // check that you can upload at all if (allowedTo('tp_dlupload')) { $context['TPortal']['can_upload'] = true; } else { $context['TPortal']['can_upload'] = false; } // fetch all files from tp-downloads if (isset($_GET['ftp']) && allowedTo('tp_dlmanager')) { TP_dlftpfiles(); } // any uploads being sent? $context['TPortal']['uploads'] = array(); if (isset($_FILES['tp-dluploadfile']['tmp_name']) || isset($_POST['tp-dluploadnot'])) { // skip the uplaod checks etc . if just an empty item if (!isset($_POST['tp-dluploadnot'])) { // check if uploaded quick-list picture if (isset($_FILES['qup_tp_dluploadtext']) && file_exists($_FILES['qup_tp_dluploadtext']['tmp_name'])) { $item_id = isset($_GET['dl']) ? $_GET['dl'] : 'upload'; $name = TPuploadpicture('qup_tp_dluploadtext', $context['user']['id'] . 'uid'); tp_createthumb('tp-images/' . $name, 50, 50, 'tp-images/thumbs/thumb_' . $name); redirectexit('action=tpmod;dl=' . $item_id); } // check that nothing happended if (!file_exists($_FILES['tp-dluploadfile']['tmp_name']) || !is_uploaded_file($_FILES['tp-dluploadfile']['tmp_name'])) { fatal_error($txt['tp-dluploadfailure']); } // first, can we upload at all? if (!$context['TPortal']['can_upload']) { unlink($_FILES['tp-dluploadfile']['tmp_name']); fatal_error($txt['tp-dluploadnotallowed']); } } // a file it is $title = isset($_POST['tp-dluploadtitle']) ? strip_tags($_POST['tp-dluploadtitle']) : $txt['tp-no_title']; if ($title == '') { $title = $txt['tp-no_title']; } $text = isset($_POST['tp_dluploadtext']) ? $_POST['tp_dluploadtext'] : ''; $category = isset($_POST['tp-dluploadcat']) ? (int) $_POST['tp-dluploadcat'] : 0; // a screenshot? if (file_exists($_FILES['tp_dluploadpic']['tmp_name']) || is_uploaded_file($_FILES['tp_dluploadpic']['tmp_name'])) { $shot = true; } else { $shot = false; } $icon = !empty($_POST['tp_dluploadicon']) ? $boardurl . '/tp-downloads/icons/' . $_POST['tp_dluploadicon'] : ''; if (!isset($_POST['tp-dluploadnot'])) { // process the file $filename = $_FILES['tp-dluploadfile']['name']; $name = strtr($filename, 'ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'); $name = strtr($name, array('Þ' => 'TH', 'þ' => 'th', 'Ð' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'Œ' => 'OE', 'œ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u')); $name = preg_replace(array('/\\s/', '/[^\\w_\\.\\-]/'), array('_', ''), $name); } else { $name = '- empty item -'; } if (isset($_POST['tp-dlupload_ftpstray'])) { $name = '- empty item - ftp'; } $status = 'normal'; if (!isset($_POST['tp-dluploadnot'])) { // check the size $dlfilesize = filesize($_FILES['tp-dluploadfile']['tmp_name']); if ($dlfilesize > 1000 * $context['TPortal']['dl_max_upload_size']) { $status = 'maxsize'; unlink($_FILES['tp-dluploadfile']['tmp_name']); $error = $txt['tp-dlmaxerror'] . ' ' . $context['TPortal']['dl_max_upload_size'] . ' Kb<br /><br />' . $txt['tp-dlmaxerror2'] . ': ' . ceil($dlfilesize / 1000) . ' Kb'; fatal_error($error); } } else { $dlfilesize = 0; } if (!isset($_POST['tp-dluploadnot'])) { // check the extension $allowed = explode(',', $context['TPortal']['dl_allowed_types']); $match = false; foreach ($allowed as $extension => $value) { $ext = '.' . $value; $extlen = strlen($ext); if (substr($name, strlen($name) - $extlen, $extlen) == $ext) { $match = true; } } if (!$match) { $status = 'wrongtype'; unlink($_FILES['tp-dluploadfile']['tmp_name']); $error = $txt['tp-dlexterror'] . ':<b> <br />' . $context['TPortal']['dl_allowed_types'] . '</b><br /><br />' . $txt['tp-dlexterror2'] . ': <b>' . $name . '</b>'; fatal_error($error); } } // ok, go ahead if ($status == 'normal') { if (!isset($_POST['tp-dluploadnot'])) { // check that no other file exists with same name if (file_exists($boarddir . '/tp-downloads/' . $name)) { $name = time() . $name; } $success = move_uploaded_file($_FILES['tp-dluploadfile']['tmp_name'], $boarddir . '/tp-downloads/' . $name); } if ($shot) { $sfile = 'tp_dluploadpic'; $uid = $context['user']['id'] . 'uid'; $dim = '1800'; $suf = 'jpg,gif,png'; $dest = 'tp-images/dlmanager'; $sname = TPuploadpicture($sfile, $uid, $dim, $suf, $dest); $screenshot = $sname; tp_createthumb($dest . '/' . $sname, $context['TPortal']['dl_screenshotsize'][0], $context['TPortal']['dl_screenshotsize'][1], $dest . '/thumb/' . $sname); tp_createthumb($dest . '/' . $sname, $context['TPortal']['dl_screenshotsize'][2], $context['TPortal']['dl_screenshotsize'][3], $dest . '/listing/' . $sname); tp_createthumb($dest . '/' . $sname, $context['TPortal']['dl_screenshotsize'][4], $context['TPortal']['dl_screenshotsize'][5], $dest . '/single/' . $sname); } else { if (isset($_POST['tp_dluploadpic_link'])) { $screenshot = $_POST['tp_dluploadpic_link']; } else { $screenshot = ''; } } // insert it into the database $now = time(); // if all uploads needs to be approved: set category to -category , but not for dl admins if ($context['TPortal']['dl_approve'] == '1' && !allowedTo('tp_dlmanager')) { $category = $category - $category - $category; } // get the category access $request = $smcFunc['db_query']('', ' SELECT access FROM {db_prefix}tp_dlmanager WHERE id = {int:cat}', array('cat' => $category)); if ($smcFunc['db_num_rows']($request) > 0) { $row = $smcFunc['db_fetch_assoc']($request); $acc = $row['access']; } else { $acc = ''; } $request = $smcFunc['db_insert']('INSERT', '{db_prefix}tp_dlmanager', array('name' => 'string', 'description' => 'string', 'icon' => 'string', 'category' => 'int', 'type' => 'string', 'downloads' => 'int', 'views' => 'int', 'file' => 'string', 'created' => 'int', 'last_access' => 'int', 'filesize' => 'int', 'parent' => 'int', 'access' => 'string', 'link' => 'string', 'author_id' => 'int', 'screenshot' => 'string', 'rating' => 'string', 'voters' => 'string', 'subitem' => 'int'), array($title, $text, $icon, $category, 'dlitem', 0, 1, $name, $now, $now, $dlfilesize, 0, '', '', $context['user']['id'], $screenshot, '', '', 0), array('id')); $newitem = $smcFunc['db_insert_id']($request); // record the event if ($context['TPortal']['dl_approve'] == '1' && allowedTo('tp_dlmanager') || $context['TPortal']['dl_approve'] == '0') { tp_recordevent($now, $context['user']['id'], 'tp-createdupload', 'action=tpmod;dl=item' . $newitem, 'Uploaded new file.', $acc, $newitem); } // should we create a topic? if (isset($_POST['create_topic']) && (allowedTo('admin_forum') || !empty($context['TPortal']['dl_create_topic']))) { $sticky = false; $announce = false; // sticky and announce? if (isset($_POST['create_topic_sticky'])) { $sticky = true; } if (isset($_POST['create_topic_announce']) && allowedTo('admin_forum')) { $announce = true; } if (!empty($_POST['create_topic_board'])) { $brd = $_POST['create_topic_board']; } if (isset($_POST['create_topic_body'])) { $body = $_POST['create_topic_body']; } $body .= '[hr][b]' . $txt['tp-download'] . ':[/b][br]' . $scripturl . '?action=tpmod;dl=item' . $newitem; // ok, create the topic then $top = TP_createtopic($title, $body, 'theme', $brd, $sticky ? 1 : 0, $context['user']['id']); // go to announce screen? if ($top > 0) { if ($announce) { redirectexit('action=announce;sa=selectgroup;topic=' . $top); } else { redirectexit('topic=' . $top); } } } // put this into submissions - id and type if ($category < 0) { $smcFunc['db_insert']('INSERT', '{db_prefix}tp_variables', array('value1' => 'string', 'value2' => 'string', 'value3' => 'string', 'type' => 'string', 'value4' => 'string', 'value5' => 'int'), array($title, $now, '', 'dl_not_approved', '', $newitem), array('id')); redirectexit('action=tpmod;sub=dlsubmitsuccess'); } else { if (!isset($_POST['tp-dluploadnot'])) { redirectexit('action=tpmod;dl=item' . $newitem); } else { redirectexit('action=tpmod;dl=adminitem' . $newitem); } } } } // ok, on with the show :) TP_dluploadcats(); TP_dlgeticons(); // showing a category, or even a single item? $context['TPortal']['dlaction'] = ''; if (isset($context['TPortal']['dlsub'])) { // a category? if (substr($context['TPortal']['dlsub'], 0, 3) == 'cat') { $context['TPortal']['dlcat'] = substr($context['TPortal']['dlsub'], 3); // check if its a number if (is_numeric($context['TPortal']['dlcat'])) { $context['TPortal']['dlaction'] = 'cat'; } else { redirectexit('action=tpmod;dl'); } } elseif (substr($context['TPortal']['dlsub'], 0, 4) == 'item') { $context['TPortal']['dlitem'] = substr($context['TPortal']['dlsub'], 4); if (is_numeric($context['TPortal']['dlitem'])) { $item = $context['TPortal']['dlitem']; $context['TPortal']['item'] = $item; $context['TPortal']['dlaction'] = 'item'; $request = $smcFunc['db_query']('', ' SELECT category, subitem FROM {db_prefix}tp_dlmanager WHERE id = {int:dl} AND type = {string:type} LIMIT 1', array('dl' => $item, 'type' => 'dlitem')); if ($smcFunc['db_num_rows']($request) > 0) { $row = $smcFunc['db_fetch_assoc']($request); $context['TPortal']['dlcat'] = $row['category']; $smcFunc['db_free_result']($request); // check that it is indeed a main item, if not : redirect to the main one. if ($row['subitem'] > 0) { redirectexit('action=tpmod;dl=item' . $row['subitem']); } } else { redirectexit('action=tpmod;dl'); } } else { redirectexit('action=tpmod;dl'); } } elseif ($context['TPortal']['dlsub'] == 'stats') { $context['TPortal']['dlaction'] = 'stats'; $context['TPortal']['dlitem'] = ''; } elseif ($context['TPortal']['dlsub'] == 'search') { $context['TPortal']['dlaction'] = 'search'; $context['TPortal']['dlitem'] = ''; } elseif ($context['TPortal']['dlsub'] == 'results') { $context['TPortal']['dlaction'] = 'results'; $context['TPortal']['dlitem'] = ''; } elseif ($context['TPortal']['dlsub'] == 'submission') { $context['TPortal']['dlaction'] = 'submission'; $context['TPortal']['dlitem'] = ''; } elseif (substr($context['TPortal']['dlsub'], 0, 3) == 'get') { $context['TPortal']['dlitem'] = substr($context['TPortal']['dlsub'], 3); if (is_numeric($context['TPortal']['dlitem'])) { $context['TPortal']['dlaction'] = 'get'; } else { redirectexit('action=tpmod;dl'); } } elseif (substr($context['TPortal']['dlsub'], 0, 6) == 'upload') { $context['TPortal']['dlitem'] = substr($context['TPortal']['dlsub'], 6); $context['TPortal']['dlaction'] = 'upload'; // check your permission for uploading isAllowedTo('tp_dlupload'); // Add in BBC editor before we call in template so the headers are there if ($context['TPortal']['dl_wysiwyg'] == 'bbc') { $context['TPortal']['editor_id'] = 'tp_dluploadtext'; TP_prebbcbox($context['TPortal']['editor_id']); } TP_dlgeticons(); // allow to attach this to another item $context['TPortal']['attachitems'] = array(); if (allowedTo('dlmanager')) { // get all items for a list $itemlist = $smcFunc['db_query']('', ' SELECT id, name FROM {db_prefix}tp_dlmanager WHERE type = {string:type} AND subitem = {int:sub} ORDER BY name ASC', array('type' => 'dlitem', 'sub' => 0)); if ($smcFunc['db_num_rows']($itemlist) > 0) { while ($ilist = $smcFunc['db_fetch_assoc']($itemlist)) { $context['TPortal']['attachitems'][] = array('id' => $ilist['id'], 'name' => $ilist['name']); } $smcFunc['db_free_result']($itemlist); } } else { // how about attaching to one of your own? // get all items for a list $itemlist = $smcFunc['db_query']('', ' SELECT id,name FROM {db_prefix}tp_dlmanager WHERE category > {int:cat} AND type = {string:type} AND subitem = {int:sub} AND author_id = {int:auth} ORDER BY name ASC', array('cat' => 0, 'type' => 'dlitem', 'sub' => 0, 'auth' => $context['user']['id'])); if (isset($itemlist) && $smcFunc['db_num_rows']($itemlist) > 0) { while ($ilist = $smcFunc['db_fetch_assoc']($itemlist)) { $context['TPortal']['attachitems'][] = array('id' => $ilist['id'], 'name' => $ilist['name']); } $smcFunc['db_free_result']($itemlist); } } $context['TPortal']['boards'] = array(); // fetch all boards $request = $smcFunc['db_query']('', ' SELECT b.ID_BOARD, b.name FROM {db_prefix}boards as b WHERE {query_see_board}'); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $context['TPortal']['boards'][] = array('id' => $row['ID_BOARD'], 'name' => $row['name']); } $smcFunc['db_free_result']($request); } } else { // check its really exists $what = $context['TPortal']['dlsub']; $request = $smcFunc['db_query']('', ' SELECT id FROM {db_prefix}tp_dlmanager WHERE link = {string:link} LIMIT 1', array('link' => $what)); if (isset($request) && $smcFunc['db_num_rows']($request) > 0) { $row = $smcFunc['db_fetch_assoc']($request); $context['TPortal']['dlcat'] = $row['id']; $context['TPortal']['dlsub'] = 'cat' . $row['id']; $context['TPortal']['dlaction'] = 'cat'; $smcFunc['db_free_result']($request); } } } // add to the linktree TPadd_linktree($scripturl . '?action=tpmod;dl=0', $txt['tp-downloads']); // set the title $context['page_title'] = $txt['tp-downloads']; $context['TPortal']['dl_title'] = $txt['tp-mainpage']; // load the dlmanager frontpage if ($context['TPortal']['dlaction'] == '') { $context['TPortal']['dlcats'] = array(); $context['TPortal']['dlcatchilds'] = array(); // add x most recent and feature the last one $context['TPortal']['dl_last_added'] = array(); $context['TPortal']['dl_most_downloaded'] = array(); $context['TPortal']['dl_week_downloaded'] = array(); $mycats = array(); dl_getcats(); foreach ($context['TPortal']['dl_allowed_cats'] as $ca) { $mycats[] = $ca['id']; } // empty? if (sizeof($mycats) > 0) { $request = $smcFunc['db_query']('', ' SELECT dlm.id, dlm.name, dlm.category, dlm.file, dlm.downloads, dlm.views, dlm.author_id as authorID, dlm.created, dlm.screenshot, dlm.filesize, dlcat.name AS catname, mem.real_name as realName, LEFT(dlm.description,100) as description FROM ({db_prefix}tp_dlmanager AS dlm, {db_prefix}members AS mem) LEFT JOIN {db_prefix}tp_dlmanager AS dlcat ON (dlcat.id = dlm.category) WHERE dlm.type = {string:type} AND dlm.category IN ({array_int:cat}) AND dlm.author_id = mem.id_member ORDER BY dlm.created DESC LIMIT 6', array('type' => 'dlitem', 'cat' => $mycats)); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $fs = ''; if ($context['TPortal']['dl_fileprefix'] == 'K') { $fs = ceil($row['filesize'] / 1000) . ' Kb'; } elseif ($context['TPortal']['dl_fileprefix'] == 'M') { $fs = ceil($row['filesize'] / 1000) / 1000 . ' Mb'; } elseif ($context['TPortal']['dl_fileprefix'] == 'G') { $fs = ceil($row['filesize'] / 1000000) / 1000 . ' Gb'; } if ($context['TPortal']['dl_usescreenshot'] == 1) { if (!empty($row['screenshot'])) { $ico = $boardurl . '/tp-images/dlmanager/thumb/' . $row['screenshot']; } else { $ico = ''; } } else { $ico = ''; } $context['TPortal']['dl_last_added'][] = array('id' => $row['id'], 'name' => $row['name'], 'category' => $row['category'], 'description' => $context['TPortal']['dl_wysiwyg'] == 'bbc' ? parse_bbc(trim(strip_tags($row['description']))) : $row['description'], 'file' => $row['file'], 'href' => $scripturl . '?action=tpmod;dl=item' . $row['id'], 'downloads' => $row['downloads'], 'views' => $row['views'], 'author' => '<a href="' . $scripturl . '?action=profile;u=' . $row['authorID'] . '">' . $row['realName'] . '</a>', 'authorID' => $row['authorID'], 'date' => timeformat($row['created']), 'screenshot' => $ico, 'catname' => $row['catname'], 'cathref' => $scripturl . '?action=tpmod;dl=cat' . $row['category'], 'filesize' => $fs); } $smcFunc['db_free_result']($request); } $request = $smcFunc['db_query']('', ' SELECT dlm.id, dlm.name, dlm.category, dlm.file, dlm.downloads, dlm.views, dlm.author_id as authorID, dlm.created, dlm.filesize, dlcat.name AS catname, mem.real_name as realName FROM ({db_prefix}tp_dlmanager AS dlm, {db_prefix}members AS mem) LEFT JOIN {db_prefix}tp_dlmanager AS dlcat ON dlcat.id = dlm.category WHERE dlm.type = {string:type} AND dlm.category IN ({array_string:cat}) AND dlm.author_id = mem.id_member ORDER BY dlm.downloads DESC LIMIT 10', array('type' => 'dlitem', 'cat' => $mycats)); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $fs = ''; if ($context['TPortal']['dl_fileprefix'] == 'K') { $fs = ceil($row['filesize'] / 1000) . ' Kb'; } elseif ($context['TPortal']['dl_fileprefix'] == 'M') { $fs = ceil($row['filesize'] / 1000) / 1000 . ' Mb'; } elseif ($context['TPortal']['dl_fileprefix'] == 'G') { $fs = ceil($row['filesize'] / 1000000) / 1000 . ' Gb'; } $context['TPortal']['dl_most_downloaded'][] = array('id' => $row['id'], 'name' => $row['name'], 'category' => $row['category'], 'file' => $row['file'], 'href' => $scripturl . '?action=tpmod;dl=item' . $row['id'], 'downloads' => $row['downloads'], 'views' => $row['views'], 'author' => '<a href="' . $scripturl . '?action=profile;u=' . $row['authorID'] . '">' . $row['realName'] . '</a>', 'authorID' => $row['authorID'], 'date' => timeformat($row['created']), 'catname' => $row['catname'], 'cathref' => $scripturl . '?action=tpmod;dl=cat' . $row['category'], 'filesize' => $fs); } $smcFunc['db_free_result']($request); } // fetch most downloaded this week $now = time(); $week = (int) date("W", $now); $year = (int) date("Y", $now); $request = $smcFunc['db_query']('', ' SELECT dlm.id, dlm.name, dlm.category, dlm.file, data.downloads, dlm.views, dlm.author_id as authorID, dlm.created, dlm.screenshot, dlm.filesize, dlcat.name AS catname, mem.real_name as realName FROM ({db_prefix}tp_dlmanager AS dlm, {db_prefix}tp_dldata AS data, {db_prefix}members AS mem) LEFT JOIN {db_prefix}tp_dlmanager AS dlcat ON dlcat.id = dlm.category WHERE dlm.type = {string:type} AND dlm.category IN ({array_string:cat}) AND data.item = dlm.id AND data.year = {int:yr} AND data.week = {int:week} AND dlm.author_id = mem.id_member ORDER BY data.downloads DESC LIMIT 10', array('type' => 'dlitem', 'cat' => $mycats, 'yr' => $year, 'week' => $week)); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { if ($context['TPortal']['dl_usescreenshot'] == 1) { if (!empty($row['screenshot'])) { $ico = $boardurl . '/tp-images/dlmanager/thumb/' . $row['screenshot']; } else { $ico = ''; } } else { $ico = ''; } $fs = ''; if ($context['TPortal']['dl_fileprefix'] == 'K') { $fs = ceil($row['filesize'] / 1000) . ' Kb'; } elseif ($context['TPortal']['dl_fileprefix'] == 'M') { $fs = ceil($row['filesize'] / 1000) / 1000 . ' Mb'; } elseif ($context['TPortal']['dl_fileprefix'] == 'G') { $fs = ceil($row['filesize'] / 1000000) / 1000 . ' Gb'; } $context['TPortal']['dl_week_downloaded'][] = array('id' => $row['id'], 'name' => $row['name'], 'category' => $row['category'], 'file' => $row['file'], 'href' => $scripturl . '?action=tpmod;dl=item' . $row['id'], 'downloads' => $row['downloads'], 'views' => $row['views'], 'author' => '<a href="' . $scripturl . '?action=profile;u=' . $row['authorID'] . '">' . $row['realName'] . '</a>', 'authorID' => $row['authorID'], 'date' => timeformat($row['created']), 'screenshot' => $ico, 'catname' => $row['catname'], 'cathref' => $scripturl . '?action=tpmod;dl=cat' . $row['category'], 'filesize' => $fs); } $smcFunc['db_free_result']($request); } } // fetch the categories, the number of files $request = $smcFunc['db_query']('', ' SELECT a.access AS access, a.icon AS icon, a.link AS shortname, a.description AS description, a.name AS name, a.id AS id, a.parent AS parent, if (a.id = b.category, count(*), 0) AS files, b.category AS subchild FROM ({db_prefix}tp_dlmanager AS a) LEFT JOIN {db_prefix}tp_dlmanager AS b ON (a.id = b.category) WHERE a.type = {string:type} GROUP BY a.id ORDER BY a.downloads ASC', array('type' => 'dlcat')); $fetched_cats = array(); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $show = get_perm($row['access'], 'tp_dlmanager'); if ($show && $row['parent'] == 0) { $context['TPortal']['dlcats'][$row['id']] = array('id' => $row['id'], 'name' => $row['name'], 'parent' => $row['parent'], 'description' => $context['TPortal']['dl_wysiwyg'] == 'bbc' ? parse_bbc(trim(strip_tags($row['description']))) : $row['description'], 'access' => $row['access'], 'icon' => $row['icon'], 'href' => !empty($row['shortname']) ? $scripturl . '?action=tpmod;dl=' . $row['shortname'] : $scripturl . '?action=tpmod;dl=cat' . $row['id'], 'shortname' => !empty($row['shortname']) ? $row['shortname'] : $row['id'], 'files' => $row['files']); $fetched_cats[] = $row['id']; } elseif ($show && $row['parent'] > 0) { $context['TPortal']['dlcatchilds'][] = array('id' => $row['id'], 'name' => $row['name'], 'parent' => $row['parent'], 'href' => $scripturl . '?action=tpmod;dl=cat' . $row['id'], 'files' => $row['files']); } } $smcFunc['db_free_result']($request); } // add filecount to parent foreach ($context['TPortal']['dlcatchilds'] as $child) { if (isset($context['TPortal']['dlcats'][$child['parent']]) && $context['TPortal']['dlcats'][$child['parent']]['parent'] == 0) { $context['TPortal']['dlcats'][$child['parent']]['files'] = $context['TPortal']['dlcats'][$child['parent']]['files'] + $child['files']; } } // do we need the featured one? if (!empty($context['TPortal']['dl_featured'])) { // fetch the item data $item = $context['TPortal']['dl_featured']; $request = $smcFunc['db_query']('', ' SELECT dl.* , dl.author_id as authorID, m.real_name as realName FROM ({db_prefix}tp_dlmanager AS dl, {db_prefix}members AS m) WHERE dl.type = {string:type} AND dl.id = {int:item} AND dl.author_id = m.id_member LIMIT 1', array('type' => 'dlitem', 'item' => $item)); if ($smcFunc['db_num_rows']($request) > 0) { $row = $smcFunc['db_fetch_assoc']($request); if ($context['TPortal']['dl_fileprefix'] == 'K') { $fs = ceil($row['filesize'] / 1000) . ' Kb'; } elseif ($context['TPortal']['dl_fileprefix'] == 'M') { $fs = ceil($row['filesize'] / 1000) / 1000 . ' Mb'; } elseif ($context['TPortal']['dl_fileprefix'] == 'G') { $fs = ceil($row['filesize'] / 1000000) / 1000 . ' Gb'; } $rat = array(); $rating_votes = 0; $rat = explode(',', $row['rating']); $rating_votes = count($rat); if ($row['rating'] == '') { $rating_votes = 0; } $total = 0; foreach ($rat as $mm => $mval) { $total = $total + $mval; } if ($rating_votes > 0 && $total > 0) { $rating_average = floor($total / $rating_votes); } else { $rating_average = 0; } $decideshot = !empty($row['screenshot']) ? $boardurl . '/' . $row['screenshot'] : ''; // does it exist? if (file_exists($boarddir . '/tp-images/dlmanager/listing/' . $row['screenshot']) && !empty($row['screenshot'])) { $decideshot = $boardurl . '/tp-images/dlmanager/listing/' . $row['screenshot']; } if ($context['user']['is_logged']) { $can_rate = in_array($context['user']['id'], explode(',', $row['voters'])) ? false : true; } else { $can_rate = false; } $context['TPortal']['featured'] = array('id' => $row['id'], 'name' => $row['name'], 'description' => $context['TPortal']['dl_wysiwyg'] == 'bbc' ? parse_bbc(trim(strip_tags($row['description']))) : $row['description'], 'category' => $row['category'], 'file' => $row['file'], 'href' => $scripturl . '?action=tpmod;dl=item' . $row['id'], 'downloads' => $row['downloads'], 'views' => $row['views'], 'link' => $row['link'], 'date_last' => $row['last_access'], 'author' => $row['realName'], 'authorID' => $row['authorID'], 'screenshot' => $row['screenshot'], 'sshot' => $decideshot, 'icon' => $row['icon'], 'created' => $row['created'], 'filesize' => $fs, 'subitem' => isset($fdata) ? $fdata : '', 'rating_votes' => $rating_votes, 'rating_average' => $rating_average, 'can_rate' => $can_rate); } $smcFunc['db_free_result']($request); } $context['TPortal']['dlheader'] = $txt['tp-downloads']; } elseif ($context['TPortal']['dlaction'] == 'cat') { // check if sorting is specified if (isset($_GET['dlsort']) && in_array($_GET['dlsort'], array('id', 'name', 'last_access', 'created', 'downloads', 'author_id'))) { $context['TPortal']['dlsort'] = $dlsort = $_GET['dlsort']; } else { $context['TPortal']['dlsort'] = $dlsort = 'id'; } if (isset($_GET['asc'])) { $context['TPortal']['dlsort_way'] = $dlsort_way = 'asc'; } else { $context['TPortal']['dlsort_way'] = $dlsort_way = 'desc'; } $currentcat = $context['TPortal']['dlcat']; //fetch all categories and its childs $context['TPortal']['dlcats'] = array(); $context['TPortal']['dlcatchilds'] = array(); $context['TPortal']['dl_week_downloaded'] = array(); // fetch most downloaded this week $now = time(); $week = (int) date("W", $now); $year = (int) date("Y", $now); $request = $smcFunc['db_query']('', ' SELECT dlm.id, dlm.name, dlm.category, dlm.file, dlm.downloads, dlm.views, dlm.author_id as authorID, dlm.created, dlm.screenshot, dlm.filesize, dlcat.name AS catname, mem.real_name as realName FROM ({db_prefix}tp_dlmanager AS dlm, {db_prefix}tp_dldata AS data, {db_prefix}members AS mem) LEFT JOIN {db_prefix}tp_dlmanager AS dlcat ON dlcat.id=dlm.category WHERE dlm.type = {string:type} AND (dlm.category = {int:cat} OR dlm.parent = {int:cat}) AND data.item = dlm.id AND data.year = {int:year} AND data.week = {int:week} AND dlm.author_id = mem.id_member ORDER BY dlm.downloads DESC LIMIT 10', array('type' => 'dlitem', 'cat' => $currentcat, 'year' => $year, 'week' => $week)); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $fs = ''; if ($context['TPortal']['dl_fileprefix'] == 'K') { $fs = ceil($row['filesize'] / 1000) . ' Kb'; } elseif ($context['TPortal']['dl_fileprefix'] == 'M') { $fs = ceil($row['filesize'] / 1000) / 1000 . ' Mb'; } elseif ($context['TPortal']['dl_fileprefix'] == 'G') { $fs = ceil($row['filesize'] / 1000000) / 1000 . ' Gb'; } $context['TPortal']['dl_week_downloaded'][] = array('id' => $row['id'], 'name' => $row['name'], 'category' => $row['category'], 'file' => $row['file'], 'href' => $scripturl . '?action=tpmod;dl=item' . $row['id'], 'downloads' => $row['downloads'], 'views' => $row['views'], 'author' => '<a href="' . $scripturl . '?action=profile;u=' . $row['authorID'] . '">' . $row['realName'] . '</a>', 'authorID' => $row['authorID'], 'date' => timeformat($row['created']), 'screenshot' => !empty($row['screenshot']) ? $row['screenshot'] : '', 'catname' => $row['catname'], 'cathref' => $scripturl . '?action=tpmod;dl=cat' . $row['category'], 'filesize' => $fs); } $smcFunc['db_free_result']($request); } // add x most recent and feature the last one $context['TPortal']['dl_last_added'] = dl_recentitems(5, 'date', 'array', $context['TPortal']['dlcat']); $context['TPortal']['dl_most_downloaded'] = dl_recentitems(5, 'downloads', 'array', $context['TPortal']['dlcat']); // do we have access then? $request = $smcFunc['db_query']('', ' SELECT parent, access, name FROM {db_prefix}tp_dlmanager WHERE id = {int:cat}', array('cat' => $currentcat)); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $currentname = $row['name']; $context['page_title'] = $row['name']; $catparent = $row['parent']; if (!get_perm($row['access'], 'tp_dlmanager')) { // if a guest, make them login/register if ($context['user']['is_guest']) { redirectexit('action=login'); } else { redirectexit('action=tpmod;dl'); } } } $smcFunc['db_free_result']($request); } else { redirectexit('action=tpmod;dl'); } $request = $smcFunc['db_query']('', ' SELECT a.access AS access, a.icon AS icon, a.link AS shortname, a.description AS description, a.name AS name, a.id AS id, a.parent AS parent, if (a.id = b.category, count(*), 0) AS files, b.category AS subchild FROM ({db_prefix}tp_dlmanager AS a) LEFT JOIN {db_prefix}tp_dlmanager AS b ON a.id = b.category WHERE a.type = {string:type} AND a.parent = {int:cat} GROUP BY a.id ORDER BY a.downloads ASC', array('type' => 'dlcat', 'cat' => $currentcat)); $context['TPortal']['dlchildren'] = array(); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $show = get_perm($row['access'], 'tp_dlmanager'); if ($show && $row['parent'] == $currentcat) { $context['TPortal']['dlcats'][] = array('id' => $row['id'], 'name' => $row['name'], 'parent' => $row['parent'], 'description' => $context['TPortal']['dl_wysiwyg'] == 'bbc' ? parse_bbc(trim(strip_tags($row['description']))) : $row['description'], 'access' => $row['access'], 'icon' => $row['icon'], 'href' => !empty($row['shortname']) ? $scripturl . '?action=tpmod;dl=' . $row['shortname'] : $scripturl . '?action=tpmod;dl=cat' . $row['id'], 'shortname' => !empty($row['shortname']) ? $row['shortname'] : $row['id'], 'files' => $row['files']); } elseif ($show && $row['parent'] != $currentcat) { $context['TPortal']['dlchildren'][] = $row['id']; $context['TPortal']['dlcatchilds'][] = array('id' => $row['id'], 'name' => $row['name'], 'parent' => $row['parent'], 'href' => !empty($row['shortname']) ? $scripturl . '?action=tpmod;dl=' . $row['shortname'] : $scripturl . '?action=tpmod;dl=cat' . $row['id'], 'shortname' => !empty($row['shortname']) ? $row['shortname'] : $row['id'], 'files' => $row['files']); } } $smcFunc['db_free_result']($request); } // get any items in the category $context['TPortal']['dlitem'] = array(); $start = 0; if (isset($_GET['p']) && !is_numeric($_GET['p'])) { fatal_error('Attempt to specify a non-integer value!'); } elseif (isset($_GET['p']) && is_numeric($_GET['p'])) { $start = $_GET['p']; } // get total count $request = $smcFunc['db_query']('', ' SELECT COUNT(*) FROM {db_prefix}tp_dlmanager WHERE type = {string:type} AND category = {int:cat} AND subitem = {int:sub}', array('type' => 'dlitem', 'cat' => $currentcat, 'sub' => 0)); $row = $smcFunc['db_fetch_row']($request); $rows2 = $row[0]; $request = $smcFunc['db_query']('', ' SELECT dl.id, LEFT(dl.description, 400) as ingress,dl.name, dl.category, dl.file, dl.downloads, dl.views, dl.link, dl.created, dl.last_access, dl.author_id as authorID, dl.icon, dl.screenshot, dl.filesize, mem.real_name as realName FROM {db_prefix}tp_dlmanager as dl LEFT JOIN {db_prefix}members as mem ON (dl.author_id=mem.id_member) WHERE dl.type = {string:type} AND dl.category = {int:cat} AND dl.subitem = {int:sub} ORDER BY dl.' . $dlsort . ' ' . $dlsort_way . ' LIMIT {int:start}, 10', array('type' => 'dlitem', 'cat' => $currentcat, 'sub' => 0, 'start' => $start)); if ($smcFunc['db_num_rows']($request) > 0) { // set up the sorting links $context['TPortal']['sortlinks'] = '<span class="smalltext">' . $txt['tp-sortby'] . ': '; $what = array('id', 'name', 'downloads', 'last_access', 'created', 'authorID'); foreach ($what as $v) { if ($context['TPortal']['dlsort'] == $v) { $context['TPortal']['sortlinks'] .= '<a href="' . $scripturl . '?action=tpmod;dl=cat' . $currentcat . ';dlsort=' . $v . ';'; if ($context['TPortal']['dlsort_way'] == 'asc') { $context['TPortal']['sortlinks'] .= 'desc;p=' . $start . '">' . $txt['tp-' . $v] . ' <img src="' . $settings['tp_images_url'] . '/TPsort_up.gif" alt="" /></a> | '; } else { $context['TPortal']['sortlinks'] .= 'asc;p=' . $start . '">' . $txt['tp-' . $v] . ' <img src="' . $settings['tp_images_url'] . '/TPsort_down.gif" alt="" /></a> | '; } } else { $context['TPortal']['sortlinks'] .= '<a href="' . $scripturl . '?action=tpmod;dl=cat' . $currentcat . ';dlsort=' . $v . ';desc;p=' . $start . '">' . $txt['tp-' . $v] . '</a> | '; } } $context['TPortal']['sortlinks'] = substr($context['TPortal']['sortlinks'], 0, strlen($context['TPortal']['sortlinks']) - 15); $context['TPortal']['sortlinks'] .= '</span>'; while ($row = $smcFunc['db_fetch_assoc']($request)) { if (substr($row['screenshot'], 0, 16) == 'tp-images/Image/') { $decideshot = $boardurl . '/' . $row['screenshot']; } else { $decideshot = $boardurl . '/tp-images/dlmanager/thumb/' . $row['screenshot']; } if ($context['TPortal']['dl_fileprefix'] == 'K') { $fs = ceil($row['filesize'] / 1000) . ' Kb'; } elseif ($context['TPortal']['dl_fileprefix'] == 'M') { $fs = ceil($row['filesize'] / 1000) / 1000 . ' Mb'; } elseif ($context['TPortal']['dl_fileprefix'] == 'G') { $fs = ceil($row['filesize'] / 1000000) / 1000 . ' Gb'; } if ($context['TPortal']['dl_usescreenshot'] == 1) { if (!empty($row['screenshot'])) { $ico = $boardurl . '/tp-images/dlmanager/thumb/' . $row['screenshot']; } else { $ico = ''; } } else { $ico = $row['icon']; } $context['TPortal']['dlitem'][] = array('id' => $row['id'], 'name' => $row['name'], 'category' => $row['category'], 'file' => $row['file'], 'description' => '', 'href' => $scripturl . '?action=tpmod;dl=item' . $row['id'], 'dlhref' => $scripturl . '?action=tpmod;dl=get' . $row['id'], 'downloads' => $row['downloads'], 'views' => $row['views'], 'link' => $row['link'], 'created' => $row['created'], 'date_last' => $row['last_access'], 'author' => '<a href="' . $scripturl . '?action=profile;u=' . $row['authorID'] . '">' . $row['realName'] . '</a>', 'authorID' => $row['authorID'], 'screenshot' => $row['screenshot'], 'sshot' => $decideshot, 'icon' => $ico, 'date' => $row['created'], 'filesize' => $fs, 'ingress' => $context['TPortal']['dl_wysiwyg'] == 'bbc' ? parse_bbc(trim(strip_tags($row['ingress']))) : $row['ingress']); } $smcFunc['db_free_result']($request); } if (isset($context['TPortal']['mystart'])) { $mystart = $context['TPortal']['mystart']; } $currsorting = ''; if (!empty($dlsort)) { $currsorting .= ';dlsort=' . $dlsort; } if (!empty($dlsort_way)) { $currsorting .= ';' . $dlsort_way; } // construct a pageindex $context['TPortal']['pageindex'] = TPageIndex($scripturl . '?action=tpmod;dl=cat' . $currentcat . $currsorting, $mystart, $rows2, 10); // check backwards for parents $done = 0; $context['TPortal']['parents'] = array(); while ($catparent > 0 || $done < 2) { if (!empty($context['TPortal']['cats'][$catparent])) { $context['TPortal']['parents'][] = array('id' => $catparent, 'name' => $context['TPortal']['cats'][$catparent]['name'], 'parent' => $context['TPortal']['cats'][$catparent]['parent']); $catparent = $context['TPortal']['cats'][$catparent]['parent']; } else { $catparent = 0; } if ($catparent == 0) { $done++; } } // make the linktree if (sizeof($context['TPortal']['parents']) > 0) { $parts = array_reverse($context['TPortal']['parents']); // add to the linktree foreach ($parts as $par) { TPadd_linktree($scripturl . '?action=tpmod;dl=cat' . $par['id'], $par['name']); } } // add to the linktree TPadd_linktree($scripturl . '?action=tpmod;dl=cat' . $currentcat, $currentname); $context['TPortal']['dlheader'] = $currentname; } elseif ($context['TPortal']['dlaction'] == 'tptag') { $context['TPortal']['dlsort'] = $dlsort = 'id'; $context['TPortal']['dlsort_way'] = $dlsort_way = 'desc'; // get any items in the category $context['TPortal']['dlitem'] = array(); $start = 0; if (isset($_GET['p']) && !is_numeric($_GET['p'])) { fatal_error($txt['tp-dlnonint']); } elseif (isset($_GET['p']) && is_numeric($_GET['p'])) { $start = $_GET['p']; } // get total count $request = $smcFunc['db_query']('', ' SELECT COUNT(*) FROM {db_prefix}tp_dlmanager WHERE type = {string:type} AND subitem = {int:sub}', array('type' => 'dlitem', 'sub' => 0)); $row = $smcFunc['db_fetch_row']($request); $rows2 = $row[0]; $request = $smcFunc['db_query']('', ' SELECT id, name, category, file, downloads, views, link, created, last_access, author_id as authorID, icon, screenshot, filesize, global_tag FROM {db_prefix}tp_dlmanager WHERE type = {string:type} AND subitem = {int:sub} LIMIT {int:start}, 10', array('type' => 'dlitem', 'sub' => 0, 'start' => $start)); if ($smcFunc['db_num_rows']($request) > 0) { if (substr($row['screenshot'], 0, 16) == 'tp-images/Image/') { $decideshot = $boardurl . '/' . $row['screenshot']; } else { $decideshot = $boardurl . '/tp-images/dlmanager/thumb/' . $row['screenshot']; } // set up the sorting links $context['TPortal']['sortlinks'] = ''; while ($row = $smcFunc['db_fetch_assoc']($request)) { if ($context['TPortal']['dl_fileprefix'] == 'K') { $fs = ceil($row['filesize'] / 1000) . ' Kb'; } elseif ($context['TPortal']['dl_fileprefix'] == 'M') { $fs = ceil($row['filesize'] / 1000) / 1000 . ' Mb'; } elseif ($context['TPortal']['dl_fileprefix'] == 'G') { $fs = ceil($row['filesize'] / 1000000) / 1000 . ' Gb'; } $context['TPortal']['dlitem'][] = array('id' => $row['id'], 'name' => $row['name'], 'category' => $row['category'], 'file' => $row['file'], 'description' => '', 'href' => $scripturl . '?action=tpmod;dl=item' . $row['id'], 'dlhref' => $scripturl . '?action=tpmod;dl=get' . $row['id'], 'downloads' => $row['downloads'], 'views' => $row['views'], 'link' => $row['link'], 'created' => $row['created'], 'date_last' => $row['last_access'], 'author' => '', 'authorID' => $row['authorID'], 'screenshot' => $row['screenshot'], 'sshot' => $decideshot, 'icon' => $row['icon'], 'date' => $row['created'], 'filesize' => $fs); } $smcFunc['db_free_result']($request); } if (isset($context['TPortal']['mystart'])) { $mystart = $context['TPortal']['mystart']; } $context['TPortal']['dlheader'] = ''; } elseif ($context['TPortal']['dlaction'] == 'item') { //fetch the category $cat = $context['TPortal']['dlcat']; $context['TPortal']['dlcats'] = array(); $catname = ''; $catdesc = ''; $request = $smcFunc['db_query']('', ' SELECT id, name, parent, icon, access, link FROM {db_prefix}tp_dlmanager WHERE id = {int:cat} AND type = {string:type} LIMIT 1', array('cat' => $cat, 'type' => 'dlcat')); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $catshortname = $row['link']; $catname = $row['name']; $catparent = $row['parent']; $firstparent = $row['parent']; // check if you are allowed in here $show = get_perm($row['access'], 'tp_dlmanager'); if (!$show) { redirectexit('action=tpmod;dl'); } } $smcFunc['db_free_result']($request); } // set the title $context['TPortal']['dl_title'] = $catname; $context['TPortal']['parents'] = array(); // check backwards for parents $done = 0; while ($catparent > 0 || $done < 2) { if (!empty($context['TPortal']['cats'][$catparent])) { $context['TPortal']['parents'][] = array('id' => $catparent, 'shortname' => $catshortname, 'name' => $context['TPortal']['cats'][$catparent]['name'], 'parent' => $context['TPortal']['cats'][$catparent]['parent']); $catparent = $context['TPortal']['cats'][$catparent]['parent']; } else { $catparent = 0; } if ($catparent == 0) { $done++; } } // make the linktree if (sizeof($context['TPortal']['parents']) > 0) { $parts = array_reverse($context['TPortal']['parents'], TRUE); // add to the linktree foreach ($parts as $parent) { if (!empty($parent['shortname'])) { TPadd_linktree($scripturl . '?action=tpmod;dl=' . $parent['shortname'], $parent['name']); } else { TPadd_linktree($scripturl . '?action=tpmod;dl=cat' . $parent['id'], $parent['name']); } } } // fetch the item data $item = $context['TPortal']['item'] = $item; $context['TPortal']['dlitem'] = array(); $request = $smcFunc['db_query']('', ' SELECT dl.*, dl.author_id as authorID, m.real_name as realName FROM ({db_prefix}tp_dlmanager AS dl) LEFT JOIN {db_prefix}members AS m ON (m.id_member = dl.author_id) WHERE dl.type = {string:type} AND dl.id = {int:item} LIMIT 1', array('type' => 'dlitem', 'item' => $item)); if ($smcFunc['db_num_rows']($request) > 0) { $rows = $smcFunc['db_num_rows']($request); while ($row = $smcFunc['db_fetch_assoc']($request)) { $subitem = $row['id']; $fetch = $smcFunc['db_query']('', ' SELECT id, name, file, downloads, filesize, created, views FROM {db_prefix}tp_dlmanager WHERE type = {string:type} AND subitem = {int:sub} ORDER BY id DESC', array('type' => 'dlitem', 'sub' => $subitem)); if ($smcFunc['db_num_rows']($fetch) > 0) { $fdata = array(); while ($frow = $smcFunc['db_fetch_assoc']($fetch)) { if ($context['TPortal']['dl_fileprefix'] == 'K') { $ffs = ceil($row['filesize'] / 1000) . ' Kb'; } elseif ($context['TPortal']['dl_fileprefix'] == 'M') { $ffs = ceil($row['filesize'] / 1000) / 1000 . ' Mb'; } elseif ($context['TPortal']['dl_fileprefix'] == 'G') { $ffs = ceil($row['filesize'] / 1000000) / 1000 . ' Gb'; } $fdata[] = array('id' => $frow['id'], 'name' => $frow['name'], 'file' => $frow['file'], 'href' => $scripturl . '?action=tpmod;dl=get' . $frow['id'], 'href2' => $scripturl . '?action=tpmod;dl=item' . $frow['id'], 'downloads' => $frow['downloads'], 'views' => $frow['views'], 'created' => $frow['created'], 'filesize' => $ffs); } $smcFunc['db_free_result']($fetch); } if ($context['TPortal']['dl_fileprefix'] == 'K') { $fs = ceil($row['filesize'] / 1000) . ' Kb'; } elseif ($context['TPortal']['dl_fileprefix'] == 'M') { $fs = ceil($row['filesize'] / 1000) / 1000 . ' Mb'; } elseif ($context['TPortal']['dl_fileprefix'] == 'G') { $fs = ceil($row['filesize'] / 1000000) / 1000 . ' Gb'; } $rat = array(); $rating_votes = 0; $rat = explode(',', $row['rating']); $rating_votes = count($rat); if ($row['rating'] == '') { $rating_votes = 0; } $total = 0; foreach ($rat as $mm => $mval) { $total = $total + $mval; } if ($rating_votes > 0 && $total > 0) { $rating_average = floor($total / $rating_votes); } else { $rating_average = 0; } $bigshot = $decideshot = !empty($row['screenshot']) ? $boardurl . '/' . $row['screenshot'] : ''; // does it exist? if (file_exists($boarddir . '/tp-images/dlmanager/listing/' . $row['screenshot']) && !empty($row['screenshot'])) { $decideshot = $boardurl . '/tp-images/dlmanager/listing/' . $row['screenshot']; } if (file_exists($boarddir . '/tp-images/dlmanager/' . $row['screenshot']) && !empty($row['screenshot'])) { $bigshot = $boardurl . '/tp-images/dlmanager/' . $row['screenshot']; } if ($context['user']['is_logged']) { $can_rate = in_array($context['user']['id'], explode(',', $row['voters'])) ? false : true; } else { $can_rate = false; } $context['TPortal']['dlitem'][] = array('id' => $row['id'], 'name' => $row['name'], 'description' => $context['TPortal']['dl_wysiwyg'] == 'bbc' ? parse_bbc(trim(strip_tags($row['description']))) : $row['description'], 'category' => $row['category'], 'file' => $row['file'], 'href' => $scripturl . '?action=tpmod;dl=get' . $row['id'], 'downloads' => $row['downloads'], 'views' => $row['views'], 'link' => $row['link'], 'date_last' => $row['last_access'], 'author' => $row['realName'], 'authorID' => $row['authorID'], 'screenshot' => $row['screenshot'], 'sshot' => $decideshot, 'bigshot' => $bigshot, 'icon' => $row['icon'], 'created' => $row['created'], 'filesize' => $fs, 'subitem' => isset($fdata) ? $fdata : '', 'rating_votes' => $rating_votes, 'rating_average' => $rating_average, 'can_rate' => $can_rate, 'global_tag' => $row['global_tag']); $author = $row['authorID']; $parent_cat = $row['category']; $views = $row['views']; $itemname = $row['name']; $itemid = $row['id']; $context['page_title'] = $row['name']; } $smcFunc['db_free_result']($request); TPadd_linktree($scripturl . '?action=tpmod;dl=cat' . $parent_cat, $catname); TPadd_linktree($scripturl . '?action=tpmod;dl=item' . $itemid, $itemname); // update the views and last access! $views++; $now = time(); $year = (int) date("Y", $now); $week = (int) date("W", $now); // update weekly views $req = $smcFunc['db_query']('', ' SELECT id FROM {db_prefix}tp_dldata WHERE year = {int:year} AND week = {int:week} AND item = {int:item}', array('year' => $year, 'week' => $week, 'item' => $itemid)); if ($smcFunc['db_num_rows']($req) > 0) { $row = $smcFunc['db_fetch_assoc']($req); $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_dldata SET views = views + 1 WHERE id = {int:item}', array('item' => $row['id'])); } else { $smcFunc['db_insert']('INSERT', '{db_prefix}tp_dldata', array('week' => 'int', 'year' => 'int', 'views' => 'int', 'item' => 'int'), array($week, $year, 1, $itemid), array('id')); } $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_dlmanager SET views = {int:views}, last_access = {int:last} WHERE id = {int:item}', array('views' => $views, 'last' => $now, 'item' => $itemid)); $context['TPortal']['dlheader'] = $itemname; } } elseif ($context['TPortal']['dlaction'] == 'get') { TPdownloadme(); } elseif ($context['TPortal']['dlaction'] == 'stats') { TPdlstats(); } elseif ($context['TPortal']['dlaction'] == 'results') { TPdlresults(); } elseif ($context['TPortal']['dlaction'] == 'search') { TPdlsearch(); } // For wireless, we use the Wireless template... if (WIRELESS) { loadTemplate('TPwireless'); if ($context['TPortal']['dlaction'] == 'item' || $context['TPortal']['dlaction'] == 'cat') { $what = $context['TPortal']['dlaction']; } else { $what = 'main'; } $context['sub_template'] = WIRELESS_PROTOCOL . '_tp_dl_' . $what; } else { loadTemplate('TPdlmanager'); } }