[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [16354] table: Merge 16351:16353 from trunk
From: |
sigurdne |
Subject: |
[Fmsystem-commits] [16354] table: Merge 16351:16353 from trunk |
Date: |
Mon, 20 Feb 2017 15:44:48 -0500 (EST) |
Revision: 16354
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=16354
Author: sigurdne
Date: 2017-02-20 15:44:47 -0500 (Mon, 20 Feb 2017)
Log Message:
-----------
table: Merge 16351:16353 from trunk
Modified Paths:
--------------
branches/Version-2_0-branch/property/inc/class.uientity.inc.php
branches/Version-2_0-branch/property/inc/class.uiimport_components.inc.php
branches/Version-2_0-branch/property/inc/import/UploadHandler.php
branches/Version-2_0-branch/property/inc/import/class.import_component_files.inc.php
branches/Version-2_0-branch/property/inc/import/class.import_components.inc.php
branches/Version-2_0-branch/property/inc/import/class.import_entity_categories.inc.php
branches/Version-2_0-branch/property/inc/import/class.import_update_components.inc.php
Property Changed:
----------------
branches/Version-2_0-branch/
Index: branches/Version-2_0-branch
===================================================================
--- branches/Version-2_0-branch 2017-02-20 20:39:26 UTC (rev 16353)
+++ branches/Version-2_0-branch 2017-02-20 20:44:47 UTC (rev 16354)
Property changes on: branches/Version-2_0-branch
___________________________________________________________________
Modified: svn:mergeinfo
## -1,4 +1,4 ##
/branches/dev-syncromind:13653
/branches/dev-syncromind-2:14933-16300
/branches/stavangerkommune:12743-12875,12986
-/trunk:14721-14732,14734-14735,14737,14739,14741,14743-14744,14746-14749,14751,14753,14755-14757,14759,14761-14764,14766-14768,14770-14783,14785-14792,14794-14813,14815-14816,14818,14820-14822,14824-14825,14827-14829,14831-14834,14836,14838,14840-14842,14844-14845,14847,14849-14866,14868-14869,14871,14873-14875,14877-14878,14880-14884,14886-14896,14898,14900-14902,14904,14906-14909,14911-14915,14917-14919,14921-14922,14924-14978,14980-15258,15260-15261,15263-15264,15266-15285,15287-15288,15290-15291,15293,15295,15297,15299-15305,15307-15310,15312-15335,15337-15352,15354,15356,15358,15360-15541,15543-15566,15568-15569,15571,15573-15581,15583,15585-15617,15619,15621-15630,15632-15635,15637-15639,15641-15643,15645,15647-15665,15667-15668,15670-15671,15673-15693,15695-15712,15714-15764,15766-15767,15769-15787,15789-15802,15804-15811,15813-15814,15816-15818,15820-15849,15851-15887,15889-15900,15902-16046,16048-16051,16053,16055,16057-16063,16065-16071,16073-16077,16079-16081,16083-16099,16101-16130,16132-16140,16142,16144-16212,16214-16219,16221,16223-16224,16226,16228-16229,16231,16233,16235,16237,16239-16240,16242,16244-16246,16248,16250-16251,16253-16255,16257-16259,16261,16263,16265,16267,16269-16276,16278,16280-16283,16285,16287-16288,16290,16292-16295,16297-16305,16307-16314,16316-16318,16320-16322,16324,16326-16330,16332,16334,16336,16338-16339,16341-16342,16344,16346,16348,16350
\ No newline at end of property
+/trunk:14721-14732,14734-14735,14737,14739,14741,14743-14744,14746-14749,14751,14753,14755-14757,14759,14761-14764,14766-14768,14770-14783,14785-14792,14794-14813,14815-14816,14818,14820-14822,14824-14825,14827-14829,14831-14834,14836,14838,14840-14842,14844-14845,14847,14849-14866,14868-14869,14871,14873-14875,14877-14878,14880-14884,14886-14896,14898,14900-14902,14904,14906-14909,14911-14915,14917-14919,14921-14922,14924-14978,14980-15258,15260-15261,15263-15264,15266-15285,15287-15288,15290-15291,15293,15295,15297,15299-15305,15307-15310,15312-15335,15337-15352,15354,15356,15358,15360-15541,15543-15566,15568-15569,15571,15573-15581,15583,15585-15617,15619,15621-15630,15632-15635,15637-15639,15641-15643,15645,15647-15665,15667-15668,15670-15671,15673-15693,15695-15712,15714-15764,15766-15767,15769-15787,15789-15802,15804-15811,15813-15814,15816-15818,15820-15849,15851-15887,15889-15900,15902-16046,16048-16051,16053,16055,16057-16063,16065-16071,16073-16077,16079-16081,16083-16099,16101-16130,16132-16140,16142,16144-16212,16214-16219,16221,16223-16224,16226,16228-16229,16231,16233,16235,16237,16239-16240,16242,16244-16246,16248,16250-16251,16253-16255,16257-16259,16261,16263,16265,16267,16269-16276,16278,16280-16283,16285,16287-16288,16290,16292-16295,16297-16305,16307-16314,16316-16318,16320-16322,16324,16326-16330,16332,16334,16336,16338-16339,16341-16342,16344,16346,16348,16350,16352-16353
\ No newline at end of property
Modified: branches/Version-2_0-branch/property/inc/class.uientity.inc.php
===================================================================
--- branches/Version-2_0-branch/property/inc/class.uientity.inc.php
2017-02-20 20:39:26 UTC (rev 16353)
+++ branches/Version-2_0-branch/property/inc/class.uientity.inc.php
2017-02-20 20:44:47 UTC (rev 16354)
@@ -598,7 +598,7 @@
$doc_type = phpgw::get_var('doc_type', 'int');
$entity_id = phpgw::get_var('entity_id', 'int');
$cat_id = phpgw::get_var('cat_id', 'int');
- $num = phpgw::get_var('num');
+ $item_id = phpgw::get_var('item_id');
$location_id = phpgw::get_var('location_id', 'int');
$export = phpgw::get_var('export', 'bool');
$values = array();
@@ -614,7 +614,8 @@
'doc_type' => $doc_type,
'entity_id' => $entity_id,
'cat_id' => $cat_id,
- 'num' => $num
+ 'num' => $item_id,
+ 'location_item_id' => $item_id,
);
$document = CreateObject('property.sodocument');
@@ -2167,7 +2168,7 @@
(
'container' =>
'datatable-container_7',
'requestUrl' =>
json_encode(self::link(array('menuaction' => 'property.uientity.get_documents',
- 'location_id' =>
$location_id, 'entity_id' => $this->entity_id, 'cat_id' => $this->cat_id, 'num'
=> $values['num'], 'phpgw_return_as' => 'json'))),
+ 'location_id' =>
$location_id, 'entity_id' => $this->entity_id, 'cat_id' => $this->cat_id,
'item_id' => $id, 'phpgw_return_as' => 'json'))),
'data' => "",
'tabletools' => ($mode ==
'edit') ? $documents_tabletools : array(),
'ColumnDefs' => $documents_def,
Modified:
branches/Version-2_0-branch/property/inc/class.uiimport_components.inc.php
===================================================================
--- branches/Version-2_0-branch/property/inc/class.uiimport_components.inc.php
2017-02-20 20:39:26 UTC (rev 16353)
+++ branches/Version-2_0-branch/property/inc/class.uiimport_components.inc.php
2017-02-20 20:44:47 UTC (rev 16354)
@@ -26,10 +26,9 @@
* @subpackage logistic
* @version $Id: class.uigeneric_document.inc.php 14913 2016-04-11
12:27:37Z sigurdne $
*/
-
phpgw::import_class('phpgwapi.uicommon_jquery');
phpgw::import_class('phpgwapi.jquery');
-
+
include_class('property', 'import_entity_categories', 'inc/import/');
include_class('property', 'import_components', 'inc/import/');
include_class('property', 'import_component_files', 'inc/import/');
@@ -36,6 +35,7 @@
class property_uiimport_components extends phpgwapi_uicommon_jquery
{
+
var $type = 'entity';
private $receipt = array();
protected $type_app = array
@@ -43,7 +43,6 @@
'entity' => 'property',
'catch' => 'catch'
);
-
public $public_functions = array(
'query' => true,
'index' => true,
@@ -73,7 +72,7 @@
{
$components = phpgwapi_cache::session_get('property',
'preview_components');
$components = ($components) ? unserialize($components)
: array();
-
+
$fields = array_keys($components[0]);
$this->bocommon->download($components, $fields,
$fields);
@@ -99,7 +98,7 @@
return $this->receipt;
}
-
+
private function _getexcelcolumnname( $index )
{
//Get the quotient : if the index superior to base 26
max ?
@@ -117,50 +116,52 @@
}
public function import_component_files()
- {
+ {
$location_code = phpgw::get_var('location_code');
//$id = phpgw::get_var('location_item_id');
//$attrib_name_componentID =
phpgw::get_var('attribute_name_component_id');
$preview = phpgw::get_var('preview');
$with_components =
phpgw::get_var('with_components_check');
-
- /*if ($_FILES['file']['tmp_name'])
- {
- if (!$attrib_name_componentID)
- {
- $receipt['error'][] = array('msg' =>
lang('Choose attribute name for Component ID'));
- return $receipt;
- }
- }*/
-
+
+ /* if ($_FILES['file']['tmp_name'])
+ {
+ if (!$attrib_name_componentID)
+ {
+ $receipt['error'][] = array('msg' => lang('Choose
attribute name for Component ID'));
+ return $receipt;
+ }
+ } */
+
if (!$location_code)
{
$receipt['error'][] = array('msg' =>
lang('Choose Location'));
return $receipt;
}
-
+
$import_component_files = new import_component_files();
-
+
if ($preview)
{
$receipt = $import_component_files->preview();
return $receipt;
}
-
+
if ($with_components)
{
$receipt =
$import_component_files->add_files_components_location();
- } else {
+ }
+ else
+ {
$receipt =
$import_component_files->add_files_location();
}
-
+
return $receipt;
}
-
- private function _getArrayItem($id, $name, $selected, $options
= array(), $no_lang = false, $attribs = '' )
+
+ private function _getArrayItem( $id, $name, $selected, $options
= array(), $no_lang = false, $attribs = '' )
{
// should be in class common.sbox
- if ( !is_array($options) || !count($options) )
+ if (!is_array($options) || !count($options))
{
$options = array('no', 'yes');
}
@@ -174,7 +175,7 @@
if (!is_array($selected))
{
- $check[$selected] = true;
+ $check[$selected] = true;
}
else
{
@@ -184,9 +185,9 @@
}
}
- foreach ( $options as $value => $option )
+ foreach ($options as $value => $option)
{
- $check2 = isset( $check[$value] ) ? ' selected'
: '';
+ $check2 = isset($check[$value]) ? ' selected' :
'';
$option = $no_lang ? $option : lang($option);
$html .= <<<HTML
@@ -200,7 +201,7 @@
HTML;
return $html;
}
-
+
public function handle_import_files()
{
$path_upload_dir =
phpgwapi_cache::session_get('property', 'path_upload_dir');
@@ -209,16 +210,16 @@
return false;
}
phpgw::import_class('property.multiuploader');
-
+
$options['upload_dir'] = $path_upload_dir;
$options['script_url'] =
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'property.uiimport_components.handle_import_files'));
$upload_handler = new property_multiuploader($options);
}
- private function _get_components_cached_file ()
+ private function _get_components_cached_file()
{
$cached_file = phpgwapi_cache::session_get('property',
'components_import_file');
-
+
if ($_FILES['file']['tmp_name'])
{
if ($cached_file)
@@ -227,7 +228,7 @@
unlink($cached_file);
unset($cached_file);
}
-
+
$file = $_FILES['file']['tmp_name'];
$cached_file = "{$file}_temporary_import_file";
@@ -234,10 +235,10 @@
file_put_contents($cached_file,
file_get_contents($file));
phpgwapi_cache::session_set('property',
'components_import_file', $cached_file);
}
-
+
return $cached_file;
}
-
+
private function _build_sheets()
{
$cached_file = $this->_get_components_cached_file();
@@ -246,7 +247,7 @@
$this->receipt['error'][] = array('msg' =>
lang('Cached file not exists'));
return;
}
-
+
$objPHPExcel = PHPExcel_IOFactory::load($cached_file);
$AllSheets = $objPHPExcel->getSheetNames();
@@ -261,11 +262,11 @@
'name' => $sheet
);
}
- }
+ }
- return $sheets;
+ return $sheets;
}
-
+
private function _build_start_line()
{
$sheet_id = phpgwapi_cache::session_get('property',
'sheet_id');
@@ -275,11 +276,11 @@
$this->receipt['error'][] = array('msg' =>
lang('Cached file not exists'));
return;
}
-
+
$objPHPExcel = PHPExcel_IOFactory::load($cached_file);
$objPHPExcel->setActiveSheetIndex((int)($sheet_id - 1));
$highestColumm =
$objPHPExcel->getActiveSheet()->getHighestDataColumn();
- $highestColumnIndex =
PHPExcel_Cell::columnIndexFromString($highestColumm);
+ $highestColumnIndex =
PHPExcel_Cell::columnIndexFromString($highestColumm);
$html_table = '<table class="pure-table
pure-table-bordered">';
$i = 0;
@@ -317,24 +318,24 @@
}
$html_table .= '</table>';
- return $html_table;
+ return $html_table;
}
-
- private function _get_default_options()
+
+ private function _get_default_options()
{
- return array (
+ return array(
'' => ' ... ',
'new_column' => lang('New attribute'),
'building_part' => lang('Building Part'),
'name_building_part' => lang('Name of the
Building Part'),
- 'component_id' => lang('Component ID')
+ 'component_id' => lang('Component ID')
);
}
-
+
private function _build_columns()
{
$cod_profile = phpgw::get_var('cod_profile');
-
+
$cached_file = $this->_get_components_cached_file();
if (!$cached_file)
{
@@ -348,10 +349,10 @@
$objPHPExcel = PHPExcel_IOFactory::load($cached_file);
$objPHPExcel->setActiveSheetIndex((int)($sheet_id - 1));
$highestColumm =
$objPHPExcel->getActiveSheet()->getHighestDataColumn();
- $highestColumnIndex =
PHPExcel_Cell::columnIndexFromString($highestColumm);
+ $highestColumnIndex =
PHPExcel_Cell::columnIndexFromString($highestColumm);
$profile = array();
-
+
if ($cod_profile)
{
$profiles =
$this->config_repository['profiles'];
@@ -373,7 +374,7 @@
$data_types = $this->bocommon->select_datatype();
$_options_data_type[''] = 'data type';
- foreach($data_types as $row)
+ foreach ($data_types as $row)
{
$_options_data_type[$row['id']] = $row['name'];
}
@@ -397,22 +398,22 @@
$html_table .= '</table>';
- return $html_table;
+ return $html_table;
}
-
- private function _prepare_profile ()
+
+ private function _prepare_profile()
{
- $columns = (array) phpgw::get_var('columns');
- $attrib_names = (array) phpgw::get_var('attrib_names');
-
+ $columns = (array)phpgw::get_var('columns');
+ $attrib_names = (array)phpgw::get_var('attrib_names');
+
$template_id = phpgwapi_cache::session_get('property',
'template_id');
$attrib_name_componentID =
phpgwapi_cache::session_get('property', 'attrib_name_componentID');
-
+
$template = explode("_", $template_id);
$entity_id = $template[0];
$cat_id = $template[1];
$attributes =
$this->custom->find($this->type_app[$this->type],
".{$this->type}.{$entity_id}.{$cat_id}", 0, '', 'ASC', 'attrib_sort', true,
true);
-
+
$_options = $this->_get_default_options();
foreach ($attributes as $attribute)
{
@@ -422,38 +423,41 @@
}
$_options[$attribute['column_name']] =
$attribute['input_text'];
}
-
+
$columns_name = array();
foreach ($columns as $k => $v)
{
if ($v == 'new_column')
{
- $columns_name[] = $k .' =>
'.$attrib_names[$k];
+ $columns_name[] = $k . ' => ' .
$attrib_names[$k];
$columns[$k] =
strtolower($attrib_names[$k]);
- } else {
- $columns_name[] = $k .' =>
'.$_options[$v];
}
+ else
+ {
+ $columns_name[] = $k . ' => ' .
$_options[$v];
+ }
}
-
+
$entity_info = $this->bo->read_single($entity_id);
$category_info =
$this->bo->read_single_category($entity_id, $cat_id);
$template_name =
"{$entity_info['name']}::{$category_info['name']}";
-
+
$profile['columns'] = array('columns' => $columns,
'columns_name' => $columns_name);
$profile['template'] = array('template_id' =>
$template_id, 'template_name' => $template_name);
- $profile['attrib_name_componentID'] = array('id' =>
$attrib_name_componentID, 'text' => $attrib_name_componentID_Text);
- phpgwapi_cache::session_set('property', 'profile',
serialize($profile));
-
+ $profile['attrib_name_componentID'] = array('id' =>
$attrib_name_componentID,
+ 'text' => $attrib_name_componentID_Text);
+ phpgwapi_cache::session_set('property', 'profile',
serialize($profile));
+
return $profile;
}
-
+
private function _prepare_values_to_preview()
{
- $columns = (array) phpgw::get_var('columns');
+ $columns = (array)phpgw::get_var('columns');
$attrib_data_types =
phpgw::get_var('attrib_data_types');
$attrib_names = phpgw::get_var('attrib_names');
$attrib_precision = phpgw::get_var('attrib_precision');
-
+
$cached_file = $this->_get_components_cached_file();
if (!$cached_file)
{
@@ -460,16 +464,16 @@
$this->receipt['error'][] = array('msg' =>
lang('Cached file not exists'));
return;
}
-
+
$sheet_id = phpgwapi_cache::session_get('property',
'sheet_id');
$start_line = phpgwapi_cache::session_get('property',
'start_line');
$template_id = phpgwapi_cache::session_get('property',
'template_id');
$attrib_name_componentID =
phpgwapi_cache::session_get('property', 'attrib_name_componentID');
-
+
$objPHPExcel = PHPExcel_IOFactory::load($cached_file);
$objPHPExcel->setActiveSheetIndex((int)($sheet_id - 1));
$rows =
$objPHPExcel->getActiveSheet()->getHighestDataRow();
-
+
$import_entity_categories = new
import_entity_categories($template_id);
$import_components = new import_components();
@@ -480,7 +484,9 @@
if ($this->receipt['error'])
{
return;
- } else {
+ }
+ else
+ {
$new_attribs_for_template =
$receipt['new_attribs_for_template'];
}
}
@@ -491,7 +497,7 @@
$building_part_in_table = array();
$import_data = array();
- $list_entity_categories =
$import_entity_categories->list_entity_categories();
+ $list_entity_categories =
$import_entity_categories->list_entity_categories();
for ($i = $start_line; $i < $rows; $i++)
{
@@ -499,7 +505,8 @@
foreach ($columns as $_row_key => $_value_key)
{
- $_result[$_value_key] =
htmlspecialchars($objPHPExcel->getActiveSheet()->getCell("{$_row_key}{$i}")->getCalculatedValue(),
ENT_QUOTES, 'UTF-8'); }
+ $_result[$_value_key] =
htmlspecialchars($objPHPExcel->getActiveSheet()->getCell("{$_row_key}{$i}")->getCalculatedValue(),
ENT_QUOTES, 'UTF-8');
+ }
if ((int)$_result['building_part'] ||
$_result['building_part'] === '0')
{
@@ -513,13 +520,15 @@
$cat_id =
$list_entity_categories[$_result['building_part']]['id'];
$entity_id =
$list_entity_categories[$_result['building_part']]['entity_id'];
-
$building_part_in_table[$_result['building_part']] = array('entity_id' =>
$entity_id, 'cat_id' => $cat_id);
+
$building_part_in_table[$_result['building_part']] = array('entity_id' =>
$entity_id,
+ 'cat_id' =>
$cat_id);
}
}
- else {
+ else
+ {
if
(empty($_result['component_id']))
{
-
$building_part_out_table[$_result['building_part']] =
$_result['building_part'].' '.$_result['name_building_part'];
+
$building_part_out_table[$_result['building_part']] = $_result['building_part']
. ' ' . $_result['name_building_part'];
}
}
@@ -531,7 +540,7 @@
$_result =
array($attrib_name_componentID => $_result['component_id']) + $_result;
$_result = array('building
part' => $_result['building_part']) + $_result;
-
$import_data[$_result['building_part']]['components'][] = $_result;
+
$import_data[$_result['building_part']]['components'][] = $_result;
}
}
}
@@ -544,19 +553,21 @@
if ($this->receipt['error'])
{
return;
- } else {
+ }
+ else
+ {
$new_entity_categories =
$receipt['new_entity_categories'];
}
- }
-
+ }
+
$result = array();
-
+
if (!count($import_data))
{
$result['error'][] = array('msg' => lang('not
exist components to import'));
return $result;
}
-
+
$preview_components =
$import_components->prepare_preview_components($import_data);
//$config = createObject('phpgwapi.config',
'component_import');
@@ -565,12 +576,14 @@
{
//$this->config->value('new_attribs_for_template',
serialize($new_attribs_for_template));
phpgwapi_cache::session_set('property',
'new_attribs_for_template', serialize($new_attribs_for_template));
- foreach($new_attribs_for_template as $attrib)
+ foreach ($new_attribs_for_template as $attrib)
{
$values[] = $attrib['column_name'];
}
$result['new_attribs_for_template'] = $values;
- } else {
+ }
+ else
+ {
phpgwapi_cache::session_set('property',
'new_attribs_for_template', '');
$result['new_attribs_for_template'][] =
lang('Not exist attributes to insert the template');
}
@@ -580,14 +593,16 @@
//$this->config->value('new_entity_categories',
serialize($new_entity_categories));
phpgwapi_cache::session_set('property',
'new_entity_categories', serialize($new_entity_categories));
$result['new_entity_categories'] =
array_values($new_entity_categories);
- } else {
+ }
+ else
+ {
phpgwapi_cache::session_set('property',
'new_entity_categories', '');
$result['new_entity_categories'][] = lang('Not
exist new entity categories');
}
-
+
$profile = $this->_prepare_profile();
$result['profile'] = $profile;
-
+
phpgwapi_cache::session_set('property',
'building_part_in_table', serialize($building_part_in_table));
phpgwapi_cache::session_set('property',
'preview_components', serialize($preview_components));
phpgwapi_cache::session_set('property',
'new_components', serialize($import_data));
@@ -594,18 +609,18 @@
return $result;
}
-
+
private function _save_values_import()
- {
+ {
$name_profile = phpgw::get_var('name_profile',
'REQUEST');
$cod_profile = phpgw::get_var('cod_profile', 'REQUEST');
$profile_option_save =
phpgw::get_var('profile_option_save', 'int', 'REQUEST');
$save_profile = phpgw::get_var('save_profile', 'int',
'REQUEST');
-
+
$template_id = phpgwapi_cache::session_get('property',
'template_id');
$attrib_name_componentID =
phpgwapi_cache::session_get('property', 'attrib_name_componentID');
$location_code =
phpgwapi_cache::session_get('property', 'location_code');
-
+
$import_entity_categories = new
import_entity_categories($template_id);
$import_components = new import_components();
@@ -625,47 +640,47 @@
$import_data = phpgwapi_cache::session_get('property',
'new_components');
$import_data = ($import_data) ?
unserialize($import_data) : array();
-
+
if (!count($import_data))
{
$this->receipt['error'][] = array('msg' =>
lang("not exist components to import"));
return;
}
-
+
$building_part_processed =
$import_entity_categories->add_entity_categories();
if (count($building_part_processed['not_added']))
{
- foreach($building_part_processed['not_added']
as $k => $v)
+ foreach ($building_part_processed['not_added']
as $k => $v)
{
- $this->receipt['message'][] =
array('msg' => lang("entity category {$v} not added"));
+ $this->receipt['message'][] =
array('msg' => lang("entity category {$v} not added"));
}
}
if (count($building_part_processed['added']))
{
- foreach($building_part_processed['added'] as $k
=> $v)
+ foreach ($building_part_processed['added'] as
$k => $v)
{
$import_data[$k]['cat_id'] = $v['id'];
- $import_data[$k]['entity_id'] =
$v['entity_id'];
+ $import_data[$k]['entity_id'] =
$v['entity_id'];
}
- $this->receipt['message'][] = array('msg' =>
lang("%1 entity category has been added",
count($building_part_processed['added'])));
+ $this->receipt['message'][] = array('msg' =>
lang("%1 entity category has been added",
count($building_part_processed['added'])));
}
$receipt =
$import_components->add_components($import_data, $location_code,
$attrib_name_componentID);
$this->receipt = $this->_msg_data($receipt);
-
+
if ($save_profile)
{
$profiles =
$this->config_repository['profiles'];
-
+
if ($profile_option_save == 1)
{
- $cod_profile = str_replace(' ', '_',
mb_strtolower($name_profile, 'UTF-8'));
+ $cod_profile = str_replace(' ', '_',
mb_strtolower($name_profile, 'UTF-8'));
$profiles[$cod_profile]['name'] =
$name_profile;
}
-
+
if ($cod_profile)
- {
+ {
$content =
phpgwapi_cache::session_get('property', 'profile');
$content = ($content) ?
unserialize($content) : array();
$profiles[$cod_profile]['content'] =
$content;
@@ -673,24 +688,24 @@
$this->config->value('profiles',
serialize($profiles));
$this->config->save_repository();
}
- }
-
+ }
+
return $this->receipt;
}
-
+
public function import_components()
- {
+ {
$step = phpgw::get_var('step', 'int', 'REQUEST');
$save = phpgw::get_var('save', 'int', 'REQUEST');
-
+
phpgw::import_class('phpgwapi.phpexcel');
-
+
if ($step == 1)
{
$result = $this->_build_sheets();
}
-
- if ($step == 2)
+
+ if ($step == 2)
{
$sheet_id = phpgw::get_var('sheet_id', 'int',
'REQUEST');
if (!$sheet_id)
@@ -699,11 +714,11 @@
return $this->receipt;
}
phpgwapi_cache::session_set('property',
'sheet_id', $sheet_id);
-
+
$result = $this->_build_start_line();
}
-
- if ($step == 3)
+
+ if ($step == 3)
{
$start_line = phpgw::get_var('start_line',
'int', 'REQUEST');
$template_id = phpgw::get_var('template_id');
@@ -719,11 +734,11 @@
}
phpgwapi_cache::session_set('property',
'start_line', $start_line);
phpgwapi_cache::session_set('property',
'template_id', $template_id);
-
+
$result = $this->_build_columns();
}
-
- if ($step == 4)
+
+ if ($step == 4)
{
$attrib_name_componentID =
phpgw::get_var('attribute_name_component_id');
if (!$attrib_name_componentID)
@@ -732,11 +747,11 @@
return $this->receipt;
}
phpgwapi_cache::session_set('property',
'attrib_name_componentID', $attrib_name_componentID);
-
+
$result = $this->_prepare_values_to_preview();
}
-
- if ($step == 5 && $save)
+
+ if ($step == 5 && $save)
{
$location_code =
phpgw::get_var('location_code');
$location_item_id =
phpgw::get_var('location_item_id');
@@ -747,18 +762,18 @@
}
phpgwapi_cache::session_set('property',
'location_code', $location_code);
phpgwapi_cache::session_set('property',
'location_item_id', $location_item_id);
-
+
$result = $this->_save_values_import();
}
-
+
if ($this->receipt['error'])
{
return $this->receipt;
}
-
+
return $result;
}
-
+
/**
* Prepare UI
* @return void
@@ -767,13 +782,15 @@
{
$tabs = array();
$tabs['locations'] = array('label' =>
lang('Locations'), 'link' => '#locations');
- $tabs['components'] = array('label' =>
lang('Components'), 'link' => '#components', 'disable' => 1);
+ $tabs['components'] = array('label' =>
lang('Components'), 'link' => '#components',
+ 'disable' => 1);
$tabs['files'] = array('label' => lang('Files'), 'link'
=> '#files', 'disable' => 0);
- $tabs['relations'] = array('label' =>
lang('Relations'), 'link' => '#relations', 'disable' => 1);
-
+ $tabs['relations'] = array('label' =>
lang('Relations'), 'link' => '#relations',
+ 'disable' => 1);
+
$active_tab = 'locations';
- $type_filter =
execMethod('property.soadmin_location.read', array());
+ $type_filter =
execMethod('property.soadmin_location.read', array());
$category_filter = $this->get_categories_for_type();
$district_filter =
$this->bocommon->select_district_list('filter');
@@ -783,30 +800,32 @@
$related_def = array
(
- array('key' => 'location_code', 'label' =>
lang('location'), 'sortable' => true, 'resizeable' => true),
+ array('key' => 'location_code', 'label' =>
lang('location'), 'sortable' => true,
+ 'resizeable' => true),
array('key' => 'loc1_name', 'label' =>
lang('name'), 'sortable' => true, 'resizeable' => true)
);
$datatable_def[] = array
- (
+ (
'container' => 'datatable-container_0',
- 'requestUrl' =>
json_encode(self::link(array('menuaction' =>
'property.uiimport_components.get_locations_for_type', 'phpgw_return_as' =>
'json'))),
+ 'requestUrl' =>
json_encode(self::link(array('menuaction' =>
'property.uiimport_components.get_locations_for_type',
+ 'phpgw_return_as' => 'json'))),
'ColumnDefs' => $related_def,
'tabletools' => array(),
'config' => array(
array('singleSelect' => true)
- )
- );
-
+ )
+ );
+
$profile_list = array();
$profiles = $this->config_repository['profiles'];
- foreach($profiles as $k => $v)
+ foreach ($profiles as $k => $v)
{
- $profile_list[] = array('id'=> $k,
'name'=>$v['name']);
+ $profile_list[] = array('id' => $k, 'name' =>
$v['name']);
}
array_unshift($profile_list, array('id' => '', 'name'
=> lang('choose profile')));
-
+
//$profile = $this->config_repository['profile'];
$entity_list = $this->bo->read(array('allrows' =>
true));
$category_list = array();
@@ -824,25 +843,26 @@
);
}
}
-
+
$multi_upload_action =
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'property.uiimport_components.handle_import_files'));
-
+
$access_error_upload_dir = '';
$import_component_files = new import_component_files();
- $receipt = $import_component_files->check_upload_dir();
+ $receipt = $import_component_files->check_upload_dir();
if (($receipt['error']))
{
$access_error_upload_dir = $receipt['error'];
- } else {
+ }
+ else
+ {
phpgwapi_cache::session_set('property',
'path_upload_dir', $import_component_files->get_path_upload_dir());
}
phpgwapi_jquery::init_multi_upload_file();
-
+
$data = array
- (
+ (
'datatable_def' => $datatable_def,
'tabs' =>
phpgwapi_jquery::tabview_generate($tabs, $active_tab),
-
'type_filter' => array('options' =>
$type_filter),
'category_filter' => array('options' =>
$category_filter),
'district_filter' => array('options' =>
$district_filter),
@@ -869,19 +889,21 @@
$template_entity_id = $template_info[0];
$template_cat_id = $template_info[1];
- $attrib_list = $this->bo->read_attrib(array('entity_id'
=> $template_entity_id, 'cat_id' => $template_cat_id, 'allrows' => true));
+ $attrib_list = $this->bo->read_attrib(array('entity_id'
=> $template_entity_id,
+ 'cat_id' => $template_cat_id, 'allrows' =>
true));
$list = array();
foreach ($attrib_list as $attrib)
{
$selected = ($selected_attribute ==
$attrib['column_name']) ? 1 : 0;
- $list[] = array('id' => $attrib['column_name'],
'name' => $attrib['input_text'], 'selected' => $selected);
+ $list[] = array('id' => $attrib['column_name'],
'name' => $attrib['input_text'],
+ 'selected' => $selected);
}
-
+
array_unshift($list, array('id' => '', 'name' =>
lang('choose attribute')));
return $list;
}
-
+
public function get_locations_for_type()
{
$type_id = phpgw::get_var('type_id', 'int');
@@ -890,7 +912,7 @@
{
$type_id = 1;
}
-
+
$search = phpgw::get_var('search');
$order = phpgw::get_var('order');
$draw = phpgw::get_var('draw', 'int');
@@ -908,18 +930,18 @@
'part_of_town_id' =>
phpgw::get_var('part_of_town_id', 'int', 'REQUEST', 0),
'allrows' => phpgw::get_var('length', 'int') ==
-1
);
-
- $solocation = CreateObject('property.solocation');
- $locations = $solocation->read($params);
+ $solocation = CreateObject('property.solocation');
+ $locations = $solocation->read($params);
+
$values = array();
- foreach($locations as $item)
+ foreach ($locations as $item)
{
$values[] = array(
'id' => $item['id'],
'location_code' =>
$item['location_code'],
'loc1_name' => $item['loc1_name']
- );
+ );
}
$result_data = array('results' => $values);
@@ -929,7 +951,7 @@
return $this->jquery_results($result_data);
}
-
+
/**
* Fetch data from $this->bo based on parametres
* @return array
@@ -938,7 +960,7 @@
{
return;
}
-
+
public function get_categories_for_type()
{
$type_id = phpgw::get_var('type_id', 'int');
@@ -947,7 +969,7 @@
{
$type_id = 1;
}
-
+
$categories =
$this->bocommon->select_category_list(array
('format' => 'filter',
'selected' => '',
@@ -959,7 +981,7 @@
return $categories;
}
-
+
public function get_profile()
{
$cod_profile = phpgw::get_var('cod_profile', 'REQUEST');
@@ -966,19 +988,19 @@
$profiles = $this->config_repository['profiles'];
$content = $profiles[$cod_profile]['content'];
-
+
$template_id = ($content['template']['template_id']);
$attrib_name_componentID =
$content['attrib_name_componentID']['id'];
- return array('template_id'=>$template_id,
'attrib_name_componentID'=>$attrib_name_componentID);
+ return array('template_id' => $template_id,
'attrib_name_componentID' => $attrib_name_componentID);
}
-
+
public function get_data_type()
{
$values = $this->bocommon->select_datatype();
return $values;
}
-
+
public function get_part_of_town()
{
$district_id = phpgw::get_var('district_id', 'int');
@@ -987,5 +1009,4 @@
return $values;
}
-
}
\ No newline at end of file
Modified: branches/Version-2_0-branch/property/inc/import/UploadHandler.php
===================================================================
--- branches/Version-2_0-branch/property/inc/import/UploadHandler.php
2017-02-20 20:39:26 UTC (rev 16353)
+++ branches/Version-2_0-branch/property/inc/import/UploadHandler.php
2017-02-20 20:44:47 UTC (rev 16354)
@@ -1,1393 +1,1557 @@
<?php
-/*
- * jQuery File Upload Plugin PHP Class
- * https://github.com/blueimp/jQuery-File-Upload
- *
- * Copyright 2010, Sebastian Tschan
- * https://blueimp.net
- *
- * Licensed under the MIT license:
- * http://www.opensource.org/licenses/MIT
- */
+ /*
+ * jQuery File Upload Plugin PHP Class
+ * https://github.com/blueimp/jQuery-File-Upload
+ *
+ * Copyright 2010, Sebastian Tschan
+ * https://blueimp.net
+ *
+ * Licensed under the MIT license:
+ * http://www.opensource.org/licenses/MIT
+ */
-class UploadHandler
-{
+ class UploadHandler
+ {
- protected $options;
+ protected $options;
+ // PHP File Upload error message codes:
+ // http://php.net/manual/en/features.file-upload.errors.php
+ protected $error_messages = array(
+ 1 => 'The uploaded file exceeds the upload_max_filesize
directive in php.ini',
+ 2 => 'The uploaded file exceeds the MAX_FILE_SIZE
directive that was specified in the HTML form',
+ 3 => 'The uploaded file was only partially uploaded',
+ 4 => 'No file was uploaded',
+ 6 => 'Missing a temporary folder',
+ 7 => 'Failed to write file to disk',
+ 8 => 'A PHP extension stopped the file upload',
+ 'post_max_size' => 'The uploaded file exceeds the
post_max_size directive in php.ini',
+ 'max_file_size' => 'File is too big',
+ 'min_file_size' => 'File is too small',
+ 'accept_file_types' => 'Filetype not allowed',
+ 'max_number_of_files' => 'Maximum number of files
exceeded',
+ 'max_width' => 'Image exceeds maximum width',
+ 'min_width' => 'Image requires a minimum width',
+ 'max_height' => 'Image exceeds maximum height',
+ 'min_height' => 'Image requires a minimum height',
+ 'abort' => 'File upload aborted',
+ 'image_resize' => 'Failed to resize image'
+ );
+ protected $image_objects = array();
- // PHP File Upload error message codes:
- // http://php.net/manual/en/features.file-upload.errors.php
- protected $error_messages = array(
- 1 => 'The uploaded file exceeds the upload_max_filesize directive in
php.ini',
- 2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was
specified in the HTML form',
- 3 => 'The uploaded file was only partially uploaded',
- 4 => 'No file was uploaded',
- 6 => 'Missing a temporary folder',
- 7 => 'Failed to write file to disk',
- 8 => 'A PHP extension stopped the file upload',
- 'post_max_size' => 'The uploaded file exceeds the post_max_size
directive in php.ini',
- 'max_file_size' => 'File is too big',
- 'min_file_size' => 'File is too small',
- 'accept_file_types' => 'Filetype not allowed',
- 'max_number_of_files' => 'Maximum number of files exceeded',
- 'max_width' => 'Image exceeds maximum width',
- 'min_width' => 'Image requires a minimum width',
- 'max_height' => 'Image exceeds maximum height',
- 'min_height' => 'Image requires a minimum height',
- 'abort' => 'File upload aborted',
- 'image_resize' => 'Failed to resize image'
- );
+ public function __construct( $options = null, $initialize =
true, $error_messages = null )
+ {
+ $this->response = array();
+ $this->options = array(
+ 'script_url' => $this->get_full_url() . '/' .
$this->basename($this->get_server_var('SCRIPT_NAME')),
+ 'upload_dir' =>
dirname($this->get_server_var('SCRIPT_FILENAME')) . '/files/',
+ 'upload_url' => $this->get_full_url() .
'/files/',
+ 'input_stream' => 'php://input',
+ 'user_dirs' => false,
+ 'mkdir_mode' => 0755,
+ 'param_name' => 'files',
+ // Set the following option to 'POST', if your
server does not support
+ // DELETE requests. This is a parameter sent to
the client:
+ 'delete_type' => 'POST',
+ 'access_control_allow_origin' => '*',
+ 'access_control_allow_credentials' => false,
+ 'access_control_allow_methods' => array(
+ 'OPTIONS',
+ 'HEAD',
+ 'GET',
+ 'POST',
+ 'PUT',
+ 'PATCH',
+ 'DELETE'
+ ),
+ 'access_control_allow_headers' => array(
+ 'Content-Type',
+ 'Content-Range',
+ 'Content-Disposition'
+ ),
+ // By default, allow redirects to the referer
protocol+host:
+ 'redirect_allow_target' => '/^' . preg_quote(
+
parse_url($this->get_server_var('HTTP_REFERER'), PHP_URL_SCHEME)
+ . '://'
+ .
parse_url($this->get_server_var('HTTP_REFERER'), PHP_URL_HOST)
+ . '/', // Trailing slash to not match
subdomains by mistake
+ '/'
// preg_quote delimiter param
+ ) . '/',
+ // Enable to provide file downloads via GET
requests to the PHP script:
+ // 1. Set to 1 to download files via
readfile method through PHP
+ // 2. Set to 2 to send a X-Sendfile header
for lighttpd/Apache
+ // 3. Set to 3 to send a X-Accel-Redirect
header for nginx
+ // If set to 2 or 3, adjust the upload_url
option to the base path of
+ // the redirect parameter, e.g. '/files/'.
+ 'download_via_php' => false,
+ // Read files in chunks to avoid memory limits
when download_via_php
+ // is enabled, set to 0 to disable chunked
reading of files:
+ 'readfile_chunk_size' => 10 * 1024 * 1024, //
10 MiB
+ // Defines which files can be displayed inline
when downloaded:
+ 'inline_file_types' => '/\.(gif|jpe?g|png)$/i',
+ // Defines which files (based on their names)
are accepted for upload:
+ 'accept_file_types' => '/.+$/i',
+ // The php.ini settings upload_max_filesize and
post_max_size
+ // take precedence over the following
max_file_size setting:
+ 'max_file_size' => null,
+ 'min_file_size' => 1,
+ // The maximum number of files for the upload
directory:
+ 'max_number_of_files' => null,
+ // Defines which files are handled as image
files:
+ 'image_file_types' => '/\.(gif|jpe?g|png)$/i',
+ // Use exif_imagetype on all files to correct
file extensions:
+ 'correct_image_extensions' => false,
+ // Image resolution restrictions:
+ 'max_width' => null,
+ 'max_height' => null,
+ 'min_width' => 1,
+ 'min_height' => 1,
+ // Set the following option to false to enable
resumable uploads:
+ 'discard_aborted_uploads' => true,
+ // Set to 0 to use the GD library to scale and
orient images,
+ // set to 1 to use imagick (if installed, falls
back to GD),
+ // set to 2 to use the ImageMagick convert
binary directly:
+ 'image_library' => 1,
+ // Uncomment the following to define an array
of resource limits
+ // for imagick:
+ /*
+ 'imagick_resource_limits' => array(
+ imagick::RESOURCETYPE_MAP => 32,
+ imagick::RESOURCETYPE_MEMORY => 32
+ ),
+ */
+ // Command or path for to the ImageMagick
convert binary:
+ 'convert_bin' => 'convert',
+ // Uncomment the following to add parameters in
front of each
+ // ImageMagick convert call (the limit
constraints seem only
+ // to have an effect if put in front):
+ /*
+ 'convert_params' => '-limit memory 32MiB
-limit map 32MiB',
+ */
+ // Command or path for to the ImageMagick
identify binary:
+ 'identify_bin' => 'identify',
+ 'image_versions' => array(
+ // The empty image version key defines
options for the original image:
+ '' => array(
+ // Automatically rotate images
based on EXIF meta data:
+ 'auto_orient' => true
+ ),
+ // Uncomment the following to create
medium sized images:
+ /*
+ 'medium' => array(
+ 'max_width' => 800,
+ 'max_height' => 600
+ ),
+ */
+ 'thumbnail' => array(
+ // Uncomment the following to
use a defined directory for the thumbnails
+ // instead of a subdirectory
based on the version identifier.
+ // Make sure that this
directory doesn't allow execution of files if you
+ // don't pose any restrictions
on the type of uploaded files, e.g. by
+ // copying the .htaccess file
from the files directory for Apache:
+ //'upload_dir' =>
dirname($this->get_server_var('SCRIPT_FILENAME')).'/thumb/',
+ //'upload_url' =>
$this->get_full_url().'/thumb/',
+ // Uncomment the following to
force the max
+ // dimensions and e.g. create
square thumbnails:
+ //'crop' => true,
+ 'max_width' => 80,
+ 'max_height' => 80
+ )
+ ),
+ 'print_response' => true
+ );
+ if ($options)
+ {
+ $this->options = $options + $this->options;
+ }
+ if ($error_messages)
+ {
+ $this->error_messages = $error_messages +
$this->error_messages;
+ }
+ if ($initialize)
+ {
+ $this->initialize();
+ }
+ }
- protected $image_objects = array();
+ protected function initialize()
+ {
+ switch ($this->get_server_var('REQUEST_METHOD'))
+ {
+ case 'OPTIONS':
+ case 'HEAD':
+ $this->head();
+ break;
+ case 'GET':
+
$this->get($this->options['print_response']);
+ break;
+ case 'PATCH':
+ case 'PUT':
+ case 'POST':
+
$this->post($this->options['print_response']);
+ break;
+ case 'DELETE':
+
$this->delete($this->options['print_response']);
+ break;
+ default:
+ $this->header('HTTP/1.1 405 Method Not
Allowed');
+ }
+ }
- public function __construct($options = null, $initialize = true,
$error_messages = null) {
- $this->response = array();
- $this->options = array(
- 'script_url' =>
$this->get_full_url().'/'.$this->basename($this->get_server_var('SCRIPT_NAME')),
- 'upload_dir' =>
dirname($this->get_server_var('SCRIPT_FILENAME')).'/files/',
- 'upload_url' => $this->get_full_url().'/files/',
- 'input_stream' => 'php://input',
- 'user_dirs' => false,
- 'mkdir_mode' => 0755,
- 'param_name' => 'files',
- // Set the following option to 'POST', if your server does not
support
- // DELETE requests. This is a parameter sent to the client:
- 'delete_type' => 'POST',
- 'access_control_allow_origin' => '*',
- 'access_control_allow_credentials' => false,
- 'access_control_allow_methods' => array(
- 'OPTIONS',
- 'HEAD',
- 'GET',
- 'POST',
- 'PUT',
- 'PATCH',
- 'DELETE'
- ),
- 'access_control_allow_headers' => array(
- 'Content-Type',
- 'Content-Range',
- 'Content-Disposition'
- ),
- // By default, allow redirects to the referer protocol+host:
- 'redirect_allow_target' => '/^'.preg_quote(
- parse_url($this->get_server_var('HTTP_REFERER'), PHP_URL_SCHEME)
- .'://'
- .parse_url($this->get_server_var('HTTP_REFERER'), PHP_URL_HOST)
- .'/', // Trailing slash to not match subdomains by mistake
- '/' // preg_quote delimiter param
- ).'/',
- // Enable to provide file downloads via GET requests to the PHP
script:
- // 1. Set to 1 to download files via readfile method through
PHP
- // 2. Set to 2 to send a X-Sendfile header for lighttpd/Apache
- // 3. Set to 3 to send a X-Accel-Redirect header for nginx
- // If set to 2 or 3, adjust the upload_url option to the base path
of
- // the redirect parameter, e.g. '/files/'.
- 'download_via_php' => false,
- // Read files in chunks to avoid memory limits when
download_via_php
- // is enabled, set to 0 to disable chunked reading of files:
- 'readfile_chunk_size' => 10 * 1024 * 1024, // 10 MiB
- // Defines which files can be displayed inline when downloaded:
- 'inline_file_types' => '/\.(gif|jpe?g|png)$/i',
- // Defines which files (based on their names) are accepted for
upload:
- 'accept_file_types' => '/.+$/i',
- // The php.ini settings upload_max_filesize and post_max_size
- // take precedence over the following max_file_size setting:
- 'max_file_size' => null,
- 'min_file_size' => 1,
- // The maximum number of files for the upload directory:
- 'max_number_of_files' => null,
- // Defines which files are handled as image files:
- 'image_file_types' => '/\.(gif|jpe?g|png)$/i',
- // Use exif_imagetype on all files to correct file extensions:
- 'correct_image_extensions' => false,
- // Image resolution restrictions:
- 'max_width' => null,
- 'max_height' => null,
- 'min_width' => 1,
- 'min_height' => 1,
- // Set the following option to false to enable resumable uploads:
- 'discard_aborted_uploads' => true,
- // Set to 0 to use the GD library to scale and orient images,
- // set to 1 to use imagick (if installed, falls back to GD),
- // set to 2 to use the ImageMagick convert binary directly:
- 'image_library' => 1,
- // Uncomment the following to define an array of resource limits
- // for imagick:
- /*
- 'imagick_resource_limits' => array(
- imagick::RESOURCETYPE_MAP => 32,
- imagick::RESOURCETYPE_MEMORY => 32
- ),
- */
- // Command or path for to the ImageMagick convert binary:
- 'convert_bin' => 'convert',
- // Uncomment the following to add parameters in front of each
- // ImageMagick convert call (the limit constraints seem only
- // to have an effect if put in front):
- /*
- 'convert_params' => '-limit memory 32MiB -limit map 32MiB',
- */
- // Command or path for to the ImageMagick identify binary:
- 'identify_bin' => 'identify',
- 'image_versions' => array(
- // The empty image version key defines options for the
original image:
- '' => array(
- // Automatically rotate images based on EXIF meta data:
- 'auto_orient' => true
- ),
- // Uncomment the following to create medium sized images:
- /*
- 'medium' => array(
- 'max_width' => 800,
- 'max_height' => 600
- ),
- */
- 'thumbnail' => array(
- // Uncomment the following to use a defined directory for
the thumbnails
- // instead of a subdirectory based on the version
identifier.
- // Make sure that this directory doesn't allow execution
of files if you
- // don't pose any restrictions on the type of uploaded
files, e.g. by
- // copying the .htaccess file from the files directory for
Apache:
- //'upload_dir' =>
dirname($this->get_server_var('SCRIPT_FILENAME')).'/thumb/',
- //'upload_url' => $this->get_full_url().'/thumb/',
- // Uncomment the following to force the max
- // dimensions and e.g. create square thumbnails:
- //'crop' => true,
- 'max_width' => 80,
- 'max_height' => 80
- )
- ),
- 'print_response' => true
- );
- if ($options) {
- $this->options = $options + $this->options;
- }
- if ($error_messages) {
- $this->error_messages = $error_messages + $this->error_messages;
- }
- if ($initialize) {
- $this->initialize();
- }
- }
+ protected function get_full_url()
+ {
+ $https = !empty($_SERVER['HTTPS']) &&
strcasecmp($_SERVER['HTTPS'], 'on') === 0 ||
+ !empty($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
+ strcasecmp($_SERVER['HTTP_X_FORWARDED_PROTO'],
'https') === 0;
+ return
+ ($https ? 'https://' : 'http://') .
+ (!empty($_SERVER['REMOTE_USER']) ?
$_SERVER['REMOTE_USER'] . '@' : '') .
+ (isset($_SERVER['HTTP_HOST']) ?
$_SERVER['HTTP_HOST'] : ($_SERVER['SERVER_NAME'] .
+ ($https && $_SERVER['SERVER_PORT'] === 443 ||
+ $_SERVER['SERVER_PORT'] === 80 ? '' : ':' .
$_SERVER['SERVER_PORT']))) .
+ substr($_SERVER['SCRIPT_NAME'], 0,
strrpos($_SERVER['SCRIPT_NAME'], '/'));
+ }
- protected function initialize() {
- switch ($this->get_server_var('REQUEST_METHOD')) {
- case 'OPTIONS':
- case 'HEAD':
- $this->head();
- break;
- case 'GET':
- $this->get($this->options['print_response']);
- break;
- case 'PATCH':
- case 'PUT':
- case 'POST':
- $this->post($this->options['print_response']);
- break;
- case 'DELETE':
- $this->delete($this->options['print_response']);
- break;
- default:
- $this->header('HTTP/1.1 405 Method Not Allowed');
- }
- }
+ protected function get_user_id()
+ {
+ @session_start();
+ return session_id();
+ }
- protected function get_full_url() {
- $https = !empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'],
'on') === 0 ||
- !empty($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
- strcasecmp($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') === 0;
- return
- ($https ? 'https://' : 'http://').
- (!empty($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'].'@' :
'').
- (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] :
($_SERVER['SERVER_NAME'].
- ($https && $_SERVER['SERVER_PORT'] === 443 ||
- $_SERVER['SERVER_PORT'] === 80 ? '' :
':'.$_SERVER['SERVER_PORT']))).
- substr($_SERVER['SCRIPT_NAME'],0, strrpos($_SERVER['SCRIPT_NAME'],
'/'));
- }
+ protected function get_user_path()
+ {
+ if ($this->options['user_dirs'])
+ {
+ return $this->get_user_id() . '/';
+ }
+ return '';
+ }
- protected function get_user_id() {
- @session_start();
- return session_id();
- }
+ protected function get_upload_path( $file_name = null, $version
= null )
+ {
+ $file_name = $file_name ? $file_name : '';
+ if (empty($version))
+ {
+ $version_path = '';
+ }
+ else
+ {
+ $version_dir =
@$this->options['image_versions'][$version]['upload_dir'];
+ if ($version_dir)
+ {
+ return $version_dir .
$this->get_user_path() . $file_name;
+ }
+ $version_path = $version . '/';
+ }
+ return $this->options['upload_dir'] .
$this->get_user_path()
+ . $version_path . $file_name;
+ }
- protected function get_user_path() {
- if ($this->options['user_dirs']) {
- return $this->get_user_id().'/';
- }
- return '';
- }
+ protected function get_query_separator( $url )
+ {
+ return strpos($url, '?') === false ? '?' : '&';
+ }
- protected function get_upload_path($file_name = null, $version = null) {
- $file_name = $file_name ? $file_name : '';
- if (empty($version)) {
- $version_path = '';
- } else {
- $version_dir =
@$this->options['image_versions'][$version]['upload_dir'];
- if ($version_dir) {
- return $version_dir.$this->get_user_path().$file_name;
- }
- $version_path = $version.'/';
- }
- return $this->options['upload_dir'].$this->get_user_path()
- .$version_path.$file_name;
- }
+ protected function get_download_url( $file_name, $version =
null, $direct = false )
+ {
+ if (!$direct && $this->options['download_via_php'])
+ {
+ $url = $this->options['script_url']
+ .
$this->get_query_separator($this->options['script_url'])
+ . $this->get_singular_param_name()
+ . '=' . rawurlencode($file_name);
+ if ($version)
+ {
+ $url .= '&version=' .
rawurlencode($version);
+ }
+ return $url . '&download=1';
+ }
+ if (empty($version))
+ {
+ $version_path = '';
+ }
+ else
+ {
+ $version_url =
@$this->options['image_versions'][$version]['upload_url'];
+ if ($version_url)
+ {
+ return $version_url .
$this->get_user_path() . rawurlencode($file_name);
+ }
+ $version_path = rawurlencode($version) . '/';
+ }
+ return $this->options['upload_url'] .
$this->get_user_path()
+ . $version_path . rawurlencode($file_name);
+ }
- protected function get_query_separator($url) {
- return strpos($url, '?') === false ? '?' : '&';
- }
+ protected function set_additional_file_properties( $file )
+ {
+ $file->deleteUrl = $this->options['script_url']
+ .
$this->get_query_separator($this->options['script_url'])
+ . $this->get_singular_param_name()
+ . '=' . rawurlencode($file->name);
+ $file->deleteType = $this->options['delete_type'];
+ if ($file->deleteType !== 'DELETE')
+ {
+ $file->deleteUrl .= '&_method=DELETE';
+ }
+ if ($this->options['access_control_allow_credentials'])
+ {
+ $file->deleteWithCredentials = true;
+ }
+ }
- protected function get_download_url($file_name, $version = null, $direct =
false) {
- if (!$direct && $this->options['download_via_php']) {
- $url = $this->options['script_url']
- .$this->get_query_separator($this->options['script_url'])
- .$this->get_singular_param_name()
- .'='.rawurlencode($file_name);
- if ($version) {
- $url .= '&version='.rawurlencode($version);
- }
- return $url.'&download=1';
- }
- if (empty($version)) {
- $version_path = '';
- } else {
- $version_url =
@$this->options['image_versions'][$version]['upload_url'];
- if ($version_url) {
- return
$version_url.$this->get_user_path().rawurlencode($file_name);
- }
- $version_path = rawurlencode($version).'/';
- }
- return $this->options['upload_url'].$this->get_user_path()
- .$version_path.rawurlencode($file_name);
- }
+ // Fix for overflowing signed 32 bit integers,
+ // works for sizes up to 2^32-1 bytes (4 GiB - 1):
+ protected function fix_integer_overflow( $size )
+ {
+ if ($size < 0)
+ {
+ $size += 2.0 * (PHP_INT_MAX + 1);
+ }
+ return $size;
+ }
- protected function set_additional_file_properties($file) {
- $file->deleteUrl = $this->options['script_url']
- .$this->get_query_separator($this->options['script_url'])
- .$this->get_singular_param_name()
- .'='.rawurlencode($file->name);
- $file->deleteType = $this->options['delete_type'];
- if ($file->deleteType !== 'DELETE') {
- $file->deleteUrl .= '&_method=DELETE';
- }
- if ($this->options['access_control_allow_credentials']) {
- $file->deleteWithCredentials = true;
- }
- }
+ protected function get_file_size( $file_path, $clear_stat_cache
= false )
+ {
+ if ($clear_stat_cache)
+ {
+ if (version_compare(PHP_VERSION, '5.3.0') >= 0)
+ {
+ clearstatcache(true, $file_path);
+ }
+ else
+ {
+ clearstatcache();
+ }
+ }
+ return
$this->fix_integer_overflow(filesize($file_path));
+ }
- // Fix for overflowing signed 32 bit integers,
- // works for sizes up to 2^32-1 bytes (4 GiB - 1):
- protected function fix_integer_overflow($size) {
- if ($size < 0) {
- $size += 2.0 * (PHP_INT_MAX + 1);
- }
- return $size;
- }
+ protected function is_valid_file_object( $file_name )
+ {
+ $file_path = $this->get_upload_path($file_name);
+ if (is_file($file_path) && $file_name[0] !== '.')
+ {
+ return true;
+ }
+ return false;
+ }
- protected function get_file_size($file_path, $clear_stat_cache = false) {
- if ($clear_stat_cache) {
- if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
- clearstatcache(true, $file_path);
- } else {
- clearstatcache();
- }
- }
- return $this->fix_integer_overflow(filesize($file_path));
- }
+ protected function get_file_object( $file_name )
+ {
+ if ($this->is_valid_file_object($file_name))
+ {
+ $file = new \stdClass();
+ $file->name = $file_name;
+ $file->size = $this->get_file_size(
+ $this->get_upload_path($file_name)
+ );
+ $file->url =
$this->get_download_url($file->name);
+ foreach ($this->options['image_versions'] as
$version => $options)
+ {
+ if (!empty($version))
+ {
+ if
(is_file($this->get_upload_path($file_name, $version)))
+ {
+ $file->{$version .
'Url'} = $this->get_download_url(
+ $file->name,
$version
+ );
+ }
+ }
+ }
+ $this->set_additional_file_properties($file);
+ return $file;
+ }
+ return null;
+ }
- protected function is_valid_file_object($file_name) {
- $file_path = $this->get_upload_path($file_name);
- if (is_file($file_path) && $file_name[0] !== '.') {
- return true;
- }
- return false;
- }
+ protected function get_file_objects( $iteration_method =
'get_file_object' )
+ {
+ $upload_dir = $this->get_upload_path();
+ if (!is_dir($upload_dir))
+ {
+ return array();
+ }
+ return array_values(array_filter(array_map(
+ array($this,
$iteration_method), scandir($upload_dir)
+ )));
+ }
- protected function get_file_object($file_name) {
- if ($this->is_valid_file_object($file_name)) {
- $file = new \stdClass();
- $file->name = $file_name;
- $file->size = $this->get_file_size(
- $this->get_upload_path($file_name)
- );
- $file->url = $this->get_download_url($file->name);
- foreach ($this->options['image_versions'] as $version => $options)
{
- if (!empty($version)) {
- if (is_file($this->get_upload_path($file_name, $version)))
{
- $file->{$version.'Url'} = $this->get_download_url(
- $file->name,
- $version
- );
- }
- }
- }
- $this->set_additional_file_properties($file);
- return $file;
- }
- return null;
- }
+ protected function count_file_objects()
+ {
+ return
count($this->get_file_objects('is_valid_file_object'));
+ }
- protected function get_file_objects($iteration_method = 'get_file_object')
{
- $upload_dir = $this->get_upload_path();
- if (!is_dir($upload_dir)) {
- return array();
- }
- return array_values(array_filter(array_map(
- array($this, $iteration_method),
- scandir($upload_dir)
- )));
- }
+ protected function get_error_message( $error )
+ {
+ return isset($this->error_messages[$error]) ?
+ $this->error_messages[$error] : $error;
+ }
- protected function count_file_objects() {
- return count($this->get_file_objects('is_valid_file_object'));
- }
+ public function get_config_bytes( $val )
+ {
+ $val = trim($val);
+ $last = strtolower($val[strlen($val) - 1]);
+ $val = (int)$val;
+ switch ($last)
+ {
+ case 'g':
+ $val *= 1024;
+ case 'm':
+ $val *= 1024;
+ case 'k':
+ $val *= 1024;
+ }
+ return $this->fix_integer_overflow($val);
+ }
- protected function get_error_message($error) {
- return isset($this->error_messages[$error]) ?
- $this->error_messages[$error] : $error;
- }
+ protected function validate( $uploaded_file, $file, $error,
$index )
+ {
+ if ($error)
+ {
+ $file->error = $this->get_error_message($error);
+ return false;
+ }
+ $content_length = $this->fix_integer_overflow(
+ (int)$this->get_server_var('CONTENT_LENGTH')
+ );
+ $post_max_size =
$this->get_config_bytes(ini_get('post_max_size'));
+ if ($post_max_size && ($content_length >
$post_max_size))
+ {
+ $file->error =
$this->get_error_message('post_max_size');
+ return false;
+ }
+ if (!preg_match($this->options['accept_file_types'],
$file->name))
+ {
+ $file->error =
$this->get_error_message('accept_file_types');
+ return false;
+ }
+ if ($uploaded_file && is_uploaded_file($uploaded_file))
+ {
+ $file_size =
$this->get_file_size($uploaded_file);
+ }
+ else
+ {
+ $file_size = $content_length;
+ }
+ if ($this->options['max_file_size'] && (
+ $file_size > $this->options['max_file_size'] ||
+ $file->size > $this->options['max_file_size'])
+ )
+ {
+ $file->error =
$this->get_error_message('max_file_size');
+ return false;
+ }
+ if ($this->options['min_file_size'] &&
+ $file_size < $this->options['min_file_size'])
+ {
+ $file->error =
$this->get_error_message('min_file_size');
+ return false;
+ }
+ if (is_int($this->options['max_number_of_files']) &&
+ ($this->count_file_objects() >=
$this->options['max_number_of_files']) &&
+ // Ignore additional chunks of existing files:
+ !is_file($this->get_upload_path($file->name)))
+ {
+ $file->error =
$this->get_error_message('max_number_of_files');
+ return false;
+ }
+ $max_width = @$this->options['max_width'];
+ $max_height = @$this->options['max_height'];
+ $min_width = @$this->options['min_width'];
+ $min_height = @$this->options['min_height'];
+ if (($max_width || $max_height || $min_width ||
$min_height) && preg_match($this->options['image_file_types'], $file->name))
+ {
+ list($img_width, $img_height) =
$this->get_image_size($uploaded_file);
- public function get_config_bytes($val) {
- $val = trim($val);
- $last = strtolower($val[strlen($val)-1]);
- $val = (int)$val;
- switch ($last) {
- case 'g':
- $val *= 1024;
- case 'm':
- $val *= 1024;
- case 'k':
- $val *= 1024;
- }
- return $this->fix_integer_overflow($val);
- }
+ // If we are auto rotating the image by
default, do the checks on
+ // the correct orientation
+ if (
+
@$this->options['image_versions']['']['auto_orient'] &&
+ function_exists('exif_read_data') &&
+ ($exif =
@exif_read_data($uploaded_file)) &&
+ (((int)@$exif['Orientation']) >= 5)
+ )
+ {
+ $tmp = $img_width;
+ $img_width = $img_height;
+ $img_height = $tmp;
+ unset($tmp);
+ }
+ }
+ if (!empty($img_width))
+ {
+ if ($max_width && $img_width > $max_width)
+ {
+ $file->error =
$this->get_error_message('max_width');
+ return false;
+ }
+ if ($max_height && $img_height > $max_height)
+ {
+ $file->error =
$this->get_error_message('max_height');
+ return false;
+ }
+ if ($min_width && $img_width < $min_width)
+ {
+ $file->error =
$this->get_error_message('min_width');
+ return false;
+ }
+ if ($min_height && $img_height < $min_height)
+ {
+ $file->error =
$this->get_error_message('min_height');
+ return false;
+ }
+ }
+ return true;
+ }
- protected function validate($uploaded_file, $file, $error, $index) {
- if ($error) {
- $file->error = $this->get_error_message($error);
- return false;
- }
- $content_length = $this->fix_integer_overflow(
- (int)$this->get_server_var('CONTENT_LENGTH')
- );
- $post_max_size = $this->get_config_bytes(ini_get('post_max_size'));
- if ($post_max_size && ($content_length > $post_max_size)) {
- $file->error = $this->get_error_message('post_max_size');
- return false;
- }
- if (!preg_match($this->options['accept_file_types'], $file->name)) {
- $file->error = $this->get_error_message('accept_file_types');
- return false;
- }
- if ($uploaded_file && is_uploaded_file($uploaded_file)) {
- $file_size = $this->get_file_size($uploaded_file);
- } else {
- $file_size = $content_length;
- }
- if ($this->options['max_file_size'] && (
- $file_size > $this->options['max_file_size'] ||
- $file->size > $this->options['max_file_size'])
- ) {
- $file->error = $this->get_error_message('max_file_size');
- return false;
- }
- if ($this->options['min_file_size'] &&
- $file_size < $this->options['min_file_size']) {
- $file->error = $this->get_error_message('min_file_size');
- return false;
- }
- if (is_int($this->options['max_number_of_files']) &&
- ($this->count_file_objects() >=
$this->options['max_number_of_files']) &&
- // Ignore additional chunks of existing files:
- !is_file($this->get_upload_path($file->name))) {
- $file->error = $this->get_error_message('max_number_of_files');
- return false;
- }
- $max_width = @$this->options['max_width'];
- $max_height = @$this->options['max_height'];
- $min_width = @$this->options['min_width'];
- $min_height = @$this->options['min_height'];
- if (($max_width || $max_height || $min_width || $min_height)
- && preg_match($this->options['image_file_types'], $file->name)) {
- list($img_width, $img_height) =
$this->get_image_size($uploaded_file);
+ protected function upcount_name_callback( $matches )
+ {
+ $index = isset($matches[1]) ? ((int)$matches[1]) + 1 :
1;
+ $ext = isset($matches[2]) ? $matches[2] : '';
+ return ' (' . $index . ')' . $ext;
+ }
- // If we are auto rotating the image by default, do the checks on
- // the correct orientation
- if (
- @$this->options['image_versions']['']['auto_orient'] &&
- function_exists('exif_read_data') &&
- ($exif = @exif_read_data($uploaded_file)) &&
- (((int) @$exif['Orientation']) >= 5)
- ) {
- $tmp = $img_width;
- $img_width = $img_height;
- $img_height = $tmp;
- unset($tmp);
- }
+ protected function upcount_name( $name )
+ {
+ return preg_replace_callback(
+ '/(?:(?: \(([\d]+)\))?(\.[^.]+))?$/',
array($this, 'upcount_name_callback'), $name, 1
+ );
+ }
- }
- if (!empty($img_width)) {
- if ($max_width && $img_width > $max_width) {
- $file->error = $this->get_error_message('max_width');
- return false;
- }
- if ($max_height && $img_height > $max_height) {
- $file->error = $this->get_error_message('max_height');
- return false;
- }
- if ($min_width && $img_width < $min_width) {
- $file->error = $this->get_error_message('min_width');
- return false;
- }
- if ($min_height && $img_height < $min_height) {
- $file->error = $this->get_error_message('min_height');
- return false;
- }
- }
- return true;
- }
+ protected function get_unique_filename( $file_path, $name,
$size, $type, $error, $index, $content_range )
+ {
+ while (is_dir($this->get_upload_path($name)))
+ {
+ $name = $this->upcount_name($name);
+ }
+ // Keep an existing filename if this is part of a
chunked upload:
+ $uploaded_bytes =
$this->fix_integer_overflow((int)$content_range[1]);
+ while (is_file($this->get_upload_path($name)))
+ {
+ if ($uploaded_bytes === $this->get_file_size(
+ $this->get_upload_path($name)))
+ {
+ break;
+ }
+ $name = $this->upcount_name($name);
+ }
+ return $name;
+ }
- protected function upcount_name_callback($matches) {
- $index = isset($matches[1]) ? ((int)$matches[1]) + 1 : 1;
- $ext = isset($matches[2]) ? $matches[2] : '';
- return ' ('.$index.')'.$ext;
- }
+ protected function fix_file_extension( $file_path, $name,
$size, $type, $error, $index, $content_range )
+ {
+ // Add missing file extension for known image types:
+ if (strpos($name, '.') === false &&
+ preg_match('/^image\/(gif|jpe?g|png)/', $type,
$matches))
+ {
+ $name .= '.' . $matches[1];
+ }
+ if ($this->options['correct_image_extensions'] &&
+ function_exists('exif_imagetype'))
+ {
+ switch (@exif_imagetype($file_path))
+ {
+ case IMAGETYPE_JPEG:
+ $extensions = array('jpg',
'jpeg');
+ break;
+ case IMAGETYPE_PNG:
+ $extensions = array('png');
+ break;
+ case IMAGETYPE_GIF:
+ $extensions = array('gif');
+ break;
+ }
+ // Adjust incorrect image file extensions:
+ if (!empty($extensions))
+ {
+ $parts = explode('.', $name);
+ $extIndex = count($parts) - 1;
+ $ext = strtolower(@$parts[$extIndex]);
+ if (!in_array($ext, $extensions))
+ {
+ $parts[$extIndex] =
$extensions[0];
+ $name = implode('.', $parts);
+ }
+ }
+ }
+ return $name;
+ }
- protected function upcount_name($name) {
- return preg_replace_callback(
- '/(?:(?: \(([\d]+)\))?(\.[^.]+))?$/',
- array($this, 'upcount_name_callback'),
- $name,
- 1
- );
- }
+ protected function trim_file_name( $file_path, $name, $size,
$type, $error, $index, $content_range )
+ {
+ // Remove path information and dots around the
filename, to prevent uploading
+ // into different directories or replacing hidden
system files.
+ // Also remove control characters and spaces
(\x00..\x20) around the filename:
+ $name = trim($this->basename(stripslashes($name)),
".\x00..\x20");
+ // Use a timestamp for empty filenames:
+ if (!$name)
+ {
+ $name = str_replace('.', '-', microtime(true));
+ }
+ return $name;
+ }
- protected function get_unique_filename($file_path, $name, $size, $type,
$error,
- $index, $content_range) {
- while(is_dir($this->get_upload_path($name))) {
- $name = $this->upcount_name($name);
- }
- // Keep an existing filename if this is part of a chunked upload:
- $uploaded_bytes = $this->fix_integer_overflow((int)$content_range[1]);
- while (is_file($this->get_upload_path($name))) {
- if ($uploaded_bytes === $this->get_file_size(
- $this->get_upload_path($name))) {
- break;
- }
- $name = $this->upcount_name($name);
- }
- return $name;
- }
+ protected function get_file_name( $file_path, $name, $size,
$type, $error, $index, $content_range )
+ {
+ $name = $this->trim_file_name($file_path, $name, $size,
$type, $error, $index, $content_range);
+ return $this->get_unique_filename(
+ $file_path,
$this->fix_file_extension($file_path, $name, $size, $type, $error, $index,
$content_range), $size, $type, $error, $index, $content_range
+ );
+ }
- protected function fix_file_extension($file_path, $name, $size, $type,
$error,
- $index, $content_range) {
- // Add missing file extension for known image types:
- if (strpos($name, '.') === false &&
- preg_match('/^image\/(gif|jpe?g|png)/', $type, $matches)) {
- $name .= '.'.$matches[1];
- }
- if ($this->options['correct_image_extensions'] &&
- function_exists('exif_imagetype')) {
- switch (@exif_imagetype($file_path)){
- case IMAGETYPE_JPEG:
- $extensions = array('jpg', 'jpeg');
- break;
- case IMAGETYPE_PNG:
- $extensions = array('png');
- break;
- case IMAGETYPE_GIF:
- $extensions = array('gif');
- break;
- }
- // Adjust incorrect image file extensions:
- if (!empty($extensions)) {
- $parts = explode('.', $name);
- $extIndex = count($parts) - 1;
- $ext = strtolower(@$parts[$extIndex]);
- if (!in_array($ext, $extensions)) {
- $parts[$extIndex] = $extensions[0];
- $name = implode('.', $parts);
- }
- }
- }
- return $name;
- }
+ protected function get_scaled_image_file_paths( $file_name,
$version )
+ {
+ $file_path = $this->get_upload_path($file_name);
+ if (!empty($version))
+ {
+ $version_dir = $this->get_upload_path(null,
$version);
+ if (!is_dir($version_dir))
+ {
+ mkdir($version_dir,
$this->options['mkdir_mode'], true);
+ }
+ $new_file_path = $version_dir . '/' .
$file_name;
+ }
+ else
+ {
+ $new_file_path = $file_path;
+ }
+ return array($file_path, $new_file_path);
+ }
- protected function trim_file_name($file_path, $name, $size, $type, $error,
- $index, $content_range) {
- // Remove path information and dots around the filename, to prevent
uploading
- // into different directories or replacing hidden system files.
- // Also remove control characters and spaces (\x00..\x20) around the
filename:
- $name = trim($this->basename(stripslashes($name)), ".\x00..\x20");
- // Use a timestamp for empty filenames:
- if (!$name) {
- $name = str_replace('.', '-', microtime(true));
- }
- return $name;
- }
+ protected function gd_get_image_object( $file_path, $func,
$no_cache = false )
+ {
+ if (empty($this->image_objects[$file_path]) ||
$no_cache)
+ {
+ $this->gd_destroy_image_object($file_path);
+ $this->image_objects[$file_path] =
$func($file_path);
+ }
+ return $this->image_objects[$file_path];
+ }
- protected function get_file_name($file_path, $name, $size, $type, $error,
- $index, $content_range) {
- $name = $this->trim_file_name($file_path, $name, $size, $type, $error,
- $index, $content_range);
- return $this->get_unique_filename(
- $file_path,
- $this->fix_file_extension($file_path, $name, $size, $type, $error,
- $index, $content_range),
- $size,
- $type,
- $error,
- $index,
- $content_range
- );
- }
+ protected function gd_set_image_object( $file_path, $image )
+ {
+ $this->gd_destroy_image_object($file_path);
+ $this->image_objects[$file_path] = $image;
+ }
- protected function get_scaled_image_file_paths($file_name, $version) {
- $file_path = $this->get_upload_path($file_name);
- if (!empty($version)) {
- $version_dir = $this->get_upload_path(null, $version);
- if (!is_dir($version_dir)) {
- mkdir($version_dir, $this->options['mkdir_mode'], true);
- }
- $new_file_path = $version_dir.'/'.$file_name;
- } else {
- $new_file_path = $file_path;
- }
- return array($file_path, $new_file_path);
- }
+ protected function gd_destroy_image_object( $file_path )
+ {
+ $image = (isset($this->image_objects[$file_path])) ?
$this->image_objects[$file_path] : null;
+ return $image && imagedestroy($image);
+ }
- protected function gd_get_image_object($file_path, $func, $no_cache =
false) {
- if (empty($this->image_objects[$file_path]) || $no_cache) {
- $this->gd_destroy_image_object($file_path);
- $this->image_objects[$file_path] = $func($file_path);
- }
- return $this->image_objects[$file_path];
- }
+ protected function gd_imageflip( $image, $mode )
+ {
+ if (function_exists('imageflip'))
+ {
+ return imageflip($image, $mode);
+ }
+ $new_width = $src_width = imagesx($image);
+ $new_height = $src_height = imagesy($image);
+ $new_img = imagecreatetruecolor($new_width,
$new_height);
+ $src_x = 0;
+ $src_y = 0;
+ switch ($mode)
+ {
+ case '1': // flip on the horizontal axis
+ $src_y = $new_height - 1;
+ $src_height = -$new_height;
+ break;
+ case '2': // flip on the vertical axis
+ $src_x = $new_width - 1;
+ $src_width = -$new_width;
+ break;
+ case '3': // flip on both axes
+ $src_y = $new_height - 1;
+ $src_height = -$new_height;
+ $src_x = $new_width - 1;
+ $src_width = -$new_width;
+ break;
+ default:
+ return $image;
+ }
+ imagecopyresampled(
+ $new_img, $image, 0, 0, $src_x, $src_y,
$new_width, $new_height, $src_width, $src_height
+ );
+ return $new_img;
+ }
- protected function gd_set_image_object($file_path, $image) {
- $this->gd_destroy_image_object($file_path);
- $this->image_objects[$file_path] = $image;
- }
+ protected function gd_orient_image( $file_path, $src_img )
+ {
+ if (!function_exists('exif_read_data'))
+ {
+ return false;
+ }
+ $exif = @exif_read_data($file_path);
+ if ($exif === false)
+ {
+ return false;
+ }
+ $orientation = (int)@$exif['Orientation'];
+ if ($orientation < 2 || $orientation > 8)
+ {
+ return false;
+ }
+ switch ($orientation)
+ {
+ case 2:
+ $new_img = $this->gd_imageflip(
+ $src_img,
defined('IMG_FLIP_VERTICAL') ? IMG_FLIP_VERTICAL : 2
+ );
+ break;
+ case 3:
+ $new_img = imagerotate($src_img, 180,
0);
+ break;
+ case 4:
+ $new_img = $this->gd_imageflip(
+ $src_img,
defined('IMG_FLIP_HORIZONTAL') ? IMG_FLIP_HORIZONTAL : 1
+ );
+ break;
+ case 5:
+ $tmp_img = $this->gd_imageflip(
+ $src_img,
defined('IMG_FLIP_HORIZONTAL') ? IMG_FLIP_HORIZONTAL : 1
+ );
+ $new_img = imagerotate($tmp_img, 270,
0);
+ imagedestroy($tmp_img);
+ break;
+ case 6:
+ $new_img = imagerotate($src_img, 270,
0);
+ break;
+ case 7:
+ $tmp_img = $this->gd_imageflip(
+ $src_img,
defined('IMG_FLIP_VERTICAL') ? IMG_FLIP_VERTICAL : 2
+ );
+ $new_img = imagerotate($tmp_img, 270,
0);
+ imagedestroy($tmp_img);
+ break;
+ case 8:
+ $new_img = imagerotate($src_img, 90, 0);
+ break;
+ default:
+ return false;
+ }
+ $this->gd_set_image_object($file_path, $new_img);
+ return true;
+ }
- protected function gd_destroy_image_object($file_path) {
- $image = (isset($this->image_objects[$file_path])) ?
$this->image_objects[$file_path] : null ;
- return $image && imagedestroy($image);
- }
+ protected function gd_create_scaled_image( $file_name,
$version, $options )
+ {
+ if (!function_exists('imagecreatetruecolor'))
+ {
+ error_log('Function not found:
imagecreatetruecolor');
+ return false;
+ }
+ list($file_path, $new_file_path) =
$this->get_scaled_image_file_paths($file_name, $version);
+ $type = strtolower(substr(strrchr($file_name, '.'), 1));
+ switch ($type)
+ {
+ case 'jpg':
+ case 'jpeg':
+ $src_func = 'imagecreatefromjpeg';
+ $write_func = 'imagejpeg';
+ $image_quality =
isset($options['jpeg_quality']) ?
+ $options['jpeg_quality'] : 75;
+ break;
+ case 'gif':
+ $src_func = 'imagecreatefromgif';
+ $write_func = 'imagegif';
+ $image_quality = null;
+ break;
+ case 'png':
+ $src_func = 'imagecreatefrompng';
+ $write_func = 'imagepng';
+ $image_quality =
isset($options['png_quality']) ?
+ $options['png_quality'] : 9;
+ break;
+ default:
+ return false;
+ }
+ $src_img = $this->gd_get_image_object(
+ $file_path, $src_func,
!empty($options['no_cache'])
+ );
+ $image_oriented = false;
+ if (!empty($options['auto_orient']) &&
$this->gd_orient_image(
+ $file_path, $src_img
+ ))
+ {
+ $image_oriented = true;
+ $src_img = $this->gd_get_image_object(
+ $file_path, $src_func
+ );
+ }
+ $max_width = $img_width = imagesx($src_img);
+ $max_height = $img_height = imagesy($src_img);
+ if (!empty($options['max_width']))
+ {
+ $max_width = $options['max_width'];
+ }
+ if (!empty($options['max_height']))
+ {
+ $max_height = $options['max_height'];
+ }
+ $scale = min(
+ $max_width / $img_width, $max_height /
$img_height
+ );
+ if ($scale >= 1)
+ {
+ if ($image_oriented)
+ {
+ return $write_func($src_img,
$new_file_path, $image_quality);
+ }
+ if ($file_path !== $new_file_path)
+ {
+ return copy($file_path, $new_file_path);
+ }
+ return true;
+ }
+ if (empty($options['crop']))
+ {
+ $new_width = $img_width * $scale;
+ $new_height = $img_height * $scale;
+ $dst_x = 0;
+ $dst_y = 0;
+ $new_img = imagecreatetruecolor($new_width,
$new_height);
+ }
+ else
+ {
+ if (($img_width / $img_height) >= ($max_width /
$max_height))
+ {
+ $new_width = $img_width / ($img_height
/ $max_height);
+ $new_height = $max_height;
+ }
+ else
+ {
+ $new_width = $max_width;
+ $new_height = $img_height / ($img_width
/ $max_width);
+ }
+ $dst_x = 0 - ($new_width - $max_width) / 2;
+ $dst_y = 0 - ($new_height - $max_height) / 2;
+ $new_img = imagecreatetruecolor($max_width,
$max_height);
+ }
+ // Handle transparency in GIF and PNG images:
+ switch ($type)
+ {
+ case 'gif':
+ case 'png':
+ imagecolortransparent($new_img,
imagecolorallocate($new_img, 0, 0, 0));
+ case 'png':
+ imagealphablending($new_img, false);
+ imagesavealpha($new_img, true);
+ break;
+ }
+ $success = imagecopyresampled(
+ $new_img, $src_img, $dst_x, $dst_y, 0,
0, $new_width, $new_height, $img_width, $img_height
+ ) && $write_func($new_img, $new_file_path,
$image_quality);
+ $this->gd_set_image_object($file_path, $new_img);
+ return $success;
+ }
- protected function gd_imageflip($image, $mode) {
- if (function_exists('imageflip')) {
- return imageflip($image, $mode);
- }
- $new_width = $src_width = imagesx($image);
- $new_height = $src_height = imagesy($image);
- $new_img = imagecreatetruecolor($new_width, $new_height);
- $src_x = 0;
- $src_y = 0;
- switch ($mode) {
- case '1': // flip on the horizontal axis
- $src_y = $new_height - 1;
- $src_height = -$new_height;
- break;
- case '2': // flip on the vertical axis
- $src_x = $new_width - 1;
- $src_width = -$new_width;
- break;
- case '3': // flip on both axes
- $src_y = $new_height - 1;
- $src_height = -$new_height;
- $src_x = $new_width - 1;
- $src_width = -$new_width;
- break;
- default:
- return $image;
- }
- imagecopyresampled(
- $new_img,
- $image,
- 0,
- 0,
- $src_x,
- $src_y,
- $new_width,
- $new_height,
- $src_width,
- $src_height
- );
- return $new_img;
- }
+ protected function imagick_get_image_object( $file_path,
$no_cache = false )
+ {
+ if (empty($this->image_objects[$file_path]) ||
$no_cache)
+ {
+ $this->imagick_destroy_image_object($file_path);
+ $image = new \Imagick();
+ if
(!empty($this->options['imagick_resource_limits']))
+ {
+ foreach
($this->options['imagick_resource_limits'] as $type => $limit)
+ {
+ $image->setResourceLimit($type,
$limit);
+ }
+ }
+ $image->readImage($file_path);
+ $this->image_objects[$file_path] = $image;
+ }
+ return $this->image_objects[$file_path];
+ }
- protected function gd_orient_image($file_path, $src_img) {
- if (!function_exists('exif_read_data')) {
- return false;
- }
- $exif = @exif_read_data($file_path);
- if ($exif === false) {
- return false;
- }
- $orientation = (int)@$exif['Orientation'];
- if ($orientation < 2 || $orientation > 8) {
- return false;
- }
- switch ($orientation) {
- case 2:
- $new_img = $this->gd_imageflip(
- $src_img,
- defined('IMG_FLIP_VERTICAL') ? IMG_FLIP_VERTICAL : 2
- );
- break;
- case 3:
- $new_img = imagerotate($src_img, 180, 0);
- break;
- case 4:
- $new_img = $this->gd_imageflip(
- $src_img,
- defined('IMG_FLIP_HORIZONTAL') ? IMG_FLIP_HORIZONTAL : 1
- );
- break;
- case 5:
- $tmp_img = $this->gd_imageflip(
- $src_img,
- defined('IMG_FLIP_HORIZONTAL') ? IMG_FLIP_HORIZONTAL : 1
- );
- $new_img = imagerotate($tmp_img, 270, 0);
- imagedestroy($tmp_img);
- break;
- case 6:
- $new_img = imagerotate($src_img, 270, 0);
- break;
- case 7:
- $tmp_img = $this->gd_imageflip(
- $src_img,
- defined('IMG_FLIP_VERTICAL') ? IMG_FLIP_VERTICAL : 2
- );
- $new_img = imagerotate($tmp_img, 270, 0);
- imagedestroy($tmp_img);
- break;
- case 8:
- $new_img = imagerotate($src_img, 90, 0);
- break;
- default:
- return false;
- }
- $this->gd_set_image_object($file_path, $new_img);
- return true;
- }
+ protected function imagick_set_image_object( $file_path, $image
)
+ {
+ $this->imagick_destroy_image_object($file_path);
+ $this->image_objects[$file_path] = $image;
+ }
- protected function gd_create_scaled_image($file_name, $version, $options) {
- if (!function_exists('imagecreatetruecolor')) {
- error_log('Function not found: imagecreatetruecolor');
- return false;
- }
- list($file_path, $new_file_path) =
- $this->get_scaled_image_file_paths($file_name, $version);
- $type = strtolower(substr(strrchr($file_name, '.'), 1));
- switch ($type) {
- case 'jpg':
- case 'jpeg':
- $src_func = 'imagecreatefromjpeg';
- $write_func = 'imagejpeg';
- $image_quality = isset($options['jpeg_quality']) ?
- $options['jpeg_quality'] : 75;
- break;
- case 'gif':
- $src_func = 'imagecreatefromgif';
- $write_func = 'imagegif';
- $image_quality = null;
- break;
- case 'png':
- $src_func = 'imagecreatefrompng';
- $write_func = 'imagepng';
- $image_quality = isset($options['png_quality']) ?
- $options['png_quality'] : 9;
- break;
- default:
- return false;
- }
- $src_img = $this->gd_get_image_object(
- $file_path,
- $src_func,
- !empty($options['no_cache'])
- );
- $image_oriented = false;
- if (!empty($options['auto_orient']) && $this->gd_orient_image(
- $file_path,
- $src_img
- )) {
- $image_oriented = true;
- $src_img = $this->gd_get_image_object(
- $file_path,
- $src_func
- );
- }
- $max_width = $img_width = imagesx($src_img);
- $max_height = $img_height = imagesy($src_img);
- if (!empty($options['max_width'])) {
- $max_width = $options['max_width'];
- }
- if (!empty($options['max_height'])) {
- $max_height = $options['max_height'];
- }
- $scale = min(
- $max_width / $img_width,
- $max_height / $img_height
- );
- if ($scale >= 1) {
- if ($image_oriented) {
- return $write_func($src_img, $new_file_path, $image_quality);
- }
- if ($file_path !== $new_file_path) {
- return copy($file_path, $new_file_path);
- }
- return true;
- }
- if (empty($options['crop'])) {
- $new_width = $img_width * $scale;
- $new_height = $img_height * $scale;
- $dst_x = 0;
- $dst_y = 0;
- $new_img = imagecreatetruecolor($new_width, $new_height);
- } else {
- if (($img_width / $img_height) >= ($max_width / $max_height)) {
- $new_width = $img_width / ($img_height / $max_height);
- $new_height = $max_height;
- } else {
- $new_width = $max_width;
- $new_height = $img_height / ($img_width / $max_width);
- }
- $dst_x = 0 - ($new_width - $max_width) / 2;
- $dst_y = 0 - ($new_height - $max_height) / 2;
- $new_img = imagecreatetruecolor($max_width, $max_height);
- }
- // Handle transparency in GIF and PNG images:
- switch ($type) {
- case 'gif':
- case 'png':
- imagecolortransparent($new_img, imagecolorallocate($new_img,
0, 0, 0));
- case 'png':
- imagealphablending($new_img, false);
- imagesavealpha($new_img, true);
- break;
- }
- $success = imagecopyresampled(
- $new_img,
- $src_img,
- $dst_x,
- $dst_y,
- 0,
- 0,
- $new_width,
- $new_height,
- $img_width,
- $img_height
- ) && $write_func($new_img, $new_file_path, $image_quality);
- $this->gd_set_image_object($file_path, $new_img);
- return $success;
- }
+ protected function imagick_destroy_image_object( $file_path )
+ {
+ $image = (isset($this->image_objects[$file_path])) ?
$this->image_objects[$file_path] : null;
+ return $image && $image->destroy();
+ }
- protected function imagick_get_image_object($file_path, $no_cache = false)
{
- if (empty($this->image_objects[$file_path]) || $no_cache) {
- $this->imagick_destroy_image_object($file_path);
- $image = new \Imagick();
- if (!empty($this->options['imagick_resource_limits'])) {
- foreach ($this->options['imagick_resource_limits'] as $type =>
$limit) {
- $image->setResourceLimit($type, $limit);
- }
- }
- $image->readImage($file_path);
- $this->image_objects[$file_path] = $image;
- }
- return $this->image_objects[$file_path];
- }
+ protected function imagick_orient_image( $image )
+ {
+ $orientation = $image->getImageOrientation();
+ $background = new \ImagickPixel('none');
+ switch ($orientation)
+ {
+ case \imagick::ORIENTATION_TOPRIGHT: // 2
+ $image->flopImage(); // horizontal flop
around y-axis
+ break;
+ case \imagick::ORIENTATION_BOTTOMRIGHT: // 3
+ $image->rotateImage($background, 180);
+ break;
+ case \imagick::ORIENTATION_BOTTOMLEFT: // 4
+ $image->flipImage(); // vertical flip
around x-axis
+ break;
+ case \imagick::ORIENTATION_LEFTTOP: // 5
+ $image->flopImage(); // horizontal flop
around y-axis
+ $image->rotateImage($background, 270);
+ break;
+ case \imagick::ORIENTATION_RIGHTTOP: // 6
+ $image->rotateImage($background, 90);
+ break;
+ case \imagick::ORIENTATION_RIGHTBOTTOM: // 7
+ $image->flipImage(); // vertical flip
around x-axis
+ $image->rotateImage($background, 270);
+ break;
+ case \imagick::ORIENTATION_LEFTBOTTOM: // 8
+ $image->rotateImage($background, 270);
+ break;
+ default:
+ return false;
+ }
+
$image->setImageOrientation(\imagick::ORIENTATION_TOPLEFT); // 1
+ return true;
+ }
- protected function imagick_set_image_object($file_path, $image) {
- $this->imagick_destroy_image_object($file_path);
- $this->image_objects[$file_path] = $image;
- }
+ protected function imagick_create_scaled_image( $file_name,
$version, $options )
+ {
+ list($file_path, $new_file_path) =
$this->get_scaled_image_file_paths($file_name, $version);
+ $image = $this->imagick_get_image_object(
+ $file_path, !empty($options['crop']) ||
!empty($options['no_cache'])
+ );
+ if ($image->getImageFormat() === 'GIF')
+ {
+ // Handle animated GIFs:
+ $images = $image->coalesceImages();
+ foreach ($images as $frame)
+ {
+ $image = $frame;
+
$this->imagick_set_image_object($file_name, $image);
+ break;
+ }
+ }
+ $image_oriented = false;
+ if (!empty($options['auto_orient']))
+ {
+ $image_oriented =
$this->imagick_orient_image($image);
+ }
+ $new_width = $max_width = $img_width =
$image->getImageWidth();
+ $new_height = $max_height = $img_height =
$image->getImageHeight();
+ if (!empty($options['max_width']))
+ {
+ $new_width = $max_width = $options['max_width'];
+ }
+ if (!empty($options['max_height']))
+ {
+ $new_height = $max_height =
$options['max_height'];
+ }
+ if (!($image_oriented || $max_width < $img_width ||
$max_height < $img_height))
+ {
+ if ($file_path !== $new_file_path)
+ {
+ return copy($file_path, $new_file_path);
+ }
+ return true;
+ }
+ $crop = !empty($options['crop']);
+ if ($crop)
+ {
+ $x = 0;
+ $y = 0;
+ if (($img_width / $img_height) >= ($max_width /
$max_height))
+ {
+ $new_width = 0; // Enables proportional
scaling based on max_height
+ $x = ($img_width / ($img_height /
$max_height) - $max_width) / 2;
+ }
+ else
+ {
+ $new_height = 0; // Enables
proportional scaling based on max_width
+ $y = ($img_height / ($img_width /
$max_width) - $max_height) / 2;
+ }
+ }
+ $success = $image->resizeImage(
+ $new_width, $new_height,
isset($options['filter']) ? $options['filter'] : \imagick::FILTER_LANCZOS,
isset($options['blur']) ? $options['blur'] : 1, $new_width && $new_height //
fit image into constraints if not to be cropped
+ );
+ if ($success && $crop)
+ {
+ $success = $image->cropImage(
+ $max_width, $max_height, $x, $y
+ );
+ if ($success)
+ {
+ $success =
$image->setImagePage($max_width, $max_height, 0, 0);
+ }
+ }
+ $type = strtolower(substr(strrchr($file_name, '.'), 1));
+ switch ($type)
+ {
+ case 'jpg':
+ case 'jpeg':
+ if (!empty($options['jpeg_quality']))
+ {
+
$image->setImageCompression(\imagick::COMPRESSION_JPEG);
+
$image->setImageCompressionQuality($options['jpeg_quality']);
+ }
+ break;
+ }
+ if (!empty($options['strip']))
+ {
+ $image->stripImage();
+ }
+ return $success && $image->writeImage($new_file_path);
+ }
- protected function imagick_destroy_image_object($file_path) {
- $image = (isset($this->image_objects[$file_path])) ?
$this->image_objects[$file_path] : null ;
- return $image && $image->destroy();
- }
+ protected function imagemagick_create_scaled_image( $file_name,
$version, $options )
+ {
+ list($file_path, $new_file_path) =
$this->get_scaled_image_file_paths($file_name, $version);
+ $resize = @$options['max_width']
+ . (empty($options['max_height']) ? '' : 'X' .
$options['max_height']);
+ if (!$resize && empty($options['auto_orient']))
+ {
+ if ($file_path !== $new_file_path)
+ {
+ return copy($file_path, $new_file_path);
+ }
+ return true;
+ }
+ $cmd = $this->options['convert_bin'];
+ if (!empty($this->options['convert_params']))
+ {
+ $cmd .= ' ' . $this->options['convert_params'];
+ }
+ $cmd .= ' ' . escapeshellarg($file_path);
+ if (!empty($options['auto_orient']))
+ {
+ $cmd .= ' -auto-orient';
+ }
+ if ($resize)
+ {
+ // Handle animated GIFs:
+ $cmd .= ' -coalesce';
+ if (empty($options['crop']))
+ {
+ $cmd .= ' -resize ' .
escapeshellarg($resize . '>');
+ }
+ else
+ {
+ $cmd .= ' -resize ' .
escapeshellarg($resize . '^');
+ $cmd .= ' -gravity center';
+ $cmd .= ' -crop ' .
escapeshellarg($resize . '+0+0');
+ }
+ // Make sure the page dimensions are correct
(fixes offsets of animated GIFs):
+ $cmd .= ' +repage';
+ }
+ if (!empty($options['convert_params']))
+ {
+ $cmd .= ' ' . $options['convert_params'];
+ }
+ $cmd .= ' ' . escapeshellarg($new_file_path);
+ exec($cmd, $output, $error);
+ if ($error)
+ {
+ error_log(implode('\n', $output));
+ return false;
+ }
+ return true;
+ }
- protected function imagick_orient_image($image) {
- $orientation = $image->getImageOrientation();
- $background = new \ImagickPixel('none');
- switch ($orientation) {
- case \imagick::ORIENTATION_TOPRIGHT: // 2
- $image->flopImage(); // horizontal flop around y-axis
- break;
- case \imagick::ORIENTATION_BOTTOMRIGHT: // 3
- $image->rotateImage($background, 180);
- break;
- case \imagick::ORIENTATION_BOTTOMLEFT: // 4
- $image->flipImage(); // vertical flip around x-axis
- break;
- case \imagick::ORIENTATION_LEFTTOP: // 5
- $image->flopImage(); // horizontal flop around y-axis
- $image->rotateImage($background, 270);
- break;
- case \imagick::ORIENTATION_RIGHTTOP: // 6
- $image->rotateImage($background, 90);
- break;
- case \imagick::ORIENTATION_RIGHTBOTTOM: // 7
- $image->flipImage(); // vertical flip around x-axis
- $image->rotateImage($background, 270);
- break;
- case \imagick::ORIENTATION_LEFTBOTTOM: // 8
- $image->rotateImage($background, 270);
- break;
- default:
- return false;
- }
- $image->setImageOrientation(\imagick::ORIENTATION_TOPLEFT); // 1
- return true;
- }
+ protected function get_image_size( $file_path )
+ {
+ if ($this->options['image_library'])
+ {
+ if (extension_loaded('imagick'))
+ {
+ $image = new \Imagick();
+ try
+ {
+ if
(@$image->pingImage($file_path))
+ {
+ $dimensions =
array($image->getImageWidth(), $image->getImageHeight());
+ $image->destroy();
+ return $dimensions;
+ }
+ return false;
+ }
+ catch (\Exception $e)
+ {
+ error_log($e->getMessage());
+ }
+ }
+ if ($this->options['image_library'] === 2)
+ {
+ $cmd = $this->options['identify_bin'];
+ $cmd .= ' -ping ' .
escapeshellarg($file_path);
+ exec($cmd, $output, $error);
+ if (!$error && !empty($output))
+ {
+ // image.jpg JPEG 1920x1080
1920x1080+0+0 8-bit sRGB 465KB 0.000u 0:00.000
+ $infos = preg_split('/\s+/',
substr($output[0], strlen($file_path)));
+ $dimensions = preg_split('/x/',
$infos[2]);
+ return $dimensions;
+ }
+ return false;
+ }
+ }
+ if (!function_exists('getimagesize'))
+ {
+ error_log('Function not found: getimagesize');
+ return false;
+ }
+ return @getimagesize($file_path);
+ }
- protected function imagick_create_scaled_image($file_name, $version,
$options) {
- list($file_path, $new_file_path) =
- $this->get_scaled_image_file_paths($file_name, $version);
- $image = $this->imagick_get_image_object(
- $file_path,
- !empty($options['crop']) || !empty($options['no_cache'])
- );
- if ($image->getImageFormat() === 'GIF') {
- // Handle animated GIFs:
- $images = $image->coalesceImages();
- foreach ($images as $frame) {
- $image = $frame;
- $this->imagick_set_image_object($file_name, $image);
- break;
- }
- }
- $image_oriented = false;
- if (!empty($options['auto_orient'])) {
- $image_oriented = $this->imagick_orient_image($image);
- }
- $new_width = $max_width = $img_width = $image->getImageWidth();
- $new_height = $max_height = $img_height = $image->getImageHeight();
- if (!empty($options['max_width'])) {
- $new_width = $max_width = $options['max_width'];
- }
- if (!empty($options['max_height'])) {
- $new_height = $max_height = $options['max_height'];
- }
- if (!($image_oriented || $max_width < $img_width || $max_height <
$img_height)) {
- if ($file_path !== $new_file_path) {
- return copy($file_path, $new_file_path);
- }
- return true;
- }
- $crop = !empty($options['crop']);
- if ($crop) {
- $x = 0;
- $y = 0;
- if (($img_width / $img_height) >= ($max_width / $max_height)) {
- $new_width = 0; // Enables proportional scaling based on
max_height
- $x = ($img_width / ($img_height / $max_height) - $max_width) /
2;
- } else {
- $new_height = 0; // Enables proportional scaling based on
max_width
- $y = ($img_height / ($img_width / $max_width) - $max_height) /
2;
- }
- }
- $success = $image->resizeImage(
- $new_width,
- $new_height,
- isset($options['filter']) ? $options['filter'] :
\imagick::FILTER_LANCZOS,
- isset($options['blur']) ? $options['blur'] : 1,
- $new_width && $new_height // fit image into constraints if not to
be cropped
- );
- if ($success && $crop) {
- $success = $image->cropImage(
- $max_width,
- $max_height,
- $x,
- $y
- );
- if ($success) {
- $success = $image->setImagePage($max_width, $max_height, 0, 0);
- }
- }
- $type = strtolower(substr(strrchr($file_name, '.'), 1));
- switch ($type) {
- case 'jpg':
- case 'jpeg':
- if (!empty($options['jpeg_quality'])) {
- $image->setImageCompression(\imagick::COMPRESSION_JPEG);
-
$image->setImageCompressionQuality($options['jpeg_quality']);
- }
- break;
- }
- if (!empty($options['strip'])) {
- $image->stripImage();
- }
- return $success && $image->writeImage($new_file_path);
- }
+ protected function create_scaled_image( $file_name, $version,
$options )
+ {
+ if ($this->options['image_library'] === 2)
+ {
+ return
$this->imagemagick_create_scaled_image($file_name, $version, $options);
+ }
+ if ($this->options['image_library'] &&
extension_loaded('imagick'))
+ {
+ return
$this->imagick_create_scaled_image($file_name, $version, $options);
+ }
+ return $this->gd_create_scaled_image($file_name,
$version, $options);
+ }
- protected function imagemagick_create_scaled_image($file_name, $version,
$options) {
- list($file_path, $new_file_path) =
- $this->get_scaled_image_file_paths($file_name, $version);
- $resize = @$options['max_width']
- .(empty($options['max_height']) ? '' : 'X'.$options['max_height']);
- if (!$resize && empty($options['auto_orient'])) {
- if ($file_path !== $new_file_path) {
- return copy($file_path, $new_file_path);
- }
- return true;
- }
- $cmd = $this->options['convert_bin'];
- if (!empty($this->options['convert_params'])) {
- $cmd .= ' '.$this->options['convert_params'];
- }
- $cmd .= ' '.escapeshellarg($file_path);
- if (!empty($options['auto_orient'])) {
- $cmd .= ' -auto-orient';
- }
- if ($resize) {
- // Handle animated GIFs:
- $cmd .= ' -coalesce';
- if (empty($options['crop'])) {
- $cmd .= ' -resize '.escapeshellarg($resize.'>');
- } else {
- $cmd .= ' -resize '.escapeshellarg($resize.'^');
- $cmd .= ' -gravity center';
- $cmd .= ' -crop '.escapeshellarg($resize.'+0+0');
- }
- // Make sure the page dimensions are correct (fixes offsets of
animated GIFs):
- $cmd .= ' +repage';
- }
- if (!empty($options['convert_params'])) {
- $cmd .= ' '.$options['convert_params'];
- }
- $cmd .= ' '.escapeshellarg($new_file_path);
- exec($cmd, $output, $error);
- if ($error) {
- error_log(implode('\n', $output));
- return false;
- }
- return true;
- }
+ protected function destroy_image_object( $file_path )
+ {
+ if ($this->options['image_library'] &&
extension_loaded('imagick'))
+ {
+ return
$this->imagick_destroy_image_object($file_path);
+ }
+ }
- protected function get_image_size($file_path) {
- if ($this->options['image_library']) {
- if (extension_loaded('imagick')) {
- $image = new \Imagick();
- try {
- if (@$image->pingImage($file_path)) {
- $dimensions = array($image->getImageWidth(),
$image->getImageHeight());
- $image->destroy();
- return $dimensions;
- }
- return false;
- } catch (\Exception $e) {
- error_log($e->getMessage());
- }
- }
- if ($this->options['image_library'] === 2) {
- $cmd = $this->options['identify_bin'];
- $cmd .= ' -ping '.escapeshellarg($file_path);
- exec($cmd, $output, $error);
- if (!$error && !empty($output)) {
- // image.jpg JPEG 1920x1080 1920x1080+0+0 8-bit sRGB 465KB
0.000u 0:00.000
- $infos = preg_split('/\s+/', substr($output[0],
strlen($file_path)));
- $dimensions = preg_split('/x/', $infos[2]);
- return $dimensions;
- }
- return false;
- }
- }
- if (!function_exists('getimagesize')) {
- error_log('Function not found: getimagesize');
- return false;
- }
- return @getimagesize($file_path);
- }
+ protected function is_valid_image_file( $file_path )
+ {
+ if (!preg_match($this->options['image_file_types'],
$file_path))
+ {
+ return false;
+ }
+ if (function_exists('exif_imagetype'))
+ {
+ return @exif_imagetype($file_path);
+ }
+ $image_info = $this->get_image_size($file_path);
+ return $image_info && $image_info[0] && $image_info[1];
+ }
- protected function create_scaled_image($file_name, $version, $options) {
- if ($this->options['image_library'] === 2) {
- return $this->imagemagick_create_scaled_image($file_name,
$version, $options);
- }
- if ($this->options['image_library'] && extension_loaded('imagick')) {
- return $this->imagick_create_scaled_image($file_name, $version,
$options);
- }
- return $this->gd_create_scaled_image($file_name, $version, $options);
- }
+ protected function handle_image_file( $file_path, $file )
+ {
+ $failed_versions = array();
+ foreach ($this->options['image_versions'] as $version
=> $options)
+ {
+ if ($this->create_scaled_image($file->name,
$version, $options))
+ {
+ if (!empty($version))
+ {
+ $file->{$version . 'Url'} =
$this->get_download_url(
+ $file->name, $version
+ );
+ }
+ else
+ {
+ $file->size =
$this->get_file_size($file_path, true);
+ }
+ }
+ else
+ {
+ $failed_versions[] = $version ?
$version : 'original';
+ }
+ }
+ if (count($failed_versions))
+ {
+ $file->error =
$this->get_error_message('image_resize')
+ . ' (' . implode($failed_versions, ',
') . ')';
+ }
+ // Free memory:
+ $this->destroy_image_object($file_path);
+ }
- protected function destroy_image_object($file_path) {
- if ($this->options['image_library'] && extension_loaded('imagick')) {
- return $this->imagick_destroy_image_object($file_path);
- }
- }
+ protected function handle_file_upload( $uploaded_file, $name,
$size, $type, $error, $index = null, $content_range = null )
+ {
+ $file = new \stdClass();
+ $file->name = $this->get_file_name($uploaded_file,
$name, $size, $type, $error, $index, $content_range);
+ $file->size = $this->fix_integer_overflow((int)$size);
+ $file->type = $type;
+ if ($this->validate($uploaded_file, $file, $error,
$index))
+ {
+ $this->handle_form_data($file, $index);
+ $upload_dir = $this->get_upload_path();
+ if (!is_dir($upload_dir))
+ {
+ mkdir($upload_dir,
$this->options['mkdir_mode'], true);
+ }
+ $file_path =
$this->get_upload_path($file->name);
+ $append_file = $content_range &&
is_file($file_path) &&
+ $file->size >
$this->get_file_size($file_path);
+ if ($uploaded_file &&
is_uploaded_file($uploaded_file))
+ {
+ // multipart/formdata uploads (POST
method uploads)
+ if ($append_file)
+ {
+ file_put_contents(
+ $file_path,
fopen($uploaded_file, 'r'), FILE_APPEND
+ );
+ }
+ else
+ {
+
move_uploaded_file($uploaded_file, $file_path);
+ }
+ }
+ else
+ {
+ // Non-multipart uploads (PUT method
support)
+ file_put_contents(
+ $file_path,
fopen($this->options['input_stream'], 'r'), $append_file ? FILE_APPEND : 0
+ );
+ }
+ $file_size = $this->get_file_size($file_path,
$append_file);
+ if ($file_size === $file->size)
+ {
+ $file->url =
$this->get_download_url($file->name);
+ if
($this->is_valid_image_file($file_path))
+ {
+
$this->handle_image_file($file_path, $file);
+ }
+ }
+ else
+ {
+ $file->size = $file_size;
+ if (!$content_range &&
$this->options['discard_aborted_uploads'])
+ {
+ unlink($file_path);
+ $file->error =
$this->get_error_message('abort');
+ }
+ }
+ $this->set_additional_file_properties($file);
+ }
+ return $file;
+ }
- protected function is_valid_image_file($file_path) {
- if (!preg_match($this->options['image_file_types'], $file_path)) {
- return false;
- }
- if (function_exists('exif_imagetype')) {
- return @exif_imagetype($file_path);
- }
- $image_info = $this->get_image_size($file_path);
- return $image_info && $image_info[0] && $image_info[1];
- }
+ protected function readfile( $file_path )
+ {
+ $file_size = $this->get_file_size($file_path);
+ $chunk_size = $this->options['readfile_chunk_size'];
+ if ($chunk_size && $file_size > $chunk_size)
+ {
+ $handle = fopen($file_path, 'rb');
+ while (!feof($handle))
+ {
+ echo fread($handle, $chunk_size);
+ @ob_flush();
+ @flush();
+ }
+ fclose($handle);
+ return $file_size;
+ }
+ return readfile($file_path);
+ }
- protected function handle_image_file($file_path, $file) {
- $failed_versions = array();
- foreach ($this->options['image_versions'] as $version => $options) {
- if ($this->create_scaled_image($file->name, $version, $options)) {
- if (!empty($version)) {
- $file->{$version.'Url'} = $this->get_download_url(
- $file->name,
- $version
- );
- } else {
- $file->size = $this->get_file_size($file_path, true);
- }
- } else {
- $failed_versions[] = $version ? $version : 'original';
- }
- }
- if (count($failed_versions)) {
- $file->error = $this->get_error_message('image_resize')
- .' ('.implode($failed_versions, ', ').')';
- }
- // Free memory:
- $this->destroy_image_object($file_path);
- }
+ protected function body( $str )
+ {
+ echo $str;
+ }
- protected function handle_file_upload($uploaded_file, $name, $size, $type,
$error,
- $index = null, $content_range = null) {
- $file = new \stdClass();
- $file->name = $this->get_file_name($uploaded_file, $name, $size,
$type, $error,
- $index, $content_range);
- $file->size = $this->fix_integer_overflow((int)$size);
- $file->type = $type;
- if ($this->validate($uploaded_file, $file, $error, $index)) {
- $this->handle_form_data($file, $index);
- $upload_dir = $this->get_upload_path();
- if (!is_dir($upload_dir)) {
- mkdir($upload_dir, $this->options['mkdir_mode'], true);
- }
- $file_path = $this->get_upload_path($file->name);
- $append_file = $content_range && is_file($file_path) &&
- $file->size > $this->get_file_size($file_path);
- if ($uploaded_file && is_uploaded_file($uploaded_file)) {
- // multipart/formdata uploads (POST method uploads)
- if ($append_file) {
- file_put_contents(
- $file_path,
- fopen($uploaded_file, 'r'),
- FILE_APPEND
- );
- } else {
- move_uploaded_file($uploaded_file, $file_path);
- }
- } else {
- // Non-multipart uploads (PUT method support)
- file_put_contents(
- $file_path,
- fopen($this->options['input_stream'], 'r'),
- $append_file ? FILE_APPEND : 0
- );
- }
- $file_size = $this->get_file_size($file_path, $append_file);
- if ($file_size === $file->size) {
- $file->url = $this->get_download_url($file->name);
- if ($this->is_valid_image_file($file_path)) {
- $this->handle_image_file($file_path, $file);
- }
- } else {
- $file->size = $file_size;
- if (!$content_range &&
$this->options['discard_aborted_uploads']) {
- unlink($file_path);
- $file->error = $this->get_error_message('abort');
- }
- }
- $this->set_additional_file_properties($file);
- }
- return $file;
- }
+ protected function header( $str )
+ {
+ header($str);
+ }
- protected function readfile($file_path) {
- $file_size = $this->get_file_size($file_path);
- $chunk_size = $this->options['readfile_chunk_size'];
- if ($chunk_size && $file_size > $chunk_size) {
- $handle = fopen($file_path, 'rb');
- while (!feof($handle)) {
- echo fread($handle, $chunk_size);
- @ob_flush();
- @flush();
- }
- fclose($handle);
- return $file_size;
- }
- return readfile($file_path);
- }
+ protected function get_upload_data( $id )
+ {
+ return @$_FILES[$id];
+ }
- protected function body($str) {
- echo $str;
- }
+ protected function get_post_param( $id )
+ {
+ return @$_POST[$id];
+ }
- protected function header($str) {
- header($str);
- }
+ protected function get_query_param( $id )
+ {
+ return @$_GET[$id];
+ }
- protected function get_upload_data($id) {
- return @$_FILES[$id];
- }
+ protected function get_server_var( $id )
+ {
+ return @$_SERVER[$id];
+ }
- protected function get_post_param($id) {
- return @$_POST[$id];
- }
+ protected function handle_form_data( $file, $index )
+ {
+ // Handle form data, e.g. $_POST['description'][$index]
+ }
- protected function get_query_param($id) {
- return @$_GET[$id];
- }
+ protected function get_version_param()
+ {
+ return
$this->basename(stripslashes($this->get_query_param('version')));
+ }
- protected function get_server_var($id) {
- return @$_SERVER[$id];
- }
+ protected function get_singular_param_name()
+ {
+ return substr($this->options['param_name'], 0, -1);
+ }
- protected function handle_form_data($file, $index) {
- // Handle form data, e.g. $_POST['description'][$index]
- }
+ protected function get_file_name_param()
+ {
+ $name = $this->get_singular_param_name();
+ return
$this->basename(stripslashes($this->get_query_param($name)));
+ }
- protected function get_version_param() {
- return
$this->basename(stripslashes($this->get_query_param('version')));
- }
+ protected function get_file_names_params()
+ {
+ $params =
$this->get_query_param($this->options['param_name']);
+ if (!$params)
+ {
+ return null;
+ }
+ foreach ($params as $key => $value)
+ {
+ $params[$key] =
$this->basename(stripslashes($value));
+ }
+ return $params;
+ }
- protected function get_singular_param_name() {
- return substr($this->options['param_name'], 0, -1);
- }
+ protected function get_file_type( $file_path )
+ {
+ switch (strtolower(pathinfo($file_path,
PATHINFO_EXTENSION)))
+ {
+ case 'jpeg':
+ case 'jpg':
+ return 'image/jpeg';
+ case 'png':
+ return 'image/png';
+ case 'gif':
+ return 'image/gif';
+ default:
+ return '';
+ }
+ }
- protected function get_file_name_param() {
- $name = $this->get_singular_param_name();
- return $this->basename(stripslashes($this->get_query_param($name)));
- }
+ protected function download()
+ {
+ switch ($this->options['download_via_php'])
+ {
+ case 1:
+ $redirect_header = null;
+ break;
+ case 2:
+ $redirect_header = 'X-Sendfile';
+ break;
+ case 3:
+ $redirect_header = 'X-Accel-Redirect';
+ break;
+ default:
+ return $this->header('HTTP/1.1 403
Forbidden');
+ }
+ $file_name = $this->get_file_name_param();
+ if (!$this->is_valid_file_object($file_name))
+ {
+ return $this->header('HTTP/1.1 404 Not Found');
+ }
+ if ($redirect_header)
+ {
+ return $this->header(
+ $redirect_header . ': ' .
$this->get_download_url(
+ $file_name,
$this->get_version_param(), true
+ )
+ );
+ }
+ $file_path = $this->get_upload_path($file_name,
$this->get_version_param());
+ // Prevent browsers from MIME-sniffing the content-type:
+ $this->header('X-Content-Type-Options: nosniff');
+ if (!preg_match($this->options['inline_file_types'],
$file_name))
+ {
+ $this->header('Content-Type:
application/octet-stream');
+ $this->header('Content-Disposition: attachment;
filename="' . $file_name . '"');
+ }
+ else
+ {
+ $this->header('Content-Type: ' .
$this->get_file_type($file_path));
+ $this->header('Content-Disposition: inline;
filename="' . $file_name . '"');
+ }
+ $this->header('Content-Length: ' .
$this->get_file_size($file_path));
+ $this->header('Last-Modified: ' . gmdate('D, d M Y
H:i:s T', filemtime($file_path)));
+ $this->readfile($file_path);
+ }
- protected function get_file_names_params() {
- $params = $this->get_query_param($this->options['param_name']);
- if (!$params) {
- return null;
- }
- foreach ($params as $key => $value) {
- $params[$key] = $this->basename(stripslashes($value));
- }
- return $params;
- }
+ protected function send_content_type_header()
+ {
+ $this->header('Vary: Accept');
+ if (strpos($this->get_server_var('HTTP_ACCEPT'),
'application/json') !== false)
+ {
+ $this->header('Content-type: application/json');
+ }
+ else
+ {
+ $this->header('Content-type: text/plain');
+ }
+ }
- protected function get_file_type($file_path) {
- switch (strtolower(pathinfo($file_path, PATHINFO_EXTENSION))) {
- case 'jpeg':
- case 'jpg':
- return 'image/jpeg';
- case 'png':
- return 'image/png';
- case 'gif':
- return 'image/gif';
- default:
- return '';
- }
- }
+ protected function send_access_control_headers()
+ {
+ $this->header('Access-Control-Allow-Origin: ' .
$this->options['access_control_allow_origin']);
+ $this->header('Access-Control-Allow-Credentials: '
+ .
($this->options['access_control_allow_credentials'] ? 'true' : 'false'));
+ $this->header('Access-Control-Allow-Methods: '
+ . implode(', ',
$this->options['access_control_allow_methods']));
+ $this->header('Access-Control-Allow-Headers: '
+ . implode(', ',
$this->options['access_control_allow_headers']));
+ }
- protected function download() {
- switch ($this->options['download_via_php']) {
- case 1:
- $redirect_header = null;
- break;
- case 2:
- $redirect_header = 'X-Sendfile';
- break;
- case 3:
- $redirect_header = 'X-Accel-Redirect';
- break;
- default:
- return $this->header('HTTP/1.1 403 Forbidden');
- }
- $file_name = $this->get_file_name_param();
- if (!$this->is_valid_file_object($file_name)) {
- return $this->header('HTTP/1.1 404 Not Found');
- }
- if ($redirect_header) {
- return $this->header(
- $redirect_header.': '.$this->get_download_url(
- $file_name,
- $this->get_version_param(),
- true
- )
- );
- }
- $file_path = $this->get_upload_path($file_name,
$this->get_version_param());
- // Prevent browsers from MIME-sniffing the content-type:
- $this->header('X-Content-Type-Options: nosniff');
- if (!preg_match($this->options['inline_file_types'], $file_name)) {
- $this->header('Content-Type: application/octet-stream');
- $this->header('Content-Disposition: attachment;
filename="'.$file_name.'"');
- } else {
- $this->header('Content-Type: '.$this->get_file_type($file_path));
- $this->header('Content-Disposition: inline;
filename="'.$file_name.'"');
- }
- $this->header('Content-Length: '.$this->get_file_size($file_path));
- $this->header('Last-Modified: '.gmdate('D, d M Y H:i:s T',
filemtime($file_path)));
- $this->readfile($file_path);
- }
+ public function generate_response( $content, $print_response =
true )
+ {
+ $this->response = $content;
+ if ($print_response)
+ {
+ $json = json_encode($content);
+ $redirect =
stripslashes($this->get_post_param('redirect'));
+ if ($redirect &&
preg_match($this->options['redirect_allow_target'], $redirect))
+ {
+ $this->header('Location: ' .
sprintf($redirect, rawurlencode($json)));
+ return;
+ }
+ $this->head();
+ if ($this->get_server_var('HTTP_CONTENT_RANGE'))
+ {
+ $files =
isset($content[$this->options['param_name']]) ?
+
$content[$this->options['param_name']] : null;
+ if ($files && is_array($files) &&
is_object($files[0]) && $files[0]->size)
+ {
+ $this->header('Range: 0-' . (
+
$this->fix_integer_overflow((int)$files[0]->size) - 1
+ ));
+ }
+ }
+ $this->body($json);
+ }
+ return $content;
+ }
- protected function send_content_type_header() {
- $this->header('Vary: Accept');
- if (strpos($this->get_server_var('HTTP_ACCEPT'), 'application/json')
!== false) {
- $this->header('Content-type: application/json');
- } else {
- $this->header('Content-type: text/plain');
- }
- }
+ public function get_response()
+ {
+ return $this->response;
+ }
- protected function send_access_control_headers() {
- $this->header('Access-Control-Allow-Origin:
'.$this->options['access_control_allow_origin']);
- $this->header('Access-Control-Allow-Credentials: '
- .($this->options['access_control_allow_credentials'] ? 'true' :
'false'));
- $this->header('Access-Control-Allow-Methods: '
- .implode(', ', $this->options['access_control_allow_methods']));
- $this->header('Access-Control-Allow-Headers: '
- .implode(', ', $this->options['access_control_allow_headers']));
- }
+ public function head()
+ {
+ $this->header('Pragma: no-cache');
+ $this->header('Cache-Control: no-store, no-cache,
must-revalidate');
+ $this->header('Content-Disposition: inline;
filename="files.json"');
+ // Prevent Internet Explorer from MIME-sniffing the
content-type:
+ $this->header('X-Content-Type-Options: nosniff');
+ if ($this->options['access_control_allow_origin'])
+ {
+ $this->send_access_control_headers();
+ }
+ $this->send_content_type_header();
+ }
- public function generate_response($content, $print_response = true) {
- $this->response = $content;
- if ($print_response) {
- $json = json_encode($content);
- $redirect = stripslashes($this->get_post_param('redirect'));
- if ($redirect &&
preg_match($this->options['redirect_allow_target'], $redirect)) {
- $this->header('Location: '.sprintf($redirect,
rawurlencode($json)));
- return;
- }
- $this->head();
- if ($this->get_server_var('HTTP_CONTENT_RANGE')) {
- $files = isset($content[$this->options['param_name']]) ?
- $content[$this->options['param_name']] : null;
- if ($files && is_array($files) && is_object($files[0]) &&
$files[0]->size) {
- $this->header('Range: 0-'.(
- $this->fix_integer_overflow((int)$files[0]->size) - 1
- ));
- }
- }
- $this->body($json);
- }
- return $content;
- }
+ public function get( $print_response = true )
+ {
+ if ($print_response &&
$this->get_query_param('download'))
+ {
+ return $this->download();
+ }
+ $file_name = $this->get_file_name_param();
+ if ($file_name)
+ {
+ $response = array(
+ $this->get_singular_param_name() =>
$this->get_file_object($file_name)
+ );
+ }
+ else
+ {
+ $response = array(
+ $this->options['param_name'] =>
$this->get_file_objects()
+ );
+ }
+ return $this->generate_response($response,
$print_response);
+ }
- public function get_response () {
- return $this->response;
- }
+ public function post( $print_response = true )
+ {
+ if ($this->get_query_param('_method') === 'DELETE')
+ {
+ return $this->delete($print_response);
+ }
+ $upload =
$this->get_upload_data($this->options['param_name']);
+ // Parse the Content-Disposition header, if available:
+ $content_disposition_header =
$this->get_server_var('HTTP_CONTENT_DISPOSITION');
+ $file_name = $content_disposition_header ?
+ rawurldecode(preg_replace(
+ '/(^[^"]+")|("$)/', '',
$content_disposition_header
+ )) : null;
+ // Parse the Content-Range header, which has the
following form:
+ // Content-Range: bytes 0-524287/2000000
+ $content_range_header =
$this->get_server_var('HTTP_CONTENT_RANGE');
+ $content_range = $content_range_header ?
+ preg_split('/[^0-9]+/', $content_range_header)
: null;
+ $size = $content_range ? $content_range[3] : null;
+ $files = array();
+ if ($upload)
+ {
+ if (is_array($upload['tmp_name']))
+ {
+ // param_name is an array identifier
like "files[]",
+ // $upload is a multi-dimensional array:
+ foreach ($upload['tmp_name'] as $index
=> $value)
+ {
+ $files[] =
$this->handle_file_upload(
+
$upload['tmp_name'][$index], $file_name ? $file_name : $upload['name'][$index],
$size ? $size : $upload['size'][$index], $upload['type'][$index],
$upload['error'][$index], $index, $content_range
+ );
+ }
+ }
+ else
+ {
+ // param_name is a single object
identifier like "file",
+ // $upload is a one-dimensional array:
+ $files[] = $this->handle_file_upload(
+ isset($upload['tmp_name']) ?
$upload['tmp_name'] : null, $file_name ? $file_name : (isset($upload['name']) ?
+ $upload['name'] : null), $size
? $size : (isset($upload['size']) ?
+ $upload['size'] :
$this->get_server_var('CONTENT_LENGTH')), isset($upload['type']) ?
+ $upload['type'] :
$this->get_server_var('CONTENT_TYPE'), isset($upload['error']) ?
$upload['error'] : null, null, $content_range
+ );
+ }
+ }
+ $response = array($this->options['param_name'] =>
$files);
+ return $this->generate_response($response,
$print_response);
+ }
- public function head() {
- $this->header('Pragma: no-cache');
- $this->header('Cache-Control: no-store, no-cache, must-revalidate');
- $this->header('Content-Disposition: inline; filename="files.json"');
- // Prevent Internet Explorer from MIME-sniffing the content-type:
- $this->header('X-Content-Type-Options: nosniff');
- if ($this->options['access_control_allow_origin']) {
- $this->send_access_control_headers();
- }
- $this->send_content_type_header();
- }
+ public function delete( $print_response = true )
+ {
+ $file_names = $this->get_file_names_params();
+ if (empty($file_names))
+ {
+ $file_names =
array($this->get_file_name_param());
+ }
+ $response = array();
+ foreach ($file_names as $file_name)
+ {
+ $file_path = $this->get_upload_path($file_name);
+ $success = is_file($file_path) && $file_name[0]
!== '.' && unlink($file_path);
+ if ($success)
+ {
+ foreach
($this->options['image_versions'] as $version => $options)
+ {
+ if (!empty($version))
+ {
+ $file =
$this->get_upload_path($file_name, $version);
+ if (is_file($file))
+ {
+ unlink($file);
+ }
+ }
+ }
+ }
+ $response[$file_name] = $success;
+ }
+ return $this->generate_response($response,
$print_response);
+ }
- public function get($print_response = true) {
- if ($print_response && $this->get_query_param('download')) {
- return $this->download();
- }
- $file_name = $this->get_file_name_param();
- if ($file_name) {
- $response = array(
- $this->get_singular_param_name() =>
$this->get_file_object($file_name)
- );
- } else {
- $response = array(
- $this->options['param_name'] => $this->get_file_objects()
- );
- }
- return $this->generate_response($response, $print_response);
- }
-
- public function post($print_response = true) {
- if ($this->get_query_param('_method') === 'DELETE') {
- return $this->delete($print_response);
- }
- $upload = $this->get_upload_data($this->options['param_name']);
- // Parse the Content-Disposition header, if available:
- $content_disposition_header =
$this->get_server_var('HTTP_CONTENT_DISPOSITION');
- $file_name = $content_disposition_header ?
- rawurldecode(preg_replace(
- '/(^[^"]+")|("$)/',
- '',
- $content_disposition_header
- )) : null;
- // Parse the Content-Range header, which has the following form:
- // Content-Range: bytes 0-524287/2000000
- $content_range_header = $this->get_server_var('HTTP_CONTENT_RANGE');
- $content_range = $content_range_header ?
- preg_split('/[^0-9]+/', $content_range_header) : null;
- $size = $content_range ? $content_range[3] : null;
- $files = array();
- if ($upload) {
- if (is_array($upload['tmp_name'])) {
- // param_name is an array identifier like "files[]",
- // $upload is a multi-dimensional array:
- foreach ($upload['tmp_name'] as $index => $value) {
- $files[] = $this->handle_file_upload(
- $upload['tmp_name'][$index],
- $file_name ? $file_name : $upload['name'][$index],
- $size ? $size : $upload['size'][$index],
- $upload['type'][$index],
- $upload['error'][$index],
- $index,
- $content_range
- );
- }
- } else {
- // param_name is a single object identifier like "file",
- // $upload is a one-dimensional array:
- $files[] = $this->handle_file_upload(
- isset($upload['tmp_name']) ? $upload['tmp_name'] : null,
- $file_name ? $file_name : (isset($upload['name']) ?
- $upload['name'] : null),
- $size ? $size : (isset($upload['size']) ?
- $upload['size'] :
$this->get_server_var('CONTENT_LENGTH')),
- isset($upload['type']) ?
- $upload['type'] :
$this->get_server_var('CONTENT_TYPE'),
- isset($upload['error']) ? $upload['error'] : null,
- null,
- $content_range
- );
- }
- }
- $response = array($this->options['param_name'] => $files);
- return $this->generate_response($response, $print_response);
- }
-
- public function delete($print_response = true) {
- $file_names = $this->get_file_names_params();
- if (empty($file_names)) {
- $file_names = array($this->get_file_name_param());
- }
- $response = array();
- foreach ($file_names as $file_name) {
- $file_path = $this->get_upload_path($file_name);
- $success = is_file($file_path) && $file_name[0] !== '.' &&
unlink($file_path);
- if ($success) {
- foreach ($this->options['image_versions'] as $version =>
$options) {
- if (!empty($version)) {
- $file = $this->get_upload_path($file_name, $version);
- if (is_file($file)) {
- unlink($file);
- }
- }
- }
- }
- $response[$file_name] = $success;
- }
- return $this->generate_response($response, $print_response);
- }
-
- protected function basename($filepath, $suffix = null) {
- $splited = preg_split('/\//', rtrim ($filepath, '/ '));
- return substr(basename('X'.$splited[count($splited)-1], $suffix), 1);
- }
-}
+ protected function basename( $filepath, $suffix = null )
+ {
+ $splited = preg_split('/\//', rtrim($filepath, '/ '));
+ return substr(basename('X' . $splited[count($splited) -
1], $suffix), 1);
+ }
+ }
\ No newline at end of file
Modified:
branches/Version-2_0-branch/property/inc/import/class.import_component_files.inc.php
===================================================================
---
branches/Version-2_0-branch/property/inc/import/class.import_component_files.inc.php
2017-02-20 20:39:26 UTC (rev 16353)
+++
branches/Version-2_0-branch/property/inc/import/class.import_component_files.inc.php
2017-02-20 20:44:47 UTC (rev 16354)
@@ -1,32 +1,33 @@
<?php
-
+
class import_component_files
- {
+ {
+
private $receipt = array();
-
+
public function __construct()
{
$this->acl = & $GLOBALS['phpgw']->acl;
$this->db = & $GLOBALS['phpgw']->db;
-
+
$this->fakebase = '/temp_files_components';
- $this->path_upload_dir =
$GLOBALS['phpgw_info']['server']['files_dir'].$this->fakebase.'/';
+ $this->path_upload_dir =
$GLOBALS['phpgw_info']['server']['files_dir'] . $this->fakebase . '/';
$this->location_code = phpgw::get_var('location_code');
$this->location_item_id =
phpgw::get_var('location_item_id');
$this->attrib_name_componentID =
phpgw::get_var('attribute_name_component_id');
-
+
$this->last_files_added = array();
$this->list_component_id = array();
$this->paths_from_file = array();
$this->paths_empty = array();
}
-
+
public function get_path_upload_dir()
{
return $this->path_upload_dir;
}
-
+
public function check_upload_dir()
{
$rs = $this->create_document_dir();
@@ -34,15 +35,15 @@
{
$receipt['error'] = lang('failed to create
directory') . ': ' . $this->fakebase;
}
-
+
if (!is_writable($this->path_upload_dir))
{
$receipt['error'] = lang('Not have permission
to access the directory') . ': ' . $this->fakebase;
}
-
+
return $receipt;
}
-
+
private function create_document_dir()
{
if (is_dir($this->path_upload_dir))
@@ -49,52 +50,52 @@
{
return true;
}
-
- $old = umask(0);
+
+ $old = umask(0);
$rs = mkdir($this->path_upload_dir, 0755);
- umask($old);
-
+ umask($old);
+
return $rs;
}
-
- private function _valid_row($row)
+
+ private function _valid_row( $row )
{
- if (empty($row[(count($row)-1)]))
+ if (empty($row[(count($row) - 1)]))
{
return false;
}
-
- if ($row[0] == 'Nummer3' && $row[(count($row)-1)] ==
'Filsti')
+
+ if ($row[0] == 'Nummer3' && $row[(count($row) - 1)] ==
'Filsti')
{
return false;
}
-
+
return true;
}
-
- private function _get_files_by_component($id, $location_id)
+
+ private function _get_files_by_component( $id, $location_id )
{
$sql = "SELECT a.location_id, a.location_item_id,
b.file_id, b.name, b.md5_sum FROM phpgw_vfs_file_relation a INNER JOIN
phpgw_vfs b "
- . " ON a.file_id = b.file_id WHERE
a.location_item_id = '{$id}' AND a.location_id = '{$location_id}'"
- . " AND b.mime_type != 'Directory' AND
b.mime_type != 'journal' AND b.mime_type != 'journal-deleted'";
+ . " ON a.file_id = b.file_id WHERE
a.location_item_id = '{$id}' AND a.location_id = '{$location_id}'"
+ . " AND b.mime_type != 'Directory' AND
b.mime_type != 'journal' AND b.mime_type != 'journal-deleted'";
$this->db->query($sql, __LINE__, __FILE__);
$values = array();
-
+
while ($this->db->next_record())
{
$values[] = $this->db->f('md5_sum');
}
- return $values;
+ return $values;
}
-
- private function _search_file_in_db($md5_sum)
+
+ private function _search_file_in_db( $md5_sum )
{
$sql = "SELECT file_id, md5_sum FROM phpgw_vfs "
- . " WHERE md5_sum = '{$md5_sum}'"
- . " AND mime_type != 'Directory' AND
mime_type != 'journal' AND mime_type != 'journal-deleted'";
+ . " WHERE md5_sum = '{$md5_sum}'"
+ . " AND mime_type != 'Directory' AND mime_type
!= 'journal' AND mime_type != 'journal-deleted'";
$this->db->query($sql, __LINE__, __FILE__);
@@ -103,33 +104,33 @@
$id = $this->db->f('file_id');
}
- return $id;
+ return $id;
}
-
- private function _search_in_last_files_added($file_data)
+
+ private function _search_in_last_files_added( $file_data )
{
$md5sum = $file_data['md5sum'];
$file_id = array_search($md5sum,
$this->last_files_added);
-
+
return $file_id;
}
-
+
public function add_files_location()
- {
+ {
@set_time_limit(5 * 60);
-
+
$message = array();
-
+
$uploaded_files =
phpgwapi_cache::session_get('property', 'import_data');
$this->paths_from_file =
phpgwapi_cache::session_get('property', 'paths_from_file');
-
+
$count_new_relations = 0;
$count_relations_existing = 0;
$files_existing = array();
$count_new_files = 0;
-
- $component = array('id' => $this->location_item_id,
'location_id' => $GLOBALS['phpgw']->locations->get_id('property',
'.location.'.count(explode('-', $this->location_code))));
+ $component = array('id' => $this->location_item_id,
'location_id' => $GLOBALS['phpgw']->locations->get_id('property', '.location.'
. count(explode('-', $this->location_code))));
+
$files_in_component =
$this->_get_files_by_component($component['id'], $component['location_id']);
foreach ($uploaded_files as $file_data)
@@ -144,12 +145,12 @@
$this->db->transaction_begin();
try
{
- $this->db->Exception_On_Error = true;
-
+ $this->db->Exception_On_Error = true;
+
$file = $file_data['file'];
$file_id =
$this->_search_in_last_files_added($file_data);
- if (!$file_id)
+ if (!$file_id)
{
$file_id =
$this->_search_file_in_db($file_data['md5sum']);
if (!$file_id)
@@ -156,20 +157,24 @@
{
$file_id =
$this->_save_file($file_data);
if (!$file_id)
- {
+ {
throw new
Exception("failed to copy file '{$file_data['path_absolute']}'");
- }
+ }
unlink($file_data['path_absolute']);
$count_new_files++;
- } else {
+ }
+ else
+ {
$files_existing[$file_data['md5sum']] = $file_data['md5sum'];
}
-
+
$result =
$this->_save_file_relation($component['id'], $component['location_id'],
$file_id);
if (!$result)
- {
+ {
$message['error'][] =
array('msg' => "failed to save relation. File: '{$file}'");
- } else {
+ }
+ else
+ {
$this->last_files_added[$file_id] = $file_data['md5sum'];
$count_new_relations++;
}
@@ -181,7 +186,7 @@
{
if ($e)
{
- $this->db->transaction_abort();
+ $this->db->transaction_abort();
if ($e->getMessage())
{
$message['error'][] =
array('msg' => $e->getMessage());
@@ -195,16 +200,21 @@
if ($count_new_files)
{
$message['message'][] = array('msg' => lang('%1
files copy successfully', $count_new_files));
- } else {
+ }
+ else
+ {
$message['message'][] = array('msg' => lang('%1
files copy', $count_new_files));
}
- if (count($files_existing)){
+ if (count($files_existing))
+ {
$message['message'][] = array('msg' => lang('%1
files existing in db', count($files_existing)));
}
if ($count_new_relations)
{
$message['message'][] = array('msg' => lang('%1
relations saved successfully', $count_new_relations));
- } else {
+ }
+ else
+ {
$message['message'][] = array('msg' =>
lang('any relation has been saved'));
}
if ($count_relations_existing)
@@ -211,31 +221,33 @@
{
$message['message'][] = array('msg' => lang('%1
relations existing', $count_relations_existing));
}
-
+
$this->_delete_all_dir_temp();
-
+
return $message;
}
-
- private function _generate_md5sum($path)
+
+ private function _generate_md5sum( $path )
{
- $output = array();
- exec('md5sum "'.$path.'" 2>&1', $output, $ret);
+ $output = array();
+ exec('md5sum "' . $path . '" 2>&1', $output, $ret);
if ($ret)
{
$md5sum = '';
- } else {
+ }
+ else
+ {
$md5sum = trim(strstr($output[0], ' ', true));
- }
-
+ }
+
return $md5sum;
}
-
- private function _compare_names(&$component_files,
$uploaded_files)
+
+ private function _compare_names( &$component_files,
$uploaded_files )
{
if (count($component_files))
{
- foreach ($component_files as &$files)
+ foreach ($component_files as &$files)
{
foreach ($files as &$file_data)
{
@@ -252,69 +264,79 @@
$file_data['path_relative'] = $file['path_relative'];
$file_data['md5sum'] = $this->_generate_md5sum($file['path_absolute']);
}
- } else {
+ }
+ else
+ {
$file_data['path_absolute'] = $file['path_absolute'];
$file_data['path_relative'] = $file_data['path'];
$file_data['md5sum'] = $this->_generate_md5sum($file['path_absolute']);
- }
+ }
}
}
- if
(!empty($file_data['md5sum']))
+ if
(!empty($file_data['md5sum']))
{
$this->paths_from_file[$file_data['md5sum']][] = $file_data['path_relative'];
- } else {
-
$this->paths_empty[strtolower($file_data['file'])] =
$file_data['path'].'/'.$file_data['file'];
}
+ else
+ {
+
$this->paths_empty[strtolower($file_data['file'])] = $file_data['path'] . '/' .
$file_data['file'];
+ }
}
}
- } else {
+ }
+ else
+ {
foreach ($uploaded_files as &$file)
{
$md5sum =
$this->_generate_md5sum($file['path_absolute']);
- if (!empty($md5sum))
+ if (!empty($md5sum))
{
$file['md5sum'] = $md5sum;
$component_files[$md5sum] =
$file;
$this->paths_from_file[$md5sum][] = $file['path_relative'];
- } else {
+ }
+ else
+ {
$this->paths_empty[] =
$file['path_absolute'];
- }
+ }
}
//$component_files = $uploaded_files;
}
}
-
- private function _un_zip($file, $dir)
+
+ private function _un_zip( $file, $dir )
{
@set_time_limit(5 * 60);
$zip = new ZipArchive;
- if ($zip->open($file) === TRUE)
+ if ($zip->open($file) === TRUE)
{
- for($i = 0; $i < $zip->numFiles; $i++)
+ for ($i = 0; $i < $zip->numFiles; $i++)
{
// $file_name = str_replace('..', '.',
iconv("CP850", "UTF-8", $zip->getNameIndex($i)));
$file_name = str_replace('..', '.',
$zip->getNameIndex($i));
- $copy_to = $dir.'/'.$file_name;
+ $copy_to = $dir . '/' . $file_name;
if (!is_dir(dirname($copy_to)))
{
mkdir(dirname($copy_to), 0777,
true);
- }
-
copy("zip://".$file."#".$zip->getNameIndex($i), "{$copy_to}");
+ }
+ copy("zip://" . $file . "#" .
$zip->getNameIndex($i), "{$copy_to}");
}
$zip->close();
-
+
return true;
- } else {
+ }
+ else
+ {
$this->receipt['error'][] = array('msg' =>
lang('Failed opening file %1', $file));
return false;
}
}
-
- private function _un_rar($file, $dir)
+
+ private function _un_rar( $file, $dir )
{
@set_time_limit(5 * 60);
-
+
$archive = RarArchive::open($file);
if ($archive === FALSE)
{
@@ -323,27 +345,27 @@
}
$entries = $archive->getEntries();
- foreach ($entries as $entry)
+ foreach ($entries as $entry)
{
$file_name = str_replace('..', '.',
$entry->getName());
- $copy_to = $dir.'/'.$file_name;
+ $copy_to = $dir . '/' . $file_name;
if (!is_dir(dirname($copy_to)))
{
mkdir(dirname($copy_to), 0777, true);
}
- copy("rar://".$file."#".$entry->getName(),
"{$copy_to}");
+ copy("rar://" . $file . "#" .
$entry->getName(), "{$copy_to}");
}
- $archive->close();
-
+ $archive->close();
+
return true;
}
-
- private function _uncompresed_file($path_file)
- {
+
+ private function _uncompresed_file( $path_file )
+ {
$info = pathinfo($path_file);
- $path_dir = $this->path_upload_dir.$info['filename'];
+ $path_dir = $this->path_upload_dir . $info['filename'];
$result = true;
-
+
if (!in_array($info['extension'], array('zip', 'rar')))
{
$this->receipt['error'][] = array('msg' =>
lang('The file extension should be zip or rar'));
@@ -355,11 +377,11 @@
exec("rm -Rf '{$path_dir}'", $ret);
}
mkdir($path_dir, 0777, true);
-
+
if ($info['extension'] == 'zip')
{
$result = $this->_un_zip($path_file, $path_dir);
- }
+ }
else if ($info['extension'] == 'rar')
{
$result = $this->_un_rar($path_file, $path_dir);
@@ -367,44 +389,45 @@
return $result;
}
-
+
private function _get_uploaded_files()
{
$compressed_file =
phpgw::get_var('compressed_file_check');
$compressed_file_name =
phpgw::get_var('compressed_file_name');
-
+
$list_files = array();
-
+
if ($compressed_file)
{
- $path_file =
$this->path_upload_dir.$compressed_file_name;
-
+ $path_file = $this->path_upload_dir .
$compressed_file_name;
+
if (!is_file($path_file))
{
$this->receipt['error'][] = array('msg'
=> lang('File %1 not exist', $path_file));
return;
}
-
+
if (!$this->_uncompresed_file($path_file))
{
return false;
}
-
+
$info = pathinfo($path_file);
- $path_dir =
$this->path_upload_dir.$info['filename'];
-
+ $path_dir = $this->path_upload_dir .
$info['filename'];
+
if (!is_dir($path_dir))
{
$this->receipt['error'][] = array('msg'
=> lang('Directory %1 not exist', $path_dir));
return;
}
-
- $list_files =
$this->_get_dir_contents($path_dir);
- }
- else {
- $list_files =
$this->_get_files($this->path_upload_dir);
+
+ $list_files =
$this->_get_dir_contents($path_dir);
}
-
+ else
+ {
+ $list_files =
$this->_get_files($this->path_upload_dir);
+ }
+
if (!count($list_files))
{
$this->receipt['error'][] = array('msg' =>
lang("no exist files to import"));
@@ -412,18 +435,18 @@
return $list_files;
}
-
- private function _get_files($dir, $results = array())
- {
+
+ private function _get_files( $dir, $results = array() )
+ {
$content = scandir($dir);
-
- foreach($content as $key => $value)
+
+ foreach ($content as $key => $value)
{
- $path = realpath($dir.'/'.$value);
- if(is_file($path))
- {
+ $path = realpath($dir . '/' . $value);
+ if (is_file($path))
+ {
$pos = strpos($value, '..');
- if (!$pos === false)
+ if (!$pos === false)
{
$new_path = str_replace('..',
'.', $path);
if (rename($path, $new_path))
@@ -431,64 +454,64 @@
$value =
str_replace('..', '.', $value);
$path = $new_path;
}
- }
+ }
- $results[] = array('file'=>$value,
- 'path_absolute'=>$path,
- 'path_relative'=>'/');
- }
+ $results[] = array('file' => $value,
+ 'path_absolute' => $path,
+ 'path_relative' => '/');
+ }
}
-
+
return $results;
}
-
- private function _get_dir_contents($dir, &$results = array())
- {
+
+ private function _get_dir_contents( $dir, &$results = array() )
+ {
$content = scandir($dir);
$patrones = array('(\\/)', '(\\\\)', '(")');
$sustituciones = array('_', '_', '_');
-
- foreach($content as $key => $value)
+
+ foreach ($content as $key => $value)
{
- $path = realpath($dir.'/'.$value);
- if(is_file($path))
- {
- $results[] = array('file'=>$value,
-
'path_string'=>preg_replace($patrones, $sustituciones, $path),
- 'path_absolute'=>$path,
- 'path_relative'=>substr($dir,
strlen($this->path_upload_dir)));
- }
- else if($value != "." && $value != "..")
+ $path = realpath($dir . '/' . $value);
+ if (is_file($path))
{
+ $results[] = array('file' => $value,
+ 'path_string' =>
preg_replace($patrones, $sustituciones, $path),
+ 'path_absolute' => $path,
+ 'path_relative' => substr($dir,
strlen($this->path_upload_dir)));
+ }
+ else if ($value != "." && $value != "..")
+ {
$this->_get_dir_contents($path,
$results);
}
}
-
+
return $results;
}
-
- public function get_relations ()
+
+ public function get_relations()
{
$exceldata =
$this->_getexceldata($_FILES['file']['tmp_name'], false);
$component_files = array();
-
+
$patrones = array('(\\/)', '(")');
$sustituciones = array('_', '_');
- foreach ($exceldata as $k => $row)
+ foreach ($exceldata as $k => $row)
{
if (!$this->_valid_row($row))
{
continue;
}
-
- $path_file = str_replace('..', '.',
$row[(count($row)-1)]);
+
+ $path_file = str_replace('..', '.',
$row[(count($row) - 1)]);
$path_file = preg_replace($patrones,
$sustituciones, $path_file);
$array_path = explode("\\", $path_file);
-
- $file_name = $array_path[count($array_path)-1];
- $path = implode("/", array_slice($array_path,
0, (count($array_path)-1)));
+
+ $file_name = $array_path[count($array_path) -
1];
+ $path = implode("/", array_slice($array_path,
0, (count($array_path) - 1)));
$path_string = implode("_", $array_path);
-
+
$component_files[$row[0]][] = array(
'name' => $row[1],
'desription' => $row[2],
@@ -498,43 +521,44 @@
'row' => ($k + 1)
);
}
-
+
return $component_files;
}
-
+
private function _delete_all_dir_temp()
{
$files = glob($this->path_upload_dir . '*', GLOB_MARK);
-
+
foreach ($files as $file)
{
$path = realpath($file);
- if (is_dir($path))
- {
- exec("rm -Rf '{$path}'", $ret);
- }
+ if (is_dir($path))
+ {
+ exec("rm -Rf '{$path}'", $ret);
+ }
}
}
-
- private function
_search_relations_with_components_location($relations)
+
+ private function _search_relations_with_components_location(
$relations )
{
- $count_new_relations = 0;
+ $count_new_relations = 0;
$count_relations_existing = 0;
- foreach ($relations as $k => $files)
+ foreach ($relations as $k => $files)
{
if (empty($k))
{
- $component = array('id' =>
$this->location_item_id, 'location_id' =>
$GLOBALS['phpgw']->locations->get_id('property',
'.location.'.count(explode('-', $this->location_code))));
+ $component = array('id' =>
$this->location_item_id, 'location_id' =>
$GLOBALS['phpgw']->locations->get_id('property', '.location.' .
count(explode('-', $this->location_code))));
}
- else {
+ else
+ {
$component = $this->_get_component($k,
$this->attrib_name_componentID, $this->location_code);
- if( empty($component['id']) ||
empty($component['location_id']))
+ if (empty($component['id']) ||
empty($component['location_id']))
{
$this->receipt['message'][] =
array('msg' => lang("Component '%1' with location code '%2' does not exist",
$k, $this->location_code));
continue;
}
}
-
+
$files_in_component =
$this->_get_files_by_component($component['id'], $component['location_id']);
foreach ($files as $file_data)
@@ -543,35 +567,39 @@
{
continue;
}
-
+
if (in_array($file_data['md5sum'],
$files_in_component))
{
$count_relations_existing++;
- } else {
+ }
+ else
+ {
$count_new_relations++;
}
}
- }
-
+ }
+
if ($count_relations_existing)
{
$this->receipt['message'][] = array('msg' =>
lang('%1 relations existing', $count_relations_existing));
- }
-
+ }
+
if ($count_new_relations)
{
$this->receipt['message'][] = array('msg' =>
lang('%1 new relations to add', $count_new_relations));
- } else {
+ }
+ else
+ {
$this->receipt['message'][] = array('msg' =>
lang('any relation to add'));
}
}
-
- private function _search_relations_with_location($relations)
+
+ private function _search_relations_with_location( $relations )
{
- $count_new_relations = 0;
+ $count_new_relations = 0;
$count_relations_existing = 0;
-
- $component = array('id' => $this->location_item_id,
'location_id' => $GLOBALS['phpgw']->locations->get_id('property',
'.location.'.count(explode('-', $this->location_code))));
+
+ $component = array('id' => $this->location_item_id,
'location_id' => $GLOBALS['phpgw']->locations->get_id('property', '.location.'
. count(explode('-', $this->location_code))));
$files_in_component =
$this->_get_files_by_component($component['id'], $component['location_id']);
foreach ($relations as $file_data)
@@ -584,49 +612,55 @@
if (in_array($file_data['md5sum'],
$files_in_component))
{
$count_relations_existing++;
- } else {
+ }
+ else
+ {
$count_new_relations++;
}
- }
-
+ }
+
if ($count_relations_existing)
{
$this->receipt['message'][] = array('msg' =>
lang('%1 relations existing', $count_relations_existing));
- }
-
+ }
+
if ($count_new_relations)
{
$this->receipt['message'][] = array('msg' =>
lang('%1 new relations to add', $count_new_relations));
- } else {
+ }
+ else
+ {
$this->receipt['message'][] = array('msg' =>
lang('any relation to add'));
}
}
-
- public function preview ()
+
+ public function preview()
{
$with_components =
phpgw::get_var('with_components_check');
-
+
$uploaded_files = $this->_get_uploaded_files();
-
+
if ($this->receipt['error'])
{
return $this->receipt;
}
-
+
if ($with_components)
{
$relations = $this->get_relations();
$this->_compare_names($relations,
$uploaded_files);
@@ Diff output truncated at 153600 characters. @@
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [16354] table: Merge 16351:16353 from trunk,
sigurdne <=