Hallo, Gast! (Registrieren)

Wir wünschen allen Besuchern frohe Ostern!

Letzte Ankündigung: MyBB 1.8.37 veröffentlicht (04.11.23)


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste
Thumbs Post Rating
#1
Eine neue Erweiterung wurde veröffentlicht: Thumbs Post Rating

Zitat:Overview:
This plugin will add a thumbs up / thumbs down rating system on every individual posts. Just like the one on the YouTube comment.

Features:
- Non-obstructive AJAX (sends the rating and updates the result instantly without refreshing the page)
- Language file support
- Option to set which usergroup allowed to rate
- Option to set which forum to be excluded to have the post rating function
- Option to enable/disable self-rating
- Option to enable/disable undo rating
- Option to enable/disable rating in a closed thread
- Compatible with both normal and classic postbit

Installation:
1. Extract the files inside the "Upload" folder of Thumbs Post Rating zip package.
2. Upload all the files extracted to the root of your forum directory.
3. Login to ACP, go to Configuration > Plugins.
4. Click "Install & Activate" next to the Thumbs Post Rating.

Uninstallation:
1. Login to ACP, go to Configuration > Plugins.
2. Click "Uninstall" next to the Thumbs Post Rating.

Upgrading from previous version:
1. Login to ACP, go to Configuration > Plugins.
2. Click "Deactivate" next to the Thumbs Post Rating.
3. Extract the files inside the "Upload" folder of Thumbs Post Rating zip package.
4. Upload all the files extracted to the root of your forum directory.
5. If required, choose to replace any old files.
6. Back to ACP Plugins section, click "Activate" next to the Thumbs Post Rating.

Notes:
Version 1.3 fixed the bug that caused users with secondary usergroup unable to rate.

p/s: I'm still new to PHP and this is just my humble 2nd mod. Feedback at the MyBB community forum plugin section is very appreciated.
http://community.mybb.com/thread-84250.html
Zitieren
#2
Hallo Leute,

kann es sein, dass das Plugin nicht mit MyBB 1.6.5 komptibel ist? Das letzte Update erschien als er noch kein MyBB 1.6.5 gab, von der englischen Plugin-Seite kann man aber entnehmen, dass es mit MyBB 1.6 funktionieren soll. Im englischen Supportthread hab ich auch noch niemanden mit dem selben Fehler gesehen und so richtig supportet wird das Plugin dort scheinbar nicht mehr.

Ich hab versucht das Plugin zu installieren, bekomme aber folgende Fehlermeldung:

Zitat:MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TYPE = MYISAM' at line 8

Query:
CREATE TABLE IF NOT EXISTS mybb_thumbspostrating ( id INT UNSIGNED NOT NULL AUTO_INCREMENT , pid INT NOT NULL , uid INT NOT NULL , thumbsup INT NOT NULL , thumbsdown INT NOT NULL , PRIMARY KEY ( id ) ) TYPE = MYISAM ;

Ich hab keine Ahnung was das bedeutet, aber der Fehler taucht auch bei einer frisch aufgesetzten MyBB 1.6.5 Installation auf. Könnte jemand bestätigen, dass das Plugin nicht mit MyBB 1.6.5 funktioniert?

Gruß

EDIT: Ich habs mittlerweile auch mit einer frischen MyBB 1.6.4 Installation probiert, bekomme hier jedoch auch die selbe Fehlermeldung. Wie kann es denn sein, dass sonst niemand diese Fehlermeldung bekommen hat? Ich habs sowohl im Localhost als auch auf ein Webspace getestet.

EDIT2: Problem gelöst. Ich hab mir angesehen, wie andere Plugins geschrieben wurden und hab dann auf gut Glück in der Plugin-PHP-Datei "TYPE=MyISAM" in "ENGINE=MyISAM" geändert und schon lief es wie geschmiert. Könnte mir vielleicht noch jemand verraten, was es damit aufisich hatte? Wieso hat es mit TYPE bei allen außer mir funktioniert?
Zitieren
#3
(05.02.2012, 00:48)mattias schrieb: Wieso hat es mit TYPE bei allen außer mir funktioniert?
Weil du wohl eine neuere MySQL-Version hast...
[Bild: banner.png]

