Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.50 KB | None | 0 0
  1. function loadType()
  2. {
  3.     global $txt, $scripturl, $context, $modSettings;
  4.     global $type, $work, $user_info, $smcFunc;
  5.  
  6.     // Start the linktree off empty..
  7.     $context['linktree'] = array();
  8.  
  9.     // Have they by chance specified a work id but nothing else?
  10.     if (empty($_REQUEST['action']) && empty($work) && empty($type) && !empty($_REQUEST['work']))
  11.     {
  12.         // Make sure the message id is really an int.
  13.         $_REQUEST['work'] = (int) $_REQUEST['work'];
  14.  
  15.         // Looking through the work table can be slow, so try using the cache first.
  16.         if (($work = cache_get_data('work-' . $_REQUEST['work'], 120)) === null)
  17.         {
  18.             $request = $smcFunc['db_query']('', '
  19.                 SELECT id_work
  20.                 FROM {db_prefix}works_works
  21.                 WHERE id_work = {int:id_work}
  22.                 LIMIT 1',
  23.                 array(
  24.                     'id_work' => $_REQUEST['work'],
  25.                 )
  26.             );
  27.  
  28.             // So did it find anything?
  29.             if ($smcFunc['db_num_rows']($request))
  30.             {
  31.                 list ($work) = $smcFunc['db_fetch_row']($request);
  32.                 $smcFunc['db_free_result']($request);
  33.                 // Save save save.
  34.                 cache_put_data('work-' . $_REQUEST['work'], $work, 120);
  35.             }
  36.         }
  37.  
  38.         // Remember redirection is the key to avoiding fallout from your bosses.
  39.         if (!empty($work))
  40.             redirectexit('work=' . $work . '');
  41.         else
  42.         {
  43.             loadPermissions();
  44.             loadTheme();
  45.             fatal_lang_error('topic_gone', false);
  46.         }
  47.     }
  48.  
  49.     if (!empty($modSettings['cache_enable']) && (empty($work) || $modSettings['cache_enable'] >= 3))
  50.     {
  51.         // @todo SLOW?
  52.         if (!empty($work))
  53.             $temp = cache_get_data('work_type-' . $work, 120);
  54.         else
  55.             $temp = cache_get_data('type-' . $type, 120);
  56.  
  57.         if (!empty($temp))
  58.         {
  59.             $type_info = $temp;
  60.             $type = $type_info['id'];
  61.         }
  62.     }
  63.  
  64.     if (empty($temp))
  65.     {
  66.         $request = $smcFunc['db_query']('', '
  67.             SELECT
  68.                 c.id_cat,
  69.                 c.cat_name,
  70.                 t.type_name,
  71.                 t.type_desc,
  72.                 t.num_works,
  73.                 t.num_comments,
  74.                 ' . (!empty($work) ? ', w.id_work' : '') . ',
  75.                 t.child_level,
  76.                 w.id_work,
  77.                 w.id_member,
  78.                 mg.group_name,
  79.                 m.real_name,
  80.                 w.work_title,
  81.                 w.work_cap,
  82.                 u.filetype,
  83.                 u.location,
  84.                 w.id_feedback,
  85.                 w.id_series,
  86.                 w.id_triggers,
  87.                 w.is_adult,
  88.                 w.poster_time,
  89.                 w.work_comments,
  90.                 w.work_views
  91.             FROM
  92.                 {db_prefix}works_uploads as u
  93.             LEFT JOIN
  94.                 {db_prefix}works_works AS w ON (w.id_work = u.id_work)
  95.             LEFT JOIN
  96.                 {db_prefix}members AS m ON (m.id_member = w.id_member)
  97.             LEFT JOIN
  98.                 {db_prefix}membergroups AS mg ON (mg.id_group = m.id_group)
  99.             LEFT JOIN
  100.                 {db_prefix}works_categories AS c ON (t.id_cat = c.id_cat)
  101.             LEFT JOIN
  102.                 {db_prefix}works_types AS t ON (t.id_type = w.id_type)
  103.             WHERE
  104.                 t.id_type = {raw:type_link}',
  105.             array(
  106.                 'current_work' => $work,
  107.                 'current_type' => $type,
  108.                 'type_link' => empty($work) ? $smcFunc['db_quote']('{int:current_type}', array('current_type' => $type)) : 't.id_type',
  109.             )
  110.         );
  111.         // If there aren't any, skip.
  112.         if ($smcFunc['db_num_rows']($request) > 0)
  113.         {
  114.             $row = $smcFunc['db_fetch_assoc']($request);
  115.  
  116.             // Set the current board.
  117.             if (!empty($row['id_type']))
  118.                 $type = $row['id_type'];
  119.  
  120.             // Basic operating information. (globals... :/)
  121.             $type_info = array(
  122.                 'id' => $type,
  123.                 'cat' => array(
  124.                     'id' => $row['id_cat'],
  125.                     'name' => $row['cat_name']
  126.                 ),
  127.                 'name' => $row['type_name'],
  128.                 'description' => $row['type_desc'],
  129.                 'num_comments' => comma_format($row['num_comments']),
  130.                 'num_works' => comma_format($row['num_works']),
  131.                 'parent' => $row['id_parent'],
  132.                 'child_level' => $row['child_level'],
  133.             );
  134.  
  135.             if (!empty($modSettings['cache_enable']) && (empty($work) || $modSettings['cache_enable'] >= 3))
  136.             {
  137.                 // @todo SLOW?
  138.                 if (!empty($work))
  139.                     cache_put_data('work_type-' . $work, $type_info, 120);
  140.                 cache_put_data('type-' . $type, $type_info, 120);
  141.             }
  142.         }
  143.         else
  144.         {
  145.             // Otherwise the topic is invalid, there are no moderators, etc.
  146.             $type_info = array(
  147.                 'error' => 'exist'
  148.             );
  149.             $work = null;
  150.             $type = 0;
  151.         }
  152.         $smcFunc['db_free_result']($request);
  153.     }
  154.  
  155.     if (!empty($work))
  156.         $_GET['type'] = (int) $type;
  157.  
  158.     if (!empty($type))
  159.     {
  160.  
  161.         // Build up the linktree.
  162.         $context['linktree'] = array_merge(
  163.             $context['linktree'],
  164.             array(array(
  165.                 'url' => $scripturl . '#c' . $type_info['cat']['id'],
  166.                 'name' => $type_info['cat']['name']
  167.             )),
  168.             array(array(
  169.                 'url' => $scripturl . '?type=' . $type . '.0',
  170.                 'name' => $type_info['name']
  171.             ))
  172.         );
  173.     }
  174.  
  175.     // Set the template contextual information.
  176.     $context['current_work'] = $work;
  177.     $context['current_type'] = $type;
  178.  
  179.     // Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
  180.     if (!empty($type_info['error']) || $board_info['error'] != 'access')
  181.     {
  182.         // The permissions and theme need loading, just to make sure everything goes smoothly.
  183.         loadPermissions();
  184.         loadTheme();
  185.  
  186.         $_GET['type'] = '';
  187.         $_GET['work'] = '';
  188.  
  189.         // The linktree should not give the game away mate!
  190.         $context['linktree'] = array(
  191.             array(
  192.                 'url' => $scripturl,
  193.                 'name' => $context['forum_name_html_safe']
  194.             )
  195.         );
  196.  
  197.         // If it's a prefetching agent or we're requesting an attachment.
  198.         if ((isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') || (!empty($_REQUEST['action']) && $_REQUEST['action'] === 'dlattach'))
  199.         {
  200.             ob_end_clean();
  201.             header('HTTP/1.1 403 Forbidden');
  202.             die;
  203.         }
  204.         elseif ($user_info['is_guest'])
  205.         {
  206.             loadLanguage('Errors');
  207.             is_not_guest($txt['topic_gone']);
  208.         }
  209.         else
  210.             fatal_lang_error('topic_gone', false);
  211.     }
  212.    
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement