123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- <?php
- if (!defined('SMF'))
- die('No direct access...');
- function Likes()
- {
- global $context, $smcFunc;
-
- $like_type = isset($_GET['ltype']) ? $_GET['ltype'] : '';
- preg_match('~^([a-z0-9\-\_]{1,6})~i', $like_type, $matches);
- $like_type = isset($matches[1]) ? $matches[1] : '';
- $like_content = isset($_GET['like']) ? (int) $_GET['like'] : 0;
- if ($like_type == '' || $like_content <= 0)
- fatal_lang_error(isset($_GET['view']) ? 'cannot_view_likes' : 'cannot_like_content', false);
-
-
- if ($like_type == 'msg')
- {
-
-
-
- $request = $smcFunc['db_query']('', '
- SELECT m.id_topic
- FROM {db_prefix}messages AS m
- INNER JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
- WHERE {query_see_board}
- AND m.id_msg = {int:msg}',
- array(
- 'msg' => $like_content,
- )
- );
- if ($smcFunc['db_num_rows']($request) == 1)
- list ($id_topic) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- if (empty($id_topic))
- fatal_lang_error(isset($_GET['view']) ? 'cannot_view_likes' : 'cannot_like_content', false);
-
-
- if (!isset($_GET['view']))
- {
- $context['flush_cache'] = 'likes_topic_' . $id_topic . '_' . $context['user']['id'];
- $context['redirect_from_like'] = 'topic=' . $id_topic . '.msg' . $like_content . '#msg' . $like_content;
- add_integration_function('integrate_issue_like', 'msg_issue_like', '', false);
- }
- }
- else
- {
-
-
-
-
-
- $can_like = call_integration_hook('integrate_valid_likes', array($like_type, $like_content));
- $found = false;
- if (!empty($can_like))
- {
- $can_like = (array) $can_like;
- foreach ($can_like as $result)
- {
- if ($result !== false)
- {
- $like_type = $result;
- $found = true;
- break;
- }
- }
- }
- if (!$found)
- fatal_lang_error(isset($_GET['view']) ? 'cannot_view_likes' : 'cannot_like_content', false);
- }
-
-
- if (isset($_GET['view']))
- viewLikes($like_type, $like_content);
- else
- {
-
- is_not_guest();
- checkSession('get');
- issueLike($like_type, $like_content);
- }
- }
- function issueLike($like_type, $like_content)
- {
- global $context, $smcFunc;
-
- $request = $smcFunc['db_query']('', '
- SELECT content_id, content_type, id_member
- FROM {db_prefix}user_likes
- WHERE content_id = {int:like_content}
- AND content_type = {string:like_type}
- AND id_member = {int:id_member}',
- array(
- 'like_content' => $like_content,
- 'like_type' => $like_type,
- 'id_member' => $context['user']['id'],
- )
- );
- $already_liked = $smcFunc['db_num_rows']($request) != 0;
- $smcFunc['db_free_result']($request);
- if ($already_liked)
- {
- $smcFunc['db_query']('', '
- DELETE FROM {db_prefix}user_likes
- WHERE content_id = {int:like_content}
- AND content_type = {string:like_type}
- AND id_member = {int:id_member}',
- array(
- 'like_content' => $like_content,
- 'like_type' => $like_type,
- 'id_member' => $context['user']['id'],
- )
- );
- }
- else
- {
-
- $smcFunc['db_insert']('insert',
- '{db_prefix}user_likes',
- array('content_id' => 'int', 'content_type' => 'string-6', 'id_member' => 'int', 'like_time' => 'int'),
- array($like_content, $like_type, $context['user']['id'], time()),
- array('content_id', 'content_type', 'id_member')
- );
-
- $smcFunc['db_insert']('insert',
- '{db_prefix}background_tasks',
- array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
- array('$sourcedir/tasks/Likes-Notify.php', 'Likes_Notify_Background', serialize(array(
- 'content_id' => $like_content,
- 'content_type' => $like_type,
- 'sender_id' => $context['user']['id'],
- 'sender_name' => $context['user']['name'],
- 'time' => time(),
- )), 0),
- array('id_task')
- );
- }
-
- $request = $smcFunc['db_query']('', '
- SELECT COUNT(id_member)
- FROM {db_prefix}user_likes
- WHERE content_id = {int:like_content}
- AND content_type = {string:like_type}',
- array(
- 'like_content' => $like_content,
- 'like_type' => $like_type,
- )
- );
- list ($num_likes) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
-
- call_integration_hook('integrate_issue_like', array($like_type, $like_content, $num_likes));
-
-
-
- if (!empty($context['flush_cache']))
- cache_put_data($context['flush_cache'], null);
- if (!empty($context['redirect_from_like']))
- redirectexit($context['redirect_from_like']);
- else
- redirectexit();
- }
- function msg_issue_like($like_type, $like_content, $num_likes)
- {
- global $smcFunc;
- if ($like_type !== 'msg')
- return;
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}messages
- SET likes = {int:num_likes}
- WHERE id_msg = {int:id_msg}',
- array(
- 'id_msg' => $like_content,
- 'num_likes' => $num_likes,
- )
- );
-
-
-
- }
- function viewLikes($like_type, $like_content)
- {
- global $smcFunc, $txt, $context, $memberContext;
-
- $context['likers'] = array();
- $request = $smcFunc['db_query']('', '
- SELECT id_member, like_time
- FROM {db_prefix}user_likes
- WHERE content_id = {int:like_content}
- AND content_type = {string:like_type}
- ORDER BY like_time DESC',
- array(
- 'like_content' => $like_content,
- 'like_type' => $like_type,
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $context['likers'][$row['id_member']] = array('timestamp' => $row['like_time']);
-
- $members = array_keys($context['likers']);
- $loaded = loadMemberData($members);
- if (count($loaded) != count($members))
- {
- $members = array_diff($members, $loaded);
- foreach ($members as $not_loaded)
- unset ($context['likers'][$not_loaded]);
- }
- foreach ($context['likers'] as $liker => $dummy)
- {
- $loaded = loadMemberContext($liker);
- if (!$loaded)
- {
- unset ($context['likers'][$liker]);
- continue;
- }
- $context['likers'][$liker]['profile'] = &$memberContext[$liker];
- $context['likers'][$liker]['time'] = !empty($dummy['timestamp']) ? timeformat($dummy['timestamp']) : '';
- }
- $count = count($context['likers']);
- $title_base = isset($txt['likes_' . $count]) ? 'likes_' . $count : 'likes_n';
- $context['page_title'] = strip_tags(sprintf($txt[$title_base], '', comma_format($count)));
-
- loadTemplate('Likes');
- loadLanguage('Help');
- $context['template_layers'] = array();
- $context['sub_template'] = 'popup';
- }
- function BookOfUnknown()
- {
- global $context, $scripturl;
- echo '<!DOCTYPE html>
- <html', $context['right_to_left'] ? ' dir="rtl"' : '', '>
- <head>
- <title>The Book of Unknown, ', @$_GET['verse'] == '2:18' ? '2:18' : '4:16', '</title>
- <style type="text/css">
- em
- {
- font-size: 1.3em;
- line-height: 0;
- }
- </style>
- </head>
- <body style="background-color: #444455; color: white; font-style: italic; font-family: serif;">
- <div style="margin-top: 12%; font-size: 1.1em; line-height: 1.4; text-align: center;">';
- if (!isset($_GET['verse']) || ($_GET['verse'] != '2:18' && $_GET['verse'] != '22:1-2'))
- $_GET['verse'] = '4:16';
- if ($_GET['verse'] == '2:18')
- echo '
- Woe, it was that his name wasn\'t <em>known</em>, that he came in mystery, and was recognized by none. And it became to be in those days <em>something</em>. Something not yet <em id="unknown" name="[Unknown]">unknown</em> to mankind. And thus what was to be known the <em>secret project</em> began into its existence. Henceforth the opposition was only <em>weary</em> and <em>fearful</em>, for now their match was at arms against them.';
- elseif ($_GET['verse'] == '4:16')
- echo '
- And it came to pass that the <em>unbelievers</em> dwindled in number and saw rise of many <em>proselytizers</em>, and the opposition found fear in the face of the <em>x</em> and the <em>j</em> while those who stood with the <em>something</em> grew stronger and came together. Still, this was only the <em>beginning</em>, and what lay in the future was <em id="unknown" name="[Unknown]">unknown</em> to all, even those on the right side.';
- elseif ($_GET['verse'] == '22:1-2')
- echo '
- <p>Now <em>behold</em>, that which was once the secret project was <em id="unknown" name="[Unknown]">unknown</em> no longer. Alas, it needed more than <em>only one</em>, but yet even thought otherwise. It became that the opposition <em>rumored</em> and lied, but still to no avail. Their match, though not <em>perfect</em>, had them outdone.</p>
- <p style="margin: 2ex 1ex 0 1ex; font-size: 1.05em; line-height: 1.5; text-align: center;">Let it continue. <em>The end</em>.</p>';
- echo '
- </div>
- <div style="margin-top: 2ex; font-size: 2em; text-align: right;">';
- if ($_GET['verse'] == '2:18')
- echo '
- from <span style="font-family: Georgia, serif;"><strong><a href="', $scripturl, '?action=about:unknown;verse=4:16" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 2:18</span>';
- elseif ($_GET['verse'] == '4:16')
- echo '
- from <span style="font-family: Georgia, serif;"><strong><a href="', $scripturl, '?action=about:unknown;verse=22:1-2" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 4:16</span>';
- elseif ($_GET['verse'] == '22:1-2')
- echo '
- from <span style="font-family: Georgia, serif;"><strong>The Book of Unknown</strong>, 22:1-2</span>';
- echo '
- </div>
- </body>
- </html>';
- obExit(false);
- }
- ?>
|