Bitte die Foren-Regeln beachten und im Profil die verwendete MyBB-Version angeben.
Zitieren
#4
Ah, daran liegst also. Dann schätze ich mal wurde das Plugin zu der Zeit geschrieben, als es noch keine MySQL-Version, die nur ENGINE unterstützt gab und der Autor einfach vergessen hat, das Plugin upzudaten oder mit einem entspechenden Hinweis zu versehen. Ich danke dir Smile
Zitieren
#5
Und schon das nächste Problem.

Standardmäßig sieht die Box ja so aus:

Zahl ThumpsUp ThumpsDown Zahl

Der HTML-Code sieht so aus:
PHP-Code:
<table class="tpr_box" id="tpr_stat_$pid">
    <
tr>
        <
td class="tu_stat" id="tu_stat_$pid">$tu_no</td>
        <
td>$tu_img</td>
        <
td>$td_img</td>
        <
td class="td_stat" id="td_stat_$pid">$td_no</td>
    </
tr>
    <
tr>
        <
td class="small" colspan="4" >
            <
span id="tpr_remove_$pid">$box_remove</span>
            
$box_view
        
</td>
    </
tr>
</
table

Nun wollte ich aber das ganze etwas anders anordnen, und zwar so:

ThumpsUp Zahl ThumpsDown Zahl

Ich hab den HTML-Code so geändert:
PHP-Code:
<table class="tpr_box" id="tpr_stat_$pid">
    <
tr>
        <
td>$tu_img</td>
        <
td class="tu_stat" id="tu_stat_$pid">$tu_no</td>
        <
td>$td_img</td>
        <
td class="td_stat" id="td_stat_$pid">$td_no</td>
    </
tr>
    <
tr>
        <
td class="small" colspan="4" >
            <
span id="tpr_remove_$pid">$box_remove</span>
            
$box_view
        
</td>
    </
tr>
</
table

Und das auch auf den erstem Blick prima funktioniert. Nun taucht aber folgendes Problem auf:

Vergebe ich ein Like oder Dislike, ändert sich die Anordnung wieder zu der alten:

Zahl ThumpsUp ThumpsDown Zahl

Allerdings nur bis man die Seite neu lädt, dann sieht die Anordung wieder wie gewünscht aus.

Ich habe vergeblich versucht, dem ganzen auf die Spur zu kommen, haben viel mit der php und der Javascript-Datei rumprobiert, aber es hat nichts genützt.

Könnte mir vielleicht jemand sagen, wie man das Problem fixt? Ich hab mal den Inhalt der php Datei und der Javascript-Datei gepostet:

PHP-Code:
<?php
/**
 *  Plugin  : Thumbs Post Rating
 *  Author  : TY Yew
 *  Version : 1.3
 *  Website : http://tyyew.com/mybb
 *  Contact : mybb@tyyew.com
 *
 *  This file is part of Thumbs Post Rating plugin for MyBB.
 *
 *  Thumbs Post Rating plugin for MyBB is free software; you can
 *  redistribute it and/or modify it under the terms of the GNU General
 *  Public License as published by the Free Software Foundation; either
 *  version 3 of the License, or (at your option) any later version.
 *
 *  Thumbs Post Rating plugin for MyBB is distributed in the hope that it
 *  will be useful, but WITHOUT ANY WARRANTY; without even the implied
 *  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
 *  the GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http:www.gnu.org/licenses/>.
 */

// No direct initiation
if( !defined('IN_MYBB') )
{
    die(
'Direct initialization of this file is not allowed.');
}

// Add hooks
$plugins->add_hook('global_start','tpr_global');
$plugins->add_hook('postbit','tpr_box');
$plugins->add_hook('xmlhttp','tpr_action');
$plugins->add_hook('class_moderation_delete_post','tpr_deletepost');
$plugins->add_hook('class_moderation_delete_thread_start','tpr_deletethread');
$plugins->add_hook('class_moderation_delete_thread','tpr_deletethread2');

// Plugin information
function thumbspostrating_info()
{
    global 
$lang;
    
$lang->load('thumbspostrating');

    return array(
        
'name' => $lang->tpr_info_name,
        
'description' => $lang->tpr_info_desc,
        
'website' => 'http://community.mybb.com/thread-84250.html',
        
'author' => 'TY Yew',
        
'authorsite' => 'http://community.mybb.com/user-30826.html',
        
'version' => '1.3',
        
'guid' => '21de27b859c0095ec17f86f561fa3737',
        
'compatibility' => '14*,15*,16*'
    
);
}

