Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Sat, Jul 19, 6:34 PM

in-portal

Index: trunk/kernel/units/reviews/reviews_config.php
===================================================================
--- trunk/kernel/units/reviews/reviews_config.php (nonexistent)
+++ trunk/kernel/units/reviews/reviews_config.php (revision 4303)
@@ -0,0 +1,131 @@
+<?php
+
+$config = Array(
+ 'Prefix' => 'rev',
+
+ 'Clones' => Array(
+
+ 'l-rev' => Array('ParentPrefix' => 'l'),
+ 'n-rev' => Array('ParentPrefix' => 'n'),
+ 'bb-rev'=> Array('ParentPrefix' => 'bb'),
+ 'p-rev' => Array('ParentPrefix' => 'p'),
+ ),
+
+ 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'),
+ 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'),
+ 'EventHandlerClass' => Array('class'=>'ReviewsEventHandler','file'=>'reviews_event_handler.php','build_event'=>'OnBuild'),
+ 'TagProcessorClass' => Array('class'=>'ReviewsTagProcessor','file'=>'reviews_tag_processor.php','build_event'=>'OnBuild'),
+ 'AutoLoad' => true,
+
+ 'QueryString' => Array(
+ 1 => 'id',
+ 2 => 'page',
+ 3 => 'event',
+ ),
+
+
+ 'ParentPrefix' => 'p', // replace all usage of rev to "p-rev" and then remove this param from here and Prefix too
+
+ 'IDField' => 'ReviewId',
+ 'StatusField' => Array('Status'), // field, that is affected by Approve/Decline events
+ 'TableName' => TABLE_PREFIX.'ItemReview',
+ 'ParentTableKey' => 'ResourceId', // linked field in master table
+ 'ForeignKey' => 'ItemId', // linked field in subtable
+
+ 'AutoDelete' => true,
+ 'AutoClone' => true,
+
+ 'TitlePresets' => Array(
+ 'reviews_edit' => Array('format' => "!la_title_Editing_Review!"),
+ ),
+ 'FilterMenu' => Array(
+ 'Groups' => Array(
+ Array('mode' => 'AND', 'filters' => Array('show_active','show_pending','show_disabled'), 'type' => WHERE_FILTER),
+ ),
+ 'Filters' => Array(
+ 'show_active' => Array('label' =>'la_Active', 'on_sql' => '', 'off_sql' => '%1$s.Status != 1' ),
+ 'show_pending' => Array('label' => 'la_Pending', 'on_sql' => '', 'off_sql' => '%1$s.Status != 2' ),
+ 'show_disabled' => Array('label' => 'la_Disabled', 'on_sql' => '', 'off_sql' => '%1$s.Status != 0' ),
+ )
+ ),
+
+ 'CalculatedFields' => Array(
+ '' => Array(
+ 'ReviewedBy' => 'IF( ISNULL(pu.Login), IF (%1$s.CreatedById = -1, \'root\', IF (%1$s.CreatedById = -2, \'Guest\', \'n/a\')), pu.Login )',
+ ),
+ 'products' => Array(
+ 'ReviewedBy' => 'IF( ISNULL(pu.Login), IF (%1$s.CreatedById = -1, \'root\', IF (%1$s.CreatedById = -2, \'Guest\', \'n/a\')), pu.Login )',
+ 'ItemName' => 'pr.l1_Name',
+ 'ProductId' => 'pr.ProductId',
+ ),
+ 'product' => Array(
+ 'ReviewedBy' => 'IF( ISNULL(pu.Login), IF (%1$s.CreatedById = -1, \'root\', IF (%1$s.CreatedById = -2, \'Guest\', \'n/a\')), pu.Login )',
+ 'ItemName' => 'pr.l1_Name',
+ 'ProductId' => 'pr.ProductId',
+ ),
+
+ ),
+
+ // key - special, value - list select sql
+ 'ListSQLs' => Array( ''=>'SELECT %1$s.* %2$s FROM %1$s
+ LEFT JOIN '.TABLE_PREFIX.'PortalUser pu ON pu.PortalUserId = %1$s.CreatedById',
+
+ 'products' => ' SELECT %1$s.* %2$s
+ FROM %1$s, '.TABLE_PREFIX.'Products pr
+ LEFT JOIN '.TABLE_PREFIX.'PortalUser pu ON pu.PortalUserId = %1$s.CreatedById',
+
+ 'product' => ' SELECT %1$s.* %2$s
+ FROM %1$s, '.TABLE_PREFIX.'Products pr
+ LEFT JOIN '.TABLE_PREFIX.'PortalUser pu ON pu.PortalUserId = %1$s.CreatedById',
+ ),
+
+ 'ItemSQLs' => Array( ''=> 'SELECT * FROM %s'),
+
+ 'ListSortings' => Array(
+ '' => Array(
+ 'ForcedSorting' => Array('Priority' => 'desc'),
+ 'Sorting' => Array('CreatedOn' => 'desc'),
+ )
+ ),
+
+ 'Fields' => Array(
+ 'ReviewId' => Array('type'=>'int'),
+ 'CreatedOn' => Array('formatter'=>'kDateFormatter','not_null'=>1,'default'=>'#NOW#'),
+ 'ReviewText' => Array('type'=>'string','required'=>1,'not_null'=>1,'default'=>''),
+ 'IPAddress' => Array('type'=>'string','max_value_inc'=>15,'not_null'=>1,'default'=>''),
+ 'ItemId' => Array('type'=>'int','not_null'=>1,'default'=>0),
+ 'CreatedById' => Array('formatter'=>'kLEFTFormatter','options'=>Array(-1=>'root',-2=>'Guest'),'left_sql'=>'SELECT %s FROM '.TABLE_PREFIX.'PortalUser WHERE `%s` = \'%s\'','left_key_field'=>'PortalUserId','left_title_field'=>'Login','required'=>1,'not_null'=>1,'default'=>-1),
+ 'ItemType' => Array('type'=>'int','not_null'=>1,'default'=>0),
+ 'Priority' => Array('type'=>'int','not_null'=>1,'default'=>0),
+ 'Status' => Array('formatter'=>'kOptionsFormatter', 'use_phrases' => 1, 'options'=>Array(1=>'la_Active',2=>'la_Pending',0=>'la_Disabled'),'not_null'=>1,'default'=>0 ),
+ 'TextFormat' => Array('type'=>'int','not_null'=>1,'default'=>0),
+ 'Module' => Array('type'=>'string','not_null'=>1,'default'=>''),
+ ),
+ 'VirtualFields' => Array(
+ 'ReviewedBy' => Array(),
+ ),
+
+ 'Grids' => Array(
+ 'Default' => Array( 'Icons' => Array('default'=>'icon16_custom.gif',1=>'icon16_review.gif',2=>'icon16_review_pending.gif',0=>'icon16_review_disabled.gif'),
+ 'Fields' => Array(
+ 'ReviewText' => Array( 'title'=>'la_col_ReviewText', 'data_block' => 'reviewtext_checkbox_td'),
+ 'ReviewedBy' => Array( 'title'=>'la_col_ReviewedBy' ),
+ 'CreatedOn_formatted' => Array( 'title'=>'la_col_CreatedOn', 'sort_field' => 'CreatedOn' ),
+ 'Status' => Array( 'title'=>'la_col_Status' ),
+ ),
+
+ ),
+
+ 'ReviewsSection' => Array( 'Icons' => Array('default'=>'icon16_custom.gif',1=>'icon16_review.gif',2=>'icon16_review_pending.gif',0=>'icon16_review_disabled.gif'),
+ 'Fields' => Array(
+ 'ReviewText' => Array( 'title'=>'la_col_ReviewText', 'data_block' => 'grid_checkbox_namelink_td'),
+ 'ReviewedBy' => Array( 'title'=>'la_col_ReviewedBy' ),
+ 'CreatedOn_formatted' => Array( 'title'=>'la_col_CreatedOn', 'sort_field' => 'CreatedOn' ),
+ 'Status' => Array( 'title'=>'la_col_Status' ),
+ ),
+
+ ),
+ ),
+ );
+
+?>
\ No newline at end of file
Property changes on: trunk/kernel/units/reviews/reviews_config.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/kernel/units/reviews/reviews_tag_processor.php
===================================================================
--- trunk/kernel/units/reviews/reviews_tag_processor.php (nonexistent)
+++ trunk/kernel/units/reviews/reviews_tag_processor.php (revision 4303)
@@ -0,0 +1,102 @@
+<?php
+
+class ReviewsTagProcessor extends kDBTagProcessor
+{
+
+
+ /**
+ * Returns a link for editing product
+ *
+ * @param Array $params
+ * @return string
+ */
+ function ItemEditLink($params)
+ {
+ $item_prefix = $params['item_prefix'];
+ $id_field = $this->Application->getUnitOption($item_prefix,'IDField');
+
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(),$this->Prefix, $params);
+ $item_id = $object->GetDBField($id_field);
+
+ return $this->Application->HREF($params['edit_template'],'', Array(
+ 'm_opener'=>'d',
+ $item_prefix.'_event'=>'OnEdit',
+ $item_prefix.'_id'=>$item_id,
+ 'pass'=>'all,'.$item_prefix
+ ),'index4.php' );
+ }
+
+ /**
+ * Get's reuested field value
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function Field($params)
+ {
+ $field = $this->SelectParam($params, 'name,field');
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(),$this->Prefix, $params);
+
+ if($field == 'ReviewText')
+ {
+ if( $object->GetDBField('TextFormat') == 1 )
+ {
+ $params['no_special'] = 'no_special';
+ }
+ else
+ {
+ unset($params['no_special']);
+ }
+ }
+
+ return parent::Field($params);
+
+ }
+
+ function AlreadyReviewed($params)
+ {
+ $user_id = ($this->Application->GetVar('u_id') == 0) ? -2 : $this->Application->GetVar('u_id');
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object =& $this->Application->recallObject($this->getPrefixSpecial());
+ $product_info = $object->getLinkedInfo();
+
+ $sql = ' SELECT * FROM '.TABLE_PREFIX.'SpamControl
+ WHERE ItemResourceId='.$product_info['ParentId'].'
+ AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
+ AND PortalUserId='.$user_id.'
+ AND DataType="Review"';
+ $res = $this->Conn->GetRow($sql);
+ if($res['Expire'] > adodb_mktime())
+ {
+ $ret = 1;
+ }
+ else
+ {
+ $sql = 'DELETE FROM '.TABLE_PREFIX.'SpamControl
+ WHERE ItemResourceId='.$product_info['ParentId'].'
+ AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
+ AND PortalUserId='.$user_id.'
+ AND DataType="Review"';
+ $this->Conn->Query($sql);
+ $ret = 0;
+ }
+ return $ret;
+ }
+
+ function HasError($params)
+ {
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
+ if(method_exists($object, 'GetErrorMsg'))
+ {
+ return parent::HasError($params);
+ }
+ else
+ {
+ return 0;
+ }
+ }
+}
+
+
+?>
\ No newline at end of file
Property changes on: trunk/kernel/units/reviews/reviews_tag_processor.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/kernel/units/reviews/reviews_event_handler.php
===================================================================
--- trunk/kernel/units/reviews/reviews_event_handler.php (nonexistent)
+++ trunk/kernel/units/reviews/reviews_event_handler.php (revision 4303)
@@ -0,0 +1,142 @@
+<?php
+
+ class ReviewsEventHandler extends InpDBEventHandler
+ {
+ /**
+ * Apply any custom changes to list's sql query
+ *
+ * @param kEvent $event
+ * @access protected
+ * @see OnListBuild
+ */
+ function SetCustomQuery(&$event)
+ {
+ $object =& $event->getObject();
+ switch ($event->Special)
+ {
+ case 'showall':
+ $object->clearFilters();
+ break;
+
+ case 'products':
+ $object->removeFilter('parent_filter'); // this is important
+ $object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId');
+ // $object->addFilter('active', '%1$s.Status = 1');
+
+ /*$this->Application->setUnitOption('p', 'AutoLoad', true);
+ $product =& $this->Application->recallObject('p');
+ $object->addFilter('current_product', 'pr.ResourceId = '.$product->GetDBField('ResourceId'));*/
+ break;
+
+ case 'product':
+ $object->clearFilters();
+ $object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId');
+ $object->addFilter('active', '%1$s.Status = 1');
+ $this->Application->setUnitOption('p', 'AutoLoad', true);
+ $product =& $this->Application->recallObject('p');
+ $object->addFilter('current_product', 'pr.ResourceId = '.$product->GetDBField('ResourceId'));
+
+ break;
+ }
+
+ if($event->getEventParam('type') == 'current_user')
+ {
+ $user_id = $this->Application->GetVar('u_id') ? $this->Application->GetVar('u_id') : -2;
+ $ip = $_SERVER['REMOTE_ADDR'];
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object =& $event->getObject();
+ $product_info = $object->getLinkedInfo();
+ $object->addFilter('current_item', '%1$s.ItemId = '.$product_info['ParentId']);
+ $object->addFilter('current_user', '%1$s.CreatedById = '.$user_id);
+ $object->addFilter('current_ip', '%1$s.IPAddress = "'.$ip.'"');
+
+ }
+ }
+
+ /**
+ * Adds review from front in case if user is logged in
+ *
+ * @param kEvent $event
+ */
+ function OnAddReview(&$event)
+ {
+ $user_id = ($this->Application->GetVar('u_id') == 0) ? -2 : $this->Application->GetVar('u_id');
+ $event->redirect_params = Array('pass' => 'all,p');
+
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object =& $event->getObject();
+ $item_info = $this->Application->GetVar('rev_product');
+ $product_info = $object->getLinkedInfo();
+
+ $sql = ' SELECT * FROM '.TABLE_PREFIX.'SpamControl
+ WHERE ItemResourceId='.$product_info['ParentId'].'
+ AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
+ AND PortalUserId='.$user_id.'
+ AND DataType="Review"';
+ $res = $this->Conn->GetRow($sql);
+
+ if( $res && $res['Expire'] < adodb_mktime() )
+ {
+ $sql = ' DELETE FROM '.TABLE_PREFIX.'SpamControl
+ WHERE ItemResourceId='.$product_info['ParentId'].'
+ AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
+ AND PortalUserId='.$user_id.'
+ AND DataType="Review"';
+ $this->Conn->Query($sql);
+ unset($res);
+ }
+
+ if(!$res)
+ {
+ $object->SetFieldsFromHash( array_shift($item_info) );
+ $object->SetDBField('CreatedById', $user_id);
+ $object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']);
+ $object->SetDBField('CreatedOn', adodb_mktime());
+
+ if( $this->Application->CheckPermission('PRODUCT.REVIEW.PENDING') )
+ {
+ $object->SetDBField('Status', 2);
+ }
+ elseif( $this->Application->CheckPermission('PRODUCT.REVIEW') )
+ {
+ $object->SetDBField('Status', 1);
+ }
+
+ $object->SetDBField('ItemId', $product_info['ParentId']);
+
+ $event->CallSubEvent('OnCreate');
+
+ if($event->status == erSUCCESS)
+ {
+ $product_object =& $this->Application->recallObject('p');
+ $sql = ' SELECT COUNT(ReviewId)
+ FROM '.$object->TableName.'
+ WHERE ItemId='.$product_info['ParentId'];
+ $review_qty = $this->Conn->GetOne($sql);
+ $product_object->SetDBField('CachedReviewsQty', $review_qty);
+ $product_object->Update();
+ $expire = adodb_mktime() + $this->Application->ConfigValue('product_ReviewDelay_Value') * $this->Application->ConfigValue('product_ReviewDelay_Interval');
+ $sql = ' INSERT INTO '.TABLE_PREFIX.'SpamControl
+ (ItemResourceId, IPaddress, PortalUserId, DataType, Expire)
+ VALUES ('.$product_info['ParentId'].',
+ "'.$_SERVER['REMOTE_ADDR'].'",
+ '.$user_id.',
+ "Review",
+ '.$expire.')';
+ $this->Conn->Query($sql);
+
+ $event->redirect_params = Array('pass' => 'all,p');
+ $event->redirect = $this->Application->GetVar('success_template');
+ }
+ }
+ else
+ {
+ $event->status == erFAIL;
+ $event->redirect=false;
+ $object->FieldErrors['ReviewText']['pseudo'] = 'too_frequent';
+ $object->ErrorMsgs['too_frequent'] = $this->Application->Phrase('lu_ferror_review_duplicate');
+ }
+ }
+ }
+
+?>
\ No newline at end of file
Property changes on: trunk/kernel/units/reviews/reviews_event_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/kernel/units/relationship/relationship_event_handler.php
===================================================================
--- trunk/kernel/units/relationship/relationship_event_handler.php (nonexistent)
+++ trunk/kernel/units/relationship/relationship_event_handler.php (revision 4303)
@@ -0,0 +1,176 @@
+<?php
+
+ class RelationshipEventHandler extends InpDBEventHandler
+ {
+ /**
+ * Add new relation
+ *
+ * @param kEvent $event
+ */
+ function OnAddRelation(&$event)
+ {
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object =& $event->getObject();
+
+ $table_info = $object->getLinkedInfo();
+ $main_item_type = $this->Application->getUnitOption($table_info['ParentPrefix'],'ItemType');
+
+ $target['id'] = $this->Application->GetVar('TargetId');
+ $target['type'] = $this->Application->GetVar('TargetType');
+
+
+ $object->SetDBField($table_info['ForeignKey'], $table_info['ParentId']);
+ $object->SetDBField('SourceType', $main_item_type);
+ $object->SetDBField('TargetId', $target['id']);
+ $object->SetDBField('TargetType', $target['type']);
+
+ // 1. get item info used in relation
+ $configs = $this->extractModulesInfo();
+ foreach($configs as $prefix => $config_data)
+ {
+ if($config_data['ItemType'] == $target['type']) break;
+ }
+
+ $db =& $this->Application->GetADODBConnection();
+ $item['name'] = $db->GetOne('SELECT '.$config_data['TitleField'].' FROM '.$config_data['TableName'].' WHERE ResourceId = '.$target['id']);
+ $item['type'] = $this->Application->Phrase($config_data['TitlePhrase']);
+ $object->SetDBField('ItemName', $item['name']);
+ $object->SetDBField('ItemType', $item['type']);
+
+ $object->setID(0);
+
+ $event->redirect = false;
+
+ // 2. substitute opener
+ $opener_stack = $this->Application->RecallVar('opener_stack');
+ $opener_stack = $opener_stack ? unserialize($opener_stack) : Array();
+ array_pop($opener_stack);
+
+ $new_level = 'index4.php|'.ltrim($this->Application->BuildEnv('in-commerce/products/products_relations',Array('m_opener'=>'u'),'all'),ENV_VAR_NAME.'=');
+ array_push($opener_stack,$new_level);
+ $this->Application->StoreVar('opener_stack',serialize($opener_stack));
+
+ $this->Application->SetVar($event->Prefix_Special.'_SaveEvent','OnCreate');
+ }
+
+ /**
+ * Creates needed sql query to load list,
+ * if no query is defined in config for
+ * special requested, then use default
+ * query
+ *
+ * @param kEvent $event
+ * @access protected
+ */
+ function ListPrepareQuery(&$event)
+ {
+ return $this->BaseQuery($event,'ListSQLs');
+ }
+
+ /**
+ * Creates needed sql query to load item,
+ * if no query is defined in config for
+ * special requested, then use default
+ * query
+ *
+ * @param kEvent $event
+ * @access protected
+ */
+ function ItemPrepareQuery(&$event)
+ {
+ return $this->BaseQuery($event,'ItemSQLs');
+ }
+
+
+ /**
+ * Get item name & type based on relation type & modules installed
+ *
+ * @param kEvent $event
+ * @param string $sql_field
+ */
+ function BaseQuery(&$event, $sql_field)
+ {
+ $sqls = $this->Application->getUnitOption($event->Prefix,$sql_field);
+ $sql = isset($sqls[$event->Special]) ? $sqls[$event->Special] : $sqls[''];
+
+ $configs = $this->extractModulesInfo();
+
+ // 2. build sql based on information queried
+ $sql_templates['ItemName'] = 'IFNULL(%s.%s,\' \')';
+ $sql_templates['TableJoin'] = 'LEFT JOIN %1$s ON %1$s.ResourceId = rel.TargetId';
+ $sql_templates['TargetName'] = 'IF(rel.TargetType = %s, \'%s\', %s)';
+
+ $sql_parts = Array();
+ $sql_parts['TargetName'] = "''";
+ foreach($configs as $prefix => $config_data)
+ {
+ $sql_parts['ItemName'][] = sprintf($sql_templates['ItemName'], $config_data['TableName'], $config_data['TitleField']);
+ $sql_parts['TableJoin'][] = sprintf($sql_templates['TableJoin'], $config_data['TableName']);
+
+ $sql_parts['TargetName'] = sprintf( $sql_templates['TargetName'],
+ $config_data['ItemType'],
+ '!'.$config_data['TitlePhrase'].'!',
+ $sql_parts['TargetName']);
+ $sql_parts['TargetName'] = str_replace('rel','%1$s',$sql_parts['TargetName']);
+ }
+
+ $object =& $event->getObject();
+
+ $vars = Array('#ITEM_NAMES#', '#ITEM_TYPES#');
+ $replacements = Array( implode(', ',$sql_parts['ItemName']), $sql_parts['TargetName'] );
+
+ $calculated_fields =& $object->getProperty('CalculatedFields');
+ foreach($calculated_fields as $field_name => $field_expression)
+ {
+ $calculated_fields[$field_name] = str_replace($vars,$replacements,$field_expression);
+ }
+
+ $object->setProperty('CalculatedFields', $calculated_fields);
+
+ $sql = str_replace('#ITEM_JOIN#', implode(' ',$sql_parts['TableJoin']), $sql);
+ $sql = str_replace('rel.','%1$s.',$sql);
+
+ return $sql;
+ }
+
+ /**
+ * Get configs from modules installed
+ *
+ * @return Array
+ * @access private
+ */
+ function extractModulesInfo()
+ {
+ // 1. get installed modules & their config info
+ $db =& $this->Application->GetADODBConnection();
+ $prefixes = $db->GetCol('SELECT Var FROM '.TABLE_PREFIX.'Modules');
+ $configs = Array();
+ foreach($prefixes as $prefix)
+ {
+ $configs[$prefix] = $this->Application->getUnitOptions($prefix);
+ if($configs[$prefix] === false) unset($configs[$prefix]);
+ }
+ return $configs;
+ }
+
+
+ /**
+ * Deletes relations to hooked item from other items
+ *
+ * @param kEvent $event
+ */
+ function OnDeleteForeignRelations(&$event)
+ {
+ $main_object =& $event->MasterEvent->getObject();
+ $resource_id = $main_object->GetDBField('ResourceId');
+
+ $table = $this->Application->getUnitOption($event->Prefix,'TableName');
+ $sql = 'DELETE FROM '.$table.' WHERE TargetId = '.$resource_id;
+ $this->Conn->Query($sql);
+ }
+
+
+ }
+
+
+?>
\ No newline at end of file
Property changes on: trunk/kernel/units/relationship/relationship_event_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/kernel/units/relationship/relationship_config.php
===================================================================
--- trunk/kernel/units/relationship/relationship_config.php (nonexistent)
+++ trunk/kernel/units/relationship/relationship_config.php (revision 4303)
@@ -0,0 +1,97 @@
+<?php
+
+$config = Array(
+ 'Prefix' => 'rel',
+ 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'),
+ 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'),
+ 'EventHandlerClass' => Array('class'=>'RelationshipEventHandler','file'=>'relationship_event_handler.php','build_event'=>'OnBuild'),
+ 'TagProcessorClass' => Array('class'=>'kDBTagProcessor','file'=>'','build_event'=>'OnBuild'),
+ 'AutoLoad' => true,
+ 'Hooks' => Array(
+ Array(
+ 'Mode' => hAFTER,
+ 'Conditional' => false,
+ 'HookToPrefix' => 'p',
+ 'HookToSpecial' => '-item',
+ 'HookToEvent' => Array('OnAfterItemDelete'),
+ 'DoPrefix' => '',
+ 'DoSpecial' => '',
+ 'DoEvent' => 'OnDeleteForeignRelations',
+ ),
+ ),
+ 'QueryString' => Array(
+ 1 => 'id',
+ 2 => 'page',
+ 3 => 'event',
+ ),
+ 'IDField' => 'RelationshipId',
+ 'StatusField' => Array('Enabled','Type'),
+ 'TableName' => TABLE_PREFIX.'Relationship',
+ 'ParentTableKey'=> 'ResourceId',
+ 'ForeignKey' => 'SourceId',
+ 'ParentPrefix' => 'p',
+ 'AutoDelete' => true,
+ 'AutoClone' => true,
+
+ 'FilterMenu' => Array(
+ 'Groups' => Array(
+ Array('mode' => 'AND', 'filters' => Array('show_active','show_disabled'), 'type' => WHERE_FILTER),
+ Array('mode' => 'AND', 'filters' => Array('show_recip','show_oneway'), 'type' => WHERE_FILTER),
+ ),
+ 'Filters' => Array(
+ 'show_active' => Array('label' =>'la_Active', 'on_sql' => '', 'off_sql' => 'Enabled != 1' ),
+ 'show_disabled' => Array('label' => 'la_Disabled', 'on_sql' => '', 'off_sql' => 'Enabled != 0' ),
+ 's1' => Array(),
+ 'show_recip' => Array('label' => 'la_Reciprocal', 'on_sql' => '', 'off_sql' => '%1$s.Type != 1' ),
+ 'show_oneway' => Array('label' => 'la_OneWay', 'on_sql' => '', 'off_sql' => '%1$s.Type != 2' ),
+ )
+ ),
+
+ 'CalculatedFields' => Array(
+ '' => Array(
+ 'ItemName' => 'TRIM(CONCAT(#ITEM_NAMES#))',
+ 'ItemType' => '#ITEM_TYPES#',
+ ),
+ ),
+
+ 'ListSQLs' => Array( ''=> 'SELECT %1$s.RelationshipId, %1$s.Priority, %1$s.Type, %1$s.Enabled %2$s
+ FROM %1$s #ITEM_JOIN#',
+ ), // key - special, value - list select sql
+
+ 'ListSortings' => Array(
+ '' => Array(
+ 'ForcedSorting' => Array('Priority' => 'desc'),
+ 'Sorting' => Array('ItemName' => 'asc', 'ItemType' => 'asc'),
+ )
+ ),
+ 'ItemSQLs' => Array( '' => 'SELECT %1$s.* %2$s FROM %1$s #ITEM_JOIN#',),
+
+ 'Fields' => Array(
+ 'RelationshipId' => Array(),
+ 'SourceId' => Array('type'=>'int'),
+ 'TargetId' => Array('type'=>'int'),
+ 'SourceType' => Array('type'=>'int','not_null'=>1,'default'=>0),
+ 'TargetType' => Array('type'=>'int','not_null'=>1,'default'=>0),
+ 'Type' => Array('type'=>'int','formatter'=>'kOptionsFormatter','options'=>Array(1=>'la_Reciprocal',0=>'la_OneWay'),'not_null'=>1,'default'=>0,'use_phrases'=>1),
+ 'Enabled' => Array('type'=>'int','formatter'=>'kOptionsFormatter','options'=>Array(0=>'la_Disabled',1=>'la_Enabled'),'not_null'=>1,'default'=>1,'use_phrases'=>1),
+ 'Priority' => Array('type'=>'int','not_null'=>1,'default'=>0),
+ ),
+ 'VirtualFields' => Array( 'ItemName' => Array(),
+ 'ItemType' => Array(),
+ ),
+
+ 'Grids' => Array(
+ 'Default' => Array(
+ 'Icons' => Array('default'=>'icon16_custom.gif','1_0'=>'icon16_relation_one-way.gif','0_0'=>'icon16_relation_one-way_disabled.gif','1_1'=>'icon16_relation_reciprocal.gif','0_1'=>'icon16_relation_reciprocal_disabled.gif'), // icons for each StatusField values, if no matches or no statusfield selected, then "default" icon is used
+ 'Fields' => Array(
+ 'ItemName' => Array( 'title'=>'la_col_TargetId', 'data_block' => 'grid_checkbox_td'),
+ 'ItemType' => Array( 'title'=>'la_col_TargetType' ),
+ 'Type' => Array( 'title'=>'la_col_RelationshipType' ),
+ 'Enabled' => Array( 'title'=>'la_col_Status' ),
+ ),
+
+ ),
+ ),
+ );
+
+?>
\ No newline at end of file
Property changes on: trunk/kernel/units/relationship/relationship_config.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/kernel/units/images/images_config.php
===================================================================
--- trunk/kernel/units/images/images_config.php (nonexistent)
+++ trunk/kernel/units/images/images_config.php (revision 4303)
@@ -0,0 +1,155 @@
+<?php
+
+$config = Array(
+ 'Prefix' => 'img',
+ 'Clones' => Array(
+ 'catimg' => Array(
+ 'ParentPrefix' => 'c',
+ 'AggregateTags' => Array(
+ Array(
+ 'AggregateTo' => 'c',
+ 'AggregatedTagName' => 'Image',
+ 'LocalTagName' => 'ItemImage',
+ ),
+ Array(
+ 'AggregateTo' => 'c',
+ 'AggregatedTagName' => 'ListImages',
+ 'LocalTagName' => 'PrintList2',
+ 'LocalSpecial' => 'list',
+ ),
+ Array(
+ 'AggregateTo' => 'c',
+ 'AggregatedTagName' => 'LargeImageExists',
+ 'LocalTagName' => 'LargeImageExists',
+ ),
+ ),
+ )
+ ),
+ 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'),
+ 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'),
+ 'EventHandlerClass' => Array('class'=>'ImageEventHandler','file'=>'image_event_handler.php','build_event'=>'OnBuild'),
+ 'TagProcessorClass' => Array('class'=>'ImageTagProcessor','file'=>'image_tag_processor.php','build_event'=>'OnBuild'),
+ 'AutoLoad' => true,
+ 'hooks' => Array(),
+ 'AggregateTags' => Array(
+ Array(
+ 'AggregateTo' => 'p',
+ 'AggregatedTagName' => 'Image',
+ 'LocalTagName' => 'ItemImage',
+ ),
+ Array(
+ 'AggregateTo' => 'p',
+ 'AggregatedTagName' => 'ListImages',
+ 'LocalTagName' => 'PrintList2',
+ 'LocalSpecial' => 'list',
+ ),
+ Array(
+ 'AggregateTo' => 'p',
+ 'AggregatedTagName' => 'LargeImageExists',
+ 'LocalTagName' => 'LargeImageExists',
+ ),
+
+ ),
+ 'QueryString' => Array(
+ 1 => 'id',
+ 2 => 'page',
+ 3 => 'event',
+ ),
+ 'IDField' => 'ImageId',
+ 'StatusField' => Array('Enabled', 'DefaultImg'), // field, that is affected by Approve/Decline events
+ 'TitleField' => 'Name', // field, used in bluebar when editing existing item
+ 'TableName' => TABLE_PREFIX.'Images',
+ 'ParentTableKey'=> 'ResourceId', // linked field in master table
+ 'ForeignKey' => 'ResourceId', // linked field in subtable
+ 'ParentPrefix' => 'p',
+ 'AutoDelete' => true,
+ 'AutoClone' => true,
+
+ 'FilterMenu' => Array(
+ 'Groups' => Array(
+ Array('mode' => 'AND', 'filters' => Array('show_active','show_disabled'), 'type' => WHERE_FILTER),
+ ),
+ 'Filters' => Array(
+ 'show_active' => Array('label' =>'la_Active', 'on_sql' => '', 'off_sql' => 'Enabled != 1' ),
+ 'show_disabled' => Array('label' => 'la_Disabled', 'on_sql' => '', 'off_sql' => 'Enabled != 0' ),
+ )
+ ),
+
+ 'CalculatedFields' => Array(
+ '' => Array(
+ 'Preview' => '0',
+ ),
+ ),
+
+ 'ListSQLs' => Array( ''=>'SELECT * FROM %s',
+ ), // key - special, value - list select sql
+ 'ItemSQLs' => Array( ''=>'SELECT * FROM %s',
+ ),
+ 'ListSortings' => Array(
+ '' => Array(
+ 'ForcedSorting' => Array('Priority' => 'desc'),
+ 'Sorting' => Array('Name' => 'asc'),
+ )
+ ),
+ 'Fields' => Array(
+ 'ImageId' => Array('type'=>'int'),
+ 'ResourceId' => Array('type'=>'int', 'not_null'=>1, 'default' => 0),
+ 'Url' => Array('max_len'=>255, 'default' => '', 'not_null'=>1),
+ 'Name' => Array('max_len'=>255, 'required'=>1, 'not_null'=>1, 'default' => ''),
+ 'AltName' => Array('max_len'=>255, 'required'=>1, 'not_null'=>1),
+ 'ImageIndex' => Array('type'=>'int', 'default' => 0, 'not_null'=>1),
+ 'LocalImage' => Array('type'=>'int', 'default' => 1, 'not_null'=>1),
+ 'LocalPath' => Array('formatter'=>'kPictureFormatter', 'skip_empty'=>1, 'max_len'=>240, 'default' => '', 'not_null' => 1, 'include_path' => 1,
+ 'allowed_types' => Array(
+ 0 => 'image/jpeg',
+ 1 => 'image/pjpeg',
+ 2 => 'image/png',
+ 3 => 'image/gif',
+ 4 => 'image/bmp'
+ ),
+ 'error_msgs' => Array( 'bad_file_format' => '!la_error_InvalidFileFormat!',
+ 'bad_file_size' => '!la_error_FileTooLarge!',
+ 'cant_save_file' => '!la_error_cant_save_file!'
+ )
+ ),
+ 'Enabled' => Array('formatter'=>'kOptionsFormatter', 'use_phrases' => 1, 'options' => Array ( 1 => 'la_Enabled', 0 => 'la_Disabled' ), 'default' => 0, 'not_null'=>1),
+ 'DefaultImg' => Array('type'=>'int', 'default' => 0, 'not_null'=>1),
+ 'ThumbUrl' => Array('max_len' => 255),
+ 'Priority' => Array('type'=>'int', 'default' => 0, 'not_null'=>1),
+ 'ThumbPath' => Array( 'formatter'=>'kPictureFormatter', 'skip_empty'=>1, 'max_len' => 255,
+ 'allowed_types' => Array(
+ 0 => 'image/jpeg',
+ 1 => 'image/pjpeg',
+ 2 => 'image/png',
+ 3 => 'image/gif',
+ 4 => 'image/bmp'
+ ),
+ 'error_msgs' => Array( 'bad_file_format' => '!la_error_InvalidFileFormat!',
+ 'bad_file_size' => '!la_error_FileTooLarge!',
+ 'cant_save_file' => '!la_error_cant_save_file!'
+ )
+ ),
+ 'LocalThumb' => Array('type'=>'int', 'default' => 1, 'not_null'=>1),
+ 'SameImages' => Array('type'=>'int', 'default' => 1, 'not_null'=>1),
+ ),
+ 'VirtualFields' => Array(
+ 'Preview' => Array(),
+ 'ImageUrl' => Array(),
+ ),
+
+ 'Grids' => Array(
+ 'Default' => Array(
+ 'Icons' => Array('default'=>'icon17_custom.gif','1_0'=>'icon16_image.gif','0_0'=>'icon16_image_disabled.gif','1_1'=>'icon16_image_primary.gif'),
+ 'Fields' => Array(
+ 'Name' => Array( 'title'=>'la_col_ImageName' , 'data_block' => 'image_caption_td'),
+ 'AltName' => Array( 'title'=>'la_col_AltName' ),
+ 'Url' => Array( 'title'=>'la_col_ImageUrl', 'data_block' => 'image_url_td' ),
+ 'Enabled' => Array( 'title'=>'la_col_ImageEnabled' ),
+ 'Preview' => Array( 'title'=>'la_col_Preview', 'data_block' => 'image_preview_td' ),
+ ),
+
+ ),
+ ),
+ );
+
+?>
\ No newline at end of file
Property changes on: trunk/kernel/units/images/images_config.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/kernel/units/images/image_tag_processor.php
===================================================================
--- trunk/kernel/units/images/image_tag_processor.php (nonexistent)
+++ trunk/kernel/units/images/image_tag_processor.php (revision 4303)
@@ -0,0 +1,206 @@
+<?php
+
+class ImageTagProcessor extends kDBTagProcessor {
+
+ function Image($params)
+ {
+ $params['img_path'] = $this->ImageSrc($params);
+ $params['img_size'] = $this->ImageSize($params);
+ if (!$params['img_size']){
+ $params['img_size'] = ' width="'.getArrayValue($params, 'DefaultWidth').'"';
+ }
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), null);
+ $params['alt'] = htmlspecialchars($object->GetField('AltName'));
+ $params['name'] = $this->SelectParam($params, 'block,render_as');
+
+ return $this->Application->ParseBlock($params);
+ }
+
+ function ItemImage($params)
+ {
+ $this->LoadItemImage($params);
+ $params['img_path'] = $this->ImageSrc($params);
+ $params['img_size'] = $this->ImageSize($params);
+ if (!$params['img_size']){
+ if (isset($params['DefaultWidth'])) {
+ $params['img_size'] = ' width="'.getArrayValue($params, 'DefaultWidth').'"';
+ }
+ }
+ $params['name'] = $this->SelectParam($params, 'render_as,block');
+ $object =& $this->Application->recallObject($this->getPrefixSpecial());
+ if ( !$object->isLoaded() && !$this->SelectParam($params, 'default_image,DefaultImage') ) return false;
+
+ $params['alt'] = htmlspecialchars($object->GetField('AltName'));
+ return $this->Application->ParseBlock($params);
+ }
+
+ function LargeImageExists($params) {
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
+ if ( $object->GetDBField('SameImages') == null || $object->GetDBField('SameImages')=='1' )
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+ function LoadItemImage($params)
+ {
+ $parent_item =& $this->Application->recallObject($params['PrefixSpecial']);
+
+ $this->Application->setUnitOption($this->Prefix,'AutoLoad',false);
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), null);
+
+ // if we need primary thumbnail which is preloaded with products list
+ $object->Clear();
+
+ // if we need primary thumbnail which is preloaded with products list
+ if (
+ $this->SelectParam($params, 'thumbnail,Thumbnail') &&
+ (
+ (
+ $this->SelectParam($params, 'primary,Primary')
+ ||
+ !isset($params['name'])
+ )
+ &&
+ !$this->Application->GetVar('img_id')
+ &&
+ isset($parent_item->Fields['LocalThumb'])
+ )
+ )
+ {
+ $object->SetDefaultValues();
+ $object->SetDBFieldsFromHash($parent_item->GetFieldValues(), Array('SameImages', 'LocalThumb', 'ThumbPath', 'ThumbUrl', 'LocalImage', 'LocalPath', 'Url') );
+ $object->Loaded = true;
+ }
+ else { // if requested image is not primary thumbnail - load it directly
+ $id_field = $this->Application->getUnitOption($this->Prefix, 'ForeignKey');
+ $parent_table_key = $this->Application->getUnitOption($this->Prefix, 'ParentTableKey');
+
+ $keys[$id_field] = $parent_item->GetDBField($parent_table_key);
+
+ // which image to load?
+ if ( getArrayValue($params, 'Primary') ) { //load primary image
+ $keys['DefaultImg'] = 1;
+ }
+ elseif ( getArrayValue($params, 'name') ) { //load by name
+ $keys['Name'] = $params['name'];
+ }
+ elseif ( $image_id = $this->Application->GetVar($this->Prefix.'_id') ) {
+ $keys['ImageId'] = $image_id;
+ }
+ else {
+ $keys['DefaultImg'] = 1; //if primary was not set explicity and name was also not passed - load primary
+ }
+
+ $object->Load($keys);
+ }
+ }
+
+ function ImageSrc($params)
+ {
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), null);
+ $ret = '';
+ // if we need thumb, or full image is same as thumb
+ if ( $this->SelectParam($params, 'thumbnail,Thumbnail') || $object->GetDBField('SameImages') )
+ {
+ // return local image or url
+ $ret = $object->GetDBField('LocalThumb') ? PROTOCOL.SERVER_NAME.BASE_PATH.'/'.$object->GetDBField('ThumbPath') : $object->GetDBField('ThumbUrl');
+ if ( $object->GetDBField('LocalThumb') && !file_exists(FULL_PATH.'/'.$object->GetDBField('ThumbPath')) ) $ret = '';
+ }
+ else { // if we need full which is not the same as thumb
+ $ret = $object->GetDBField('LocalImage') ? PROTOCOL.SERVER_NAME.BASE_PATH.'/'.$object->GetDBField('LocalPath') : $object->GetDBField('Url');
+ if ( $object->GetDBField('LocalImage') && !file_exists(FULL_PATH.'/'.$object->GetDBField('LocalPath')) ) $ret = '';
+ }
+
+ return ($ret && $ret != PROTOCOL.SERVER_NAME.BASE_PATH && $ret != PROTOCOL.SERVER_NAME.BASE_PATH.'/') ? $ret : PROTOCOL.SERVER_NAME.BASE_PATH.THEMES_PATH.'/'.$this->SelectParam($params, 'default_image,DefaultImage');
+ }
+
+ function GetFullPath($path)
+ {
+ if(!$path) return $path;
+
+ // absolute url
+ if( preg_match('/^(.*):\/\/(.*)$/U', $path) )
+ {
+ if(strpos($path, PROTOCOL.SERVER_NAME.BASE_PATH) === 0)
+ {
+ $path = str_replace(PROTOCOL.SERVER_NAME.BASE_PATH, FULL_PATH.'/', $path);
+ }
+ return $path;
+ }
+
+ // relative url
+ return FULL_PATH.'/'.substr(THEMES_PATH,1).'/'.$path;
+ }
+
+ /**
+ * Makes size clause for img tag, such as
+ * ' width="80" height="100"' according to max_width
+ * and max_heght limits.
+ *
+ * @param array $params
+ * @return string
+ */
+ function ImageSize($params)
+ {
+ $img_path = $this->GetFullPath( getArrayValue($params, 'img_path') );
+
+ $image_info = @getimagesize($img_path);
+
+// if( !($img_path && file_exists($img_path) && isset($image_info) ) )
+ if( !$image_info )
+ {
+ trigger_error('Image <b>'.$img_path.'</b> <span class="debug_error">missing or invalid</span>', E_USER_WARNING);
+ return false;
+ }
+
+ $orig_width = getArrayValue($image_info, 0);
+ $orig_height = getArrayValue($image_info, 1);
+ $max_width = getArrayValue($params, 'MaxWidth');
+ $max_height = getArrayValue($params, 'MaxHeight');
+
+ $too_large = is_numeric($max_width) ? ($orig_width > $max_width) : false;
+ $too_large = $too_large || (is_numeric($max_height) ? ($orig_height > $max_height) : false);
+
+ if($too_large)
+ {
+ $width_ratio = $max_width ? $max_width / $orig_width : 1;
+ $height_ratio = $max_height ? $max_height / $orig_height : 1;
+ $ratio = min($width_ratio, $height_ratio);
+
+ $width = ceil($orig_width * $ratio);
+ $height = ceil($orig_height * $ratio);
+ }
+ else
+ {
+ $width = $orig_width;
+ $height = $orig_height;
+ }
+
+ $size_clause = ' width="'.$width.'" height="'.$height.'"';
+ return $size_clause;
+ }
+
+
+ // used in admin
+ function ImageUrl($params)
+ {
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
+ if ($object->GetDBField('SameImages') ? $object->GetDBField('LocalThumb') : $object->GetDBField('LocalImage') )
+ {
+ $ret = $this->Application->Phrase(getArrayValue($params,'local_phrase'));
+ }
+ else
+ {
+ $ret = $object->GetDBField('SameImages') ? $object->GetDBField('ThumbUrl') : $object->GetDBField('Url');
+ }
+ return $ret;
+ }
+
+}
+
+?>
\ No newline at end of file
Property changes on: trunk/kernel/units/images/image_tag_processor.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/kernel/units/images/image_event_handler.php
===================================================================
--- trunk/kernel/units/images/image_event_handler.php (nonexistent)
+++ trunk/kernel/units/images/image_event_handler.php (revision 4303)
@@ -0,0 +1,336 @@
+<?php
+class ImageEventHandler extends InpDBEventHandler {
+
+ function mapEvents()
+ {
+ parent::mapEvents(); // ensure auto-adding of approve/decine and so on events
+ $image_events = Array(
+ 'OnAfterCopyToTemp'=>'ImageAction',
+ 'OnBeforeDeleteFromLive'=>'ImageAction',
+ 'OnBeforeCopyToLive'=>'ImageAction',
+ 'OnBeforeItemDelete'=>'ImageAction',
+ 'OnAfterClone'=>'ImageAction',
+ );
+
+ $this->eventMethods = array_merge($this->eventMethods, $image_events);
+ }
+
+ function customProcessing(&$event, $type)
+ {
+ $object =& $event->GetObject();
+ switch ($type)
+ {
+ case 'before' :
+ if ($object->GetDBField('LocalImage'))
+ {
+ $object->SetDBField('Url', '');
+ }
+ else
+ {
+ $object->SetDBField('LocalPath', '');
+ }
+
+ if ($object->GetDBField('LocalThumb'))
+ {
+ $object->SetDBField('ThumbUrl', '');
+ }
+ else
+ {
+ $object->SetDBField('ThumbPath', '');
+ }
+
+ if ($object->GetDBField('SameImages'))
+ {
+ $object->SetDBField('LocalImage', 1);
+ $object->SetDBField('LocalPath', '');
+ $object->SetDBField('Url', '');
+ }
+ break;
+ case 'after' :
+ if ($object->GetDBField('DefaultImg') )
+ {
+ $sql = 'UPDATE '.$object->TableName.' SET DefaultImg=0 WHERE ResourceId='.
+ $object->GetDBField('ResourceId').' AND ImageId<>'.
+ $object->GetId();
+ $res = $this->Conn->Query($sql);
+ }
+ break;
+ default:
+ }
+ }
+
+ function ImageAction(&$event)
+ {
+ $id = $event->getEventParam('id');
+ $object =& $this->Application->recallObject($event->Prefix.'.-item', $event->Prefix);
+ if (in_array($event->Name, Array('OnBeforeDeleteFromLive','OnAfterClone')) ) {
+ $object->SwitchToLive();
+ }
+ elseif ($event->Name == 'OnBeforeItemDelete') {
+ // keep current table
+ }
+ else {
+ $object->SwitchToTemp();
+ }
+
+ $object->Load($id);
+
+ $fields = Array('LocalPath' => 'LocalImage', 'ThumbPath' => 'LocalThumb');
+ foreach ($fields as $a_field => $mode_field) {
+ $file = $object->GetField($a_field);
+ if (!$file) continue;
+ $source_file = FULL_PATH.$file;
+
+ switch ($event->Name) {
+ // Copy image files to pending dir and update corresponding fields in temp record
+ // Checking for existing files and renaming if nessessary - two users may upload same pending files at the same time!
+ case 'OnAfterCopyToTemp':
+ $new_file = IMAGES_PENDING_PATH . $this->ValidateFileName(FULL_PATH.IMAGES_PENDING_PATH, basename($file));
+ $dest_file = FULL_PATH.$new_file;
+ copy($source_file, $dest_file);
+ $object->Fields[$a_field]['skip_empty'] = false;
+ $object->SetDBField($a_field, $new_file);
+ break;
+
+ // Copy image files to live dir (checking if fileexists and renameing if nessessary)
+ // and update corresponding fields in temp record (which gets copied to live automatically)
+ case 'OnBeforeCopyToLive':
+ if ( $object->GetDBField($mode_field) ) { // if image is local
+ // rename file if it exists in live folder
+ $new_file = IMAGES_PATH . $this->ValidateFileName(FULL_PATH.IMAGES_PATH, basename($file));
+ $dest_file = FULL_PATH.$new_file;
+ rename($source_file, $dest_file);
+ }
+ else { // if image is remote url - remove local file (if any), update local file field with empty value
+ if (file_exists($source_file)) @unlink($source_file);
+ $new_file = '';
+ }
+ $object->Fields[$a_field]['skip_empty'] = false;
+ $object->SetDBField($a_field, $new_file);
+ break;
+
+ case 'OnBeforeDeleteFromLive': // Delete image files from live folder before copying over from temp
+ case 'OnBeforeItemDelete': // Delete image files when deleteing Image object
+ @unlink(FULL_PATH.$file);
+ break;
+
+ case 'OnAfterClone': // Copy files when cloning objects, renaming it on the fly
+ $path_info = pathinfo($file);
+ $new_file = $path_info['dirname'].'/'.$this->ValidateFileName(FULL_PATH.$path_info['dirname'], $path_info['basename']);
+ $dest_file = FULL_PATH . $new_file;
+ copy($source_file, $dest_file);
+ $object->Fields[$a_field]['skip_empty'] = false;
+ $object->SetDBField($a_field, $new_file);
+ break;
+ }
+ }
+ if ( in_array($event->Name, Array('OnAfterClone', 'OnBeforeCopyToLive', 'OnAfterCopyToTemp')) ) {
+ $object->Update(null, true);
+ }
+ }
+
+ function ValidateFileName($path, $name)
+ {
+ $parts = pathinfo($name);
+ $ext = '.'.$parts['extension'];
+ $filename = substr($parts['basename'], 0, -strlen($ext));
+ $new_name = $filename.$ext;
+ while ( file_exists($path.'/'.$new_name) )
+ {
+ if ( preg_match("/({$filename}_)([0-9]*)($ext)/", $new_name, $regs) ) {
+ $new_name = $regs[1].($regs[2]+1).$regs[3];
+ }
+ else {
+ $new_name = $filename.'_1'.$ext;
+ }
+ }
+ return $new_name;
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function OnSetPrimary(&$event)
+ {
+ $object =& $event->getObject();
+ $object->SetDBField('DefaultImg', 1);
+ $object->Update();
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function OnBeforeItemUpdate(&$event)
+ {
+ $object =& $event->getObject();
+// $parent_info = $object->getLinkedInfo();
+ $id = $object->GetDBField('ResourceId');
+// $id = $parent_info['ParentId'] ? $parent_info['ParentId'] : $this->Application->GetVar('p_id');
+ $sql = 'SELECT ImageId FROM '.$object->TableName.' WHERE ResourceId='.$id.' AND DefaultImg=1';
+ if(!$this->Conn->GetOne($sql))
+ {
+ $object->SetDBField('DefaultImg', 1);
+ }
+ if($object->GetDBField('DefaultImg') && $object->Validate())
+ {
+
+ $sql = 'UPDATE '.$object->TableName.'
+ SET DefaultImg = 0
+ WHERE ResourceId = '.$id.' AND ImageId <> '.$object->GetDBField('ImageId');
+ $this->Conn->Query($sql);
+ $object->SetDBField('Enabled', 1);
+ }
+ }
+
+ function OnAfterItemCreate(&$event)
+ {
+ $event->CallSubEvent('OnBeforeItemUpdate');
+ $object =& $event->getObject();
+ $object->Update();
+ }
+
+ /**
+ * Deletes all selected items.
+ * Automatically recurse into sub-items using temp handler, and deletes sub-items
+ * by calling its Delete method if sub-item has AutoDelete set to true in its config file
+ *
+ * @param kEvent $event
+ */
+ function OnMassDelete(&$event)
+ {
+ $event->status=erSUCCESS;
+
+ $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
+
+ $this->StoreSelectedIDs($event);
+
+ $event->setEventParam('ids', $this->getSelectedIDs($event) );
+ $this->customProcessing($event, 'before');
+ $ids = $event->getEventParam('ids');
+
+ $object =& $event->getObject();
+ $sql = 'SELECT ImageId FROM '.$object->TableName.' WHERE DefaultImg=1';
+ $primary = $this->Conn->GetOne($sql);
+ if( $primary && ($key = array_search($primary, $ids)) )
+ {
+ $sql = 'SELECT ImageId FROM '.$object->TableName.' WHERE DefaultImg=0';
+ $res = $this->Conn->Query($sql);
+ if($res)
+ {
+ unset($ids[$key]);
+ }
+ }
+
+ if($ids)
+ {
+ $temp->DeleteItems($event->Prefix, $event->Special, $ids);
+ }
+ $this->clearSelectedIDs($event);
+ }
+
+ /*function OnAfterItemLoad(&$event)
+ {
+ $object =& $event->getObject();
+
+ if ( $object->GetDBField('ThumbPath') || $object->GetDBField('SameImages') )
+ {
+ // return local image or url
+ $path = $object->GetDBField('LocalThumb') ? PROTOCOL.SERVER_NAME.BASE_PATH.$object->GetDBField('ThumbPath') : $object->GetDBField('ThumbUrl');
+ if ( $object->GetDBField('LocalThumb') && !file_exists(FULL_PATH.$object->GetDBField('ThumbPath')) ) $path = '';
+ }
+ else { // if we need full which is not the same as thumb
+ $path = $object->GetDBField('LocalImage') ? PROTOCOL.SERVER_NAME.BASE_PATH.$object->GetDBField('LocalPath') : $object->GetDBField('Url');
+ if ( $object->GetDBField('LocalImage') && !file_exists(FULL_PATH.$object->GetDBField('LocalPath')) ) $path = '';
+ }
+
+ $object->SetDBField('ImageUrl', $path);
+ }*/
+
+ function SetCustomQuery(&$event)
+ {
+ parent::SetCustomQuery($event);
+
+ $types=$event->getEventParam('types');
+ $except_types=$event->getEventParam('except');
+ $object =& $event->getObject();
+ $type_clauses = Array();
+
+ if( !$this->Application->IsAdmin() )
+ {
+ $object->addFilter('active', '%1$s.Enabled = 1');
+ }
+
+ if($product_id = $event->getEventParam('product_id'))
+ {
+ $object->removeFilter('parent_filter');
+ $sql = 'SELECT ResourceId FROM '.$this->Application->getUnitOption('p', 'TableName').'
+ WHERE ProductId = '.$product_id;
+ $resource_id = (int) $this->Conn->GetOne($sql);
+ $object->addFilter('product_images', '%1$s.ResourceId = '.$resource_id);
+ }
+
+ $type_clauses['additional']['include'] = '%1$s.DefaultImg != 1';
+ $type_clauses['additional']['except'] = '%1$s.DefaultImg = 1';
+ $type_clauses['additional']['having_filter'] = false;
+
+ /********************************************/
+
+ $includes_or_filter =& $this->Application->makeClass('kMultipleFilter');
+ $includes_or_filter->setType(FLT_TYPE_OR);
+
+ $excepts_and_filter =& $this->Application->makeClass('kMultipleFilter');
+ $excepts_and_filter->setType(FLT_TYPE_AND);
+
+ $includes_or_filter_h =& $this->Application->makeClass('kMultipleFilter');
+ $includes_or_filter_h->setType(FLT_TYPE_OR);
+
+ $excepts_and_filter_h =& $this->Application->makeClass('kMultipleFilter');
+ $excepts_and_filter_h->setType(FLT_TYPE_AND);
+
+ $except_types_array=explode(',', $types);
+
+ if ($types){
+ $types_array=explode(',', $types);
+ for ($i=0; $i<sizeof($types_array); $i++){
+ $type=trim($types_array[$i]);
+ if (isset($type_clauses[$type])){
+ if ($type_clauses[$type]['having_filter']){
+ $includes_or_filter_h->removeFilter('filter_'.$type);
+ $includes_or_filter_h->addFilter('filter_'.$type, $type_clauses[$type]['include']);
+ }else{
+ $includes_or_filter->removeFilter('filter_'.$type);
+ $includes_or_filter->addFilter('filter_'.$type, $type_clauses[$type]['include']);
+ }
+ }
+ }
+ }
+
+ if ($except_types){
+ $except_types_array=explode(',', $except_types);
+ for ($i=0; $i<sizeof($except_types_array); $i++){
+ $type=trim($except_types_array[$i]);
+ if (isset($type_clauses[$type])){
+ if ($type_clauses[$type]['having_filter']){
+ $excepts_and_filter_h->removeFilter('filter_'.$type);
+ $excepts_and_filter_h->addFilter('filter_'.$type, $type_clauses[$type]['except']);
+ }else{
+ $excepts_and_filter->removeFilter('filter_'.$type);
+ $excepts_and_filter->addFilter('filter_'.$type, $type_clauses[$type]['except']);
+ }
+ }
+ }
+ }
+
+ $object->addFilter('includes_filter', $includes_or_filter);
+ $object->addFilter('excepts_filter', $excepts_and_filter);
+
+ $object->addFilter('includes_filter_h', $includes_or_filter_h, HAVING_FILTER);
+ $object->addFilter('excepts_filter_h', $excepts_and_filter_h, HAVING_FILTER);
+ }
+}
+
+?>
\ No newline at end of file
Property changes on: trunk/kernel/units/images/image_event_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/kernel/units/images/images.php
===================================================================
--- trunk/kernel/units/images/images.php (nonexistent)
+++ trunk/kernel/units/images/images.php (revision 4303)
@@ -0,0 +1,23 @@
+<?php
+
+class ImagesItem extends kDBItem {
+
+ function Delete($id)
+ {
+ $this->Load($id);
+ $local_path = FULL_PATH.$this->GetDBField('LocalPath');
+ $thumb_path = FULL_PATH.$this->GetDBField('ThumbPath');
+ if(file_exists($local_path))
+ {
+ unlink($local_path);
+ }
+ if(file_exists($thumb_path))
+ {
+ unlink($thumb_path);
+ }
+ return parent::Delete($id);
+ }
+
+}
+
+?>
\ No newline at end of file
Property changes on: trunk/kernel/units/images/images.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/core/kernel/processors/main_processor.php
===================================================================
--- trunk/core/kernel/processors/main_processor.php (revision 4302)
+++ trunk/core/kernel/processors/main_processor.php (revision 4303)
@@ -1,871 +1,871 @@
<?php
class kMainTagProcessor extends TagProcessor {
function Init($prefix,$special)
{
parent::Init($prefix,$special);
$actions =& $this->Application->recallObject('kActions');
$actions->Set('t', $this->Application->GetVar('t'));
$actions->Set('sid', $this->Application->GetSID());
$actions->Set('m_opener', $this->Application->GetVar('m_opener') );
}
/**
* Used to handle calls where tag name
* match with existing php function name
*
* @param Tag $tag
* @return string
*/
function ProcessTag(&$tag)
{
if ($tag->Tag=='include') $tag->Tag='MyInclude';
return parent::ProcessTag($tag);
}
/**
* Creates <base href ..> HTML tag for all templates
* affects future css, js files and href params of links
*
* @return string
* @access public
*/
function Base_Ref()
{
$url = $this->Application->BaseURL().substr(THEMES_PATH,1).'/';
return '<base href="'.$url.'" />';
}
/**
* Returns base url for web-site
*
* @return string
* @access public
*/
function BaseURL()
{
return $this->Application->BaseURL();
}
function TemplatesBase($params)
{
return $this->Application->BaseURL().THEMES_PATH;
}
function ProjectBase($params)
{
return $this->Application->BaseURL();
}
/*function Base($params)
{
return $this->Application->BaseURL().$params['add'];
}*/
/**
* Used to create link to any template.
* use "pass" paramter if "t" tag to specify
* prefix & special of object to be represented
* in resulting url
*
* @param Array $params
* @return string
* @access public
*/
function T($params)
{
//by default link to current template
$t = $this->SelectParam($params, 't,template');
unset($params['t']);
unset($params['template']);
$prefix=isset($params['prefix']) ? $params['prefix'] : ''; unset($params['prefix']);
$index_file = isset($params['index_file']) ? $params['index_file'] : null; unset($params['index_file']);
return $this->Application->HREF($t, $prefix, $params, $index_file);
}
function Link($params)
{
if (isset($params['template'])) {
$params['t'] = $params['template'];
unset($params['template']);
}
if (!isset($params['pass']) && !isset($params['no_pass'])) $params['pass'] = 'm';
if (isset($params['no_pass'])) unset($params['no_pass']);
if( $this->Application->GetVar('admin') ) $params['admin'] = 1;
return $this->T($params);
}
function Env($params)
{
$t = $params['template'];
unset($params['template']);
return $this->Application->BuildEnv($t, $params, 'm', null, false);
}
function FormAction($params)
{
return $this->Application->ProcessParsedTag('m', 't', Array( 'pass'=>'all,m' ) );
}
/*// NEEDS TEST
function Config($params)
{
return $this->Application->ConfigOption($params['var']);
}
function Object($params)
{
$name = $params['name'];
$method = $params['method'];
$tmp =& $this->Application->recallObject($name);
if ($tmp != null) {
if (method_exists($tmp, $method))
return $tmp->$method($params);
else
echo "Method $method does not exist in object ".get_class($tmp)." named $name<br>";
}
else
echo "Object $name does not exist in the appliaction<br>";
}*/
/**
* Tag, that always returns true.
* For parser testing purposes
*
* @param Array $params
* @return bool
* @access public
*/
function True($params)
{
return true;
}
/**
* Tag, that always returns false.
* For parser testing purposes
*
* @param Array $params
* @return bool
* @access public
*/
function False($params)
{
return false;
}
/**
* Returns block parameter by name
*
* @param Array $params
* @return stirng
* @access public
*/
function Param($params)
{
//$parser =& $this->Application->recallObject('TemplateParser');
$res = $this->Application->Parser->GetParam($params['name']);
if ($res === false) $res = '';
if (isset($params['plus']))
$res += $params['plus'];
return $res;
}
/**
* Gets value of specified field from specified prefix_special and set it as parser param
*
* @param Array $params
*/
/*function SetParam($params)
{
// <inp2:m_SetParam param="custom_name" src="cf:FieldName"/>
list($prefix_special, $field_name) = explode(':', $params['src']);
$object =& $this->Application->recallObject($prefix_special);
$name = $this->SelectParam($params, 'param,name,var');
$this->Application->Parser->SetParam($name, $object->GetField($field_name) );
}*/
/**
* Compares block parameter with value specified
*
* @param Array $params
* @return bool
* @access public
*/
function ParamEquals($params)
{
//$parser =& $this->Application->recallObject('TemplateParser');
$name = $this->SelectParam($params, 'name,var,param');
$value = $params['value'];
return ($this->Application->Parser->GetParam($name) == $value);
}
/*function PHP_Self($params)
{
return $HTTP_SERVER_VARS['PHP_SELF'];
}
*/
/**
* Returns session variable value by name
*
* @param Array $params
* @return string
* @access public
*/
function Recall($params)
{
$ret = $this->Application->RecallVar( $this->SelectParam($params,'name,var,param') );
$ret = ($ret === false && isset($params['no_null'])) ? '' : $ret;
if( getArrayValue($params,'special') || getArrayValue($params,'htmlchars')) $ret = htmlspecialchars($ret);
if ( getArrayValue($params, 'urlencode') ) $ret = urlencode($ret);
return $ret;
}
// bad style to store something from template to session !!! (by Alex)
// Used here only to test how session works, nothing more
function Store($params)
{
//echo"Store $params[name]<br>";
$name = $params['name'];
$value = $params['value'];
$this->Application->StoreVar($name,$value);
}
/**
* Sets application variable value(-s)
*
* @param Array $params
* @access public
*/
function Set($params)
{
foreach ($params as $param => $value) {
$this->Application->SetVar($param, $value);
}
}
/**
* Increment application variable
* specified by number specified
*
* @param Array $params
* @access public
*/
function Inc($params)
{
$this->Application->SetVar($params['param'], $this->Application->GetVar($params['param']) + $params['by']);
}
/**
* Retrieves application variable
* value by name
*
* @param Array $params
* @return string
* @access public
*/
function Get($params)
{
$ret = $this->Application->GetVar($this->SelectParam($params, 'name,var,param'), '');
return getArrayValue($params, 'htmlchars') ? htmlspecialchars($ret) : $ret;
}
/**
* Retrieves application constant
* value by name
*
* @param Array $params
* @return string
* @access public
*/
function GetConst($params)
{
return defined($this->SelectParam($params, 'name,const')) ? constant($this->SelectParam($params, 'name,const,param')) : '';
}
/**
* Retrieves configuration variable value by name
*
* @param Array $params
* @return string
* @access public
*/
function GetConfig($params)
{
$config_name = $this->SelectParam($params, 'name,var');
$ret = $this->Application->ConfigValue($config_name);
if( getArrayValue($params, 'escape') ) $ret = addslashes($ret);
return $ret;
}
function ConfigEquals($params)
{
$option = $this->SelectParam($params, 'name,option,var');
return $this->Application->ConfigValue($option) == getArrayValue($params, 'value');
}
/**
* Creates all hidden fields
* needed for kernel_form
*
* @param Array $params
* @return string
* @access public
*/
function DumpSystemInfo($params)
{
$actions =& $this->Application->recallObject('kActions');
$actions->Set('t', $this->Application->GetVar('t') );
$params = $actions->GetParams();
$o='';
foreach ($params AS $name => $val)
{
$o .= "<input type='hidden' name='$name' id='$name' value='$val'>\n";
}
return $o;
}
function GetFormHiddens($params)
{
$sid = $this->Application->GetSID();
$t = $this->SelectParam($params, 'template,t');
unset($params['template']);
$env = $this->Application->BuildEnv($t, $params, 'm', null, false);
$o = '';
if ( $this->Application->RewriteURLs() )
{
$session =& $this->Application->recallObject('Session');
if ($session->NeedQueryString()) {
$o .= "<input type='hidden' name='sid' id='sid' value='$sid'>\n";
}
}
else {
$o .= "<input type='hidden' name='env' id='env' value='$env'>\n";
}
return $o;
}
function Odd_Even($params)
{
$odd = $params['odd'];
$even = $params['even'];
if (!isset($params['var'])) {
$var = 'odd_even';
}
else {
$var = $params['var'];
}
if ($this->Application->GetVar($var) == 'even') {
if (!isset($params['readonly']) || !$params['readonly']) {
$this->Application->SetVar($var, 'odd');
}
return $even;
}
else {
if (!isset($params['readonly']) || !$params['readonly']) {
$this->Application->SetVar($var, 'even');
}
return $odd;
}
}
/**
* Returns phrase translation by name
*
* @param Array $params
* @return string
* @access public
*/
function Phrase($params)
{
// m:phrase name="phrase_name" default="Tr-alala" updated="2004-01-29 12:49"
if (array_key_exists('default', $params)) return $params['default']; //backward compatibility
$translation = $this->Application->Phrase($this->SelectParam($params, 'label,name,title'));
if (getArrayValue($params, 'escape')) {
$translation = htmlspecialchars($translation);
$translation = str_replace('\'', '&#39;', $translation);
$translation = addslashes($translation);
}
return $translation;
}
// for tabs
function is_active($params)
{
$test_templ = $this->SelectParam($params, 'templ,template,t');
if ( !getArrayValue($params,'allow_empty') )
{
$if_true=getArrayValue($params,'true') ? $params['true'] : 1;
$if_false=getArrayValue($params,'false') ? $params['false'] : 0;
}
else
{
$if_true=$params['true'];
$if_false=$params['false'];
}
if ( preg_match("/^".str_replace('/', '\/', $test_templ)."/", $this->Application->GetVar('t'))) {
return $if_true;
}
else {
return $if_false;
}
}
function IsNotActive($params)
{
return !$this->is_active($params);
}
function IsActive($params)
{
return $this->is_active($params);
}
function is_t_active($params)
{
return $this->is_active($params);
}
function CurrentTemplate($params)
{
return $this->is_active($params);
}
/**
* Checks if session variable
* specified by name value match
* value passed as parameter
*
* @param Array $params
* @return string
* @access public
*/
function RecallEquals($params)
{
$name = $this->SelectParam($params, 'name,var');
$value = $params['value'];
return ($this->Application->RecallVar($name) == $value);
}
/**
* Checks if application variable
* specified by name value match
* value passed as parameter
*
* @param Array $params
* @return bool
* @access public
*/
function GetEquals($params)
{
$name = $this->SelectParam($params, 'var,name,param');
$value = $params['value'];
if ($this->Application->GetVar($name) == $value) {
return 1;
}
}
/**
* Includes template
* and returns it's
* parsed version
*
* @param Array $params
* @return string
* @access public
*/
function MyInclude($params)
{
$BlockParser =& $this->Application->makeClass('TemplateParser');
$BlockParser->SetParams($params);
$parser =& $this->Application->Parser;
$this->Application->Parser =& $BlockParser;
$t = $this->SelectParam($params, 't,template,block,name');
$t = eregi_replace("\.tpl$", '', $t);
$templates_cache =& $this->Application->recallObject('TemplatesCache');
$res = $BlockParser->Parse( $templates_cache->GetTemplateBody($t), $t );
if ( !$BlockParser->DataExists && (isset($params['data_exists']) || isset($params['block_no_data'])) ) {
if ($block_no_data = getArrayValue($params, 'block_no_data')) {
$res = $BlockParser->Parse(
$templates_cache->GetTemplateBody($block_no_data, $silent),
$t
);
}
else {
$res = '';
}
}
$this->Application->Parser =& $parser;
$this->Application->Parser->DataExists = $this->Application->Parser->DataExists || $BlockParser->DataExists;
return $res;
}
/*function Kernel_Scripts($params)
{
return '<script type="text/javascript" src="'.PROTOCOL.SERVER_NAME.BASE_PATH.'/kernel3/js/grid.js"></script>';
}*/
/*function GetUserPermission($params)
{
// echo"GetUserPermission $params[name]";
if ($this->Application->RecallVar('user_type') == 1)
return 1;
else {
$perm_name = $params[name];
$aPermissions = unserialize($this->Application->RecallVar('user_permissions'));
if ($aPermissions)
return $aPermissions[$perm_name];
}
}*/
/**
* Set's parser block param value
*
* @param Array $params
* @access public
*/
function AddParam($params)
{
$parser =& $this->Application->Parser; // recallObject('TemplateParser');
foreach ($params as $param => $value) {
$this->Application->SetVar($param, $value);
$parser->SetParam($param, $value);
$parser->AddParam('/\$'.$param.'/', $value);
}
}
/*function ParseToVar($params)
{
$var = $params['var'];
$tagdata = $params['tag'];
$parser =& $this->Application->Parser; //recallObject('TemplateParser');
$res = $this->Application->ProcessTag($tagdata);
$parser->SetParam($var, $res);
$parser->AddParam('/\$'.$var.'/', $res);
return '';
}*/
/*function TagNotEmpty($params)
{
$tagdata = $params['tag'];
$res = $this->Application->ProcessTag($tagdata);
return $res != '';
}*/
/*function TagEmpty($params)
{
return !$this->TagNotEmpty($params);
}*/
/**
* Parses block and returns result
*
* @param Array $params
* @return string
* @access public
*/
function ParseBlock($params)
{
$parser =& $this->Application->Parser; // recallObject('TemplateParser');
return $parser->ParseBlock($params);
}
function RenderElement($params)
{
return $this->ParseBlock($params);
}
/**
* Checks if debug mode is on
*
* @return bool
* @access public
*/
function IsDebugMode()
{
return $this->Application->isDebugMode();
}
function MassParse($params)
{
$qty = $params['qty'];
$block = $params['block'];
$mode = $params['mode'];
$o = '';
if ($mode == 'func') {
$func = create_function('$params', '
$o = \'<tr>\';
$o.= \'<td>a\'.$params[\'param1\'].\'</td>\';
$o.= \'<td>a\'.$params[\'param2\'].\'</td>\';
$o.= \'<td>a\'.$params[\'param3\'].\'</td>\';
$o.= \'<td>a\'.$params[\'param4\'].\'</td>\';
$o.= \'</tr>\';
return $o;
');
for ($i=1; $i<$qty; $i++) {
$block_params['param1'] = rand(1, 10000);
$block_params['param2'] = rand(1, 10000);
$block_params['param3'] = rand(1, 10000);
$block_params['param4'] = rand(1, 10000);
$o .= $func($block_params);
}
return $o;
}
$block_params['name'] = $block;
for ($i=0; $i<$qty; $i++) {
$block_params['param1'] = rand(1, 10000);
$block_params['param2'] = rand(1, 10000);
$block_params['param3'] = rand(1, 10000);
$block_params['param4'] = rand(1, 10000);
$block_params['passed'] = $params['passed'];
$block_params['prefix'] = 'm';
$o.= $this->Application->ParseBlock($block_params, 1);
}
return $o;
}
function AfterScript($params)
{
$after_script = $this->Application->GetVar('after_script');
if ( $after_script ) {
return '<script type="text/javascript">'.$after_script.'</script>';
}
return '';
}
function LoggedIn($params)
{
return $this->Application->LoggedIn();
}
/**
* Checks if user is logged in and if not redirects it to template passed
*
* @param Array $params
*/
function RequireLogin($params)
{
if($permission_groups = getArrayValue($params, 'permissions'))
{
$permission_groups = explode('|', $permission_groups);
$group_has_permission = false;
foreach($permission_groups as $permission_group)
{
$permissions = explode(',', $permission_group);
$has_permission = true;
foreach($permissions as $permission)
{
$has_permission = $has_permission && $this->Application->CheckPermission($permission);
}
$group_has_permission = $group_has_permission || $has_permission;
if($group_has_permission)
{
return;
}
}
if( !$this->Application->LoggedIn() )
{
$t = $this->Application->GetVar('t');
$this->Application->Redirect( $params['login_template'], Array('next_template'=>$t) );
}
else
{
$this->Application->Redirect( $params['no_permissions_template'] );
}
}
$condition = getArrayValue($params,'condition');
if(!$condition)
{
$condition = true;
}
else
{
if( substr($condition,0,1) == '!' )
{
$condition = !$this->Application->ConfigValue( substr($condition,1) );
}
else
{
$condition = $this->Application->ConfigValue($condition);
}
}
$group = $this->SelectParam($params, 'group');
$group_access = true;
if ($group) {
$conn =& $this->Application->DB;
$group_id = $conn->GetOne('SELECT GroupId FROM '.TABLE_PREFIX.'PortalGroup WHERE Name = '.$conn->qstr($group));
if ($group_id) {
$groups = explode(',', $this->Application->RecallVar('UserGroups'));
$group_access = in_array($group_id, $groups);
}
}
if( (!$this->Application->LoggedIn() || !$group_access) && $condition )
{
$t = $this->Application->GetVar('t');
$this->Application->Redirect( $params['login_template'], Array('next_template'=>$t) );
}
}
/**
* Checks if SSL is on and redirects to SSL URL if needed
* If SSL_URL is not defined in config - the tag does not do anything
* If for_logged_in_only="1" exits if user is not logged in.
* If called without params forces https right away. If called with by_config="1" checks the
* Require SSL setting from General Config and if it is ON forces https
*
* @param unknown_type $params
*/
function CheckSSL($params)
{
$ssl = $this->Application->ConfigValue('SSL_URL');
if (!$ssl) return; //SSL URL is not set - no way to require SSL
$require = false;
if ($params['mode'] == 'required') {
$require = true;
if (isset($params['for_logged_in_only']) && $params['for_logged_in_only'] && !$this->Application->LoggedIn()) {
$require = false;
}
if (isset($params['condition'])) {
if (!$this->Application->ConfigValue($params['condition'])) {
$require = false;
}
}
}
$http_query =& $this->Application->recallObject('HTTPQuery');
$pass = $http_query->getRedirectParams();
if ($require) {
if (PROTOCOL == 'https://') {
$this->Application->SetVar('__KEEP_SSL__', 1);
return;
}
$this->Application->Redirect('', array_merge_recursive2($pass, Array('__SSL__' => 1)));
}
else {
if (PROTOCOL == 'https://' && $this->Application->ConfigValue('Force_HTTP_When_SSL_Not_Required')) {
if ($this->Application->GetVar('__KEEP_SSL__')) return;
$this->Application->Redirect('', array_merge_recursive2($pass, Array('__SSL__' => 0)));
}
}
}
function SaveReturnScript($params)
{
// admin/save_redirect.php?do=
$url = str_replace($this->Application->BaseURL(), '', $this->Link($params) );
$url = explode('?', $url, 2);
$url = 'save_redirect.php?'.$url[1].'&do='.$url[0];
$this->Application->StoreVar('ReturnScript', $url);
}
function ConstOn($params)
{
$name = $this->SelectParam($params,'name,const');
- return $this->Application->isDebugMode() && dbg_ConstOn($name);
+ return ConstOn($name);
}
function SetDefaultCategory($params)
{
$module_name = $params['module'];
$module =& $this->Application->recallObject('mod.'.$module_name);
$this->Application->SetVar('m_cat_id', $module->GetDBField('RootCat') );
}
function ImportRedirect($params)
{
$import_id = $this->Application->GetVar('import_id');
if ($import_id) {
// redirect forward to step3 (import parameters coosing)
$this->Application->StoreVar('ImportScriptID', $import_id);
$sql = 'SELECT *
FROM '.TABLE_PREFIX.'ImportScripts
WHERE is_id = '.$import_id;
$db =& $this->Application->GetADODBConnection();
$is_params = $db->GetRow($sql);
if ($is_params['is_type'] == 'db') {
$this->Application->Redirect('', null, '', 'import/step3.php');
}
elseif ($is_params['is_type'] == 'csv') {
$module = strtolower($is_params['is_Module']);
$template = $module.'/import';
$sql = 'SELECT Var
FROM '.TABLE_PREFIX.'Modules
WHERE LOWER(Name) = '.$db->qstr($module);
$item_prefix = $db->GetOne($sql);
$pass_params = Array('m_opener' => 'd', $item_prefix.'.import_id' => 0, $item_prefix.'.import_event' => 'OnNew', 'pass' => 'm,'.$item_prefix.'.import');
$this->Application->Redirect($template, $pass_params);
}
}
else {
// redirect back to step2 (import type choosing)
$this->Application->Redirect('', null, '', 'import/step2.php');
}
}
function GetSectionTitle($params)
{
$params['name'] = replaceModuleSection($params['phrase']);
return $this->Phrase($params);
}
function GetSectionIcon($params)
{
return replaceModuleSection($params['icon']);
}
function StoreSystemVars($params)
{
// save theese variables to session, because they are useful for most configuration templates
$this->Application->LinkVar('module');
$this->Application->LinkVar('section');
}
function StoreMainPrefix($params)
{
$this->Application->LinkVar('main_prefix'); // window prefix, that opener selector
$this->Application->LinkVar('dst_field'); // field to set value choosed in selector
$this->Application->LinkVar('return_template'); // template to go, when something was coosen from popup (from finalizePopup)
}
}
?>
Property changes on: trunk/core/kernel/processors/main_processor.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.39
\ No newline at end of property
+1.40
\ No newline at end of property
Index: trunk/core/units/reviews/reviews_config.php
===================================================================
--- trunk/core/units/reviews/reviews_config.php (nonexistent)
+++ trunk/core/units/reviews/reviews_config.php (revision 4303)
@@ -0,0 +1,131 @@
+<?php
+
+$config = Array(
+ 'Prefix' => 'rev',
+
+ 'Clones' => Array(
+
+ 'l-rev' => Array('ParentPrefix' => 'l'),
+ 'n-rev' => Array('ParentPrefix' => 'n'),
+ 'bb-rev'=> Array('ParentPrefix' => 'bb'),
+ 'p-rev' => Array('ParentPrefix' => 'p'),
+ ),
+
+ 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'),
+ 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'),
+ 'EventHandlerClass' => Array('class'=>'ReviewsEventHandler','file'=>'reviews_event_handler.php','build_event'=>'OnBuild'),
+ 'TagProcessorClass' => Array('class'=>'ReviewsTagProcessor','file'=>'reviews_tag_processor.php','build_event'=>'OnBuild'),
+ 'AutoLoad' => true,
+
+ 'QueryString' => Array(
+ 1 => 'id',
+ 2 => 'page',
+ 3 => 'event',
+ ),
+
+
+ 'ParentPrefix' => 'p', // replace all usage of rev to "p-rev" and then remove this param from here and Prefix too
+
+ 'IDField' => 'ReviewId',
+ 'StatusField' => Array('Status'), // field, that is affected by Approve/Decline events
+ 'TableName' => TABLE_PREFIX.'ItemReview',
+ 'ParentTableKey' => 'ResourceId', // linked field in master table
+ 'ForeignKey' => 'ItemId', // linked field in subtable
+
+ 'AutoDelete' => true,
+ 'AutoClone' => true,
+
+ 'TitlePresets' => Array(
+ 'reviews_edit' => Array('format' => "!la_title_Editing_Review!"),
+ ),
+ 'FilterMenu' => Array(
+ 'Groups' => Array(
+ Array('mode' => 'AND', 'filters' => Array('show_active','show_pending','show_disabled'), 'type' => WHERE_FILTER),
+ ),
+ 'Filters' => Array(
+ 'show_active' => Array('label' =>'la_Active', 'on_sql' => '', 'off_sql' => '%1$s.Status != 1' ),
+ 'show_pending' => Array('label' => 'la_Pending', 'on_sql' => '', 'off_sql' => '%1$s.Status != 2' ),
+ 'show_disabled' => Array('label' => 'la_Disabled', 'on_sql' => '', 'off_sql' => '%1$s.Status != 0' ),
+ )
+ ),
+
+ 'CalculatedFields' => Array(
+ '' => Array(
+ 'ReviewedBy' => 'IF( ISNULL(pu.Login), IF (%1$s.CreatedById = -1, \'root\', IF (%1$s.CreatedById = -2, \'Guest\', \'n/a\')), pu.Login )',
+ ),
+ 'products' => Array(
+ 'ReviewedBy' => 'IF( ISNULL(pu.Login), IF (%1$s.CreatedById = -1, \'root\', IF (%1$s.CreatedById = -2, \'Guest\', \'n/a\')), pu.Login )',
+ 'ItemName' => 'pr.l1_Name',
+ 'ProductId' => 'pr.ProductId',
+ ),
+ 'product' => Array(
+ 'ReviewedBy' => 'IF( ISNULL(pu.Login), IF (%1$s.CreatedById = -1, \'root\', IF (%1$s.CreatedById = -2, \'Guest\', \'n/a\')), pu.Login )',
+ 'ItemName' => 'pr.l1_Name',
+ 'ProductId' => 'pr.ProductId',
+ ),
+
+ ),
+
+ // key - special, value - list select sql
+ 'ListSQLs' => Array( ''=>'SELECT %1$s.* %2$s FROM %1$s
+ LEFT JOIN '.TABLE_PREFIX.'PortalUser pu ON pu.PortalUserId = %1$s.CreatedById',
+
+ 'products' => ' SELECT %1$s.* %2$s
+ FROM %1$s, '.TABLE_PREFIX.'Products pr
+ LEFT JOIN '.TABLE_PREFIX.'PortalUser pu ON pu.PortalUserId = %1$s.CreatedById',
+
+ 'product' => ' SELECT %1$s.* %2$s
+ FROM %1$s, '.TABLE_PREFIX.'Products pr
+ LEFT JOIN '.TABLE_PREFIX.'PortalUser pu ON pu.PortalUserId = %1$s.CreatedById',
+ ),
+
+ 'ItemSQLs' => Array( ''=> 'SELECT * FROM %s'),
+
+ 'ListSortings' => Array(
+ '' => Array(
+ 'ForcedSorting' => Array('Priority' => 'desc'),
+ 'Sorting' => Array('CreatedOn' => 'desc'),
+ )
+ ),
+
+ 'Fields' => Array(
+ 'ReviewId' => Array('type'=>'int'),
+ 'CreatedOn' => Array('formatter'=>'kDateFormatter','not_null'=>1,'default'=>'#NOW#'),
+ 'ReviewText' => Array('type'=>'string','required'=>1,'not_null'=>1,'default'=>''),
+ 'IPAddress' => Array('type'=>'string','max_value_inc'=>15,'not_null'=>1,'default'=>''),
+ 'ItemId' => Array('type'=>'int','not_null'=>1,'default'=>0),
+ 'CreatedById' => Array('formatter'=>'kLEFTFormatter','options'=>Array(-1=>'root',-2=>'Guest'),'left_sql'=>'SELECT %s FROM '.TABLE_PREFIX.'PortalUser WHERE `%s` = \'%s\'','left_key_field'=>'PortalUserId','left_title_field'=>'Login','required'=>1,'not_null'=>1,'default'=>-1),
+ 'ItemType' => Array('type'=>'int','not_null'=>1,'default'=>0),
+ 'Priority' => Array('type'=>'int','not_null'=>1,'default'=>0),
+ 'Status' => Array('formatter'=>'kOptionsFormatter', 'use_phrases' => 1, 'options'=>Array(1=>'la_Active',2=>'la_Pending',0=>'la_Disabled'),'not_null'=>1,'default'=>0 ),
+ 'TextFormat' => Array('type'=>'int','not_null'=>1,'default'=>0),
+ 'Module' => Array('type'=>'string','not_null'=>1,'default'=>''),
+ ),
+ 'VirtualFields' => Array(
+ 'ReviewedBy' => Array(),
+ ),
+
+ 'Grids' => Array(
+ 'Default' => Array( 'Icons' => Array('default'=>'icon16_custom.gif',1=>'icon16_review.gif',2=>'icon16_review_pending.gif',0=>'icon16_review_disabled.gif'),
+ 'Fields' => Array(
+ 'ReviewText' => Array( 'title'=>'la_col_ReviewText', 'data_block' => 'reviewtext_checkbox_td'),
+ 'ReviewedBy' => Array( 'title'=>'la_col_ReviewedBy' ),
+ 'CreatedOn_formatted' => Array( 'title'=>'la_col_CreatedOn', 'sort_field' => 'CreatedOn' ),
+ 'Status' => Array( 'title'=>'la_col_Status' ),
+ ),
+
+ ),
+
+ 'ReviewsSection' => Array( 'Icons' => Array('default'=>'icon16_custom.gif',1=>'icon16_review.gif',2=>'icon16_review_pending.gif',0=>'icon16_review_disabled.gif'),
+ 'Fields' => Array(
+ 'ReviewText' => Array( 'title'=>'la_col_ReviewText', 'data_block' => 'grid_checkbox_namelink_td'),
+ 'ReviewedBy' => Array( 'title'=>'la_col_ReviewedBy' ),
+ 'CreatedOn_formatted' => Array( 'title'=>'la_col_CreatedOn', 'sort_field' => 'CreatedOn' ),
+ 'Status' => Array( 'title'=>'la_col_Status' ),
+ ),
+
+ ),
+ ),
+ );
+
+?>
\ No newline at end of file
Property changes on: trunk/core/units/reviews/reviews_config.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/core/units/reviews/reviews_tag_processor.php
===================================================================
--- trunk/core/units/reviews/reviews_tag_processor.php (nonexistent)
+++ trunk/core/units/reviews/reviews_tag_processor.php (revision 4303)
@@ -0,0 +1,102 @@
+<?php
+
+class ReviewsTagProcessor extends kDBTagProcessor
+{
+
+
+ /**
+ * Returns a link for editing product
+ *
+ * @param Array $params
+ * @return string
+ */
+ function ItemEditLink($params)
+ {
+ $item_prefix = $params['item_prefix'];
+ $id_field = $this->Application->getUnitOption($item_prefix,'IDField');
+
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(),$this->Prefix, $params);
+ $item_id = $object->GetDBField($id_field);
+
+ return $this->Application->HREF($params['edit_template'],'', Array(
+ 'm_opener'=>'d',
+ $item_prefix.'_event'=>'OnEdit',
+ $item_prefix.'_id'=>$item_id,
+ 'pass'=>'all,'.$item_prefix
+ ),'index4.php' );
+ }
+
+ /**
+ * Get's reuested field value
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function Field($params)
+ {
+ $field = $this->SelectParam($params, 'name,field');
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(),$this->Prefix, $params);
+
+ if($field == 'ReviewText')
+ {
+ if( $object->GetDBField('TextFormat') == 1 )
+ {
+ $params['no_special'] = 'no_special';
+ }
+ else
+ {
+ unset($params['no_special']);
+ }
+ }
+
+ return parent::Field($params);
+
+ }
+
+ function AlreadyReviewed($params)
+ {
+ $user_id = ($this->Application->GetVar('u_id') == 0) ? -2 : $this->Application->GetVar('u_id');
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object =& $this->Application->recallObject($this->getPrefixSpecial());
+ $product_info = $object->getLinkedInfo();
+
+ $sql = ' SELECT * FROM '.TABLE_PREFIX.'SpamControl
+ WHERE ItemResourceId='.$product_info['ParentId'].'
+ AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
+ AND PortalUserId='.$user_id.'
+ AND DataType="Review"';
+ $res = $this->Conn->GetRow($sql);
+ if($res['Expire'] > adodb_mktime())
+ {
+ $ret = 1;
+ }
+ else
+ {
+ $sql = 'DELETE FROM '.TABLE_PREFIX.'SpamControl
+ WHERE ItemResourceId='.$product_info['ParentId'].'
+ AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
+ AND PortalUserId='.$user_id.'
+ AND DataType="Review"';
+ $this->Conn->Query($sql);
+ $ret = 0;
+ }
+ return $ret;
+ }
+
+ function HasError($params)
+ {
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
+ if(method_exists($object, 'GetErrorMsg'))
+ {
+ return parent::HasError($params);
+ }
+ else
+ {
+ return 0;
+ }
+ }
+}
+
+
+?>
\ No newline at end of file
Property changes on: trunk/core/units/reviews/reviews_tag_processor.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/core/units/reviews/reviews_event_handler.php
===================================================================
--- trunk/core/units/reviews/reviews_event_handler.php (nonexistent)
+++ trunk/core/units/reviews/reviews_event_handler.php (revision 4303)
@@ -0,0 +1,142 @@
+<?php
+
+ class ReviewsEventHandler extends InpDBEventHandler
+ {
+ /**
+ * Apply any custom changes to list's sql query
+ *
+ * @param kEvent $event
+ * @access protected
+ * @see OnListBuild
+ */
+ function SetCustomQuery(&$event)
+ {
+ $object =& $event->getObject();
+ switch ($event->Special)
+ {
+ case 'showall':
+ $object->clearFilters();
+ break;
+
+ case 'products':
+ $object->removeFilter('parent_filter'); // this is important
+ $object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId');
+ // $object->addFilter('active', '%1$s.Status = 1');
+
+ /*$this->Application->setUnitOption('p', 'AutoLoad', true);
+ $product =& $this->Application->recallObject('p');
+ $object->addFilter('current_product', 'pr.ResourceId = '.$product->GetDBField('ResourceId'));*/
+ break;
+
+ case 'product':
+ $object->clearFilters();
+ $object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId');
+ $object->addFilter('active', '%1$s.Status = 1');
+ $this->Application->setUnitOption('p', 'AutoLoad', true);
+ $product =& $this->Application->recallObject('p');
+ $object->addFilter('current_product', 'pr.ResourceId = '.$product->GetDBField('ResourceId'));
+
+ break;
+ }
+
+ if($event->getEventParam('type') == 'current_user')
+ {
+ $user_id = $this->Application->GetVar('u_id') ? $this->Application->GetVar('u_id') : -2;
+ $ip = $_SERVER['REMOTE_ADDR'];
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object =& $event->getObject();
+ $product_info = $object->getLinkedInfo();
+ $object->addFilter('current_item', '%1$s.ItemId = '.$product_info['ParentId']);
+ $object->addFilter('current_user', '%1$s.CreatedById = '.$user_id);
+ $object->addFilter('current_ip', '%1$s.IPAddress = "'.$ip.'"');
+
+ }
+ }
+
+ /**
+ * Adds review from front in case if user is logged in
+ *
+ * @param kEvent $event
+ */
+ function OnAddReview(&$event)
+ {
+ $user_id = ($this->Application->GetVar('u_id') == 0) ? -2 : $this->Application->GetVar('u_id');
+ $event->redirect_params = Array('pass' => 'all,p');
+
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object =& $event->getObject();
+ $item_info = $this->Application->GetVar('rev_product');
+ $product_info = $object->getLinkedInfo();
+
+ $sql = ' SELECT * FROM '.TABLE_PREFIX.'SpamControl
+ WHERE ItemResourceId='.$product_info['ParentId'].'
+ AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
+ AND PortalUserId='.$user_id.'
+ AND DataType="Review"';
+ $res = $this->Conn->GetRow($sql);
+
+ if( $res && $res['Expire'] < adodb_mktime() )
+ {
+ $sql = ' DELETE FROM '.TABLE_PREFIX.'SpamControl
+ WHERE ItemResourceId='.$product_info['ParentId'].'
+ AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
+ AND PortalUserId='.$user_id.'
+ AND DataType="Review"';
+ $this->Conn->Query($sql);
+ unset($res);
+ }
+
+ if(!$res)
+ {
+ $object->SetFieldsFromHash( array_shift($item_info) );
+ $object->SetDBField('CreatedById', $user_id);
+ $object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']);
+ $object->SetDBField('CreatedOn', adodb_mktime());
+
+ if( $this->Application->CheckPermission('PRODUCT.REVIEW.PENDING') )
+ {
+ $object->SetDBField('Status', 2);
+ }
+ elseif( $this->Application->CheckPermission('PRODUCT.REVIEW') )
+ {
+ $object->SetDBField('Status', 1);
+ }
+
+ $object->SetDBField('ItemId', $product_info['ParentId']);
+
+ $event->CallSubEvent('OnCreate');
+
+ if($event->status == erSUCCESS)
+ {
+ $product_object =& $this->Application->recallObject('p');
+ $sql = ' SELECT COUNT(ReviewId)
+ FROM '.$object->TableName.'
+ WHERE ItemId='.$product_info['ParentId'];
+ $review_qty = $this->Conn->GetOne($sql);
+ $product_object->SetDBField('CachedReviewsQty', $review_qty);
+ $product_object->Update();
+ $expire = adodb_mktime() + $this->Application->ConfigValue('product_ReviewDelay_Value') * $this->Application->ConfigValue('product_ReviewDelay_Interval');
+ $sql = ' INSERT INTO '.TABLE_PREFIX.'SpamControl
+ (ItemResourceId, IPaddress, PortalUserId, DataType, Expire)
+ VALUES ('.$product_info['ParentId'].',
+ "'.$_SERVER['REMOTE_ADDR'].'",
+ '.$user_id.',
+ "Review",
+ '.$expire.')';
+ $this->Conn->Query($sql);
+
+ $event->redirect_params = Array('pass' => 'all,p');
+ $event->redirect = $this->Application->GetVar('success_template');
+ }
+ }
+ else
+ {
+ $event->status == erFAIL;
+ $event->redirect=false;
+ $object->FieldErrors['ReviewText']['pseudo'] = 'too_frequent';
+ $object->ErrorMsgs['too_frequent'] = $this->Application->Phrase('lu_ferror_review_duplicate');
+ }
+ }
+ }
+
+?>
\ No newline at end of file
Property changes on: trunk/core/units/reviews/reviews_event_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/core/units/relationship/relationship_event_handler.php
===================================================================
--- trunk/core/units/relationship/relationship_event_handler.php (nonexistent)
+++ trunk/core/units/relationship/relationship_event_handler.php (revision 4303)
@@ -0,0 +1,176 @@
+<?php
+
+ class RelationshipEventHandler extends InpDBEventHandler
+ {
+ /**
+ * Add new relation
+ *
+ * @param kEvent $event
+ */
+ function OnAddRelation(&$event)
+ {
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object =& $event->getObject();
+
+ $table_info = $object->getLinkedInfo();
+ $main_item_type = $this->Application->getUnitOption($table_info['ParentPrefix'],'ItemType');
+
+ $target['id'] = $this->Application->GetVar('TargetId');
+ $target['type'] = $this->Application->GetVar('TargetType');
+
+
+ $object->SetDBField($table_info['ForeignKey'], $table_info['ParentId']);
+ $object->SetDBField('SourceType', $main_item_type);
+ $object->SetDBField('TargetId', $target['id']);
+ $object->SetDBField('TargetType', $target['type']);
+
+ // 1. get item info used in relation
+ $configs = $this->extractModulesInfo();
+ foreach($configs as $prefix => $config_data)
+ {
+ if($config_data['ItemType'] == $target['type']) break;
+ }
+
+ $db =& $this->Application->GetADODBConnection();
+ $item['name'] = $db->GetOne('SELECT '.$config_data['TitleField'].' FROM '.$config_data['TableName'].' WHERE ResourceId = '.$target['id']);
+ $item['type'] = $this->Application->Phrase($config_data['TitlePhrase']);
+ $object->SetDBField('ItemName', $item['name']);
+ $object->SetDBField('ItemType', $item['type']);
+
+ $object->setID(0);
+
+ $event->redirect = false;
+
+ // 2. substitute opener
+ $opener_stack = $this->Application->RecallVar('opener_stack');
+ $opener_stack = $opener_stack ? unserialize($opener_stack) : Array();
+ array_pop($opener_stack);
+
+ $new_level = 'index4.php|'.ltrim($this->Application->BuildEnv('in-commerce/products/products_relations',Array('m_opener'=>'u'),'all'),ENV_VAR_NAME.'=');
+ array_push($opener_stack,$new_level);
+ $this->Application->StoreVar('opener_stack',serialize($opener_stack));
+
+ $this->Application->SetVar($event->Prefix_Special.'_SaveEvent','OnCreate');
+ }
+
+ /**
+ * Creates needed sql query to load list,
+ * if no query is defined in config for
+ * special requested, then use default
+ * query
+ *
+ * @param kEvent $event
+ * @access protected
+ */
+ function ListPrepareQuery(&$event)
+ {
+ return $this->BaseQuery($event,'ListSQLs');
+ }
+
+ /**
+ * Creates needed sql query to load item,
+ * if no query is defined in config for
+ * special requested, then use default
+ * query
+ *
+ * @param kEvent $event
+ * @access protected
+ */
+ function ItemPrepareQuery(&$event)
+ {
+ return $this->BaseQuery($event,'ItemSQLs');
+ }
+
+
+ /**
+ * Get item name & type based on relation type & modules installed
+ *
+ * @param kEvent $event
+ * @param string $sql_field
+ */
+ function BaseQuery(&$event, $sql_field)
+ {
+ $sqls = $this->Application->getUnitOption($event->Prefix,$sql_field);
+ $sql = isset($sqls[$event->Special]) ? $sqls[$event->Special] : $sqls[''];
+
+ $configs = $this->extractModulesInfo();
+
+ // 2. build sql based on information queried
+ $sql_templates['ItemName'] = 'IFNULL(%s.%s,\' \')';
+ $sql_templates['TableJoin'] = 'LEFT JOIN %1$s ON %1$s.ResourceId = rel.TargetId';
+ $sql_templates['TargetName'] = 'IF(rel.TargetType = %s, \'%s\', %s)';
+
+ $sql_parts = Array();
+ $sql_parts['TargetName'] = "''";
+ foreach($configs as $prefix => $config_data)
+ {
+ $sql_parts['ItemName'][] = sprintf($sql_templates['ItemName'], $config_data['TableName'], $config_data['TitleField']);
+ $sql_parts['TableJoin'][] = sprintf($sql_templates['TableJoin'], $config_data['TableName']);
+
+ $sql_parts['TargetName'] = sprintf( $sql_templates['TargetName'],
+ $config_data['ItemType'],
+ '!'.$config_data['TitlePhrase'].'!',
+ $sql_parts['TargetName']);
+ $sql_parts['TargetName'] = str_replace('rel','%1$s',$sql_parts['TargetName']);
+ }
+
+ $object =& $event->getObject();
+
+ $vars = Array('#ITEM_NAMES#', '#ITEM_TYPES#');
+ $replacements = Array( implode(', ',$sql_parts['ItemName']), $sql_parts['TargetName'] );
+
+ $calculated_fields =& $object->getProperty('CalculatedFields');
+ foreach($calculated_fields as $field_name => $field_expression)
+ {
+ $calculated_fields[$field_name] = str_replace($vars,$replacements,$field_expression);
+ }
+
+ $object->setProperty('CalculatedFields', $calculated_fields);
+
+ $sql = str_replace('#ITEM_JOIN#', implode(' ',$sql_parts['TableJoin']), $sql);
+ $sql = str_replace('rel.','%1$s.',$sql);
+
+ return $sql;
+ }
+
+ /**
+ * Get configs from modules installed
+ *
+ * @return Array
+ * @access private
+ */
+ function extractModulesInfo()
+ {
+ // 1. get installed modules & their config info
+ $db =& $this->Application->GetADODBConnection();
+ $prefixes = $db->GetCol('SELECT Var FROM '.TABLE_PREFIX.'Modules');
+ $configs = Array();
+ foreach($prefixes as $prefix)
+ {
+ $configs[$prefix] = $this->Application->getUnitOptions($prefix);
+ if($configs[$prefix] === false) unset($configs[$prefix]);
+ }
+ return $configs;
+ }
+
+
+ /**
+ * Deletes relations to hooked item from other items
+ *
+ * @param kEvent $event
+ */
+ function OnDeleteForeignRelations(&$event)
+ {
+ $main_object =& $event->MasterEvent->getObject();
+ $resource_id = $main_object->GetDBField('ResourceId');
+
+ $table = $this->Application->getUnitOption($event->Prefix,'TableName');
+ $sql = 'DELETE FROM '.$table.' WHERE TargetId = '.$resource_id;
+ $this->Conn->Query($sql);
+ }
+
+
+ }
+
+
+?>
\ No newline at end of file
Property changes on: trunk/core/units/relationship/relationship_event_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/core/units/relationship/relationship_config.php
===================================================================
--- trunk/core/units/relationship/relationship_config.php (nonexistent)
+++ trunk/core/units/relationship/relationship_config.php (revision 4303)
@@ -0,0 +1,97 @@
+<?php
+
+$config = Array(
+ 'Prefix' => 'rel',
+ 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'),
+ 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'),
+ 'EventHandlerClass' => Array('class'=>'RelationshipEventHandler','file'=>'relationship_event_handler.php','build_event'=>'OnBuild'),
+ 'TagProcessorClass' => Array('class'=>'kDBTagProcessor','file'=>'','build_event'=>'OnBuild'),
+ 'AutoLoad' => true,
+ 'Hooks' => Array(
+ Array(
+ 'Mode' => hAFTER,
+ 'Conditional' => false,
+ 'HookToPrefix' => 'p',
+ 'HookToSpecial' => '-item',
+ 'HookToEvent' => Array('OnAfterItemDelete'),
+ 'DoPrefix' => '',
+ 'DoSpecial' => '',
+ 'DoEvent' => 'OnDeleteForeignRelations',
+ ),
+ ),
+ 'QueryString' => Array(
+ 1 => 'id',
+ 2 => 'page',
+ 3 => 'event',
+ ),
+ 'IDField' => 'RelationshipId',
+ 'StatusField' => Array('Enabled','Type'),
+ 'TableName' => TABLE_PREFIX.'Relationship',
+ 'ParentTableKey'=> 'ResourceId',
+ 'ForeignKey' => 'SourceId',
+ 'ParentPrefix' => 'p',
+ 'AutoDelete' => true,
+ 'AutoClone' => true,
+
+ 'FilterMenu' => Array(
+ 'Groups' => Array(
+ Array('mode' => 'AND', 'filters' => Array('show_active','show_disabled'), 'type' => WHERE_FILTER),
+ Array('mode' => 'AND', 'filters' => Array('show_recip','show_oneway'), 'type' => WHERE_FILTER),
+ ),
+ 'Filters' => Array(
+ 'show_active' => Array('label' =>'la_Active', 'on_sql' => '', 'off_sql' => 'Enabled != 1' ),
+ 'show_disabled' => Array('label' => 'la_Disabled', 'on_sql' => '', 'off_sql' => 'Enabled != 0' ),
+ 's1' => Array(),
+ 'show_recip' => Array('label' => 'la_Reciprocal', 'on_sql' => '', 'off_sql' => '%1$s.Type != 1' ),
+ 'show_oneway' => Array('label' => 'la_OneWay', 'on_sql' => '', 'off_sql' => '%1$s.Type != 2' ),
+ )
+ ),
+
+ 'CalculatedFields' => Array(
+ '' => Array(
+ 'ItemName' => 'TRIM(CONCAT(#ITEM_NAMES#))',
+ 'ItemType' => '#ITEM_TYPES#',
+ ),
+ ),
+
+ 'ListSQLs' => Array( ''=> 'SELECT %1$s.RelationshipId, %1$s.Priority, %1$s.Type, %1$s.Enabled %2$s
+ FROM %1$s #ITEM_JOIN#',
+ ), // key - special, value - list select sql
+
+ 'ListSortings' => Array(
+ '' => Array(
+ 'ForcedSorting' => Array('Priority' => 'desc'),
+ 'Sorting' => Array('ItemName' => 'asc', 'ItemType' => 'asc'),
+ )
+ ),
+ 'ItemSQLs' => Array( '' => 'SELECT %1$s.* %2$s FROM %1$s #ITEM_JOIN#',),
+
+ 'Fields' => Array(
+ 'RelationshipId' => Array(),
+ 'SourceId' => Array('type'=>'int'),
+ 'TargetId' => Array('type'=>'int'),
+ 'SourceType' => Array('type'=>'int','not_null'=>1,'default'=>0),
+ 'TargetType' => Array('type'=>'int','not_null'=>1,'default'=>0),
+ 'Type' => Array('type'=>'int','formatter'=>'kOptionsFormatter','options'=>Array(1=>'la_Reciprocal',0=>'la_OneWay'),'not_null'=>1,'default'=>0,'use_phrases'=>1),
+ 'Enabled' => Array('type'=>'int','formatter'=>'kOptionsFormatter','options'=>Array(0=>'la_Disabled',1=>'la_Enabled'),'not_null'=>1,'default'=>1,'use_phrases'=>1),
+ 'Priority' => Array('type'=>'int','not_null'=>1,'default'=>0),
+ ),
+ 'VirtualFields' => Array( 'ItemName' => Array(),
+ 'ItemType' => Array(),
+ ),
+
+ 'Grids' => Array(
+ 'Default' => Array(
+ 'Icons' => Array('default'=>'icon16_custom.gif','1_0'=>'icon16_relation_one-way.gif','0_0'=>'icon16_relation_one-way_disabled.gif','1_1'=>'icon16_relation_reciprocal.gif','0_1'=>'icon16_relation_reciprocal_disabled.gif'), // icons for each StatusField values, if no matches or no statusfield selected, then "default" icon is used
+ 'Fields' => Array(
+ 'ItemName' => Array( 'title'=>'la_col_TargetId', 'data_block' => 'grid_checkbox_td'),
+ 'ItemType' => Array( 'title'=>'la_col_TargetType' ),
+ 'Type' => Array( 'title'=>'la_col_RelationshipType' ),
+ 'Enabled' => Array( 'title'=>'la_col_Status' ),
+ ),
+
+ ),
+ ),
+ );
+
+?>
\ No newline at end of file
Property changes on: trunk/core/units/relationship/relationship_config.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/core/units/images/images_config.php
===================================================================
--- trunk/core/units/images/images_config.php (nonexistent)
+++ trunk/core/units/images/images_config.php (revision 4303)
@@ -0,0 +1,155 @@
+<?php
+
+$config = Array(
+ 'Prefix' => 'img',
+ 'Clones' => Array(
+ 'catimg' => Array(
+ 'ParentPrefix' => 'c',
+ 'AggregateTags' => Array(
+ Array(
+ 'AggregateTo' => 'c',
+ 'AggregatedTagName' => 'Image',
+ 'LocalTagName' => 'ItemImage',
+ ),
+ Array(
+ 'AggregateTo' => 'c',
+ 'AggregatedTagName' => 'ListImages',
+ 'LocalTagName' => 'PrintList2',
+ 'LocalSpecial' => 'list',
+ ),
+ Array(
+ 'AggregateTo' => 'c',
+ 'AggregatedTagName' => 'LargeImageExists',
+ 'LocalTagName' => 'LargeImageExists',
+ ),
+ ),
+ )
+ ),
+ 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'),
+ 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'),
+ 'EventHandlerClass' => Array('class'=>'ImageEventHandler','file'=>'image_event_handler.php','build_event'=>'OnBuild'),
+ 'TagProcessorClass' => Array('class'=>'ImageTagProcessor','file'=>'image_tag_processor.php','build_event'=>'OnBuild'),
+ 'AutoLoad' => true,
+ 'hooks' => Array(),
+ 'AggregateTags' => Array(
+ Array(
+ 'AggregateTo' => 'p',
+ 'AggregatedTagName' => 'Image',
+ 'LocalTagName' => 'ItemImage',
+ ),
+ Array(
+ 'AggregateTo' => 'p',
+ 'AggregatedTagName' => 'ListImages',
+ 'LocalTagName' => 'PrintList2',
+ 'LocalSpecial' => 'list',
+ ),
+ Array(
+ 'AggregateTo' => 'p',
+ 'AggregatedTagName' => 'LargeImageExists',
+ 'LocalTagName' => 'LargeImageExists',
+ ),
+
+ ),
+ 'QueryString' => Array(
+ 1 => 'id',
+ 2 => 'page',
+ 3 => 'event',
+ ),
+ 'IDField' => 'ImageId',
+ 'StatusField' => Array('Enabled', 'DefaultImg'), // field, that is affected by Approve/Decline events
+ 'TitleField' => 'Name', // field, used in bluebar when editing existing item
+ 'TableName' => TABLE_PREFIX.'Images',
+ 'ParentTableKey'=> 'ResourceId', // linked field in master table
+ 'ForeignKey' => 'ResourceId', // linked field in subtable
+ 'ParentPrefix' => 'p',
+ 'AutoDelete' => true,
+ 'AutoClone' => true,
+
+ 'FilterMenu' => Array(
+ 'Groups' => Array(
+ Array('mode' => 'AND', 'filters' => Array('show_active','show_disabled'), 'type' => WHERE_FILTER),
+ ),
+ 'Filters' => Array(
+ 'show_active' => Array('label' =>'la_Active', 'on_sql' => '', 'off_sql' => 'Enabled != 1' ),
+ 'show_disabled' => Array('label' => 'la_Disabled', 'on_sql' => '', 'off_sql' => 'Enabled != 0' ),
+ )
+ ),
+
+ 'CalculatedFields' => Array(
+ '' => Array(
+ 'Preview' => '0',
+ ),
+ ),
+
+ 'ListSQLs' => Array( ''=>'SELECT * FROM %s',
+ ), // key - special, value - list select sql
+ 'ItemSQLs' => Array( ''=>'SELECT * FROM %s',
+ ),
+ 'ListSortings' => Array(
+ '' => Array(
+ 'ForcedSorting' => Array('Priority' => 'desc'),
+ 'Sorting' => Array('Name' => 'asc'),
+ )
+ ),
+ 'Fields' => Array(
+ 'ImageId' => Array('type'=>'int'),
+ 'ResourceId' => Array('type'=>'int', 'not_null'=>1, 'default' => 0),
+ 'Url' => Array('max_len'=>255, 'default' => '', 'not_null'=>1),
+ 'Name' => Array('max_len'=>255, 'required'=>1, 'not_null'=>1, 'default' => ''),
+ 'AltName' => Array('max_len'=>255, 'required'=>1, 'not_null'=>1),
+ 'ImageIndex' => Array('type'=>'int', 'default' => 0, 'not_null'=>1),
+ 'LocalImage' => Array('type'=>'int', 'default' => 1, 'not_null'=>1),
+ 'LocalPath' => Array('formatter'=>'kPictureFormatter', 'skip_empty'=>1, 'max_len'=>240, 'default' => '', 'not_null' => 1, 'include_path' => 1,
+ 'allowed_types' => Array(
+ 0 => 'image/jpeg',
+ 1 => 'image/pjpeg',
+ 2 => 'image/png',
+ 3 => 'image/gif',
+ 4 => 'image/bmp'
+ ),
+ 'error_msgs' => Array( 'bad_file_format' => '!la_error_InvalidFileFormat!',
+ 'bad_file_size' => '!la_error_FileTooLarge!',
+ 'cant_save_file' => '!la_error_cant_save_file!'
+ )
+ ),
+ 'Enabled' => Array('formatter'=>'kOptionsFormatter', 'use_phrases' => 1, 'options' => Array ( 1 => 'la_Enabled', 0 => 'la_Disabled' ), 'default' => 0, 'not_null'=>1),
+ 'DefaultImg' => Array('type'=>'int', 'default' => 0, 'not_null'=>1),
+ 'ThumbUrl' => Array('max_len' => 255),
+ 'Priority' => Array('type'=>'int', 'default' => 0, 'not_null'=>1),
+ 'ThumbPath' => Array( 'formatter'=>'kPictureFormatter', 'skip_empty'=>1, 'max_len' => 255,
+ 'allowed_types' => Array(
+ 0 => 'image/jpeg',
+ 1 => 'image/pjpeg',
+ 2 => 'image/png',
+ 3 => 'image/gif',
+ 4 => 'image/bmp'
+ ),
+ 'error_msgs' => Array( 'bad_file_format' => '!la_error_InvalidFileFormat!',
+ 'bad_file_size' => '!la_error_FileTooLarge!',
+ 'cant_save_file' => '!la_error_cant_save_file!'
+ )
+ ),
+ 'LocalThumb' => Array('type'=>'int', 'default' => 1, 'not_null'=>1),
+ 'SameImages' => Array('type'=>'int', 'default' => 1, 'not_null'=>1),
+ ),
+ 'VirtualFields' => Array(
+ 'Preview' => Array(),
+ 'ImageUrl' => Array(),
+ ),
+
+ 'Grids' => Array(
+ 'Default' => Array(
+ 'Icons' => Array('default'=>'icon17_custom.gif','1_0'=>'icon16_image.gif','0_0'=>'icon16_image_disabled.gif','1_1'=>'icon16_image_primary.gif'),
+ 'Fields' => Array(
+ 'Name' => Array( 'title'=>'la_col_ImageName' , 'data_block' => 'image_caption_td'),
+ 'AltName' => Array( 'title'=>'la_col_AltName' ),
+ 'Url' => Array( 'title'=>'la_col_ImageUrl', 'data_block' => 'image_url_td' ),
+ 'Enabled' => Array( 'title'=>'la_col_ImageEnabled' ),
+ 'Preview' => Array( 'title'=>'la_col_Preview', 'data_block' => 'image_preview_td' ),
+ ),
+
+ ),
+ ),
+ );
+
+?>
\ No newline at end of file
Property changes on: trunk/core/units/images/images_config.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/core/units/images/image_tag_processor.php
===================================================================
--- trunk/core/units/images/image_tag_processor.php (nonexistent)
+++ trunk/core/units/images/image_tag_processor.php (revision 4303)
@@ -0,0 +1,206 @@
+<?php
+
+class ImageTagProcessor extends kDBTagProcessor {
+
+ function Image($params)
+ {
+ $params['img_path'] = $this->ImageSrc($params);
+ $params['img_size'] = $this->ImageSize($params);
+ if (!$params['img_size']){
+ $params['img_size'] = ' width="'.getArrayValue($params, 'DefaultWidth').'"';
+ }
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), null);
+ $params['alt'] = htmlspecialchars($object->GetField('AltName'));
+ $params['name'] = $this->SelectParam($params, 'block,render_as');
+
+ return $this->Application->ParseBlock($params);
+ }
+
+ function ItemImage($params)
+ {
+ $this->LoadItemImage($params);
+ $params['img_path'] = $this->ImageSrc($params);
+ $params['img_size'] = $this->ImageSize($params);
+ if (!$params['img_size']){
+ if (isset($params['DefaultWidth'])) {
+ $params['img_size'] = ' width="'.getArrayValue($params, 'DefaultWidth').'"';
+ }
+ }
+ $params['name'] = $this->SelectParam($params, 'render_as,block');
+ $object =& $this->Application->recallObject($this->getPrefixSpecial());
+ if ( !$object->isLoaded() && !$this->SelectParam($params, 'default_image,DefaultImage') ) return false;
+
+ $params['alt'] = htmlspecialchars($object->GetField('AltName'));
+ return $this->Application->ParseBlock($params);
+ }
+
+ function LargeImageExists($params) {
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
+ if ( $object->GetDBField('SameImages') == null || $object->GetDBField('SameImages')=='1' )
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+ function LoadItemImage($params)
+ {
+ $parent_item =& $this->Application->recallObject($params['PrefixSpecial']);
+
+ $this->Application->setUnitOption($this->Prefix,'AutoLoad',false);
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), null);
+
+ // if we need primary thumbnail which is preloaded with products list
+ $object->Clear();
+
+ // if we need primary thumbnail which is preloaded with products list
+ if (
+ $this->SelectParam($params, 'thumbnail,Thumbnail') &&
+ (
+ (
+ $this->SelectParam($params, 'primary,Primary')
+ ||
+ !isset($params['name'])
+ )
+ &&
+ !$this->Application->GetVar('img_id')
+ &&
+ isset($parent_item->Fields['LocalThumb'])
+ )
+ )
+ {
+ $object->SetDefaultValues();
+ $object->SetDBFieldsFromHash($parent_item->GetFieldValues(), Array('SameImages', 'LocalThumb', 'ThumbPath', 'ThumbUrl', 'LocalImage', 'LocalPath', 'Url') );
+ $object->Loaded = true;
+ }
+ else { // if requested image is not primary thumbnail - load it directly
+ $id_field = $this->Application->getUnitOption($this->Prefix, 'ForeignKey');
+ $parent_table_key = $this->Application->getUnitOption($this->Prefix, 'ParentTableKey');
+
+ $keys[$id_field] = $parent_item->GetDBField($parent_table_key);
+
+ // which image to load?
+ if ( getArrayValue($params, 'Primary') ) { //load primary image
+ $keys['DefaultImg'] = 1;
+ }
+ elseif ( getArrayValue($params, 'name') ) { //load by name
+ $keys['Name'] = $params['name'];
+ }
+ elseif ( $image_id = $this->Application->GetVar($this->Prefix.'_id') ) {
+ $keys['ImageId'] = $image_id;
+ }
+ else {
+ $keys['DefaultImg'] = 1; //if primary was not set explicity and name was also not passed - load primary
+ }
+
+ $object->Load($keys);
+ }
+ }
+
+ function ImageSrc($params)
+ {
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), null);
+ $ret = '';
+ // if we need thumb, or full image is same as thumb
+ if ( $this->SelectParam($params, 'thumbnail,Thumbnail') || $object->GetDBField('SameImages') )
+ {
+ // return local image or url
+ $ret = $object->GetDBField('LocalThumb') ? PROTOCOL.SERVER_NAME.BASE_PATH.'/'.$object->GetDBField('ThumbPath') : $object->GetDBField('ThumbUrl');
+ if ( $object->GetDBField('LocalThumb') && !file_exists(FULL_PATH.'/'.$object->GetDBField('ThumbPath')) ) $ret = '';
+ }
+ else { // if we need full which is not the same as thumb
+ $ret = $object->GetDBField('LocalImage') ? PROTOCOL.SERVER_NAME.BASE_PATH.'/'.$object->GetDBField('LocalPath') : $object->GetDBField('Url');
+ if ( $object->GetDBField('LocalImage') && !file_exists(FULL_PATH.'/'.$object->GetDBField('LocalPath')) ) $ret = '';
+ }
+
+ return ($ret && $ret != PROTOCOL.SERVER_NAME.BASE_PATH && $ret != PROTOCOL.SERVER_NAME.BASE_PATH.'/') ? $ret : PROTOCOL.SERVER_NAME.BASE_PATH.THEMES_PATH.'/'.$this->SelectParam($params, 'default_image,DefaultImage');
+ }
+
+ function GetFullPath($path)
+ {
+ if(!$path) return $path;
+
+ // absolute url
+ if( preg_match('/^(.*):\/\/(.*)$/U', $path) )
+ {
+ if(strpos($path, PROTOCOL.SERVER_NAME.BASE_PATH) === 0)
+ {
+ $path = str_replace(PROTOCOL.SERVER_NAME.BASE_PATH, FULL_PATH.'/', $path);
+ }
+ return $path;
+ }
+
+ // relative url
+ return FULL_PATH.'/'.substr(THEMES_PATH,1).'/'.$path;
+ }
+
+ /**
+ * Makes size clause for img tag, such as
+ * ' width="80" height="100"' according to max_width
+ * and max_heght limits.
+ *
+ * @param array $params
+ * @return string
+ */
+ function ImageSize($params)
+ {
+ $img_path = $this->GetFullPath( getArrayValue($params, 'img_path') );
+
+ $image_info = @getimagesize($img_path);
+
+// if( !($img_path && file_exists($img_path) && isset($image_info) ) )
+ if( !$image_info )
+ {
+ trigger_error('Image <b>'.$img_path.'</b> <span class="debug_error">missing or invalid</span>', E_USER_WARNING);
+ return false;
+ }
+
+ $orig_width = getArrayValue($image_info, 0);
+ $orig_height = getArrayValue($image_info, 1);
+ $max_width = getArrayValue($params, 'MaxWidth');
+ $max_height = getArrayValue($params, 'MaxHeight');
+
+ $too_large = is_numeric($max_width) ? ($orig_width > $max_width) : false;
+ $too_large = $too_large || (is_numeric($max_height) ? ($orig_height > $max_height) : false);
+
+ if($too_large)
+ {
+ $width_ratio = $max_width ? $max_width / $orig_width : 1;
+ $height_ratio = $max_height ? $max_height / $orig_height : 1;
+ $ratio = min($width_ratio, $height_ratio);
+
+ $width = ceil($orig_width * $ratio);
+ $height = ceil($orig_height * $ratio);
+ }
+ else
+ {
+ $width = $orig_width;
+ $height = $orig_height;
+ }
+
+ $size_clause = ' width="'.$width.'" height="'.$height.'"';
+ return $size_clause;
+ }
+
+
+ // used in admin
+ function ImageUrl($params)
+ {
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
+ if ($object->GetDBField('SameImages') ? $object->GetDBField('LocalThumb') : $object->GetDBField('LocalImage') )
+ {
+ $ret = $this->Application->Phrase(getArrayValue($params,'local_phrase'));
+ }
+ else
+ {
+ $ret = $object->GetDBField('SameImages') ? $object->GetDBField('ThumbUrl') : $object->GetDBField('Url');
+ }
+ return $ret;
+ }
+
+}
+
+?>
\ No newline at end of file
Property changes on: trunk/core/units/images/image_tag_processor.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/core/units/images/image_event_handler.php
===================================================================
--- trunk/core/units/images/image_event_handler.php (nonexistent)
+++ trunk/core/units/images/image_event_handler.php (revision 4303)
@@ -0,0 +1,336 @@
+<?php
+class ImageEventHandler extends InpDBEventHandler {
+
+ function mapEvents()
+ {
+ parent::mapEvents(); // ensure auto-adding of approve/decine and so on events
+ $image_events = Array(
+ 'OnAfterCopyToTemp'=>'ImageAction',
+ 'OnBeforeDeleteFromLive'=>'ImageAction',
+ 'OnBeforeCopyToLive'=>'ImageAction',
+ 'OnBeforeItemDelete'=>'ImageAction',
+ 'OnAfterClone'=>'ImageAction',
+ );
+
+ $this->eventMethods = array_merge($this->eventMethods, $image_events);
+ }
+
+ function customProcessing(&$event, $type)
+ {
+ $object =& $event->GetObject();
+ switch ($type)
+ {
+ case 'before' :
+ if ($object->GetDBField('LocalImage'))
+ {
+ $object->SetDBField('Url', '');
+ }
+ else
+ {
+ $object->SetDBField('LocalPath', '');
+ }
+
+ if ($object->GetDBField('LocalThumb'))
+ {
+ $object->SetDBField('ThumbUrl', '');
+ }
+ else
+ {
+ $object->SetDBField('ThumbPath', '');
+ }
+
+ if ($object->GetDBField('SameImages'))
+ {
+ $object->SetDBField('LocalImage', 1);
+ $object->SetDBField('LocalPath', '');
+ $object->SetDBField('Url', '');
+ }
+ break;
+ case 'after' :
+ if ($object->GetDBField('DefaultImg') )
+ {
+ $sql = 'UPDATE '.$object->TableName.' SET DefaultImg=0 WHERE ResourceId='.
+ $object->GetDBField('ResourceId').' AND ImageId<>'.
+ $object->GetId();
+ $res = $this->Conn->Query($sql);
+ }
+ break;
+ default:
+ }
+ }
+
+ function ImageAction(&$event)
+ {
+ $id = $event->getEventParam('id');
+ $object =& $this->Application->recallObject($event->Prefix.'.-item', $event->Prefix);
+ if (in_array($event->Name, Array('OnBeforeDeleteFromLive','OnAfterClone')) ) {
+ $object->SwitchToLive();
+ }
+ elseif ($event->Name == 'OnBeforeItemDelete') {
+ // keep current table
+ }
+ else {
+ $object->SwitchToTemp();
+ }
+
+ $object->Load($id);
+
+ $fields = Array('LocalPath' => 'LocalImage', 'ThumbPath' => 'LocalThumb');
+ foreach ($fields as $a_field => $mode_field) {
+ $file = $object->GetField($a_field);
+ if (!$file) continue;
+ $source_file = FULL_PATH.$file;
+
+ switch ($event->Name) {
+ // Copy image files to pending dir and update corresponding fields in temp record
+ // Checking for existing files and renaming if nessessary - two users may upload same pending files at the same time!
+ case 'OnAfterCopyToTemp':
+ $new_file = IMAGES_PENDING_PATH . $this->ValidateFileName(FULL_PATH.IMAGES_PENDING_PATH, basename($file));
+ $dest_file = FULL_PATH.$new_file;
+ copy($source_file, $dest_file);
+ $object->Fields[$a_field]['skip_empty'] = false;
+ $object->SetDBField($a_field, $new_file);
+ break;
+
+ // Copy image files to live dir (checking if fileexists and renameing if nessessary)
+ // and update corresponding fields in temp record (which gets copied to live automatically)
+ case 'OnBeforeCopyToLive':
+ if ( $object->GetDBField($mode_field) ) { // if image is local
+ // rename file if it exists in live folder
+ $new_file = IMAGES_PATH . $this->ValidateFileName(FULL_PATH.IMAGES_PATH, basename($file));
+ $dest_file = FULL_PATH.$new_file;
+ rename($source_file, $dest_file);
+ }
+ else { // if image is remote url - remove local file (if any), update local file field with empty value
+ if (file_exists($source_file)) @unlink($source_file);
+ $new_file = '';
+ }
+ $object->Fields[$a_field]['skip_empty'] = false;
+ $object->SetDBField($a_field, $new_file);
+ break;
+
+ case 'OnBeforeDeleteFromLive': // Delete image files from live folder before copying over from temp
+ case 'OnBeforeItemDelete': // Delete image files when deleteing Image object
+ @unlink(FULL_PATH.$file);
+ break;
+
+ case 'OnAfterClone': // Copy files when cloning objects, renaming it on the fly
+ $path_info = pathinfo($file);
+ $new_file = $path_info['dirname'].'/'.$this->ValidateFileName(FULL_PATH.$path_info['dirname'], $path_info['basename']);
+ $dest_file = FULL_PATH . $new_file;
+ copy($source_file, $dest_file);
+ $object->Fields[$a_field]['skip_empty'] = false;
+ $object->SetDBField($a_field, $new_file);
+ break;
+ }
+ }
+ if ( in_array($event->Name, Array('OnAfterClone', 'OnBeforeCopyToLive', 'OnAfterCopyToTemp')) ) {
+ $object->Update(null, true);
+ }
+ }
+
+ function ValidateFileName($path, $name)
+ {
+ $parts = pathinfo($name);
+ $ext = '.'.$parts['extension'];
+ $filename = substr($parts['basename'], 0, -strlen($ext));
+ $new_name = $filename.$ext;
+ while ( file_exists($path.'/'.$new_name) )
+ {
+ if ( preg_match("/({$filename}_)([0-9]*)($ext)/", $new_name, $regs) ) {
+ $new_name = $regs[1].($regs[2]+1).$regs[3];
+ }
+ else {
+ $new_name = $filename.'_1'.$ext;
+ }
+ }
+ return $new_name;
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function OnSetPrimary(&$event)
+ {
+ $object =& $event->getObject();
+ $object->SetDBField('DefaultImg', 1);
+ $object->Update();
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function OnBeforeItemUpdate(&$event)
+ {
+ $object =& $event->getObject();
+// $parent_info = $object->getLinkedInfo();
+ $id = $object->GetDBField('ResourceId');
+// $id = $parent_info['ParentId'] ? $parent_info['ParentId'] : $this->Application->GetVar('p_id');
+ $sql = 'SELECT ImageId FROM '.$object->TableName.' WHERE ResourceId='.$id.' AND DefaultImg=1';
+ if(!$this->Conn->GetOne($sql))
+ {
+ $object->SetDBField('DefaultImg', 1);
+ }
+ if($object->GetDBField('DefaultImg') && $object->Validate())
+ {
+
+ $sql = 'UPDATE '.$object->TableName.'
+ SET DefaultImg = 0
+ WHERE ResourceId = '.$id.' AND ImageId <> '.$object->GetDBField('ImageId');
+ $this->Conn->Query($sql);
+ $object->SetDBField('Enabled', 1);
+ }
+ }
+
+ function OnAfterItemCreate(&$event)
+ {
+ $event->CallSubEvent('OnBeforeItemUpdate');
+ $object =& $event->getObject();
+ $object->Update();
+ }
+
+ /**
+ * Deletes all selected items.
+ * Automatically recurse into sub-items using temp handler, and deletes sub-items
+ * by calling its Delete method if sub-item has AutoDelete set to true in its config file
+ *
+ * @param kEvent $event
+ */
+ function OnMassDelete(&$event)
+ {
+ $event->status=erSUCCESS;
+
+ $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
+
+ $this->StoreSelectedIDs($event);
+
+ $event->setEventParam('ids', $this->getSelectedIDs($event) );
+ $this->customProcessing($event, 'before');
+ $ids = $event->getEventParam('ids');
+
+ $object =& $event->getObject();
+ $sql = 'SELECT ImageId FROM '.$object->TableName.' WHERE DefaultImg=1';
+ $primary = $this->Conn->GetOne($sql);
+ if( $primary && ($key = array_search($primary, $ids)) )
+ {
+ $sql = 'SELECT ImageId FROM '.$object->TableName.' WHERE DefaultImg=0';
+ $res = $this->Conn->Query($sql);
+ if($res)
+ {
+ unset($ids[$key]);
+ }
+ }
+
+ if($ids)
+ {
+ $temp->DeleteItems($event->Prefix, $event->Special, $ids);
+ }
+ $this->clearSelectedIDs($event);
+ }
+
+ /*function OnAfterItemLoad(&$event)
+ {
+ $object =& $event->getObject();
+
+ if ( $object->GetDBField('ThumbPath') || $object->GetDBField('SameImages') )
+ {
+ // return local image or url
+ $path = $object->GetDBField('LocalThumb') ? PROTOCOL.SERVER_NAME.BASE_PATH.$object->GetDBField('ThumbPath') : $object->GetDBField('ThumbUrl');
+ if ( $object->GetDBField('LocalThumb') && !file_exists(FULL_PATH.$object->GetDBField('ThumbPath')) ) $path = '';
+ }
+ else { // if we need full which is not the same as thumb
+ $path = $object->GetDBField('LocalImage') ? PROTOCOL.SERVER_NAME.BASE_PATH.$object->GetDBField('LocalPath') : $object->GetDBField('Url');
+ if ( $object->GetDBField('LocalImage') && !file_exists(FULL_PATH.$object->GetDBField('LocalPath')) ) $path = '';
+ }
+
+ $object->SetDBField('ImageUrl', $path);
+ }*/
+
+ function SetCustomQuery(&$event)
+ {
+ parent::SetCustomQuery($event);
+
+ $types=$event->getEventParam('types');
+ $except_types=$event->getEventParam('except');
+ $object =& $event->getObject();
+ $type_clauses = Array();
+
+ if( !$this->Application->IsAdmin() )
+ {
+ $object->addFilter('active', '%1$s.Enabled = 1');
+ }
+
+ if($product_id = $event->getEventParam('product_id'))
+ {
+ $object->removeFilter('parent_filter');
+ $sql = 'SELECT ResourceId FROM '.$this->Application->getUnitOption('p', 'TableName').'
+ WHERE ProductId = '.$product_id;
+ $resource_id = (int) $this->Conn->GetOne($sql);
+ $object->addFilter('product_images', '%1$s.ResourceId = '.$resource_id);
+ }
+
+ $type_clauses['additional']['include'] = '%1$s.DefaultImg != 1';
+ $type_clauses['additional']['except'] = '%1$s.DefaultImg = 1';
+ $type_clauses['additional']['having_filter'] = false;
+
+ /********************************************/
+
+ $includes_or_filter =& $this->Application->makeClass('kMultipleFilter');
+ $includes_or_filter->setType(FLT_TYPE_OR);
+
+ $excepts_and_filter =& $this->Application->makeClass('kMultipleFilter');
+ $excepts_and_filter->setType(FLT_TYPE_AND);
+
+ $includes_or_filter_h =& $this->Application->makeClass('kMultipleFilter');
+ $includes_or_filter_h->setType(FLT_TYPE_OR);
+
+ $excepts_and_filter_h =& $this->Application->makeClass('kMultipleFilter');
+ $excepts_and_filter_h->setType(FLT_TYPE_AND);
+
+ $except_types_array=explode(',', $types);
+
+ if ($types){
+ $types_array=explode(',', $types);
+ for ($i=0; $i<sizeof($types_array); $i++){
+ $type=trim($types_array[$i]);
+ if (isset($type_clauses[$type])){
+ if ($type_clauses[$type]['having_filter']){
+ $includes_or_filter_h->removeFilter('filter_'.$type);
+ $includes_or_filter_h->addFilter('filter_'.$type, $type_clauses[$type]['include']);
+ }else{
+ $includes_or_filter->removeFilter('filter_'.$type);
+ $includes_or_filter->addFilter('filter_'.$type, $type_clauses[$type]['include']);
+ }
+ }
+ }
+ }
+
+ if ($except_types){
+ $except_types_array=explode(',', $except_types);
+ for ($i=0; $i<sizeof($except_types_array); $i++){
+ $type=trim($except_types_array[$i]);
+ if (isset($type_clauses[$type])){
+ if ($type_clauses[$type]['having_filter']){
+ $excepts_and_filter_h->removeFilter('filter_'.$type);
+ $excepts_and_filter_h->addFilter('filter_'.$type, $type_clauses[$type]['except']);
+ }else{
+ $excepts_and_filter->removeFilter('filter_'.$type);
+ $excepts_and_filter->addFilter('filter_'.$type, $type_clauses[$type]['except']);
+ }
+ }
+ }
+ }
+
+ $object->addFilter('includes_filter', $includes_or_filter);
+ $object->addFilter('excepts_filter', $excepts_and_filter);
+
+ $object->addFilter('includes_filter_h', $includes_or_filter_h, HAVING_FILTER);
+ $object->addFilter('excepts_filter_h', $excepts_and_filter_h, HAVING_FILTER);
+ }
+}
+
+?>
\ No newline at end of file
Property changes on: trunk/core/units/images/image_event_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/core/units/images/images.php
===================================================================
--- trunk/core/units/images/images.php (nonexistent)
+++ trunk/core/units/images/images.php (revision 4303)
@@ -0,0 +1,23 @@
+<?php
+
+class ImagesItem extends kDBItem {
+
+ function Delete($id)
+ {
+ $this->Load($id);
+ $local_path = FULL_PATH.$this->GetDBField('LocalPath');
+ $thumb_path = FULL_PATH.$this->GetDBField('ThumbPath');
+ if(file_exists($local_path))
+ {
+ unlink($local_path);
+ }
+ if(file_exists($thumb_path))
+ {
+ unlink($thumb_path);
+ }
+ return parent::Delete($id);
+ }
+
+}
+
+?>
\ No newline at end of file
Property changes on: trunk/core/units/images/images.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

Event Timeline