Page MenuHomeIn-Portal Phabricator

in-link
No OneTemporary

File Metadata

Created
Wed, Feb 12, 2:45 PM
Index: branches/5.2.x/units/links/links_event_handler.php
===================================================================
--- branches/5.2.x/units/links/links_event_handler.php (revision 15213)
+++ branches/5.2.x/units/links/links_event_handler.php (revision 15214)
@@ -1,612 +1,612 @@
<?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);
$object = $event->getObject();
/* @var $object kDBList */
if ( !$this->Application->isAdminUser ) {
$object->addFilter('expire_filter', '(Expire > ' . adodb_mktime() . ' OR Expire IS NULL)');
}
if ( substr($event->Special, 0, 10) == 'duplicates' ) {
$object->removeFilter('category_filter');
$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':
$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)
{
$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 ();
$id_field = $this->Application->getUnitOption($event->Prefix, 'IDField');
$table_name = $this->Application->getUnitOption($event->Prefix, 'TableName');
$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 ) {
$temp_handler = $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler');
/* @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;
}
$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 ;
}
$free_listings = $this->Application->ConfigValue('Link_AllowFreeListings');
$virtual_fields = $this->Application->getUnitOption($event->Prefix, 'VirtualFields');
$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);
$this->Application->setUnitOption($event->Prefix, 'VirtualFields', $virtual_fields);
if (!$this->Application->isAdminUser) {
// for now only on Front-End
$this->Application->setUnitOption($event->Prefix, 'PopulateMlFields', 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);
$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 */
$send_params = 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_event =& $this->Application->EmailEventUser('LINK.CONTACTFORM', $object->GetDBField('CreatedById'), $send_params);
+ $email_sent = $this->Application->EmailEventUser('LINK.CONTACTFORM', $object->GetDBField('CreatedById'), $send_params);
- if ($email_event->status == kEvent::erSUCCESS) {
+ 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->EmailEventAdmin('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 ;
}
$object = $event->getObject();
/* @var $object kDBItem */
if ($object->GetDBField('Url') != $object->GetOriginalField('Url')) {
// check only when url was changed
$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->EmailEventAdmin('LINK.RECIPROCAL.CHECK.FAILED');
}
}
}
/**
* Update links status by their reciprocal status
*
* @param kEvent $event
*/
function OnProcessReciprocalLinks($event)
{
if ( !$this->Application->ConfigValue('ReciprocalLinkChecking') ) {
return;
}
$object = $event->getObject( Array('skip_autoload' => true) );
/* @var $object kCatDBItem */
$link_helper = $this->Application->recallObject('LinkHelper');
/* @var $link_helper LinkHelper */
$id_field = $this->Application->getUnitOption($event->Prefix, 'IDField');
$table_name = $this->Application->getUnitOption($event->Prefix, 'TableName');
// 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->EmailEventAdmin('LINK.RECIPROCAL.CHECK.FAILED');
}
}
// 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);
}
$sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . '
FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . '
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' ) {
$clones = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'Clones');
$subitem_prefix = $event->Prefix . '-' . $event->MasterEvent->Prefix;
$clones[$subitem_prefix]['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',
);
$this->Application->setUnitOption($event->MasterEvent->Prefix, 'Clones', $clones);
}
}
/**
* 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);
$object = $event->getObject();
/* @var $object kDBItem */
$link_id = $event->getEventParam('original_id');
$new_resource_id = $object->GetDBField('ResourceId');
$sql = 'SELECT ResourceId
FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . '
WHERE ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . '=' . $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);
$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->getUnitOption($prefix, 'TableName');
$this->Conn->doUpdate($fields_hash, $table_name, $field . ' = ' . $old_resource_id);
}
}
\ No newline at end of file
Index: branches/5.2.x/units/listings/listings_event_handler.php
===================================================================
--- branches/5.2.x/units/listings/listings_event_handler.php (revision 15213)
+++ branches/5.2.x/units/listings/listings_event_handler.php (revision 15214)
@@ -1,846 +1,846 @@
<?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();
$selected_ids = $this->Application->GetVar('selected_ids');
if ($selected_ids['l']) {
$link_id = $selected_ids['l'];
$sql = 'SELECT ResourceId
FROM '.$this->Application->getUnitOption('l', 'TableName').'
WHERE '.$this->Application->getUnitOption('l', 'IDField').' = '.$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)
{
$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);
$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);
$object = $event->getObject();
/* @var $object kDBItem */
$sql = 'SELECT *
FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . '
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_event = $object->GetDBField('Status') ? 'LINK.ENHANCE.APPROVE' : 'LINK.ENHANCE.DENY';
$sql = 'SELECT CreatedById
FROM ' . $this->Application->getUnitOption('l', 'TableName') . '
WHERE ResourceId = ' . $object->GetDBField('ItemResourceId');
$user_id = $this->Conn->GetOne($sql);
$this->Application->EmailEventUser($email_event, $user_id);
$this->Application->EmailEventAdmin($email_event);
}
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);
}
}
function EnhanceLink(&$object, $original_values)
{
if ($object->GetDBField('Status') != STATUS_ACTIVE) {
return false;
}
if ($object->GetDBField('ExpiresOn') < adodb_mktime()) {
$object->SetDBField('Status', STATUS_PENDING);
$object->Update();
$this->ResetLink($original_values);
return false;
}
$this->UpdateLink('OnPurchase', $object->GetDBField('ItemResourceId'), $object->GetDBField('ListingTypeId'));
$listtype_object = $this->Application->recallObject('lst');
if ( $listtype_object->GetDBField('OnPurchaseAddToCatEnabled') )
{
$link_object = $this->Application->recallObject('l');
$add_to_cat = (int)$listtype_object->GetDBField('OnPurchaseAddToCat');
$sql = 'DELETE FROM '.$this->Application->getUnitOption('l-ci', 'TableName').'
WHERE CategoryId = '.$add_to_cat.'
AND ItemResourceId = '.$link_object->GetDBField('ResourceId').'
AND PrimaryCat = 0';
$this->Conn->Query($sql);
$sql = 'INSERT INTO '.$this->Application->getUnitOption('l-ci', 'TableName').'
(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;
$this->UpdateLink('OnExpire', $original_values['ItemResourceId'], $original_values['ListingTypeId']);
$listtype_object = $this->Application->recallObject('lst');
if( $listtype_object->GetDBField('OnExpireRemoveFromCatEnabled') )
{
$remove_from_cat = $listtype_object->GetDBField('OnExpireRemoveFromCat');
$sql = 'DELETE FROM '.$this->Application->getUnitOption('l-ci', 'TableName').'
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();
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnRequestEnhancement($event)
{
if ($this->Application->isModuleEnabled('In-Commerce')) {
$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;
$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;
}
// get resource_id of link beeing enhanced
$sql = 'SELECT ResourceId
FROM '.$this->Application->getUnitOption('l', 'TableName').'
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(adodb_mktime(), $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));
$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');
$sql = 'SELECT CreatedById FROM '.$this->Application->getUnitOption('l', 'TableName').'
WHERE ResourceId = '.$object->GetDBField('ItemResourceId');
- $email_event_user =& $this->Application->EmailEventUser('LINK.ENHANCE', $this->Conn->GetOne($sql));
- $email_event_admin =& $this->Application->EmailEventAdmin('LINK.ENHANCE');
+ $this->Application->EmailEventUser('LINK.ENHANCE', $this->Conn->GetOne($sql));
+ $this->Application->EmailEventAdmin('LINK.ENHANCE');
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();
$orditems_idfield = $this->Application->getUnitOption('orditems', 'IDField');
$orditems_table = $this->Application->getUnitOption('orditems', 'TableName');
$this->Conn->doUpdate( Array('ItemData' => serialize($item_data)), $orditems_table, $orditems_idfield.' = '.$fields['OrderItemId'] );
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function EnhanceLinkAfterOrderApprove($event)
{
$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 = adodb_mktime() - $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');
$temp_handler->DeleteItems($event->Prefix, $event->Special, Array($listing_id));
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function ExpireLink($event)
{
$object = $event->getObject(Array ('skip_autoload' => true));
/* @var $object kDBItem */
$fields = $event->getEventParam('field_values');
$item_data = unserialize($fields['ItemData']);
$sql = 'SELECT ListingId FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . '
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)
{
$object = $event->getObject(Array ('skip_autoload' => true));
/* @var $object kDBItem */
$ids = $this->StoreSelectedIDs($event);
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);
$sql = 'SELECT CreatedById
FROM ' . $this->Application->getUnitOption('l', 'TableName') . '
WHERE ResourceId = ' . $object->GetDBField('ItemResourceId');
- $email_event_user =& $this->Application->EmailEventUser('LINK.ENHANCE.DENY', $this->Conn->GetOne($sql));
- $email_event_admin =& $this->Application->EmailEventAdmin('LINK.ENHANCE.DENY');
+ $this->Application->EmailEventUser('LINK.ENHANCE.DENY', $this->Conn->GetOne($sql));
+ $this->Application->EmailEventAdmin('LINK.ENHANCE.DENY');
}
}
}
parent::iterateItems($event);
// extend period for pending/renewal links (if owner has agreed)
if ( $event->Name == 'OnMassApprove' ) {
$lst_object = $this->Application->recallObject('lst', null, Array ('skip_autoload' => true));
/* @var $lst_object kDBItem */
foreach ($ids as $id) {
$object->Load($id);
$sql = 'SELECT CreatedById
FROM ' . $this->Application->getUnitOption('l', 'TableName') . '
WHERE ResourceId = ' . $object->GetDBField('ItemResourceId');
$owner_id = $this->Conn->GetOne($sql);
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(adodb_mktime(), $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->status = kEvent::erSUCCESS;
$event->SetRedirectParam('opener', 's');
$this->Application->EmailEventUser('LINK.ENHANCE.RENEW', $owner_id);
$this->Application->EmailEventAdmin('LINK.ENHANCE.RENEW');
}
else {
$event->status = kEvent::erFAIL;
$event->redirect = false;
break;
}
}
else {
$this->Application->EmailEventUser('LINK.ENHANCE.APPROVE', $owner_id);
$this->Application->EmailEventAdmin('LINK.ENHANCE.APPROVE');
}
}
}
}
/**
* 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->getUnitOption('l', 'TableName').'
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 '.$this->Application->getUnitOption($event->Prefix, 'TableName').'
WHERE ItemResourceId = '.$resource_id;
return $this->Conn->GetOne($sql);
}
function OnExtendEnhancement($event)
{
$listing_id = $this->verifyListingOwner($event);
if (!$listing_id) {
return ;
}
$object = $event->getObject( Array('skip_autoload' => true) );
$object->Load($listing_id);
$object->SetDBField('PendingRenewal', 1);
$object->Update();
$event->redirect = $this->Application->GetVar('success_template');
$sql = 'SELECT CreatedById FROM '.$this->Application->getUnitOption('l', 'TableName').'
WHERE ResourceId = '.$object->GetDBField('ItemResourceId');
- $email_event_user =& $this->Application->EmailEventUser('LINK.ENHANCE.EXTEND', $this->Conn->GetOne($sql));
- $email_event_admin =& $this->Application->EmailEventAdmin('LINK.ENHANCE.EXTEND');
+ $this->Application->EmailEventUser('LINK.ENHANCE.EXTEND', $this->Conn->GetOne($sql));
+ $this->Application->EmailEventAdmin('LINK.ENHANCE.EXTEND');
}
/**
* Cancels enhancement
*
* @param kEvent $event
*/
function OnCancelEnhancement($event)
{
$listing_id = $this->verifyListingOwner($event);
if ( !$listing_id ) {
return;
}
$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);
$sql = 'SELECT CreatedById FROM ' . $this->Application->getUnitOption('l', 'TableName') . '
WHERE ResourceId = ' . $object->GetDBField('ItemResourceId');
$this->Application->EmailEventUser('LINK.ENHANCE.CANCEL', $this->Conn->GetOne($sql));
$this->Application->EmailEventAdmin('LINK.ENHANCE.CANCEL');
$object->Delete();
$event->redirect = $this->Application->GetVar('success_template');
}
/**
* Checks expired paid listings
*
* @param kEvent $event
*/
function OnCheckExpiredPaidListings($event)
{
$sql = 'SELECT ListingId FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').'
WHERE ExpiresOn < '.adodb_mktime().' AND Status = 1';
$expired_listings = $this->Conn->GetCol($sql);
if(is_array($expired_listings) && count($expired_listings) > 0)
{
$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();
$sql = 'SELECT CreatedById FROM '.$this->Application->getUnitOption('l', 'TableName').'
WHERE ResourceId = '.$object->GetDBField('ItemResourceId');
- $email_event_user =& $this->Application->EmailEventUser('LINK.ENHANCE.EXPIRE', $this->Conn->GetOne($sql));
- $email_event_admin =& $this->Application->EmailEventAdmin('LINK.ENHANCE.EXPIRE');
+ $this->Application->EmailEventUser('LINK.ENHANCE.EXPIRE', $this->Conn->GetOne($sql));
+ $this->Application->EmailEventAdmin('LINK.ENHANCE.EXPIRE');
}
}
$sql = 'SELECT ls.ListingId, l.CreatedById FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' ls
LEFT JOIN '.$this->Application->getUnitOption('lst', 'TableName').' lst
ON ls.ListingTypeId = lst.ListingTypeId
LEFT JOIN '.$this->Application->getUnitOption('l', 'TableName').' l
ON ls.ItemResourceId = l.ResourceId
WHERE ls.Status = 1
AND ls.ExpiresOn < '.adodb_mktime().' + 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)
{
- $email_event_user =& $this->Application->EmailEventUser('LINK.ENHANCE.RENEWAL.NOTICE', $record['CreatedById']);
- $email_event_admin =& $this->Application->EmailEventAdmin('LINK.ENHANCE.RENEWAL.NOTICE');
+ $this->Application->EmailEventUser('LINK.ENHANCE.RENEWAL.NOTICE', $record['CreatedById']);
+ $this->Application->EmailEventAdmin('LINK.ENHANCE.RENEWAL.NOTICE');
$listing_ids[] = $record['ListingId'];
}
$sql = 'UPDATE '.$this->Application->getUnitOption($event->Prefix, 'TableName').'
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)
{
$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)
{
$id_field = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'IDField');
$item_table_name = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'TableName');
$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 = $this->Application->getUnitOption($event->Prefix, 'TableName');
$sql = 'UPDATE '.$table_name.'
SET ItemResourceId = '.$resource_ids[$pending_id].'
WHERE ItemResourceId = '.$resource_ids[$original_id];
$this->Conn->Query($sql);
}
/**
* 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');
$calculated_fields = $this->Application->getUnitOption($event->Prefix, 'CalculatedFields');
$calculated_fields['']['LinkName'] = 'CONCAT(item_table.l' . $language_id . '_Name, " (", item_table.Url, ")")';
$this->Application->setUnitOption($event->Prefix, 'CalculatedFields', $calculated_fields);
}
}
\ No newline at end of file
Index: branches/5.2.x/install/upgrades.php
===================================================================
--- branches/5.2.x/install/upgrades.php (revision 15213)
+++ branches/5.2.x/install/upgrades.php (revision 15214)
@@ -1,176 +1,177 @@
<?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!');
$upgrade_class = 'InLinkUpgrades';
/**
* Class, that holds all upgrade scripts for "In-Link" module
*
*/
class InLinkUpgrades extends kUpgradeHelper {
public function __construct()
{
parent::__construct();
$this->dependencies = Array (
'4.3.9' => Array ('Core' => '4.3.9'),
'5.0.0' => Array ('Core' => '5.0.0'),
'5.0.1' => Array ('Core' => '5.0.1'),
'5.0.2-B1' => Array ('Core' => '5.0.2-B1'),
'5.0.2-B2' => Array ('Core' => '5.0.2-B2'),
'5.0.2-RC1' => Array ('Core' => '5.0.2-RC1'),
'5.0.2' => Array ('Core' => '5.0.2'),
'5.0.3-B1' => Array ('Core' => '5.0.3-B1'),
'5.0.3-B2' => Array ('Core' => '5.0.3-B2'),
'5.0.3-RC1' => Array ('Core' => '5.0.3-RC1'),
'5.0.3' => Array ('Core' => '5.0.3'),
'5.0.4-B1' => Array ('Core' => '5.0.4-B1'),
'5.0.4-B2' => Array ('Core' => '5.0.4-B2'),
'5.0.4' => Array ('Core' => '5.0.4'),
'5.1.0-B1' => Array ('Core' => '5.1.0-B1'),
'5.1.0-RC1' => Array ('Core' => '5.1.0-RC1'),
'5.1.0' => Array ('Core' => '5.1.0'),
'5.1.1-B1' => Array ('Core' => '5.1.1-B1'),
'5.1.1-B2' => Array ('Core' => '5.1.1-B2'),
'5.1.1-RC1' => Array ('Core' => '5.1.1-RC1'),
'5.1.1' => Array ('Core' => '5.1.1'),
'5.1.2-B1' => Array ('Core' => '5.1.2-B1'),
'5.1.2-RC1' => Array ('Core' => '5.1.2-RC1'),
'5.1.2' => Array ('Core' => '5.1.2'),
'5.1.3-B1' => Array ('Core' => '5.1.3-B2'),
'5.1.3-RC1' => Array ('Core' => '5.1.3-RC1'),
'5.1.3-RC2' => Array ('Core' => '5.1.3-RC2'),
'5.1.3' => Array ('Core' => '5.1.3'),
'5.2.0-B1' => Array ('Core' => '5.2.0-B1'),
'5.2.0-B2' => Array ('Core' => '5.2.0-B2'),
+ '5.2.0-B3' => Array ('Core' => '5.2.0-B3'),
);
}
/**
* Changes table structure, where multilingual fields of TEXT type are present
*
* @param string $mode when called mode {before, after)
*/
function Upgrade_5_0_0($mode)
{
if ($mode == 'after') {
$root_category = $this->Application->findModule('Name', 'In-Link', 'RootCat');
$sql = 'UPDATE ' . $this->Application->getUnitOption('c', 'TableName') . '
SET UseMenuIconUrl = 1, MenuIconUrl = "in-link/img/menu_links.gif"
WHERE ' . $this->Application->getUnitOption('c', 'IDField') . ' = ' . $root_category;
$this->Conn->Query($sql);
$this->_updateDetailTemplate('l', 'inlink/detail', 'in-link/designs/detail');
// copy link name and description to their multilingual equivalents
$this->_copyToMultilingual();
}
}
/**
* Copy link values from normal fields to multilingual
*
*/
function _copyToMultilingual()
{
$fields = Array ('Name', 'Description');
$primary_language = $this->Application->GetDefaultLanguageId();
$set_clause = Array ();
foreach ($fields as $field) {
$set_clause[] = 'l' . $primary_language . '_' . $field . ' = ' . $field;
}
$sql = 'UPDATE ' . TABLE_PREFIX . 'Link
SET ' . implode(', ', $set_clause);
$this->Conn->Query($sql);
}
/**
* Update to 5.0.1
*
* @param string $mode when called mode {before, after)
*/
function Upgrade_5_0_1($mode)
{
if ($mode == 'after') {
$this->_updateDetailTemplate('l', 'in-link/designs/detail', 'in-link/links/link_detail');
// delete old events
$events_to_delete = Array ( 'LINK.OWNER.MODIFY.PENDING', 'LINK.OWNER.MODIFY' );
$sql = 'SELECT EventId FROM ' . TABLE_PREFIX . 'Events
WHERE Event IN ("' . implode('","', $events_to_delete) . '")';
$event_ids = $this->Conn->GetCol($sql);
if ($event_ids) {
$sql = 'DELETE FROM ' . TABLE_PREFIX . 'EmailMessage
WHERE EventId IN (' . implode(',', $event_ids) . ')';
$this->Conn->Query($sql);
$sql = 'DELETE FROM ' . TABLE_PREFIX . 'Events
WHERE EventId IN (' . implode(',', $event_ids) . ')';
$this->Conn->Query($sql);
$sql = 'DELETE FROM ' . TABLE_PREFIX . 'Phrase
WHERE Phrase IN ("la_event_link.owner.modify", "la_event_link.owner.modify.pending")';
$this->Conn->Query($sql);
}
}
}
/**
* Update to 5.0.4-B1
*
* @param string $mode when called mode {before, after)
*/
function Upgrade_5_0_4_B1($mode)
{
if ($mode == 'after') {
// check in-link custom fields if need to add to search config
$custom_fields = Array (
'LinkAddress' => "('CustomField', 'LinkAddress', 1, 1, 'la_fld_LinkAddress', 'lu_fld_LinkAddress', 'In-Link', 'la_section_BusinessLocation', 1, DEFAULT, 0, 'text', NULL, NULL, NULL, NULL, NULL, NULL, {CUSTOM_FIELD_ID})",
'LinkCity' => "('CustomField', 'LinkCity', 1, 1, 'la_fld_LinkCity', 'lu_fld_LinkCity', 'In-Link', 'la_section_BusinessLocation', 2, DEFAULT, 0, 'text', NULL, NULL, NULL, NULL, NULL, NULL, {CUSTOM_FIELD_ID})",
'LinkState' => "('CustomField', 'LinkState', 1, 1, 'la_fld_LinkState', 'lu_fld_LinkState', 'In-Link', 'la_section_BusinessLocation', 3, DEFAULT, 0, 'select', NULL, NULL, NULL, NULL, NULL, NULL, {CUSTOM_FIELD_ID})",
'LinkZipCode' => "('CustomField', 'LinkZipCode', 1, 1, 'la_fld_LinkZipCode', 'lu_fld_LinkZipCode', 'In-Link', 'la_section_BusinessLocation', 4, DEFAULT, 0, 'text', NULL, NULL, NULL, NULL, NULL, NULL, {CUSTOM_FIELD_ID})",
'LinkCountry' => "('CustomField', 'LinkCountry', 1, 1, 'la_fld_LinkCountry', 'lu_fld_LinkCountry', 'In-Link', 'la_section_BusinessLocation', 5, DEFAULT, 0, 'select', NULL, NULL, NULL, NULL, NULL, NULL, {CUSTOM_FIELD_ID})",
'LinkPhone' => "('CustomField', 'LinkPhone', 1, 1, 'la_fld_LinkPhone', 'lu_fld_LinkPhone', 'In-Link', 'la_section_BusinessLocation', 6, DEFAULT, 0, 'text', NULL, NULL, NULL, NULL, NULL, NULL, {CUSTOM_FIELD_ID})",
);
// get all in-link custom fields ides at once
$sql = 'SELECT CustomFieldId, FieldName
FROM ' . TABLE_PREFIX . 'CustomField
WHERE Type = 4 AND IsSystem = 0';
$custom_field_ids = $this->Conn->GetCol($sql, 'FieldName');
foreach ($custom_fields as $field_name => $custom_field_sql) {
$sql = 'SELECT FieldName
FROM ' . TABLE_PREFIX . 'SearchConfig
WHERE (FieldName = ' . $this->Conn->qstr($field_name) . ') AND (LOWER(ModuleName) = "in-link")';
$found = $this->Conn->GetOne($sql);
if (!$found) {
// replace sql and insert new search config record
$sql = str_replace('{CUSTOM_FIELD_ID}', $custom_field_ids[$field_name], $custom_field_sql);
$sql = 'INSERT INTO ' . TABLE_PREFIX . 'SearchConfig VALUES ' . $sql;
$this->Conn->Query($sql);
}
}
}
}
}
\ No newline at end of file
Index: branches/5.2.x/install/upgrades.sql
===================================================================
--- branches/5.2.x/install/upgrades.sql (revision 15213)
+++ branches/5.2.x/install/upgrades.sql (revision 15214)
@@ -1,189 +1,191 @@
# ===== v 4.3.9 =====
INSERT INTO Events VALUES (DEFAULT, 'LINK.VALIDATION.RESULTS', NULL, 1, 0, 'In-Link', 'la_event_link.validation.results', 1);
INSERT INTO ImportScripts VALUES (DEFAULT, 'Links from CSV file [In-Link]', '', 'l', 'In-Link', '', 'CSV', '1');
UPDATE CustomField
SET ValueList = '=+||<SQL>SELECT DestAbbr AS OptionValue, DestName AS OptionName FROM <PREFIX>StdDestinations WHERE DestType = 2 AND (DestParentId = 225 OR DestParentId = 38) ORDER BY DestParentId DESC, DestAbbr ASC</SQL>'
WHERE FieldName = 'LinkState';
UPDATE CustomField
SET ValueList = '=+||<SQL>SELECT DestAbbr AS OptionValue, DestName AS OptionName FROM <PREFIX>StdDestinations WHERE DestType = 1 ORDER BY DestAbbr ASC</SQL>'
WHERE FieldName = 'LinkCountry';
# ===== v 5.0.0 =====
INSERT INTO Counters VALUES (DEFAULT, 'linkhits_count', 'SELECT ROUND(SUM(Hits)) FROM <%PREFIX%>Link', NULL, NULL, '300', '0', '|Link|');
UPDATE Category SET Template = '/in-link/designs/section' WHERE Template = 'inlink/index';
UPDATE Category SET CachedTemplate = '/in-link/designs/section' WHERE CachedTemplate = 'inlink/index';
UPDATE ConfigurationValues SET VariableValue = '/in-link/designs/section' WHERE VariableName = 'l_CategoryTemplate';
UPDATE ConfigurationValues SET VariableValue = 'in-link/designs/detail' WHERE VariableName = 'l_ItemTemplate';
INSERT INTO Permissions VALUES (DEFAULT, 'in-link:links.view', 11, 1, 1, 0);
INSERT INTO Permissions VALUES (DEFAULT, 'in-link:setting_folder.view', 11, 1, 1, 0);
DELETE FROM Permissions WHERE Permission LIKE 'in-link:inlink_general.%';
UPDATE Events SET Description = 'la_event_link.owner.modify' WHERE Description = 'la_event_link.modify.modify';
UPDATE Events SET Description = 'la_event_link.owner.modify.pending' WHERE Description = 'la_event_link.modify.modify.pending';
UPDATE Phrase SET Module = 'In-Link' WHERE ((Phrase LIKE '%Links%' OR Phrase LIKE '%Listing%') AND (Module = 'Core') AND Phrase NOT IN ('la_section_QuickLinks'));
UPDATE Phrase SET Module = 'In-Link', PhraseType = 1 WHERE ( (Phrase LIKE '%Validation%' OR Phrase LIKE 'la_title_In-Link') AND (Module = 'Core') AND Phrase NOT IN ('la_ValidationEmail', 'la_prompt_validation'));
# ===== v 5.0.1 =====
UPDATE ConfigurationValues SET VariableValue = 'in-link/links/link_detail' WHERE VariableName = 'l_ItemTemplate';
UPDATE ConfigurationAdmin SET ValueList = 'ReviewText=la_opt_CommentText,CreatedOn=la_opt_CreatedOn'
WHERE VariableName IN ('Link_ReviewsSort', 'Link_ReviewsSort2');
UPDATE ConfigurationAdmin SET ValueList = 'ASC=la_common_Ascending,DESC=la_common_Descending'
WHERE VariableName IN ('Link_ReviewsOrder', 'Link_ReviewsOrder2');
UPDATE ConfigurationAdmin SET ValueList = 'Name=la_Link_Name,Description=la_Link_Description,Url=la_Link_URL,CreatedOn=la_opt_CreatedOn,Hits=la_Link_Hits,CachedRating=la_opt_Rating,<SQL>SELECT Prompt AS OptionName, CONCAT("cust_", FieldName) AS OptionValue FROM <PREFIX>CustomField WHERE (Type = 4) AND (IsSystem = 0)</SQL>'
WHERE VariableName IN ('Link_SortField', 'Link_SortField2');
UPDATE ConfigurationAdmin
SET ValueList = '1=la_opt_Sec,60=la_opt_Min,3600=la_opt_Hour,86400=la_opt_Day,604800=la_opt_Week,2419200=la_opt_Month,29030400=la_opt_Year'
WHERE VariableName IN ('link_ReviewDelay_Interval', 'link_RatingDelay_Interval');
UPDATE CustomField SET FieldLabel = 'la_fld_cust_l_ItemTemplate', Prompt = 'la_fld_cust_l_ItemTemplate' WHERE FieldName = 'l_ItemTemplate';
INSERT INTO Events VALUES(DEFAULT, 'LINK.REVIEW.ADD.PENDING', NULL, 1, 0, NULL, 'In-Link', 'la_event_link.review.add.pending', 1);
UPDATE ConfigurationAdmin SET ValueList = 'style="width: 50px;"' WHERE VariableName IN ('link_ReviewDelay_Value', 'link_RatingDelay_Value');
# ===== v 5.0.2-B1 =====
ALTER TABLE ListingTypes CHANGE Description Description text NULL;
ALTER TABLE LinkValidation CHANGE ValidationTime ValidationTime INT NULL DEFAULT NULL;
ALTER TABLE LinkVisits CHANGE VisitTimestamp VisitTimestamp INT(11) NULL DEFAULT NULL;
# ===== v 5.0.2-B2 =====
# ===== v 5.0.2-RC1 =====
# ===== v 5.0.2 =====
# ===== v 5.0.3-B1 =====
UPDATE Phrase
SET Module = 'In-Link'
WHERE Phrase IN (
'lu_PermName_Link.Add.Pending_desc', 'lu_PermName_Link.Add_desc', 'lu_PermName_Link.Delete_desc',
'lu_PermName_Link.Modify.Pending_desc', 'lu_PermName_Link.Modify_desc', 'lu_PermName_Link.Owner.Delete_desc',
'lu_PermName_Link.Owner.Modify.Pending_desc', 'lu_PermName_Link.Owner.Modify_desc', 'lu_PermName_Link.Rate_desc',
'lu_PermName_Link.Review_Pending_desc', 'lu_PermName_Link.View_desc'
);
# ===== v 5.0.3-B2 =====
# ===== v 5.0.3-RC1 =====
# ===== v 5.0.3 =====
# ===== v 5.0.4-B1 =====
# ===== v 5.0.4-B2 =====
# ===== v 5.0.4 =====
# ===== v 5.1.0-B1 =====
UPDATE Modules SET Path = 'modules/in-link/' WHERE `Name` = 'In-Link';
DELETE FROM ConfigurationValues WHERE VariableName IN ('StartValidationTime', 'LastExpirationTime', 'Link_Root');
UPDATE CustomField
SET ValueList = '=+||<SQL+>SELECT IsoCode AS OptionValue, l%3$s_Name AS OptionName FROM <PREFIX>CountryStates WHERE Type = 2 ORDER BY StateCountryId DESC, IsoCode ASC</SQL>'
WHERE ValueList = '=+||<SQL>SELECT DestAbbr AS OptionValue, DestName AS OptionName FROM <PREFIX>StdDestinations WHERE DestType = 2 AND (DestParentId = 225 OR DestParentId = 38) ORDER BY DestParentId DESC, DestAbbr ASC</SQL>';
UPDATE CustomField
SET ValueList = '=+||<SQL+>SELECT IsoCode AS OptionValue, l%3$s_Name AS OptionName FROM <PREFIX>CountryStates WHERE Type = 1 ORDER BY IsoCode ASC</SQL>'
WHERE ValueList = '=+||<SQL>SELECT DestAbbr AS OptionValue, DestName AS OptionName FROM <PREFIX>StdDestinations WHERE DestType = 1 ORDER BY DestAbbr ASC</SQL>';
DELETE FROM Permissions WHERE Permission LIKE 'in-link:configuration_email%';
# ===== v 5.1.0-RC1 =====
# ===== v 5.1.0 =====
# ===== v 5.1.1-B1 =====
ALTER TABLE Link
CHANGE CreatedById CreatedById INT(11) NULL DEFAULT NULL ,
CHANGE ModifiedById ModifiedById INT(11) NULL DEFAULT NULL;
# ===== v 5.1.1-B2 =====
UPDATE Events
SET l<%PRIMARY_LANGUAGE%>_Body = REPLACE(l<%PRIMARY_LANGUAGE%>_Body, '<inp2:<inp2:', '<inp2:')
WHERE Event LIKE 'LINK.ADD.PENDING' AND `Type` = 1;
# ===== v 5.1.1-RC1 =====
# ===== v 5.1.1 =====
# ===== v 5.1.2-B1 =====
# ===== v 5.1.2-RC1 =====
# ===== v 5.1.2 =====
# ===== v 5.1.3-B1 =====
# ===== v 5.1.3-RC1 =====
UPDATE ConfigurationValues
SET VariableValue = 'in-link/links/link_detail'
WHERE VariableName = 'l_ItemTemplate' AND VariableValue = 'in-link/designs/detail';
# ===== v 5.1.3-RC2 =====
# ===== v 5.1.3 =====
UPDATE Phrase
SET `Module` = 'Core'
WHERE PhraseKey IN ('LA_FLD_LISTINGID', 'LA_FLD_LISTINGTYPE');
# ===== v 5.2.0-B1 =====
UPDATE SearchConfig
SET ForeignField = 'PortalUser.Username'
WHERE ForeignField = 'PortalUser.Login' AND ModuleName = 'In-Link';
UPDATE SearchConfig
SET DisplayName = REPLACE(DisplayName, 'lu_', 'lc_')
WHERE DisplayName IN ('lu_field_linkid', 'lu_field_url');
UPDATE SystemSettings
SET Section = 'in-portal:configure_advanced', ModuleOwner = 'In-Portal', Heading = 'la_section_Settings3rdPartyAPI', DisplayOrder = 80.02
WHERE VariableName = 'l_GoogleMapsAPIKey';
UPDATE SystemSettings
SET DisplayOrder = DisplayOrder - 0.01
WHERE VariableName IN ('l_EnableLinkContactForm', 'ReciprocalLinkChecking');
UPDATE LanguageLabels
SET Module = 'In-Link'
WHERE PhraseKey IN ('LA_LINK_CREATEDON', 'LA_LINK_DESCRIPTION', 'LA_LINK_HITS', 'LA_LINK_NAME', 'LA_LINK_URL');
DELETE FROM LanguageLabels
WHERE PhraseKey IN (
'LA_LINK_URLSTATUS_PROMPT', 'LA_TEXT_LINK_SEARCH', 'LA_LINK_CATCHEDRATING',
'LA_LINK_CATCHEDREVIEWSQTY', 'LA_LINK_CATCHEDVOTESQTY'
);
DELETE FROM SystemSettings
WHERE VariableName IN (
'Link_Highlight_OpenTag', 'Link_Highlight_CloseTag', 'Link_RatingToPop', 'Link_UrlStatus',
'Search_Link_CatchedRating', 'Search_Link_CatchedReviewsQty', 'Search_Link_CatchedVotesQty',
'Search_Link_CreatedOn', 'Search_Link_Description', 'Search_Link_EditorsPick', 'Search_Link_Hits',
'Search_Link_HotItem', 'Search_Link_LinkId', 'Search_Link_Name', 'Search_Link_NewItem', 'Search_Link_PopItem',
'Search_Link_Priority', 'Search_Link_ResourceId', 'Search_Link_ReviewById', 'Search_Link_Status', 'Search_Link_Url'
);
UPDATE SystemSettings
SET DisplayOrder = DisplayOrder - 0.01
WHERE VariableName IN (
'link_ReviewDelay_Value', 'link_ReviewDelay_Interval', 'link_RatingDelay_Value', 'link_RatingDelay_Interval',
'l_MaxCategories', 'l_EnableGoogleMaps', 'l_EnableLinkContactForm', 'ReciprocalLinkChecking'
);
UPDATE SearchConfig
SET ForeignField = 'Users.Username'
WHERE ForeignField = 'PortalUser.Username' AND ModuleName = 'In-Link';
# ===== v 5.2.0-B2 =====
UPDATE Link main_table
SET main_table.CachedReviewsQty = (SELECT COUNT(*) FROM <%TABLE_PREFIX%>CatalogReviews review_table WHERE review_table.ItemId = main_table.ResourceId);
+
+# ===== v 5.2.0-B3 =====

Event Timeline