Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Tue, Sep 23, 6:07 AM

in-portal

Index: trunk/kernel/units/general/helpers/filenames_helper.php
===================================================================
--- trunk/kernel/units/general/helpers/filenames_helper.php (revision 5508)
+++ trunk/kernel/units/general/helpers/filenames_helper.php (revision 5509)
@@ -1,81 +1,90 @@
<?php
class kFilenamesHelper extends kHelper {
/**
* replace not allowed symbols with "_" chars + remove duplicate "_" chars in result
*
* @param string $string
* @return string
*/
function stripDisallowed($table, $id_field, $item_id, $filename)
{
$not_allowed = Array( ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', '`',
'~', '!', '@', '#', '$', '%', '^', '&', '(', ')', '~',
'+', '=', '-', '{', '}', ']', '[', "'", ';', '.', ',');
$filename = str_replace($not_allowed, '_', $filename);
$filename = preg_replace('/(_+)/', '_', $filename);
$filename = $this->checkAutoFilename($table, $id_field, $item_id, $filename);
return $filename;
}
function checkAutoFilename($table, $id_field, $item_id, $filename)
{
if(!$filename) return $filename;
$item_id = !$item_id ? 0 : $item_id;
if ($table == TABLE_PREFIX.'CategoryItems') {
- $table = $this->Application->IsTempTable($table) ? $this->Application->GetLiveName($table) : $table;
- $item_tmp_categories = $this->Conn->GetCol('SELECT CategoryId FROM '.$this->Application->GetTempName($table).' WHERE ItemResourceId = '.$item_id);
- $item_live_categories = $this->Conn->GetCol('SELECT CategoryId FROM '.$table.' WHERE ItemResourceId = '.$item_id);
- $item_categories = array_unique(array_merge($item_tmp_categories, $item_live_categories));
+ $item_categories_cur = $this->Conn->GetCol('SELECT CategoryId FROM '.$table.' WHERE ItemResourceId = '.$item_id);
+ $item_categories_live = $this->Application->IsTempTable($table) ? $this->Conn->GetCol('SELECT CategoryId FROM '.$this->Application->GetLiveName($table).' WHERE ItemResourceId = '.$item_id) : array();
+
+ $item_categories = array_unique(array_merge($item_categories_cur, $item_categories_live));
if (!$item_categories) {
$item_categories = array($this->Application->GetVar('m_cat_id')); // this may happen when creating new item
}
$cat_filter = ' AND CategoryId IN ('.implode(',', $item_categories).')';
}
else {
$cat_filter = '';
}
- // check temp table
+ // check current table (temp or live)
$sql_temp = 'SELECT '.$id_field.' FROM '.$table.' WHERE Filename = '.$this->Conn->qstr($filename).$cat_filter;
$found_temp_ids = $this->Conn->GetCol($sql_temp);
- // check live table
- $sql_live = 'SELECT '.$id_field.' FROM '.$this->Application->GetLiveName($table).' WHERE Filename = '.$this->Conn->qstr($filename).$cat_filter;
- $found_live_ids = $this->Conn->GetCol($sql_live);
+ // check live table if current is temp
+ if ( $this->Application->IsTempTable($table) ) {
+ $sql_live = 'SELECT '.$id_field.' FROM '.$this->Application->GetLiveName($table).' WHERE Filename = '.$this->Conn->qstr($filename).$cat_filter;
+ $found_live_ids = $this->Conn->GetCol($sql_live);
+ }
+ else {
+ $found_live_ids = array();
+ }
$found_item_ids = array_unique( array_merge($found_temp_ids, $found_live_ids) );
$has_page = preg_match('/(.*)_([\d]+)([a-z]*)$/', $filename, $rets);
$duplicates_found = (count($found_item_ids) > 1) || ($found_item_ids && $found_item_ids[0] != $item_id);
if ($duplicates_found || $has_page) // other category has same filename as ours OR we have filename, that ends with _number
{
$append = $duplicates_found ? '_a' : '';
if($has_page)
{
$filename = $rets[1].'_'.$rets[2];
$append = $rets[3] ? $rets[3] : '_a';
}
// check live & temp table
- $sql_temp = 'SELECT '.$id_field.' FROM '.$table.' WHERE (Filename = %s) AND ('.$id_field.' != '.$item_id.')'.$cat_filter;
- $sql_live = 'SELECT '.$id_field.' FROM '.$this->Application->GetLiveName($table).' WHERE (Filename = %s) AND ('.$id_field.' != '.$item_id.')'.$cat_filter;
- while ( $this->Conn->GetOne( sprintf($sql_temp, $this->Conn->qstr($filename.$append)) ) > 0 ||
- $this->Conn->GetOne( sprintf($sql_live, $this->Conn->qstr($filename.$append)) ) > 0 )
+ $sql_cur = 'SELECT '.$id_field.' FROM '.$table.' WHERE (Filename = %s) AND ('.$id_field.' != '.$item_id.')'.$cat_filter;
+ $sql_live = $this->Application->IsTempTable($table) ? 'SELECT '.$id_field.' FROM '.$this->Application->GetLiveName($table).' WHERE (Filename = %s) AND ('.$id_field.' != '.$item_id.')'.$cat_filter : false;
+ while ( $this->Conn->GetOne( sprintf($sql_cur, $this->Conn->qstr($filename.$append)) ) > 0 ||
+ ( $sql_live
+ &&
+ ( $this->Conn->GetOne( sprintf($sql_live, $this->Conn->qstr($filename.$append)) ) > 0 )
+ )
+ )
{
if (substr($append, -1) == 'z') $append .= 'a';
$append = substr($append, 0, strlen($append) - 1) . chr( ord( substr($append, -1) ) + 1 );
}
return $filename.$append;
}
return $filename;
}
}
\ No newline at end of file
Property changes on: trunk/kernel/units/general/helpers/filenames_helper.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.1
\ No newline at end of property
+1.2
\ No newline at end of property
Index: trunk/core/units/general/helpers/filenames_helper.php
===================================================================
--- trunk/core/units/general/helpers/filenames_helper.php (revision 5508)
+++ trunk/core/units/general/helpers/filenames_helper.php (revision 5509)
@@ -1,81 +1,90 @@
<?php
class kFilenamesHelper extends kHelper {
/**
* replace not allowed symbols with "_" chars + remove duplicate "_" chars in result
*
* @param string $string
* @return string
*/
function stripDisallowed($table, $id_field, $item_id, $filename)
{
$not_allowed = Array( ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', '`',
'~', '!', '@', '#', '$', '%', '^', '&', '(', ')', '~',
'+', '=', '-', '{', '}', ']', '[', "'", ';', '.', ',');
$filename = str_replace($not_allowed, '_', $filename);
$filename = preg_replace('/(_+)/', '_', $filename);
$filename = $this->checkAutoFilename($table, $id_field, $item_id, $filename);
return $filename;
}
function checkAutoFilename($table, $id_field, $item_id, $filename)
{
if(!$filename) return $filename;
$item_id = !$item_id ? 0 : $item_id;
if ($table == TABLE_PREFIX.'CategoryItems') {
- $table = $this->Application->IsTempTable($table) ? $this->Application->GetLiveName($table) : $table;
- $item_tmp_categories = $this->Conn->GetCol('SELECT CategoryId FROM '.$this->Application->GetTempName($table).' WHERE ItemResourceId = '.$item_id);
- $item_live_categories = $this->Conn->GetCol('SELECT CategoryId FROM '.$table.' WHERE ItemResourceId = '.$item_id);
- $item_categories = array_unique(array_merge($item_tmp_categories, $item_live_categories));
+ $item_categories_cur = $this->Conn->GetCol('SELECT CategoryId FROM '.$table.' WHERE ItemResourceId = '.$item_id);
+ $item_categories_live = $this->Application->IsTempTable($table) ? $this->Conn->GetCol('SELECT CategoryId FROM '.$this->Application->GetLiveName($table).' WHERE ItemResourceId = '.$item_id) : array();
+
+ $item_categories = array_unique(array_merge($item_categories_cur, $item_categories_live));
if (!$item_categories) {
$item_categories = array($this->Application->GetVar('m_cat_id')); // this may happen when creating new item
}
$cat_filter = ' AND CategoryId IN ('.implode(',', $item_categories).')';
}
else {
$cat_filter = '';
}
- // check temp table
+ // check current table (temp or live)
$sql_temp = 'SELECT '.$id_field.' FROM '.$table.' WHERE Filename = '.$this->Conn->qstr($filename).$cat_filter;
$found_temp_ids = $this->Conn->GetCol($sql_temp);
- // check live table
- $sql_live = 'SELECT '.$id_field.' FROM '.$this->Application->GetLiveName($table).' WHERE Filename = '.$this->Conn->qstr($filename).$cat_filter;
- $found_live_ids = $this->Conn->GetCol($sql_live);
+ // check live table if current is temp
+ if ( $this->Application->IsTempTable($table) ) {
+ $sql_live = 'SELECT '.$id_field.' FROM '.$this->Application->GetLiveName($table).' WHERE Filename = '.$this->Conn->qstr($filename).$cat_filter;
+ $found_live_ids = $this->Conn->GetCol($sql_live);
+ }
+ else {
+ $found_live_ids = array();
+ }
$found_item_ids = array_unique( array_merge($found_temp_ids, $found_live_ids) );
$has_page = preg_match('/(.*)_([\d]+)([a-z]*)$/', $filename, $rets);
$duplicates_found = (count($found_item_ids) > 1) || ($found_item_ids && $found_item_ids[0] != $item_id);
if ($duplicates_found || $has_page) // other category has same filename as ours OR we have filename, that ends with _number
{
$append = $duplicates_found ? '_a' : '';
if($has_page)
{
$filename = $rets[1].'_'.$rets[2];
$append = $rets[3] ? $rets[3] : '_a';
}
// check live & temp table
- $sql_temp = 'SELECT '.$id_field.' FROM '.$table.' WHERE (Filename = %s) AND ('.$id_field.' != '.$item_id.')'.$cat_filter;
- $sql_live = 'SELECT '.$id_field.' FROM '.$this->Application->GetLiveName($table).' WHERE (Filename = %s) AND ('.$id_field.' != '.$item_id.')'.$cat_filter;
- while ( $this->Conn->GetOne( sprintf($sql_temp, $this->Conn->qstr($filename.$append)) ) > 0 ||
- $this->Conn->GetOne( sprintf($sql_live, $this->Conn->qstr($filename.$append)) ) > 0 )
+ $sql_cur = 'SELECT '.$id_field.' FROM '.$table.' WHERE (Filename = %s) AND ('.$id_field.' != '.$item_id.')'.$cat_filter;
+ $sql_live = $this->Application->IsTempTable($table) ? 'SELECT '.$id_field.' FROM '.$this->Application->GetLiveName($table).' WHERE (Filename = %s) AND ('.$id_field.' != '.$item_id.')'.$cat_filter : false;
+ while ( $this->Conn->GetOne( sprintf($sql_cur, $this->Conn->qstr($filename.$append)) ) > 0 ||
+ ( $sql_live
+ &&
+ ( $this->Conn->GetOne( sprintf($sql_live, $this->Conn->qstr($filename.$append)) ) > 0 )
+ )
+ )
{
if (substr($append, -1) == 'z') $append .= 'a';
$append = substr($append, 0, strlen($append) - 1) . chr( ord( substr($append, -1) ) + 1 );
}
return $filename.$append;
}
return $filename;
}
}
\ No newline at end of file
Property changes on: trunk/core/units/general/helpers/filenames_helper.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.1
\ No newline at end of property
+1.2
\ No newline at end of property

Event Timeline