// Install function
function thumbspostrating_install()
{
    global 
$db;

    @
ignore_user_abort(true);
    @
set_time_limit(600);
    
$db->write_query('ALTER TABLE '.TABLE_PREFIX.'posts ADD `thumbsup` INT UNSIGNED NOT NULL DEFAULT 0, ADD `thumbsdown` INT UNSIGNED NOT NULL DEFAULT 0'true);
    
$db->write_query('CREATE TABLE IF NOT EXISTS '.TABLE_PREFIX.'thumbspostrating (
        id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
        pid INT NOT NULL ,
        uid INT NOT NULL ,
        thumbsup INT NOT NULL ,
        thumbsdown INT NOT NULL ,
        PRIMARY KEY ( id )
        ) ENGINE=MyISAM'
    
);
}

// Activate function
function thumbspostrating_activate()
{
    global 
$db$lang;
    
$lang->load('thumbspostrating');

    require 
MYBB_ROOT.'/inc/adminfunctions_templates.php';

    
find_replace_templatesets('postbit','#'.preg_quote('<div class="post_body" id="pid_{$post[\'pid\']}">').'#','<div class="float_right">{$post[\'tprdsp\']}</div><div class="post_body" id="pid_{$post[\'pid\']}">');
    
find_replace_templatesets('postbit_classic','#'.preg_quote('{$post[\'message\']}').'#','<div class="float_right">{$post[\'tprdsp\']}</div>{$post[\'message\']}');

    
$tpr_setting_group_1 = array(
        
'name' => 'tpr_group',
        
'title' => $db->escape_string($lang->tpr_set_group_1_title),
        
'description' => $db->escape_string($lang->tpr_set_group_1_desc),
        
'disporder' => '38',
        
'isdefault' => 'no'
    
);
    
$db->insert_query('settinggroups',$tpr_setting_group_1);
    
$gid $db->insert_id();

    
$disporder 0;
    foreach(array(
        
'usergroups' => array('text''2,3,4,6'),
        
'forums' => array('text''0'),
        
'selfrate'  => array('yesno'1),
        
'undorate' => array('yesno'1),
        
'closerate' => array('yesno'1),
    ) as 
$name => $opts)
    {
        
$lang_title 'tpr_set_'.$name.'_title';
        
$lang_desc 'tpr_set_'.$name.'_desc';
        
$db->insert_query('settings', array(
            
'name' => 'tpr_'.$name,
            
'title' => $db->escape_string($lang->$lang_title),
            
'description' => $db->escape_string($lang->$lang_desc),
            
'optionscode' => $opts[0],
            
'value' => $db->escape_string($opts[1]),
            
'disporder' => ++$disporder,
            
'gid' => $gid,
        ));
    }

    
rebuild_settings();
}

// Deactivate function
function thumbspostrating_deactivate()
{
    global 
$db;

    
$gid $db->fetch_field($db->simple_select('settinggroups','gid','name="tpr_group"'),'gid');
    if(
$gid)
    {
        
$db->delete_query('settings','gid='.$gid);
        
$db->delete_query('settinggroups','gid='.$gid);
    }
    
rebuild_settings();

    require 
MYBB_ROOT.'/inc/adminfunctions_templates.php';
    
find_replace_templatesets('postbit','#'.preg_quote('<div class="float_right">{$post[\'tprdsp\']}</div>').'#','');
    
find_replace_templatesets('postbit_classic','#'.preg_quote('<div class="float_right">{$post[\'tprdsp\']}</div>').'#','');    
}

// Is Installed function
function thumbspostrating_is_installed()
{
    global 
$db;

    if(
$db->table_exists('thumbspostrating'))
    {
        return 
true;
    }
    return 
false;
}

// Uninstall function
function thumbspostrating_uninstall()
{
    global 
$db;

    @
ignore_user_abort(true);
    @
set_time_limit(600);
    
$db->write_query('ALTER TABLE '.TABLE_PREFIX.'posts DROP thumbsup, DROP thumbsdown'true);
    
$db->write_query('DROP TABLE IF EXISTS '.TABLE_PREFIX.'thumbspostrating');
}

