function do_articles() { global $context, $txt, $settings, $boardurl, $scripturl, $smcFunc; // do an update of stray articles and categories $acats = array(); $request = $smcFunc['db_query']('', ' SELECT id FROM {db_prefix}tp_variables WHERE type = {string:type}', array('type' => 'category')); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $acats[] = $row['id']; } $smcFunc['db_free_result']($request); } if (count($acats) > 0) { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET value2 = {int:val2} WHERE type = {string:type} AND value2 NOT IN ({array_string:value2})', array('val2' => 0, 'type' => 'category', 'value2' => $acats)); $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET category = {int:cat} WHERE category NOT IN({array_int:category}) AND category > 0', array('cat' => 0, 'category' => $acats)); } // first check any ajax stuff if (isset($_GET['arton'])) { checksession('get'); $what = is_numeric($_GET['arton']) ? $_GET['arton'] : '0'; if ($what > 0) { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET off = IF(off = 0 , 1, 0) WHERE id = {int:artid}', array('artid' => $what)); } else { return; } } elseif (isset($_GET['artlock'])) { checksession('get'); $what = is_numeric($_GET['artlock']) ? $_GET['artlock'] : '0'; if ($what > 0) { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET locked = IF(locked = 0 , 1, 0) WHERE id = {int:artid}', array('artid' => $what)); } else { return; } } elseif (isset($_GET['artsticky'])) { checksession('get'); $what = is_numeric($_GET['artsticky']) ? $_GET['artsticky'] : '0'; if ($what > 0) { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET sticky = IF(sticky = 0 , 1, 0) WHERE id = {int:artid}', array('artid' => $what)); } else { return; } } elseif (isset($_GET['artfront'])) { checksession('get'); $what = is_numeric($_GET['artfront']) ? $_GET['artfront'] : '0'; if ($what > 0) { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET frontpage = IF(frontpage = 0 , 1, 0) WHERE id = {int:artid}', array('artid' => $what)); } else { return; } } elseif (isset($_GET['artfeat'])) { checksession('get'); $what = is_numeric($_GET['artfeat']) ? $_GET['artfeat'] : '0'; if ($what > 0) { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET featured = IF(featured = 0, 1, 0) WHERE id = {int:artid}', array('artid' => $what)); $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET featured = {int:featured} WHERE id != {int:artid}', array('featured' => 0, 'artid' => $what)); } else { return; } } elseif (isset($_GET['catdelete'])) { checksession('get'); $what = is_numeric($_GET['catdelete']) ? $_GET['catdelete'] : '0'; if ($what > 0) { // first get info $request = $smcFunc['db_query']('', ' SELECT id, value2 FROM {db_prefix}tp_variables WHERE id = {int:varid} LIMIT 1', array('varid' => $what)); $row = $smcFunc['db_fetch_assoc']($request); $smcFunc['db_free_result']($request); $newcat = !empty($row['value2']) ? $row['value2'] : 0; $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_variables SET value2 = {int:val2} WHERE value2 = {int:varid}', array('val2' => $newcat, 'varid' => $what)); $smcFunc['db_query']('', ' DELETE FROM {db_prefix}tp_variables WHERE id = {int:varid}', array('varid' => $what)); $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_articles SET category = {int:cat} WHERE category = {int:catid}', array('cat' => $newcat, 'catid' => $what)); redirectexit('action=tpadmin;sa=categories'); } else { redirectexit('action=tpadmin;sa=categories'); } } elseif (isset($_GET['artdelete'])) { checksession('get'); $what = is_numeric($_GET['artdelete']) ? $_GET['artdelete'] : '0'; $cu = is_numeric($_GET['cu']) ? $_GET['cu'] : ''; if ($cu == -1) { $strays = true; $cu = ''; } if ($what > 0) { $smcFunc['db_query']('', ' DELETE FROM {db_prefix}tp_articles WHERE id = {int:artid}', array('artid' => $what)); $smcFunc['db_query']('', ' DELETE FROM {db_prefix}tp_variables WHERE value5 = {int:artid}', array('artid' => $what)); } redirectexit('action=tpadmin' . (!empty($cu) ? ';cu=' . $cu : '') . (isset($strays) ? ';sa=strays' . $cu : ';sa=articles')); } // for the non-category articles, do a count. $request = $smcFunc['db_query']('', ' SELECT COUNT(*) as total FROM {db_prefix}tp_articles WHERE category = 0 OR category = 9999'); $row = $smcFunc['db_fetch_assoc']($request); $context['TPortal']['total_nocategory'] = $row['total']; $smcFunc['db_free_result']($request); // for the submissions too $request = $smcFunc['db_query']('', ' SELECT COUNT(*) as total FROM {db_prefix}tp_articles WHERE approved = 0'); $row = $smcFunc['db_fetch_assoc']($request); $context['TPortal']['total_submissions'] = $row['total']; $smcFunc['db_free_result']($request); // we are on categories screen if (in_array($context['TPortal']['subaction'], array('categories', 'addcategory'))) { TPadd_linktree($scripturl . '?action=tpadmin;sa=categories', $txt['tp-categories']); // first check if we simply want to copy or set as child if (isset($_GET['cu']) && is_numeric($_GET['cu'])) { $ccat = $_GET['cu']; if (isset($_GET['copy'])) { $request = $smcFunc['db_query']('', ' SELECT * FROM {db_prefix}tp_variables WHERE id = {int:varid}', array('varid' => $ccat)); if ($smcFunc['db_num_rows']($request) > 0) { $row = $smcFunc['db_fetch_assoc']($request); $row['value1'] .= '__copy'; $smcFunc['db_free_result']($request); $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($row['value1'], $row['value2'], $row['value3'], $row['type'], $row['value4'], $row['value5'], $row['subtype'], $row['value7'], $row['value8'], $row['subtype2']), array('id')); } redirectexit('action=tpadmin;sa=categories'); } elseif (isset($_GET['child'])) { $request = $smcFunc['db_query']('', ' SELECT * FROM {db_prefix}tp_variables WHERE id = {int:varid}', array('varid' => $ccat)); if ($smcFunc['db_num_rows']($request) > 0) { $row = $smcFunc['db_fetch_assoc']($request); $row['value1'] .= '__copy'; $smcFunc['db_free_result']($request); $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($row['value1'], $row['id'], $row['value3'], $row['type'], $row['value4'], $row['value5'], $row['subtype'], $row['value7'], $row['value8'], $row['subtype2']), array('id')); } redirectexit('action=tpadmin;sa=categories'); } else { // get membergroups get_grps(); $context['html_headers'] .= ' <script type="text/javascript"><!-- // --><![CDATA[ function changeIllu(node,name) { node.src = \'' . $boardurl . '/tp-files/tp-articles/illustrations/\' + name; } function changeIcon(node,name) { node.src = \'' . $boardurl . '/tp-files/tp-articles/icons/\' + name; } // ]]></script>'; $request = $smcFunc['db_query']('', ' SELECT * FROM {db_prefix}tp_variables WHERE id = {int:varid} LIMIT 1', array('varid' => $ccat)); if ($smcFunc['db_num_rows']($request) > 0) { $row = $smcFunc['db_fetch_assoc']($request); $o = explode('|', $row['value7']); foreach ($o as $t => $opt) { $b = explode('=', $opt); if (isset($b[1])) { $row[$b[0]] = $b[1]; } } $smcFunc['db_free_result']($request); $check = array('layout', 'catlayout', 'toppanel', 'bottompanel', 'leftpanel', 'rightpanel', 'upperpanel', 'lowerpanel', 'showchild'); foreach ($check as $c => $ch) { if (!isset($row[$ch])) { $row[$ch] = 0; } } $context['TPortal']['editcategory'] = $row; } // fetch all categories and subcategories $request = $smcFunc['db_query']('', ' SELECT id, value1 as name, value2 as parent, value3, value4, value5, subtype, value7, value8, subtype2 FROM {db_prefix}tp_variables WHERE type = {string:type}', array('type' => 'category')); $context['TPortal']['editcats'] = array(); $allsorted = array(); $alcats = array(); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $row['indent'] = 0; $allsorted[$row['id']] = $row; $alcats[] = $row['id']; } $smcFunc['db_free_result']($request); if (count($allsorted) > 1) { $context['TPortal']['editcats'] = chain('id', 'parent', 'name', $allsorted); } else { $context['TPortal']['editcats'] = $allsorted; } } TPadd_linktree($scripturl . '?action=tpadmin;sa=categories;cu=' . $ccat, $txt['tp-editcategory']); } return; } // fetch all categories and subcategories $request = $smcFunc['db_query']('', ' SELECT id, value1 as name, value2 as parent, value3, value4, value5, subtype, value7, value8, subtype2 FROM {db_prefix}tp_variables WHERE type = {string:type}', array('type' => 'category')); $context['TPortal']['editcats'] = array(); $allsorted = array(); $alcats = array(); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $row['indent'] = 0; $allsorted[$row['id']] = $row; $alcats[] = $row['id']; } $smcFunc['db_free_result']($request); if (count($allsorted) > 1) { $context['TPortal']['editcats'] = chain('id', 'parent', 'name', $allsorted); } else { $context['TPortal']['editcats'] = $allsorted; } } // get the filecount as well if (count($alcats) > 0) { $request = $smcFunc['db_query']('', ' SELECT art.category as id, COUNT(art.id) as files FROM {db_prefix}tp_articles as art WHERE art.category IN ({string:cats}) GROUP BY art.category', array('cats' => implode(',', $alcats))); if ($smcFunc['db_num_rows']($request) > 0) { $context['TPortal']['cats_count'] = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { $context['TPortal']['cats_count'][$row['id']] = $row['files']; } $smcFunc['db_free_result']($request); } } if ($context['TPortal']['subaction'] == 'addcategory') { TPadd_linktree($scripturl . '?action=tpadmin;sa=addcategory', $txt['tp-addcategory']); } return; } TPadd_linktree($scripturl . '?action=tpadmin;sa=articles', $txt['tp-articles']); // are we inside a category? if (isset($_GET['cu']) && is_numeric($_GET['cu'])) { $where = $_GET['cu']; } // show the no category articles? if (isset($_GET['sa']) && $_GET['sa'] == 'strays') { TPadd_linktree($scripturl . '?action=tpadmin;sa=strays', $txt['tp-strays']); $show_nocategory = true; } // submissions? if (isset($_GET['sa']) && $_GET['sa'] == 'submission') { TPadd_linktree($scripturl . '?action=tpadmin;sa=submission', $txt['tp-submissions']); $show_submission = true; } // single article? if (isset($_GET['sa']) && substr($_GET['sa'], 0, 11) == 'editarticle') { TPadd_linktree($scripturl . '?action=tpadmin;sa=' . $_GET['sa'], $txt['tp-editarticle']); $whatarticle = substr($_GET['sa'], 11); } // are we starting a new one? if (isset($_GET['sa']) && substr($_GET['sa'], 0, 11) == 'addarticle_') { TPadd_linktree($scripturl . '?action=tpadmin;sa=' . $_GET['sa'], $txt['tp-addarticle']); $context['TPortal']['editarticle'] = array('id' => '', 'date' => time(), 'body' => '', 'intro' => '', 'useintro' => 0, 'category' => !empty($_GET['cu']) ? $_GET['cu'] : 0, 'frontpage' => 1, 'author_id' => $context['user']['id'], 'subject' => '', 'author' => $context['user']['name'], 'frame' => 'theme', 'approved' => 0, 'off' => 1, 'options' => 'date,title,author,linktree,top,cblock,rblock,lblock,bblock,tblock,lbblock,category,catlist,comments,commentallow,commentupshrink,views,rating,ratingallow,avatar,inherit,social,nofrontsetting', 'parse' => 0, 'comments' => 0, 'comments_var' => '', 'views' => 0, 'rating' => 0, 'voters' => '', 'id_theme' => 0, 'shortname' => '', 'sticky' => 0, 'fileimport' => '', 'topic' => 0, 'locked' => 0, 'illustration' => '', 'headers' => '', 'type' => substr($_GET['sa'], 11), 'featured' => 0, 'realName' => $context['user']['name'], 'authorID' => $context['user']['id'], 'articletype' => substr($_GET['sa'], 11), 'ID_THEME' => 0, 'pub_start' => 0, 'pub_end' => 0); $context['html_headers'] .= ' <script type="text/javascript"><!-- // --><![CDATA[ function changeIllu(node,name) { node.src = \'' . $boardurl . '/tp-files/tp-articles/illustrations/\' + name; } function changeIcon(node,name) { node.src = \'' . $boardurl . '/tp-files/tp-articles/icons/\' + name; } // ]]></script>'; // Add in BBC editor before we call in template so the headers are there if (substr($_GET['sa'], 11) == 'bbc') { $context['TPortal']['editor_id'] = 'tp_article_body'; TP_prebbcbox($context['TPortal']['editor_id']); } } // fetch categories and subcategories if (!isset($show_nocategory)) { $request = $smcFunc['db_query']('', ' SELECT DISTINCT var.id as id, var.value1 as name, var.value2 as parent FROM {db_prefix}tp_variables AS var WHERE var.type = {string:type} ' . (isset($where) ? 'AND var.value2 = {int:whereval}' : '') . ' ORDER BY parent, id DESC', array('type' => 'category', 'whereval' => isset($where) ? $where : 0)); if ($smcFunc['db_num_rows']($request) > 0) { $context['TPortal']['basecats'] = isset($where) ? array($where) : array('0', '9999'); $cats = array(); $context['TPortal']['cats'] = array(); $sorted = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { $sorted[$row['id']] = $row; $cats[] = $row['id']; } $smcFunc['db_free_result']($request); if (count($sorted) > 1) { $context['TPortal']['cats'] = chain('id', 'parent', 'name', $sorted); } else { $context['TPortal']['cats'] = $sorted; } } } if (isset($show_submission) && $context['TPortal']['total_submissions'] > 0) { // check if we have any start values $start = !empty($_GET['p']) && is_numeric($_GET['p']) ? $_GET['p'] : 0; // sorting? $sort = $context['TPortal']['sort'] = !empty($_GET['sort']) && in_array($_GET['sort'], array('date', 'id', 'author_id', 'type', 'subject', 'parse')) ? $_GET['sort'] : 'date'; $context['TPortal']['pageindex'] = TPageIndex($scripturl . '?action=tpadmin;sa=submission;sort=' . $sort, $start, $context['TPortal']['total_submissions'], 15); $request = $smcFunc['db_query']('', ' SELECT art.id, art.date, art.frontpage, art.category, art.author_id as authorID, IFNULL(mem.real_name, art.author) as author, art.subject, art.approved, art.sticky, art.type, art.featured, art.locked, art.off, art.parse as pos FROM {db_prefix}tp_articles AS art LEFT JOIN {db_prefix}members AS mem ON (art.author_id = mem.id_member) WHERE art.approved = {int:approved} ORDER BY art.{raw:col} {raw:sort} LIMIT {int:start}, 15', array('approved' => 0, 'col' => $sort, 'start' => $start, 'sort' => in_array($sort, array('sticky', 'locked', 'frontpage', 'date', 'active')) ? 'DESC' : 'ASC')); if ($smcFunc['db_num_rows']($request) > 0) { $context['TPortal']['arts_submissions'] = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { $context['TPortal']['arts_submissions'][] = $row; } $smcFunc['db_free_result']($request); } } if (isset($show_nocategory) && $context['TPortal']['total_nocategory'] > 0) { // check if we have any start values $start = !empty($_GET['p']) && is_numeric($_GET['p']) ? $_GET['p'] : 0; // sorting? $sort = $context['TPortal']['sort'] = !empty($_GET['sort']) && in_array($_GET['sort'], array('off', 'date', 'id', 'author_id', 'locked', 'frontpage', 'sticky', 'featured', 'type', 'subject', 'parse')) ? $_GET['sort'] : 'date'; $context['TPortal']['pageindex'] = TPageIndex($scripturl . '?action=tpadmin;sa=articles;sort=' . $sort, $start, $context['TPortal']['total_nocategory'], 15); $request = $smcFunc['db_query']('', ' SELECT art.id, art.date, art.frontpage, art.category, art.author_id as authorID, IFNULL(mem.real_name, art.author) as author, art.subject, art.approved, art.sticky, art.type, art.featured,art.locked, art.off, art.parse as pos FROM {db_prefix}tp_articles AS art LEFT JOIN {db_prefix}members AS mem ON (art.author_id = mem.id_member) WHERE (art.category = 0 OR art.category = 9999) ORDER BY art.{raw:col} {raw:sort} LIMIT {int:start}, 15', array('col' => $sort, 'sort' => in_array($sort, array('sticky', 'locked', 'frontpage', 'date', 'active')) ? 'DESC' : 'ASC', 'start' => $start)); if ($smcFunc['db_num_rows']($request) > 0) { $context['TPortal']['arts_nocat'] = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { $context['TPortal']['arts_nocat'][] = $row; } $smcFunc['db_free_result']($request); } } // ok, fetch single article if (isset($whatarticle)) { $request = $smcFunc['db_query']('', ' SELECT art.*, IFNULL(mem.real_name, art.author) as realName, art.author_id as authorID, art.type as articletype, art.id_theme as ID_THEME FROM {db_prefix}tp_articles as art LEFT JOIN {db_prefix}members as mem ON (art.author_id = mem.id_member) WHERE art.id = {int:artid}', array('artid' => is_numeric($whatarticle) ? $whatarticle : 0)); if ($smcFunc['db_num_rows']($request) > 0) { $context['TPortal']['editarticle'] = $smcFunc['db_fetch_assoc']($request); $context['TPortal']['editing_article'] = true; $context['TPortal']['editarticle']['body'] = $smcFunc['htmlspecialchars']($context['TPortal']['editarticle']['body'], ENT_QUOTES); $smcFunc['db_free_result']($request); } // Add in BBC editor before we call in template so the headers are there if ($context['TPortal']['editarticle']['articletype'] == 'bbc') { $context['TPortal']['editor_id'] = 'tp_article_body'; TP_prebbcbox($context['TPortal']['editor_id'], strip_tags($context['TPortal']['editarticle']['body'])); } // fetch the WYSIWYG value $request = $smcFunc['db_query']('', ' SELECT value1 FROM {db_prefix}tp_variables WHERE subtype2 = {int:subtype} AND type = {string:type} LIMIT 1', array('subtype' => $whatarticle, 'type' => 'editorchoice')); if ($smcFunc['db_num_rows']($request) > 0) { $row = $smcFunc['db_fetch_assoc']($request); $smcFunc['db_free_result']($request); $context['TPortal']['editorchoice'] = $row['value1']; } else { $context['TPortal']['editorchoice'] = 1; } $context['html_headers'] .= ' <script type="text/javascript"><!-- // --><![CDATA[ function changeIllu(node,name) { node.src = \'' . $boardurl . '/tp-files/tp-articles/illustrations/\' + name; } function changeIcon(node,name) { node.src = \'' . $boardurl . '/tp-files/tp-articles/icons/\' + name; } // ]]></script>'; } // fetch article count for these if (isset($cats)) { $request = $smcFunc['db_query']('', ' SELECT art.category as id, COUNT(art.id) as files FROM {db_prefix}tp_articles as art WHERE art.category IN ({array_int:cat}) GROUP BY art.category', array('cat' => $cats)); $context['TPortal']['cats_count'] = array(); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $context['TPortal']['cats_count'][$row['id']] = $row['files']; } $smcFunc['db_free_result']($request); } } // get the icons needed tp_collectArticleIcons(); // fetch all categories and subcategories $request = $smcFunc['db_query']('', ' SELECT id, value1 as name, value2 as parent FROM {db_prefix}tp_variables WHERE type = {string:type}', array('type' => 'category')); $context['TPortal']['allcats'] = array(); $allsorted = array(); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $allsorted[$row['id']] = $row; } $smcFunc['db_free_result']($request); if (count($allsorted) > 1) { $context['TPortal']['allcats'] = chain('id', 'parent', 'name', $allsorted); } else { $context['TPortal']['allcats'] = $allsorted; } } // not quite done yet lol, now we need to sort out if articles are to be listed if (isset($where)) { // check if we have any start values $start = !empty($_GET['p']) && is_numeric($_GET['p']) ? $_GET['p'] : 0; // sorting? $sort = $context['TPortal']['sort'] = !empty($_GET['sort']) && in_array($_GET['sort'], array('off', 'date', 'id', 'author_id', 'locked', 'frontpage', 'sticky', 'featured', 'type', 'subject', 'parse')) ? $_GET['sort'] : 'date'; $context['TPortal']['categoryID'] = $where; // get the name $request = $smcFunc['db_query']('', ' SELECT value1 FROM {db_prefix}tp_variables WHERE id = {int:varid} LIMIT 1', array('varid' => $where)); $f = $smcFunc['db_fetch_assoc']($request); $smcFunc['db_free_result']($request); $context['TPortal']['categoryNAME'] = $f['value1']; // get the total first $request = $smcFunc['db_query']('', ' SELECT COUNT(*) as total FROM {db_prefix}tp_articles WHERE category = {int:cat}', array('cat' => $where)); $row = $smcFunc['db_fetch_assoc']($request); $context['TPortal']['pageindex'] = TPageIndex($scripturl . '?action=tpadmin;sa=articles;sort=' . $sort . ';cu=' . $where, $start, $row['total'], 15); $smcFunc['db_free_result']($request); $request = $smcFunc['db_query']('', ' SELECT art.id, art.date, art.frontpage, art.category, art.author_id as authorID, IFNULL(mem.real_name, art.author) as author, art.subject, art.approved, art.sticky, art.type, art.featured, art.locked, art.off, art.parse as pos FROM {db_prefix}tp_articles AS art LEFT JOIN {db_prefix}members AS mem ON (art.author_id = mem.id_member) WHERE art.category = {int:cat} ORDER BY art.{raw:sort} {raw:sorter} LIMIT {int:start}, 15', array('cat' => $where, 'sort' => $sort, 'sorter' => in_array($sort, array('sticky', 'locked', 'frontpage', 'date', 'active')) ? 'DESC' : 'ASC', 'start' => $start)); TPadd_linktree($scripturl . '?action=tpadmin;sa=articles;cu=' . $where, $txt['tp-blocktype19']); if ($smcFunc['db_num_rows']($request) > 0) { $context['TPortal']['arts'] = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { $context['TPortal']['arts'][] = $row; } $smcFunc['db_free_result']($request); } } $context['html_headers'] .= ' <script type="text/javascript" src="' . $settings['default_theme_url'] . '/scripts/editor.js?rc1"></script> <script type="text/javascript"><!-- // --><![CDATA[ function getXMLHttpRequest() { if (window.XMLHttpRequest) return new XMLHttpRequest; else if (window.ActiveXObject) return new ActiveXObject("MICROSOFT.XMLHTTP"); else alert("Sorry, but your browser does not support Ajax"); } window.onload = startToggle; function startToggle() { var img = document.getElementsByTagName("img"); for(var i = 0; i < img.length; i++) { if (img[i].className == "toggleFront") img[i].onclick = toggleFront; else if (img[i].className == "toggleSticky") img[i].onclick = toggleSticky; else if (img[i].className == "toggleLock") img[i].onclick = toggleLock; else if (img[i].className == "toggleActive") img[i].onclick = toggleActive; else if (img[i].className == "toggleFeatured") img[i].onclick = toggleFeatured; } } function toggleActive(e) { var e = e ? e : window.event; var target = e.target ? e.target : e.srcElement; while(target.className != "toggleActive") target = target.parentNode; var id = target.id.replace("artActive", ""); var Ajax = getXMLHttpRequest(); Ajax.open("POST", "?action=tpadmin;arton=" + id + ";' . $context['session_var'] . '=' . $context['session_id'] . '"); Ajax.setRequestHeader("Content-type", "application/x-www-form-urlencode"); var source = target.src; target.src = "' . $settings['tp_images_url'] . '/ajax.gif" Ajax.onreadystatechange = function() { if(Ajax.readyState == 4) { target.src = source == "' . $settings['tp_images_url'] . '/TPactive2.gif" ? "' . $settings['tp_images_url'] . '/TPactive1.gif" : "' . $settings['tp_images_url'] . '/TPactive2.gif"; } } var params = "?action=tpadmin;arton=" + id + ";' . $context['session_var'] . '=' . $context['session_id'] . '"; Ajax.send(params); } function toggleFront(e) { var e = e ? e : window.event; var target = e.target ? e.target : e.srcElement; while(target.className != "toggleFront") target = target.parentNode; var id = target.id.replace("artFront", ""); var Ajax = getXMLHttpRequest(); Ajax.open("POST", "?action=tpadmin;artfront=" + id + ";' . $context['session_var'] . '=' . $context['session_id'] . '"); Ajax.setRequestHeader("Content-type", "application/x-www-form-urlencode"); var source = target.src; target.src = "' . $settings['tp_images_url'] . '/ajax.gif" Ajax.onreadystatechange = function() { if(Ajax.readyState == 4) { target.src = source == "' . $settings['tp_images_url'] . '/TPfront.gif" ? "' . $settings['tp_images_url'] . '/TPfront2.gif" : "' . $settings['tp_images_url'] . '/TPfront.gif"; } } var params = "?action=tpadmin;artfront=" + id + ";' . $context['session_var'] . '=' . $context['session_id'] . '"; Ajax.send(params); } function toggleSticky(e) { var e = e ? e : window.event; var target = e.target ? e.target : e.srcElement; while(target.className != "toggleSticky") target = target.parentNode; var id = target.id.replace("artSticky", ""); var Ajax = getXMLHttpRequest(); Ajax.open("POST", "?action=tpadmin;artsticky=" + id + ";' . $context['session_var'] . '=' . $context['session_id'] . '"); Ajax.setRequestHeader("Content-type", "application/x-www-form-urlencode"); var source = target.src; target.src = "' . $settings['tp_images_url'] . '/ajax.gif" Ajax.onreadystatechange = function() { if(Ajax.readyState == 4) { target.src = source == "' . $settings['tp_images_url'] . '/TPsticky1.gif" ? "' . $settings['tp_images_url'] . '/TPsticky2.gif" : "' . $settings['tp_images_url'] . '/TPsticky1.gif"; } } var params = "?action=tpadmin;artsticky=" + id + ";' . $context['session_var'] . '=' . $context['session_id'] . '"; Ajax.send(params); } function toggleLock(e) { var e = e ? e : window.event; var target = e.target ? e.target : e.srcElement; while(target.className != "toggleLock") target = target.parentNode; var id = target.id.replace("artLock", ""); var Ajax = getXMLHttpRequest(); Ajax.open("POST", "?action=tpadmin;artlock=" + id + ";' . $context['session_var'] . '=' . $context['session_id'] . '"); Ajax.setRequestHeader("Content-type", "application/x-www-form-urlencode"); var source = target.src; target.src = "' . $settings['tp_images_url'] . '/ajax.gif" Ajax.onreadystatechange = function() { if(Ajax.readyState == 4) { target.src = source == "' . $settings['tp_images_url'] . '/TPlock1.gif" ? "' . $settings['tp_images_url'] . '/TPlock2.gif" : "' . $settings['tp_images_url'] . '/TPlock1.gif"; } } var params = "?action=tpadmin;artlock=" + id + ";' . $context['session_var'] . '=' . $context['session_id'] . '"; Ajax.send(params); } function toggleFeatured(e) { var e = e ? e : window.event; var target = e.target ? e.target : e.srcElement; var aP=document.getElementsByTagName(\'img\'); for(var i=0; i<aP.length; i++) { if(aP[i].className===\'toggleFeatured\' && aP[i] != target) { aP[i].src=\'' . $settings['tp_images_url'] . '/TPflag2.gif\'; } } while(target.className != "toggleFeatured") target = target.parentNode; var id = target.id.replace("artFeatured", ""); var Ajax = getXMLHttpRequest(); Ajax.open("POST", "?action=tpadmin;artfeat=" + id + ";' . $context['session_var'] . '=' . $context['session_id'] . '"); Ajax.setRequestHeader("Content-type", "application/x-www-form-urlencode"); var source = target.src; target.src = "' . $settings['tp_images_url'] . '/ajax.gif" Ajax.onreadystatechange = function() { if(Ajax.readyState == 4) { target.src = source == "' . $settings['tp_images_url'] . '/TPflag.gif" ? "' . $settings['tp_images_url'] . '/TPflag2.gif" : "' . $settings['tp_images_url'] . '/TPflag.gif"; } } var params = "?action=tpadmin;artfeat=" + id + ";' . $context['session_var'] . '=' . $context['session_id'] . '"; Ajax.send(params); } // ]]></script>'; if ($context['TPortal']['subaction'] == 'artsettings') { TPadd_linktree($scripturl . '?action=tpadmin;sa=artsettings', $txt['tp-settings']); } elseif ($context['TPortal']['subaction'] == 'articons') { TPadd_linktree($scripturl . '?action=tpadmin;sa=articons', $txt['tp-adminicons']); } }
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'); } }
function tpshout_profile($memID) { global $context, $scripturl, $txt, $smcFunc; $context['page_title'] = $txt['shoutboxprofile']; if (isset($context['TPortal']['mystart'])) { $start = $context['TPortal']['mystart']; } else { $start = 0; } $context['TPortal']['memID'] = $memID; $sorting = 'value2'; $max = 0; // get all shouts $request = $smcFunc['db_query']('', ' SELECT COUNT(*) FROM {db_prefix}tp_shoutbox WHERE value5 = {int:val5} AND type = {string:type}', array('val5' => $memID, 'type' => 'shoutbox')); $result = $smcFunc['db_fetch_row']($request); $max = $result[0]; $smcFunc['db_free_result']($request); $context['TPortal']['all_shouts'] = $max; $context['TPortal']['profile_shouts'] = array(); $request = $smcFunc['db_query']('', ' SELECT * FROM {db_prefix}tp_shoutbox WHERE value5 = {int:val5} AND type = {string:type} ORDER BY {raw:sort} DESC LIMIT {int:start}, 10', array('val5' => $memID, 'type' => 'shoutbox', 'sort' => $sorting, 'start' => $start)); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $context['TPortal']['profile_shouts'][] = array('id' => $row['id'], 'shout' => parse_bbc(censorText($row['value1'])), 'created' => timeformat($row['value2']), 'ip' => $row['value4'], 'editlink' => allowedTo('tp_shoutbox') ? $scripturl . '?action=tpmod;shout=admin;u=' . $memID : ''); } $smcFunc['db_free_result']($request); } // construct pageindexes if ($max > 0) { $context['TPortal']['pageindex'] = TPageIndex($scripturl . '?action=profile;area=tpshoutbox;u=' . $memID . ';tpsort=' . $sorting, $start, $max, '10', true); } else { $context['TPortal']['pageindex'] = ''; } loadtemplate('TPShout'); if (loadLanguage('TPShout') == false) { loadLanguage('TPShout', 'english'); } $context['sub_template'] = 'tpshout_profile'; }
function tpshout_admin() { global $context, $scripturl, $txt, $smcFunc, $sourcedir; // check permissions isAllowedTo('tp_can_admin_shout'); if (!isset($context['tp_panels'])) { $context['tp_panels'] = array(); } if (isset($_GET['p']) && is_numeric($_GET['p'])) { $tpstart = $_GET['p']; } else { $tpstart = 0; } require_once $sourcedir . '/Subs-Post.php'; loadtemplate('TPShout'); $context['template_layers'][] = 'tpadm'; $context['template_layers'][] = 'subtab'; loadlanguage('TPortalAdmin'); TPadminIndex('shout', true); $context['current_action'] = 'admin'; if (isset($_REQUEST['send']) || isset($_REQUEST[$txt['tp-send']]) || isset($_REQUEST['tp_preview']) || isset($_REQUEST['TPadmin_blocks'])) { $go = 0; $changeArray = array(); foreach ($_POST as $what => $value) { if (substr($what, 0, 18) == 'tp_shoutbox_remove') { $val = substr($what, 18); $smcFunc['db_query']('', ' DELETE FROM {db_prefix}tp_shoutbox WHERE id = {int:shout}', array('shout' => $val)); $go = 2; } elseif (substr($what, 0, 18) == 'tp_shoutbox_hidden') { $val = substr($what, 18); if (!empty($_POST['tp_shoutbox_sticky' . $val])) { $value = '1'; } else { $value = ''; } if (!empty($_POST['tp_shoutbox_sticky_layout' . $val]) && is_numeric($_POST['tp_shoutbox_sticky_layout' . $val])) { $svalue = $_POST['tp_shoutbox_sticky_layout' . $val]; } else { $svalue = '0'; } $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_shoutbox SET value6 = "' . $value . '",value8 = "' . $svalue . '" WHERE id = {int:shout}', array('shout' => $val)); $go = 2; } elseif ($what == 'tp_shoutsdelall' && $value == 'ON') { $smcFunc['db_query']('', ' DELETE FROM {db_prefix}tp_shoutbox WHERE type = {string:type}', array('type' => 'shoutbox')); $go = 2; } elseif ($what == 'tp_shoutsunstickall' && $value == 'ON') { $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_shoutbox SET value6 = "0", value8 = "0" WHERE 1'); $go = 2; } elseif (substr($what, 0, 16) == 'tp_shoutbox_item') { $val = substr($what, 16); $bshout = $smcFunc['htmlspecialchars'](substr($value, 0, 300)); preparsecode($bshout); $smcFunc['db_query']('', ' UPDATE {db_prefix}tp_shoutbox SET value1 = {string:val1} WHERE id = {int:val}', array('val1' => $bshout, 'val' => $val)); $go = 2; } else { $what = substr($what, 3); if ($what == 'shoutbox_smile') { $changeArray['show_shoutbox_smile'] = $value; } if ($what == 'shoutbox_icons') { $changeArray['show_shoutbox_icons'] = $value; } if ($what == 'shoutbox_height') { $changeArray['shoutbox_height'] = $value; } if ($what == 'shoutbox_usescroll') { $changeArray['shoutbox_usescroll'] = $value; } if ($what == 'shoutbox_scrollduration') { if ($value > 5) { $value = 5; } elseif ($value < 1) { $value = 1; } $changeArray['shoutbox_scrollduration'] = $value; } if ($what == 'shoutbox_limit') { if (!is_numeric($value)) { $value = 10; } $changeArray['shoutbox_limit'] = $value; } if ($what == 'shoutbox_refresh') { if (empty($value)) { $value = '0'; } $changeArray['shoutbox_refresh'] = $value; } if ($what == 'show_profile_shouts') { $changeArray['profile_shouts_hide'] = $value; } if ($what == 'shout_allow_links') { $changeArray['shout_allow_links'] = $value; } if ($what == 'shoutbox_layout') { $changeArray['shoutbox_layout'] = $value; } if ($what == 'shout_submit_returnkey') { $changeArray['shout_submit_returnkey'] = $value; } if ($what == 'shoutbox_stitle') { $changeArray['shoutbox_stitle'] = $value; } } } updateTPSettings($changeArray, true); if (empty($go)) { redirectexit('action=tpmod;shout=admin;settings'); } else { redirectexit('action=tpmod;shout=admin'); } } // get latest shouts for admin section // check that a member has been filtered if (isset($_GET['u'])) { $memID = $_GET['u']; } // check that a IP has been filtered if (isset($_GET['ip'])) { $ip = $_GET['ip']; } if (isset($_GET['s'])) { $single = $_GET['s']; } $context['TPortal']['admin_shoutbox_items'] = array(); if (isset($memID)) { $shouts = $smcFunc['db_query']('', ' SELECT COUNT(*) FROM {db_prefix}tp_shoutbox WHERE type = {string:type} AND value5 = {int:val5} AND value7 = {int:val7}', array('type' => 'shoutbox', 'val5' => $memID, 'val7' => 0)); $weh = $smcFunc['db_fetch_row']($shouts); $smcFunc['db_free_result']($shouts); $allshouts = $weh[0]; $context['TPortal']['admin_shoutbox_items_number'] = $allshouts; $context['TPortal']['shoutbox_pageindex'] = 'Member ' . $memID . ' filtered (<a href="' . $scripturl . '?action=tpmod;shout=admin">' . $txt['remove'] . '</a>) <br />' . TPageIndex($scripturl . '?action=tpmod;shout=admin;u=' . $memID, $tpstart, $allshouts, 10, true); $request = $smcFunc['db_query']('', ' SELECT * FROM {db_prefix}tp_shoutbox WHERE type = {string:type} AND value5 = {int:val5} AND value7 = {int:val7} ORDER BY value2 DESC LIMIT {int:start},10', array('type' => 'shoutbox', 'val5' => $memID, 'val7' => 0, 'start' => $tpstart)); } elseif (isset($ip)) { $shouts = $smcFunc['db_query']('', ' SELECT COUNT(*) FROM {db_prefix}tp_shoutbox WHERE type = {string:type} AND value4 = {string:val4} AND value7 = {int:val7}', array('type' => 'shoutbox', 'val4' => $ip, 'val7' => 0)); $weh = $smcFunc['db_fetch_row']($shouts); $smcFunc['db_free_result']($shouts); $allshouts = $weh[0]; $context['TPortal']['admin_shoutbox_items_number'] = $allshouts; $context['TPortal']['shoutbox_pageindex'] = 'IP ' . $ip . ' filtered (<a href="' . $scripturl . '?action=tpmod;shout=admin">' . $txt['remove'] . '</a>) <br />' . TPageIndex($scripturl . '?action=tpmod;shout=admin;ip=' . urlencode($ip), $tpstart, $allshouts, 10, true); $request = $smcFunc['db_query']('', ' SELECT * FROM {db_prefix}tp_shoutbox WHERE type = {string:type} AND value4 = {string:val4} AND value7 = {int:val7} ORDER BY value2 DESC LIMIT {int:start}, 10', array('type' => 'shoutbox', 'val4' => $ip, 'val7' => 0, 'start' => $tpstart)); } elseif (isset($single)) { // check session checkSession('get'); $context['TPortal']['shoutbox_pageindex'] = ''; $request = $smcFunc['db_query']('', ' SELECT * FROM {db_prefix}tp_shoutbox WHERE type = {string:type} AND value7 = {int:val7} AND id = {int:shout}', array('type' => 'shoutbox', 'val7' => 0, 'shout' => $single)); } else { $shouts = $smcFunc['db_query']('', ' SELECT COUNT(*) FROM {db_prefix}tp_shoutbox WHERE type = {string:type} AND value7 = {int:val7}', array('type' => 'shoutbox', 'val7' => 0)); $weh = $smcFunc['db_fetch_row']($shouts); $smcFunc['db_free_result']($shouts); $allshouts = $weh[0]; $context['TPortal']['admin_shoutbox_items_number'] = $allshouts; $context['TPortal']['shoutbox_pageindex'] = TPageIndex($scripturl . '?action=tpmod;shout=admin', $tpstart, $allshouts, 10, true); $request = $smcFunc['db_query']('', ' SELECT * FROM {db_prefix}tp_shoutbox WHERE type = {string:type} AND value7 = {int:val7} ORDER BY value2 DESC LIMIT {int:start}, 10', array('type' => 'shoutbox', 'val7' => 0, 'start' => $tpstart)); } if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $context['TPortal']['admin_shoutbox_items'][] = array('id' => $row['id'], 'body' => html_entity_decode($row['value1'], ENT_QUOTES), 'poster' => $row['value3'], 'timestamp' => $row['value2'], 'time' => timeformat($row['value2']), 'ip' => $row['value4'], 'ID_MEMBER' => $row['value5'], 'sort_member' => '<a href="' . $scripturl . '?action=tpmod;shout=admin;u=' . $row['value5'] . '">' . $txt['tp-allshoutsbymember'] . '</a>', 'sticky' => $row['value6'], 'sticky_layout' => $row['value8'], 'sort_ip' => '<a href="' . $scripturl . '?action=tpmod;shout=admin;ip=' . $row['value4'] . '">' . $txt['tp-allshoutsbyip'] . '</a>', 'single' => isset($single) ? '<hr><a href="' . $scripturl . '?action=tpmod;shout=admin"><b>' . $txt['tp-allshouts'] . '</b></a>' : ''); } $smcFunc['db_free_result']($request); } $context['TPortal']['subtabs'] = ''; // setup menu items if (allowedTo('tp_can_admin_shout')) { $context['TPortal']['subtabs'] = array('shoutbox_settings' => array('text' => 'tp-settings', 'url' => $scripturl . '?action=tpmod;shout=admin;settings', 'active' => isset($_GET['action']) && ($_GET['action'] == 'tpmod' || $_GET['action'] == 'tpadmin') && isset($_GET['shout']) && $_GET['shout'] == 'admin' && isset($_GET['settings']) ? true : false), 'shoutbox' => array('text' => 'tp-tabs10', 'url' => $scripturl . '?action=tpmod;shout=admin', 'active' => isset($_GET['action']) && ($_GET['action'] == 'tpmod' || $_GET['action'] == 'tpadmin') && isset($_GET['shout']) && $_GET['shout'] == 'admin' && !isset($_GET['settings']) ? true : false)); $context['admin_header']['tp_shout'] = $txt['tp_shout']; } // on settings screen? if (isset($_GET['settings'])) { $context['sub_template'] = 'tpshout_admin_settings'; } else { $context['sub_template'] = 'tpshout_admin'; } $context['page_title'] = 'Shoutbox admin'; tp_hidebars(); }
function doTPfrontpage() { global $context, $scripturl, $user_info, $modSettings, $smcFunc, $txt; // check we aren't in any other section because 'cat' is used in SMF and TP if (isset($_GET['action']) || isset($_GET['board']) || isset($_GET['topic'])) { return; } $now = time(); // set up visual options for frontpage $context['TPortal']['visual_opts'] = explode(',', $context['TPortal']['frontpage_visual']); // first, the panels foreach (array('left', 'right', 'center', 'top', 'bottom', 'lower') as $pan => $panel) { if ($context['TPortal'][$panel . 'panel'] == 1 && in_array($panel, $context['TPortal']['visual_opts'])) { $context['TPortal'][$panel . 'panel'] = 1; } else { $context['TPortal'][$panel . 'panel'] = 0; } } // get the sorting foreach ($context['TPortal']['visual_opts'] as $vi => $vo) { if (substr($vo, 0, 5) == 'sort_') { $catsort = substr($vo, 5); } else { $catsort = 'date'; } if (substr($vo, 0, 10) == 'sortorder_') { $catsort_order = substr($vo, 10); } else { $catsort_order = 'desc'; } } if (!in_array($catsort, array('date', 'author_id', 'id', 'parse'))) { $catsort = 'date'; } $max = $context['TPortal']['frontpage_limit']; $start = $context['TPortal']['mystart']; // fetch the articles, sorted if ($context['TPortal']['front_type'] == 'articles_only') { // first, get all available if (!$context['user']['is_admin']) { $artgroups = 'AND (FIND_IN_SET(' . implode(', var.value3) OR FIND_IN_SET(', $user_info['groups']) . ', var.value3))'; } else { $artgroups = ''; } $request = $smcFunc['db_query']('', ' SELECT art.id FROM ({db_prefix}tp_articles AS art, {db_prefix}tp_variables AS var) WHERE art.off = 0 AND var.id = art.category ' . $artgroups . ' AND art.category > 0 AND ((art.pub_start = 0 AND art.pub_end = 0) OR (art.pub_start != 0 AND art.pub_start < ' . $now . ' AND art.pub_end = 0) OR (art.pub_start = 0 AND art.pub_end != 0 AND art.pub_end > ' . $now . ') OR (art.pub_start != 0 AND art.pub_end != 0 AND art.pub_end > ' . $now . ' AND art.pub_start < ' . $now . ')) AND art.approved = 1 AND art.frontpage = 1'); if ($smcFunc['db_num_rows']($request) > 0) { $articles_total = $smcFunc['db_num_rows']($request); $smcFunc['db_free_result']($request); } else { $articles_total = 0; } // make the pageindex! $context['TPortal']['pageindex'] = TPageIndex($scripturl . '?frontpage', $start, $articles_total, $max); $request = $smcFunc['db_query']('', ' SELECT art.id, IF(art.useintro > 0, art.intro, art.body) AS body, art.date, art.category, art.subject, art.author_id as authorID, var.value1 as category_name, var.value8 as category_shortname, art.frame, art.comments, art.options, art.intro, art.useintro, art.comments_var, art.views, art.rating, art.voters, art.shortname, art.fileimport, art.topic, art.illustration,art.type as rendertype , IFNULL(mem.real_name, art.author) as realName, mem.avatar, mem.posts, mem.date_registered as dateRegistered,mem.last_login as lastLogin, IFNULL(a.id_attach, 0) AS ID_ATTACH, a.filename, a.attachment_type as attachmentType FROM {db_prefix}tp_articles AS art LEFT JOIN {db_prefix}tp_variables AS var ON(var.id = art.category) LEFT JOIN {db_prefix}members AS mem ON (art.author_id = mem.id_member) LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member AND a.attachment_type!=3) WHERE art.off = 0 ' . $artgroups . ' AND ((art.pub_start = 0 AND art.pub_end = 0) OR (art.pub_start != 0 AND art.pub_start < ' . $now . ' AND art.pub_end = 0) OR (art.pub_start = 0 AND art.pub_end != 0 AND art.pub_end > ' . $now . ') OR (art.pub_start != 0 AND art.pub_end != 0 AND art.pub_end > ' . $now . ' AND art.pub_start < ' . $now . ')) AND art.category > 0 AND art.approved = 1 AND (art.frontpage = 1 OR art.featured = 1) ORDER BY art.featured DESC, art.sticky DESC, art.' . $catsort . ' ' . $catsort_order . ' LIMIT {int:start}, {int:max}', array('start' => $start, 'max' => $max)); if ($smcFunc['db_num_rows']($request) > 0) { $total = $smcFunc['db_num_rows']($request); $col1 = ceil($total / 2); $col2 = $total - $col1; $counter = 0; $context['TPortal']['category'] = array('articles' => array(), 'col1' => array(), 'col2' => array(), 'options' => array('catlayout' => $context['TPortal']['frontpage_catlayout'])); while ($row = $smcFunc['db_fetch_assoc']($request)) { // expand the vislaoptions $row['visual_options'] = explode(',', $row['options']); $row['avatar'] = $row['avatar'] == '' ? $row['ID_ATTACH'] > 0 ? '<img src="' . (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt=" " />' : '' : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '" alt=" " />' : '<img src="' . $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($row['avatar'], ENT_QUOTES) . '" alt=" " />'); if ($counter == 0) { $context['TPortal']['category']['featured'] = $row; } elseif ($counter < $col1) { $context['TPortal']['category']['col1'][] = $row; } elseif ($counter > $col1 || $counter == $col1) { $context['TPortal']['category']['col2'][] = $row; } $counter++; } $smcFunc['db_free_result']($request); } } elseif ($context['TPortal']['front_type'] == 'single_page') { $request = $smcFunc['db_query']('', ' SELECT art.id, IF(art.useintro > 0, art.intro, art.body) AS body, art.date, art.category, art.subject, art.author_id as authorID, var.value1 as category_name, var.value8 as category_shortname, art.frame, art.comments, art.options, art.intro, art.useintro, art.comments_var, art.views, art.rating, art.voters, art.shortname, art.fileimport, art.topic, art.illustration,art.type as rendertype , IFNULL(mem.real_name, art.author) as realName, mem.avatar, mem.posts, mem.date_registered as dateRegistered,mem.last_login as lastLogin, IFNULL(a.id_attach, 0) AS ID_ATTACH, a.filename, a.attachment_type as attachmentType FROM {db_prefix}tp_articles AS art LEFT JOIN {db_prefix}tp_variables AS var ON(var.id = art.category) LEFT JOIN {db_prefix}members AS mem ON (art.author_id = mem.id_member) LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member AND a.attachment_type!=3) WHERE art.off = 0 AND ((art.pub_start = 0 AND art.pub_end = 0) OR (art.pub_start != 0 AND art.pub_start < ' . $now . ' AND art.pub_end = 0) OR (art.pub_start = 0 AND art.pub_end != 0 AND art.pub_end > ' . $now . ') OR (art.pub_start != 0 AND art.pub_end != 0 AND art.pub_end > ' . $now . ' AND art.pub_start < ' . $now . ')) AND art.featured = 1 AND art.approved = 1 LIMIT 1'); if ($smcFunc['db_num_rows']($request) > 0) { $context['TPortal']['category'] = array('articles' => array(), 'col1' => array(), 'col2' => array(), 'options' => array('catlayout' => $context['TPortal']['frontpage_catlayout'])); $row = $smcFunc['db_fetch_assoc']($request); // expand the vislaoptions $row['visual_options'] = explode(',', $row['options']); $row['avatar'] = $row['avatar'] == '' ? $row['ID_ATTACH'] > 0 ? '<img src="' . (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt=" " />' : '' : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '" alt=" " />' : '<img src="' . $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($row['avatar'], ENT_QUOTES) . '" alt=" " />'); $context['TPortal']['category']['featured'] = $row; $smcFunc['db_free_result']($request); } } elseif (in_array($context['TPortal']['front_type'], array('forum_only', 'forum_selected'))) { $totalmax = 200; loadLanguage('Stats'); // Find the post ids. if ($context['TPortal']['front_type'] == 'forum_only') { $request = $smcFunc['db_query']('', ' SELECT t.id_first_msg as ID_FIRST_MSG FROM ({db_prefix}topics as t, {db_prefix}boards as b) WHERE t.id_board = b.id_board AND t.id_board IN({raw:board}) ' . ($context['TPortal']['allow_guestnews'] == 0 ? 'AND {query_see_board}' : '') . ' ORDER BY t.id_first_msg DESC LIMIT {int:max}', array('board' => $context['TPortal']['SSI_board'], 'max' => $totalmax)); } else { $request = $smcFunc['db_query']('', ' SELECT t.id_first_msg as ID_FIRST_MSG FROM ({db_prefix}topics as t, {db_prefix}boards as b) WHERE t.id_board = b.id_board AND t.id_topic IN(' . (empty($context['TPortal']['frontpage_topics']) ? 0 : '{raw:topics}') . ') ' . ($context['TPortal']['allow_guestnews'] == 0 ? 'AND {query_see_board}' : '') . ' ORDER BY t.id_first_msg DESC', array('topics' => $context['TPortal']['frontpage_topics'])); } $posts = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { $posts[] = $row['ID_FIRST_MSG']; } $smcFunc['db_free_result']($request); if (empty($posts)) { return array(); } // do some conversion if ($catsort == 'date') { $catsort = 'poster_time'; } elseif ($catsort == 'authorID') { $catsort = 'id_member'; } elseif ($catsort == 'parse' || $catsort == 'id') { $catsort = 'id_msg'; } else { $catsort = 'poster_time'; } $request = $smcFunc['db_query']('', ' SELECT m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS realName, m.poster_time as date, mem.avatar,mem.posts, mem.date_registered as dateRegistered,mem.last_login as lastLogin, IFNULL(a.id_attach, 0) AS ID_ATTACH, a.filename, a.attachment_type as attachmentType, t.id_board as category, b.name as category_name, t.num_replies as numReplies, t.id_topic as id, m.id_member as authorID, t.num_views as views,t.num_replies as replies, t.locked, IFNULL(thumb.id_attach, 0) AS thumb_id, thumb.filename as thumb_filename FROM ({db_prefix}topics AS t, {db_prefix}messages AS m) LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member AND a.attachment_type !=3) LEFT JOIN {db_prefix}attachments AS thumb ON (t.id_first_msg = thumb.id_msg AND thumb.attachment_type = 3) LEFT JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board) WHERE t.id_first_msg IN ({array_int:posts}) AND m.id_msg = t.id_first_msg GROUP BY t.id_first_msg ORDER BY m.{raw:catsort} DESC LIMIT {int:start}, {int:max}', array('posts' => $posts, 'catsort' => $catsort, 'start' => $start, 'max' => $max)); // make the pageindex! $context['TPortal']['pageindex'] = TPageIndex($scripturl . '?frontpage', $start, count($posts), $max); if ($smcFunc['db_num_rows']($request) > 0) { $total = $smcFunc['db_num_rows']($request); $col1 = ceil($total / 2); $col2 = $total - $col1; $counter = 0; $context['TPortal']['category'] = array('articles' => array(), 'col1' => array(), 'col2' => array(), 'options' => array('catlayout' => $context['TPortal']['frontpage_catlayout'])); while ($row = $smcFunc['db_fetch_assoc']($request)) { $length = $context['TPortal']['frontpage_limit_len']; if (!empty($length) && $smcFunc['strlen']($row['body']) > $length) { $row['body'] = $smcFunc['substr']($row['body'], 0, $length); // The first space or line break. (<br />, etc.) $cutoff = max(strrpos($row['body'], ' '), strrpos($row['body'], '<')); if ($cutoff !== false) { $row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff); } $row['body'] .= '... <p><strong><a href="' . $scripturl . '?topic=' . $row['id'] . '">' . $txt['tp-readmore'] . '</a></strong></p>'; } // some needed addons $row['rendertype'] = 'bbc'; $row['frame'] = 'theme'; $row['boardnews'] = 1; if (!isset($context['TPortal']['frontpage_visopts'])) { $context['TPortal']['frontpage_visopts'] = 'date,title,author,views' . ($context['TPortal']['forumposts_avatar'] == 1 ? ',avatar' : ''); } $row['visual_options'] = explode(',', $context['TPortal']['frontpage_visopts']); $row['useintro'] = '0'; $row['avatar'] = $row['avatar'] == '' ? $row['ID_ATTACH'] > 0 ? '<img src="' . (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt=" " />' : '' : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '" alt=" " />' : '<img src="' . $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($row['avatar'], ENT_QUOTES) . '" alt=" " />'); if (!empty($row['thumb_id'])) { $row['illustration'] = $scripturl . '?action=tpmod;sa=tpattach;topic=' . $row['id'] . '.0;attach=' . $row['thumb_id'] . ';image'; } if ($counter == 0) { $context['TPortal']['category']['featured'] = $row; } elseif ($counter < $col1 && $counter > 0) { $context['TPortal']['category']['col1'][] = $row; } elseif ($counter > $col1 || $counter == $col1) { $context['TPortal']['category']['col2'][] = $row; } $counter++; } $smcFunc['db_free_result']($request); } } elseif (in_array($context['TPortal']['front_type'], array('forum_articles', 'forum_selected_articles'))) { // first, get all available if (!$context['user']['is_admin']) { $artgroups = 'AND (FIND_IN_SET(' . implode(', var.value3) OR FIND_IN_SET(', $user_info['groups']) . ', var.value3))'; } else { $artgroups = ''; } $totalmax = 200; loadLanguage('Stats'); $year = 10000000; $year2 = 100000000; $request = $smcFunc['db_query']('', 'SELECT art.id, art.date, art.sticky, art.featured FROM ({db_prefix}tp_articles AS art, {db_prefix}tp_variables AS var) WHERE art.off = 0 AND var.id = art.category ' . $artgroups . ' AND ((art.pub_start = 0 AND art.pub_end = 0) OR (art.pub_start != 0 AND art.pub_start < ' . $now . ' AND art.pub_end = 0) OR (art.pub_start = 0 AND art.pub_end != 0 AND art.pub_end > ' . $now . ') OR (art.pub_start != 0 AND art.pub_end != 0 AND art.pub_end > ' . $now . ' AND art.pub_start < ' . $now . ')) AND art.category > 0 AND art.approved = 1 AND (art.frontpage = 1 OR art.featured = 1) ORDER BY art.featured DESC, art.sticky desc, art.date DESC'); $posts = array(); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { if ($row['sticky'] == 1) { $row['date'] += $year; } if ($row['featured'] == 1) { $row['date'] += $year2; } $posts[$row['date'] . '_' . sprintf("%06s", $row['id'])] = 'a_' . $row['id']; } $smcFunc['db_free_result']($request); } // Find the post ids. if ($context['TPortal']['front_type'] == 'forum_articles') { $request = $smcFunc['db_query']('', ' SELECT t.id_first_msg as ID_FIRST_MSG , m.poster_time as date FROM ({db_prefix}topics as t, {db_prefix}boards as b, {db_prefix}messages as m) WHERE t.id_board = b.id_board AND t.id_first_msg = m.id_msg AND t.id_board IN({raw:board}) ' . ($context['TPortal']['allow_guestnews'] == 0 ? 'AND {query_see_board}' : '') . ' ORDER BY date DESC LIMIT {int:max}', array('board' => $context['TPortal']['SSI_board'], 'max' => $totalmax)); } else { $request = $smcFunc['db_query']('', ' SELECT t.id_first_msg as ID_FIRST_MSG , m.poster_time as date FROM ({db_prefix}topics as t, {db_prefix}boards as b, {db_prefix}messages as m) WHERE t.id_board = b.id_board AND t.id_first_msg = m.id_msg AND t.id_topic IN(' . (empty($context['TPortal']['frontpage_topics']) ? '0' : $context['TPortal']['frontpage_topics']) . ') ' . ($context['TPortal']['allow_guestnews'] == 0 ? 'AND {query_see_board}' : '') . ' ORDER BY date DESC'); } if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $posts[$row['date'] . '_' . sprintf("%06s", $row['ID_FIRST_MSG'])] = 'm_' . $row['ID_FIRST_MSG']; } $smcFunc['db_free_result']($request); } // Sort the articles/posts before grabing the limit, otherwise they are out of order ksort($posts, SORT_NUMERIC); $posts = array_reverse($posts); // which should we select $aposts = array(); $mposts = array(); $a = 0; foreach ($posts as $ab => $val) { if (($a == $start || $a > $start) && $a < $start + $max) { if (substr($val, 0, 2) == 'a_') { $aposts[] = substr($val, 2); } elseif (substr($val, 0, 2) == 'm_') { $mposts[] = substr($val, 2); } } $a++; } $thumbs = array(); if (count($mposts) > 0) { // Find the thumbs. $request = $smcFunc['db_query']('', ' SELECT id_thumb FROM {db_prefix}attachments WHERE id_msg IN ({array_int:posts}) AND id_thumb > 0', array('posts' => $mposts)); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $thumbs[] = $row['id_thumb']; } $smcFunc['db_free_result']($request); } } // make the pageindex! $context['TPortal']['pageindex'] = TPageIndex($scripturl . '?frontpage', $start, count($posts), $max); // ok we got the post ids now, fetch each one, forum first if (count($mposts) > 0) { $request = $smcFunc['db_query']('', ' SELECT m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS realName, m.poster_time as date, mem.avatar, mem.posts, mem.date_registered as dateRegistered, mem.last_login as lastLogin, IFNULL(a.id_attach, 0) AS ID_ATTACH, a.filename, a.attachment_type as attachmentType, t.id_board as category, b.name as category_name, t.num_replies as numReplies, t.id_topic as id, m.id_member as authorID, t.num_views as views, t.num_replies as replies, t.locked, IFNULL(thumb.id_attach, 0) AS thumb_id, thumb.filename as thumb_filename FROM ({db_prefix}topics AS t, {db_prefix}messages AS m) LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member AND a.attachment_type != 3) LEFT JOIN {db_prefix}attachments AS thumb ON (t.id_first_msg = thumb.id_msg AND thumb.attachment_type = 3 AND thumb.fileext IN ("jpg","gif","png") ) LEFT JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board) WHERE t.id_first_msg IN ({array_int:posts}) AND m.id_msg = t.id_first_msg GROUP BY t.id_first_msg ORDER BY date DESC, thumb.id_attach ASC', array('posts' => $mposts)); } $context['TPortal']['category'] = array('articles' => array(), 'col1' => array(), 'col2' => array(), 'options' => array('catlayout' => $context['TPortal']['frontpage_catlayout'], 'layout' => $context['TPortal']['frontpage_layout']), 'category_opts' => array('catlayout' => $context['TPortal']['frontpage_catlayout'], 'template' => $context['TPortal']['frontpage_template'])); unset($posts); $posts = array(); // insert the forumposts into $posts if (is_resource($request) && $smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $length = $context['TPortal']['frontpage_limit_len']; if (!empty($length) && $smcFunc['strlen']($row['body']) > $length) { $row['body'] = $smcFunc['substr']($row['body'], 0, $length); // The first space or line break. (<br />, etc.) $cutoff = max(strrpos($row['body'], ' '), strrpos($row['body'], '<')); if ($cutoff !== false) { $row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff); } $row['body'] .= '... <p><strong><a href="' . $scripturl . '?topic=' . $row['id'] . '">' . $txt['tp-readmore'] . '</a></strong></p>'; } // some needed addons $row['rendertype'] = 'bbc'; $row['frame'] = 'theme'; $row['boardnews'] = 1; if (!isset($context['TPortal']['frontpage_visopts'])) { $context['TPortal']['frontpage_visopts'] = 'date,title,author,views' . ($context['TPortal']['forumposts_avatar'] == 1 ? ',avatar' : ''); } $row['visual_options'] = explode(',', $context['TPortal']['frontpage_visopts']); $row['useintro'] = '0'; $row['avatar'] = $row['avatar'] == '' ? $row['ID_ATTACH'] > 0 ? '<img src="' . (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt=" " />' : '' : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '" alt=" " />' : '<img src="' . $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($row['avatar'], ENT_QUOTES) . '" alt=" " />'); if (!empty($row['thumb_id'])) { $row['illustration'] = $scripturl . '?action=tpmod;sa=tpattach;topic=' . $row['id'] . '.0;attach=' . $row['thumb_id'] . ';image'; } $posts[$row['date'] . '0' . sprintf("%06s", $row['id'])] = $row; } $smcFunc['db_free_result']($request); } // next up is articles if (count($aposts) > 0) { $request = $smcFunc['db_query']('', ' SELECT art.id, IF(art.useintro > 0, art.intro, art.body) AS body, art.date, art.category, art.subject, art.author_id as authorID, var.value1 as category_name, var.value8 as category_shortname, art.frame, art.comments, art.options, art.intro, art.useintro, art.sticky, art.featured, art.comments_var, art.views, art.rating, art.voters, art.shortname, art.fileimport, art.topic, art.illustration, art.type as rendertype, IFNULL(mem.real_name, art.author) as realName, mem.avatar, mem.posts, mem.date_registered as dateRegistered,mem.last_login as lastLogin, IFNULL(a.id_attach, 0) AS ID_ATTACH, a.filename, a.attachment_type as attachmentType FROM {db_prefix}tp_articles AS art LEFT JOIN {db_prefix}tp_variables AS var ON(var.id = art.category) LEFT JOIN {db_prefix}members AS mem ON (art.author_id = mem.id_member) LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member) WHERE art.id IN ({array_string:artid}) ORDER BY art.featured desc, art.sticky desc, art.' . $catsort . ' ' . $catsort_order, array('artid' => $aposts)); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { // expand the vislaoptions $row['visual_options'] = explode(',', $row['options']); $row['visual_options']['layout'] = $context['TPortal']['frontpage_layout']; $row['rating'] = array_sum(explode(',', $row['rating'])); $row['avatar'] = $row['avatar'] == '' ? $row['ID_ATTACH'] > 0 ? '<img src="' . (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt=" " />' : '' : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '" alt=" " />' : '<img src="' . $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($row['avatar'], ENT_QUOTES) . '" alt=" " />'); // we need some trick to put featured/sticky on top $sortdate = $row['date']; if ($row['sticky'] == 1) { $sortdate = $row['date'] + $year; } if ($row['featured'] == 1) { $sortdate = $row['date'] + $year + $year; } $posts[$sortdate . '0' . sprintf("%06s", $row['id'])] = $row; } $smcFunc['db_free_result']($request); } } $total = count($posts); $col1 = ceil($total / 2); $col2 = $total - $col1; $counter = 0; // divide it ksort($posts, SORT_NUMERIC); $all = array_reverse($posts); foreach ($all as $p => $row) { if ($counter == 0) { $context['TPortal']['category']['featured'] = $row; } elseif ($counter < $col1 && $counter > 0) { $context['TPortal']['category']['col1'][] = $row; } elseif ($counter > $col1 || $counter == $col1) { $context['TPortal']['category']['col2'][] = $row; } $counter++; } } // collect up frontblocks $blocks = array('front' => ''); $blocktype = array('no', 'userbox', 'newsbox', 'statsbox', 'searchbox', 'html', 'onlinebox', 'themebox', 'oldshoutbox', 'catmenu', 'phpbox', 'scriptbox', 'recentbox', 'ssi', 'module', 'rss', 'sitemap', 'oldadmin', 'articlebox', 'categorybox', 'tpmodulebox'); // set the membergroup access $mygroups = $user_info['groups']; $access = '(FIND_IN_SET(' . implode(', access) OR FIND_IN_SET(', $mygroups) . ', access))'; if (allowedTo('tp_blocks') && (!empty($context['TPortal']['admin_showblocks']) || !isset($context['TPortal']['admin_showblocks']))) { $access = '1'; } // get the blocks $request = $smcFunc['db_query']('', ' SELECT * FROM {db_prefix}tp_blocks WHERE off = 0 AND bar = 4 AND ' . $access . ' ORDER BY pos,id ASC'); $count = array('front' => 0); $fetch_articles = array(); $fetch_article_titles = array(); $panels = array(4 => 'front'); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { // some tests to minimize sql calls if ($row['type'] == 7) { $test_themebox = true; } elseif ($row['type'] == 18) { $test_articlebox = true; if (is_numeric($row['body'])) { $fetch_articles[] = $row['body']; } } elseif ($row['type'] == 9) { $test_menubox = true; } elseif ($row['type'] == 19) { $test_catbox = true; if (is_numeric($row['body'])) { $fetch_article_titles[] = $row['body']; } } elseif ($row['type'] == 20) { if (!empty($context['TPortal']['tpmodules']['blockrender'][$row['var1']]['sourcefile']) && file_exists($context['TPortal']['tpmodules']['blockrender'][$row['var1']]['sourcefile'])) { require_once $context['TPortal']['tpmodules']['blockrender'][$row['var1']]['sourcefile']; } } $can_edit = get_perm($row['editgroups'], ''); $can_manage = allowedTo('tp_blocks'); if ($can_manage) { $can_edit = false; } $blocks[$panels[$row['bar']]][$count[$panels[$row['bar']]]] = array('frame' => $row['frame'], 'title' => strip_tags($row['title'], '<center>'), 'type' => $blocktype[$row['type']], 'body' => $row['body'], 'visible' => $row['visible'], 'var1' => $row['var1'], 'var2' => $row['var2'], 'var3' => $row['var3'], 'var4' => $row['var4'], 'id' => $row['id'], 'lang' => $row['lang'], 'access2' => $row['access2'], 'can_edit' => $can_edit, 'can_manage' => $can_manage); $count[$panels[$row['bar']]]++; } $smcFunc['db_free_result']($request); } if (sizeof($fetch_articles) > 0) { $fetchart = '(art.id=' . implode(' OR art.id=', $fetch_articles) . ')'; } else { $fetchart = ''; } if (sizeof($fetch_article_titles) > 0) { $fetchtitles = '(art.category=' . implode(' OR art.category=', $fetch_article_titles) . ')'; } else { $fetchtitles = ''; } // if a block displays an article if (isset($test_articlebox) && $fetchart != '') { $context['TPortal']['blockarticles'] = array(); $request = $smcFunc['db_query']('', ' SELECT art.*, var.value1, var.value2, var.value3, var.value4, var.value5, var.value7, var.value8, art.type as rendertype, IFNULL(mem.real_name,art.author) as realName, mem.avatar, mem.posts, mem.date_registered as dateRegistered, mem.last_login as lastLogin, IFNULL(a.id_attach, 0) AS ID_ATTACH, a.filename, a.attachment_type as attachmentType, var.value9 FROM {db_prefix}tp_articles as art LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = art.author_id) LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = art.author_id AND a.attachment_type !=3) LEFT JOIN {db_prefix}tp_variables as var ON (var.id= art.category) WHERE ' . $fetchart . ' AND art.off = 0 AND ((art.pub_start = 0 AND art.pub_end = 0) OR (art.pub_start != 0 AND art.pub_start < ' . $now . ' AND art.pub_end = 0) OR (art.pub_start = 0 AND art.pub_end != 0 AND art.pub_end > ' . $now . ') OR (art.pub_start != 0 AND art.pub_end != 0 AND art.pub_end > ' . $now . ' AND art.pub_start < ' . $now . ')) AND art.category > 0 AND art.approved = 1 AND art.category > 0 AND art.category < 9999'); if ($smcFunc['db_num_rows']($request) > 0) { while ($article = $smcFunc['db_fetch_assoc']($request)) { // allowed and all is well, go on with it. $context['TPortal']['blockarticles'][$article['id']] = $article; $context['TPortal']['blockarticles'][$article['id']]['avatar'] = $row['avatar'] == '' ? $row['ID_ATTACH'] > 0 ? '<img src="' . (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt=" " />' : '' : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '" alt=" " />' : '<img src="' . $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($row['avatar'], ENT_QUOTES) . '" alt=" " />'); // sort out the options $context['TPortal']['blockarticles'][$article['id']]['visual_options'] = array(); // since these are inside blocks, some stuff has to be left out $context['TPortal']['blockarticles'][$article['id']]['frame'] = 'none'; } $smcFunc['db_free_result']($request); } } // any cat listings from blocks? if (isset($test_catbox) && $fetchtitles != '') { $request = $smcFunc['db_query']('', ' SELECT art.id, art.subject, art.date, art.category, art.author_id as authorID, art.shortname, IFNULL(mem.real_name,art.author) as real_name FROM {db_prefix}tp_articles AS art LEFT JOIN {db_prefix}members AS mem ON (art.author_id = mem.id_member) WHERE ' . $fetchtitles . ' AND ((art.pub_start = 0 AND art.pub_end = 0) OR (art.pub_start != 0 AND art.pub_start < ' . $now . ' AND art.pub_end = 0) OR (art.pub_start = 0 AND art.pub_end != 0 AND art.pub_end > ' . $now . ') OR (art.pub_start != 0 AND art.pub_end != 0 AND art.pub_end > ' . $now . ' AND art.pub_start < ' . $now . ')) AND art.off = 0 AND art.category > 0 AND art.approved = 1'); if (!isset($context['TPortal']['blockarticle_titles'])) { $context['TPortal']['blockarticle_titles'] = array(); } if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $context['TPortal']['blockarticle_titles'][$row['category']][$row['date'] . '_' . $row['id']] = array('id' => $row['id'], 'subject' => $row['subject'], 'shortname' => $row['shortname'] != '' ? $row['shortname'] : $row['id'], 'category' => $row['category'], 'poster' => '<a href="' . $scripturl . '?action=profile;u=' . $row['authorID'] . '">' . $row['real_name'] . '</a>'); } $smcFunc['db_free_result']($request); } } // get menubox items if (isset($test_menubox)) { $context['TPortal']['menu'] = array(); $request = $smcFunc['db_query']('', ' SELECT * FROM {db_prefix}tp_variables WHERE type = {string:type} ORDER BY value5 ASC', array('type' => 'menubox')); if ($smcFunc['db_num_rows']($request) > 0) { while ($row = $smcFunc['db_fetch_assoc']($request)) { $icon = ''; if ($row['value5'] != -1 && $row['value2'] != '-1') { $mtype = substr($row['value3'], 0, 4); $idtype = substr($row['value3'], 4); if ($mtype != 'cats' && $mtype != 'arti' && $mtype != 'head' && $mtype != 'spac') { $mtype = 'link'; $idtype = $row['value3']; } if ($mtype == 'cats') { if (isset($context['TPortal']['article_categories']['icon'][$idtype])) { $icon = $context['TPortal']['article_categories']['icon'][$idtype]; } } if ($mtype == 'head') { $mtype = 'head'; $idtype = $row['value1']; } $menupos = $row['value5']; $context['TPortal']['menu'][$row['subtype2']][] = array('id' => $row['id'], 'menuID' => $row['subtype2'], 'name' => $row['value1'], 'pos' => $menupos, 'type' => $mtype, 'IDtype' => $idtype, 'off' => '0', 'sub' => $row['value4'], 'icon' => $icon, 'newlink' => $row['value2'], 'sitemap' => in_array($row['id'], $context['TPortal']['sitemap']) ? true : false); } } $smcFunc['db_free_result']($request); } } // check the panels foreach ($panels as $p => $panel) { // any blocks at all? if ($count[$panel] < 1) { $context['TPortal'][$panel . 'panel'] = 0; } } $context['TPortal']['frontblocks'] = $blocks; if (WIRELESS) { $context['TPortal']['single_article'] = false; loadtemplate('TPwireless'); // decide what subtemplate $context['sub_template'] = WIRELESS_PROTOCOL . '_tp_frontpage'; } }