KeyDog

Ajax Rating 0.0.3

Dec 29th, 2011
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 29.85 KB | None | 0 0
  1.  
  2. <!--
  3. /**
  4. * Allows users to to rate posts
  5. *
  6. * @copyright Copyright (C) 2009 crurf.info
  7. * @license http://creativecommons.org/licenses/by-sa/3.0/ Creative Commons License version 3.0 or higher
  8. * @package ajax_rating
  9. */
  10. -->
  11.  
  12. <extension engine="1.0">
  13.     <id>ajax_rating</id>
  14.     <title>Ajax Rating</title>
  15.     <version>0.0.3</version>
  16.     <description>Adds rating feature for posts.</description>
  17.     <author>Radoslav Salov</author>
  18.     <minversion>1.4</minversion>
  19.     <maxtestedon>1.4.1</maxtestedon>
  20.  
  21.     <install><![CDATA[
  22.        
  23.         $update = 0;
  24.         $version = 0;
  25.        
  26.         $query = array(
  27.           'SELECT' => 'version',
  28.           'FROM' => 'extensions',
  29.           'WHERE' => 'id = \'ajax_rating\'',
  30.         );
  31.        
  32.         $result = $forum_db->query_build($query);
  33.         if ((int)$forum_db->num_rows($result)) {
  34.             $update ++;
  35.             list($version) = $forum_db->fetch_row($result);
  36.         }
  37.        
  38.         $query = array(
  39.           'SELECT' => 'count(*) AS cnt',
  40.           'FROM' => 'postrating',
  41.         );
  42.        
  43.         $result = $forum_db->query_build($query);
  44.         if ((int)$forum_db->num_rows($result)) $update ++;
  45.        
  46.         if ($update == 2) {
  47.             if ($version == '0.0.1') {
  48.                 $forum_db->query('ALTER TABLE ' . $forum_db->prefix . 'postrating_det ADD COLUMN rating INT(1) NOT NULL DEFAULT 0');
  49.                 $forum_db->query('ALTER TABLE ' . $forum_db->prefix . 'postrating_det DROP INDEX postrating_det_postrating_det_postid_ip');
  50.                 $forum_db->query('ALTER TABLE ' . $forum_db->prefix . 'postrating_det DROP INDEX postrating_det_postid_ip');
  51.             }
  52.         } else {
  53.             $schema = array(
  54.                 'FIELDS' => array(
  55.                     'postid'        => array(
  56.                         'datatype'      => 'SERIAL',
  57.                         'allow_null'    => false
  58.                     ),
  59.                     'yescnt'    => array(
  60.                         'datatype'      => 'INT(10)',
  61.                         'allow_null'    => false,
  62.                         'default'       => 0
  63.                     ),
  64.                     'nocnt' => array(
  65.                         'datatype'      => 'INT(10)',
  66.                         'allow_null'    => false,
  67.                         'default'       => 0
  68.                     ),
  69.                     'rating'    => array(
  70.                         'datatype'      => 'FLOAT',
  71.                         'allow_null'    => false,
  72.                         'default'       => 0
  73.                     ),
  74.                     'cnt'   => array(
  75.                         'datatype'      => 'INT(10)',
  76.                         'allow_null'    => false,
  77.                         'default'       => 0
  78.                     )
  79.                 ),
  80.                 'PRIMARY KEY'   =>  array('postid'),
  81.                 'ENGINE'        =>  'MyISAM'
  82.             );
  83.             $forum_db->create_table('postrating', $schema);
  84.  
  85.             $schema = array(
  86.                 'FIELDS'        => array(
  87.                     'id'            => array(
  88.                         'datatype'      => 'SERIAL',
  89.                         'allow_null'    => false
  90.                     ),
  91.                     'postid'        => array(
  92.                         'datatype'      => 'INT(10)',
  93.                         'allow_null'    => false
  94.                     ),
  95.                     'ip'        => array(
  96.                         'datatype'      => 'VARCHAR(15)',
  97.                         'allow_null'    => false
  98.                     ),
  99.                     'rating'    => array(
  100.                         'datatype'      => 'INT(1)',
  101.                         'allow_null'    => false,
  102.                         'default'       => 0
  103.                     ),
  104.                     'tstamp'            => array(
  105.                         'datatype'      => 'INT(11)',
  106.                         'allow_null'    => false
  107.                     )
  108.                 ),
  109.                 'PRIMARY KEY'   =>  array('id'),
  110.                 'ENGINE'        =>  'MyISAM'
  111.             );
  112.             $forum_db->create_table('postrating_det', $schema);
  113.         }
  114.        
  115.         $query_conf = array(
  116.             'INSERT'    => 'conf_name, conf_value',
  117.             'INTO'      => 'config',
  118.             'VALUES'    => '"p_ajax_rating_type","0"'
  119.         );
  120.         $forum_db->query_build($query_conf);
  121.        
  122.         $query_conf = array(
  123.             'INSERT'    => 'conf_name, conf_value',
  124.             'INTO'      => 'config',
  125.             'VALUES'    => '"p_ajax_rating_allow_multiple","0"'
  126.         );
  127.         $forum_db->query_build($query_conf);
  128.        
  129.         $query_conf = array(
  130.             'INSERT'    => 'conf_name, conf_value',
  131.             'INTO'      => 'config',
  132.             'VALUES'    => '"p_ajax_rating_allow_guest","0"'
  133.         );
  134.         $forum_db->query_build($query_conf);
  135.         $toprated = FORUM_ROOT . 'toprated.php';
  136.         if (!is_file($toprated)) {
  137.             $tr_contents = '<?php
  138. /**
  139. * Allows users to to rate posts
  140. *
  141. * @copyright Copyright (C) 2009 crurf.info
  142. * @license http://creativecommons.org/licenses/by-sa/3.0/ Creative Commons License version 3.0 or higher
  143. * @package ajax_rating
  144. */
  145.  
  146. define(\'FORUM_SKIP_CSRF_CONFIRM\', 1);
  147.  
  148. if (!defined(\'FORUM_ROOT\'))
  149.     define(\'FORUM_ROOT\', \'./\');
  150. require FORUM_ROOT.\'include/common.php\';
  151.  
  152. include_once FORUM_ROOT . \'/extensions/ajax_rating/fns.php\';
  153.  
  154. if (!$lang_ajax_rating) {
  155.     if (file_exists(FORUM_ROOT . \'/extensions/' . $ext_info['id'] . '/lang/\' . $forum_user[\'language\'] . \'/' . $ext_info['id'] . '2.php\'))
  156.         include_once FORUM_ROOT . \'/extensions/' . $ext_info['id'] . '/lang/\' . $forum_user[\'language\'] . \'/' . $ext_info['id'] . '2.php\';
  157.     else
  158.         include_once FORUM_ROOT . \'/extensions/' . $ext_info['id'] . '/lang/English/' . $ext_info['id'] . '2.php\';
  159. }
  160.  
  161. // Load the viewtopic.php language file
  162. require FORUM_ROOT.\'lang/\'.$forum_user[\'language\'].\'/topic.php\';
  163.  
  164. $type = isset($_GET[\'type\']) ? intval($_GET[\'type\']) : 0;
  165. $tab = isset($_GET[\'tab\']) ? intval($_GET[\'tab\']) : 0;
  166.  
  167. if (!in_array($type, array(0,1))) $type = 0;
  168. if (!in_array($tab, array(0,1,2))) $tab = 0;
  169.  
  170. $curtime = mktime();
  171. $period = 24 * 60 * 60;
  172. switch ($tab) {
  173.     case 1:
  174.         $period = 7 * 24 * 60 * 60;
  175.         break;
  176.     case 2:
  177.         $period = 30 * 24 * 60 * 60;
  178.         break;
  179. }
  180.  
  181. $forum_page[\'item_count\'] = 0;    // Keep track of post numbers
  182.  
  183. // Retrieve the posts (and their respective poster/online status)
  184. $query = array(
  185.  \'SELECT\'    => \'a.rate, t.subject as topicsubj, p.topic_id, u.email, u.title, u.url, u.location, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, u.avatar, u.avatar_width, u.avatar_height, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online\',
  186.     \'FROM\' => \'(
  187.         SELECT ((sum(pd.rating) * 100) / count(*)) as rate, pd.postid
  188.         FROM \' . $forum_db->prefix . \'postrating_det AS pd
  189.         WHERE pd.tstamp <= \' . $curtime . \' AND pd.tstamp >= \' . ($curtime - $period) . \'
  190.         GROUP BY pd.postid
  191.     ) AS a\',
  192.     \'JOINS\'       => array(
  193.         array(
  194.             \'INNER JOIN\'  => $forum_db->prefix . \'posts AS p\',
  195.             \'ON\'          => \'p.id=a.postid\'
  196.         ),
  197.         array(
  198.             \'INNER JOIN\'  => $forum_db->prefix . \'topics AS t\',
  199.             \'ON\'          => \'p.topic_id=t.id\'
  200.         ),
  201.         array(
  202.             \'INNER JOIN\'  => $forum_db->prefix . \'users AS u\',
  203.             \'ON\'          => \'u.id=p.poster_id\'
  204.         ),
  205.         array(
  206.             \'INNER JOIN\'  => $forum_db->prefix . \'groups AS g\',
  207.             \'ON\'          => \'g.g_id=u.group_id\'
  208.         ),
  209.         array(
  210.             \'LEFT JOIN\'       => $forum_db->prefix . \'online AS o\',
  211.             \'ON\'          => \'(o.user_id=u.id AND o.user_id!=1 AND o.idle=0)\'
  212.         ),
  213.     ),
  214.     \'ORDER BY\'    => \'a.rate \' . ($type == 1 ? \'ASC\' : \'DESC\'),
  215.     \'LIMIT\'       => 5,
  216.     \'PARAMS\'      => array(\'NO_PREFIX\' => 1)
  217. );
  218.  
  219. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  220.  
  221. if (!$forum_db->num_rows($result)) {
  222.     message($lang_common[\'Bad request\']);
  223. } else {
  224.     define(\'FORUM_PAGE\', \'toprated\');
  225.     require FORUM_ROOT.\'header.php\';
  226.    
  227.     // START SUBST - <!-- forum_main -->
  228.     ob_start();
  229.     ?>
  230.     <div class="admin-menu gen-content">
  231.         <ul>
  232.             <li class="<?php echo ($type == 0 ? \'active \' : \'\'); ?>first-item"><a href="?type=0&tab=<? echo $tab; ?>"><span><?php echo $lang_ajax_rating[\'Best\']; ?></span></a></li>
  233.             <li class="<?php echo ($type == 1 ? \'active \' : \'\'); ?>normal"><a href="?type=1&tab=<? echo $tab; ?>"><span><?php echo $lang_ajax_rating[\'Worst\']; ?></span></a></li>
  234.         </ul>
  235.     </div>
  236.     <div class="admin-submenu gen-content">
  237.         <ul>
  238.             <li class="<?php echo ($tab == 0 ? \'active \' : \'\'); ?>first-item"><a href="?type=<? echo $type; ?>&tab=0"><span><?php echo $lang_ajax_rating[\'Last day\']; ?></span></a></li>
  239.             <li class="<?php echo ($tab == 1 ? \'active \' : \'\'); ?>normal"><a href="?type=<? echo $type; ?>&tab=1"><span><?php echo $lang_ajax_rating[\'Last week\']; ?></span></a></li>
  240.             <li class="<?php echo ($tab == 2 ? \'active \' : \'\'); ?>normal"><a href="?type=<? echo $type; ?>&tab=2"><span><?php echo $lang_ajax_rating[\'Last month\']; ?></span></a></li>
  241.         </ul>
  242.     </div>
  243.     <div class="main-content main-topic" id="forum1">
  244.         <?php
  245.             while ($cur_post = $forum_db->fetch_assoc($result)) {
  246.                 ++$forum_page[\'item_count\'];
  247.                 $forum_page[\'post_ident\'] = array();
  248.                 $forum_page[\'author_ident\'] = array();
  249.                 $forum_page[\'author_info\'] = array();
  250.                 $forum_page[\'post_options\'] = array();
  251.                 $forum_page[\'post_contacts\'] = array();
  252.                 $forum_page[\'post_actions\'] = array();
  253.                 $forum_page[\'message\'] = array();
  254.  
  255.                 // Generate the post heading
  256.                 $forum_page[\'post_ident\'][\'num\'] = \'<span class="post-num">\'.forum_number_format($forum_page[\'start_from\'] + $forum_page[\'item_count\']).\'</span>\';
  257.  
  258.                 if ($cur_post[\'poster_id\'] > 1)
  259.                     $forum_page[\'post_ident\'][\'byline\'] = \'<span class="post-byline">\'.sprintf((($cur_post[\'id\'] == $cur_topic[\'first_post_id\']) ? $lang_topic[\'Topic byline\'] : $lang_topic[\'Reply byline\']), (($forum_user[\'g_view_users\'] == \'1\') ? \'<a title="\'.sprintf($lang_topic[\'Go to profile\'], forum_htmlencode($cur_post[\'username\'])).\'" href="\'.forum_link($forum_url[\'user\'], $cur_post[\'poster_id\']).\'">\'.forum_htmlencode($cur_post[\'username\']).\'</a>\' : \'<strong>\'.forum_htmlencode($cur_post[\'username\']).\'</strong>\')).\'</span>\';
  260.                 else
  261.                     $forum_page[\'post_ident\'][\'byline\'] = \'<span class="post-byline">\'.sprintf((($cur_post[\'id\'] == $cur_topic[\'first_post_id\']) ? $lang_topic[\'Topic byline\'] : $lang_topic[\'Reply byline\']), \'<strong>\'.forum_htmlencode($cur_post[\'username\']).\'</strong>\').\'</span>\';
  262.  
  263.                 $forum_page[\'post_ident\'][\'link\'] = \'<span class="post-link"><a class="permalink" href="\'.forum_link($forum_url[\'topic\'], $cur_post[\'topic_id\']).\'"><b>\'. $cur_post[\'topicsubj\'] .\'</b></a> - <a class="permalink" rel="bookmark" title="\'.$lang_topic[\'Permalink post\'].\'" href="\'.forum_link($forum_url[\'post\'], $cur_post[\'id\']).\'">\'.format_time($cur_post[\'posted\']).\'</a></span>\';
  264.  
  265.                 ($hook = get_hook(\'vt_row_pre_post_ident_merge\')) ? eval($hook) : null;
  266.  
  267.                 if (isset($user_data_cache[$cur_post[\'poster_id\']][\'author_ident\']))
  268.                     $forum_page[\'author_ident\'] = $user_data_cache[$cur_post[\'poster_id\']][\'author_ident\'];
  269.                 else
  270.                 {
  271.                     // Generate author identification
  272.                     if ($cur_post[\'poster_id\'] > 1)
  273.                     {
  274.                         if ($forum_config[\'o_avatars\'] == \'1\' && $forum_user[\'show_avatars\'] != \'0\')
  275.                         {
  276.                             $forum_page[\'avatar_markup\'] = generate_avatar_markup($cur_post[\'poster_id\'], $cur_post[\'avatar\'], $cur_post[\'avatar_width\'], $cur_post[\'avatar_height\'], $cur_post[\'poster\']);
  277.  
  278.                             if (!empty($forum_page[\'avatar_markup\']))
  279.                                 $forum_page[\'author_ident\'][\'avatar\'] = \'<li class="useravatar">\'.$forum_page[\'avatar_markup\'].\'</li>\';
  280.                         }
  281.  
  282.                         $forum_page[\'author_ident\'][\'username\'] = \'<li class="username">\'.(($forum_user[\'g_view_users\'] == \'1\') ? \'<a title="\'.sprintf($lang_topic[\'Go to profile\'], forum_htmlencode($cur_post[\'username\'])).\'" href="\'.forum_link($forum_url[\'user\'], $cur_post[\'poster_id\']).\'">\'.forum_htmlencode($cur_post[\'username\']).\'</a>\' : \'<strong>\'.forum_htmlencode($cur_post[\'username\']).\'</strong>\').\'</li>\';
  283.                         $forum_page[\'author_ident\'][\'usertitle\'] = \'<li class="usertitle"><span>\'.get_title($cur_post).\'</span></li>\';
  284.  
  285.                         if ($cur_post[\'is_online\'] == $cur_post[\'poster_id\'])
  286.                             $forum_page[\'author_ident\'][\'status\'] = \'<li class="userstatus"><span>\'.$lang_topic[\'Online\'].\'</span></li>\';
  287.                         else
  288.                             $forum_page[\'author_ident\'][\'status\'] = \'<li class="userstatus"><span>\'.$lang_topic[\'Offline\'].\'</span></li>\';
  289.                     }
  290.                     else
  291.                     {
  292.                         $forum_page[\'author_ident\'][\'username\'] = \'<li class="username"><strong>\'.forum_htmlencode($cur_post[\'username\']).\'</strong></li>\';
  293.                         $forum_page[\'author_ident\'][\'usertitle\'] = \'<li class="usertitle"><span>\'.get_title($cur_post).\'</span></li>\';
  294.                     }
  295.                 }
  296.  
  297.                 if (isset($user_data_cache[$cur_post[\'poster_id\']][\'author_info\']))
  298.                     $forum_page[\'author_info\'] = $user_data_cache[$cur_post[\'poster_id\']][\'author_info\'];
  299.                 else
  300.                 {
  301.                     // Generate author information
  302.                     if ($cur_post[\'poster_id\'] > 1)
  303.                     {
  304.                         if ($forum_config[\'o_show_user_info\'] == \'1\')
  305.                         {
  306.                             if ($cur_post[\'location\'] != \'\')
  307.                             {
  308.                                 if ($forum_config[\'o_censoring\'] == \'1\')
  309.                                     $cur_post[\'location\'] = censor_words($cur_post[\'location\']);
  310.  
  311.                                 $forum_page[\'author_info\'][\'from\'] = \'<li><span>\'.$lang_topic[\'From\'].\' <strong>\'.forum_htmlencode($cur_post[\'location\']).\'</strong></span></li>\';
  312.                             }
  313.  
  314.                             $forum_page[\'author_info\'][\'registered\'] = \'<li><span>\'.$lang_topic[\'Registered\'].\' <strong>\'.format_time($cur_post[\'registered\'], 1).\'</strong></span></li>\';
  315.  
  316.                             if ($forum_config[\'o_show_post_count\'] == \'1\' || $forum_user[\'is_admmod\'])
  317.                                 $forum_page[\'author_info\'][\'posts\'] = \'<li><span>\'.$lang_topic[\'Posts info\'].\' <strong>\'.forum_number_format($cur_post[\'num_posts\']).\'</strong></span></li>\';
  318.                         }
  319.  
  320.                         if ($forum_user[\'is_admmod\'])
  321.                         {
  322.                             if ($cur_post[\'admin_note\'] != \'\')
  323.                                 $forum_page[\'author_info\'][\'note\'] = \'<li><span>\'.$lang_topic[\'Note\'].\' <strong>\'.forum_htmlencode($cur_post[\'admin_note\']).\'</strong></span></li>\';
  324.                         }
  325.                     }
  326.                 }
  327.  
  328.                 // Generate IP information for moderators/administrators
  329.                 if ($forum_user[\'is_admmod\'])
  330.                     $forum_page[\'author_info\'][\'ip\'] = \'<li><span>\'.$lang_topic[\'IP\'].\' <a href="\'.forum_link($forum_url[\'get_host\'], $cur_post[\'id\']).\'">\'.$cur_post[\'poster_ip\'].\'</a></span></li>\';
  331.  
  332.                 // Generate author contact details
  333.                 if ($forum_config[\'o_show_user_info\'] == \'1\')
  334.                 {
  335.                     if (isset($user_data_cache[$cur_post[\'poster_id\']][\'post_contacts\']))
  336.                         $forum_page[\'post_contacts\'] = $user_data_cache[$cur_post[\'poster_id\']][\'post_contacts\'];
  337.                     else
  338.                     {
  339.                         if ($cur_post[\'poster_id\'] > 1)
  340.                         {
  341.                             if ($cur_post[\'url\'] != \'\')
  342.                                 $forum_page[\'post_contacts\'][\'url\'] = \'<span class="user-url\'.(empty($forum_page[\'post_contacts\']) ? \' first-item\' : \'\').\'"><a class="external" href="\'.forum_htmlencode(($forum_config[\'o_censoring\'] == \'1\') ? censor_words($cur_post[\'url\']) : $cur_post[\'url\']).\'">\'.sprintf($lang_topic[\'Visit website\'], \'<span>\'.sprintf($lang_topic[\'User possessive\'], forum_htmlencode($cur_post[\'username\'])).\'</span>\').\'</a></span>\';
  343.                             if ((($cur_post[\'email_setting\'] == \'0\' && !$forum_user[\'is_guest\']) || $forum_user[\'is_admmod\']) && $forum_user[\'g_send_email\'] == \'1\')
  344.                                 $forum_page[\'post_contacts\'][\'email\'] = \'<span class="user-email\'.(empty($forum_page[\'post_contacts\']) ? \' first-item\' : \'\').\'"><a href="mailto:\'.forum_htmlencode($cur_post[\'email\']).\'">\'.$lang_topic[\'E-mail\'].\'<span>&#160;\'.forum_htmlencode($cur_post[\'username\']).\'</span></a></span>\';
  345.                             else if ($cur_post[\'email_setting\'] == \'1\' && !$forum_user[\'is_guest\'] && $forum_user[\'g_send_email\'] == \'1\')
  346.                                 $forum_page[\'post_contacts\'][\'email\'] = \'<span class="user-email\'.(empty($forum_page[\'post_contacts\']) ? \' first-item\' : \'\').\'"><a href="\'.forum_link($forum_url[\'email\'], $cur_post[\'poster_id\']).\'">\'.$lang_topic[\'E-mail\'].\'<span>&#160;\'.forum_htmlencode($cur_post[\'username\']).\'</span></a></span>\';
  347.                         }
  348.                         else
  349.                         {
  350.                             if ($cur_post[\'poster_email\'] != \'\' && !$forum_user[\'is_guest\'] && $forum_user[\'g_send_email\'] == \'1\')
  351.                                 $forum_page[\'post_contacts\'][\'email\'] = \'<span class="user-email\'.(empty($forum_page[\'post_contacts\']) ? \' first-item\' : \'\').\'"><a href="mailto:\'.forum_htmlencode($cur_post[\'poster_email\']).\'">\'.$lang_topic[\'E-mail\'].\'<span>&#160;\'.forum_htmlencode($cur_post[\'username\']).\'</span></a></span>\';
  352.                         }
  353.                     }
  354.  
  355.                     ($hook = get_hook(\'vt_row_pre_post_contacts_merge\')) ? eval($hook) : null;
  356.  
  357.                     if (!empty($forum_page[\'post_contacts\']))
  358.                         $forum_page[\'post_options\'][\'contacts\'] = \'<p class="post-contacts">\'.implode(\' \', $forum_page[\'post_contacts\']).\'</p>\';
  359.                 }
  360.  
  361.                 // Generate the post options links
  362.                 if (!$forum_user[\'is_guest\'])
  363.                 {
  364.                     $forum_page[\'post_actions\'][\'report\'] = \'<span class="report-post\'.(empty($forum_page[\'post_actions\']) ? \' first-item\' : \'\').\'"><a href="\'.forum_link($forum_url[\'report\'], $cur_post[\'id\']).\'">\'.$lang_topic[\'Report\'].\'<span> \'.$lang_topic[\'Post\'].\' \'.forum_number_format($forum_page[\'start_from\'] + $forum_page[\'item_count\']).\'</span></a></span>\';
  365.  
  366.                     if (!$forum_page[\'is_admmod\'])
  367.                     {
  368.                         if ($cur_topic[\'closed\'] == \'0\')
  369.                         {
  370.                             if ($cur_post[\'poster_id\'] == $forum_user[\'id\'])
  371.                             {
  372.                                 if (($forum_page[\'start_from\'] + $forum_page[\'item_count\']) == 1 && $forum_user[\'g_delete_topics\'] == \'1\')
  373.                                     $forum_page[\'post_actions\'][\'delete\'] = \'<span class="delete-topic\'.(empty($forum_page[\'post_actions\']) ? \' first-item\' : \'\').\'"><a href="\'.forum_link($forum_url[\'delete\'], $cur_topic[\'first_post_id\']).\'">\'.$lang_topic[\'Delete topic\'].\'</a></span>\';
  374.                                 if (($forum_page[\'start_from\'] + $forum_page[\'item_count\']) > 1 && $forum_user[\'g_delete_posts\'] == \'1\')
  375.                                     $forum_page[\'post_actions\'][\'delete\'] = \'<span class="delete-post\'.(empty($forum_page[\'post_actions\']) ? \' first-item\' : \'\').\'"><a href="\'.forum_link($forum_url[\'delete\'], $cur_post[\'id\']).\'">\'.$lang_topic[\'Delete\'].\'<span> \'.$lang_topic[\'Post\'].\' \'.forum_number_format($forum_page[\'start_from\'] + $forum_page[\'item_count\']).\'</span></a></span>\';
  376.                                 if ($forum_user[\'g_edit_posts\'] == \'1\')
  377.                                     $forum_page[\'post_actions\'][\'edit\'] = \'<span class="edit-post\'.(empty($forum_page[\'post_actions\']) ? \' first-item\' : \'\').\'"><a href="\'.forum_link($forum_url[\'edit\'], $cur_post[\'id\']).\'">\'.$lang_topic[\'Edit\'].\'<span> \'.$lang_topic[\'Post\'].\' \'.forum_number_format($forum_page[\'start_from\'] + $forum_page[\'item_count\']).\'</span></a></span>\';
  378.                             }
  379.  
  380.                             if (($cur_topic[\'post_replies\'] == \'\' && $forum_user[\'g_post_replies\'] == \'1\') || $cur_topic[\'post_replies\'] == \'1\')
  381.                                 $forum_page[\'post_actions\'][\'quote\'] = \'<span class="quote-post\'.(empty($forum_page[\'post_actions\']) ? \' first-item\' : \'\').\'"><a href="\'.forum_link($forum_url[\'quote\'], array($id, $cur_post[\'id\'])).\'">\'.$lang_topic[\'Quote\'].\'<span> \'.$lang_topic[\'Post\'].\' \'.forum_number_format($forum_page[\'start_from\'] + $forum_page[\'item_count\']).\'</span></a></span>\';
  382.                         }
  383.                     }
  384.                     else
  385.                     {
  386.                         if (($forum_page[\'start_from\'] + $forum_page[\'item_count\']) == 1)
  387.                             $forum_page[\'post_actions\'][\'delete\'] = \'<span class="delete-topic\'.(empty($forum_page[\'post_actions\']) ? \' first-item\' : \'\').\'"><a href="\'.forum_link($forum_url[\'delete\'], $cur_topic[\'first_post_id\']).\'">\'.$lang_topic[\'Delete topic\'].\'</a></span>\';
  388.                         else
  389.                             $forum_page[\'post_actions\'][\'delete\'] = \'<span class="delete-post\'.(empty($forum_page[\'post_actions\']) ? \' first-item\' : \'\').\'"><a href="\'.forum_link($forum_url[\'delete\'], $cur_post[\'id\']).\'">\'.$lang_topic[\'Delete\'].\'<span> \'.$lang_topic[\'Post\'].\' \'.forum_number_format($forum_page[\'start_from\'] + $forum_page[\'item_count\']).\'</span></a></span>\';
  390.  
  391.                         $forum_page[\'post_actions\'][\'edit\'] = \'<span class="edit-post\'.(empty($forum_page[\'post_actions\']) ? \' first-item\' : \'\').\'"><a href="\'.forum_link($forum_url[\'edit\'], $cur_post[\'id\']).\'">\'.$lang_topic[\'Edit\'].\'<span> \'.$lang_topic[\'Post\'].\' \'.forum_number_format($forum_page[\'start_from\'] + $forum_page[\'item_count\']).\'</span></a></span>\';
  392.                         $forum_page[\'post_actions\'][\'quote\'] = \'<span class="quote-post\'.(empty($forum_page[\'post_actions\']) ? \' first-item\' : \'\').\'"><a href="\'.forum_link($forum_url[\'quote\'], array($id, $cur_post[\'id\'])).\'">\'.$lang_topic[\'Quote\'].\'<span> \'.$lang_topic[\'Post\'].\' \'.forum_number_format($forum_page[\'start_from\'] + $forum_page[\'item_count\']).\'</span></a></span>\';
  393.                     }
  394.                 }
  395.                 else
  396.                 {
  397.                     if ($cur_topic[\'closed\'] == \'0\')
  398.                     {
  399.                         if (($cur_topic[\'post_replies\'] == \'\' && $forum_user[\'g_post_replies\'] == \'1\') || $cur_topic[\'post_replies\'] == \'1\')
  400.                             $forum_page[\'post_actions\'][\'quote\'] = \'<span class="report-post\'.(empty($forum_page[\'post_actions\']) ? \' first-item\' : \'\').\'"><a href="\'.forum_link($forum_url[\'quote\'], array($id, $cur_post[\'id\'])).\'">\'.$lang_topic[\'Quote\'].\'<span> \'.$lang_topic[\'Post\'].\' \'.forum_number_format($forum_page[\'start_from\'] + $forum_page[\'item_count\']).\'</span></a></span>\';
  401.                     }
  402.                 }
  403.  
  404.                 ($hook = get_hook(\'vt_row_pre_post_actions_merge\')) ? eval($hook) : null;
  405.  
  406.                 if (!empty($forum_page[\'post_actions\']))
  407.                     $forum_page[\'post_options\'][\'actions\'] = \'<p class="post-actions">\'.implode(\' \', $forum_page[\'post_actions\']).\'</p>\';
  408.  
  409.                 // Give the post some class
  410.                 $forum_page[\'item_status\'] = array(
  411.                     \'post\',
  412.                     ($forum_page[\'item_count\'] % 2 != 0) ? \'odd\' : \'even\'
  413.                 );
  414.  
  415.                 if ($forum_page[\'item_count\'] == 1)
  416.                     $forum_page[\'item_status\'][\'firstpost\'] = \'firstpost\';
  417.  
  418.                 if (($forum_page[\'start_from\'] + $forum_page[\'item_count\']) == $forum_page[\'finish_at\'])
  419.                     $forum_page[\'item_status\'][\'lastpost\'] = \'lastpost\';
  420.  
  421.                 if ($cur_post[\'id\'] == $cur_topic[\'first_post_id\'])
  422.                     $forum_page[\'item_status\'][\'topicpost\'] = \'topicpost\';
  423.                 else
  424.                     $forum_page[\'item_status\'][\'replypost\'] = \'replypost\';
  425.  
  426.  
  427.                 // Generate the post title
  428.                 if ($cur_post[\'id\'] == $cur_topic[\'first_post_id\'])
  429.                     $forum_page[\'item_subject\'] = sprintf($lang_topic[\'Topic title\'], $cur_topic[\'subject\']);
  430.                 else
  431.                     $forum_page[\'item_subject\'] = sprintf($lang_topic[\'Reply title\'], $cur_topic[\'subject\']);
  432.  
  433.                 $forum_page[\'item_subject\'] = forum_htmlencode($forum_page[\'item_subject\']);
  434.  
  435.                 // Perform the main parsing of the message (BBCode, smilies, censor words etc)
  436.                 $forum_page[\'message\'][\'message\'] = parse_message($cur_post[\'message\'], $cur_post[\'hide_smilies\']);
  437.  
  438.                 if ($cur_post[\'edited\'] != \'\')
  439.                     $forum_page[\'message\'][\'edited\'] = \'<p class="lastedit"><em>\'.sprintf($lang_topic[\'Last edited\'], forum_htmlencode($cur_post[\'edited_by\']), format_time($cur_post[\'edited\'])).\'</em></p>\';
  440.  
  441.                 // Do signature parsing/caching
  442.                 if ($cur_post[\'signature\'] != \'\' && $forum_user[\'show_sig\'] != \'0\' && $forum_config[\'o_signatures\'] == \'1\')
  443.                 {
  444.                     if (!isset($signature_cache[$cur_post[\'poster_id\']]))
  445.                         $signature_cache[$cur_post[\'poster_id\']] = parse_signature($cur_post[\'signature\']);
  446.  
  447.                     $forum_page[\'message\'][\'signature\'] = \'<div class="sig-content"><span class="sig-line"><!-- --></span>\'.$signature_cache[$cur_post[\'poster_id\']].\'</div>\';
  448.                 }
  449.                 ?>
  450.                 <div class="<?php echo implode(\' \', $forum_page[\'item_status\']) ?>">
  451.                     <div id="p<?php echo $cur_post[\'id\'] ?>" class="posthead">
  452.                         <h3 class="hn post-ident"><?php echo implode(\' \', $forum_page[\'post_ident\']) ?></h3>
  453.                     </div>
  454.                     <div class="postbody<?php echo ($cur_post[\'is_online\'] == $cur_post[\'poster_id\']) ? \' online\' : \'\' ?>">
  455.                         <div class="post-author">
  456.                             <ul class="author-ident">
  457.                                 <?php echo implode("\n\t\t\t\t\t\t", $forum_page[\'author_ident\'])."\n" ?>
  458.                             </ul>
  459.                             <ul class="author-info">
  460.                                 <?php echo implode("\n\t\t\t\t\t\t", $forum_page[\'author_info\'])."\n" ?>
  461.                             </ul>
  462.                         </div>
  463.                         <div class="post-entry">
  464.                             <h4 id="pc<?php echo $cur_post[\'id\'] ?>" class="entry-title hn"><?php echo $forum_page[\'item_subject\'] ?></h4>
  465.                             <div class="entry-content">
  466.                                 <?php echo implode("\n\t\t\t\t\t\t", $forum_page[\'message\'])."\n" ?>
  467.                             </div>
  468.                         </div>
  469.                     </div>
  470.                     <div class="postfoot">
  471.                         <div class="post-options">
  472.                             <?php
  473.                                 AR_getRating($cur_post[\'id\'], $forum_page[\'post_options\'], $forum_user[\'is_guest\']);
  474.                                 echo implode("\n\t\t\t\t\t", $forum_page[\'post_options\'])."\n";
  475.                             ?>
  476.                         </div>
  477.                     </div>
  478.                 </div>
  479.                 <?php
  480.             }
  481.         ?>
  482.     </div>
  483.     <?php
  484.     $tpl_temp = forum_trim(ob_get_contents());
  485.     $tpl_main = str_replace(\'<!-- forum_main -->\', $tpl_temp, $tpl_main);
  486.     ob_end_clean();
  487.     // END SUBST - <!-- forum_main -->
  488.    
  489.     require FORUM_ROOT.\'footer.php\';
  490. }
  491. ?>
  492.             ';
  493.            
  494.             $fp = fopen($toprated, 'w');
  495.             fwrite($fp, $tr_contents);
  496.             fclose($fp);
  497.         }
  498.     ]]></install>
  499.  
  500.     <uninstall><![CDATA[
  501.         $forum_db->drop_table('postrating');   
  502.         $forum_db->drop_table('postrating_det');
  503.        
  504.         $query_conf = array(
  505.             'DELETE'    => 'config',
  506.             'WHERE'     => 'conf_name="p_ajax_rating_type"'
  507.         );
  508.         $forum_db->query_build($query_conf);
  509.        
  510.         $query_conf = array(
  511.             'DELETE'    => 'config',
  512.             'WHERE'     => 'conf_name="p_ajax_rating_allow_multiple"'
  513.         );
  514.         $forum_db->query_build($query_conf);
  515.        
  516.         $query_conf = array(
  517.             'DELETE'    => 'config',
  518.             'WHERE'     => 'conf_name="p_ajax_rating_allow_guest"'
  519.         );
  520.         $forum_db->query_build($query_conf);
  521.        
  522.         $toprated = FORUM_ROOT . 'toprated.php';
  523.         if (is_file($toprated)) {
  524.             unlink($toprated);
  525.         }
  526.     ]]></uninstall>
  527.  
  528.     <hooks>
  529.         <hook id="hd_head"><![CDATA[
  530.             if (FORUM_PAGE == 'viewtopic' || FORUM_PAGE == 'toprated') {
  531.                 require_once FORUM_ROOT.'include/parser.php';
  532.                 $forum_head['style_ajax_rating'] = '<link rel="stylesheet" type="text/css" media="screen" href="'.$ext_info['url'].'/ajax_rating.css" />';
  533.                 $forum_head['prototypejs'] = '<script type="text/javascript" src="'.$ext_info['url'].'/js/prototype.js"></script>';
  534.                 $forum_head['js_ajax_rating'] = '<script type="text/javascript" src="'.$ext_info['url'].'/js/ajax_rating.js?baseUri='.$base_url.'/&amp;extUri='.$ext_info['url'].'"></script>';
  535.             }
  536.         ]]></hook>
  537.         <hook id="vt_start, mi_start"><![CDATA[
  538.             include_once $ext_info['path'].'/fns.php';
  539.         ]]></hook>
  540.         <hook id="vt_row_pre_display"><![CDATA[
  541.             AR_getRating($cur_post['id'], $forum_page['post_options'], $forum_user['is_guest']);
  542.         ]]></hook>
  543.         <hook id="mi_new_action"><![CDATA[
  544.             AR_processRequest($action);
  545.         ]]></hook>
  546.         <hook id="co_modify_url_scheme"><![CDATA[
  547.         // disable token validation for chat submit
  548.         if(preg_match('/(.*)\/misc.php\?action\=ajax_rating$/', get_current_url(), $m)) {
  549.             if (is_array($m)) {
  550.                 $_POST['csrf_token'] = generate_form_token($m[1].'/misc.php?action=ajax_rating');
  551.             } else {
  552.                 $_POST['csrf_token'] = generate_form_token($base_url.'/misc.php?action=ajax_rating');
  553.             }
  554.         }
  555.         ]]></hook>
  556.         <hook id="aop_features_pre_header_load"><![CDATA[
  557.             if (file_exists($ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php'))
  558.                 include_once $ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php';
  559.             else
  560.                 include_once $ext_info['path'].'/lang/English/'.$ext_info['id'].'.php';
  561.         ]]></hook>
  562.         <hook id="aop_features_validation"><![CDATA[
  563.             if (!isset($form['ajax_rating_type']) || $form['ajax_rating_type'] != '1') $form['ajax_rating_type'] = '0';
  564.             if (!isset($form['ajax_rating_allow_guest']) || $form['ajax_rating_allow_guest'] != '1') $form['ajax_rating_allow_guest'] = '0';
  565.             if (!isset($form['ajax_rating_allow_multiple']) || $form['ajax_rating_allow_multiple'] != '1') $form['ajax_rating_allow_multiple'] = '0';
  566.         ]]></hook>
  567.         <hook id="aop_features_avatars_fieldset_end"><![CDATA[
  568.             ?>
  569.                     <div class="content-head">
  570.                         <h2 class="hn"><span><?php echo $lang_ajax_rating['Settings header'] ?></span></h2>
  571.                     </div>                 
  572.                     <fieldset class="frm-group group1">
  573.             <?php
  574.                         if (defined('AR_DEBUG_MODE')) {
  575.             ?>
  576.                         <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
  577.                             <div class="sf-box checkbox">
  578.                                 <span class="fld-input">
  579.                                     <input id="fld<?php echo ++$forum_page['fld_count'] ?>" type="checkbox" name="form[ajax_rating_type]" value="1"<?php if ($forum_config['p_ajax_rating_type'] == '1') echo ' checked="checked"' ?>/>
  580.                                 </span>
  581.                                 <label for="fld<?php echo ++$forum_page['fld_count'] ?>">
  582.                                     <span><?php echo $lang_ajax_rating['Rating type'] ?></span>
  583.                                 </label>
  584.                             </div>
  585.                         </div>
  586.             <?php
  587.                         }
  588.             ?>
  589.                         <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
  590.                             <div class="sf-box checkbox">
  591.                                 <span class="fld-input">
  592.                                     <input id="fld<?php echo ++$forum_page['fld_count'] ?>" type="checkbox" name="form[ajax_rating_allow_multiple]" value="1"<?php if ($forum_config['p_ajax_rating_allow_multiple'] == '1') echo ' checked="checked"' ?>/>
  593.                                 </span>
  594.                                 <label for="fld<?php echo ++$forum_page['fld_count'] ?>">
  595.                                     <span><?php echo $lang_ajax_rating['Multiple rates'] ?></span>
  596.                                 </label>
  597.                             </div>
  598.                         </div>
  599.                         <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
  600.                             <div class="sf-box checkbox">
  601.                                 <span class="fld-input">
  602.                                     <input id="fld<?php echo ++$forum_page['fld_count'] ?>" type="checkbox" name="form[ajax_rating_allow_guest]" value="1"<?php if ($forum_config['p_ajax_rating_allow_guest'] == '1') echo ' checked="checked"' ?>/>
  603.                                 </span>
  604.                                 <label for="fld<?php echo ++$forum_page['fld_count'] ?>">
  605.                                     <span><?php echo $lang_ajax_rating['Allow guest'] ?></span>
  606.                                 </label>
  607.                             </div>
  608.                         </div>
  609.                     </fieldset>
  610.             <?php
  611.  
  612.         ]]></hook>
  613.         <hook id="fn_generate_navlinks_end"><![CDATA[
  614.             if (!$lang_ajax_rating) {
  615.                 if (file_exists($ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php'))
  616.                     include_once $ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php';
  617.                 else
  618.                     include_once $ext_info['path'].'/lang/English/'.$ext_info['id'].'.php';
  619.             }
  620.             $links['ajax_rating_toprated'] = '<li id="navtoprated"'.((FORUM_PAGE == 'toprated') ? ' class="isactive"' : '').'><a href="'.forum_link('toprated.php').'">'.$lang_ajax_rating['Post ratings'].'</a></li>';
  621.         ]]></hook>
  622.     </hooks>
  623. </extension>
Add Comment
Please, Sign In to add comment