Nel mio thanks.php

Il Padrino

Nuovo Utente
6 Gen 2008
1
0
0
Questo codice permette di ringraziare ed eventualmente di togliere il grazie che ha effettuato, ora un informazione quale parte di codice devo eliminare per non far apparire il rimuovi grazie ( cioè mi spiego meglio una volta premuto il tasto Grazie vorrei che al posto del rimuovi grazie non visualizzasse niente cosi gli utenti non possono togliere il suo grazie all'utente)

Grazie se è possibile


Codice:
<?php
/** 
*
* @package phpBB3
* @version $Id: thanks.php,v 0.2.0 2007/04/21 23:56:31 geoffreak Exp $
* @copyright (c) 2007 Geoffreak
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit; 
}
define('THANKS_TABLE', $table_prefix . 'thanks');

// create an array of all users
$sql = 'SELECT *
	FROM ' . USERS_TABLE;
$result = $db->sql_query($sql);
$users = array();
while ($row = $db->sql_fetchrow($result))
{
	if ((!isset($row['user_thanked']) || !isset($row['user_thanked_others'])) && $user->data['user_type'] == USER_FOUNDER)
	{
		install_040();
	}
	$users[$row['user_id']] = array( 
		'username' 			=> $row['username'], 
		'user_id'	 		=> $row['user_id'], 
		'user_colour' 		=> $row['user_colour'], 
		'user_gender' 		=> (isset($row['user_gender'])) ?  $row['user_gender'] : false,
		'thanks_give'		=> (isset($row['user_thanked_others'])) ? $row['user_thanked_others'] : 0,
		'thanks_receive'	=> (isset($row['user_thanked'])) ? $row['user_thanked'] : 0,
	);
}
$db->sql_freeresult($result);

// Do stuff based on header variables
// Two variables are needed to avoid accidental refresh errors
if (isset($_REQUEST['thanks']) && !isset($_REQUEST['rthanks'])) 
{
	insert_thanks(request_var('thanks', 0), $user->data['user_id']);
}
if (isset($_REQUEST['rthanks']) && !isset($_REQUEST['thanks']))
{
	delete_thanks(request_var('rthanks', 0), $user->data['user_id']);
}


// create an array of all thanks info
$sql = 'SELECT *
	FROM ' . THANKS_TABLE;
$result = $db->sql_query($sql);
$thankers = array();
$i = 0;
while ($row = $db->sql_fetchrow($result))
{
	$thankers[$i] = array(  
		'user_id' => $row['user_id'], 
		'post_id' => $row['post_id'], 
	);
	$i++;
}
$db->sql_freeresult($result);

function install_040()
{
	global $db, $user; 
	$sql = 'SELECT *
		FROM ' . POSTS_TABLE;
	$result = $db->sql_query($sql);
	$posts_arr = array();
	while ($row = $db->sql_fetchrow($result))
	{
		$posts_arr[$row['poster_id']][] = $row['post_id'];
	}
	$db->sql_freeresult($result);
	
	$sql = 'SELECT *
		FROM ' . USERS_TABLE;
	$result = $db->sql_query($sql);
	$users_thanked = array();
	$users_thanked_others = array();
	while ($row = $db->sql_fetchrow($result))
	{
		$users_thanked[$row['user_id']] = 0;
		$users_thanked_others[$row['user_id']] = 0;
	}
	$db->sql_freeresult($result);
	
	$sql = 'ALTER TABLE `' . USERS_TABLE . '` ADD `user_thanked` INT NOT NULL ;';
	$db->sql_query($sql);
	$sql = 'ALTER TABLE `' . USERS_TABLE . '` ADD `user_thanked_others` INT NOT NULL ;';
	$db->sql_query($sql);

	foreach ($users_thanked as $this_user_id => $thanks_count)
	{
		if (isset($posts_arr[$this_user_id]) && is_array($posts_arr[$this_user_id]))
		{
			foreach ($posts_arr[$this_user_id] as $key2 => $this_post_id)
			{
				foreach ($thankers as $key => $values)
				{
					if ($values['post_id'] == $this_post_id)
					{
						$users_thanked[$this_user_id]++;
					}
				}
			}
		}
		foreach ($thankers as $key => $values)
		{
			if ($values['user_id'] == $this_user_id)
			{
				$users_thanked_others[$this_user_id]++;
			}
		}
		$sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array(
			'user_thanked'			=> $users_thanked[$this_user_id],
			'user_thanked_others'	=> $users_thanked_others[$this_user_id],
		)) . " WHERE user_id = $this_user_id";
		$db->sql_query($sql);
	}
	$sql2 = 'INSERT INTO ' . CONFIG_TABLE . ' ' . $db->sql_build_array('INSERT', array(
		'config_name'	=> 'thanks_version',
		'config_value'	=> '0.4.0',
	));
	$db->sql_query($sql2);
	trigger_error($user->lang['TP_040_UPGRADED']);
}


// Output thanks list
function get_thanks($post_id)
{
	global $db, $users, $poster_id, $thankers;
	$return = '';
    $user_list = array();
	foreach($thankers as $key => $value)
	{
		if ($thankers[$key]['post_id'] == $post_id && $thankers[$key]['user_id'] != $poster_id)
		{
			$user_list[ strtolower( $users[$thankers[$key]['user_id']]['username'] ) ] = array( 
				'username' => $users[$thankers[$key]['user_id']]['username'], 
				'user_id' => $users[$thankers[$key]['user_id']]['user_id'], 
				'user_colour' => $users[$thankers[$key]['user_id']]['user_colour'], 
			);
		}
	}
	ksort($user_list);
	$i = 0;
	foreach($user_list as $key => $value)
	{
		if ($i > 0)
		{
			$return .= ', ';
		}
		$i++;
		$return .= get_username_string('full', $value['user_id'], $value['username'], $value['user_colour'], $value['username']);
	}
	$return = ($return == '') ? false : $return;
	return $return;
}
function get_thanks_number($post_id)
{
	global $db, $thankers;
	$i = 0;
	foreach($thankers as $key => $value)
	{
		if ($thankers[$key]['post_id'] == $post_id)
		{
			$i++;
		}
	}
	return $i;
}
// add a user to the thanks list
function insert_thanks($post_id, $user_id)
{
	global $db, $users;
	if ($user_id != ANONYMOUS)
	{	
		$sql = 'SELECT *
			FROM ' . THANKS_TABLE . "
			WHERE post_id = $post_id 
				AND user_id = $user_id
			LIMIT 1";
		$result = $db->sql_query($sql);
		$row = $db->sql_fetchrow($result);
		$db->sql_freeresult($result);
		
		$to_id = request_var('to_id', 0);
		if (empty($row) && !empty($to_id))
		{
			$sql2 = 'INSERT INTO ' . THANKS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
				'user_id'	=> $user_id,
				'post_id'	=> $post_id
			));
			$db->sql_query($sql2);
			$users[$user_id]['thanks_give'] += 1;
			$users[$to_id]['thanks_receive'] += 1;
			$sql1 = 'UPDATE ' . USERS_TABLE . ' 
				SET user_thanked_others = ' . $users[$user_id]['thanks_give'] . "
				WHERE user_id = $user_id";
			$sql3 = 'UPDATE ' . USERS_TABLE . ' 
				SET user_thanked = ' . $users[$to_id]['thanks_receive'] . "
				WHERE user_id = $to_id";
			$db->sql_query($sql1);
			$db->sql_query($sql3);
		}
	}
}
// remove a user's thanks
function delete_thanks($post_id, $user_id)
{
	global $db, $user, $users;
	if ($user_id != ANONYMOUS)
	{
		$sql = 'SELECT *
			FROM ' . THANKS_TABLE . "
			WHERE post_id = $post_id AND user_id = $user_id
			LIMIT 1";
		$result = $db->sql_query($sql);
		$row = $db->sql_fetchrow($result);
		$db->sql_freeresult($result);

		$to_id = request_var('to_id', 0);
		if (!empty($row) && !empty($to_id))
		{
			$sql = "DELETE FROM " . THANKS_TABLE . "
				WHERE post_id = $post_id AND user_id = " . $user->data['user_id'];
			$db->sql_query($sql);
			$users[$user_id]['thanks_give'] -= 1;
			$users[$to_id]['thanks_receive'] -= 1;
			$sql1 = 'UPDATE ' . USERS_TABLE . ' 
				SET user_thanked_others = ' . $users[$user_id]['thanks_give'] . "
				WHERE user_id = $user_id";
			$sql3 = 'UPDATE ' . USERS_TABLE . ' 
				SET user_thanked = ' . $users[$to_id]['thanks_receive'] . "
				WHERE user_id = $to_id";
			$db->sql_query($sql1);
			$db->sql_query($sql3);
		}
	}
}
// display the text/image saying either to add or remove thanks
function get_thanks_text($post_id)
{
	global $db, $user, $postrow;
	if (already_thanked($post_id, $user->data['user_id']))
	{
		$postrow = array_merge($postrow, array(
			'THANK_ALT'		=> $user->lang['REMOVE_THANKS'],
			'THANK_ALT2'	=> $user->lang['THANK_POST2'],
			'THANKS_IMG'	=> '/removethanks.gif',
		));
		return;
	}
	$postrow = array_merge($postrow, array(
		'THANK_ALT'		=> $user->lang['THANK_POST1'],
		'THANK_ALT2'	=> $user->lang['THANK_POST2'],
		'THANKS_IMG'	=> '/thankposts.gif',
	));
	return;
}
// change the variable sent via the link to avoid odd errors
function get_thanks_link($post_id)
{
	global $db, $user;
	if (already_thanked($post_id, $user->data['user_id']))
	{
		return 'rthanks';
	}
	return 'thanks';
}
// check if the user has already thanked that post
function already_thanked($post_id, $user_id)
{
	global $db, $thankers;
	$thanked = false;
	foreach($thankers as $key => $value)
	{
		if ($thankers[$key]['post_id'] == $post_id && $thankers[$key]['user_id'] == $user_id)
		{
			$thanked = true;
		}
	}
	return $thanked;
}
// check gender in applicable
function get_gender($user_id)
{
	global $users, $user;
	if ($user_id == ANONYMOUS || $users[$user_id]['user_gender'] == false)
	{
		return $user->lang['THANK_GENDER_U'];
	}
	else if ($users[$user_id]['user_gender'] == 1)
	{
		return $user->lang['THANK_GENDER_M'];
	}
	else if ($users[$user_id]['user_gender'] == 2)
	{
		return $user->lang['THANK_GENDER_F'];
	}
	return $user->lang['THANK_GENDER_U'];
}
// gets the number of users that have thanked the poster
function get_user_count($user_id, $receive)
{
	global $users;
	if ($receive)
	{
		return $users[$user_id]['thanks_receive'];
	}
	else
	{
		return $users[$user_id]['thanks_give'];
	}
}
// stuff goes here to avoid over-editing viewtopic.php
function output_thanks($user_id)
{
	global $db, $user, $poster_id, $postrow, $row, $phpEx, $topic_data, $phpbb_root_path;
	if (!empty($postrow))
	{
		$forum_id = (isset($forum_id)) ? $forum_id : 0;
		$number = get_thanks_number($row['post_id']) . ' ';
		$pl_text = $user->lang['THANK_TEXT_2pl'];
		if ($number == 1)
		{
			$pl_text = $user->lang['THANK_TEXT_2'];
			$number = '';
		}
		get_thanks_text($row['post_id']);
		$postrow = array_merge($postrow, array(
			'THANKS_GENDER' 		=> ' ' . get_gender($user_id),
			'THANKS'				=> get_thanks($row['post_id']),
			'THANKS_LINK'			=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['post_id']) . (($topic_data['topic_type'] == POST_GLOBAL) ? '&amp;f=' . $forum_id : '') . '&amp;' . get_thanks_link($row['post_id']) . '=' . $row['post_id'] . '&amp;to_id=' . $poster_id . '#p' . $row['post_id'],
			'THANK_TEXT'			=> $user->lang['THANK_TEXT_1'] . ' ' . $number . $pl_text . ' ',
			'POSTER_RECEIVE_COUNT'	=> get_user_count($poster_id, true),
			'POSTER_GIVE_COUNT'		=> get_user_count($poster_id, false),
			'S_IS_OWN_POST'			=> ($user->data['user_id'] == $poster_id) ? true : false,
		));
	}
}

?>
 

Eliox

Utente Attivo
25 Feb 2005
4.390
3
0
Rimuovi questa funzione:
PHP:
// remove a user's thanks
function delete_thanks($post_id, $user_id)
{
	global $db, $user, $users;
	if ($user_id != ANONYMOUS)
	{
		$sql = 'SELECT *
			FROM ' . THANKS_TABLE . "
			WHERE post_id = $post_id AND user_id = $user_id
			LIMIT 1";
		$result = $db->sql_query($sql);
		$row = $db->sql_fetchrow($result);
		$db->sql_freeresult($result);

		$to_id = request_var('to_id', 0);
		if (!empty($row) && !empty($to_id))
		{
			$sql = "DELETE FROM " . THANKS_TABLE . "
				WHERE post_id = $post_id AND user_id = " . $user->data['user_id'];
			$db->sql_query($sql);
			$users[$user_id]['thanks_give'] -= 1;
			$users[$to_id]['thanks_receive'] -= 1;
			$sql1 = 'UPDATE ' . USERS_TABLE . ' 
				SET user_thanked_others = ' . $users[$user_id]['thanks_give'] . "
				WHERE user_id = $user_id";
			$sql3 = 'UPDATE ' . USERS_TABLE . ' 
				SET user_thanked = ' . $users[$to_id]['thanks_receive'] . "
				WHERE user_id = $to_id";
			$db->sql_query($sql1);
			$db->sql_query($sql3);
		}
	}
}
 
Discussioni simili
Autore Titolo Forum Risposte Data
M Vendo il mio sito web teknosurfng.com, che trasmette nel campo della tecnologia Compravendita siti e domini 0
M [VENDO] Banner pubblicitari nel mio blog Vendere e Acquistare pubblicita' online 2
Shyson [WordPress] Richiamare nel mio sito numero iscritti da gruppo Facebook WordPress 0
gandalf1959 IPN Listener di Paypal, non riesco a registrare utente nel mio DB PHP 14
G Perchè nel mio photoshop non trovo sfocatura gaussiana Photoshop 1
filippino facebook: come inglobare i miei ultimi post nel mio sito web? HTML e CSS 1
Nik Non compare la admin bar nel mio tema WordPress 0
Jam1 Errore nel creare miniature da immagini caricate su un mio form PHP 0
G Nel mio caso posso usare javascript o devo avere un web server? Javascript 2
S Problemi di accesso al sito internet [era: Aiuto!!! problemi ad entrare nel mio sito con ie] Windows e Software 2
P come avere più visite nel mio sito? SEO e Posizionamento 3
D MOOTOOLS: cosa c'è di sbagliato nel mio codice Ajax? Ajax 1
L informazioni per inserire password nel mio sito web HTML e CSS 13
T Campo commenti nel mio sito PHP 5
P Inserire facebook nel mio sito HTML e CSS 4
giancadeejay Come inserire 3 elementi nel mio sito per riuscire a creare un intro flash? Flash 0
S Cerco appassionati d'informatica per entrare nel team del mio blog Offerte e Richieste di Lavoro e/o Collaborazione 0
P Chi mi aiuta a capire dove sbaglio nel mio CSS? HTML e CSS 3
S Area Blog nel mio sito, come? HTML e CSS 2
N Mettere FILE VIDEO nel MIO SITO internet ?!!? Javascript 1
D Blog nel mio sito Discussioni Varie 0
D forum nel mio sito PHP 5
F Scegliete path nel mio HD Javascript 1
S Nel mio sito ho... Presenta il tuo Sito 0
M Nel mio sito propongo.. Guadagnare col Sito 0
M Aiutooo nel mio Sito HTML e CSS 5
W musica nel mio sito HTML e CSS 2
S Aprire documento word nel mio form Programmazione 0
maxnegri cerco programmatore php per un lavoro di integrazione import csv nel mio sito PHP 1
T il tuo sito nel mio - aumenta le visite! Presenta il tuo Sito 0
T MUSICA E VIDEO NEL MIO SITO...come si fa??? HTML e CSS 2
F problemi inserimento formmail nel mio blog Supporto Mr.Webmaster 1
G <---Techno&trance--->Benvenuti nel mio sito...ne vale la pena passarci Presenta il tuo Sito 22
G AIUTO! Vorrei creare un guestbook nel mio sito html.. come faccio? HTML e CSS 2
W Scrivete nel mio forum--in cambio servizio parole chiave e submission Altri Annunci 0
S gioco .exe nel mio sito HTML e CSS 10
D Come faccio a inserire 1 finestra di news sulla asRoma nel mio sito? HTML e CSS 5
D problemi con le tabelle nel mio sito HTML e CSS 7
P Come posso inserire musica di sottofondo nel mio sito Javascript 16
A Segnala il tuo sito nel mio Presenta il tuo Sito 2
S problema redirect e js nel mio sito Supporto Mr.Webmaster 0
C Come posso farmi lasciare commenti nel mio sito? HTML e CSS 29
icebracker mettere un contatore nel mio sito HTML e CSS 1
C non si visualizzano le immagini nel mio sito HTML e CSS 6
D server php nel mio pc PHP 5
I nome utente non esiste nel database PHP 1
S Problema nel ciclare un json Javascript 0
M Aggiunta prodotti nel carrello con lo stesso in e varianti diverse PHP 0
U PHP creare un file excel dopo ricerca nel DB PHP 0
C prendere dei valori da Plugin e inserirli nel database joomla Joomla 0

Discussioni simili