[問題] 已爬文無解 ....關於會員列表及瀏覽文章的問題....
發表於 : 2005-01-30 03:29
我遇到了奇怪的問題,請各位大大幫我看看
在遇到問題之前我裝了cash mod 2.2.2 正常運作了兩天
後來又加裝[2.0.6] Profile Control Panel (我不清楚中文怎麼翻...不知道是不是超級版主..不確定)
檔案連結網址 http://www.phpbb.com/phpBB/viewtopic.php?t=150925
問題有兩個:
Parse error: parse error, unexpected '}' in c:\appserv\www\phpbb\includes\template.php(127) : eval()'d code on line 116
Fatal error: Call to a member function on a non-object in c:\appserv\www\phpbb\includes\classes_cash.php on line 369
但是我在裝[2.0.6] Profile Control Panel 的時候並沒有動到 classes_cash.php檔案
測試帳號:tester
密碼:1234
網址:http://queenie.idv.st
#####################################################################
1.template.php #
#######################################################################
<?php
/***************************************************************************
* template.php
* -------------------
* begin : Saturday, Feb 13, 2001
* copyright : (C) 2001 The phpBB Group
* email : support@phpbb.com
*
* $Id: template.php,v 1.10.2.3 2002/12/21 19:09:57 psotfx Exp $
*
*
***************************************************************************/
/***************************************************************************
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
/**
* Template class. By Nathan Codding of the phpBB group.
* The interface was originally inspired by PHPLib templates,
* and the template file formats are quite similar.
*
*/
class Template {
var $classname = "Template";
// variable that holds all the data we'll be substituting into
// the compiled templates.
// ...
// This will end up being a multi-dimensional array like this:
// $this->_tpldata[block.][iteration#][child.][iteration#][child2.][iteration#][variablename] == value
// if it's a root-level variable, it'll be like this:
// $this->_tpldata[.][0][varname] == value
var $_tpldata = array();
// Hash of filenames for each template handle.
var $files = array();
// Root template directory.
var $root = "";
// this will hash handle names to the compiled code for that handle.
var $compiled_code = array();
// This will hold the uncompiled code for that handle.
var $uncompiled_code = array();
/**
* Constructor. Simply sets the root dir.
*
*/
function Template($root = ".")
{
$this->set_rootdir($root);
}
/**
* Destroys this template object. Should be called when you're done with it, in order
* to clear out the template data so you can load/parse a new template set.
*/
function destroy()
{
$this->_tpldata = array();
}
/**
* Sets the template root directory for this Template object.
*/
function set_rootdir($dir)
{
if (!is_dir($dir))
{
return false;
}
$this->root = $dir;
return true;
}
/**
* Sets the template filenames for handles. $filename_array
* should be a hash of handle => filename pairs.
*/
function set_filenames($filename_array)
{
if (!is_array($filename_array))
{
return false;
}
reset($filename_array);
while(list($handle, $filename) = each($filename_array))
{
$this->files[$handle] = $this->make_filename($filename);
}
return true;
}
/**
* Load the file for the handle, compile the file,
* and run the compiled code. This will print out
* the results of executing the template.
*/
function pparse($handle)
{
if (!$this->loadfile($handle))
{
die("Template->pparse(): Couldn't load template file for handle $handle");
}
// actually compile the template now.
if (!isset($this->compiled_code[$handle]) || empty($this->compiled_code[$handle]))
{
// Actually compile the code now.
$this->compiled_code[$handle] = $this->compile($this->uncompiled_code[$handle]);
}
// Run the compiled code.
eval($this->compiled_code[$handle]);
return true;
}
/**
* Inserts the uncompiled code for $handle as the
* value of $varname in the root-level. This can be used
* to effectively include a template in the middle of another
* template.
* Note that all desired assignments to the variables in $handle should be done
* BEFORE calling this function.
*/
function assign_var_from_handle($varname, $handle)
{
if (!$this->loadfile($handle))
{
die("Template->assign_var_from_handle(): Couldn't load template file for handle $handle");
}
// Compile it, with the "no echo statements" option on.
$_str = "";
$code = $this->compile($this->uncompiled_code[$handle], true, '_str');
// evaluate the variable assignment.
eval($code);
// assign the value of the generated variable to the given varname.
$this->assign_var($varname, $_str);
return true;
}
/**
* Block-level variable assignment. Adds a new block iteration with the given
* variable assignments. Note that this should only be called once per block
* iteration.
*/
function assign_block_vars($blockname, $vararray)
{
if (strstr($blockname, '.'))
{
// Nested block.
$blocks = explode('.', $blockname);
$blockcount = sizeof($blocks) - 1;
$str = '$this->_tpldata';
for ($i = 0; $i < $blockcount; $i++)
{
$str .= '[\'' . $blocks[$i] . '.\']';
eval('$lastiteration = sizeof(' . $str . ') - 1;');
$str .= '[' . $lastiteration . ']';
}
// Now we add the block that we're actually assigning to.
// We're adding a new iteration to this block with the given
// variable assignments.
$str .= '[\'' . $blocks[$blockcount] . '.\'][] = $vararray;';
// Now we evaluate this assignment we've built up.
eval($str);
}
else
{
// Top-level block.
// Add a new iteration to this block with the variable assignments
// we were given.
$this->_tpldata[$blockname . '.'][] = $vararray;
}
return true;
}
/**
* Root-level variable assignment. Adds to current assignments, overriding
* any existing variable assignment with the same name.
*/
function assign_vars($vararray)
{
reset ($vararray);
while (list($key, $val) = each($vararray))
{
$this->_tpldata['.'][0][$key] = $val;
}
return true;
}
/**
* Root-level variable assignment. Adds to current assignments, overriding
* any existing variable assignment with the same name.
*/
function assign_var($varname, $varval)
{
$this->_tpldata['.'][0][$varname] = $varval;
return true;
}
/**
* Generates a full path+filename for the given filename, which can either
* be an absolute name, or a name relative to the rootdir for this Template
* object.
*/
function make_filename($filename)
{
// Check if it's an absolute or relative path.
if (substr($filename, 0, 1) != '/')
{
$filename = phpbb_realpath($this->root . '/' . $filename);
}
if (!file_exists($filename))
{
die("Template->make_filename(): Error - file $filename does not exist");
}
return $filename;
}
/**
* If not already done, load the file for the given handle and populate
* the uncompiled_code[] hash with its code. Do not compile.
*/
function loadfile($handle)
{
// If the file for this handle is already loaded and compiled, do nothing.
if (isset($this->uncompiled_code[$handle]) && !empty($this->uncompiled_code[$handle]))
{
return true;
}
// If we don't have a file assigned to this handle, die.
if (!isset($this->files[$handle]))
{
die("Template->loadfile(): No file specified for handle $handle");
}
$filename = $this->files[$handle];
$str = implode("", @file($filename));
if (empty($str))
{
die("Template->loadfile(): File $filename for handle $handle is empty");
}
$this->uncompiled_code[$handle] = $str;
return true;
}
/**
* Compiles the given string of code, and returns
* the result in a string.
* If "do_not_echo" is true, the returned code will not be directly
* executable, but can be used as part of a variable assignment
* for use in assign_code_from_handle().
*/
function compile($code, $do_not_echo = false, $retvar = '')
{
// replace \ with \\\ and then ' with \'.
$code = str_replace('\\\', '\\\\\\\', $code);
$code = str_replace('\'', '\\\\\'', $code);
// change template varrefs into PHP varrefs
// This one will handle varrefs WITH namespaces
$varrefs = array();
preg_match_all('#\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}#is', $code, $varrefs);
$varcount = sizeof($varrefs[1]);
for ($i = 0; $i < $varcount; $i++)
{
$namespace = $varrefs[1][$i];
$varname = $varrefs[3][$i];
$new = $this->generate_block_varref($namespace, $varname);
$code = str_replace($varrefs[0][$i], $new, $code);
}
// This will handle the remaining root-level varrefs
$code = preg_replace('#\{([a-z0-9\-_]*?)\}#is', '\' . ( ( isset($this->_tpldata[\'.\'][0][\'\1\']) ) ? $this->_tpldata[\'.\'][0][\'\1\'] : \'\' ) . \'', $code);
// Break it up into lines.
$code_lines = explode("
", $code);
$block_nesting_level = 0;
$block_names = array();
$block_names[0] = ".";
// Second: prepend echo ', append ' . "
"; to each line.
$line_count = sizeof($code_lines);
for ($i = 0; $i < $line_count; $i++)
{
$code_lines[$i] = chop($code_lines[$i]);
if (preg_match('#<!-- BEGIN (.*?) -->#', $code_lines[$i], $m))
{
$n[0] = $m[0];
$n[1] = $m[1];
// Added: dougk_ff7-Keeps templates from bombing if begin is on the same line as end.. I think.
if ( preg_match('#<!-- END (.*?) -->#', $code_lines[$i], $n) )
{
$block_nesting_level++;
$block_names[$block_nesting_level] = $m[1];
if ($block_nesting_level < 2)
{
// Block is not nested.
$code_lines[$i] = '$_' . $n[1] . '_count = ( isset($this->_tpldata[\'' . $n[1] . '.\']) ) ? sizeof($this->_tpldata[\'' . $n[1] . '.\']) : 0;';
$code_lines[$i] .= "
" . 'for ($_' . $n[1] . '_i = 0; $_' . $n[1] . '_i < $_' . $n[1] . '_count; $_' . $n[1] . '_i++)';
$code_lines[$i] .= "
" . '{';
}
else
{
// This block is nested.
// Generate a namespace string for this block.
$namespace = implode('.', $block_names);
// strip leading period from root level..
$namespace = substr($namespace, 2);
// Get a reference to the data array for this block that depends on the
// current indices of all parent blocks.
$varref = $this->generate_block_data_ref($namespace, false);
// Create the for loop code to iterate over this block.
$code_lines[$i] = '$_' . $n[1] . '_count = ( isset(' . $varref . ') ) ? sizeof(' . $varref . ') : 0;';
$code_lines[$i] .= "
" . 'for ($_' . $n[1] . '_i = 0; $_' . $n[1] . '_i < $_' . $n[1] . '_count; $_' . $n[1] . '_i++)';
$code_lines[$i] .= "
" . '{';
}
// We have the end of a block.
unset($block_names[$block_nesting_level]);
$block_nesting_level--;
$code_lines[$i] .= '} // END ' . $n[1];
$m[0] = $n[0];
$m[1] = $n[1];
}
else
{
// We have the start of a block.
$block_nesting_level++;
$block_names[$block_nesting_level] = $m[1];
if ($block_nesting_level < 2)
{
// Block is not nested.
$code_lines[$i] = '$_' . $m[1] . '_count = ( isset($this->_tpldata[\'' . $m[1] . '.\']) ) ? sizeof($this->_tpldata[\'' . $m[1] . '.\']) : 0;';\r
$code_lines[$i] .= "
" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1] . '_count; $_' . $m[1] . '_i++)';
$code_lines[$i] .= "
" . '{';
}
else
{
// This block is nested.
// Generate a namespace string for this block.
$namespace = implode('.', $block_names);
// strip leading period from root level..
$namespace = substr($namespace, 2);
// Get a reference to the data array for this block that depends on the
// current indices of all parent blocks.
$varref = $this->generate_block_data_ref($namespace, false);
// Create the for loop code to iterate over this block.
$code_lines[$i] = '$_' . $m[1] . '_count = ( isset(' . $varref . ') ) ? sizeof(' . $varref . ') : 0;';
$code_lines[$i] .= "
" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1] . '_count; $_' . $m[1] . '_i++)';
$code_lines[$i] .= "\
" . '{';
}
}
}
else if (preg_match('#<!-- END (.*?) -->#', $code_lines[$i], $m))
{
// We have the end of a block.
unset($block_names[$block_nesting_level]);
$block_nesting_level--;
$code_lines[$i] = '} // END ' . $m[1];
}
else
{
// We have an ordinary line of code.
if (!$do_not_echo)
{
$code_lines[$i] = 'echo \'' . $code_lines[$i] . '\' . "\\
";';
}
else
{
$code_lines[$i] = '$' . $retvar . '.= \'' . $code_lines[$i] . '\' . "\\
";';
}
}
}
// Bring it back into a single string of lines of code.
$code = implode("
", $code_lines);
return $code ;
}
/**
* Generates a reference to the given variable inside the given (possibly nested)
* block namespace. This is a string of the form:
* ' . $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['varname'] . '
* It's ready to be inserted into an "echo" line in one of the templates.
* NOTE: expects a trailing "." on the namespace.
*/
function generate_block_varref($namespace, $varname)
{
// Strip the trailing period.
$namespace = substr($namespace, 0, strlen($namespace) - 1);
// Get a reference to the data block for this namespace.
$varref = $this->generate_block_data_ref($namespace, true);
// Prepend the necessary code to stick this in an echo line.
// Append the variable reference.
$varref .= '[\'' . $varname . '\']';
$varref = '\' . ( ( isset(' . $varref . ') ) ? ' . $varref . ' : \'\' ) . \'';
return $varref;
}
/**
* Generates a reference to the array of data values for the given
* (possibly nested) block namespace. This is a string of the form:
* $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['$childN']
*
* If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above.
* NOTE: does not expect a trailing "." on the blockname.
*/
function generate_block_data_ref($blockname, $include_last_iterator)
{
// Get an array of the blocks involved.
$blocks = explode(".", $blockname);
$blockcount = sizeof($blocks) - 1;
$varref = '$this->_tpldata';
// Build up the string with everything but the last child.
for ($i = 0; $i < $blockcount; $i++)
{
$varref .= '[\'' . $blocks[$i] . '.\'][$_' . $blocks[$i] . '_i]';
}
// Add the block reference for the last child.
$varref .= '[\'' . $blocks[$blockcount] . '.\']';
// Add the iterator for the last child if requried.
if ($include_last_iterator)
{
$varref .= '[$_' . $blocks[$blockcount] . '_i]';
}
return $varref;
}
}
?>
######################################################################
2.classes_cash.php #
#################################################################
<?php
/***************************************************************************
* classes_cash.php
* -------------------
* begin : Tuesday, Oct 07, 2003
* copyright : (C) 2003 Xore
* email : mods@xore.ca
*
* $Id: classes_cash.php,v 1.0.0.0 2003/10/07 19:54:52 Xore $
*
*
***************************************************************************/
/***************************************************************************
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
if ( !defined('IN_PHPBB') )
{
die("Hacking attempt");
}
if ( defined('CASH_CLASSES_INCLUDE') )
{
return;
}
define('CASH_CLASSES_INCLUDE',TRUE);
//
//=============[ Template extended functionality ]=========================
//
class Template_plus extends Template
{
var $classname = "Template";
var $_tpldata = array();
var $files = array();
var $root = "";
var $compiled_code = array();
var $uncompiled_code = array();
function set(&$template)
{
$this->classname = &$template->classname;
$this->_tpldata = &$template->_tpldata;
$this->files = &$template->files;
$this->root = &$template->root;
$this->compiled_code = &$template->compiled_code;
$this->uncompiled_code = &$template->uncompiled_code;
}
/**
* Inserts the uncompiled code for $handle as the
* value of $varname in the block-level. This can be used
* to effectively include a template in the middle of another
* template.
* Note that all desired assignments to the variables in $handle should be done
* BEFORE calling this function.
*/
function assign_block_var_from_handle($varname, $handle)
{
if (!$this->loadfile($handle))
{
die("Template->assign_var_from_handle(): Couldn't load template file for handle $handle");
}
// Compile it, with the "no echo statements" option on.
$_str = "";
$code = $this->compile($this->uncompiled_code[$handle], true, '_str');
// evaluate the variable assignment.
eval($code);
// assign the value of the generated variable to the given varname.
if (strstr($varname, '.'))
{
$lastposition = strrpos($varname,'.');
$blockname = substr($varname,0,$lastposition);
$varname = substr($varname,$lastposition+1);
$this->reassign_block_vars($blockname,array($varname => $_str));
}
else
{
$this->assign_var($varname, $_str);
}
return true;
}
/**
* Block-level variable re-assignment. Prevents new block iteration with the given
* variable assignments. Note that once you've iterated to a new block via assign_block_vars,
* you won't be able to come back to an old block.
*/
function reassign_block_vars($blockname, $vararray)
{
if (strstr($blockname, '.'))
{
// Nested block.
$blocks = explode('.', $blockname);
$blockcount = sizeof($blocks);
$str = '$this->_tpldata';
for ($i = 0; $i < $blockcount; $i++)
{
$str .= '[\'' . $blocks[$i] . '.\']';
eval('$lastiteration = sizeof(' . $str . ') - 1;');
$str .= '[' . $lastiteration . ']';
}
// Now we add the block that we're actually assigning to.
reset ($vararray);
while (list($key,$val) = each($vararray))
{
$current_string = $str . '[$key] = $val';
// Now we evaluate this assignment we've built up.
eval($current_string);
}
}
else
{
// Top-level block.
// Add a new iteration to this block with the variable assignments
// we were given.
$lastiteration = sizeof($this->_tpldata[$blockname . '.']) - 1;
reset ($vararray);
while (list($key,$val) = each($vararray))
{
$this->_tpldata[$blockname . '.'][$lastiteration][$key] = $val;
}
}
return true;
}
/**
* Block-level variable clearing. Removes a block of data so it can be re-written
* fresh (for iterative file handled arrays, when different data is needed)
*/
function clear_block_var($blockname)
{
if (strstr($blockname, '.'))
{
// i don't know how the heck this would be used, if ever.
// i can't think of a situation where it would be useful personally
// but, who knows... Only the top-level block makes sense to me
// Nested block.
$blocks = explode('.', $blockname);
$blockcount = sizeof($blocks) - 1;
$str = '$this->_tpldata';
for ($i = 0; $i < $blockcount; $i++)
{
$str .= '[\'' . $blocks[$i] . '.\']';
eval('$lastiteration = sizeof(' . $str . ') - 1;');
$str .= '[' . $lastiteration . ']';
}
// Now we add the block that we're actually assigning to.
// We're adding a new iteration to this block with the given
// variable assignments.
$str .= '[\'' . $blocks[$blockcount] . '.\'] = array();';
// Now we evaluate this assignment we've built up.
eval($str);
}
else
{
// Top-level block.
// Add a new iteration to this block with the variable assignments
// we were given.
$this->_tpldata[$blockname . '.'] = array();
}
return true;
}
}
//
//=============[ Events handler ]=========================
//
if ( defined('CM_EVENT') )
{
class cash_events
{
var $events;
function cash_events()
{
global $db;
$this->events = array();
$sql = "SELECT *
FROM " . CASH_EVENTS_TABLE;
if ( !$result = $db->sql_query($sql) )
{
message_die(CRITICAL_ERROR, "Could not query events information", "", __LINE__, __FILE__, $sql);
}
while ( $row = $db->sql_fetchrow($result) )
{
$this->events[$row['event_name']] = $row['event_data'];
}
}
function get_event_data($string)
{
global $board_config;
if ( $board_config['cash_disable'])
{
return array();
}
if ( isset($this->events[$string]) )
{
return cash_event_unpack($this->events[$string]);
}
else
{
return array();
}
}
}
$cm_events = new cash_events();
}
//
//=============[ Memberlist handler ]=========================
//
if ( defined('CM_MEMBERLIST') )
{
class cash_memberlist
{
function droplists(&$mode_types_text,&$mode_types)
{
global $board_config, $cash;
if ( $board_config['cash_disable'])
{
return;
}
while ( $c_cur = &$cash->currency_next($cm_i,CURRENCY_ENABLED | CURRENCY_VIEWMEMBERLIST) )
{
$mode_types_text[] = $c_cur->name(true);
$mode_types[] = 'cash_' . $c_cur->id();
}
}
function modecheck($mode)
{
global $board_config, $cash;
if ( $board_config['cash_disable'])
{
return 'cash_mod';
}
while ( $c_cur = &$cash->currency_next($cm_i,CURRENCY_ENABLED | CURRENCY_VIEWMEMBERLIST) )
{
if ( $mode == 'cash_' . $c_cur->id() )
{
return $mode;
}
}
return 'cash_mod';
}
function getfield($mode)
{
global $cash;
$id = substr($mode,5);
$c_cur = &$cash->currency($id);
return $c_cur->db();
}
function generate_columns(&$template,&$sql,$num_columns = 8)
{
global $board_config, $cash;
if ( $board_config['cash_disable'] )
{
$template->assign_var('NUM_COLUMNS',$num_columns);
return;
}
// whee! now that we have the $template, we can do whatever we want with it! yay!
$cash_field = "";
$count = $cash->currency_count(CURRENCY_ENABLED | CURRENCY_VIEWMEMBERLIST);
$template->assign_var('NUM_COLUMNS',$count + $num_columns);
while ( $c_cur = &$cash->currency_next($cm_i,CURRENCY_ENABLED | CURRENCY_VIEWMEMBERLIST) )
{
$template->assign_block_vars('cashrow',array('NAME' => $c_cur->name()));
$cash_field .= $c_cur->db() . ', ';
}
if ( strstr($sql,'*') )
{
return;
}
$insertpoint = strpos($sql,'user_id');
$sql = substr($sql,0,$insertpoint) . $cash_field . substr($sql,$insertpoint);
}
function listing(&$template,&$row)
{
global $board_config, $cash;
if ( $board_config['cash_disable'])
{
return;
}
while ( $c_cur = &$cash->currency_next($cm_i,CURRENCY_ENABLED | CURRENCY_VIEWMEMBERLIST) )
{
$template->assign_block_vars('memberrow.cashrow', array('CASH_DISPLAY' => $c_cur->display($row[$c_cur->db()])));
}
}
}
$cm_memberlist = new cash_memberlist();
}
//
//=============[ Viewtopic handler ]=========================
//
if ( defined('CM_VIEWTOPIC') )
{
class cash_viewtopic
{
var $template;
function generate_columns(&$template,$forum_id,&$sql)
{
global $board_config, $cash;
if ( $board_config['cash_disable'])
{
return '';
}
$this->template = new Template_plus();
$this->template->set($template);
$this->template->set_filenames(array(
'cm_viewtopic' => 'cash_viewtopic.tpl')
);
if ( strstr($sql,'u.*') )
{
return;
}
$cash_field = "";
while ( $c_cur = &$cash->currency_next($cm_i,CURRENCY_ENABLED | CURRENCY_VIEWTOPIC,$forum_id) )
{
$cash_field .= 'u.' . $c_cur->db() . ', ';
}
$insertpoint = strpos($sql,'u.user_id');
$sql = substr($sql,0,$insertpoint) . $cash_field . substr($sql,$insertpoint);
}
function post_vars(&$postdata,&$userdata,$forum_id)
{
$template = &$this->template;
global $board_config, $lang, $phpEx, $cash;
if ( $board_config['cash_disable'])
{
return;
}
$mask = false;
if ( $userdata['user_level'] != ADMIN )
{
$mask = CURRENCY_ENABLED;
if ( $postdata['user_id'] != $userdata['user_id'] )
{
$mask &= CURRENCY_VIEWTOPIC;
}
}
else
{
$forum_id = false;
}
while ( $c_cur = &$cash->currency_next($cm_i,$mask,$forum_id) )
{
$template->assign_block_vars('cashrow',array( 'CASH_DISPLAY' => $c_cur->display($postdata[$c_cur->db()])));
}
if ( ($cash->currency_count(CURRENCY_ENABLED | CURRENCY_EXCHANGEABLE) >= 2) && $userdata['session_logged_in'] )
{
$template->assign_block_vars('cashlinks',array( 'U_LINK' => append_sid("cash.$phpEx"),
'L_NAME' => $lang['Exchange']));
}
if ( $cash->currency_count(CURRENCY_ENABLED | CURRENCY_DONATE,$forum_id) && ($userdata['user_id'] != $postdata['user_id']) && $userdata['session_logged_in'] )
{
$template->assign_block_vars('cashlinks',array( 'U_LINK' => append_sid('cash.'.$phpEx.'?mode=donate&ref=viewtopic&'.POST_USERS_URL.'='.$postdata['user_id'].'&'.POST_POST_URL.'='.$postdata['post_id']),
'L_NAME' => $lang['Donate']));
}
if ( $cash->currency_count() && (($userdata['user_level'] == ADMIN) || (($userdata['user_level'] == MOD) && $cash->currency_count(CURRENCY_ENABLED | CURRENCY_MODEDIT | CURRENCY_VIEWTOPIC, $forum_id))) )
{
$template->assign_block_vars('cashlinks',array( 'U_LINK' => append_sid('cash.'.$phpEx.'?mode=modedit&ref=viewtopic&'.POST_USERS_URL.'='.$postdata['user_id'].'&'.POST_POST_URL.'='.$postdata['post_id']),
'L_NAME' => sprintf($lang['Mod_usercash'],$postdata['username'])));
}
$template->assign_block_var_from_handle('postrow.CASH', 'cm_viewtopic');
$template->clear_block_var('cashrow');
$template->clear_block_var('cashlinks');
}
}
$cm_viewtopic = new cash_viewtopic();
}
//
//=============[ Viewprofile handler ]=========================
//
if ( defined('CM_VIEWPROFILE') )
{
class cash_viewprofile
{
function post_vars(&$old_template,&$profiledata,&$userdata)
{
global $board_config, $lang, $phpEx, $cash;
if ( $board_config['cash_disable'])
{
return;
}
$template = new Template_plus();
$template->set($old_template);
$mask = false;
if ( $userdata['user_level'] != ADMIN )
{
$mask = CURRENCY_ENABLED;
if ( $profiledata['user_id'] != $userdata['user_id'] )
{
$mask &= CURRENCY_VIEWPROFILE;
}
}
$template->set_filenames(array(
'cm_viewprofile' => 'cash_viewprofile.tpl')
);
while ( $c_cur = &$cash->currency_next($cm_i,$mask) )
{
$template->assign_block_vars('cashrow', array( 'CASH_NAME' => $c_cur->name(),
'CASH_AMOUNT' => $profiledata[$c_cur->db()]));
}
if ( $userdata['session_logged_in'] && (($cash->currency_count(CURRENCY_ENABLED | CURRENCY_EXCHANGEABLE) >= 2) || ($cash->currency_count(CURRENCY_ENABLED | CURRENCY_DONATE) && ($userdata['user_id'] != $profiledata['user_id'])) || ($cash->currency_count() && (($userdata['user_level'] == ADMIN) || (($userdata['user_level'] == MOD) && $cash->currency_count(CURRENCY_ENABLED | CURRENCY_MODEDIT))))) )
{
$template->assign_block_vars('switch_cashlinkson',array());
if ( $cash->currency_count(CURRENCY_ENABLED | CURRENCY_EXCHANGEABLE) >= 2 )
{
$template->assign_block_vars('switch_cashlinkson.cashlinks',array( 'U_LINK' => append_sid("cash.$phpEx"),
'L_NAME' => $lang['Exchange']));
}
if ( $cash->currency_count(CURRENCY_ENABLED | CURRENCY_DONATE) && ($userdata['user_id'] != $profiledata['user_id']) )
{
$template->assign_block_vars('switch_cashlinkson.cashlinks',array( 'U_LINK' => append_sid('cash.'.$phpEx.'?mode=donate&ref=viewprofile&'.POST_USERS_URL.'='.$profiledata['user_id']),
'L_NAME' => $lang['Donate']));
}
if ( $cash->currency_count() && (($userdata['user_level'] == ADMIN) || (($userdata['user_level'] == MOD) && $cash->currency_count(CURRENCY_ENABLED | CURRENCY_MODEDIT))) )
{
$template->assign_block_vars('switch_cashlinkson.cashlinks',array( 'U_LINK' => append_sid('cash.'.$phpEx.'?mode=modedit&ref=viewprofile&'.POST_USERS_URL.'='.$profiledata['user_id']),
'L_NAME' => sprintf($lang['Mod_usercash'],$profiledata['username'])));
}
}
$template->assign_block_var_from_handle('CASH', 'cm_viewprofile');
}
}
$cm_viewprofile = new cash_viewprofile();
}
//
//=============[ Posting handler ]=========================
//
if ( defined('CM_POSTING') )
{
class cash_posting
{
function update_post($mode, &$post_data, $forum_id, $topic_id, $post_id, $topic_type, $bbcode_uid, $post_username, &$post_message)
{
global $board_config, $userdata;
if ( $board_config['cash_disable'] || (($mode != 'newtopic') && ($mode != 'reply') && ($mode != 'editpost')) )
{
return '';
}
$first_post = $post_data['first_post'];
$poster_id = $userdata['user_id'];
$old_message = '';
$new_bbcode = $bbcode_uid;
$old_bbcode = '';
if ( $mode == 'editpost' )
{
$poster_id = $post_data['poster_id'];
$old_message = &$post_data['post_text'];
$old_bbcode = $post_data['bbcode_uid'];
}
if ( $mode == 'reply' )
{
$topic_starter = $post_data['topic_poster'];
}
else
{
$topic_starter = false;
}
return $this->cash_update($mode, $poster_id, $first_post, $old_message, $post_message, $forum_id, $topic_id, $post_id, $new_bbcode, $topic_starter, $old_bbcode);
}
function update_delete($mode, &$post_data, $forum_id, $topic_id, $post_id)
{
global $board_config;
if ( $board_config['cash_disable'] || ($mode != 'delete') )
{
return;
}
$first_post = $post_data['first_post'];
$poster_id = $post_data['poster_id'];
$new_message = '';
$new_bbcode = '';
$old_bbcode = $post_data['bbcode_uid'];
$topic_starter = ANONYMOUS;
$this->cash_update($mode, $poster_id, $first_post, $post_data['post_text'], $new_message, $forum_id, $topic_id, $post_id, $new_bbcode, $topic_starter, $old_bbcode);
}
function cash_update($mode, $poster_id, $first_post, &$old_message, &$new_message, $forum_id, $topic_id, $post_id, $new_bbcode, $topic_starter, $old_bbcode)
{
global $board_config, $lang, $db, $phpbb_root_path, $phpEx, $userdata, $cash;
if ( ($mode == 'reply') && ($poster_id != $topic_starter) && ($topic_userdata = get_userdata($topic_starter)) )
{
$topic_creator = new cash_user($topic_starter,$topic_userdata);
$topic_creator->give_bonus($topic_id);
}
if ( $poster_id == ANONYMOUS )
{
return;
}
if ( $userdata['user_id'] == $poster_id )
{
$posting_user = new cash_user($userdata['user_id'], $userdata);
}
else
{
$posting_user = new cash_user($poster_id);
}
$all_active = true;
$forumcount = array();
$forumlist = array();
if ( (($mode == 'newtopic') || ($mode == 'reply')) && (intval($board_config['cash_disable_spam_num']) > 0) )
{
$all_active = false;
$interval = time() - (3600 * intval($board_config['cash_disable_spam_time']));
$sum = 0;
$sql = "SELECT forum_id, count(post_id) as postcount
FROM " . POSTS_TABLE . "
WHERE poster_id = $poster_id
AND post_time > $interval
GROUP BY forum_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error retrieving post data', '', __LINE__, __FILE__, $sql);
}
while ( $row = $db->sql_fetchrow($result) )
{
$forumlist[] = $row['forum_id'];
$forumcount[$row['forum_id']] = $row['postcount'];
$sum += $row['postcount'];
}
if ( $sum < $board_config['cash_disable_spam_num'] )
{
$all_active = true;
}
}
$new_len = array(strlen($new_message),cash_quotematch($new_message,$new_bbcode));
$old_len = array(strlen($old_message),cash_quotematch($old_message,$old_bbcode));
$sql_clause = array();
$message_clause = array();
$reply_bonus = array();
$all_spam = !$all_active;
while ( $c_cur = &$cash->currency_next($cm_i,CURRENCY_ENABLED,$forum_id) )
{
$this_enabled = $all_active;
if ( !$all_active )
{
$sum = 0;
for ( $i = 0; $i < count($forumlist); $i++ )
{
if ( $c_cur->forum_active($forumlist[$i]) )
{
$sum += $forumcount[$forumlist[$i]];
}
}
if ( $sum < $board_config['cash_disable_spam_num'] )
{
$this_enabled = true;
$all_spam = false;
}
}
if ( $this_enabled )
{
$base = ( $first_post ) ? $posting_user->get_setting($c_cur->id(),'cash_perpost') : $posting_user->get_setting($c_cur->id(),'cash_perreply');
$perchar = $posting_user->get_setting($c_cur->id(),'cash_perchar',PERCHAR_DEC_BONUS);
$max = $posting_user->get_setting($c_cur->id(),'cash_maxearn');
$quotes = ( $c_cur->mask(CURRENCY_INCLUDEQUOTES) ) ? 0 : 1;
$total_added = ( $mode != 'delete' ) ? min($max,$base + ($perchar * $new_len[$quotes])) : 0;
$total_removed = ( ($mode != 'newtopic') && ($mode != 'reply') ) ? min($max,$base + ($perchar * $old_len[$quotes])) : 0;
$total_change = $total_added - $total_removed;
if ( $total_change != 0 )
{
$change_sign = ($total_change > 0);
$change_amount = ( ( $change_sign ) ? $total_change : (-$total_change) );
$change_sign = ( ( $change_sign ) ? " + " : " - " );
$sql_clause[] = $c_cur->db() . " = " . $c_cur->db() . $change_sign . $change_amount;
$message_clause[] = $c_cur->display($change_amount);
}
}
}
if ( $all_spam )
{
return $board_config['cash_disable_spam_message'];
}
if ( count($sql_clause) > 0 )
{
$sql = "UPDATE " . USERS_TABLE . "
SET " . implode(', ',$sql_clause) . "
WHERE user_id = " . $poster_id;
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Error in updating cash', '', __LINE__, __FILE__, $sql);
}
}
return ( ($userdata['user_id'] == $poster_id) && ($board_config['cash_display_after_posts'] == 1) ) ? sprintf($board_config['cash_post_message'],implode(', ',$message_clause)) : '';
}
}
$cm_posting = new cash_posting();
}
//
//=============[ END Page-Specific Classes ]=========================
//
?>
#########################################################################################################