Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function loadType()
- {
- global $txt, $scripturl, $context, $modSettings;
- global $type, $work, $user_info, $smcFunc;
- // Start the linktree off empty..
- $context['linktree'] = array();
- // Have they by chance specified a work id but nothing else?
- if (empty($_REQUEST['action']) && empty($work) && empty($type) && !empty($_REQUEST['work']))
- {
- // Make sure the message id is really an int.
- $_REQUEST['work'] = (int) $_REQUEST['work'];
- // Looking through the work table can be slow, so try using the cache first.
- if (($work = cache_get_data('work-' . $_REQUEST['work'], 120)) === null)
- {
- $request = $smcFunc['db_query']('', '
- SELECT id_work
- FROM {db_prefix}works_works
- WHERE id_work = {int:id_work}
- LIMIT 1',
- array(
- 'id_work' => $_REQUEST['work'],
- )
- );
- // So did it find anything?
- if ($smcFunc['db_num_rows']($request))
- {
- list ($work) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- // Save save save.
- cache_put_data('work-' . $_REQUEST['work'], $work, 120);
- }
- }
- // Remember redirection is the key to avoiding fallout from your bosses.
- if (!empty($work))
- redirectexit('work=' . $work . '');
- else
- {
- loadPermissions();
- loadTheme();
- fatal_lang_error('topic_gone', false);
- }
- }
- if (!empty($modSettings['cache_enable']) && (empty($work) || $modSettings['cache_enable'] >= 3))
- {
- // @todo SLOW?
- if (!empty($work))
- $temp = cache_get_data('work_type-' . $work, 120);
- else
- $temp = cache_get_data('type-' . $type, 120);
- if (!empty($temp))
- {
- $type_info = $temp;
- $type = $type_info['id'];
- }
- }
- if (empty($temp))
- {
- $request = $smcFunc['db_query']('', '
- SELECT
- c.id_cat,
- c.cat_name,
- t.type_name,
- t.type_desc,
- t.num_works,
- t.num_comments,
- ' . (!empty($work) ? ', w.id_work' : '') . ',
- t.child_level,
- w.id_work,
- w.id_member,
- mg.group_name,
- m.real_name,
- w.work_title,
- w.work_cap,
- u.filetype,
- u.location,
- w.id_feedback,
- w.id_series,
- w.id_triggers,
- w.is_adult,
- w.poster_time,
- w.work_comments,
- w.work_views
- FROM
- {db_prefix}works_uploads as u
- LEFT JOIN
- {db_prefix}works_works AS w ON (w.id_work = u.id_work)
- LEFT JOIN
- {db_prefix}members AS m ON (m.id_member = w.id_member)
- LEFT JOIN
- {db_prefix}membergroups AS mg ON (mg.id_group = m.id_group)
- LEFT JOIN
- {db_prefix}works_categories AS c ON (t.id_cat = c.id_cat)
- LEFT JOIN
- {db_prefix}works_types AS t ON (t.id_type = w.id_type)
- WHERE
- t.id_type = {raw:type_link}',
- array(
- 'current_work' => $work,
- 'current_type' => $type,
- 'type_link' => empty($work) ? $smcFunc['db_quote']('{int:current_type}', array('current_type' => $type)) : 't.id_type',
- )
- );
- // If there aren't any, skip.
- if ($smcFunc['db_num_rows']($request) > 0)
- {
- $row = $smcFunc['db_fetch_assoc']($request);
- // Set the current board.
- if (!empty($row['id_type']))
- $type = $row['id_type'];
- // Basic operating information. (globals... :/)
- $type_info = array(
- 'id' => $type,
- 'cat' => array(
- 'id' => $row['id_cat'],
- 'name' => $row['cat_name']
- ),
- 'name' => $row['type_name'],
- 'description' => $row['type_desc'],
- 'num_comments' => comma_format($row['num_comments']),
- 'num_works' => comma_format($row['num_works']),
- 'parent' => $row['id_parent'],
- 'child_level' => $row['child_level'],
- );
- if (!empty($modSettings['cache_enable']) && (empty($work) || $modSettings['cache_enable'] >= 3))
- {
- // @todo SLOW?
- if (!empty($work))
- cache_put_data('work_type-' . $work, $type_info, 120);
- cache_put_data('type-' . $type, $type_info, 120);
- }
- }
- else
- {
- // Otherwise the topic is invalid, there are no moderators, etc.
- $type_info = array(
- 'error' => 'exist'
- );
- $work = null;
- $type = 0;
- }
- $smcFunc['db_free_result']($request);
- }
- if (!empty($work))
- $_GET['type'] = (int) $type;
- if (!empty($type))
- {
- // Build up the linktree.
- $context['linktree'] = array_merge(
- $context['linktree'],
- array(array(
- 'url' => $scripturl . '#c' . $type_info['cat']['id'],
- 'name' => $type_info['cat']['name']
- )),
- array(array(
- 'url' => $scripturl . '?type=' . $type . '.0',
- 'name' => $type_info['name']
- ))
- );
- }
- // Set the template contextual information.
- $context['current_work'] = $work;
- $context['current_type'] = $type;
- // Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
- if (!empty($type_info['error']) || $board_info['error'] != 'access')
- {
- // The permissions and theme need loading, just to make sure everything goes smoothly.
- loadPermissions();
- loadTheme();
- $_GET['type'] = '';
- $_GET['work'] = '';
- // The linktree should not give the game away mate!
- $context['linktree'] = array(
- array(
- 'url' => $scripturl,
- 'name' => $context['forum_name_html_safe']
- )
- );
- // If it's a prefetching agent or we're requesting an attachment.
- if ((isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') || (!empty($_REQUEST['action']) && $_REQUEST['action'] === 'dlattach'))
- {
- ob_end_clean();
- header('HTTP/1.1 403 Forbidden');
- die;
- }
- elseif ($user_info['is_guest'])
- {
- loadLanguage('Errors');
- is_not_guest($txt['topic_gone']);
- }
- else
- fatal_lang_error('topic_gone', false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement