Точки от мнения – phpBB2

Автор: djvato

да обесня за тези който незнаят за какво служи урока … той може да ви потрябва ако искате да напрвите някакви игри във форума ви с точки както е тук само , че няма support ами са само точки след като пишеш мнения ви дава точки след като пуснеш тема ви дава отново точки сега не съм засичал колко дава на нова тема на ново мнение в твоя тема в чужда но има разлика и има и разлика зависи колко е посещавана темата и т .н. общо взето.

и така нека започнем :

първо трябва да направим два файла ето ги и тях :

resync.php

<?php

// Change the php.ini file to remove the maximum execution time (default is 60 seconds)
ini_set("max_execution_time", 0);

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.' . $phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//

if ( !$userdata['session_logged_in'] )
{
$redirect = "resync.$phpEx";
$redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : '';
header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true));
}

function count_words($str) {
return substr_count($str, ' ') + 1;
}

function Remove($string, $sep1, $sep2)
{
$string = strrev(substr($string, 0, strpos($string, $sep2)));
$string = strrev(substr($string,0,strpos($string, strrev($sep1))));
return $string;
}

$name = $userdata['username'];
if ($_REQUEST['action'] == "sync") {
$user = $userdata['user_id'];
$sql2 = "SELECT user_id, username FROM " . USERS_TABLE . " WHERE user_id='$user'";
if ( !($result2 = $db->sql_query($sql2)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error getting user_id from the user table.'); }
$j = 0;
while ( $words3 = $db->sql_fetchrow($result2) )
{
$j++;
$auser_id = $words3['user_id'];
// Joins phpbb_posts_text and phpbb_posts together to grab the users id and all the post text.
$sql = "SELECT a.post_text,b.post_id,b.poster_id FROM " . POSTS_TEXT_TABLE . " a, " . POSTS_TABLE . " b WHERE b.post_id=a.post_id and b.poster_id=$auser_id";
if ( !($result = $db->sql_query($sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error joining posts and post_text tables.'); }
$x = 0;
while ( $words = $db->sql_fetchrow($result) )
{
$x++;
$word_post = $words['post_text'];

// Removes [QUOTE] and [/QUOTE] from being counted
$text = Remove($word_post,"[quote:","[/quote:");
$word_post = str_replace($text, "", $word_post);

$total_words = $total_words . $word_post; // $total_words contains all the text a user has posted
}

$total_update = count_words($total_words); // Concerts $total_words from text into a number (word count)
$sql3 = "UPDATE " . USERS_TABLE . " SET user_wordcount='$total_update' WHERE user_id='$auser_id'";
$result3 = $db->sql_query($sql3);
$total_words = 0;
$total_update = 0;
}
message_die(GENERAL_MESSAGE, 'Finished updating '.$name.'\'s word count.');
} else {
message_die(GENERAL_MESSAGE, 'This will re-sync the databse with your proper word count.<br />This will take approx. 15 seconds if you have about least 2000 posts.<br />More than 2000 posts may take upwards of a 30 seconds to a full minute.<br /> Please be patient.<br /><br /><b><center><a href=resync.php?action=sync>CLICK TO RESYNC WORD COUNT</a></center></b>');
}
message_die(GENERAL_MESSAGE, 'Finished updating '.$name.'\'s word count.');
?>

слагате го в главната директория на форума .

word_count_sync.php

<?php
// Change the php.ini file to remove the maximum execution time (default is 60 seconds)
ini_set("max_execution_time", 0);

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.' . $phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//

if ( !$userdata['session_logged_in'] )
{
$redirect = "word_count_sync.$phpEx";
$redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : '';
header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true));
}

// This stops anyone other than the admin from running this script
if($userdata['user_level'] != ADMIN) {
message_die(GENERAL_MESSAGE, 'You are not logged in as an Admin!<br /><br />Exiting script.<br /><br />');
}

function count_words($str) {
return substr_count($str, ' ') + 1;
}

function Remove($string, $sep1, $sep2)
{
$string = strrev(substr($string, 0, strpos($string, $sep2)));
$string = strrev(substr($string,0,strpos($string, strrev($sep1))));
return $string;
}

if ($_REQUEST['action'] == "sync") {
$sql2 = "SELECT user_id,username FROM " . USERS_TABLE . " WHERE user_id > 0 and user_posts > 10"; // Change the 10 higher or lower depending on the the min. number of posts a user must have in order to calculate the total words.
if ( !($result2 = $db->sql_query($sql2)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error getting user_id from the user table.'); }
$j = 0;
while ( $words3 = $db->sql_fetchrow($result2) )
{
$j++;
$auser_id = $words3['user_id'];
// Joins phpbb_posts_text and phpbb_posts together to grab the users id and all the post text.
$sql = "SELECT a.post_text,b.post_id,b.poster_id FROM " . POSTS_TEXT_TABLE . " a, " . POSTS_TABLE . " b WHERE b.post_id=a.post_id and b.poster_id=$auser_id";
if ( !($result = $db->sql_query($sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error joining posts and post_text tables.'); }

$x = 0;
while ( $words = $db->sql_fetchrow($result) )
{
$x++;
$word_post = $words['post_text'];

// Removes [QUOTE] and [/QUOTE] from being counted
$text = Remove($word_post,"[quote:","[/quote:");
$word_post = str_replace($text, "", $word_post);

$total_words = $total_words . $word_post; // $total_words contains all the text a user has posted
}

$total_update = count_words($total_words); // Converts $total_words from text into a number (word count)
$sql3 = "UPDATE " . USERS_TABLE . " SET user_wordcount='$total_update' WHERE user_id='$auser_id'";
$result3 = $db->sql_query($sql3);
$total_words = 0;
$total_update = 0;
}
message_die(GENERAL_MESSAGE, 'Finished updating all user\'s word count.');
} else {
message_die(GENERAL_MESSAGE, 'This will re-sync your user database with the proper word count.<br />This will take approx. 5-15 seconds PER user if they have at least 2000 posts.<br />More than 2000 posts may take upwards of a 20-30 seconds, while<br />someone with only 200 posts will take just 1-2 seconds. Please be patient.<br /><br /><b><center><a href=word_count_sync.php?action=sync>CLICK TO RESYNC WORD COUNT</a></center></b>');
}

// Fail Safe
message_die(GENERAL_MESSAGE, 'Invalid Action.');
?>

и него го слагате в главната директория

и така нека найстина започнем със самия урок :

#-----[ SQL ]-------------------------------------------------
#
ALTER TABLE `phpbb_users` ADD `user_wordcount` INT(255) DEFAULT '0' NOT NULL;



#
#-----[ отваряте ]------------------------------------------------
#
includes/functions_post.php

#
#-----[ намирате ]------------------------------------------------
#
$unhtml_specialchars_replace = array('>', '<', '"', '&');

#
#-----[ след него добавяте ]------------------------------------------
#

function Remove($string, $sep1, $sep2)
{
$string = strrev(substr($string, 0, strpos($string, $sep2)));
$string = strrev(substr($string,0,strpos($string, strrev($sep1))));
return $string;
}

#
#-----[ намирате ]------------------------------------------------
#
message_die(GENERAL_MESSAGE, $lang['Flood_Error']);
}
}
}
}

#
#-----[ след него добавяте ]------------------------------------------
#

// WORD COUNT START by NoahK
// This function takes the character count, and simply counts the
// spaces. Then adds one to account for the first word.
function count_words($str) {
return substr_count($str, ' ') + 1;
}
if ($mode == 'newtopic' || $mode == 'reply')
{
// The below code takes the message, stores it into a new
// variable and strips all the standard BB Codes from being
// counted towards a users word count.

// Setting of some Variables
$uid = $bbcode_uid;
$post_message2 = $post_message;

// Removes [QUOTE] and [/QUOTE], as well as the text inbetween them!
$text = Remove($post_message2,"[quote:","[/quote:");
$post_message2 = str_replace($text, "", $post_message2);
$post_message2 = str_replace("[quote:$uid]", "", $post_message2);
$post_message2 = str_replace("[/quote:$uid]", "", $post_message2);
$post_message2 = preg_replace("/\[quote:$uid=\"(.*?)\"\]/si", "", $post_message2);

// Removes li tags
$post_message2 = str_replace("[*:$uid]", "", $post_message2);

// Removes ending tags
$post_message2 = str_replace("[/list:u:$uid]", "", $post_message2);
$post_message2 = str_replace("[/list:o:$uid]", "", $post_message2);

// Removes ordered lists
$post_message2 = preg_replace("/\[list=([a1]):$uid\]/si", "", $post_message2);

// Removes colors
$post_message2 = preg_replace("/\[color=(\#[0-9A-F]{6}|[a-z]+):$uid\]/si", "", $post_message2);
$post_message2 = str_replace("[/color:$uid]", "", $post_message2);

// Removes size
$post_message2 = preg_replace("/\[size=([1-2]?[0-9]):$uid\]/si", "", $post_message2);
$post_message2 = str_replace("[/size:$uid]", "", $post_message2);

// Removes and for bolding text.
$post_message2 = str_replace("[b:$uid]", "", $post_message2);
$post_message2 = str_replace("[/b:$uid]", "", $post_message2);

// Removes [u] and [/u] for underlining text.
$post_message2 = str_replace("[u:$uid]", "", $post_message2);
$post_message2 = str_replace("[/u:$uid]", "", $post_message2);

// Removes [i] and [/i] for italicizing text.
$post_message2 = str_replace("[i:$uid]", "", $post_message2);
$post_message2 = str_replace("[/i:$uid]", "", $post_message2);

// The SQL command to take the current word count total, and add
// the new word count to store back into the database.
$howmany = count_words($post_message2);
$sql = "UPDATE " . USERS_TABLE . " SET user_wordcount = user_wordcount + $howmany WHERE user_id='{$userdata['user_id']}'";
$result2 = $db->sql_query($sql);
}
// WORD COUNT END by NoahK



#
#-----[ отваряте ]------------------------------------------------
#
language/lang_english/lang_main.php


#
#-----[ намирате ]------------------------------------------------
#
// That's all, Folks!

#
#-----[ преди него добавяте ]------------------------------------------
#

$lang['Total_Words'] = 'Точки: ';
$lang['Word_NA'] = 'все още няма';
$lang['Word_Count'] = 'Точки: ';
$lang['Word_Text'] = 'по толкос мнения';
$lang['Word_Memberlist'] = 'Точки';


#
#-----[ отваряте ]------------------------------------------------
#
viewtopic.php


#
#-----[ намирате ]------------------------------------------------
#
//
// Again this will be handled by the templating
// code at some point
//

#
#-----[ преди него добавяте ]------------------------------------------
#

// WORD COUNT START by NoahK
$sql = "SELECT user_wordcount FROM " . USERS_TABLE . " WHERE user_id='$poster_id'";
$result = $db->sql_query($sql);
$words = $db->sql_fetchrow($result);
$wordcount = $words['user_wordcount'];
// Format the result in a human readable number
$rest3 = number_format($wordcount);
// The code below is not utilized in this mod for viewtopic, however the .TPL could easily be changed to include the word average by using WORD_AVG.
// Check for division by 0, if a user has no posts you can safely change the lang[word_na] to '0' or any other text in the language file
// The 2 at the end of the next line controls the number of decimal places shown at the end of the number. Change that to 0 if you want to use whole numbers.
$avg_words = ($wordcount == 0) ? $lang['Word_NA'] : round(($wordcount / $postrow[$i]['user_posts']),2);
// WORD COUNT END by NoahK


#
#-----[ намирате ]------------------------------------------------
#
'POSTER_NAME' => $poster,

#
#-----[ след него добавяте ]------------------------------------------
#

'WORD_COUNT' => $rest3,
'WORD_AVG' => $avg_words,
'TOTAL_WORDS_TEXT' => $lang['Total_Words'],



#
#-----[ отваряте ]------------------------------------------------
#
templates/subSilver/viewtopic_body.tpl

#
#-----[ намирате ]------------------------------------------------
#
{postrow.POSTER_POSTS}<br />



#
#-----[ след него добавяте ]------------------------------------------
#

{postrow.TOTAL_WORDS_TEXT}{postrow.WORD_COUNT}<br />


#
#-----[ отваряте ]------------------------------------------------
#
includes/usercp_viewprofile.php

#
#-----[ намирате ]------------------------------------------
#

//
// Generate page
//

#
#-----[ преди него добавяте ]------------------------------------------------
#

// WORD COUNT START by NoahK
$sql = "SELECT user_wordcount FROM " . USERS_TABLE . " WHERE user_id='{$profiledata['user_id']}'";
$result = $db->sql_query($sql);
$words = $db->sql_fetchrow($result);
$wordcount = $words['user_wordcount'];
// Format the result in a human readable number
$rest3 = number_format($wordcount);
// Check for division by 0
if (($wordcount == 0) || ($profiledata['user_posts'] == 0)) {
$avg_words = $lang['Word_NA']; // If a user has no posts. You may safely change N/A to 0 or any other text in the language file.
} else {
$avg_words = round(($wordcount / $profiledata['user_posts']),2); // The 2 controls the numbers shown after the decimal. Use 0 if you want whole numbers.
}
// WORD COUNT END by NoahK

#
#-----[ намирате ]------------------------------------------
#
'POSTER_RANK' => $poster_rank,

#
#-----[ след него добавяте ]------------------------------------------------
#
'WORD_COUNT' => $rest3,
'WORD_AVG' => $avg_words,
'WORD_COUNT_TEXT' => $lang['Word_Count'],
'WORD_TEXT' => $lang['Word_Text'],

#
#-----[ отваряте ]-------------------------------------------------
#
templates/subSilver/profile_view_body.tpl

#
#-----[ намирате ]------------------------------------------
#

<tr>
<td valign="middle" align="right" nowrap="nowrap"><span class="gen">{L_LOCATION}: </span></td>
<td><b><span class="gen">{LOCATION}</span></b></td>
</tr>

#
#-----[ преди него добавяте ]-------------------------------------------------
#
<tr>
<td valign="middle" align="right" nowrap="nowrap"><span class="gen">{WORD_COUNT_TEXT}</span></td>
<td><b><span class="genmed">{WORD_COUNT}<br />{WORD_AVG} {WORD_TEXT}</span></b></td>
</tr>

Успех !

Вашият коментар