Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Wed, Feb 12, 10:15 AM

in-portal

Index: branches/RC/core/units/fck/fck_tp.php
===================================================================
--- branches/RC/core/units/fck/fck_tp.php (revision 11848)
+++ branches/RC/core/units/fck/fck_tp.php (revision 11849)
@@ -1,121 +1,121 @@
<?php
class FckTagProcessor extends kDBTagProcessor {
-
-
+
+
function ReadFolders($files_dir)
{
$aFolders = array();
$oCurrentFolder = opendir($files_dir) ;
- $KernelSystemFolders = defined('KERNEL_SYSTEM_FOLDERS') ? KERNEL_SYSTEM_FOLDERS : array('icons','CVS');
+ $KernelSystemFolders = defined('KERNEL_SYSTEM_FOLDERS') ? KERNEL_SYSTEM_FOLDERS : array('icons', 'CVS', '.svn');
while ( $sFile = readdir( $oCurrentFolder ) )
{
if (is_dir($files_dir . $sFile ) && !in_array($sFile,$KernelSystemFolders) && $sFile != '.' && $sFile != '..') {
$aFolders[] = $sFile;
}
}
- closedir( $oCurrentFolder ) ;
+ closedir( $oCurrentFolder ) ;
return $aFolders;
}
-
+
function ReadFiles($files_dir)
{
$aFiles = array();
$oCurrentFolder = opendir($files_dir) ;
-// $KernelSystemFolders = defined('KERNEL_SYSTEM_FOLDERS') ? KERNEL_SYSTEM_FOLDERS : array('icons','CVS');
+// $KernelSystemFolders = defined('KERNEL_SYSTEM_FOLDERS') ? KERNEL_SYSTEM_FOLDERS : array('icons', 'CVS', '.svn');
while ( $sFile = readdir( $oCurrentFolder ) )
{
if (!is_dir($files_dir . $sFile )) {
$aFiles[] = $sFile;
}
}
- closedir( $oCurrentFolder ) ;
+ closedir( $oCurrentFolder ) ;
return $aFiles;
}
-
+
function CheckCreateDefaultFolders()
{
$user_files_dir = WRITEABLE."/user_files/";
$FCKDefaultFolders = defined('FCK_DEFAULT_FOLDERS') ? FCK_DEFAULT_FOLDERS : array('Files','Images','Flash','Documents');
$ret = '';
$aFolders = $this->ReadFolders($user_files_dir);
$fck_helper =& $this->Application->recallObject('FCKHelper');
/* @var fck_helper fckFCKHelper*/
-
+
foreach ($FCKDefaultFolders as $k=>$v)
{
if (!in_array($v,$aFolders)) {
if ($fck_helper->CreateFolder($v)) {
- $aFolders[] = $v;
+ $aFolders[] = $v;
}
}
}
-
+
if (count($aFolders) > 0) {
natcasesort($aFolders);
foreach($aFolders AS $k=>$v) {
$selected = ($this->Application->GetVar('type') == $v) ? 'selected' : '';
$ret.= '<option value="' . $v . '" '.$selected.' />' . $v ;
}
}
return $ret;
}
-
+
function PrintFolders($params)
{
$order_by = $this->Application->GetVar('order_by');
$sort_by = $this->Application->GetVar('sort_by');
$params['folder'] = $this->Application->GetVar('folder');
$files_dir = WRITEABLE."/user_files/".$params['folder']."/";
$aFolders = $this->ReadFolders($files_dir);
$block_params = $this->prepareTagParams($params);
$block_params['name'] = $block_params['render_as'];
$ret = '';
foreach ($aFolders as $k => $v) {
$block_params['folder_name'] = $v;
$block_params['path'] = $params['folder']."/".$v;
$ret .= $this->Application->ParseBlock($block_params);
}
return $ret;
}
-
+
function PrintFiles($params)
{
$params['folder'] = $this->Application->GetVar('folder');
$files_dir = WRITEABLE."/user_files/".$params['folder']."/";
$files_url = BASE_PATH.WRITEBALE_BASE."/user_files/".$params['folder']."/";
$aFiles = $this->ReadFiles($files_dir);
$block_params = $this->prepareTagParams($params);
$block_params['name'] = $block_params['render_as'];
$ret = '';
$date_format = "m/d/Y h:i A";
$a_ext = 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');
foreach ($aFiles as $k => $v) {
$size = filesize( $files_dir . $v ) ;
if ( $size > 0 ) {
$size = round( $size / 1024 );
$size = ($size < 1)? 1:$size;// round( $iFileSize / 1024 ) ;
- }
-
+ }
+
eregi("(\.[a-zA-Z0-9]{1,10})$", $v, $regs);
$ext = strtolower(ltrim($regs[1],"."));
if (in_array($ext, $a_ext))
{
$icon = $ext;
} else {
$icon = 'default.icon';
}
-
+
$block_params['file_name'] = $v;
$block_params['size'] = $size;
$block_params['url'] = $files_url.$v;
$block_params['icon'] = $icon;
$block_params['date'] = date($date_format, filectime( $files_dir . $v ));
// $block_params['path'] = $params['folder']."/".$v;
$ret .= $this->Application->ParseBlock($block_params);
}
return $ret;
- }
-
-
- }
+ }
+
+
+ }
Index: branches/RC/core/units/general/helpers/fck_helper.php
===================================================================
--- branches/RC/core/units/general/helpers/fck_helper.php (revision 11848)
+++ branches/RC/core/units/general/helpers/fck_helper.php (revision 11849)
@@ -1,276 +1,276 @@
<?php
class fckFCKHelper extends kHelper {
-
+
var $Config = Array();
-
- function fckFCKHelper()
+
+ function fckFCKHelper()
{
parent::kHelper();
-
+
$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['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');
-
+
}
function CreateFolder($folder = '')
{
if (!$folder) return false;
$folderPath = WRITEABLE.'/user_files/'.$folder;
if (file_exists($folderPath) && is_dir($folderPath)) return false;
-
+
$permissions = defined(FCK_FOLDERS_PERMISSIONS) ? FCK_FOLDERS_PERMISSIONS : '0777';
- mkdir( $folderPath) ; // , $permissions
+ mkdir( $folderPath) ; // , $permissions
return true;
}
-
- function IsAllowedExtension($folder, $file_name)
+
+ function IsAllowedExtension($folder, $file_name)
{
$base_folder = $this->getBaseFolder($folder);
eregi("(\.[a-zA-Z0-9]{1,10})$", $file_name, $regs);
$ext = strtolower(ltrim($regs[1],"."));
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;
}
-
- function getBaseFolder($folder)
+
+ function getBaseFolder($folder)
{
$end = strpos("/", $folder);
if ($end) {
return substr($folder, 0, $end);
}
return $folder;
}
function ReadFolders($files_dir)
{
$aFolders = array();
$oCurrentFolder = opendir($files_dir) ;
- $KernelSystemFolders = defined('KERNEL_SYSTEM_FOLDERS') ? KERNEL_SYSTEM_FOLDERS : array('icons','CVS');
+ $KernelSystemFolders = defined('KERNEL_SYSTEM_FOLDERS') ? KERNEL_SYSTEM_FOLDERS : array('icons', 'CVS', '.svn');
while ( $sFile = readdir( $oCurrentFolder ) )
{
if (is_dir($files_dir . $sFile ) && !in_array($sFile,$KernelSystemFolders) && $sFile != '.' && $sFile != '..') {
$aFolders[] = $sFile;
}
}
- closedir( $oCurrentFolder ) ;
+ closedir( $oCurrentFolder ) ;
return $aFolders;
}
-
-
+
+
function ReadFiles($files_dir)
{
$aFiles = array();
$oCurrentFolder = opendir($files_dir) ;
while ( $sFile = readdir( $oCurrentFolder ) )
{
if (!is_dir($files_dir . $sFile )) {
$aFiles[] = $sFile;
}
}
- closedir( $oCurrentFolder ) ;
+ closedir( $oCurrentFolder ) ;
return $aFiles;
}
-
+
function PrintFolders()
{
$order_by = $this->Application->GetVar('order_by');
$sort_by = $this->Application->GetVar('sort_by');
$folder = $this->Application->GetVar('folder');
$files_dir = WRITEABLE."/user_files/".$folder."/";
$aFolders = $this->ReadFolders($files_dir);
$ret = '';
$order_by = $this->Application->GetVar('order_by');
$sort_by = $this->Application->GetVar('sort_by');
natcasesort($aFolders);
foreach ($aFolders as $k => $v) {
$ret .= '<folder2 path="'.$folder."/".$v.'">'.$v.'</folder2>'."\n";
}
if ($sort_by == 'name' && $order_by == '_desc') {
$aFolders = array_reverse($aFolders);
}
foreach ($aFolders as $k => $v) {
$ret .= '<folder path="'.$folder."/".$v.'">'.$v.'</folder>'."\n";
}
return $ret;
}
-
+
function CalculateFileSize($size)
{
if ( $size > 0 ) {
$size = round( $size / 1024 );
$size = ($size < 1)? 1:$size;// round( $iFileSize / 1024 ) ;
- }
+ }
return $size;
}
-
+
function CheckIconType($v)
{
$a_ext = 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');
eregi("(\.[a-zA-Z0-9]{1,10})$", $v, $regs);
$ext = strtolower(ltrim($regs[1],"."));
if (in_array($ext, $a_ext))
{
$icon = $ext;
} else {
$icon = 'default.icon';
}
return $icon;
}
-
+
function GetXmlString($size,$url,$icon,$date,$file_name)
{
return '<file size="'.$size.'" url="'.$url.'" icon="'.$icon.'" date="'.$date.'">'.$file_name.'</file>'."\n";
}
-
+
function PrintFiles()
{
$order_by = $this->Application->GetVar('order_by');
$sort_by = $this->Application->GetVar('sort_by');
$folder = $this->Application->GetVar('folder');
$files_dir = WRITEABLE."/user_files/".$folder."/";
$files_url = BASE_PATH.WRITEBALE_BASE."/user_files/".$folder."/";
$aFiles = $this->ReadFiles($files_dir);
$ret = '';
$date_format = "m/d/Y h:i A";
natcasesort($aFiles);
if ($sort_by == 'name' && $order_by == '_desc') {
$aFiles = array_reverse($aFiles,TRUE);
}
-
- foreach ($aFiles as $k => $v)
+
+ foreach ($aFiles as $k => $v)
{
$aFilesSize[$k] = filesize( $files_dir . $v);
$aFilesDate[$k] = filectime( $files_dir . $v);
}
if ($sort_by == 'name') {
foreach ($aFiles as $k => $file) {
- $size = $this->CalculateFileSize($aFilesSize[$k]);
+ $size = $this->CalculateFileSize($aFilesSize[$k]);
$date = date($date_format, $aFilesDate[$k]);
$icon = $this->CheckIconType($file);
$ret .= $this->GetXmlString($size,$files_url.$file,$icon,$date,$file);
}
}
if ($sort_by == 'date') {
asort($aFilesDate);
if($order_by == '_desc') {
$aFilesDate = array_reverse($aFilesDate,TRUE);
}
foreach ($aFilesDate as $k => $date) {
$size = $this->CalculateFileSize($aFilesSize[$k]);
- $file = $aFiles[$k];
+ $file = $aFiles[$k];
$date = date($date_format, $date);
$icon = $this->CheckIconType($file);
$ret .= $this->GetXmlString($size,$files_url.$file,$icon,$date,$file);
}
}
if ($sort_by == 'size') {
asort($aFilesSize);
if($order_by == '_desc') {
$aFilesSize = array_reverse($aFilesSize,TRUE);
}
foreach ($aFilesSize as $k => $size) {
$size = $this->CalculateFileSize($size);
- $file = $aFiles[$k];
+ $file = $aFiles[$k];
$date = date($date_format, $aFilesDate[$k]);
$icon = $this->CheckIconType($file);
$ret .= $this->GetXmlString($size,$files_url.$file,$icon,$date,$file);
}
}
return $ret;
- }
-
+ }
+
function UploadFile()
{
$Extensions['Allowed']['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') ;
$Extensions['Allowed']['Images'] = array('jpg','gif','jpeg','png', 'bmp') ;
$Extensions['Allowed']['Flash'] = array('swf','fla') ;
$Extensions['Allowed']['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') ;
$Extensions['Allowed']['Documents'] = array('doc','pdf','ppt','rdp','swf','swt','txt','vsd','xls','csv','zip','odt') ;
-
+
$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,$Extensions['Allowed'][$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, '.' ) ) ;
}
-
+
}
\ No newline at end of file
Index: branches/RC/core/units/general/helpers/themes_helper.php
===================================================================
--- branches/RC/core/units/general/helpers/themes_helper.php (revision 11848)
+++ branches/RC/core/units/general/helpers/themes_helper.php (revision 11849)
@@ -1,378 +1,381 @@
<?php
class kThemesHelper extends kHelper {
/**
* Where all themes are located
*
* @var string
*/
var $themesFolder = '';
/**
* List of theme names, found on system
*
* @var Array
*/
var $_themeNames = Array ();
/**
* Temporary array when all theme files from db are stored
*
* @var Array
*/
var $themeFiles = Array ();
function kThemesHelper()
{
parent::kHelper();
$this->themesFolder = FULL_PATH.'/themes';
}
/**
* Updates file system changes to database for selected theme
*
* @param string $theme_name
*
* @return mixed returns ID of created/used theme or false, if none created
*/
function refreshTheme($theme_name)
{
if (!file_exists($this->themesFolder . '/' . $theme_name)) {
// requested theme was not found on hdd
return false;
}
$id_field = $this->Application->getUnitOption('theme', 'IDField');
$table_name = $this->Application->getUnitOption('theme', 'TableName');
$sql = 'SELECT ' . $id_field . ', Enabled
FROM ' . $table_name . '
WHERE Name = ' . $this->Conn->qstr($theme_name);
$theme_info = $this->Conn->GetRow($sql);
if ($theme_info) {
$theme_id = $theme_info[$id_field];
$theme_enabled = $theme_info['Enabled'];
}
else {
$theme_id = $theme_enabled = false;
}
$this->themeFiles = Array ();
if ($theme_id) {
if (!$theme_enabled) {
// don't process existing theme files, that are disabled
return $theme_id;
}
// reset found mark for every themes file (if theme is not new)
$sql = 'UPDATE '.TABLE_PREFIX.'ThemeFiles
SET FileFound = 0
WHERE ThemeId = '.$theme_id;
$this->Conn->Query($sql);
// get all theme files from db
$sql = 'SELECT FileId, CONCAT(FilePath, "/", FileName) AS FullPath
FROM '.TABLE_PREFIX.'ThemeFiles
WHERE ThemeId = '.$theme_id;
$this->themeFiles = $this->Conn->GetCol($sql, 'FullPath');
}
else {
// theme was not found in db, but found on hdd -> create new
$fields_hash = Array (
'Name' => $theme_name,
'Enabled' => 0,
'Description' => $theme_name,
'PrimaryTheme' => 0,
'CacheTimeout' => 3600, // not in use right now
'StylesheetId' => 0, // not in use right now
);
$this->Conn->doInsert($fields_hash, $table_name);
$theme_id = $this->Conn->getInsertID();
if (!$theme_enabled) {
// don't process newly created theme files, because they are disabled
return $theme_id;
}
}
$this->_themeNames[$theme_id] = $theme_name;
$theme_path = $this->themesFolder.'/'.$theme_name;
$this->FindThemeFiles('', $theme_path, $theme_id); // search from base theme directory
// delete file records from db, that were not found on hdd
$sql = 'DELETE FROM '.TABLE_PREFIX.'ThemeFiles
WHERE ThemeId = '.$theme_id.' AND FileFound = 0';
$this->Conn->Query($sql);
return $theme_id;
}
/**
* Searches for new templates (missing in db) in spefied folder
*
* @param string $folder_path subfolder of searchable theme
* @param string $theme_path theme path from web server root
* @param int $theme_id id of theme we are scanning
*/
function FindThemeFiles($folder_path, $theme_path, $theme_id, $auto_structure_mode = 1)
{
$fh = opendir($theme_path.$folder_path.'/');
// always ingore design and element templates
$ignore = Array ('^CVS$', '^\.svn$', '\.des\.tpl$', '\.elm\.tpl$');
$sms_ingore = $theme_path . $folder_path . '/.smsignore';
if (file_exists($sms_ingore)) {
$ignore = array_merge($ignore, file($sms_ingore));
}
while (($filename = readdir($fh))) {
if ($filename == '.' || $filename == '..') continue;
$auto_structure = $auto_structure_mode;
foreach ($ignore as $pattern) {
if (preg_match('/'.str_replace('/', '\\/', trim($pattern)).'/', $filename)) {
$auto_structure = 2;
break;
}
}
$full_path = $theme_path.$folder_path.'/'.$filename;
if (is_dir($full_path)) {
$this->FindThemeFiles($folder_path.'/'.$filename, $theme_path, $theme_id, $auto_structure);
}
elseif (substr($filename, -4) == '.tpl') {
$file_path = $folder_path.'/'.$filename;
$meta_info = $this->_getTemplateMetaInfo(trim($file_path, '/'), $theme_id);
$file_id = isset($this->themeFiles[$file_path]) ? $this->themeFiles[$file_path] : false;
$file_description = array_key_exists('desc', $meta_info) ? $meta_info['desc'] : '';
if ($file_id) {
// file was found in db & on hdd -> mark as existing
$fields_hash = Array (
'FileFound' => 1,
'Description' => $file_description,
'FileType' => $auto_structure,
'FileMetaInfo' => serialize($meta_info),
);
$this->Conn->doUpdate($fields_hash, TABLE_PREFIX . 'ThemeFiles', 'FileId = ' . $file_id);
}
else {
// file was found on hdd, but missing in db -> create new file record
$fields_hash = Array (
'ThemeId' => $theme_id,
'FileName' => $filename,
'FilePath' => $folder_path,
'Description' => $file_description,
'FileType' => $auto_structure, // 1 - built-in, 0 - custom (not in use right now), 2 - skipped in structure
'FileMetaInfo' => serialize($meta_info),
'FileFound' => 1,
);
$this->Conn->doInsert($fields_hash, TABLE_PREFIX.'ThemeFiles');
$this->themeFiles[$file_path] = $this->Conn->getInsertID();
}
// echo 'FilePath: [<strong>'.$folder_path.'</strong>]; FileName: [<strong>'.$filename.'</strong>]; IsNew: [<strong>'.($file_id > 0 ? 'NO' : 'YES').'</strong>]<br />';
}
}
}
/**
* Returns template information (name, description, path) from it's header comment
*
* @param string $template
* @param int $theme_id
* @return Array
*/
function _getTemplateMetaInfo($template, $theme_id)
{
static $init_made = false;
if (!$init_made) {
$this->Application->InitParser(true);
$init_made = true;
}
$template = 'theme:' . $this->_themeNames[$theme_id] . '/' . $template;
$template_file = $this->Application->TemplatesCache->GetRealFilename($template); // ".tpl" was added before
return $this->parseTemplateMetaInfo($template_file);
}
function parseTemplateMetaInfo($template_file)
{
if (!file_exists($template_file)) {
// when template without info it's placed in top category
return Array ();
}
$template_data = file_get_contents($template_file);
if (substr($template_data, 0, 6) == '<!--##') {
// template starts with comment in such format
/*<!--##
<NAME></NAME>
<DESC></DESC>
<SECTION>||</SECTION>
##-->*/
$comment_end = strpos($template_data, '##-->');
if ($comment_end === false) {
// badly formatted comment
return Array ();
}
$comment = trim( substr($template_data, 6, $comment_end - 6) );
if (preg_match_all('/<(NAME|DESC|SECTION)>(.*?)<\/(NAME|DESC|SECTION)>/is', $comment, $regs)) {
$ret = Array ();
foreach ($regs[1] as $param_order => $param_name) {
$ret[ strtolower($param_name) ] = trim($regs[2][$param_order]);
}
if (array_key_exists('section', $ret) && $ret['section']) {
$category_path = explode('||', $ret['section']);
$category_path = array_map('trim', $category_path);
$ret['section'] = implode('||', $category_path);
}
return $ret;
}
}
return Array ();
}
/**
* Updates file system changes to database for all themes (including new ones)
*
*/
function refreshThemes()
{
$themes_found = Array();
+ $skip_filenames = Array ('.', '..', 'CVS', '.svn');
$fh = opendir($this->themesFolder.'/');
while (($filename = readdir($fh))) {
- if ($filename == '.' || $filename == '..' || $filename == 'CVS') continue;
+ if (in_array($filename, $skip_filenames)) {
+ continue;
+ }
if (is_dir($this->themesFolder.'/'.$filename)) {
$theme_id = $this->refreshTheme($filename);
if ($theme_id) {
$themes_found[] = $theme_id;
}
}
}
$id_field = $this->Application->getUnitOption('theme', 'IDField');
$table_name = $this->Application->getUnitOption('theme', 'TableName');
// 1. only one theme found -> enable it and make primary
/*if (count($themes_found) == 1) {
$sql = 'UPDATE ' . $table_name . '
SET Enabled = 1, PrimaryTheme = 1
WHERE ' . $id_field . ' = ' . current($themes_found);
$this->Conn->Query($sql);
}*/
// 2. if none themes found -> delete all from db OR delete all except of found themes
$sql = 'SELECT '.$id_field.'
FROM '.$table_name;
if ($themes_found) {
$sql .= ' WHERE '.$id_field.' NOT IN ('.implode(',', $themes_found).')';
}
$theme_ids = $this->Conn->GetCol($sql);
$this->deleteThemes($theme_ids);
}
/**
* Deletes themes with ids passed from db
*
* @param Array $theme_ids
*/
function deleteThemes($theme_ids)
{
if (!$theme_ids) {
return ;
}
$id_field = $this->Application->getUnitOption('theme', 'IDField');
$table_name = $this->Application->getUnitOption('theme', 'TableName');
$sql = 'DELETE FROM '.$table_name.'
WHERE '.$id_field.' IN ('.implode(',', $theme_ids).')';
$this->Conn->Query($sql);
$sql = 'DELETE FROM '.TABLE_PREFIX.'ThemeFiles
WHERE '.$id_field.' IN ('.implode(',', $theme_ids).')';
$this->Conn->Query($sql);
}
/**
* Returns current theme (also works in admin)
*
* @return int
*/
function getCurrentThemeId()
{
static $theme_id = null;
if (isset($theme_id)) {
return $theme_id;
}
if ($this->Application->IsAdmin()) {
// get theme, that user selected in catalog
$theme_id = $this->Application->RecallVar('theme_id');
if ($theme_id === false) {
// query, because "m_theme" is always empty in admin
$id_field = $this->Application->getUnitOption('theme', 'IDField');
$table_name = $this->Application->getUnitOption('theme', 'TableName');
$sql = 'SELECT ' . $id_field . '
FROM ' . $table_name . '
WHERE (PrimaryTheme = 1) AND (Enabled = 1)';
$theme_id = $this->Conn->GetOne($sql);
}
return $theme_id;
}
// use current theme, because it's available on Front-End
$theme_id = $this->Application->GetVar('m_theme');
if (!$theme_id) {
// happens in mod-rewrite mode, then requested template is not found
$theme_id = $this->Application->GetDefaultThemeId();
}
return $theme_id;
}
/**
* Returns page id based on given template
*
* @param string $template
* @return int
*/
function getPageByTemplate($template)
{
$sql = 'SELECT ' . $this->Application->getUnitOption('c', 'IDField') . '
FROM ' . $this->Application->getUnitOption('c', 'TableName') . '
WHERE
(
(NamedParentPath = ' . $this->Conn->qstr('Content/' . $template) . ') OR
(IsSystem = 1 AND CachedTemplate = ' . $this->Conn->qstr($template) . ')
)
AND (ThemeId = ' . $this->getCurrentThemeId() . ' OR ThemeId = 0)';
return $this->Conn->GetOne($sql);
}
}
?>
\ No newline at end of file

Event Timeline