// Function - Load TPR template and style only in showthread.php
function tpr_global()
{
    if(
$GLOBALS['current_page'] != 'showthread.php') return;
    
$GLOBALS['templatelist'] .= ',postbit_tpr';
}

// Function - Forum exclusion
function tpr_forum($fidcheck)
{
    global 
$mybb;
    
    
$fidset =& $mybb->settings['tpr_forums'];
    if(
$fidset != 0)
    {
        foreach(
array_map('trim'explode(',',$fidset)) as $fid)
        {
            if( 
$fid == $fidcheck )
            {
                return 
false;
            }
        }
    }
    return 
true;
}

// Function - Usergroup checking
function grpchk($setting)
{
    global 
$mybb;
    
$user $mybb->user;

    
$set array_map('trim',explode(',',$mybb->settings['tpr_'.$setting]));

    if(
$set != 0)
    {
        foreach(
$set as $grp)
        {
            if(
$grp == $user['usergroup'])
            {
                
$result true;
            }
        }
    }

    if(
$user['additionalgroups'])
    {
        
$addgrp array_map('trim',explode(',',$user['additionalgroups']));
        
$com array_intersect($addgrp$set);
        if (!empty(
$com))
        {
            
$result true;
        }
    }    

    if(
$result != true) return false;

    return 
true;
}

// Function - Check whether user can rate (Usergroup, Self rating, Closed thread)
function tpr_canrate($postuid)
{
    global 
$mybb;

    
$user =& $mybb->user;

    
// Guests
    
if(!$user['uid']) return false;

    
// Usergroup permission
    
if(!grpchk('usergroups')) return false;

    
// Self-rating
    
if($postuid == $user['uid'] && $mybb->settings['tpr_selfrate'] == 1) return false;

    
// Rate close thread
    
if($GLOBALS['thread']['closed'] && $mybb->settings['tpr_closerate'] != 1) return false;

    return 
true;
}

