Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Mon, Jan 6, 5:09 AM

in-portal

Index: branches/5.2.x/core/units/skins/skins_config.php
===================================================================
--- branches/5.2.x/core/units/skins/skins_config.php (revision 15557)
+++ branches/5.2.x/core/units/skins/skins_config.php (revision 15558)
@@ -1,183 +1,183 @@
<?php
/**
* @version $Id$
* @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!');
$config = Array(
'Prefix' => 'skin',
'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'),
'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'),
'EventHandlerClass' => Array('class'=>'SkinEventHandler','file'=>'skin_eh.php','build_event'=>'OnBuild'),
'TagProcessorClass' => Array('class'=>'kDBTagProcessor','file'=>'','build_event'=>'OnBuild'),
'AutoLoad' => true,
'Hooks' => Array(
Array(
'Mode' => hAFTER,
'Conditional' => false,
'HookToPrefix' => 'skin',
'HookToSpecial' => '',
'HookToEvent' => Array('OnSave'),
'DoPrefix' => '',
'DoSpecial' => '',
'DoEvent' => 'OnCompileStylesheet',
),
),
'QueryString' => Array(
1 => 'id',
2 => 'Page',
3 => 'PerPage',
4 => 'event',
5 => 'mode',
),
'IDField' => 'SkinId',
'StatusField' => Array('IsPrimary'),
'TableName' => TABLE_PREFIX.'AdminSkins',
/*
'ForeignKey' => 'ParentId', // field title in TableName, linking record to a parent
'ParentTableKey' => 'ParentId', // id (or other key) field title in parent's table
'ParentPrefix' => 'parent',
'AutoDelete' => true, // delete these items when parent is being deleted
'AutoClone' => true, // clone these items when parent is being cloned
*/
'TitlePresets' => Array(
'default' => Array(
'new_status_labels' => Array('skin'=>'!la_title_AddingSkin!'),
'edit_status_labels' => Array('skin'=>'!la_title_EditingSkin!'),
'new_titlefield' => Array('skin'=>''),
),
'skin_list'=>Array(
'prefixes' => Array('skin_List'),
'format' => '!la_tab_Skins!',
'toolbar_buttons' => Array ('new_item', 'edit', 'delete', 'setprimary', 'clone', 'view', 'dbl-click'),
),
'skin_edit'=>Array(
'prefixes' => Array('skin'),
'format' => '#skin_status# #skin_titlefield#',
'toolbar_buttons' => Array ('select', 'cancel', 'reset_edit', 'prev', 'next'),
),
),
'PermSection' => Array('main' => 'in-portal:skins'),
// don't forget to add corresponding permissions to install script
// INSERT INTO Permissions VALUES (0, 'custom:custom.view', 11, 1, 1, 0);
// INSERT INTO Permissions VALUES (0, 'in-portal:skins.view', 11, 1, 1, 0), (0, 'in-portal:skins.add', 11, 1, 1, 0), (0, 'in-portal:skins.edit', 11, 1, 1, 0), (0, 'in-portal:skins.delete', 11, 1, 1, 0);
'Sections' => Array(
'in-portal:skins' => Array(
'parent' => 'in-portal:tools',
'icon' => 'admin_skins',
'label' => 'la_tab_Skins',
'url' => Array('t' => 'skins/skin_list', 'pass' => 'm'),
'permissions' => Array('view', 'add', 'edit', 'delete'),
'priority' => 7,
// 'show_mode' => smSUPER_ADMIN,
'type' => stTREE,
),
),
'TitleField' => 'Name', // field, used in bluebar when editing existing item
// Use %1$s for local table name with prefix, %2$s for calculated fields
'ListSQLs' => Array( // key - special, value - list select sql
'' => 'SELECT %1$s.* %2$s
FROM %1$s',
),
'ItemSQLs' => Array(
'' => 'SELECT %1$s.* %2$s
FROM %1$s',
),
'ListSortings' => Array(
'' => Array(
// 'ForcedSorting' => Array('Priority' => 'desc'),
'Sorting' => Array('Name' => 'asc'),
)
),
'Fields' => Array (
'SkinId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
'Name' => Array ('type' => 'string', 'max_len' => 255, 'required' => 1, 'default' => NULL),
'CSS' => Array ('type' => 'string', 'default' => NULL),
'Logo' => Array(
'type'=>'string', 'formatter'=>'kUploadFormatter',
'max_size'=>MAX_UPLOAD_SIZE, // in Bytes !
- 'file_types'=>'*.jpg;*.gif;*.png', 'files_description'=>'!la_hint_ImageFiles!',
+ 'file_types'=>'*.jpg;*.jpeg;*.gif;*.png;*.bmp', 'files_description'=>'!la_hint_ImageFiles!',
'upload_dir' => WRITEBALE_BASE . '/user_files/', // relative to project's home
'thumb_format' => 'resize:100x100',
'multiple'=>false, // false or max number of files - will be stored as serialized array of paths
'direct_links'=>false, // use direct file urls or send files through wrapper (requires mod_mime_magic)
'default' => null,
),
'LogoBottom' => Array(
'type'=>'string', 'formatter'=>'kUploadFormatter',
'max_size'=>MAX_UPLOAD_SIZE, // in Bytes !
- 'file_types'=>'*.jpg;*.gif;*.png', 'files_description'=>'!la_hint_ImageFiles!',
+ 'file_types'=>'*.jpg;*.jpeg;*.gif;*.png;*.bmp', 'files_description'=>'!la_hint_ImageFiles!',
'upload_dir' => WRITEBALE_BASE . '/user_files/', // relative to project's home
'thumb_format' => 'resize:100x100',
'multiple'=>false, // false or max number of files - will be stored as serialized array of paths
'direct_links'=>false, // use direct file urls or send files through wrapper (requires mod_mime_magic)
'not_null' => 1, 'default' => '',
),
'LogoLogin' => Array(
'type'=>'string', 'formatter'=>'kUploadFormatter',
'max_size'=>MAX_UPLOAD_SIZE, // in Bytes !
- 'file_types'=>'*.jpg;*.gif;*.png', 'files_description'=>'!la_hint_ImageFiles!',
+ 'file_types'=>'*.jpg;*.jpeg;*.gif;*.png;*.bmp', 'files_description'=>'!la_hint_ImageFiles!',
'upload_dir' => WRITEBALE_BASE . '/user_files/', // relative to project's home
'thumb_format' => 'resize:100x100',
'multiple'=>false, // false or max number of files - will be stored as serialized array of paths
'direct_links'=>false, // use direct file urls or send files through wrapper (requires mod_mime_magic)
'not_null' => 1, 'default' => '',
),
'Options' => Array(
'type' => 'string', 'default' => NULL,
'formatter' => 'kSerializedFormatter',
'default'=>serialize(
array(
'HeadBgColor' => array('Description'=>'Head frame background color', 'Value'=>'#1961B8'),
'HeadColor' => array('Description'=>'Head frame text color', 'Value'=>'#000000'),
'SectionBgColor' => array('Description'=>'Section bar background color', 'Value'=>'#2D79D6'),
'SectionColor' => array('Description'=>'Section bar text color', 'Value'=>'#000000'),
)
),
),
'LastCompiled' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
'IsPrimary' => Array(
'type' => 'int', 'formatter' => 'kOptionsFormatter',
'options' => Array(1 => 'la_Yes', 0 => 'la_No'), 'use_phrases' => 1,
'not_null' => 1, 'default' => 0
),
'DisplaySiteNameInHeader' => Array (
'type' => 'int', 'formatter' => 'kOptionsFormatter',
'options' => Array (1 => 'la_Yes', 0 => 'la_No'), 'use_phrases' => 1,
'not_null' => 1, 'default' => 1
),
),
'Grids' => Array(
'Default' => Array(
'Icons' => Array(
'default' => 'icon16_item.png',
1 => 'icon16_primary.png',
),
'Fields' => Array(
'SkinId' => Array ('title' => 'column:la_fld_Id', 'data_block' => 'grid_checkbox_td', 'filter_block' => 'grid_range_filter', 'width' => 50, ),
'Name' => Array ('title' => 'column:la_fld_SkinName', 'filter_block' => 'grid_like_filter', 'width' => 200, ),
'IsPrimary' => Array ('filter_block' => 'grid_options_filter', 'width' => 100),
),
),
),
);
\ No newline at end of file
Index: branches/5.2.x/core/units/promo_blocks/promo_block_eh.php
===================================================================
--- branches/5.2.x/core/units/promo_blocks/promo_block_eh.php (revision 15557)
+++ branches/5.2.x/core/units/promo_blocks/promo_block_eh.php (revision 15558)
@@ -1,351 +1,351 @@
<?php
/**
* @version $Id$
* @package In-Portal
* @copyright Copyright (C) 1997 - 2011 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 PromoBlockEventHandler extends kDBEventHandler {
/**
* Define alternative event processing method names
*
* @return void
* @see kEventHandler::$eventMethods
* @access protected
*/
protected function mapEvents()
{
parent::mapEvents();
$events_map = Array (
'OnMassMoveUp' => 'OnChangePriority',
'OnMassMoveDown' => 'OnChangePriority',
);
$this->eventMethods = array_merge($this->eventMethods, $events_map);
}
/**
* Allows to override standard permission mapping
*
* @return void
* @access protected
* @see kEventHandler::$permMapping
*/
protected function mapPermissions()
{
parent::mapPermissions();
$permissions = Array (
'OnItemBuild' => Array ('self' => true),
'OnSetSticky' => Array ('self' => 'view'),
'OnRegisterView' => Array ('self' => true),
'OnFollowLink' => Array ('self' => true),
'OnResetCounters' => Array ('self' => 'add|edit'),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
}
/**
* Sets default value for promo block group
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnPreCreate(kEvent $event)
{
parent::OnPreCreate($event);
$object = $event->getObject();
/* @var $object kDBItem */
$promo_block_group = $this->Application->recallObject('promo-block-group');
/* @var $promo_block_group kDBItem */
$object->SetDBField('PromoBlockGroupId', $promo_block_group->GetID());
}
/**
* Processes OnMassMoveUp, OnMassMoveDown events
*
* @param kEvent $event
*/
function OnChangePriority($event)
{
$this->Application->SetVar('priority_prefix', $event->getPrefixSpecial());
$event->CallSubEvent('priority:' . $event->Name);
}
/**
* 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->isAdmin ) {
$promo_block_group = $this->Application->recallObject('promo-block-group');
/* @var $promo_block_group kDBItem */
$object->addFilter('promo_group_filter', '%1$s.PromoBlockGroupId = ' . $promo_block_group->GetID());
return;
}
$group_id = $event->getEventParam('group_id');
if ( !$group_id ) {
$page = $this->Application->recallObject('st');
/* @var $page CategoriesItem */
$group_id = $page->GetDBField('PromoBlockGroupId');
}
$object->addFilter('status_filter', '%1$s.Status = ' . STATUS_ACTIVE);
$object->addFilter('scheduled_from_filter', '%1$s.ScheduleFromDate IS NULL OR %1$s.ScheduleFromDate <= ' . TIMENOW);
$object->addFilter('scheduled_to_filter', '%1$s.ScheduleToDate IS NULL OR %1$s.ScheduleToDate >= ' . TIMENOW);
$object->addFilter('promo_group_filter', $group_id ? '%1$s.PromoBlockGroupId = ' . $group_id : 'FALSE');
}
/**
* Set's block as sticky
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnSetSticky(kEvent $event)
{
$object = $event->getObject( Array('skip_autoload' => true) );
/* @var $object kDBItem */
$ids = $this->StoreSelectedIDs($event);
if ( $ids ) {
$id = array_shift($ids);
$sql = 'UPDATE ' . $object->TableName . '
SET Sticky = 0';
$this->Conn->Query($sql);
$sql = 'UPDATE ' . $object->TableName . '
SET Sticky = 1, Status = ' . STATUS_ACTIVE . '
WHERE BlockId = ' . $id;
$this->Conn->Query($sql);
}
$this->clearSelectedIDs($event);
}
/**
* Set Required fields
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnBeforeItemCreate(kEvent $event)
{
parent::OnBeforeItemCreate($event);
$this->_itemChanged($event);
}
/**
* Set Required fields
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnBeforeItemUpdate(kEvent $event)
{
parent::OnBeforeItemUpdate($event);
$this->_itemChanged($event);
}
/**
* Schedule dates
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function _itemChanged(kEvent $event)
{
$object = $event->getObject();
/* @var $object kDBItem */
$date_from = $object->GetDBField('ScheduleFromDate_date');
$date_to = $object->GetDBField('ScheduleToDate_date');
if ( $date_from && $date_to && $date_from >= $date_to ) {
$object->SetError('ScheduleFromDate_date', 'wrong_date_interval');
}
$object->setRequired('CategoryId', $object->GetDBField('LinkType') == PromoBlockType::INTERNAL);
$object->setRequired('ExternalLink', $object->GetDBField('LinkType') == PromoBlockType::EXTERNAL);
}
/**
* Registers view of the promo block
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnRegisterView(kEvent $event)
{
$this->_incrementField($event, 'NumberOfViews');
}
/**
* Registers click on the promo block
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnFollowLink(kEvent $event)
{
$object = $event->getObject();
/* @var $object kDBItem */
$this->_incrementField($event, 'NumberOfClicks', false);
if ( $object->GetDBField('LinkType') == 1 ) { // Internal
$sql = 'SELECT NamedParentPath
FROM ' . TABLE_PREFIX . 'Categories
WHERE CategoryId = ' . $object->GetDBField('CategoryId');
$event->redirect = $this->Conn->GetOne($sql);
$event->SetRedirectParam('pass', 'm');
}
else {
$ext_url = $object->GetDBField('ExternalLink');
$event->redirect = 'external:' . (preg_match('/^(http|ftp):\\/\\/.*/', $ext_url) ? $ext_url : $this->Application->BaseURL() . $ext_url);
}
}
/**
* Increment given promo block counters
*
* @param kEvent $event
* @param string $field
* @param bool $is_ajax
* @return void
* @access protected
*/
protected function _incrementField(kEvent $event, $field, $is_ajax = true)
{
if ( $is_ajax ) {
$event->status = kEvent::erSTOP;
if ( $this->Application->GetVar('ajax') != 'yes' ) {
return ;
}
}
$object = $event->getObject();
/* @var $object kDBItem */
if ( !$object->isLoaded() ) {
echo 'FAILED';
return ;
}
// don't use kDBItem::Update to support concurrent view updates from different visitors
$sql = 'UPDATE ' . $object->TableName . '
SET ' . $field . ' = ' . $field . ' + 1
WHERE ' . $object->IDField . ' = ' . $object->GetID();
$this->Conn->Query($sql);
echo 'OK';
}
/**
* Resets promo block counters
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnResetCounters(kEvent $event)
{
$object = $event->getObject( Array ('skip_autoload' => true) );
/* @var $object kDBItem */
$ids = $this->StoreSelectedIDs($event);
foreach ($ids as $id) {
$object->Load($id);
$object->SetDBField('NumberOfViews', 0);
$object->SetDBField('NumberOfClicks', 0);
$object->Update();
}
$this->clearSelectedIDs($event);
}
/**
* Occurs, when config was parsed, allows to change config data dynamically
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnAfterConfigRead(kEvent $event)
{
parent::OnAfterConfigRead($event);
$category_helper = $this->Application->recallObject('CategoryHelper');
/* @var $category_helper CategoryHelper */
$fields = $this->Application->getUnitOption($event->Prefix, 'Fields');
$fields['CategoryId']['options'] = $category_helper->getStructureTreeAsOptions();
// images multilang fields
$a_image = Array(
'type' => 'string', 'max_len' => 255,
'formatter' => 'kUploadFormatter', 'upload_dir' => IMAGES_PATH . 'promo_blocks/',
'multiple' => 1, 'thumb_format' => 'resize:100x100',
- 'file_types' => '*.jpg;*.gif;*.png', 'files_description' => '!la_hint_ImageFiles!',
+ 'file_types' => '*.jpg;*.jpeg;*.gif;*.png;*.bmp', 'files_description' => '!la_hint_ImageFiles!',
'not_null' => 1, 'default' => '',
);
// get active languages
$sql = 'SELECT LanguageId
FROM ' . TABLE_PREFIX . 'Languages';
$languages = $this->Conn->GetCol($sql);
foreach ($languages as $lang_id) {
$fields['l' . $lang_id . '_Image'] = $a_image;
}
$fields['l' . $this->Application->GetDefaultLanguageId() . '_Image']['required'] = 1;
$this->Application->setUnitOption($event->Prefix, 'Fields', $fields);
}
}
Index: branches/5.2.x/core/units/helpers/fck_helper.php
===================================================================
--- branches/5.2.x/core/units/helpers/fck_helper.php (revision 15557)
+++ branches/5.2.x/core/units/helpers/fck_helper.php (revision 15558)
@@ -1,411 +1,411 @@
<?php
/**
* @version $Id$
* @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 fckFCKHelper extends kHelper {
var $Config = Array();
/**
* Currently selected folder
*
* @var string
* @access protected
*/
protected $folder = '';
/**
* Current sorting field
*
* @var string
* @access protected
*/
protected $sortField = '';
/**
* Current sorting direction
*
* @var string
* @access protected
*/
protected $sortDirection = '';
public function __construct()
{
parent::__construct();
$this->folder = $this->Application->GetVar('folder');
$this->sortField = $this->Application->GetVar('sort_by');
$this->sortDirection = $this->Application->GetVar('order_by');
- $this->Config['AllowedExtensions']['Files'] = Array('jpg','gif','jpeg','png','swf','fla','jpg','gif','jpeg','png','avi','mpg','mpeg','zip','rar','arj','gz','tar','doc','pdf','ppt','rdp','swf','swt','txt','vsd','xls','csv','odt');
+ $this->Config['AllowedExtensions']['Files'] = Array('gif','jpeg','png','swf','fla','jpg','gif','jpeg','png','avi','mpg','mpeg','zip','rar','arj','gz','tar','doc','pdf','ppt','rdp','swf','swt','txt','vsd','xls','csv','odt');
$this->Config['DeniedExtensions']['Files'] = Array('php','asp','aspx','ascx','jsp','cfm','cfc','pl','bat','exe','dll','reg');
$this->Config['AllowedExtensions']['Images'] = Array('jpg','gif','jpeg','png', 'bmp');
$this->Config['DeniedExtensions']['Images'] = Array('php','asp','aspx','ascx','jsp','cfm','cfc','pl','bat','exe','dll','reg');
$this->Config['AllowedExtensions']['Flash'] = Array('swf','fla');
$this->Config['DeniedExtensions']['Flash'] = Array('php','asp','aspx','ascx','jsp','cfm','cfc','pl','bat','exe','dll','reg');
$this->Config['AllowedExtensions']['Media'] = Array('asf','asx','avi','wav','wax','wma','wm','wmv','m3u','mp2v','mpg','mpeg','m1v','mp2','mp3','mpa','mpe','mpv2','mp4','mid','midi','rmi','qt','aif','aifc','aiff','mov','flv','rm','svcd','swf','vcd');
$this->Config['DeniedExtensions']['Media'] = Array('php','asp','aspx','ascx','jsp','cfm','cfc','pl','bat','exe','dll','reg');
$this->Config['AllowedExtensions']['Documents'] = Array('doc','pdf','ppt','rdp','swf','swt','txt','vsd','xls','csv','zip','odt');
$this->Config['DeniedExtensions']['Documents'] = Array('php','asp','aspx','ascx','jsp','cfm','cfc','pl','bat','exe','dll','reg');
$this->Config['ExtensionIcons'] = Array('ai','avi','bmp','cs','dll','doc','exe','fla','gif','htm','html','jpg','js','mdb','mp3','pdf','png','ppt','rdp','swf','swt','txt','vsd','xls','xml','zip');
}
function CreateFolder($folder = '')
{
if ( !$folder ) {
return false;
}
$folderPath = WRITEABLE . '/user_files/' . $folder;
if ( file_exists($folderPath) && is_dir($folderPath) ) {
return true;
}
/*$permissions = defined('FCK_FOLDERS_PERMISSIONS') ? FCK_FOLDERS_PERMISSIONS : '0777';
return mkdir($folderPath, $permissions);*/
return mkdir($folderPath);
}
function IsAllowedExtension($folder, $file_name)
{
$ext = strtolower( pathinfo($file_name, PATHINFO_EXTENSION) );
if ( isset($this->Config['DeniedExtensions'][$folder]) ) {
if ( in_array($ext, $this->Config['DeniedExtensions'][$folder]) ) {
return false;
}
}
if ( isset($this->Config['AllowedExtensions'][$folder]) ) {
if ( !in_array($ext, $this->Config['AllowedExtensions'][$folder]) ) {
return false;
}
}
return true;
}
/**
* Returns list of sub-folders from given folder (automatically excludes system folders)
*
* @param string $files_dir
* @return Array
* @access public
*/
public function ReadFolders($files_dir)
{
$ret = Array ();
$system_folders = defined('KERNEL_SYSTEM_FOLDERS') ? KERNEL_SYSTEM_FOLDERS : Array ('icons', 'CVS', '.svn');
try {
$iterator = new DirectoryIterator($files_dir);
/* @var $file_info DirectoryIterator */
}
catch (UnexpectedValueException $e) {
return $ret;
}
foreach ($iterator as $file_info) {
$filename = $file_info->getFilename();
if ( $file_info->isDir() && !$file_info->isDot() ) {
$ret[] = $filename;
}
}
return array_diff($ret, $system_folders);
}
/**
* Returns list of files in given folder
*
* @param string $files_dir
* @return Array
* @access public
*/
public function ReadFiles($files_dir)
{
$ret = Array ();
try {
$iterator = new DirectoryIterator($files_dir);
/* @var $file_info DirectoryIterator */
}
catch (UnexpectedValueException $e) {
return $ret;
}
foreach ($iterator as $file_info) {
if ( !$file_info->isDir() ) {
$ret[] = $file_info->getFilename();
}
}
return $ret;
}
/**
* Returns xml containing list of folders in current folder
*
* @return string
* @access public
*/
public function PrintFolders()
{
$files_dir = WRITEABLE . '/user_files/' . $this->folder . '/';
$sub_folders = $this->ReadFolders($files_dir);
natcasesort($sub_folders);
$ret = $this->_buildFoldersXML($sub_folders, 'folder2');
if ( $this->sortField == 'name' && $this->sortDirection == '_desc' ) {
$sub_folders = array_reverse($sub_folders);
}
$ret .= $this->_buildFoldersXML($sub_folders, 'folder');
return $ret;
}
/**
* Build XML, that will output folders for FCKEditor
*
* @param Array $sub_folders
* @param string $xml_node
* @return string
*/
protected function _buildFoldersXML($sub_folders, $xml_node)
{
$ret = '';
foreach ($sub_folders as $sub_folder) {
$ret .= '<' . $xml_node . ' path="' . $this->folder . "/" . $sub_folder . '">' . $sub_folder . '</' . $xml_node . '>' . "\n";
}
return $ret;
}
/**
* Transforms filesize in bytes into kilobytes
*
* @param int $size
* @return int
* @access protected
*/
protected function CalculateFileSize($size)
{
if ( $size > 0 ) {
$size = round($size / 1024);
$size = ($size < 1) ? 1 : $size;
}
return $size;
}
/**
* Detects icon for given file extension
*
* @param string $file
* @return string
* @access protected
*/
protected function CheckIconType($file)
{
$ext = strtolower( pathinfo($file, PATHINFO_EXTENSION) );
return $ext && in_array($ext, $this->Config['ExtensionIcons']) ? $ext : 'default.icon';
}
/**
* Build one file xml node
*
* @param int $size
* @param string $url
* @param string $icon
* @param string $date
* @param string $file_name
* @return string
*/
protected function _buildFileXml($size,$url,$icon,$date,$file_name)
{
return '<file size="' . $size . '" url="' . $url . '" icon="' . $icon . '" date="' . $date . '">' . $file_name . '</file>' . "\n";
}
/**
* Returns xml containing list of files in current folder
*
* @return string
* @access public
*/
public function PrintFiles()
{
$files_dir = WRITEABLE . '/user_files/' . $this->folder . '/';
$files_url = BASE_PATH . str_replace(DIRECTORY_SEPARATOR, '/', WRITEBALE_BASE) . '/user_files/' . $this->folder . '/';
$aFiles = $this->ReadFiles($files_dir);
$ret = '';
$date_format = "m/d/Y h:i A";
natcasesort($aFiles);
if ( $this->sortField == 'name' && $this->sortDirection == '_desc' ) {
$aFiles = array_reverse($aFiles, TRUE);
}
$aFilesSize = $aFilesDate = Array ();
foreach ($aFiles as $k => $v) {
$aFilesSize[$k] = filesize($files_dir . $v);
$aFilesDate[$k] = filectime($files_dir . $v);
}
if ( $this->sortField == 'name' ) {
foreach ($aFiles as $k => $file) {
$size = $this->CalculateFileSize($aFilesSize[$k]);
$date = date($date_format, $aFilesDate[$k]);
$icon = $this->CheckIconType($file);
$ret .= $this->_buildFileXml($size, $files_url . $file, $icon, $date, $file);
}
}
if ( $this->sortField == 'date' ) {
asort($aFilesDate);
if ( $this->sortDirection == '_desc' ) {
$aFilesDate = array_reverse($aFilesDate, TRUE);
}
foreach ($aFilesDate as $k => $date) {
$size = $this->CalculateFileSize($aFilesSize[$k]);
$file = $aFiles[$k];
$date = date($date_format, $date);
$icon = $this->CheckIconType($file);
$ret .= $this->_buildFileXml($size, $files_url . $file, $icon, $date, $file);
}
}
if ( $this->sortField == 'size' ) {
asort($aFilesSize);
if ( $this->sortDirection == '_desc' ) {
$aFilesSize = array_reverse($aFilesSize, TRUE);
}
foreach ($aFilesSize as $k => $size) {
$size = $this->CalculateFileSize($size);
$file = $aFiles[$k];
$date = date($date_format, $aFilesDate[$k]);
$icon = $this->CheckIconType($file);
$ret .= $this->_buildFileXml($size, $files_url . $file, $icon, $date, $file);
}
}
return $ret;
}
function UploadFile()
{
$upload_dir = $this->Application->GetVar('upload_dir');
$type = explode('/', $upload_dir);
$type = $type[0];
$sServerDir = WRITEABLE . '/user_files/' . $upload_dir . '/';
$aUpFile = $_FILES['NewFile'];
$sFileName = $aUpFile['name'];
$sOriginalFileName = $aUpFile['name'];
$sExtension = strtolower(substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) );
$sErrorNumber = 0;
if ( isset( $_FILES['NewFile'] ) && !is_null( $_FILES['NewFile']['tmp_name'] ) )
{
if (in_array($sExtension, $this->Config['AllowedExtensions'][$type]))
{
if (!$aUpFile['error']) {
$iCounter = 0 ;
while ( true )
{
$sFilePath = $sServerDir . $sFileName;
if ( is_file( $sFilePath ) )
{
$iCounter++ ;
$sFileName = $this->RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension;
$sErrorNumber = '201';
}
else
{
// Turn off all error reporting.
error_reporting( 0 ) ;
// Enable error tracking to catch the error.
ini_set( 'track_errors', '1' );
move_uploaded_file( $aUpFile['tmp_name'], $sFilePath );
$sErrorMsg = $php_errormsg;
// Restore the configurations.
ini_restore( 'track_errors' );
ini_restore( 'error_reporting' );
if ( is_file( $sFilePath ) ) {
$oldumask = umask(0);
chmod( $sFilePath, 0666 );
umask( $oldumask );
}
break ;
}
}
}
}
else {
$sErrorNumber = '203';
}
}
else {
$sErrorNumber = '202' ;
}
echo '<script type="text/javascript">' ;
echo 'window.parent.frames["frmUpload"].OnUploadCompleted(' . $sErrorNumber . ',"' . str_replace( '"', '\\"', $sFileName ) . '") ;' ;
echo '</script>' ;
}
function RemoveExtension( $fileName )
{
return substr( $fileName, 0, strrpos( $fileName, '.' ) ) ;
}
/**
* Returns transit parameters, that should be passed to every used CKEditor instance
*
* @param Array $tag_params
* @return Array
*/
public function getTransitParams($tag_params = Array ())
{
$ret = Array ();
$transit_params = Array ('bgcolor' => '', 'body_class' => '', 'body_id' => '');
foreach ($transit_params as $param_name => $default_value) {
$param_value = isset($tag_params[$param_name]) ? $tag_params[$param_name] : $this->Application->GetVar($param_name);
if ( $param_value || $default_value ) {
$ret[$param_name] = $param_value ? $param_value : $default_value;
}
}
return $ret;
}
}
\ No newline at end of file

Event Timeline