Index: branches/unlabeled/unlabeled-1.2.20/kernel/include/statitem.php
===================================================================
diff -u -r3393 -r6504
--- branches/unlabeled/unlabeled-1.2.20/kernel/include/statitem.php (.../statitem.php) (revision 3393)
+++ branches/unlabeled/unlabeled-1.2.20/kernel/include/statitem.php (.../statitem.php) (revision 6504)
@@ -3,7 +3,7 @@
{
var $GotValue;
var $TagCache = Array(); // parsed tag (in sql queries only) values are cached
-
+
var $CurrentSQL = ''; // sql query being currently processed
var $PostFormatting = false; // apply formatting to sql query results
var $PostFormattingParams = Array(); // post formatting params if any
@@ -14,21 +14,21 @@
$this->id_field = "StatItemId";
$this->NoResourceId = 1;
$this->GotValue = FALSE;
-
+
if($id)
$this->LoadFromDatabase($id);
}
-
-
+
+
function LoadFromDatabase($Id)
{
global $Errors;
-
+
if(!isset($Id))
{
$Errors->AddError("error.AppError",NULL,'Internal error: LoadFromDatabase id',"",get_class($this),"LoadFromDatabase");
return false;
- }
+ }
$sql = sprintf("SELECT * FROM ".$this->tablename." WHERE ".$this->IdField()." = '%s'",$Id);
$result = $this->adodbConnection->Execute($sql);
if ($result === false)
@@ -41,7 +41,7 @@
$this->SetFromArray($data);
return true;
- }
+ }
function ExecuteResetSQL()
{
@@ -53,29 +53,29 @@
function ExecuteValueSQL()
{
global $ADODB_FETCH_MODE;
-
- $ADODB_FETCH_MODE = 3;
+
+ $ADODB_FETCH_MODE = 3;
$this->CurrentSQL = $this->Get("ValueSQL");
-
+
// 1. replace prefix to actual one
$this->CurrentSQL = str_replace("<%prefix%>", GetTablePrefix(), $this->CurrentSQL);
-
- // 2. replace config variable to it's value
- while( ($tag = $this->FindTag()) != false )
- {
- if( !array_key_exists( trim($tag), $this->TagCache ) )
- {
- // unprocessed tag -> parse it to get result
- $this->TagCache[ trim($tag) ] = $this->ProcessTag($tag);
- }
-
- $tagResult = $this->TagCache[ trim($tag) ]; // return result from cache
- $this->CurrentSQL = str_replace('<%'.$tag.'%>', $tagResult, $this->CurrentSQL);
- }
-
+
+ // 2. replace config variable to it's value
+ while( ($tag = $this->FindTag()) != false )
+ {
+ if( !array_key_exists( trim($tag), $this->TagCache ) )
+ {
+ // unprocessed tag -> parse it to get result
+ $this->TagCache[ trim($tag) ] = $this->ProcessTag($tag);
+ }
+
+ $tagResult = $this->TagCache[ trim($tag) ]; // return result from cache
+ $this->CurrentSQL = str_replace('<%'.$tag.'%>', $tagResult, $this->CurrentSQL);
+ }
+
$values = array();
$rs = $this->adodbConnection->Execute($this->CurrentSQL);
- if($rs && !$rs->EOF)
+ if($rs && !$rs->EOF)
{
$value = $rs->fields[0];
if($this->PostFormatting)
@@ -85,7 +85,7 @@
case 'number': // simple-specific postformatting
$value = LangNumber($value, $this->PostFormattingParams['precision']);
break;
-
+
// extended postformatting
case 'COUNT':
$value = $rs->RecordCount();
@@ -96,7 +96,7 @@
while(!$rs->EOF)
{
$field_sum += $rs->fields[ $this->PostFormattingParams['field'] ];
- $rs->MoveNext();
+ $rs->MoveNext();
}
$value = $field_sum;
if($this->PostFormattingParams['format_as'] == 'file') $value = size($value);
@@ -105,7 +105,7 @@
case 'SysFileSize':
$value = size( dir_size($GLOBALS['pathtoroot']) );
break;
-
+
default: // simple-default postformatting
$value = adodb_date($this->PostFormatting, $value);
break;
@@ -115,7 +115,7 @@
}
$this->Set("Value", $value);
}
- $ADODB_FETCH_MODE = 2;
+ $ADODB_FETCH_MODE = 2;
$this->GotValue=TRUE;
}
@@ -132,7 +132,7 @@
}
return false;
}
-
+
function ProcessTag($tag)
{
$db =& $this->adodbConnection;
@@ -151,90 +151,90 @@
$sql = 'SELECT VariableValue FROM '.GetTablePrefix()."ConfigurationValues WHERE VariableName = '%s'";
return $db->GetOne( sprintf($sql, $tag_params['name']) );
break;
-
+
case 'm:post_format':
switch($tag_params['type'])
{
case 'date': $this->PostFormatting = GetDateFormat(); break;
case 'time': $this->PostFormatting = GetTimeFormat(); break;
- case 'currency':
+ case 'currency':
$this->PostFormatting = 'number';
$this->PostFormattingParams['precision'] = $tag_params['precision'];
break;
}
return $tag_params['field'];
break;
-
+
case 'm:custom_action':
$this->PostFormatting = $tag_params['action'];
return ($tag_params['sql'] == 'empty') ? 'SELECT 1' : $tag_params['sql'];
break;
-
+
//m:sql_action sql="SHOW TABLES" action="COUNT" field="*"
case 'm:sql_action':
$this->PostFormatting = $tag_params['action'];
$this->PostFormattingParams = $tag_params;
return $tag_params['sql'];
break;
-
+
case 'link:hit_count':
$type = $tag_params['type'];
$sql = 'SELECT Hits FROM '.GetTablePrefix().'Link ';
if($type == 'top') // by now only top is supported
- {
- $top_links_count = $this->ProcessTag('m:config name="Link_TopCount"'); // 5 - default
+ {
+ $top_links_count = $this->ProcessTag('m:config name="Link_MinPopRating"'); // 5 - default
$sql .= 'ORDER BY Hits DESC LIMIT 0,'.$top_links_count;
-
+
$rs = $db->Execute($sql);
if($rs->RecordCount() > 0)
{
$rs->MoveLast();
- return $rs->fields['Hits'];
+ return $rs->fields['Hits'];
}
else
return 0;
}
break;
-
+
case 'article:hit_count':
$type = $tag_params['type'];
$sql = 'SELECT CachedRating FROM '.GetTablePrefix().'News ';
if($type == 'top') // by now only top is supported
- {
- $top_articles_count = $this->ProcessTag('m:config name="News_VotesToHot"');
- $min_votes = $this->ProcessTag('m:config name="News_MinVotes"');
+ {
+ $top_articles_count = $this->ProcessTag('m:config name="News_MaxHotNumber"');
+ $min_votes = $this->ProcessTag('m:config name="News_MinPopVotes"');
$sql .= 'WHERE CachedVotesQty > '.$min_votes.' ORDER BY CachedRating DESC LIMIT 0,'.$top_articles_count;
-
+
$rs = $db->Execute($sql);
if($rs->RecordCount() > 0)
{
$rs->MoveLast();
- return $rs->fields['CachedRating'];
+ return $rs->fields['CachedRating'];
}
else
return 0;
}
- break;
-
+ break;
+
case 'topic:hit_count':
$type = $tag_params['type'];
$sql = 'SELECT Views FROM '.GetTablePrefix().'Topic ';
if($type == 'top') // by now only top is supported
- {
- $top_posts_count = $this->ProcessTag('m:config name="Topic_PostsToPop"');
+ {
+ $top_posts_count = $this->ProcessTag('m:config name="Topic_MinPopRating"');
$sql .= ' ORDER BY Views DESC LIMIT 0,'.$top_posts_count;
-
+
$rs = $db->Execute($sql);
if($rs->RecordCount() > 0)
{
$rs->MoveLast();
- return $rs->fields['Views'];
+ return $rs->fields['Views'];
}
else
return 0;
}
break;
-
+
case 'modules:get_current':
return $this->Get('Module');
break;
@@ -253,11 +253,11 @@
{
return $this->parsetag($element->name);
}
-
+
function parsetag($tag)
{
if(is_object($tag))
- {
+ {
$tagname = $tag->name;
}
else
@@ -300,7 +300,7 @@
{
// fills list with data
$this->LoadStatItems($where,$orderBy, $use_limit );
-
+
for($i=0; $i < $this->NumItems(); $i++)
{
$s =& $this->GetItemRefByIndex($i);
@@ -314,14 +314,14 @@
for($i=0;$i<$this->NumItems();$i++)
{
$s =& $this->GetItemRefByIndex($i);
- $s->ExecuteValueSQL();
+ $s->ExecuteValueSQL();
}
if($this->debuglevel) echo "LastSQL: ".$s->CurrentSQL.'
';
}
function ExecuteResetSQL()
{
- foreach($this->Items as $s) $s->ExecuteResetSQL();
+ foreach($this->Items as $s) $s->ExecuteResetSQL();
}
function LoadStatItems($where=NULL,$orderBy, $use_limit = false)
@@ -333,10 +333,10 @@
$sql .= " WHERE ".$where;
if(strlen(trim($orderBy)))
$sql .= " ORDER BY ".$orderBy;
-
+
if($use_limit)
$sql .= " ".GetLimitSQL($this->Page,$objConfig->Get($this->PerPageVar));
-
+
if($this->debuglevel) echo "StatGetSQL: $sql
";
$this->Query_Item($sql);
}