// Function - Display ratebox
function tpr_box(&$post)
{
    global 
$db$mybb$templates$lang$current_page$box_view$tprdsp;

    
$pid = (int) $post['pid'];
    
$postuid = (int) $post['uid'];
    
$uid $mybb->user['uid'];
    
$user $mybb->user;
    
$fid $post['fid'];
    if(!
$pid) return;

    
// Remove hook if forum is excluded from TPR
    
if(!tpr_forum($post['fid']))
    {
        global 
$plugins;
        
$plugins->remove_hook('postbit''tpr_box');
        return;
    }

    
// Stick in JS and CSS
    
$GLOBALS['headerinclude'] .= '<script type="text/javascript" src="'.$mybb->settings['bburl'].'/jscripts/thumbspostrating.js?ver=1600"></script><link type="text/css" rel="stylesheet" href="'.$mybb->settings['bburl'].'/css/thumbspostrating.css" />';

    
// Build user rating cache
    
static $done_init false;
    static 
$user_ru null;
    static 
$user_rd null;
    if(!
$done_init)
    {
        
$done_init true;
        
        
$user_ru = array();
        
$user_rd = array();
        
        if(
$current_page == 'showthread.php')
        {
            
$lang->load('thumbspostrating');
            
            
// If user is not guest, check for user ratings
            
if($mybb->user['uid'])
            {
                
                if(
$mybb->input['mode'] == 'threaded')
                {
                    
$query $db->simple_select('thumbspostrating''pid,thumbsup,thumbsdown''uid='.$mybb->user['uid'].' AND pid='.(int)$mybb->input['pid']);
                }
                else
                {
                    
$query $db->simple_select('thumbspostrating''pid,thumbsup,thumbsdown''uid='.$mybb->user['uid'].' AND '.$GLOBALS['pids']);
                }
            
                while(
$ttrate $db->fetch_array($query))
                {
                    
$user_ru[$ttrate['pid']] = $ttrate['thumbsup'];
                    
$user_rd[$ttrate['pid']] = $ttrate['thumbsdown'];
                }

                
$db->free_result($query);
            }
        }
    }

    
// If user already rated...
    
if ($user_ru[$pid] == xor $user_rd[$pid] == 1)
    {
        
$userrated[$pid] = true;
        
// Make thumbs for user who rated up
        
if ($user_ru[$pid] == 1)
        {
            
$tu_img '<div class="tpr_thumb tu1"></div>';
            
$td_img '<div class="tpr_thumb td0"></div>';
        }
        
// Make thumbs for user who rated down
        
else
        {
            
$tu_img '<div class="tpr_thumb tu0"></div>';
            
$td_img '<div class="tpr_thumb td1"></div>';
        }
    }
    else
    {
        
$userrated[$pid] = false;
    }

    
// Check whether the user can rate
    
if (!tpr_canrate($postuid))
    {
        
$cantrate true;
    }

    
$tu_url $mybb->settings['bburl'].'/xmlhttp.php?action=tpr&amp;my_post_key='.$mybb->post_code.'&amp;pid='.$pid.'&amp;tu=1&amp;td=0';
    
$td_url $mybb->settings['bburl'].'/xmlhttp.php?action=tpr&amp;my_post_key='.$mybb->post_code.'&amp;pid='.$pid.'&amp;tu=0&amp;td=1';
    
$un_url $mybb->settings['bburl'].'/xmlhttp.php?action=tpr&amp;my_post_key='.$mybb->post_code.'&amp;pid='.$pid.'&amp;tu=0&amp;td=0';

    
// If user have not yet rated (correctly)...
    
if ($userrated[$pid] != true)
    {
        
// Fail-safe (force user who incorectly rated to be unable to rate)
        
if (isset($user_ru[$pid]) || isset($user_rd[$pid]))
        {
            if (
$user_ru[$pid] != xor $user_rd[$pid] != 1)
            {
                return;
            }
            else
            {
                
$cantrate true;
            }
        }

        
// Make thumbs for user who cannot rate
        
if ($cantrate == true)
        {
            
$tu_img '<div class="tpr_thumb tu0"></div>';
            
$td_img '<div class="tpr_thumb td0"></div>';
        }
        
// Make thumbs for user who can rate
        
else
        {
            
$tu_img '<a href='.$tu_url.' class="tpr_thumb tu2" title="'.$lang->tpr_rate_up.'" onclick="return thumbRate(1,0,'.$pid.')" ></a>';
            
$td_img '<a href='.$td_url.' class="tpr_thumb td2" title="'.$lang->tpr_rate_down.'" onclick="return thumbRate(0,1,'.$pid.')" ></a>';
            
            
// Respect MyBB's wish to disable xmlhttp
            
if($mybb->settings['use_xmlhttprequest'] == 0)
            {
                
$tu_img str_replace('onclick="return thumbRate''rel="'$tu_img);
                
$td_img str_replace('onclick="return thumbRate''rel="'$td_img);
            }
        }
    }

    
// Display number of thumbs
    
$tu_no $post['thumbsup'];
    
$td_no $post['thumbsdown'];

    
// Display undo rating?
    
if($mybb->settings['tpr_undorate'] == && $userrated[$pid] == true && !$cantrate)
    {
        
$box_remove '<a href='.$un_url.' onclick="return thumbRate(0,0,'.$pid.')" >'.$lang->tpr_undo_rate.'</a><br />';

        
// Respect MyBB's wish to disable xmlhttp
        
if($mybb->settings['use_xmlhttprequest'] == 0)
        {
            
$box_remove str_replace('onclick="return thumbRate''rel="'$box_remove);
        }
    }

    
// Make the box
    
$box = <<<BOX
<table class="tpr_box" id="tpr_stat_$pid">
    <tr>
        <td>
$tu_img</td>
        <td class="tu_stat" id="tu_stat_
$pid">$tu_no</td>
        <td>
$td_img</td>
        <td class="td_stat" id="td_stat_
$pid">$td_no</td>
    </tr>
    <tr>
        <td class="small" colspan="4" >
            <span id="tpr_remove_
$pid">$box_remove</span>
            
$box_view
        </td>
    </tr>
</table>
BOX;

$post['tprdsp'] = $box;
}

