Page MenuHomeIn-Portal Phabricator

skin_eh.php
No OneTemporary

File Metadata

Created
Sun, Oct 12, 2:49 PM

skin_eh.php

<?php
/**
* @version $Id: skin_eh.php 16513 2017-01-20 14:10:53Z alex $
* @package In-Portal
* @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 SkinEventHandler 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);
}
/**
* With "primary" special loads primary skin
*
* @param kEvent $event
* @return int
* @access public
*/
public function getPassedID(kEvent $event)
{
if ( $event->Special == 'primary' ) {
return Array ('IsPrimary' => 1);
}
return parent::getPassedID($event);
}
/**
* Allows to set selected theme as primary
*
* @param kEvent $event
*/
function OnSetPrimary($event)
{
if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) {
$event->status = kEvent::erFAIL;
return;
}
$ids = $this->StoreSelectedIDs($event);
if ($ids) {
$id = array_shift($ids);
$this->setPrimary($id);
}
$this->clearSelectedIDs($event);
}
function setPrimary($id)
{
$id_field = $this->Application->getUnitOption($this->Prefix, 'IDField');
$table_name = $this->Application->getUnitOption($this->Prefix, 'TableName');
$sql = 'UPDATE '.$table_name.'
SET IsPrimary = 0';
$this->Conn->Query($sql);
$sql = 'UPDATE '.$table_name.'
SET IsPrimary = 1
WHERE '.$id_field.' = '.$id;
$this->Conn->Query($sql);
}
/**
* Don't make cloned skin primary
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnBeforeClone(kEvent $event)
{
parent::OnBeforeClone($event);
/** @var kDBItem $object */
$object = $event->getObject();
$object->SetDBField('IsPrimary', 0);
}
/**
* Re-compile skin, after it's changed (live table only)
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnAfterItemUpdate(kEvent $event)
{
parent::OnAfterItemUpdate($event);
/** @var kDBItem $object */
$object = $event->getObject();
if ( !$object->IsTempTable() ) {
/** @var SkinHelper $skin_helper */
$skin_helper = $this->Application->recallObject('SkinHelper');
$skin_helper->compile($object);
}
}
/**
* [HOOK] Compile stylesheet file based on theme definitions
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnCompileStylesheet($event)
{
/** @var kDBItem $object */
$object = $event->getObject( Array ('skip_autoload' => true) );
$object->SwitchToLive();
$ids = $event->MasterEvent->getEventParam('ids');
if ( !is_array($ids) ) {
$ids = explode(',', $ids);
}
if ( !$ids ) {
return ;
}
/** @var SkinHelper $skin_helper */
$skin_helper = $this->Application->recallObject('SkinHelper');
foreach ($ids as $id) {
$object->Load($id);
$skin_helper->compile($object);
}
}
}

Event Timeline