Page MenuHomeIn-Portal Phabricator

in-link
No OneTemporary

File Metadata

Created
Sun, Feb 23, 10:13 PM
Index: branches/5.3.x/units/links/links_event_handler.php
===================================================================
--- branches/5.3.x/units/links/links_event_handler.php (revision 16522)
+++ branches/5.3.x/units/links/links_event_handler.php (revision 16523)
@@ -1,621 +1,621 @@
<?php
/**
* @version $Id$
* @package In-Link
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class LinksEventHandler extends kCatDBEventHandler {
/**
* Allows to override standard permission mapping
*
* @return void
* @access protected
* @see kEventHandler::$permMapping
*/
protected function mapPermissions()
{
parent::mapPermissions();
$permissions = Array (
'OnContactFormSubmit' => Array ('self' => true),
'OnProcessReciprocalLinks' => Array ('self' => true),
'OnSetGrouping' => Array ('self' => 'view'),
'OnStoreSelected' => Array ('self' => 'view'),
'OnMerge' => Array ('self' => 'edit'),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
}
/**
* Apply any custom changes to list's sql query
*
* @param kEvent $event
* @return void
* @access protected
* @see kDBEventHandler::OnListBuild()
*/
protected function SetCustomQuery(kEvent $event)
{
parent::SetCustomQuery($event);
+ /** @var kDBList $object */
$object = $event->getObject();
- /* @var $object kDBList */
if ( !$this->Application->isAdminUser ) {
$object->addFilter('expire_filter', '(Expire > ' . time() . ' OR Expire IS NULL)');
}
if ( substr($event->Special, 0, 10) == 'duplicates' ) {
$object->removeFilter('category_filter');
+ /** @var LinkHelper $link_helper */
$link_helper = $this->Application->recallObject('LinkHelper');
- /* @var $link_helper LinkHelper */
$grouping = $link_helper->getGrouping($event->getPrefixSpecial());
switch ($event->Special) {
case 'duplicates':
foreach ($grouping as $group_field) {
$object->AddGroupByField($object->TableName . '.' . $group_field);
}
$object->addFilter('has_dupes_filter', 'DupeCount > 1', kDBList::AGGREGATE_FILTER);
break;
case 'duplicates-sub':
+ /** @var kDBItem $main_object */
$main_object = $this->Application->recallObject($event->Prefix . '.duplicates');
- /* @var $main_object kDBItem */
foreach ($grouping as $field_index => $group_field) {
$object->addFilter('dupe_filter_' . $field_index, '%1$s.`' . $group_field . '` = ' . $this->Conn->qstr($main_object->GetDBField($group_field)));
}
break;
}
$object->addFilter('primary_filter', TABLE_PREFIX . 'CategoryItems.PrimaryCat = 1');
}
}
/**
* Set groping fields for link duplicate checker
*
* @param kEvent $event
*/
function OnSetGrouping($event)
{
$this->Application->LinkVar($event->getPrefixSpecial(true).'_dupe_fields', $event->getPrefixSpecial().'_dupe_fields');
}
/**
* Merge duplicate links together (only categories) & delete duplicates
*
* @param kEvent $event
*/
function OnMerge($event)
{
+ /** @var LinkHelper $link_helper */
$link_helper = $this->Application->recallObject('LinkHelper');
- /* @var $link_helper LinkHelper */
$grouping = $link_helper->getGrouping($event->getPrefixSpecial());
$ids = $this->StoreSelectedIDs($event);
if ( !$ids ) {
return;
}
// check, that user has not selected multiple links from same group
$primary_links = Array ();
$config = $event->getUnitConfig();
$id_field = $config->getIDField();
$table_name = $config->getTableName();
$sql = 'SELECT *
FROM ' . $table_name . '
WHERE ' . $id_field . ' IN (' . implode(',', $ids) . ')';
$links = $this->Conn->Query($sql, $id_field);
$groping_error = false;
foreach ($links as $link_data) {
$group_key = '';
foreach ($grouping as $grouping_field) {
$group_key .= 'main_table.`' . $grouping_field . '` = ' . $this->Conn->qstr($link_data[$grouping_field]) . ' AND ';
}
$group_key = substr($group_key, 0, -5);
if ( isset($primary_links[$group_key]) ) {
$groping_error = true;
break;
}
else {
$primary_links[$group_key] = $link_data['ResourceId'];
}
}
if ( !$groping_error ) {
+ /** @var kTempTablesHandler $temp_handler */
$temp_handler = $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler', Array ('parent_event' => $event));
- /* @var $temp_handler kTempTablesHandler */
$categories_sql = ' SELECT main_table.ResourceId, ci.CategoryId, main_table.' . $id_field . '
FROM ' . $table_name . ' main_table
LEFT JOIN ' . TABLE_PREFIX . 'CategoryItems ci ON main_table.ResourceId = ci.ItemResourceId
WHERE %s';
foreach ($primary_links as $group_key => $primary_resource_id) {
$categories = Array ();
$group_links = Array ();
$group_categories = $this->Conn->Query(sprintf($categories_sql, $group_key));
foreach ($group_categories as $category_data) {
$group_links[$category_data['ResourceId']] = $category_data[$id_field];
$categories[$category_data['ResourceId'] == $primary_resource_id ? 'remove' : 'add'][] = $category_data['CategoryId'];
}
unset($group_links[$primary_resource_id]);
$categories = array_unique(array_diff($categories['add'], $categories['remove']));
if ( $categories ) {
// add link to other link categories
$values_sql = '';
foreach ($categories as $category_id) {
$values_sql .= '(' . $category_id . ',' . $primary_resource_id . ',0),';
}
$values_sql = substr($values_sql, 0, -1);
$insert_sql = 'INSERT INTO ' . TABLE_PREFIX . 'CategoryItems (CategoryId,ItemResourceId,PrimaryCat) VALUES ' . $values_sql;
$this->Conn->Query($insert_sql);
}
// delete all links from group except primary
$temp_handler->DeleteItems($event->Prefix, $event->Special, array_values($group_links));
}
}
else {
$event->status = kEvent::erFAIL;
$event->redirect = false;
$this->Application->SetVar($event->getPrefixSpecial().'_error', 1);
}
}
/**
* Stores ids, that were selected in duplicate checker
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnStoreSelected(kEvent $event)
{
$this->StoreSelectedIDs($event);
$event->SetRedirectParam('pass', 'm,' . $event->getPrefixSpecial());
}
/**
* Allows to enhance link after creation
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnCreate(kEvent $event)
{
parent::OnCreate($event);
if ( $event->status != kEvent::erSUCCESS ) {
return;
}
+ /** @var kDBItem $object */
$object = $event->getObject();
- /* @var $object kDBItem */
// replace 0 id in post with actual created id (used in enhancement process)
$items_info = $this->Application->GetVar($event->getPrefixSpecial(true));
kUtil::array_rename_key($items_info, 0, $object->GetID());
$this->Application->SetVar($event->getPrefixSpecial(true), $items_info);
// listing was created -> enhance it right away
$enhancement_event = new kEvent('ls:OnRequestEnhancement');
$this->Application->HandleEvent($enhancement_event);
if ( ($enhancement_event->status == kEvent::erSUCCESS) && strlen($enhancement_event->redirect) ) {
$event->SetRedirectParam('next_template', $event->redirect);
$event->redirect = $enhancement_event->redirect;
}
}
/**
* Adds free listing option to listing type selection
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnAfterConfigRead(kEvent $event)
{
parent::OnAfterConfigRead($event);
if ( defined('IS_INSTALL') && IS_INSTALL ) {
return;
}
$config = $event->getUnitConfig();
$free_listings = $this->Application->ConfigValue('Link_AllowFreeListings');
$virtual_fields = $config->getVirtualFields();
$virtual_fields['ListingTypeId']['options'] = $free_listings ? Array (0 => 'lu_free_listing') : Array ();
$language_id = $this->Application->GetVar('m_lang');
$duplicate_options = array_flip($virtual_fields['DuplicateCheckFields']['options']);
$duplicate_options['NAME'] = 'l' . $language_id . '_Name';
$virtual_fields['DuplicateCheckFields']['options'] = array_flip($duplicate_options);
$default = $virtual_fields['DuplicateCheckFields']['default'];
$virtual_fields['DuplicateCheckFields']['default'] = str_replace('|Name|', '|l' . $language_id . '_Name|', $default);
$config->setVirtualFields($virtual_fields);
if ( !$this->Application->isAdminUser ) {
// for now only on Front-End
$event->getUnitConfig()->setPopulateMlFields(true);
}
}
/**
* contact us form submitted on link details page
*
* @param kEvent $event
*/
function OnContactFormSubmit($event)
{
$fields = Array (
'ContactFormFullName', 'ContactFormEmail', 'ContactFormSubject', 'ContactFormBody', 'ContactFormCaptcha'
);
// reset errors var
$this->Application->SetVar('ContactForm_HasErrors', '');
// 1. validate form fields
$required_fields = $this->Application->GetVar('FormRequiredFields');
foreach ($fields as $field_name) {
$field_value = trim($this->Application->GetVar($field_name));
if (in_array($field_name, $required_fields)) {
// custom captcha validation
if ($field_name == 'ContactFormCaptcha') {
if (!strlen($field_value) || ($field_value != $this->Application->RecallVar($event->Prefix . '_captcha_code'))) {
$this->Application->SetVar('error_'.$field_name, 1);
+ /** @var kCaptchaHelper $captcha_helper */
$captcha_helper = $this->Application->recallObject('CaptchaHelper');
- /* @var $captcha_helper kCaptchaHelper */
$this->Application->StoreVar($event->Prefix . '_captcha_code', $captcha_helper->GenerateCaptchaCode());
$event->status = kEvent::erFAIL;
$event->redirect = false;
}
}
// email validation
elseif (!strlen($field_value) || ($field_name == 'ContactFormEmail' && !preg_match('/'.REGEX_EMAIL_USER.'@'.REGEX_EMAIL_DOMAIN.'/', $field_value))) {
$this->Application->SetVar('error_'.$field_name, 1);
$event->status = kEvent::erFAIL;
$event->redirect = false;
}
}
}
if ($event->status != kEvent::erSUCCESS) {
// set errors var
$this->Application->SetVar('ContactForm_HasErrors', 1);
return ;
}
$object = $event->getObject(); // get link object
- /* @var $object kDBItem */
+ /** @var kDBItem $object */
$send_params = $object->getEmailParams(Array(
'from_name' => $this->Application->GetVar('ContactFormFullName'),
'from_email' => $this->Application->GetVar('ContactFormEmail'),
'from_subject' => $this->Application->GetVar('ContactFormSubject'),
'message' => $this->Application->GetVar('ContactFormBody'),
'to_linkname' => $object->GetField('Name'),
));
$email_sent = $this->Application->emailUser('LINK.CONTACTFORM', $object->GetDBField('CreatedById'), $send_params);
if ( $email_sent ) {
$event->redirect = $this->Application->GetVar('success_template');
$redirect_params = Array (
'opener' => 's',
'pass' => 'all',
'thankyou_header' => $this->Application->GetVar('success_label_header'),
'thankyou_text' => $this->Application->GetVar('success_label_body')
);
$event->setRedirectParams($redirect_params);
$this->Application->emailAdmin('LINK.CONTACTFORM', null, $send_params);
}
else {
$this->Application->SetVar('error_ContactFormEmail', 1);
$event->status = kEvent::erFAIL;
$event->redirect = false;
}
}
/**
* Makes reciprocal check on link, when it is created
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnBeforeItemCreate(kEvent $event)
{
parent::OnBeforeItemCreate($event);
$this->_checkLink($event);
}
/**
* Makes reciprocal check on link, when it is updated
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnBeforeItemUpdate(kEvent $event)
{
parent::OnBeforeItemUpdate($event);
$this->_checkLink($event);
}
/**
* Makes reciprocal check on link & saves results
*
* @param kEvent $event
*/
function _checkLink($event)
{
if (!$this->Application->ConfigValue('ReciprocalLinkChecking')) {
return ;
}
+ /** @var kDBItem $object */
$object = $event->getObject();
- /* @var $object kDBItem */
if ($object->GetDBField('Url') != $object->GetOriginalField('Url')) {
// check only when url was changed
+ /** @var LinkHelper $link_helper */
$link_helper = $this->Application->recallObject('LinkHelper');
- /* @var $link_helper LinkHelper */
$link_checked = $link_helper->CheckReciprocalURL($object->GetDBField('Url'));
$object->SetDBField('ReciprocalLinkFound', $link_checked ? LINK_IS_RECIPROCAL : LINK_IS_NOT_RECIPROCAL);
if (!$link_checked) {
$this->Application->emailAdmin('LINK.RECIPROCAL.CHECK.FAILED', null, $object->getEmailParams());
}
}
}
/**
* Update links status by their reciprocal status
*
* @param kEvent $event
*/
function OnProcessReciprocalLinks($event)
{
if ( !$this->Application->ConfigValue('ReciprocalLinkChecking') ) {
return;
}
+ /** @var kCatDBItem $object */
$object = $event->getObject( Array('skip_autoload' => true) );
- /* @var $object kCatDBItem */
+ /** @var LinkHelper $link_helper */
$link_helper = $this->Application->recallObject('LinkHelper');
- /* @var $link_helper LinkHelper */
$config = $event->getUnitConfig();
$id_field = $config->getIDField();
$table_name = $config->getTableName();
// 1. verify all links, that were not verified previously
$sql = 'SELECT ' . $id_field . '
FROM ' . $table_name . '
WHERE (ReciprocalLinkFound = 0)';
$not_checked_links = $this->Conn->GetCol($sql);
foreach ($not_checked_links as $link_id) {
$object->Load($link_id);
$link_checked = $link_helper->CheckReciprocalURL($object->GetDBField('Url'));
$object->SetDBField('ReciprocalLinkFound', $link_checked ? LINK_IS_RECIPROCAL : LINK_IS_NOT_RECIPROCAL);
$object->Update();
if ( $link_checked ) {
$object->ApproveChanges();
}
else {
$object->DeclineChanges();
$this->Application->emailAdmin('LINK.RECIPROCAL.CHECK.FAILED', null, $object->getEmailParams());
}
}
// 2. approve all links, that have succeeded in reciprocal check (during adding/changing on front-end)
$sql = 'SELECT ' . $id_field . '
FROM ' . $table_name . '
WHERE (ReciprocalLinkFound = ' . LINK_IS_RECIPROCAL . ') AND (Status <> ' . STATUS_ACTIVE . ')';
$verified_links = $this->Conn->GetCol($sql);
foreach ($verified_links as $link_id) {
$object->Load($link_id);
$object->ApproveChanges();
}
// 3. decline all links, that failed in reciprocal check (during adding/changing on front-end)
$sql = 'SELECT ' . $id_field . '
FROM ' . $table_name . '
WHERE (ReciprocalLinkFound = ' . LINK_IS_NOT_RECIPROCAL . ') AND (Status <> ' . STATUS_DISABLED . ')';
$not_verified_links = $this->Conn->GetCol($sql);
foreach ($not_verified_links as $link_id) {
$object->Load($link_id);
$object->DeclineChanges();
}
}
/**
* Allows to load duplicate link by special id
*
* @param kEvent $event
* @return int
* @access public
*/
public function getPassedID(kEvent $event)
{
$id = parent::getPassedID($event);
if ( ($event->Special == 'duplicates') && !is_numeric($id) ) {
$load_keys = unserialize(base64_decode($id));
// can't return $load_keys as $id, because "kCatDBItem::GetKeyClause" will ignore them
foreach ($load_keys as $field => $value) {
$load_keys[$field] = $field . ' = ' . $this->Conn->qstr($value);
}
$config = $event->getUnitConfig();
$sql = 'SELECT ' . $config->getIDField() . '
FROM ' . $config->getTableName() . '
WHERE (' . implode(') AND (', $load_keys) . ')';
$id = $this->Conn->GetOne($sql);
}
return $id;
}
/**
* Returns events, that require item-based (not just event-name based) permission check
*
* @return Array
*/
function _getMassPermissionEvents()
{
$events = parent::_getMassPermissionEvents();
$events[] = 'OnMerge';
return $events;
}
/**
* [HOOK] Allows to add cloned subitem to given prefix
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnCloneSubItem(kEvent $event)
{
parent::OnCloneSubItem($event);
if ( $event->MasterEvent->Prefix == 'rev' ) {
$master_config = $event->MasterEvent->getUnitConfig();
$sub_item_prefix = $event->Prefix . '-' . $event->MasterEvent->Prefix;
$master_config->addClones(Array (
$sub_item_prefix => Array (
'ConfigMapping' => Array (
'PerPage' => 'Perpage_LinkReviews',
'ShortListPerPage' => 'Perpage_LinkReviews_Short',
'DefaultSorting1Field' => 'Link_ReviewsSort',
'DefaultSorting2Field' => 'Link_ReviewsSort2',
'DefaultSorting1Dir' => 'Link_ReviewsOrder',
'DefaultSorting2Dir' => 'Link_ReviewsOrder2',
'ReviewDelayInterval' => 'link_ReviewDelay_Interval',
'ReviewDelayValue' => 'link_ReviewDelay_Value',
)
)
));
}
}
/**
* Occurs before original item of item in pending editing got deleted (for hooking only)
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnBeforeDeleteOriginal(kEvent $event)
{
parent::OnBeforeDeleteOriginal($event);
+ /** @var kDBItem $object */
$object = $event->getObject();
- /* @var $object kDBItem */
$link_id = $event->getEventParam('original_id');
$new_resource_id = $object->GetDBField('ResourceId');
$config = $event->getUnitConfig();
$sql = 'SELECT ResourceId
FROM ' . $config->getTableName() . '
WHERE ' . $config->getIDField() . '=' . $link_id;
$old_resource_id = $this->Conn->GetOne($sql);
$this->Application->SetVar('original_resource_id', $old_resource_id);
$this->changeResourceId('rel', 'TargetId', $old_resource_id, $new_resource_id);
}
/**
* Occurs after original item of item in pending editing got deleted
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnAfterDeleteOriginal(kEvent $event)
{
parent::OnAfterDeleteOriginal($event);
+ /** @var kDBItem $object */
$object = $event->getObject();
- /* @var $object kDBItem */
$old_resource_id = $this->Application->GetVar('original_resource_id');
$new_resource_id = $object->GetDBField('ResourceId');
$this->changeResourceId('ls', 'ItemResourceId', $old_resource_id, $new_resource_id);
}
/**
* Changes item resource id in one field
*
* @param string $prefix
* @param string $field
* @param string $old_resource_id
* @param string $new_resource_id
* @return void
* @access protected
*/
protected function changeResourceId($prefix, $field, $old_resource_id, $new_resource_id)
{
$fields_hash = Array ($field => $new_resource_id);
$table_name = $this->Application->getUnitConfig($prefix)->getTableName();
$this->Conn->doUpdate($fields_hash, $table_name, $field . ' = ' . $old_resource_id);
}
- }
\ No newline at end of file
+ }
Index: branches/5.3.x/units/links/link_tag_processor.php
===================================================================
--- branches/5.3.x/units/links/link_tag_processor.php (revision 16522)
+++ branches/5.3.x/units/links/link_tag_processor.php (revision 16523)
@@ -1,464 +1,464 @@
<?php
/**
* @version $Id$
* @package In-Link
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class LinkTagProcessor extends kCatDBTagProcessor {
/**
* Returns object used in tag processor
*
* @access public
* @return kDBBase
*/
/*function &getObject($params = Array())
{
$object =& parent::getObject($params);
// Forces item loading (compatibility with old theme)
if (is_subclass_of($object, 'kDBItem')) {
// force reload when using from old code
$id = $this->Application->GetVar($this->Prefix.'_id');
if ($object->isLoaded() && $id && ($object->GetID() != $id)) {
$object->Load($id);
}
}
return $object;
}*/
function getListingInfo($resource_id, $field = null)
{
$sql = 'SELECT *
FROM ' . $this->Application->getUnitConfig('ls')->getTableName() . '
WHERE ItemResourceId = ' . $resource_id;
$listing_info = $this->Conn->GetRow($sql);
return isset($field) ? $listing_info[$field] : $listing_info;
}
/**
* Detects listing enhancement status (enhanced or not)
*
* @param Array $params
* @return int
*/
function LinkIsEnhanced($params)
{
+ /** @var kDBItem $object */
$object = $this->getObject($params);
- /* @var $object kDBItem */
if ($object->GetDBField('Status') == STATUS_PENDING || $object->GetDBField('Status') == STATUS_PENDING_EDITING) {
return false;
}
$listing_type_id = $this->getListingInfo($object->GetDBField('ResourceId'), 'ListingTypeId');
$this->Application->SetVar('lst_id', $listing_type_id); // compatibility with old-theme
return $listing_type_id ? 1 : 0;
}
/**
* Detects if enhancement is pending approval
*
* @param Array $params
* @return int
*/
function EnhancementIsPending($params)
{
+ /** @var kDBItem $object */
$object = $this->getObject($params);
- /* @var $object kDBItem */
$status = $this->getListingInfo($object->GetDBField('ResourceId'), 'Status');
return $status == STATUS_PENDING ? 1 : 0;
}
function ListingTypeField($params)
{
+ /** @var kDBItem $object */
$object = $this->getObject($params);
- /* @var $object kDBItem */
$lst_id = $this->getListingInfo($object->GetDBField('ResourceId'), 'ListingTypeId');
$lst_object = $this->Application->recallObject('lst', null, Array('skip_autoload' => true));
$lst_object->Load($lst_id);
return $lst_object->GetField( $this->SelectParam($params, 'name,field') );
}
function EnhancementField($params)
{
+ /** @var kDBItem $object */
$object = $this->getObject($params);
- /* @var $object kDBItem */
$listing_id = $this->getListingInfo($object->GetDBField('ResourceId'), 'ListingId');
$listing_object = $this->Application->recallObject('ls', null, Array('skip_autoload' => true));
$listing_object->Load($listing_id);
return $listing_object->GetField( $this->SelectParam($params, 'name,field') );
}
function IsRenewalPeriod($params)
{
+ /** @var kDBItem $object */
$object = $this->getObject($params);
- /* @var $object kDBItem */
$listing_info = $this->getListingInfo($object->GetDBField('ResourceId'));
$sql = 'SELECT RenewalReminder
FROM ' . $this->Application->getUnitConfig('lst')->getTableName() . '
WHERE ListingTypeId = ' . $listing_info['ListingTypeId'];
$renewal_interval = $this->Conn->GetOne($sql) * 3600 * 24;
return ($listing_info['ExpiresOn'] - time() < $renewal_interval) ? 1 : 0;
}
function FirstListingType($params)
{
static $first = true;
if ($first) {
$first = false;
return true;
}
else {
return false;
}
}
function IsReocurringEnhancement($params)
{
$params['name'] = 'Recurring';
return $this->ListingTypeField($params);
}
function EnhanceUsingInCommerce($params)
{
if ( !$this->Application->prefixRegistred('ord') ) {
return 0;
}
+ /** @var kDBItem $object */
$object = $this->getObject($params);
- /* @var $object kDBItem */
$listtype_id = $this->getListingInfo($object->GetDBField('ResourceId'), 'ListingTypeId');
$lst_object = $this->Application->recallObject('lst', null, Array('skip_autoload' => true));
$lst_object->Load($listtype_id);
return $lst_object->GetDBField('EnableBuying');
}
function ClickLink($params)
{
$object = $this->getObject($params);
return $this->Application->HREF($params['t'], '', Array('l_id' => $object->GetID(), 'pass'=>'all,l' ));
}
function ListRelatedLinks($params)
{
return $this->PrintList2($params);
}
function LinkLink($params)
{
return $this->ItemLink($params, 'link');
}
function ListingDescription($params)
{
+ /** @var kDBItem $listing_type */
$listing_type = $this->Application->recallObject('lst');
- /* @var $listing_type kDBItem */
return $listing_type->GetDBField('Description');
}
function ListingTypeDetailsLink($params)
{
+ /** @var kDBList $listing_type */
$listing_type = $this->Application->recallObject('lst', null, Array ('raise_warnings' => 0));
- /* @var $listing_type kDBList */
$params['lst_id'] = $listing_type->isLoaded() ? $listing_type->GetID() : $this->Application->Parser->GetParam('key');
return $this->Application->ProcessParsedTag('m', 'Link', $params);
}
/**
* Register hit & go to link url
*
* @param Array $params
*/
function FollowLocation($params)
{
+ /** @var kCatDBItem $object */
$object = $this->getObject($params);
- /* @var $object kCatDBItem */
if (!$object->isLoaded()) {
throw new Exception('No Link ID for redirect');
}
$object->RegisterHit();
// save user and time
if (!$this->Application->isAdmin && $this->Application->LoggedIn()) {
$resource_id = $object->GetDBField('ResourceId');
$user_id = $this->Application->RecallVar('user_id');
+ /** @var kDBItem $link_visit */
$link_visit = $this->Application->recallObject('l-visit', null, Array ('skip_autoload' => true));
- /* @var $link_visit kDBItem */
$link_visit->Load( Array ('ResourceId' => $resource_id, 'PortalUserId' => $user_id) );
if ($link_visit->isLoaded()) {
// for existing visits update date
$link_visit->SetDBField('VisitTimestamp_date', time());
$link_visit->SetDBField('VisitTimestamp_time', time());
}
else {
// for new visits set user & link, visit will be set as default value
$link_visit->SetDBField('ResourceId', $resource_id);
$link_visit->SetDBField('PortalUserId', $user_id);
}
$status = $link_visit->isLoaded() ? $link_visit->Update() : $link_visit->Create();
}
$url_field = $this->Application->GetVar('url_field');
$url = $object->GetDBField($url_field);
if (!preg_match('/^(http|ftp|mailto:)(.*)/U', $url)) {
$url = 'http://'.$url;
}
$this->Application->Redirect('external:'.$url);
}
/**
* Returns formatted address (from custom fields) for using with google
*
* @param Array $params
* @return string
*/
function GetGoogleAddress($params)
{
$object = $this->getObject($params);
if (isset($params['display_info']) && $params['display_info']) {
$ret = $object->GetField('cust_LinkAddress') ? $object->GetField('cust_LinkAddress').'<BR/>' : '';
$ret .= $object->GetField('cust_LinkCity') ? $object->GetField('cust_LinkCity').',' : '';
$ret .= $object->GetField('cust_LinkState') ? $object->GetField('cust_LinkState') : '';
$ret .= $object->GetField('cust_LinkZipCode') ? $object->GetField('cust_LinkZipCode').'<BR/>' : '';
$ret .= $object->GetField('cust_LinkCountry') ? $object->GetField('cust_LinkCountry').'<BR/>' : '';
$ret .= $object->GetField('cust_LinkPhone') ? '<b>'.$this->Application->Phrase('lu_fld_LinkPhone').':</b> '.$object->GetField('cust_LinkPhone') : '';
return $ret;
}
$ret = $object->GetField('cust_LinkAddress') ? $object->GetField('cust_LinkAddress').',' : '';
$ret .= $object->GetField('cust_LinkCity') ? $object->GetField('cust_LinkCity').',' : '';
$ret .= $object->GetField('cust_LinkState') ? $object->GetField('cust_LinkState').',' : '';
$ret .= $object->GetField('cust_LinkZipCode') ? $object->GetField('cust_LinkZipCode').',' : '';
$ret .= $object->GetField('cust_LinkCountry') ? $object->GetField('cust_LinkCountry') : '';
return $ret;
}
/**
* Returns timestamp of last link visit for logged in users only.
*
* @param Array $params
* @return string
*/
function LastVisited($params)
{
if ( !$this->Application->LoggedIn() ) {
// we don't gather link visit statistics for Guests
return '';
}
static $link_visited = Array ();
+ /** @var kDBList $object */
$object = $this->getObject($params);
- /* @var $object kDBList */
if ( !isset($link_visited[$this->Special]) ) {
$resource_ids = $object->GetCol('ResourceId');
$user_id = $this->Application->RecallVar('user_id');
$table_name = $this->Application->getUnitConfig('l-visit')->getTableName();
$sql = 'SELECT VisitTimestamp, ResourceId
FROM ' . $table_name . '
WHERE (PortalUserId = ' . $user_id . ') AND (ResourceId IN (' . implode(',', $resource_ids) . '))';
$link_visited[$this->Special] = $this->Conn->GetCol($sql, 'ResourceId');
}
if ( !isset($link_visited[$this->Special][$object->GetDBField('ResourceId')]) ) {
// link has no visit information for current user
return '';
}
$link_visit = $link_visited[$this->Special][$object->GetDBField('ResourceId')];
if ( isset($params['formatted']) && $params['formatted'] ) {
// format the date
$lang = $this->Application->recallObject('lang.current');
/* @var $lang LanguagesItem */
if ( isset($params['display_time']) && $params['display_time'] ) {
$display_format = $lang->GetDBField('DateFormat') . ' @ ' . $lang->GetDBField('TimeFormat');
}
else {
$display_format = $lang->GetDBField('DateFormat');
}
return date($display_format, $link_visit);
}
return $link_visit;
}
/**
* Checks if specified Custom Fields and condition are true
*
* @param Array $params
* @return string
*/
function HasValue($params)
{
$condition = isset($params['condition']) ? strtolower($params['condition']) : false;
$fields = isset($params['fields']) ? $params['fields'] : false;
if (!$fields || !in_array($condition, Array('or', 'and'))) {
// required parameters not passed
return false;
}
$fields = explode(',', $fields);
+ /** @var kDBList $object */
$object = $this->getObject($params);
- /* @var $object kDBList */
switch ($condition) {
case 'or':
foreach ($fields as $field) {
if (strlen($object->GetDBField($field))) {
return true;
}
}
break;
case 'and':
foreach ($fields as $field) {
if (!strlen($object->GetDBField($field))) {
return false;
}
}
break;
}
return $condition == 'and' ? true : false;
}
/**
* Gets and parses custom details template or default one
*
* @param Array $params
* @return string
*/
function DisplayDetailTemplate($params)
{
+ /** @var kDBItem $object */
$object = $this->getObject($params);
- /* @var $object kDBItem */
$template_name = $object->GetDBField('CustomTemplate');
if (!$template_name || !$this->Application->TemplatesCache->TemplateExists($template_name)) {
$template_name = $params['default_template'];
}
$block_params['name'] = $template_name;
// parse template
return $this->Application->IncludeTemplate($block_params);
}
/**
* Changes title preset of "Duplicate checker" section to show current grouping
*
* @param Array $params
*/
function ModifyUnitConfig($params)
{
$grid = array_key_exists('grid', $params) ? $params['grid'] : false;
if ($grid != 'Duplicates') {
// only for "Duplicate Checker" section
return ;
}
+ /** @var LinkHelper $link_helper */
$link_helper = $this->Application->recallObject('LinkHelper');
- /* @var $link_helper LinkHelper */
// 1. get current grouping
$grouping = $link_helper->getGrouping( $this->getPrefixSpecial() );
$config = $this->getUnitConfig();
// 2. replace field names in grouping with their corresponding column titles
$grids = $config->getGrids();
foreach ($grouping as $index => $group_field) {
$group_field = preg_replace('/^l[\d]+_/', '', $group_field); // remove ml prefix
$grouping[$index] = $this->Application->Phrase($grids[$grid]['Fields'][$group_field]['title']);
}
// 3. patch resulting title preset
$concat_with = "' " . $this->Application->Phrase('la_and') . " '";
$title_preset = $config->getTitlePresetByName('duplicate_links');
$title_preset = str_replace('%s', "'" . implode($concat_with, $grouping) . "'", $title_preset);
$config->addTitlePresets($title_preset, 'duplicate_links');
}
/**
* Allows to modify block params & current list record before PrintList parses record
*
* @param kDBList $object
* @param Array $block_params
*/
function PrepareListElementParams(&$object, &$block_params)
{
$grid = array_key_exists('grid', $block_params) ? $block_params['grid'] : false;
if ($grid != 'Duplicates') {
// only for "Duplicate Checker" section
return ;
}
static $grouping = null;
if (!isset($grouping)) {
+ /** @var LinkHelper $link_helper */
$link_helper = $this->Application->recallObject('LinkHelper');
- /* @var $link_helper LinkHelper */
// 1. get current grouping
$grouping = $link_helper->getGrouping( $this->getPrefixSpecial() );
}
$fields_hash =& $object->getCurrentRecord();
$key_fields = Array ();
foreach ($grouping as $group_field) {
$key_fields[$group_field] = $fields_hash[$group_field];
}
$fields_hash['LinkId'] = base64_encode( serialize($key_fields) );
}
}
Index: branches/5.3.x/units/link_validation/link_validation_eh.php
===================================================================
--- branches/5.3.x/units/link_validation/link_validation_eh.php (revision 16522)
+++ branches/5.3.x/units/link_validation/link_validation_eh.php (revision 16523)
@@ -1,578 +1,578 @@
<?php
/**
* @version $Id$
* @package In-Link
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class LinkValidationEventHandler extends kDBEventHandler {
/**
* Allows to override standard permission mapping
*
* @return void
* @access protected
* @see kEventHandler::$permMapping
*/
protected function mapPermissions()
{
parent::mapPermissions();
$permissions = Array (
'OnResetValidationStatus' => Array ('self' => 'advanced:reset',),
'OnRestartValidation' => Array ('self' => 'advanced:restart',),
'OnContinueValidation' => Array ('self' => 'advanced:continue',),
'OnValidateSelected' => Array ('self' => 'advanced:validate',),
'OnValidateProgress' => Array ('self' => 'advanced:validate|advanced:continue|advanced:restart|advanced:reset',),
'OnCancelValidation' => Array ('self' => 'advanced:validate|advanced:continue|advanced:restart|advanced:reset',),
'OnCronValidation' => Array ('self' => 'advanced:validate|advanced:continue|advanced:restart|advanced:reset',),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
}
/**
* Define alternative event processing method names
*
* @return void
* @see kEventHandler::$eventMethods
* @access protected
*/
protected function mapEvents()
{
parent::mapEvents();
$events_map = Array (
'OnApproveLinks' => 'iterateItems',
'OnDeclineLinks' => 'iterateItems',
);
$this->eventMethods = array_merge($this->eventMethods, $events_map);
}
/**
* Checks user permission to execute given $event
*
* @param kEvent $event
* @return bool
* @access public
*/
public function CheckPermission(kEvent $event)
{
$check_events = Array ('OnApproveLinks', 'OnDeclineLinks', 'OnDeleteLinks');
if ( in_array($event->Name, $check_events) ) {
$ids = $this->_getSelectedIds($event);
$perm_value = true;
if ( $ids ) {
+ /** @var kPermissionsHelper $perm_helper */
$perm_helper = $this->Application->recallObject('PermissionsHelper');
- /* @var $perm_helper kPermissionsHelper */
$items = $perm_helper->GetCategoryItemData('l', $ids);
$check_method = $event->Name == 'OnDeleteLinks' ? 'DeleteCheckPermission' : 'ModifyCheckPermission';
foreach ($items as $item_id => $item_data) {
if ( $perm_helper->$check_method($item_data['CreatedById'], $item_data['CategoryId'], 'l') == 0 ) {
// one of items selected has no permission
$perm_value = false;
break;
}
}
if ( !$perm_value ) {
$event->status = kEvent::erPERM_FAIL;
}
}
return $perm_value;
}
return parent::CheckPermission($event);
}
/**
* Adds calculates fields for category name
*
* @param kDBItem|kDBList $object
* @param kEvent $event
* @return void
* @access protected
*/
protected function prepareObject(&$object, kEvent $event)
{
parent::prepareObject($object, $event);
$object->addCalculatedField('CachedNavbar', 'c.l' . $this->Application->GetVar('m_lang') . '_CachedNavbar');
}
/**
* Allows to show only invalid links
*
* @param kEvent $event
* @return void
* @access protected
* @see kDBEventHandler::OnListBuild()
*/
protected function SetCustomQuery(kEvent $event)
{
parent::SetCustomQuery($event);
+ /** @var kDBList $object */
$object = $event->getObject();
- /* @var $object kDBList */
$object->addFilter('primary_category_filter', 'ci.PrimaryCat = 1');
if ( $event->Special == 'invalid' ) {
$object->addFilter('status_filter', '%1$s.ValidationStatus = ' . LINK_VALIDATION_INVALID);
}
}
/**
* Restarts link validation process
*
* @param kEvent $event
*/
function OnRestartValidation($event)
{
$this->_resetValidation($event);
$this->OnContinueValidation($event);
}
/**
* Restarts link validation process
*
* @param kEvent $event
*/
function _resetValidation($event)
{
$config = $event->getUnitConfig();
// 1. delete previous validation results
$sql = 'SELECT ' . $config->getIDField() . '
FROM ' . $config->getTableName();
$ids = $this->Conn->GetCol($sql);
if ( $ids ) {
+ /** @var kTempTablesHandler $temp_handler */
$temp_handler = $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler');
- /* @var $temp_handler kTempTablesHandler */
$temp_handler->DeleteItems($event->Prefix, $event->Special, $ids);
}
}
/**
* Validates only selected links
*
* @param kEvent $event
*/
function OnValidateSelected($event)
{
$link_ids = $this->_getSelectedIds($event);
if (!$link_ids) {
return ;
}
$validation_data = Array (
'processed' => 0,
'total' => count($link_ids),
'items' => $link_ids,
);
$this->Application->StoreVar($event->Prefix . '_status', serialize($validation_data));
$event->redirect = $this->Application->GetVar('progress_template');
}
/**
* Validates only links, that were not previously validated
*
* @param kEvent $event
*/
function OnContinueValidation($event)
{
$have_data = $this->_prepareValidation($event);
if ($have_data) {
$event->redirect = $this->Application->GetVar('progress_template');
}
}
/**
* Performs validation
*
* @param kEvent $event
* @param bool $from_ajax
*/
function _validate($event, $from_ajax = true)
{
$validation_data = unserialize( $this->Application->RecallVar($event->Prefix . '_status') );
$i = 0;
$link_ids = $validation_data['items'];
$per_page = count($link_ids) >= LINK_VALIDATION_PER_PAGE ? LINK_VALIDATION_PER_PAGE : count($link_ids);
while ($i < $per_page) {
$this->_validateLink($link_ids[$i]);
$i++;
}
// remove processed links from array
array_splice($link_ids, 0, LINK_VALIDATION_PER_PAGE);
// store validation progress
$validation_data['processed'] += $i;
$validation_data['items'] = $link_ids;
if ($validation_data['processed'] >= $validation_data['total']) {
// finished
$this->Application->emailAdmin('LINK.VALIDATION.RESULTS');
$this->Application->RemoveVar($event->Prefix . '_status');
return true;
}
// show progress, proceed to next step
$this->Application->StoreVar($event->Prefix . '_status', serialize($validation_data));
if ($from_ajax) {
echo $validation_data['processed'] / $validation_data['total'] * 100;
$event->status = kEvent::erSTOP;
}
return false;
}
/**
* Performs validation of links (called from AjaxProgressBar)
*
* @param kEvent $event
*/
function OnValidateProgress($event)
{
$done = $this->_validate($event, true);
if ($done) {
$this->Application->Redirect( $this->Application->GetVar('finish_template') );
}
}
/**
* Returns categories, that are located inside recycle bin category
*
* @return Array
*/
function _getRecycleBinCategories()
{
$recycle_bin = $this->Application->ConfigValue('RecycleBinFolder');
if ( !is_numeric($recycle_bin) ) {
return Array ();
}
$recycle_categories = $this->Application->RecallVar('recycle_categories');
if ( $recycle_categories === false ) {
$categories_config = $this->Application->getUnitConfig('c');
$tree_indexes = $this->Application->getTreeIndex($recycle_bin);
$sql = 'SELECT ' . $categories_config->getIDField() . '
FROM ' . $categories_config->getTableName() . '
WHERE TreeLeft BETWEEN ' . $tree_indexes['TreeLeft'] . ' AND ' . $tree_indexes['TreeRight'];
$recycle_categories = serialize($this->Conn->GetCol($sql));
// store recycle bin categories in session to prevent query below happening on each link validation step
$this->Application->StoreVar('recycle_categories', $recycle_categories);
}
return unserialize($recycle_categories);
}
/**
* Checks, that link is located in one of RecycleBin subcategories
*
* @param unknown_type $resource_id
* @return unknown
*/
function _inRecycleBin($resource_id)
{
static $recycle_bin = null;
if ( !isset($recycle_bin) ) {
$recycle_bin = $this->_getRecycleBinCategories();
}
if ( !$recycle_bin ) {
// Recycle Bin not used in system -> link is 100% not there
return false;
}
$sql = 'SELECT CategoryId
FROM ' . $this->Application->getUnitConfig('l-ci')->getTableName() . '
WHERE ItemResourceId = ' . $resource_id . ' AND PrimaryCat = 1';
return in_array($this->Conn->GetOne($sql), $recycle_bin);
}
function _validateLink($link_id)
{
+ /** @var kCurlHelper $curl_helper */
$curl_helper = $this->Application->recallObject('CurlHelper');
- /* @var $curl_helper kCurlHelper */
$link_config = $this->Application->getUnitConfig('l');
$sql = 'SELECT Url, ResourceId
FROM ' . $link_config->getTableName() . '
WHERE ' . $link_config->getIDField() . ' = ' . $link_id;
$link_data = $this->Conn->GetRow($sql);
if ( !preg_match('/^(http|https):\/\/(.*)/U', $link_data['Url']) || $this->_inRecycleBin($link_data['ResourceId']) ) {
return;
}
$curl_helper->timeout = LINK_VALIDATION_TIMEOUT;
$result = $curl_helper->Send($link_data['Url']);
if ( $result === false || $curl_helper->lastErrorMsg != '' ) {
$curl_helper->lastHTTPCode = 500;
}
+ /** @var kDBItem $link_validation */
$link_validation = $this->Application->recallObject($this->Prefix . '.-item', null, Array ('skip_autoload' => true));
- /* @var $link_validation kDBItem */
$link_validation->Load($link_id, 'LinkId');
$now = time();
$fields_hash = Array (
'LinkId' => $link_id,
'ValidationTime_date' => $now,
'ValidationTime_time' => $now,
'ValidationCode' => $curl_helper->lastHTTPCode,
'ValidationStatus' => $curl_helper->lastHTTPCode < 400 ? LINK_VALIDATION_VALID : LINK_VALIDATION_INVALID,
);
$link_validation->SetDBFieldsFromHash($fields_hash);
return $link_validation->isLoaded() ? $link_validation->Update() : $link_validation->Create();
}
/**
* Cancels validation (from validation progress bar)
*
* @param kEvent $event
*/
function OnCancelValidation($event)
{
$this->Application->RemoveVar($event->Prefix . '_status');
}
/**
* Resets validation status for selected
*
* @param kEvent $event
*/
function OnResetValidationStatus($event)
{
$ids = $this->_getSelectedIds($event, true);
if (!$ids) {
return ;
}
+ /** @var kTempTablesHandler $temp_handler */
$temp_handler = $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler', Array ('parent_event' => $event));
- /* @var $temp_handler kTempTablesHandler */
$temp_handler->DeleteItems($event->Prefix, $event->Special, $ids);
}
/**
* Returns ids, that user has checked in grid
*
* @param kEvent $event
* @param bool $transform convert link ids to link validation ids
* @return Array
*/
function _getSelectedIds($event, $transform = false)
{
$ids = Array ();
$items_info = $this->Application->GetVar($event->getPrefixSpecial(true));
if ( $items_info ) {
foreach ($items_info as $id => $field_values) {
if ( getArrayValue($field_values, 'ForeignLinkId') ) {
// we are not gathering ids by unit idfield here!
array_push($ids, $id);
}
}
}
if ( $transform && $ids ) {
$config = $event->getUnitConfig();
$sql = 'SELECT ' . $config->getIDField() . '
FROM ' . $config->getTableName() . '
WHERE LinkId IN (' . implode(',', $ids) . ')';
$ids = $this->Conn->GetCol($sql);
}
return $ids;
}
/**
* Approves/declines selected links
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function iterateItems(kEvent $event)
{
if ( $this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1) ) {
$event->status = kEvent::erFAIL;
return;
}
$ids = $this->_getSelectedIds($event);
if ( !$ids ) {
return;
}
+ /** @var kCatDBItem $object */
$object = $this->Application->recallObject('l.-item', null, Array ('skip_autoload' => true));
- /* @var $object kCatDBItem */
foreach ($ids as $id) {
$object->Load($id);
switch ( $event->Name ) {
case 'OnApproveLinks':
$object->ApproveChanges();
break;
case 'OnDeclineLinks':
$object->DeclineChanges();
break;
}
}
}
/**
* Deletes selected links
*
* @param kEvent $event
*/
function OnDeleteLinks($event)
{
if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) {
$event->status = kEvent::erFAIL;
return;
}
$ids = $this->_getSelectedIds($event);
if (!$ids) {
return ;
}
+ /** @var kTempTablesHandler $temp_handler */
$temp_handler = $this->Application->recallObject('l_TempHandler', 'kTempTablesHandler', Array ('parent_event' => $event));
- /* @var $temp_handler kTempTablesHandler */
$temp_handler->DeleteItems('l', '', $ids);
}
/**
* [HOOK] Allows to edit links, used in selected link validation records
*
* @param kEvent $event
*/
function OnPrepareLinkEditing($event)
{
// hook to OnAfterConfigRead instead of OnEdit, because fake ids should be available in CheckPermission
if ( $this->Application->GetVar('l_event') != 'OnEdit' ) {
return;
}
$items_info = Array ();
$ids = $this->_getSelectedIds($event);
$id_field = $this->Application->getUnitConfig('l')->getIDField();
foreach ($ids as $id) {
$items_info[$id][$id_field] = 'on';
}
$this->Application->SetVar('l', $items_info);
}
/**
* Gets all links, that are not yet validated and prepare data
*
* @param kEvent $event
*
* @return bool
*/
function _prepareValidation($event)
{
// 2. get ids of all links and put them into validation queue
$links_config = $this->Application->getUnitConfig('l');
$sql = 'SELECT ' . $links_config->getIDField() . '
FROM ' . $links_config->getTableName() . '
WHERE LinkId NOT IN (SELECT LinkId FROM ' . $event->getUnitConfig()->getTableName() . ')';
$link_ids = $this->Conn->GetCol($sql);
if ( $link_ids ) {
$validation_data = Array (
'processed' => 0,
'total' => count($link_ids),
'items' => $link_ids,
);
$this->Application->StoreVar($event->Prefix . '_status', serialize($validation_data)); // 4K links will be 78KB serialized
return true;
}
return false;
}
/**
* [SCHEDULED TASK] Performs link validation through cron
*
* @param kEvent $event
*/
function OnCronValidation($event)
{
$this->_resetValidation($event); // remove this for continuing to non validated before links
$have_data = $this->_prepareValidation($event);
if ($have_data) {
do {
$done = $this->_validate($event, false);
} while (!$done);
}
}
/**
* Makes calculated fields to go to multilingual link fields
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnAfterConfigRead(kEvent $event)
{
parent::OnAfterConfigRead($event);
$event->getUnitConfig()->addCalculatedFieldsBySpecial('', Array (
'LinkName' => 'l.l' . $this->Application->GetVar('m_lang') . '_Name',
));
}
}
Index: branches/5.3.x/units/listings/listings_event_handler.php
===================================================================
--- branches/5.3.x/units/listings/listings_event_handler.php (revision 16522)
+++ branches/5.3.x/units/listings/listings_event_handler.php (revision 16523)
@@ -1,875 +1,875 @@
<?php
/**
* @version $Id$
* @package In-Link
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class ListingsEventHandler extends kDBEventHandler {
/**
* Allows to override standard permission mapping
*
* @return void
* @access protected
* @see kEventHandler::$permMapping
*/
protected function mapPermissions()
{
parent::mapPermissions();
$permissions = Array(
// front
'OnRequestEnhancement' => Array ('self' => true),
'OnCancelEnhancement' => Array ('self' => true),
'OnExtendEnhancement' => Array ('self' => true),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
}
/**
* Adds selected link to listing
*
* @param kEvent $event
*/
function OnProcessSelected($event)
{
$object =& $event->getObject();
/* @var $object kDBItem */
$selected_ids = $this->Application->GetVar('selected_ids');
if ( $selected_ids['l'] ) {
$link_id = $selected_ids['l'];
$config = $this->Application->getUnitConfig('l');
$sql = 'SELECT ResourceId
FROM ' . $config->getTableName() . '
WHERE ' . $config->getIDField() . ' = ' . $link_id;
$object->SetDBField($this->Application->RecallVar('dst_field'), $this->Conn->GetOne($sql));
$object->IgnoreValidation = true;
// $this->RemoveRequiredFields($object);
$object->Update();
}
$this->finalizePopup($event);
}
function OnPreSaveListing($event)
{
$event->redirect=false;
$object = $event->getObject( Array('skip_autoload' => true) );
$object->IgnoreValidation = true;
// $this->RemoveRequiredFields($object);
$event->CallSubEvent('OnPreSave');
$this->Application->SetVar($event->getPrefixSpecial(true).'_id', $object->GetId());
return;
}
/**
* Occurs before updating item
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnBeforeItemUpdate(kEvent $event)
{
+ /** @var kDBItem $object */
$object = $event->getObject();
- /* @var $object kDBItem */
if ( $object->IgnoreValidation ) {
$object->UpdateFormattersMasterFields();
}
}
/**
* Occurs before creating item
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnBeforeItemCreate(kEvent $event)
{
parent::OnBeforeItemCreate($event);
+ /** @var kDBItem $object */
$object = $event->getObject();
- /* @var $object kDBItem */
if ( $object->IgnoreValidation ) {
$object->UpdateFormattersMasterFields();
}
}
/**
* Occurs before an item is deleted from live table when copying from temp
* (temp handler deleted all items from live and then copy over all items from temp)
* Id of item being deleted is passed as event' 'id' param
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnBeforeDeleteFromLive(kEvent $event)
{
parent::OnBeforeDeleteFromLive($event);
+ /** @var kDBItem $object */
$object = $event->getObject();
- /* @var $object kDBItem */
$sql = 'SELECT *
FROM ' . $event->getUnitConfig()->getTableName() . '
WHERE ListingId = ' . $object->GetId();
$original_values = $this->Conn->GetRow($sql);
$type_modified = ($object->GetDBField('ListingTypeId') != $original_values['ListingTypeId']);
$link_modified = ($object->GetDBField('ItemResourceId') != $original_values['ItemResourceId']);
$status_modified = ($object->GetDBField('Status') != $original_values['Status']);
if ( $status_modified ) {
$email_template = $object->GetDBField('Status') ? 'LINK.ENHANCE.APPROVE' : 'LINK.ENHANCE.DENY';
$this->notifyOwner($email_template, $object);
}
if ( $type_modified || $link_modified ) {
$this->ResetLink($original_values);
}
if ( $status_modified || $type_modified || $link_modified ) {
$this->EnhanceLink($object, $original_values);
}
if ( $status_modified && !($type_modified || $link_modified) ) {
$this->ResetLink($original_values);
}
}
/**
* Enhances link
*
* @param kDBItem $object
* @param Array $original_values
* @return bool
*/
function EnhanceLink(&$object, $original_values)
{
if ( $object->GetDBField('Status') != STATUS_ACTIVE ) {
return false;
}
if ( $object->GetDBField('ExpiresOn') < time() ) {
$object->SetDBField('Status', STATUS_PENDING);
$object->Update();
$this->ResetLink($original_values);
return false;
}
list($link_object, $listing_type_object) = $this->UpdateLink(
'OnPurchase',
$object->GetDBField('ItemResourceId'),
$object->GetDBField('ListingTypeId')
);
if ( $listing_type_object->GetDBField('OnPurchaseAddToCatEnabled') ) {
$add_to_cat = (int)$listing_type_object->GetDBField('OnPurchaseAddToCat');
$category_item_config = $this->Application->getUnitConfig('l-ci');
$sql = 'DELETE FROM ' . $category_item_config->getTableName() . '
WHERE CategoryId = ' . $add_to_cat . '
AND ItemResourceId = ' . $link_object->GetDBField('ResourceId') . '
AND PrimaryCat = 0';
$this->Conn->Query($sql);
$sql = 'INSERT INTO ' . $category_item_config->getTableName() . '
(CategoryId, ItemResourceId, PrimaryCat)
VALUES (' . $add_to_cat . ', ' . $link_object->GetDBField('ResourceId') . ', 0)';
$this->Conn->Query($sql);
}
}
function ResetLink($original_values)
{
static $has_been_reset = Array ();
if ( $original_values['Status'] != STATUS_ACTIVE || getArrayValue($has_been_reset, $original_values['ListingId']) ) {
return;
}
$has_been_reset[$original_values['ListingId']] = 1;
list (, $listing_type_object) = $this->UpdateLink(
'OnExpire',
$original_values['ItemResourceId'],
$original_values['ListingTypeId']
);
if ( $listing_type_object->GetDBField('OnExpireRemoveFromCatEnabled') ) {
$remove_from_cat = $listing_type_object->GetDBField('OnExpireRemoveFromCat');
$sql = 'DELETE FROM ' . $this->Application->getUnitConfig('l-ci')->getTableName() . '
WHERE ItemResourceId = ' . $original_values['ItemResourceId'] . '
AND CategoryId = ' . $remove_from_cat . '
AND PrimaryCat = 0';
$this->Conn->Query($sql);
}
}
function UpdateLink($action_prefix, $resource_id, $listtype_id)
{
$link_object = $this->Application->recallObject('l', null, Array('skip_autoload' => true));
$link_object->Load($resource_id, 'ResourceId');
// "-item", because can be called as regular after event, and just "lst" recalls list instead
$listtype_object = $this->Application->recallObject('lst.-item', null, Array('skip_autoload' => true));
$listtype_object->Load($listtype_id);
$action_fields = Array( 'EdPick' => 'EditorsPick',
'New' => 'NewItem',
'Hot' => 'HotItem',
'Pop' => 'PopItem',
'Status' => 'Status',
'CustomTemplate' => 'CustomTemplate',
);
// $action_prefix = 'OnPurchase';
foreach($action_fields as $action => $field)
{
$action_value = $listtype_object->GetDBField($action_prefix.$action);
if( $action_value != 3 )
{
$link_object->SetDBField($field, $action_value);
}
}
$priority_value = $listtype_object->GetDBField($action_prefix.'PriorityValue');
switch( $listtype_object->GetDBField($action_prefix.'PriorityAction') )
{
case 1: // equal
$link_object->SetDBField('Priority', $priority_value);
break;
case 2: // increase
$original_priority = $link_object->GetDBField('Priority');
$link_object->SetDBField('Priority', $original_priority + $priority_value);
break;
case 3: // decrease
$original_priority = $link_object->GetDBField('Priority');
$link_object->SetDBField('Priority', $original_priority - $priority_value);
break;
default:
}
$link_object->Update();
return array($link_object, $listtype_object);
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnRequestEnhancement($event)
{
if ( $this->Application->prefixRegistred('ord') ) {
$l_info = $this->Application->GetVar('l');
if (!$l_info) {
return false;
}
list ($link_id, $link_info) = each($l_info);
$listing_type_id = $link_info['ListingTypeId'];
$listing_type = $this->Application->recallObject('lst', null, Array('skip_autoload' => true));
$listing_type->Load($listing_type_id);
if ($listing_type->GetDBField('EnableBuying')) {
$add_to_cart_event = new kEvent('ord:OnAddVirtualProductToCart');
$this->Application->HandleEvent($add_to_cart_event);
if ($add_to_cart_event->redirect) {
$event->SetRedirectParam('pass', 'm');
$event->redirect = $add_to_cart_event->redirect;
}
return true;
}
}
$event->CallSubEvent('OnListingCreate');
}
/**
* Create listing or extend existing listing period
*
* @param kEvent $event
*/
function OnListingCreate($event)
{
$new_processing = false;
$link_id = $listing_type_id = 0;
+ /** @var kDBItem $object */
$object = $event->getObject( Array('skip_autoload' => true) );
- /* @var $object kDBItem */
switch ($event->Name) {
case 'EnhanceLinkAfterOrderApprove':
case 'EnhancedLinkOnCompleteOrder':
// when order with listing virtual product is approved
$fields = $event->getEventParam('field_values');
$item_data = unserialize($fields['ItemData']);
$listing_type_id = $item_data['ListingTypeId'];
$link_id = $item_data['LinkId'];
$new_processing = getArrayValue($item_data, 'HasNewProcessing');
break;
case 'OnListingCreate':
// when requesting enhancement from front (and not via in-commerce)
$links_info = $this->Application->GetVar('l');
if (!$links_info) return false;
$event->redirect = false;
list($link_id, $link_info) = each($links_info);
$listing_type_id = $link_info['ListingTypeId'];
$new_processing = false;
break;
}
if (!$listing_type_id) {
// free or invalid listing type selected
return false;
}
$links_config = $this->Application->getUnitConfig('l');
// get resource_id of link being enhanced
$sql = 'SELECT ResourceId
FROM '.$links_config->getTableName().'
WHERE LinkId = '.$link_id;
$resource_id = $this->Conn->GetOne($sql);
// get listing by link's resource_id
$object->Load($resource_id, 'ItemResourceId');
if ($object->isLoaded()) {
$original_values = $object->GetFieldValues();
}
else {
// set initial fields to listing
$object->SetDBField('ListingTypeId', $listing_type_id);
$object->SetDBField('ItemResourceId', $resource_id);
if ($event->Name == 'OnListingCreate' || $new_processing) {
$item_status = STATUS_PENDING;
}
else {
$item_status = STATUS_ACTIVE;
}
$object->SetDBField('Status', $item_status);
}
// set date of purchase for new listings
$purchased_on = max(time(), $object->GetDBField('ExpiresOn'));
if (!$object->isLoaded()) {
$object->SetDBField('PurchasedOn_date', $purchased_on);
$object->SetDBField('PurchasedOn_time', $purchased_on);
}
// set expiration time for listing
$listing_type = $this->Application->recallObject('lst', null, Array('skip_autoload' => true));
/* @var $listing_type kDBItem */
$listing_type->Load($listing_type_id);
$dur_type_mapping = Array( 1 => 1,
2 => 60,
3 => 3600,
4 => 3600*24,
5 => 3600*24*7,
6 => 3600*24*365/12,
7 => 3600*24*365
);
$duration = $listing_type->GetDBField('Duration');
$duration_type = $listing_type->GetDBField('DurationType');
$expiration_interval = $duration * $dur_type_mapping[$duration_type];
$expiration_date = $purchased_on + $expiration_interval;
$object->SetDBField('ExpiresOn_date', $expiration_date);
$object->SetDBField('ExpiresOn_time', $expiration_date);
// when extending enhancement mark listing as non-received renewal reminder
$object->SetDBField('RenewalReminderSent', 0);
$action = $object->isLoaded() ? 'Update' : 'Create';
if ($object->$action()) {
$event->status = kEvent::erSUCCESS;
switch ($event->Name) {
case 'EnhanceLinkAfterOrderApprove':
case 'EnhancedLinkOnCompleteOrder':
// when order with listing virtual product is approved
if (getArrayValue($original_values, 'Status') != STATUS_ACTIVE) {
$this->EnhanceLink($object, Array());
}
break;
case 'OnListingCreate':
// when requesting enhancement from front (and not via in-commerce)
$event->redirect = $this->Application->GetVar('success_template');
$this->notifyOwner('LINK.ENHANCE', $object);
break;
}
}
else {
$event->status = kEvent::erFAIL;
}
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function EnhancedLinkOnCompleteOrder($event)
{
// create enhancement, but pending
$this->OnListingCreate($event);
// save created listing_id back to itemdata
$object = $event->getObject( Array('skip_autoload' => true) );
$fields = $event->getEventParam('field_values');
$item_data = unserialize($fields['ItemData']);
unset($item_data['ListingTypeId']);
$item_data['ListingId'] = $object->GetID();
$order_items_config = $this->Application->getUnitConfig('orditems');
$orditems_idfield = $order_items_config->getIDField();
$orditems_table = $order_items_config->getTableName();
$this->Conn->doUpdate( Array('ItemData' => serialize($item_data)), $orditems_table, $orditems_idfield.' = '.$fields['OrderItemId'] );
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function EnhanceLinkAfterOrderApprove($event)
{
+ /** @var kDBItem $object */
$object = $event->getObject( Array('skip_autoload' => true) );
- /* @var $object kDBItem */
$fields = $event->getEventParam('field_values');
$item_data = unserialize($fields['ItemData']);
if ( getArrayValue($item_data, 'HasNewProcessing') ) {
// new processing: just approve created listing here
$listing_id = $item_data['ListingId'];
$object->Load($listing_id);
// moved enhancement period to time admin approved enhancement
$time_diff = time() - $object->GetDBField('PurchasedOn');
$object->SetDBField('PurchasedOn_date', $object->GetDBField('PurchasedOn_date') + $time_diff);
$object->SetDBField('PurchasedOn_time', $object->GetDBField('PurchasedOn_time') + $time_diff);
$object->SetDBField('ExpiresOn_date', $object->GetDBField('ExpiresOn_date') + $time_diff);
$object->SetDBField('ExpiresOn_time', $object->GetDBField('ExpiresOn_time') + $time_diff);
$object->SetDBField('Status', STATUS_ACTIVE);
$object->Update();
$this->EnhanceLink($object, Array());
return true;
}
else {
// create listing & approve it at the same time
$this->OnListingCreate($event);
}
}
/**
* Delete listing
*
* @param kEvent $event
*/
function EnhanceLinkAfterOrderDeny($event)
{
$object = $event->getObject( Array('skip_autoload' => true) );
$fields = $event->getEventParam('field_values');
$item_data = unserialize($fields['ItemData']);
$listing_id = $item_data['ListingId'];
$temp_handler = $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler', Array ('parent_event' => $event));
/* @var $temp_handler kTempTablesHandler */
$temp_handler->DeleteItems($event->Prefix, $event->Special, Array($listing_id));
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function ExpireLink($event)
{
+ /** @var kDBItem $object */
$object = $event->getObject(Array ('skip_autoload' => true));
- /* @var $object kDBItem */
$fields = $event->getEventParam('field_values');
$item_data = unserialize($fields['ItemData']);
$sql = 'SELECT ListingId FROM ' . $event->getUnitConfig()->getTableName() . '
WHERE ItemResourceId = ' . $item_data['LinkId'];
$listing_id = $this->Conn->GetOne($sql);
$object->Load($listing_id);
$original_values = $object->GetFieldValues();
$object->SetDBField('Status', 2);
if ( $object->Update() ) {
$event->status = kEvent::erSUCCESS;
$this->ResetLink($original_values);
}
else {
$event->status = kEvent::erFAIL;
}
}
/**
* Apply same processing to each item being selected in grid
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function iterateItems(kEvent $event)
{
+ /** @var kDBItem $object */
$object = $event->getObject(Array ('skip_autoload' => true));
- /* @var $object kDBItem */
$ids = $this->StoreSelectedIDs($event);
$links_config = $this->Application->getUnitConfig('l');
if ( $event->Name == 'OnMassApprove' ) {
foreach ($ids as $id) {
$object->Load($id);
if ( $object->GetDBField('Status') != STATUS_ACTIVE ) {
$original_values = $object->GetFieldValues();
$object->SetDBField('Status', STATUS_ACTIVE);
$this->EnhanceLink($object, $original_values);
}
}
}
if ( $event->Name == 'OnMassDecline' ) {
foreach ($ids as $id) {
$object->Load($id);
if ( $object->GetDBField('Status') == STATUS_ACTIVE ) {
$original_values = $object->GetFieldValues();
$this->ResetLink($original_values);
$this->notifyOwner('LINK.ENHANCE.DENY', $object);
}
}
}
parent::iterateItems($event);
// extend period for pending/renewal links (if owner has agreed)
if ( $event->Name == 'OnMassApprove' ) {
+ /** @var kDBItem $lst_object */
$lst_object = $this->Application->recallObject('lst', null, Array ('skip_autoload' => true));
- /* @var $lst_object kDBItem */
foreach ($ids as $id) {
$object->Load($id);
if ( $object->GetDBField('PendingRenewal') == 1 ) {
$lst_object->Load( $object->GetDBField('ListingTypeId') );
$dur_type_mapping = Array (
1 => 1, 2 => 60, 3 => 3600, 4 => 3600 * 24, 5 => 3600 * 24 * 7,
6 => 3600 * 24 * 365 / 12, 7 => 3600 * 24 * 365
);
$duration = $lst_object->GetDBField('Duration');
$duration_type = $lst_object->GetDBField('DurationType');
$expiration_interval = $duration * $dur_type_mapping[$duration_type];
$renewal_begins = max(time(), $object->GetDBField('ExpiresOn'));
$expiration_date = $renewal_begins + $expiration_interval;
$object->SetDBField('ExpiresOn_date', $expiration_date);
$object->SetDBField('ExpiresOn_time', $expiration_date);
$object->SetDBField('RenewalReminderSent', 0);
$object->SetDBField('PendingRenewal', 0);
if ( $object->Update() ) {
$event->SetRedirectParam('opener', 's');
$this->notifyOwner('LINK.ENHANCE.RENEW', $object);
}
}
else {
$this->notifyOwner('LINK.ENHANCE.APPROVE', $object);
}
}
}
}
/**
* Redirects to cancel template on front-end
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnCancel(kEvent $event)
{
parent::OnCancel($event);
if ( !$this->Application->isAdmin ) {
$event->SetRedirectParam('opener', 's');
$event->redirect = $this->Application->GetVar('cancel_template');
}
}
/**
* Checks that user is owner of link & returns listing id if permissions are ok
*
* @param kEvent $event
* @return mixed
*/
function verifyListingOwner($event)
{
$link_id = $this->Application->GetVar('l_id');
$user_id = $this->Application->RecallVar('user_id');
$sql = 'SELECT ResourceId
FROM '.$this->Application->getUnitConfig('l')->getTableName().'
WHERE (LinkId = '.$link_id.') AND (CreatedById = '.$user_id.')';
$resource_id = $this->Conn->GetOne($sql);
if (!$resource_id) {
$event->status = kEvent::erFAIL;
return false;
}
$sql = 'SELECT ListingId
FROM '.$event->getUnitConfig()->getTableName().'
WHERE ItemResourceId = '.$resource_id;
return $this->Conn->GetOne($sql);
}
protected function OnExtendEnhancement(kEvent $event)
{
$listing_id = $this->verifyListingOwner($event);
if (!$listing_id) {
return ;
}
$object = $event->getObject( Array('skip_autoload' => true) );
/* @var $object kDBItem */
$object->Load($listing_id);
$object->SetDBField('PendingRenewal', 1);
$object->Update();
$event->redirect = $this->Application->GetVar('success_template');
$this->notifyOwner('LINK.ENHANCE.EXTEND', $object);
}
/**
* Cancels enhancement
*
* @param kEvent $event
*/
function OnCancelEnhancement($event)
{
$listing_id = $this->verifyListingOwner($event);
if ( !$listing_id ) {
return;
}
+ /** @var kDBItem $object */
$object = $event->getObject(Array ('skip_autoload' => true));
- /* @var $object kDBItem */
$object->Load($listing_id);
$original_values = $object->GetFieldValues();
$original_values['Status'] = 1;
$this->ResetLink($original_values);
$this->notifyOwner('LINK.ENHANCE.CANCEL', $object);
$object->Delete();
$event->redirect = $this->Application->GetVar('success_template');
}
/**
* Checks expired paid listings
*
* @param kEvent $event
*/
function OnCheckExpiredPaidListings($event)
{
$config = $event->getUnitConfig();
$links_config = $this->Application->getUnitConfig('l');
$sql = 'SELECT ListingId FROM '.$config->getTableName().'
WHERE ExpiresOn < '.time().' AND Status = 1';
$expired_listings = $this->Conn->GetCol($sql);
if(is_array($expired_listings) && count($expired_listings) > 0)
{
+ /** @var kDBItem $object */
$object = $this->Application->recallObject($event->Prefix.'.-item', null, Array('skip_autoload' => true));
- /* @var $object kDBItem */
foreach($expired_listings as $listing_id)
{
$object->Load($listing_id);
$original_values = $object->GetFieldValues();
$this->ResetLink($original_values);
$object->SetDBField('Status', 2);
$object->Update();
$this->notifyOwner('LINK.ENHANCE.EXPIRE', $object);
}
}
$link_id_field = $this->Application->getUnitConfig('l')->getIDField();
$sql = 'SELECT ls.ListingId, l.CreatedById, l.' . $link_id_field . ' FROM ' . $config->getTableName() . ' ls
LEFT JOIN ' . $this->Application->getUnitConfig('lst')->getTableName() . ' lst
ON ls.ListingTypeId = lst.ListingTypeId
LEFT JOIN ' . $links_config->getTableName() . ' l
ON ls.ItemResourceId = l.ResourceId
WHERE ls.Status = 1
AND ls.ExpiresOn < ' . time() . ' + lst.RenewalReminder * 3600 *24
AND ls.RenewalReminderSent = 0';
$res = $this->Conn->Query($sql);
if(is_array($res) && count($res) > 0)
{
$listing_ids = Array();
foreach($res as $record)
{
$send_params = Array (
'PrefixSpecial' => 'l',
'item_id' => $record[$link_id_field]
);
$this->Application->emailUser('LINK.ENHANCE.RENEWAL.NOTICE', $record['CreatedById'], $send_params);
$this->Application->emailAdmin('LINK.ENHANCE.RENEWAL.NOTICE', null, $send_params);
$listing_ids[] = $record['ListingId'];
}
$sql = 'UPDATE '.$config->getTableName().'
SET RenewalReminderSent = 1
WHERE ListingId IN ('.implode(',', $listing_ids).')';
$this->Conn->Query($sql);
}
}
/**
* Removes enhancements on listing delete
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnMassDelete(kEvent $event)
{
+ /** @var kDBItem $object */
$object = $event->getObject(Array ('skip_autoload' => true));
- /* @var $object kDBItem */
$ids = $this->StoreSelectedIDs($event);
foreach ($ids as $id) {
$object->Load($id);
if ( $object->GetDBField('Status') == STATUS_ACTIVE ) {
$this->ResetLink( $object->GetFieldValues() );
}
}
parent::OnMassDelete($event);
}
/**
* Moves enhancement from original link to it's pending copy, that is going to be approved
*
* @param kEvent $event
*/
function OnMoveEnhancement($event)
{
$master_config = $event->MasterEvent->getUnitConfig();
$id_field = $master_config->getIDField();
$item_table_name = $master_config->getTableName();
$pending_id = $event->MasterEvent->getEventParam('id');
$original_id = $event->MasterEvent->getEventParam('original_id');
$sql = 'SELECT ResourceId, '.$id_field.'
FROM '.$item_table_name.'
WHERE '.$id_field.' IN ('.$pending_id.','.$original_id.')';
$resource_ids = $this->Conn->GetCol($sql, $id_field);
$table_name = $event->getUnitConfig()->getTableName();
$sql = 'UPDATE '.$table_name.'
SET ItemResourceId = '.$resource_ids[$pending_id].'
WHERE ItemResourceId = '.$resource_ids[$original_id];
$this->Conn->Query($sql);
}
/**
* Notifies link owner about listing related action.
*
* @param string $email_template E-mail template.
* @param kDBItem $listing Listing.
*
* @return void
*/
protected function notifyOwner($email_template, kDBItem $listing)
{
$unit_config = $this->Application->getUnitConfig('l');
$id_field = $unit_config->getIDField();
$sql = 'SELECT CreatedById, ' . $id_field . '
FROM ' . $unit_config->getTableName() . '
WHERE ResourceId = ' . $listing->GetDBField('ItemResourceId');
$link_data = $this->Conn->GetRow($sql);
$send_params = array(
'PrefixSpecial' => 'l',
'item_id' => $link_data[$id_field],
);
$this->Application->emailUser($email_template, $link_data['CreatedById'], $send_params);
$this->Application->emailAdmin($email_template, null, $send_params);
}
/**
* Makes calculated fields to go to multilingual link fields
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnAfterConfigRead(kEvent $event)
{
parent::OnAfterConfigRead($event);
$language_id = $this->Application->GetVar('m_lang');
$event->getUnitConfig()->addCalculatedFieldsBySpecial('', Array (
'LinkName' => 'CONCAT(item_table.l' . $language_id . '_Name, " (", item_table.Url, ")")',
));
}
}
Index: branches/5.3.x/units/listings/listings_tag_processor.php
===================================================================
--- branches/5.3.x/units/listings/listings_tag_processor.php (revision 16522)
+++ branches/5.3.x/units/listings/listings_tag_processor.php (revision 16523)
@@ -1,92 +1,92 @@
<?php
/**
* @version $Id$
* @package In-Link
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class ListingsTagProcessor extends kDBTagProcessor {
/**
* Returns a link for editing product
*
* @param Array $params
* @return string
*/
function ListingTypeLink($params)
{
+ /** @var kDBItem $object */
$object = $this->getObject($params);
- /* @var $object kDBItem */
return $this->Application->HREF($params['edit_template'],'', Array(
'm_opener' => 'd',
'lst_mode' => 't',
'lst_event' => 'OnEdit',
'lst_id' => $object->GetDBField('ListingTypeId'),
'pass' => 'all,lst'
), 'index.php');
}
function LinkEditLink($params)
{
+ /** @var kDBItem $object */
$object = $this->getObject($params);
- /* @var $object kDBItem */
$links_config = $this->Application->getUnitConfig('l');
$sql = 'SELECT '.$links_config->getIDField().'
FROM '.$links_config->getTableName().'
WHERE ResourceId = '.$object->GetDBField('ItemResourceId');
return $this->Application->HREF($params['edit_template'],'', Array(
'm_opener' => 'd',
'l_mode' => 't',
'l_event' => 'OnEdit',
'l_id' => $this->Conn->GetOne($sql),
'pass' => 'all,l'
));
}
protected function ExpirationDate($params)
{
return $this->_expirationField($params, 'DateFormat');
}
protected function ExpirationTime($params)
{
return $this->_expirationField($params, 'TimeFormat');
}
protected function _expirationField($params, $format_field)
{
+ /** @var kDBItem $object */
$object = $this->getObject($params);
- /* @var $object kDBItem */
+ /** @var kDBItem $listing_type */
$listing_type = $this->Application->recallObject( 'lst', 'lst', $params );
- /* @var $listing_type kDBItem */
$dur_type_mapping = Array (
1 => 1, 2 => 60, 3 => 3600, 4 => 3600 * 24,
5 => 3600 * 24 * 7, 6 => 3600 * 24 * 365 / 12, 7 => 3600 * 24 * 365
);
$duration = $listing_type->GetDBField('Duration');
$duration_type = $listing_type->GetDBField('DurationType');
$expiration_interval = $duration * $dur_type_mapping[$duration_type];
$expiration_date = time() + $expiration_interval;
+ /** @var LanguagesItem $lang */
$lang = $this->Application->recallObject('lang.current');
- /* @var $lang LanguagesItem */
return date($lang->GetDBField($format_field), $expiration_date);
}
}
\ No newline at end of file
Index: branches/5.3.x/units/listing_types/listing_types_event_handler.php
===================================================================
--- branches/5.3.x/units/listing_types/listing_types_event_handler.php (revision 16522)
+++ branches/5.3.x/units/listing_types/listing_types_event_handler.php (revision 16523)
@@ -1,97 +1,97 @@
<?php
/**
* @version $Id$
* @package In-Link
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class ListingTypesEventHandler extends kDBEventHandler {
/**
* Allows to override standard permission mapping
*
* @return void
* @access protected
* @see kEventHandler::$permMapping
*/
protected function mapPermissions()
{
parent::mapPermissions();
$permissions = Array (
'OnItemBuild' => Array ('self' => true),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
}
/**
* Set's selected category to listing type
*
* @param kEvent $event
*/
function OnProcessSelected($event)
{
$object = $event->getObject();
$selected_ids = $this->Application->GetVar('selected_ids');
$object->SetDBField($this->Application->RecallVar('dst_field'), $selected_ids['c']);
$this->RemoveRequiredFields($object);
$object->Update();
$this->finalizePopup($event);
}
function OnPreSaveListingType($event)
{
$event->redirect = false;
$object = $event->getObject( Array('skip_autoload' => true) );
$this->RemoveRequiredFields($object);
$event->CallSubEvent('OnPreSave');
$this->Application->SetVar($event->getPrefixSpecial(true).'_id', $object->GetID());
}
/**
* Prepare temp tables and populate it
* with items selected in the grid
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnEdit(kEvent $event)
{
if ( $this->Application->prefixRegistred('p') ) {
$this->Application->recallObject('p', null, Array ('skip_autoload' => true));
}
parent::OnEdit($event);
}
/**
* Makes shopping cart name required, when buying is enabled
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnBeforeItemUpdate(kEvent $event)
{
parent::OnBeforeItemUpdate($event);
+ /** @var kDBItem $object */
$object = $event->getObject();
- /* @var $object kDBItem */
$object->setRequired('ShopCartName', $object->GetDBField('EnableBuying'));
}
}
\ No newline at end of file
Index: branches/5.3.x/units/listing_types/listing_types_tag_processor.php
===================================================================
--- branches/5.3.x/units/listing_types/listing_types_tag_processor.php (revision 16522)
+++ branches/5.3.x/units/listing_types/listing_types_tag_processor.php (revision 16523)
@@ -1,49 +1,49 @@
<?php
/**
* @version $Id$
* @package In-Link
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class ListingTypesTagProcessor extends kDBTagProcessor {
function CategoryPath($params)
{
$object = $this->getObject($params);
$params['cat_id'] = $object->GetDBField($params['field']);
+ /** @var kNavigationBar $navigation_bar */
$navigation_bar = $this->Application->recallObject('kNavigationBar');
- /* @var $navigation_bar kNavigationBar */
return $navigation_bar->build($params);
}
/**
* Makes 1st listing type default
*
* @param Array $params
* @return bool
*/
function IsDefault($params)
{
static $listing_type_id = null;
+ /** @var kDBItem $object */
$object = $this->getObject($params);
- /* @var $object kDBItem */
if (!isset($listing_type_id)) {
$listing_type_id = $object->GetID();
}
return $listing_type_id == $object->GetID();
}
}
\ No newline at end of file
Index: branches/5.3.x/install.php
===================================================================
--- branches/5.3.x/install.php (revision 16522)
+++ branches/5.3.x/install.php (revision 16523)
@@ -1,58 +1,58 @@
<?php
/**
* @version $Id$
* @package In-Link
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
$module_folder = 'modules/in-link';
if ( !defined('IS_INSTALL') ) {
// separate module install
define('IS_INSTALL', 1);
define('ADMIN', 1);
define('FULL_PATH', realpath(dirname(__FILE__) . '/../..'));
include_once(FULL_PATH . '/core/kernel/startup.php');
require_once FULL_PATH . '/core/install/install_toolkit.php';
$constants_file = FULL_PATH . '/' . $module_folder . '/constants.php';
if ( file_exists($constants_file) ) {
require_once $constants_file;
}
$toolkit = new kInstallToolkit();
}
else {
// install, using installation wizard
+ /** @var kInstallToolkit $toolkit */
$toolkit =& $this->toolkit;
- /* @var $toolkit kInstallToolkit */
}
$application =& kApplication::Instance();
$application->Init();
if ( $application->RecallVar('user_id') != USER_ROOT ) {
die('restricted access!');
}
$category =& $toolkit->createModuleCategory('Directory', 'Link Directory', '#in-link/section_design#', 'in-link/img/menu_links.gif');
$toolkit->RunSQL('/' . $module_folder . '/install/install_schema.sql');
$toolkit->RunSQL('/' . $module_folder . '/install/install_data.sql', '{LinkCatId}', $category->GetID());
$toolkit->ImportLanguage('/' . $module_folder . '/install/english', isset($constants_file));
$toolkit->SetModuleRootCategory(basename($module_folder), $category->GetID());
$toolkit->linkCustomFields(basename($module_folder), 'l', 4); // to create Custom Fields for Links
$toolkit->linkCustomFields('KERNEL', 'c', 1); // to create ItemTemplate custom field
$toolkit->setModuleItemTemplate($category, 'l', '#in-link/item_design#');
$toolkit->finalizeModuleInstall($module_folder, true);
Index: branches/5.3.x
===================================================================
--- branches/5.3.x (revision 16522)
+++ branches/5.3.x (revision 16523)
Property changes on: branches/5.3.x
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /modules/in-link/branches/5.2.x:r16517

Event Timeline