// Function - Thumbs Action
function tpr_action()
{
    global 
$mybb$db$tid$lang;

    
// Return if action is not TPR
    
if ($mybb->input['action'] != 'tpr' ) return;

    
$uid $mybb->user['uid'];
    
$pid = (int)$mybb->input['pid'];
    
$tu = (int)$mybb->input['tu'];
    
$td = (int)$mybb->input['td'];
    
$lang->load('thumbspostrating');

    
// Check whether the rating is valid
    
if (($tu == && $td == 0) || ($tu == && $td == 1) || ($tu == && $td == 0))
    {
        
// Check whether the post key is valid
        
if (!verify_post_check($mybb->input['my_post_key'], true)) xmlhttp_error($lang->invalid_post_code);
    }
    else
    {
        
xmlhttp_error($lang->tpr_error_invalid_rating);
    }

    
$post get_post($pid);
    
$thread get_thread($post['tid']);
    
$forumpermissions forum_permissions($post['fid']);

    
// Check whether the post exist and is visible
    
if(!$post['pid']) xmlhttp_error($lang->post_doesnt_exist);
    if((
$thread['visible'] != || $post['visible'] != 1) && !$ismodxmlhttp_error($lang->post_doesnt_exist);

    
// Check whether the user can rate
    
$postuid = (int) $post['uid'];
    if (!
tpr_canrate($postuid)) xmlhttp_error($lang->tpr_error_cannot_rate);
    
    
// Check whether the user can view the post
    
if($forumpermissions['canview'] != || $forumpermissions['canviewthreads'] != 1xmlhttp_error($lang->post_doesnt_exist);
    if(
$forumpermissions['canonlyviewownthreads'] == && $thread['uid'] != $mybb->user['uid']) xmlhttp_error($lang->post_doesnt_exist);

    
// Check whether the user has rated
    
$rated $db->fetch_array($db->simple_select('thumbspostrating','thumbsup,thumbsdown','uid='.$uid.' and pid='.$pid));
    if((
$rated['thumbsup'] == || $rated['thumbsdown'] == 1) && ($tu == || $td == 1)) xmlhttp_error($lang->tpr_error_already_rated);

    
// Action for user who rated thumbs up
    
if($tu == && $td == 0)
    {
        
$insert_thumbs = array(
            
'thumbsup' => 1,
            
'uid' => $uid,
            
'pid' => $pid
    
);

        
// Insert the data into database
        
$db->insert_query('thumbspostrating',$insert_thumbs);
        
$db->write_query('UPDATE '.TABLE_PREFIX.'posts SET thumbsup = thumbsup +1 WHERE pid='.$pid);

        ++
$post['thumbsup'];
    }
    
// Action for user who rated thumbs down
    
elseif($tu == && $td == 1)
    {
        
$insert_thumbs = array(
            
'thumbsdown' => 1,
            
'uid' => $uid,
            
'pid' => $pid
        
);

        
// Insert the data into database
        
$db->insert_query('thumbspostrating',$insert_thumbs);
        
$db->write_query('UPDATE '.TABLE_PREFIX.'posts SET thumbsdown = thumbsdown +1 WHERE pid='.$pid);
        
        ++
$post['thumbsdown'];
    }
    
// Action for user who undo rating
    
elseif($tu == && $td == 0)
    {
        if (
$rated['thumbsup'] == 1)
        {
            
$db->write_query('UPDATE '.TABLE_PREFIX.'posts SET thumbsup = thumbsup -1 WHERE pid='.$pid);
            --
$post['thumbsup'];
        }
        elseif (
$rated['thumbsdown'] == 1)
        {
            
$db->write_query('UPDATE '.TABLE_PREFIX.'posts SET thumbsdown = thumbsdown -1 WHERE pid='.$pid);
            --
$post['thumbsdown'];
        }
        else
        {
            return;
        }

        
$db->delete_query('thumbspostrating''uid='.$uid.' and pid='.$pid);
    }
    
// Error if none of the above
    
else
    {
        
xmlhttp_error($lang->tpr_error_invalid_rating);
    }

    
// Feedback to the user
    
if(!$mybb->input['ajax'])
    {
        
header('Location: '.htmlspecialchars_decode(get_post_link($pid$post['tid'])).'#pid'.$pid);
    }
    else
    {
        
// Push new values to client    
        
echo 'success||'$post['pid'], '||', (int)$post['thumbsup'], '||', (int)$post['thumbsdown'];
        
        
// What user has just rated?
        
if ($tu == && $td == 0)
        {
            echo 
'||1';
        }
        elseif (
$tu == && $td == 1)
        {
            echo 
'||-1';
        }
        elseif (
$tu == && $td == 0)
        {
            echo 
'||0';
        }

        
// Show undo rating if enabled
        
if($mybb->settings['tpr_undorate'] == && ($tu || $td) == 1)
        {
            echo 
'||show_undo';
        }

        
// Remove undo rating if undone
        
elseif($mybb->settings['tpr_undorate'] == && ($tu && $td) == 0)
        {
            echo 
'||hide_undo';
        }
    }
}

// Function - Delete post
function tpr_deletepost($pid)
{
    global 
$db;
    
$db->delete_query('thumbspostrating''pid='.$pid);
}

// Function - Delete thread
function tpr_deletethread($tid)
{
    global 
$db$tpr_pids;
    
// grab pids, but only delete later
    
$tpr_pids '';
    
$query $db->simple_select('posts''pid''tid='.$tid);
    while(
$pid $db->fetch_field($query'pid'))
        
$tpr_pids .= ($tpr_pids ',':'') . $pid;
    
$db->free_result($query);
}

// Function - Delete thread 2
function tpr_deletethread2($tid)
{
    global 
$tpr_pids$db;
    if(!
$tpr_pids) return;
    
    
$db->delete_query('thumbspostrating''pid IN ('.$tpr_pids.')');
    
$tpr_pids '';
}
?>

PHP-Code:
/**
 * Thumbs Post Rating 1.3 by TY Yew
 * thumbspostrating.js
 */

function thumbRate(tu,td,pid)
{
    new 
Ajax.Request('xmlhttp.php?action=tpr&tu=' tu '&td=' td '&pid=' pid "&ajax=1&my_post_key=" my_post_key,{onComplete:thumbResponse});
    return 
false;
}

function 
thumbResponse(request)
{
    if(
error request.responseText.match(/<error>(.*)<\/error>/))
        
alert("An error occurred when rating the post.\n\n" error[1]);        
    else
    {
        
response request.responseText.split('||');
        if(
response[0] != 'success')
            
alert("An unknown error occurred when rating the post.");
        else
        {
            var 
pid parseInt(response[1]);
            var 
x=document.getElementById('tpr_stat_' pid).rows[0].cells;    
            if( 
response[4] == )
            {
                
x[1].innerHTML '<div class="tpr_thumb tu1"></div>';
                
x[2].innerHTML '<div class="tpr_thumb td0"></div>';
            }
            else if( 
response[4] == -)
            {
                
x[1].innerHTML '<div class="tpr_thumb tu0"></div>';
                
x[2].innerHTML '<div class="tpr_thumb td1"></div>';
            }
            else if( 
response[4] == )
            {
                
x[1].innerHTML '<a href="JavaScript:void(0);" class="tpr_thumb tu2" title="Rate thumbs up" onclick="return thumbRate(1,0,' pid ')" ></a>';
                
x[2].innerHTML '<a href="JavaScript:void(0);" class="tpr_thumb td2" title="Rate thumbs down" onclick="return thumbRate(0,1,' pid ')" ></a>';
            }
            else
            {
                
alert('Error: Invalid rating input.')
            }

            
x[0].innerHTML parseInt(response[2]);
            
x[3].innerHTML parseInt(response[3]);

            if(
response[5] == 'show_undo')
            {
                
document.getElementById('tpr_remove_' pid).innerHTML '<a href="JavaScript:void(0);" onclick="thumbRate(0,0,' pid ')" >Undo rating</a><br />';
            }

            if(
response[5] == 'hide_undo')
            {
                
document.getElementById('tpr_remove_' pid).innerHTML '';
            }
        }
    }
    return 
false;



Gruß
Zitieren
#6
Eine neue Version wurde veröffentlicht: Thumbs Post Rating 1.3
Zitieren
#7
Habe die Version von 1.6 zu 1.8 geändert, im Themplate "Postbit" eingebunden und wird nicht angezeigt.
Zitieren
#8
postbit TPL vor

Code:
<div class="post_body scaleimages" id="pid_{$post['pid']}">

dies eintragen

Code:
{$post['tprdsp']}

DONE
Mit freundlichen Grüßen

MrBrechreiz
Zitieren
#9
Ich weiß nicht genau, welches Themplate Du meinst. TPL?
Zitieren
#10
Steht doch da "postbit"
Mit freundlichen Grüßen

MrBrechreiz
Zitieren


Möglicherweise verwandte Themen…
Thema Verfasser Antworten Ansichten Letzter Beitrag
  Thumbs Post Rating MyBB.de Bot 1 1.269 17.02.2020, 22:55
Letzter Beitrag: MyBB.de Bot