Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Tue, Mar 11, 11:06 AM

in-portal

Index: branches/RC/kernel/units/reviews/reviews_event_handler.php
===================================================================
--- branches/RC/kernel/units/reviews/reviews_event_handler.php (revision 9474)
+++ branches/RC/kernel/units/reviews/reviews_event_handler.php (revision 9475)
@@ -1,346 +1,346 @@
<?php
class ReviewsEventHandler extends kDBEventHandler
{
/**
* Get's special of main item for linking with subitem
*
* @param kEvent $event
* @return string
*/
function getMainSpecial(&$event)
{
if ($event->Special == 'product' && !$this->Application->IsAdmin()) {
// rev.product should auto-link
return '';
}
return parent::getMainSpecial($event);
}
/**
* Checks REVIEW/REVIEW.PENDING permission by main object primary category (not current category)
*
* @param kEvent $event
*/
function CheckPermission(&$event)
{
if ($event->Name == 'OnAddReview' || $event->Name == 'OnCreate') {
$perm_helper =& $this->Application->recallObject('PermissionsHelper');
/* @var $perm_helper kPermissionsHelper */
$parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix');
$main_object =& $this->Application->recallObject($parent_prefix);
/* @var $main_object kCatDBItem */
$perm_name = $this->getPermPrefix($event).'.REVIEW';
$res = $this->Application->CheckPermission($perm_name, 0, $main_object->GetDBField('CategoryId')) ||
$this->Application->CheckPermission($perm_name.'.PENDING', 0, $main_object->GetDBField('CategoryId'));
if (!$res) {
$event->status = erPERM_FAIL;
}
return $res;
}
return parent::CheckPermission($event);
}
/**
* Returns prefix for permissions
*
* @param kEvent $event
*/
function getPermPrefix(&$event)
{
$main_prefix = $this->Application->GetTopmostPrefix($event->Prefix);
// this will return LINK for l, ARTICLE for n, TOPIC for bb, PRODUCT for p
$item_prefix = $this->Application->getUnitOption($main_prefix, 'PermItemPrefix');
return $item_prefix;
}
/**
* Apply any custom changes to list's sql query
*
* @param kEvent $event
* @access protected
* @see OnListBuild
*/
function SetCustomQuery(&$event)
{
$object =& $event->getObject();
/* @var $object kDBList */
if (!$this->Application->IsAdmin()) {
$object->addFilter('active', '%1$s.Status = '.STATUS_ACTIVE);
}
switch ($event->Special)
{
case 'showall':
$object->clearFilters();
break;
case 'item': // used ?
$object->clearFilters();
$info = $object->getLinkedInfo();
$this->Application->setUnitOption($info['ParentPrefix'], 'AutoLoad', true);
$parent =& $this->Application->recallObject($info['ParentPrefix']);
$object->addFilter('item_reviews', '%1$s.ItemId = '.$parent->GetDBField('ResourceId'));
break;
- case 'products': // used ?
+ case 'products': // used in In-Portal (Sturcture & Data -> Reviews section)
$object->removeFilter('parent_filter'); // this is important
-// $object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId');
+ $object->addFilter('product_reviews', 'pr.ResourceId IS NOT NULL');
break;
/*case 'product':
$object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId'); // for LEFT JOIN
break;*/
}
if ($event->getEventParam('type') == 'current_user') {
// $object->removeFilter('active');
$object->addFilter('current_user', '%1$s.CreatedById = '.$this->Application->RecallVar('user_id'));
$object->addFilter('current_ip', '%1$s.IPAddress = "'.$_SERVER['REMOTE_ADDR'].'"');
}
}
/**
* Adds review from front in case if user is logged in
*
* @param kEvent $event
*/
function OnAddReview(&$event)
{
$event->CallSubEvent('OnCreate');
}
/**
* Get new review status on user review permission
*
* @param kEvent $event
* @return int
*/
function getReviewStatus(&$event)
{
$parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix');
$main_object =& $this->Application->recallObject($parent_prefix);
/* @var $main_object kCatDBItem */
$ret = STATUS_DISABLED;
$perm_name = $this->getPermPrefix($event).'.REVIEW';
if ($this->Application->CheckPermission($perm_name, 0, $main_object->GetDBField('CategoryId'))) {
$ret = STATUS_ACTIVE;
}
else if ($this->Application->CheckPermission($perm_name.'.PENDING', 0, $main_object->GetDBField('CategoryId'))) {
$ret = STATUS_PENDING;
}
return $ret;
}
/**
* Prefills all fields on front-end
*
* @param kEvent $event
*/
function OnBeforeItemCreate(&$event)
{
$object =& $event->getObject();
/* @var $object kDBItem */
$parent_info = $object->getLinkedInfo();
$item_type = $this->Application->getUnitOption($parent_info['ParentPrefix'], 'ItemType');
$object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']);
$object->SetDBField('ItemType', $item_type);
$object->SetDBField('Module', $this->Application->findModule('Var', $parent_info['ParentPrefix'], 'Name'));
if ($this->Application->IsAdmin()) {
return ;
}
$spam_helper =& $this->Application->recallObject('SpamHelper');
/* @var $spam_helper SpamHelper */
$spam_helper->InitHelper($parent_info['ParentId'], 'Review', 0);
if ($spam_helper->InSpamControl()) {
$event->status = erFAIL;
$object->SetError('ReviewText', 'too_frequent', 'lu_ferror_review_duplicate');
return ;
}
$rating = $object->GetDBField('Rating');
if ($rating < 1 || $rating > 5) {
$object->SetDBField('Rating', null);
}
$object->SetDBField('ItemId', $parent_info['ParentId']); // ResourceId
$object->SetDBField('CreatedById', $this->Application->RecallVar('user_id'));
$object->SetDBField('Status', $this->getReviewStatus($event));
$object->SetDBField('TextFormat', 0); // set plain text format directly
}
/**
* Sets correct rating value
*
* @param kEvent $event
*/
function OnBeforeItemUpdate(&$event)
{
$object =& $event->getObject();
$rating = $object->GetDBField('Rating');
if (!$rating) {
$object->SetDBField('Rating', null);
}
}
/**
* Updates item review counter
*
* @param kEvent $event
*/
function OnAfterItemCreate(&$event)
{
$this->updateSubitemCounters($event);
if (!$this->Application->IsAdmin()) {
$spam_helper =& $this->Application->recallObject('SpamHelper');
/* @var $spam_helper SpamHelper */
$object =& $event->getObject();
$parent_info = $object->getLinkedInfo();
$config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping');
$review_settings = $config_mapping['ReviewDelayValue'].':'.$config_mapping['ReviewDelayInterval'];
$spam_helper->InitHelper($parent_info['ParentId'], 'Review', $review_settings);
$spam_helper->AddToSpamControl();
}
}
/**
* Updates item review counter
*
* @param kEvent $event
*/
function OnAfterItemUpdate(&$event)
{
$this->updateSubitemCounters($event);
}
/**
* Updates total review counter, cached rating, votes count
*
* @param kEvent $event
*/
function updateSubitemCounters(&$event)
{
$parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix');
$main_object =& $this->Application->recallObject($parent_prefix, null, Array ('raise_warnings' => 0));
/* @var $main_object kCatDBItem */
if (!$main_object->isLoaded()) {
// deleting main item / cloning main item
return ;
}
$object =& $event->getObject(); // for temp tables
/* @var $object kDBItem */
// 1. update review counter
$sql = 'SELECT COUNT(ReviewId)
FROM '.$object->TableName.'
WHERE ItemId = '.$main_object->GetDBField('ResourceId');
$review_count = $this->Conn->GetOne($sql);
$main_object->SetDBField('CachedReviewsQty', $review_count);
// 2. update votes counter + rating
$rating = $object->GetDBField('Rating');
$avg_rating = $main_object->GetDBField('CachedRating');
$votes_count = $main_object->GetDBField('CachedVotesQty');
switch ($event->Name) {
case 'OnAfterItemCreate': // adding new review with rating
$this->changeRating($avg_rating, $votes_count, $rating, '+');
break;
case 'OnAfterItemDelete':
$this->changeRating($avg_rating, $votes_count, $rating, '-');
break;
case 'OnAfterItemUpdate':
$this->changeRating($avg_rating, $votes_count, $object->GetOriginalField('Rating'), '-');
$this->changeRating($avg_rating, $votes_count, $rating, '+');
break;
}
$main_object->SetDBField('CachedRating', $avg_rating);
$main_object->SetDBField('CachedVotesQty', $votes_count);
$main_object->Update();
}
/**
* Changes average rating and votes count based on requested operation
*
* @param float $avg_rating average rating before new vote
* @param int $votes_count votes count before new vote
* @param int $rating new vote (from 1 to 5)
* @param string $operation requested operation (+ / -)
*/
function changeRating(&$avg_rating, &$votes_count, $rating, $operation)
{
if ($rating < 1 || $rating > 5) {
return ;
}
if ($operation == '+') {
$avg_rating = (($avg_rating * $votes_count) + $rating) / ($votes_count + 1);
++$votes_count;
}
else {
$avg_rating = (($avg_rating * $votes_count) - $rating) / ($votes_count - 1);
--$votes_count;
}
}
/**
* Updates main item cached review counter
*
* @param kEvent $event
*/
function OnAfterItemDelete(&$event)
{
$this->updateSubitemCounters($event);
}
/**
* Creates review & redirect to confirmation template
*
* @param kEvent $event
*/
function OnCreate(&$event)
{
parent::OnCreate($event);
if ($event->status != erSUCCESS || $this->Application->IsAdmin()) {
return ;
}
$object =& $event->getObject();
$next_template = $object->GetDBField('Status') == STATUS_ACTIVE ? 'success_template' : 'success_pending_template';
$event->redirect = $this->Application->GetVar($next_template);
$event->SetRedirectParam('opener', 's');
$parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix');
$event->SetRedirectParam('pass', 'm,'.$parent_prefix);
}
}
?>
\ No newline at end of file
Property changes on: branches/RC/kernel/units/reviews/reviews_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.14.2.1
\ No newline at end of property
+1.14.2.2
\ No newline at end of property
Index: branches/RC/admin/reviews.php
===================================================================
--- branches/RC/admin/reviews.php (revision 9474)
+++ branches/RC/admin/reviews.php (revision 9475)
@@ -1,312 +1,315 @@
<?php
##############################################################
##In-portal ##
##############################################################
## In-portal ##
## Intechnic Corporation ##
## All Rights Reserved, 1998-2002 ##
## ##
## No portion of this code may be copied, reproduced or ##
## otherwise redistributed without proper written ##
## consent of Intechnic Corporation. Violation will ##
## result in revocation of the license and support ##
## privileges along maximum prosecution allowed by law. ##
##############################################################
-function k4getmicrotime()
-{
- list($usec, $sec) = explode(" ", microtime());
- return ((float)$usec + (float)$sec);
-}
+function k4getmicrotime()
+{
+ list($usec, $sec) = explode(" ", microtime());
+ return ((float)$usec + (float)$sec);
+}
$start = k4getmicrotime();
// new startup: begin
define('REL_PATH', 'admin');
$relation_level = count( explode('/', REL_PATH) );
define('FULL_PATH', realpath(dirname(__FILE__) . str_repeat('/..', $relation_level) ) );
require_once FULL_PATH.'/kernel/startup.php';
// new startup: end
checkViewPermission('in-portal:reviews');
define('REQUIRE_LAYER_HEADER', 1);
$b_topmargin = "0";
//$b_header_addon = "<DIV style='position:relative; z-Index: 1; background-color: #ffffff; padding-top:1px;'><div style='position:absolute; width:100%;top:0px;' align='right'><img src='images/logo_bg.gif'></div><img src='images/spacer.gif' width=1 height=15><br><div style='z-Index:1; position:relative'>";
require_login();
$indexURL = $rootURL."index.php";
$homeURL = "javascript:AdminCatNav('".$_SERVER["PHP_SELF"]."?env=".BuildEnv()."');";
$m_var_list_update["cat"] = 0;
unset($m_var_list_update["cat"]);
//admin only util
$pathtolocal = $pathtoroot."kernel/";
require_once ($pathtoroot.$admin."/include/elements.php");
//require_once ($pathtoroot."kernel/admin/include/navmenu.php");
require_once ($pathtolocal."admin/include/navmenu.php");
require_once($pathtoroot.$admin."/browse/toolbar.php");
$mod_prefixes = Array();
$m = GetModuleArray();
foreach($m as $key=>$value)
{
$path = $pathtoroot.$value."admin/include/parser.php";
if(file_exists($path))
{
//echo "<!-- $path -->";
$mod_prefixes[] = $key;
@include_once($path);
}
}
$application->InitParser();
$cat_templates = $objModules->ExecuteFunction('GetModuleInfo', 'reviews_template');
foreach ($cat_templates as $a_mod => $a_template) {
if (!$a_template) continue;
$a_var = $a_mod.'_TAB_HTML';
$$a_var = $application->ParseBlock(Array('name'=>$a_template), 0, true);
}
if( !defined('IS_INSTALL') ) define('IS_INSTALL', 0);
if( !IS_INSTALL ) require_login();
//Set Section
$section = 'in-portal:reviews';
//Set Environment Variable
// save last category visited
$objSession->SetVariable('prev_category', $objSession->GetVariable('last_category') );
$objSession->SetVariable('last_category', $objCatList->CurrentCategoryID() );
$objSession->SetVariable("HasChanges", 0);
// where should all edit popups submit changes
$objSession->SetVariable("ReturnScript", basename($_SERVER['PHP_SELF']) );
// common "Advanced View" tab php functions: begin
function GetAdvView_SearchWord($prefix,$postfix='_adv_view_search')
{
global $objSession;
return $objSession->GetVariable($prefix.$postfix);
}
function SaveAdvView_SearchWord($prefix,$postfix='_adv_view_search')
{
global $objSession;
$SearchWord = $objSession->GetVariable($prefix.$postfix);
if( isset($_REQUEST['SearchWord']) )
- {
+ {
$SearchWord = $_REQUEST['SearchWord'];
$objSession->SetVariable($prefix.$postfix, $SearchWord);
}
}
function ResetAdvView_SearchWord($prefix,$postfix='_adv_view_search')
{
global $objSession;
$objSession->SetVariable($prefix.$postfix, '');
}
function ShowSearchForm($prefix, $envar, $TabID, $postfix='_adv_view_search')
{
global $imagesURL;
$btn_prefix = $imagesURL.'/toolbar/icon16_search';
$SearchWord = GetAdvView_SearchWord($prefix,$postfix);
echo '<form method="post" action="'.$_SERVER["PHP_SELF"].'?'.$envar.'" name="'.$prefix.'_adv_view_search" id="'.$prefix.$postfix.'">
<input type="hidden" name="Action" value="">
<table cellspacing="0" cellpadding="0">
<tr>
<td>'.admin_language('la_SearchLabel').'&nbsp;</td>
<td><input id="'.$prefix.'_SearchWord" type="text" value="'.inp_htmlize($SearchWord,1).'" name="SearchWord" size="10" style="border-width: 1; border-style: solid; border-color: 999999"></td>
<td>
- <img
- id="'.$TabID.'_imgSearch"
- src="'.$btn_prefix.'.gif"
- title="'.admin_language("la_ToolTip_Search").'"
+ <img
+ id="'.$TabID.'_imgSearch"
+ src="'.$btn_prefix.'.gif"
+ title="'.admin_language("la_ToolTip_Search").'"
align="absMiddle"
onclick="SubmitSearch(\''.$prefix.$postfix.'\',\''.$prefix.$postfix.'\');"
- onmouseover="this.src=\''.$btn_prefix.'_f2.gif\'"
- onmouseout="this.src=\''.$btn_prefix.'.gif\'"
- style="cursor:hand"
- width="22"
+ onmouseover="this.src=\''.$btn_prefix.'_f2.gif\'"
+ onmouseout="this.src=\''.$btn_prefix.'.gif\'"
+ style="cursor:hand"
+ width="22"
height="22"
>
- <img
- id="imgSearchReset"
- src="'.$btn_prefix.'_reset.gif"
- title="'.admin_language("la_ToolTip_Search").'"
+ <img
+ id="imgSearchReset"
+ src="'.$btn_prefix.'_reset.gif"
+ title="'.admin_language("la_ToolTip_Search").'"
align="absMiddle"
onclick="SubmitSearch(\''.$prefix.$postfix.'\',\''.$prefix.$postfix.'_reset\');"
- onmouseover="this.src=\''.$btn_prefix.'_reset_f2.gif\'"
- onmouseout="this.src=\''.$btn_prefix.'_reset.gif\'"
- style="cursor:hand"
+ onmouseover="this.src=\''.$btn_prefix.'_reset_f2.gif\'"
+ onmouseout="this.src=\''.$btn_prefix.'_reset.gif\'"
+ style="cursor:hand"
width="22"
- height="22"
- >&nbsp;
-
-
+ height="22"
+ >&nbsp;
+
+
</td>
</tr>
</table>
</form>
<script language="javascript">
document.getElementById("'.$prefix.'_SearchWord").onkeydown = getKey;
</script>
-
+
';
}
// common "Advanced View" tab php functions: end
/* page header */
$charset = GetRegionalOption('Charset');
+$base_href = $application->ProcessParsedTag('m', 'Base_Ref', Array());
+
print <<<END
<html>
<head>
<title>In-portal</title>
+ $base_href
<meta http-equiv="content-type" content="text/html;charset=$charset">
<meta http-equiv="Pragma" content="no-cache">
<script language="JavaScript">
imagesPath='$imagesURL'+'/';
- </script>
+ </script>
END;
require_once($pathtoroot.$admin."/include/mainscript.php");
print <<<END
<script type="text/javascript">
if (window.opener != null) {
theMainScript.CloseAndRefreshParent();
- }
+ }
</script>
END;
print <<<END
<script src="$browseURL/toolbar.js"></script>
<script src="$browseURL/checkboxes_new.js"></script>
<script language="JavaScript1.2" src="$browseURL/fw_menu.js"></script>
<link rel="stylesheet" type="text/css" href="$browseURL/checkboxes.css">
<link rel="stylesheet" type="text/css" href="$cssURL/style.css">
<link rel="stylesheet" type="text/css" href="$browseURL/toolbar.css">
END;
load_module_styles();
if( !isset($list) ) $list = '';
int_SectionHeader();
$filter = false;
$bit_combo = $objModules->ExecuteFunction('GetModuleInfo', 'all_bitmask');
$bit_combo = $objModules->MergeReturn($bit_combo);
foreach($bit_combo['VarName'] as $mod_name => $VarName)
{
//echo "VarName: [$VarName] = [".$objConfig->Get($VarName)."], ALL = [".$bit_combo['Bits'][$mod_name]."]<br>";
if( $objConfig->Get($VarName) )
if( $objConfig->Get($VarName) != $bit_combo['Bits'][$mod_name] )
{
$filter = true;
- break;
+ break;
}
}
?>
</div>
<!-- alex mark -->
<table class="toolbar" height="30" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td>
<div name="toolBar" id="mainToolBar">
<tb:button action="edit" title="<?php echo admin_language("la_ToolTip_Edit"); ?>" ImagePath="<?php echo $imagesURL."/toolbar/";?>">
<tb:button action="delete" title="<?php echo admin_language("la_ToolTip_Delete"); ?>" ImagePath="<?php echo $imagesURL."/toolbar/";?>">
<tb:separator ImagePath="<?php echo $imagesURL."/toolbar/";?>">
<tb:button action="approve" title="<?php echo admin_language("la_ToolTip_Approve"); ?>" ImagePath="<?php echo $imagesURL."/toolbar/";?>">
<tb:button action="decline" title="<?php echo admin_language("la_ToolTip_Decline"); ?>" ImagePath="<?php echo $imagesURL."/toolbar/";?>">
<tb:separator ImagePath="<?php echo $imagesURL."/toolbar/";?>">
<tb:button action="print" title="<?php echo admin_language("la_ToolTip_Print"); ?>" ImagePath="<?php echo $imagesURL."/toolbar/";?>">
<tb:button action="view" title="<?php echo admin_language("la_ToolTip_View"); ?>" ImagePath="<?php echo $imagesURL."/toolbar/";?>">
</div>
</td>
</tr>
</tbody>
</table>
<?php if ($filter) { ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="toolbar">
<tr>
<td valign="top">
<?php int_hint_red(admin_language("la_Warning_Filter")); ?>
</td>
</tr>
</table>
<?php } ?>
-<br>
+<br>
<!-- CATEGORY DIVIDER -->
</DIV>
</div>
<DIV style="background-color: #ffffff; position: relative; padding-top: 1px; top: -1px; z-Index:0" id="firstContainer">
<DIV style="background-color: #ffffff; position: relative; padding-top: 1px; top: -1px; z-Index:2" id="secondContainer">
-
+
<?php
-
+
print $ItemTabs->TabRow();
-
+
if(count($ItemTabs->Tabs))
- {
+ {
?>
<div class="divider" id="tabsDevider"><img width=1 height=1 src="images/spacer.gif"></div>
<?php
}
?>
</DIV>
-
+
<?php
unset($m);
$m = GetModuleArray("admin");
-
-
+
+
foreach($m as $key=>$value)
{
$path = $pathtoroot.$value."admin/reviews.php";
//echo "Including File: $path<br>";
if(file_exists($path))
{
//echo "\n<!-- $path -->\n";
include_once($path);
}
}
$admin = $objConfig->Get("AdminDirectory");
- if(!strlen($admin)) $admin = "admin";
+ if(!strlen($admin)) $admin = "admin";
?>
<form method="post" action="<?php echo $rootURL.$admin; ?>/reviews.php?env=<?php echo BuildEnv(); ?>" name="viewmenu">
<input type="hidden" name="fieldname" value="">
<input type="hidden" name="varvalue" value="">
<input type="hidden" name="varvalue2" value="">
<input type="hidden" name="Action" value="">
</form>
</DIV>
<!-- END CODE-->
<script language="JavaScript">
InitPage();
if(default_tab.length == 0)
- {
+ {
cookie_start = theMainScript.GetCookie('active_tab');
if (cookie_start != null) start_tab = cookie_start;
if(start_tab!=null) toggleTabB(start_tab, true);
}
else
{
toggleTabB(default_tab,true);
}
</script>
-<?php
+<?php
$objSession->SetVariable("HasChanges", 0);
- int_footer();
+ int_footer();
?>
\ No newline at end of file
Property changes on: branches/RC/admin/reviews.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.13
\ No newline at end of property
+1.13.2.1
\ No newline at end of property
Index: branches/RC/core/units/reviews/reviews_event_handler.php
===================================================================
--- branches/RC/core/units/reviews/reviews_event_handler.php (revision 9474)
+++ branches/RC/core/units/reviews/reviews_event_handler.php (revision 9475)
@@ -1,346 +1,346 @@
<?php
class ReviewsEventHandler extends kDBEventHandler
{
/**
* Get's special of main item for linking with subitem
*
* @param kEvent $event
* @return string
*/
function getMainSpecial(&$event)
{
if ($event->Special == 'product' && !$this->Application->IsAdmin()) {
// rev.product should auto-link
return '';
}
return parent::getMainSpecial($event);
}
/**
* Checks REVIEW/REVIEW.PENDING permission by main object primary category (not current category)
*
* @param kEvent $event
*/
function CheckPermission(&$event)
{
if ($event->Name == 'OnAddReview' || $event->Name == 'OnCreate') {
$perm_helper =& $this->Application->recallObject('PermissionsHelper');
/* @var $perm_helper kPermissionsHelper */
$parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix');
$main_object =& $this->Application->recallObject($parent_prefix);
/* @var $main_object kCatDBItem */
$perm_name = $this->getPermPrefix($event).'.REVIEW';
$res = $this->Application->CheckPermission($perm_name, 0, $main_object->GetDBField('CategoryId')) ||
$this->Application->CheckPermission($perm_name.'.PENDING', 0, $main_object->GetDBField('CategoryId'));
if (!$res) {
$event->status = erPERM_FAIL;
}
return $res;
}
return parent::CheckPermission($event);
}
/**
* Returns prefix for permissions
*
* @param kEvent $event
*/
function getPermPrefix(&$event)
{
$main_prefix = $this->Application->GetTopmostPrefix($event->Prefix);
// this will return LINK for l, ARTICLE for n, TOPIC for bb, PRODUCT for p
$item_prefix = $this->Application->getUnitOption($main_prefix, 'PermItemPrefix');
return $item_prefix;
}
/**
* Apply any custom changes to list's sql query
*
* @param kEvent $event
* @access protected
* @see OnListBuild
*/
function SetCustomQuery(&$event)
{
$object =& $event->getObject();
/* @var $object kDBList */
if (!$this->Application->IsAdmin()) {
$object->addFilter('active', '%1$s.Status = '.STATUS_ACTIVE);
}
switch ($event->Special)
{
case 'showall':
$object->clearFilters();
break;
case 'item': // used ?
$object->clearFilters();
$info = $object->getLinkedInfo();
$this->Application->setUnitOption($info['ParentPrefix'], 'AutoLoad', true);
$parent =& $this->Application->recallObject($info['ParentPrefix']);
$object->addFilter('item_reviews', '%1$s.ItemId = '.$parent->GetDBField('ResourceId'));
break;
- case 'products': // used ?
+ case 'products': // used in In-Portal (Sturcture & Data -> Reviews section)
$object->removeFilter('parent_filter'); // this is important
-// $object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId');
+ $object->addFilter('product_reviews', 'pr.ResourceId IS NOT NULL');
break;
/*case 'product':
$object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId'); // for LEFT JOIN
break;*/
}
if ($event->getEventParam('type') == 'current_user') {
// $object->removeFilter('active');
$object->addFilter('current_user', '%1$s.CreatedById = '.$this->Application->RecallVar('user_id'));
$object->addFilter('current_ip', '%1$s.IPAddress = "'.$_SERVER['REMOTE_ADDR'].'"');
}
}
/**
* Adds review from front in case if user is logged in
*
* @param kEvent $event
*/
function OnAddReview(&$event)
{
$event->CallSubEvent('OnCreate');
}
/**
* Get new review status on user review permission
*
* @param kEvent $event
* @return int
*/
function getReviewStatus(&$event)
{
$parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix');
$main_object =& $this->Application->recallObject($parent_prefix);
/* @var $main_object kCatDBItem */
$ret = STATUS_DISABLED;
$perm_name = $this->getPermPrefix($event).'.REVIEW';
if ($this->Application->CheckPermission($perm_name, 0, $main_object->GetDBField('CategoryId'))) {
$ret = STATUS_ACTIVE;
}
else if ($this->Application->CheckPermission($perm_name.'.PENDING', 0, $main_object->GetDBField('CategoryId'))) {
$ret = STATUS_PENDING;
}
return $ret;
}
/**
* Prefills all fields on front-end
*
* @param kEvent $event
*/
function OnBeforeItemCreate(&$event)
{
$object =& $event->getObject();
/* @var $object kDBItem */
$parent_info = $object->getLinkedInfo();
$item_type = $this->Application->getUnitOption($parent_info['ParentPrefix'], 'ItemType');
$object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']);
$object->SetDBField('ItemType', $item_type);
$object->SetDBField('Module', $this->Application->findModule('Var', $parent_info['ParentPrefix'], 'Name'));
if ($this->Application->IsAdmin()) {
return ;
}
$spam_helper =& $this->Application->recallObject('SpamHelper');
/* @var $spam_helper SpamHelper */
$spam_helper->InitHelper($parent_info['ParentId'], 'Review', 0);
if ($spam_helper->InSpamControl()) {
$event->status = erFAIL;
$object->SetError('ReviewText', 'too_frequent', 'lu_ferror_review_duplicate');
return ;
}
$rating = $object->GetDBField('Rating');
if ($rating < 1 || $rating > 5) {
$object->SetDBField('Rating', null);
}
$object->SetDBField('ItemId', $parent_info['ParentId']); // ResourceId
$object->SetDBField('CreatedById', $this->Application->RecallVar('user_id'));
$object->SetDBField('Status', $this->getReviewStatus($event));
$object->SetDBField('TextFormat', 0); // set plain text format directly
}
/**
* Sets correct rating value
*
* @param kEvent $event
*/
function OnBeforeItemUpdate(&$event)
{
$object =& $event->getObject();
$rating = $object->GetDBField('Rating');
if (!$rating) {
$object->SetDBField('Rating', null);
}
}
/**
* Updates item review counter
*
* @param kEvent $event
*/
function OnAfterItemCreate(&$event)
{
$this->updateSubitemCounters($event);
if (!$this->Application->IsAdmin()) {
$spam_helper =& $this->Application->recallObject('SpamHelper');
/* @var $spam_helper SpamHelper */
$object =& $event->getObject();
$parent_info = $object->getLinkedInfo();
$config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping');
$review_settings = $config_mapping['ReviewDelayValue'].':'.$config_mapping['ReviewDelayInterval'];
$spam_helper->InitHelper($parent_info['ParentId'], 'Review', $review_settings);
$spam_helper->AddToSpamControl();
}
}
/**
* Updates item review counter
*
* @param kEvent $event
*/
function OnAfterItemUpdate(&$event)
{
$this->updateSubitemCounters($event);
}
/**
* Updates total review counter, cached rating, votes count
*
* @param kEvent $event
*/
function updateSubitemCounters(&$event)
{
$parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix');
$main_object =& $this->Application->recallObject($parent_prefix, null, Array ('raise_warnings' => 0));
/* @var $main_object kCatDBItem */
if (!$main_object->isLoaded()) {
// deleting main item / cloning main item
return ;
}
$object =& $event->getObject(); // for temp tables
/* @var $object kDBItem */
// 1. update review counter
$sql = 'SELECT COUNT(ReviewId)
FROM '.$object->TableName.'
WHERE ItemId = '.$main_object->GetDBField('ResourceId');
$review_count = $this->Conn->GetOne($sql);
$main_object->SetDBField('CachedReviewsQty', $review_count);
// 2. update votes counter + rating
$rating = $object->GetDBField('Rating');
$avg_rating = $main_object->GetDBField('CachedRating');
$votes_count = $main_object->GetDBField('CachedVotesQty');
switch ($event->Name) {
case 'OnAfterItemCreate': // adding new review with rating
$this->changeRating($avg_rating, $votes_count, $rating, '+');
break;
case 'OnAfterItemDelete':
$this->changeRating($avg_rating, $votes_count, $rating, '-');
break;
case 'OnAfterItemUpdate':
$this->changeRating($avg_rating, $votes_count, $object->GetOriginalField('Rating'), '-');
$this->changeRating($avg_rating, $votes_count, $rating, '+');
break;
}
$main_object->SetDBField('CachedRating', $avg_rating);
$main_object->SetDBField('CachedVotesQty', $votes_count);
$main_object->Update();
}
/**
* Changes average rating and votes count based on requested operation
*
* @param float $avg_rating average rating before new vote
* @param int $votes_count votes count before new vote
* @param int $rating new vote (from 1 to 5)
* @param string $operation requested operation (+ / -)
*/
function changeRating(&$avg_rating, &$votes_count, $rating, $operation)
{
if ($rating < 1 || $rating > 5) {
return ;
}
if ($operation == '+') {
$avg_rating = (($avg_rating * $votes_count) + $rating) / ($votes_count + 1);
++$votes_count;
}
else {
$avg_rating = (($avg_rating * $votes_count) - $rating) / ($votes_count - 1);
--$votes_count;
}
}
/**
* Updates main item cached review counter
*
* @param kEvent $event
*/
function OnAfterItemDelete(&$event)
{
$this->updateSubitemCounters($event);
}
/**
* Creates review & redirect to confirmation template
*
* @param kEvent $event
*/
function OnCreate(&$event)
{
parent::OnCreate($event);
if ($event->status != erSUCCESS || $this->Application->IsAdmin()) {
return ;
}
$object =& $event->getObject();
$next_template = $object->GetDBField('Status') == STATUS_ACTIVE ? 'success_template' : 'success_pending_template';
$event->redirect = $this->Application->GetVar($next_template);
$event->SetRedirectParam('opener', 's');
$parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix');
$event->SetRedirectParam('pass', 'm,'.$parent_prefix);
}
}
?>
\ No newline at end of file
Property changes on: branches/RC/core/units/reviews/reviews_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.14.2.1
\ No newline at end of property
+1.14.2.2
\ No newline at end of property
Index: branches/RC/core/units/general/inp1_parser.php
===================================================================
--- branches/RC/core/units/general/inp1_parser.php (revision 9474)
+++ branches/RC/core/units/general/inp1_parser.php (revision 9475)
@@ -1,162 +1,163 @@
<?php
class Inp1Parser extends kHelper {
var $InportalInited = false;
var $InpParsetInited = false;
function Parse($tname, $template_body)
{
global $objTemplate, $var_list, $var_list_update;
if ($tname == 'email_template') {
if ( !$this->InportalInited) {
$this->InitInPortal();
}
// in case Parsing was called through InitInPortal -> moudles -> frontaction -> emailevent
// we need to make sure old parser is initialized
$this->InitParser();
$template_body = $objTemplate->ParseTemplateFromBuffer($tname, $template_body);
return $template_body;
}
if (!$this->InportalInited) {
//$save_t = $this->Application->GetVar('t');
$this->InitInPortal();
$var_list['t'] = $this->cutTPL($var_list['t']);
if($var_list['t'] != $this->Application->GetVar('t'))
{
$get = $_GET;
unset($get['env'], $get['Action'], $get['_mod_rw_url_'], $get['rewrite']);
$this->Application->StoreVar('K4_Template_Referer', $this->Application->GetVar('t') );
$this->Application->Redirect($var_list['t'], $get);
}
}
$var_list['t'] = $this->cutTPL($var_list['t']);
if ($var_list['t'] != $this->Application->GetVar('t')) {
//$var_list['t'] = rtrim($var_list['t'],'.tpl');
$t = $var_list['t'];
$this->Application->SetVar('t', $t);
$template_cache =& $this->Application->recallObject('TemplatesCache');
$template_body = $this->Application->Parser->Parse( $template_cache->GetTemplateBody($t), $t, 0 );
}
else {
$this->InitParser();
$template_body = $objTemplate->ParseTemplateFromBuffer($tname, $template_body);
}
return $template_body;
}
function cutTPL($tname)
{
if( substr($tname,-4) == '.tpl' )
{
return substr($tname, 0, strlen($tname)-4 );
}
return $tname;
}
function InitParser()
{
global $objTemplate, $CurrentTheme, $objThemes, $var_list;
if ($this->InpParsetInited) return true;
$theme_id = $this->Application->IsAdmin() ? 1 : $this->Application->GetVar('m_theme');
if ($theme_id) {
$CurrentTheme = $objThemes->GetItem($theme_id);
$timeout = $CurrentTheme->Get('CacheTimeout');
$objTemplate = new clsTemplateList(FULL_PATH.THEMES_PATH.'/');
}
$this->InpParsetInited = true;
}
function InitInPortal()
{
$this->InportalInited = true;
/*global $pathtoroot, $FrontEnd, $indexURL, $rootURL, $secureURL, $var_list, $CurrentTheme,
$objThemes, $objConfig, $m_var_list, $timeout, $objLanguages,
$TemplateRoot, $objTemplate, $html, $objSession, $Errors, $objCatList, $objUsers,
$env, $mod_prefix, $ExtraVars, $timestart, $timeend, $timeout, $sqlcount, $totalsql,
$template_path, $modules_loaded, $mod_root_cats, $objModules, $objItemTypes;*/
global $sec, $usec, $timestart, $pathtoroot, $FrontEnd, $indexURL, $kernel_version, $FormError,
$FormValues, $ItemTables, $KeywordIgnore, $debuglevel,
$LogLevel, $LogFile, $rq_value, $rq_name, $dbg_constMap, $dbg_constValue, $dbg_constName,
$debugger, $g_LogFile, $LogData, $Errors,
$g_DebugMode, $totalsql, $sqlcount, $objConfig, $ItemTypePrefixes, $ItemTagFiles, $objModules,
$objSystemCache, $objBanList, $objItemTypes, $objThemes, $objLanguages, $objImageList, $objFavorites,
$objUsers, $objGroups, $DownloadId, $objPermissions, $objPermCache, $m_var_list, $objCatList,
$objCustomFieldList, $objCustomDataList, $objCountCache, $CRLF, $objMessageList, $objEmailQueue,
$ExtraVars, $adodbConnection, $sql, $rs, $mod_prefix, $modules_loaded, $name,
$template_path, $mod_root_cats, $value, $mod, $ItemTypes,
$ParserFiles, $SessionQueryString, $var_list, $objSession,
$orderByClause, $TemplateRoot, $ip, $UseSession, $Action, $CookieTest, $sessionId,
$var_list_update, $CurrentTheme, $UserID, $objCurrentUser,
$folder_name, $objLinkList, $tag_override, $timeZones, $siteZone, $serverZone,
$lastExpire, $diffZone, $date, $nowDate, $lastExpireDate, $SearchPerformed,
$TotalMessagesSent, $ado, $adminDir, $rootURL, $secureURL, $html, $timeout,
$pathchar, $objTemplate, $objTopicList, $objArticleList, $objPostingList, $objCensorList,
- $objSmileys, $objPMList, $SubscribeAddress, $SubscribeError, $SubscribeResult, $application;
+ $objSmileys, $objPMList, $SubscribeAddress, $SubscribeError, $SubscribeResult, $application,
+ $FCKeditorBasePath;
$pathtoroot = FULL_PATH.'/';
if (!file_exists(FULL_PATH.'/config.php')) {
echo "In-Portal is probably not installed, or configuration file is missing.<br>";
echo "Please use the installation script to fix the problem.<br><br>";
echo "<a href='admin/install.php'>Go to installation script</a><br><br>";
flush();
$this->Application->ApplicationDie();
}
//ob_start();
$FrontEnd = 1;
$indexURL="../../index.php"; //Set to relative URL from the theme directory
/* initalize the in-portal system */
include_once(FULL_PATH."/kernel/startup.php");
$rootURL="http://".ThisDomain().$objConfig->Get("Site_Path");
$secureURL = $rootURL;
if( !$var_list['t'] ) $var_list['t'] = 'index';
$this->InitParser();
// process referer in session: begin
if (is_object($objSession)) {
$k4_referer = $objSession->GetVariable('K4_Template_Referer');
if ($k4_referer) {
$_local_t = $k4_referer;
$this->Application->RemoveVar('K4_Template_Referer');
}
$objSession->SetVariable('Template_Referer', isset($_local_t) ? $_local_t : '');
}
// process referer in session: end
if ($this->Application->isDebugMode() && $Action) {
$this->Application->Debugger->setHTMLByIndex(1, 'Front Action: <b>'.$Action.'</b>', 'append');
}
LogEntry("Output Complete\n");
$timeend = getmicrotime();
$diff = $timeend - $timestart;
LogEntry("\nTotal Queries Executed: $sqlcount in $totalsql seconds\n");
LogEntry("\nPage Execution Time: $diff seconds\n", true);
if ($LogFile) {
fclose($LogFile);
}
}
}
?>
\ No newline at end of file
Property changes on: branches/RC/core/units/general/inp1_parser.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.20
\ No newline at end of property
+1.20.2.1
\ No newline at end of property

Event Timeline