mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-11 04:52:14 +09:00
issue 2622 coding convention in classes
git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12218 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
1b2d64a4d7
commit
66e2363b43
6 changed files with 992 additions and 893 deletions
|
|
@ -1,29 +1,30 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Superclass of the edit component.
|
* Superclass of the edit component.
|
||||||
* Set up the component variables
|
* Set up the component variables
|
||||||
*
|
*
|
||||||
* @class EditorHandler
|
* @class EditorHandler
|
||||||
* @author NHN (developers@xpressengine.com)
|
* @author NHN (developers@xpressengine.com)
|
||||||
**/
|
*/
|
||||||
|
class EditorHandler extends Object
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* set the xml and other information of the component
|
||||||
|
* @param object $info editor information
|
||||||
|
* @return void
|
||||||
|
**/
|
||||||
|
function setInfo($info)
|
||||||
|
{
|
||||||
|
Context::set('component_info', $info);
|
||||||
|
|
||||||
class EditorHandler extends Object {
|
if(!$info->extra_vars) return;
|
||||||
|
|
||||||
/**
|
foreach($info->extra_vars as $key => $val)
|
||||||
* set the xml and other information of the component
|
{
|
||||||
* @param object $info editor information
|
$this->{$key} = trim($val->value);
|
||||||
* @return void
|
}
|
||||||
**/
|
}
|
||||||
function setInfo($info) {
|
|
||||||
Context::set('component_info', $info);
|
|
||||||
|
|
||||||
if(!$info->extra_vars) return;
|
}
|
||||||
|
/* End of file EditorHandler.class.php */
|
||||||
foreach($info->extra_vars as $key => $val) {
|
/* Location: ./classes/editor/EditorHandler.class.php */
|
||||||
$this->{$key} = trim($val->value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
|
||||||
|
|
@ -1,397 +1,413 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* A class to handle extra variables used in posts, member and others
|
* A class to handle extra variables used in posts, member and others
|
||||||
|
*
|
||||||
|
* @author NHN (developers@xpressengine.com)
|
||||||
|
*/
|
||||||
|
class ExtraVar
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* sequence of module
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
var $module_srl = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current module's Set of ExtraItem
|
||||||
|
* @var ExtraItem[]
|
||||||
|
*/
|
||||||
|
var $keys = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get instance of ExtraVar (singleton)
|
||||||
*
|
*
|
||||||
* @author NHN (developers@xpressengine.com)
|
* @param int $module_srl Sequence of module
|
||||||
**/
|
* @return ExtraVar
|
||||||
class ExtraVar {
|
*/
|
||||||
|
function &getInstance($module_srl)
|
||||||
|
{
|
||||||
|
return new ExtraVar($module_srl);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sequence of module
|
* Constructor
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
var $module_srl = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Current module's Set of ExtraItem
|
|
||||||
* @var ExtraItem[]
|
|
||||||
*/
|
|
||||||
var $keys = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get instance of ExtraVar (singleton)
|
|
||||||
*
|
|
||||||
* @param int $module_srl Sequence of module
|
|
||||||
* @return ExtraVar
|
|
||||||
**/
|
|
||||||
function &getInstance($module_srl) {
|
|
||||||
return new ExtraVar($module_srl);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
*
|
|
||||||
* @param int $module_srl Sequence of module
|
|
||||||
* @return void
|
|
||||||
**/
|
|
||||||
function ExtraVar($module_srl) {
|
|
||||||
$this->module_srl = $module_srl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a key of extra variable
|
|
||||||
*
|
|
||||||
* @param object[] $extra_keys Array of extra variable. A value of array is object that contains module_srl, idx, name, default, desc, is_required, search, value, eid.
|
|
||||||
* @return void
|
|
||||||
**/
|
|
||||||
function setExtraVarKeys($extra_keys) {
|
|
||||||
if(!is_array($extra_keys) || !count($extra_keys)) return;
|
|
||||||
foreach($extra_keys as $key => $val) {
|
|
||||||
$obj = null;
|
|
||||||
$obj = new ExtraItem($val->module_srl, $val->idx, $val->name, $val->type, $val->default, $val->desc, $val->is_required, $val->search, $val->value, $val->eid);
|
|
||||||
$this->keys[$val->idx] = $obj;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an array of ExtraItem
|
|
||||||
*
|
|
||||||
* @return ExtraItem[]
|
|
||||||
**/
|
|
||||||
function getExtraVars() {
|
|
||||||
return $this->keys;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Each value of the extra vars
|
|
||||||
*
|
*
|
||||||
* @author NHN (developers@xpressengine.com)
|
* @param int $module_srl Sequence of module
|
||||||
**/
|
* @return void
|
||||||
class ExtraItem {
|
*/
|
||||||
/**
|
function ExtraVar($module_srl)
|
||||||
* Sequence of module
|
{
|
||||||
* @var int
|
$this->module_srl = $module_srl;
|
||||||
*/
|
}
|
||||||
var $module_srl = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Index of extra variable
|
* Register a key of extra variable
|
||||||
* @var int
|
*
|
||||||
*/
|
* @param object[] $extra_keys Array of extra variable. A value of array is object that contains module_srl, idx, name, default, desc, is_required, search, value, eid.
|
||||||
var $idx = 0;
|
* @return void
|
||||||
|
*/
|
||||||
|
function setExtraVarKeys($extra_keys)
|
||||||
|
{
|
||||||
|
if(!is_array($extra_keys) || !count($extra_keys)) return;
|
||||||
|
foreach($extra_keys as $key => $val)
|
||||||
|
{
|
||||||
|
$obj = null;
|
||||||
|
$obj = new ExtraItem($val->module_srl, $val->idx, $val->name, $val->type, $val->default, $val->desc, $val->is_required, $val->search, $val->value, $val->eid);
|
||||||
|
$this->keys[$val->idx] = $obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of extra variable
|
* Returns an array of ExtraItem
|
||||||
* @var string
|
*
|
||||||
*/
|
* @return ExtraItem[]
|
||||||
var $name = 0;
|
*/
|
||||||
|
function getExtraVars()
|
||||||
|
{
|
||||||
|
return $this->keys;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type of extra variable
|
* Each value of the extra vars
|
||||||
* @var string text, homepage, email_address, tel, textarea, checkbox, date, select, radio, kr_zip
|
*
|
||||||
*/
|
* @author NHN (developers@xpressengine.com)
|
||||||
var $type = 'text';
|
*/
|
||||||
|
class ExtraItem
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Sequence of module
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
var $module_srl = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default values
|
* Index of extra variable
|
||||||
* @var string[]
|
* @var int
|
||||||
*/
|
*/
|
||||||
var $default = null;
|
var $idx = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description
|
* Name of extra variable
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
var $desc = '';
|
var $name = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether required or not requred this extra variable
|
* Type of extra variable
|
||||||
* @var string Y, N
|
* @var string text, homepage, email_address, tel, textarea, checkbox, date, select, radio, kr_zip
|
||||||
*/
|
*/
|
||||||
var $is_required = 'N';
|
var $type = 'text';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether can or can not search this extra variable
|
* Default values
|
||||||
* @var string Y, N
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
var $search = 'N';
|
var $default = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Value
|
* Description
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
var $value = null;
|
var $desc = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unique id of extra variable in module
|
* Whether required or not requred this extra variable
|
||||||
* @var string
|
* @var string Y, N
|
||||||
*/
|
*/
|
||||||
var $eid = '';
|
var $is_required = 'N';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Whether can or can not search this extra variable
|
||||||
*
|
* @var string Y, N
|
||||||
* @param int $module_srl Sequence of module
|
*/
|
||||||
* @param int $idx Index of extra variable
|
var $search = 'N';
|
||||||
* @param string $type Type of extra variable. text, homepage, email_address, tel, textarea, checkbox, date, sleect, radio, kr_zip
|
|
||||||
* @param string[] $default Default values
|
|
||||||
* @param string $desc Description
|
|
||||||
* @param string $is_required Whether required or not requred this extra variable. Y, N
|
|
||||||
* @param string $search Whether can or can not search this extra variable
|
|
||||||
* @param string $value Value
|
|
||||||
* @param string $eid Unique id of extra variable in module
|
|
||||||
* @return void
|
|
||||||
**/
|
|
||||||
function ExtraItem($module_srl, $idx, $name, $type = 'text', $default = null, $desc = '', $is_required = 'N', $search = 'N', $value = null, $eid = '') {
|
|
||||||
if(!$idx) return;
|
|
||||||
$this->module_srl = $module_srl;
|
|
||||||
$this->idx = $idx;
|
|
||||||
$this->name = $name;
|
|
||||||
$this->type = $type;
|
|
||||||
$this->default = $default;
|
|
||||||
$this->desc = $desc;
|
|
||||||
$this->is_required = $is_required;
|
|
||||||
$this->search = $search;
|
|
||||||
$this->value = $value;
|
|
||||||
$this->eid = $eid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets Value
|
* Value
|
||||||
*
|
* @var string
|
||||||
* @param string $value The value to set
|
*/
|
||||||
* @return void
|
var $value = null;
|
||||||
**/
|
|
||||||
function setValue($value) {
|
|
||||||
$this->value = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a given value converted based on its type
|
* Unique id of extra variable in module
|
||||||
*
|
* @var string
|
||||||
* @param string $type Type of variable
|
*/
|
||||||
* @param string $value Value
|
var $eid = '';
|
||||||
* @return string Returns a converted value
|
|
||||||
**/
|
|
||||||
function _getTypeValue($type, $value) {
|
|
||||||
$value = trim($value);
|
|
||||||
if(!isset($value)) return;
|
|
||||||
switch($type) {
|
|
||||||
case 'homepage' :
|
|
||||||
if($value && !preg_match('/^([a-z]+):\/\//i',$value)) $value = 'http://'.$value;
|
|
||||||
return htmlspecialchars($value);
|
|
||||||
break;
|
|
||||||
case 'tel' :
|
|
||||||
if(is_array($value)) $values = $value;
|
|
||||||
elseif(strpos($value,'|@|')!==false) $values = explode('|@|', $value);
|
|
||||||
elseif(strpos($value,',')!==false) $values = explode(',', $value);
|
|
||||||
$values[0] = $values[0];
|
|
||||||
$values[1] = $values[1];
|
|
||||||
$values[2] = $values[2];
|
|
||||||
return $values;
|
|
||||||
break;
|
|
||||||
break;
|
|
||||||
case 'checkbox' :
|
|
||||||
case 'radio' :
|
|
||||||
case 'select' :
|
|
||||||
if(is_array($value)) $values = $value;
|
|
||||||
elseif(strpos($value,'|@|')!==false) $values = explode('|@|', $value);
|
|
||||||
elseif(strpos($value,',')!==false) $values = explode(',', $value);
|
|
||||||
else $values = array($value);
|
|
||||||
for($i=0;$i<count($values);$i++) $values[$i] = htmlspecialchars($values[$i]);
|
|
||||||
return $values;
|
|
||||||
break;
|
|
||||||
case 'kr_zip' :
|
|
||||||
if(is_array($value)) $values = $value;
|
|
||||||
elseif(strpos($value,'|@|')!==false) $values = explode('|@|', $value);
|
|
||||||
elseif(strpos($value,',')!==false) $values = explode(',', $value);
|
|
||||||
else $values = array($value);
|
|
||||||
return $values;
|
|
||||||
break;
|
|
||||||
//case 'date' :
|
|
||||||
//case 'email_address' :
|
|
||||||
//case 'text' :
|
|
||||||
//case 'textarea' :
|
|
||||||
default :
|
|
||||||
return htmlspecialchars($value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a value for HTML
|
* Constructor
|
||||||
*
|
*
|
||||||
* @return string Returns a value expressed in HTML.
|
* @param int $module_srl Sequence of module
|
||||||
**/
|
* @param int $idx Index of extra variable
|
||||||
function getValueHTML() {
|
* @param string $type Type of extra variable. text, homepage, email_address, tel, textarea, checkbox, date, sleect, radio, kr_zip
|
||||||
$value = $this->_getTypeValue($this->type, $this->value);
|
* @param string[] $default Default values
|
||||||
switch($this->type) {
|
* @param string $desc Description
|
||||||
case 'homepage' :
|
* @param string $is_required Whether required or not requred this extra variable. Y, N
|
||||||
return ($value)?(sprintf('<a href="%s" target="_blank">%s</a>', $value, strlen($value)>60?substr($value,0,40).'...'.substr($value,-10):$value)):"";
|
* @param string $search Whether can or can not search this extra variable
|
||||||
case 'email_address' :
|
* @param string $value Value
|
||||||
return ($value)?sprintf('<a href="mailto:%s">%s</a>', $value, $value):"";
|
* @param string $eid Unique id of extra variable in module
|
||||||
break;
|
* @return void
|
||||||
case 'tel' :
|
*/
|
||||||
return sprintf('%s - %s - %s', $value[0],$value[1],$value[2]);
|
function ExtraItem($module_srl, $idx, $name, $type = 'text', $default = null, $desc = '', $is_required = 'N', $search = 'N', $value = null, $eid = '')
|
||||||
break;
|
{
|
||||||
case 'textarea' :
|
if(!$idx) return;
|
||||||
return nl2br($value);
|
$this->module_srl = $module_srl;
|
||||||
break;
|
$this->idx = $idx;
|
||||||
case 'checkbox' :
|
$this->name = $name;
|
||||||
if(is_array($value)) return implode(', ',$value);
|
$this->type = $type;
|
||||||
else return $value;
|
$this->default = $default;
|
||||||
break;
|
$this->desc = $desc;
|
||||||
case 'date' :
|
$this->is_required = $is_required;
|
||||||
return zdate($value,"Y-m-d");
|
$this->search = $search;
|
||||||
break;
|
$this->value = $value;
|
||||||
case 'select' :
|
$this->eid = $eid;
|
||||||
case 'radio' :
|
}
|
||||||
if(is_array($value)) return implode(', ',$value);
|
|
||||||
else return $value;
|
|
||||||
break;
|
|
||||||
case 'kr_zip' :
|
|
||||||
if(is_array($value)) return implode(' ',$value);
|
|
||||||
else return $value;
|
|
||||||
break;
|
|
||||||
// case 'text' :
|
|
||||||
default :
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a form based on its type
|
* Sets Value
|
||||||
*
|
*
|
||||||
* @return string Returns a form html.
|
* @param string $value The value to set
|
||||||
**/
|
* @return void
|
||||||
function getFormHTML() {
|
*/
|
||||||
static $id_num = 1000;
|
function setValue($value)
|
||||||
|
{
|
||||||
|
$this->value = $value;
|
||||||
|
}
|
||||||
|
|
||||||
$type = $this->type;
|
/**
|
||||||
$name = $this->name;
|
* Returns a given value converted based on its type
|
||||||
$value = $this->_getTypeValue($this->type, $this->value);
|
*
|
||||||
$default = $this->_getTypeValue($this->type, $this->default);
|
* @param string $type Type of variable
|
||||||
$column_name = 'extra_vars'.$this->idx;
|
* @param string $value Value
|
||||||
$tmp_id = $column_name.'-'.$id_num++;
|
* @return string Returns a converted value
|
||||||
|
*/
|
||||||
|
function _getTypeValue($type, $value)
|
||||||
|
{
|
||||||
|
$value = trim($value);
|
||||||
|
if(!isset($value)) return;
|
||||||
|
switch($type)
|
||||||
|
{
|
||||||
|
case 'homepage' :
|
||||||
|
if($value && !preg_match('/^([a-z]+):\/\//i',$value)) $value = 'http://'.$value;
|
||||||
|
return htmlspecialchars($value);
|
||||||
|
break;
|
||||||
|
case 'tel' :
|
||||||
|
if(is_array($value)) $values = $value;
|
||||||
|
elseif(strpos($value,'|@|')!==false) $values = explode('|@|', $value);
|
||||||
|
elseif(strpos($value,',')!==false) $values = explode(',', $value);
|
||||||
|
$values[0] = $values[0];
|
||||||
|
$values[1] = $values[1];
|
||||||
|
$values[2] = $values[2];
|
||||||
|
return $values;
|
||||||
|
break;
|
||||||
|
break;
|
||||||
|
case 'checkbox' :
|
||||||
|
case 'radio' :
|
||||||
|
case 'select' :
|
||||||
|
if(is_array($value)) $values = $value;
|
||||||
|
elseif(strpos($value,'|@|')!==false) $values = explode('|@|', $value);
|
||||||
|
elseif(strpos($value,',')!==false) $values = explode(',', $value);
|
||||||
|
else $values = array($value);
|
||||||
|
for($i=0;$i<count($values);$i++) $values[$i] = htmlspecialchars($values[$i]);
|
||||||
|
return $values;
|
||||||
|
break;
|
||||||
|
case 'kr_zip' :
|
||||||
|
if(is_array($value)) $values = $value;
|
||||||
|
elseif(strpos($value,'|@|')!==false) $values = explode('|@|', $value);
|
||||||
|
elseif(strpos($value,',')!==false) $values = explode(',', $value);
|
||||||
|
else $values = array($value);
|
||||||
|
return $values;
|
||||||
|
break;
|
||||||
|
//case 'date' :
|
||||||
|
//case 'email_address' :
|
||||||
|
//case 'text' :
|
||||||
|
//case 'textarea' :
|
||||||
|
default :
|
||||||
|
return htmlspecialchars($value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$buff = '';
|
/**
|
||||||
switch($type) {
|
* Returns a value for HTML
|
||||||
// Homepage
|
*
|
||||||
case 'homepage' :
|
* @return string Returns a value expressed in HTML.
|
||||||
$buff .= '<input type="text" name="'.$column_name.'" value="'.$value.'" class="homepage" />';
|
*/
|
||||||
break;
|
function getValueHTML()
|
||||||
// Email Address
|
{
|
||||||
case 'email_address' :
|
$value = $this->_getTypeValue($this->type, $this->value);
|
||||||
$buff .= '<input type="text" name="'.$column_name.'" value="'.$value.'" class="email_address" />';
|
switch($this->type)
|
||||||
break;
|
{
|
||||||
// Phone Number
|
case 'homepage' :
|
||||||
case 'tel' :
|
return ($value)?(sprintf('<a href="%s" target="_blank">%s</a>', $value, strlen($value)>60?substr($value,0,40).'...'.substr($value,-10):$value)):"";
|
||||||
$buff .=
|
case 'email_address' :
|
||||||
'<input type="text" name="'.$column_name.'[]" value="'.$value[0].'" size="4" maxlength="4" class="tel" />'.
|
return ($value)?sprintf('<a href="mailto:%s">%s</a>', $value, $value):"";
|
||||||
'<input type="text" name="'.$column_name.'[]" value="'.$value[1].'" size="4" maxlength="4" class="tel" />'.
|
break;
|
||||||
'<input type="text" name="'.$column_name.'[]" value="'.$value[2].'" size="4" maxlength="4" class="tel" />';
|
case 'tel' :
|
||||||
break;
|
return sprintf('%s - %s - %s', $value[0],$value[1],$value[2]);
|
||||||
|
break;
|
||||||
|
case 'textarea' :
|
||||||
|
return nl2br($value);
|
||||||
|
break;
|
||||||
|
case 'checkbox' :
|
||||||
|
if(is_array($value)) return implode(', ',$value);
|
||||||
|
else return $value;
|
||||||
|
break;
|
||||||
|
case 'date' :
|
||||||
|
return zdate($value,"Y-m-d");
|
||||||
|
break;
|
||||||
|
case 'select' :
|
||||||
|
case 'radio' :
|
||||||
|
if(is_array($value)) return implode(', ',$value);
|
||||||
|
else return $value;
|
||||||
|
break;
|
||||||
|
case 'kr_zip' :
|
||||||
|
if(is_array($value)) return implode(' ',$value);
|
||||||
|
else return $value;
|
||||||
|
break;
|
||||||
|
// case 'text' :
|
||||||
|
default :
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// textarea
|
/**
|
||||||
case 'textarea' :
|
* Returns a form based on its type
|
||||||
$buff .= '<textarea name="'.$column_name.'" rows="8" cols="42">'.$value.'</textarea>';
|
*
|
||||||
break;
|
* @return string Returns a form html.
|
||||||
// multiple choice
|
*/
|
||||||
case 'checkbox' :
|
function getFormHTML()
|
||||||
$buff .= '<ul>';
|
{
|
||||||
foreach($default as $v) {
|
static $id_num = 1000;
|
||||||
if($value && in_array(trim($v), $value)) $checked = ' checked="checked"';
|
|
||||||
else $checked = '';
|
|
||||||
|
|
||||||
// Temporary ID for labeling
|
$type = $this->type;
|
||||||
$tmp_id = $column_name.'-'.$id_num++;
|
$name = $this->name;
|
||||||
|
$value = $this->_getTypeValue($this->type, $this->value);
|
||||||
|
$default = $this->_getTypeValue($this->type, $this->default);
|
||||||
|
$column_name = 'extra_vars'.$this->idx;
|
||||||
|
$tmp_id = $column_name.'-'.$id_num++;
|
||||||
|
|
||||||
$buff .='<li><input type="checkbox" name="'.$column_name.'[]" id="'.$tmp_id.'" value="'.htmlspecialchars($v).'" '.$checked.' /><label for="'.$tmp_id.'">'.$v.'</label></li>';
|
$buff = '';
|
||||||
}
|
switch($type)
|
||||||
$buff .= '</ul>';
|
{
|
||||||
break;
|
// Homepage
|
||||||
// single choice
|
case 'homepage' :
|
||||||
case 'select' :
|
$buff .= '<input type="text" name="'.$column_name.'" value="'.$value.'" class="homepage" />';
|
||||||
$buff .= '<select name="'.$column_name.'" class="select">';
|
break;
|
||||||
foreach($default as $v) {
|
// Email Address
|
||||||
if($value && in_array($v,$value)) $selected = ' selected="selected"';
|
case 'email_address' :
|
||||||
else $selected = '';
|
$buff .= '<input type="text" name="'.$column_name.'" value="'.$value.'" class="email_address" />';
|
||||||
$buff .= '<option value="'.$v.'" '.$selected.'>'.$v.'</option>';
|
break;
|
||||||
}
|
// Phone Number
|
||||||
$buff .= '</select>';
|
case 'tel' :
|
||||||
break;
|
$buff .=
|
||||||
|
'<input type="text" name="'.$column_name.'[]" value="'.$value[0].'" size="4" maxlength="4" class="tel" />'.
|
||||||
|
'<input type="text" name="'.$column_name.'[]" value="'.$value[1].'" size="4" maxlength="4" class="tel" />'.
|
||||||
|
'<input type="text" name="'.$column_name.'[]" value="'.$value[2].'" size="4" maxlength="4" class="tel" />';
|
||||||
|
break;
|
||||||
|
// textarea
|
||||||
|
case 'textarea' :
|
||||||
|
$buff .= '<textarea name="'.$column_name.'" rows="8" cols="42">'.$value.'</textarea>';
|
||||||
|
break;
|
||||||
|
// multiple choice
|
||||||
|
case 'checkbox' :
|
||||||
|
$buff .= '<ul>';
|
||||||
|
foreach($default as $v)
|
||||||
|
{
|
||||||
|
if($value && in_array(trim($v), $value)) $checked = ' checked="checked"';
|
||||||
|
else $checked = '';
|
||||||
|
|
||||||
// radio
|
// Temporary ID for labeling
|
||||||
case 'radio' :
|
$tmp_id = $column_name.'-'.$id_num++;
|
||||||
$buff .= '<ul>';
|
|
||||||
foreach($default as $v) {
|
|
||||||
if($value && in_array($v,$value)) $checked = ' checked="checked"';
|
|
||||||
else $checked = '';
|
|
||||||
|
|
||||||
// Temporary ID for labeling
|
$buff .='<li><input type="checkbox" name="'.$column_name.'[]" id="'.$tmp_id.'" value="'.htmlspecialchars($v).'" '.$checked.' /><label for="'.$tmp_id.'">'.$v.'</label></li>';
|
||||||
$tmp_id = $column_name.'-'.$id_num++;
|
}
|
||||||
|
$buff .= '</ul>';
|
||||||
|
break;
|
||||||
|
// single choice
|
||||||
|
case 'select' :
|
||||||
|
$buff .= '<select name="'.$column_name.'" class="select">';
|
||||||
|
foreach($default as $v)
|
||||||
|
{
|
||||||
|
if($value && in_array($v,$value)) $selected = ' selected="selected"';
|
||||||
|
else $selected = '';
|
||||||
|
$buff .= '<option value="'.$v.'" '.$selected.'>'.$v.'</option>';
|
||||||
|
}
|
||||||
|
$buff .= '</select>';
|
||||||
|
break;
|
||||||
|
// radio
|
||||||
|
case 'radio' :
|
||||||
|
$buff .= '<ul>';
|
||||||
|
foreach($default as $v)
|
||||||
|
{
|
||||||
|
if($value && in_array($v,$value)) $checked = ' checked="checked"';
|
||||||
|
else $checked = '';
|
||||||
|
|
||||||
$buff .= '<li><input type="radio" name="'.$column_name.'" id="'.$tmp_id.'" '.$checked.' value="'.$v.'" class="radio" /><label for="'.$tmp_id.'">'.$v.'</label></li>';
|
// Temporary ID for labeling
|
||||||
}
|
$tmp_id = $column_name.'-'.$id_num++;
|
||||||
$buff .= '</ul>';
|
|
||||||
break;
|
|
||||||
// date
|
|
||||||
case 'date' :
|
|
||||||
// datepicker javascript plugin load
|
|
||||||
Context::loadJavascriptPlugin('ui.datepicker');
|
|
||||||
|
|
||||||
$buff .=
|
$buff .= '<li><input type="radio" name="'.$column_name.'" id="'.$tmp_id.'" '.$checked.' value="'.$v.'" class="radio" /><label for="'.$tmp_id.'">'.$v.'</label></li>';
|
||||||
'<input type="hidden" name="'.$column_name.'" value="'.$value.'" />'.
|
}
|
||||||
'<input type="text" id="date_'.$column_name.'" value="'.zdate($value,'Y-m-d').'" class="date" /> <input type="button" value="' . Context::getLang('cmd_delete') . '" id="dateRemover_' . $column_name . '" />'."\n".
|
$buff .= '</ul>';
|
||||||
'<script>'."\n".
|
break;
|
||||||
'(function($){'."\n".
|
// date
|
||||||
' $(function(){'."\n".
|
case 'date' :
|
||||||
' var option = { dateFormat: "yy-mm-dd", changeMonth:true, changeYear:true, gotoCurrent: false,yearRange:\'-100:+10\', onSelect:function(){'."\n".
|
// datepicker javascript plugin load
|
||||||
' $(this).prev(\'input[type="hidden"]\').val(this.value.replace(/-/g,""))}'."\n".
|
Context::loadJavascriptPlugin('ui.datepicker');
|
||||||
' };'."\n".
|
|
||||||
' $.extend(option,$.datepicker.regional[\''.Context::getLangType().'\']);'."\n".
|
|
||||||
' $("#date_'.$column_name.'").datepicker(option);'."\n".
|
|
||||||
' $("#dateRemover_' . $column_name . '").click(function(){' . "\n" .
|
|
||||||
' $(this).siblings("input").val("");' . "\n" .
|
|
||||||
' return false;' . "\n" .
|
|
||||||
' })' . "\n" .
|
|
||||||
' });'."\n".
|
|
||||||
'})(jQuery);'."\n".
|
|
||||||
'</script>';
|
|
||||||
break;
|
|
||||||
// address
|
|
||||||
case "kr_zip" :
|
|
||||||
// krzip address javascript plugin load
|
|
||||||
Context::loadJavascriptPlugin('ui.krzip');
|
|
||||||
|
|
||||||
$buff .=
|
$buff .=
|
||||||
'<div id="addr_searched_'.$column_name.'" style="display:'.($value[0]?'block':'none').';">'.
|
'<input type="hidden" name="'.$column_name.'" value="'.$value.'" />'.
|
||||||
'<input type="text" readonly="readonly" name="'.$column_name.'[]" value="'.$value[0].'" class="address" />'.
|
'<input type="text" id="date_'.$column_name.'" value="'.zdate($value,'Y-m-d').'" class="date" /> <input type="button" value="' . Context::getLang('cmd_delete') . '" id="dateRemover_' . $column_name . '" />'."\n".
|
||||||
'<a href="#" onclick="doShowKrZipSearch(this, \''.$column_name.'\'); return false;" class="button red"><span>'.Context::getLang('cmd_cancel').'</span></a>'.
|
'<script>'."\n".
|
||||||
'</div>'.
|
'(function($){'."\n".
|
||||||
|
' $(function(){'."\n".
|
||||||
|
' var option = { dateFormat: "yy-mm-dd", changeMonth:true, changeYear:true, gotoCurrent: false,yearRange:\'-100:+10\', onSelect:function(){'."\n".
|
||||||
|
' $(this).prev(\'input[type="hidden"]\').val(this.value.replace(/-/g,""))}'."\n".
|
||||||
|
' };'."\n".
|
||||||
|
' $.extend(option,$.datepicker.regional[\''.Context::getLangType().'\']);'."\n".
|
||||||
|
' $("#date_'.$column_name.'").datepicker(option);'."\n".
|
||||||
|
' $("#dateRemover_' . $column_name . '").click(function(){' . "\n" .
|
||||||
|
' $(this).siblings("input").val("");' . "\n" .
|
||||||
|
' return false;' . "\n" .
|
||||||
|
' })' . "\n" .
|
||||||
|
' });'."\n".
|
||||||
|
'})(jQuery);'."\n".
|
||||||
|
'</script>';
|
||||||
|
break;
|
||||||
|
// address
|
||||||
|
case "kr_zip" :
|
||||||
|
// krzip address javascript plugin load
|
||||||
|
Context::loadJavascriptPlugin('ui.krzip');
|
||||||
|
|
||||||
'<div id="addr_list_'.$column_name.'" style="display:none;">'.
|
$buff .=
|
||||||
'<select name="addr_list_'.$column_name.'"></select>'.
|
'<div id="addr_searched_'.$column_name.'" style="display:'.($value[0]?'block':'none').';">'.
|
||||||
'<a href="#" onclick="doSelectKrZip(this, \''.$column_name.'\'); return false;" class="button blue"><span>'.Context::getLang('cmd_select').'</span></a>'.
|
'<input type="text" readonly="readonly" name="'.$column_name.'[]" value="'.$value[0].'" class="address" />'.
|
||||||
'<a href="#" onclick="doHideKrZipList(this, \''.$column_name.'\'); return false;" class="button red"><span>'.Context::getLang('cmd_cancel').'</span></a>'.
|
'<a href="#" onclick="doShowKrZipSearch(this, \''.$column_name.'\'); return false;" class="button red"><span>'.Context::getLang('cmd_cancel').'</span></a>'.
|
||||||
'</div>'.
|
'</div>'.
|
||||||
|
|
||||||
'<div id="addr_search_'.$column_name.'" style="display:'.($value[0]?'none':'block').'">'.
|
'<div id="addr_list_'.$column_name.'" style="display:none;">'.
|
||||||
'<input type="text" name="addr_search_'.$column_name.'" class="address" value="" />'.
|
'<select name="addr_list_'.$column_name.'"></select>'.
|
||||||
'<a href="#" onclick="doSearchKrZip(this, \''.$column_name.'\'); return false;" class="button green"><span>'.Context::getLang('cmd_search').'</span></a>'.
|
'<a href="#" onclick="doSelectKrZip(this, \''.$column_name.'\'); return false;" class="button blue"><span>'.Context::getLang('cmd_select').'</span></a>'.
|
||||||
'</div>'.
|
'<a href="#" onclick="doHideKrZipList(this, \''.$column_name.'\'); return false;" class="button red"><span>'.Context::getLang('cmd_cancel').'</span></a>'.
|
||||||
|
'</div>'.
|
||||||
|
|
||||||
'<input type="text" name="'.$column_name.'[]" value="'.htmlspecialchars($value[1]).'" class="address" />'.
|
'<div id="addr_search_'.$column_name.'" style="display:'.($value[0]?'none':'block').'">'.
|
||||||
'';
|
'<input type="text" name="addr_search_'.$column_name.'" class="address" value="" />'.
|
||||||
break;
|
'<a href="#" onclick="doSearchKrZip(this, \''.$column_name.'\'); return false;" class="button green"><span>'.Context::getLang('cmd_search').'</span></a>'.
|
||||||
// General text
|
'</div>'.
|
||||||
default :
|
|
||||||
$buff .=' <input type="text" name="'.$column_name.'" value="'.($value ? $value : $default).'" class="text" />';
|
'<input type="text" name="'.$column_name.'[]" value="'.htmlspecialchars($value[1]).'" class="address" />'.
|
||||||
break;
|
'';
|
||||||
}
|
break;
|
||||||
if($this->desc) $buff .= '<p>'.$this->desc.'</p>';
|
// General text
|
||||||
return $buff;
|
default :
|
||||||
}
|
$buff .=' <input type="text" name="'.$column_name.'" value="'.($value ? $value : $default).'" class="text" />';
|
||||||
}
|
break;
|
||||||
?>
|
}
|
||||||
|
if($this->desc) $buff .= '<p>'.$this->desc.'</p>';
|
||||||
|
return $buff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* End of file ExtraVar.class.php */
|
||||||
|
/* Location: ./classes/extravar/ExtraVar.class.php */
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,17 @@
|
||||||
* Contains methods for accessing file system
|
* Contains methods for accessing file system
|
||||||
*
|
*
|
||||||
* @author NHN (developers@xpressengine.com)
|
* @author NHN (developers@xpressengine.com)
|
||||||
**/
|
*/
|
||||||
class FileHandler {
|
class FileHandler
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Changes path of target file, directory into absolute path
|
* Changes path of target file, directory into absolute path
|
||||||
*
|
*
|
||||||
* @param string $source path to change into absolute path
|
* @param string $source path to change into absolute path
|
||||||
* @return string Absolute path
|
* @return string Absolute path
|
||||||
**/
|
*/
|
||||||
function getRealPath($source) {
|
function getRealPath($source)
|
||||||
|
{
|
||||||
$temp = explode('/', $source);
|
$temp = explode('/', $source);
|
||||||
if($temp[0] == '.') $source = _XE_PATH_.substr($source, 2);
|
if($temp[0] == '.') $source = _XE_PATH_.substr($source, 2);
|
||||||
return $source;
|
return $source;
|
||||||
|
|
@ -27,8 +29,9 @@ class FileHandler {
|
||||||
* @param string $filter Regex to filter files. If file matches this regex, the file is not copied.
|
* @param string $filter Regex to filter files. If file matches this regex, the file is not copied.
|
||||||
* @param string $type If set as 'force'. Even if the file exists in target, the file is copied.
|
* @param string $type If set as 'force'. Even if the file exists in target, the file is copied.
|
||||||
* @return void
|
* @return void
|
||||||
**/
|
*/
|
||||||
function copyDir($source_dir, $target_dir, $filter=null,$type=null){
|
function copyDir($source_dir, $target_dir, $filter=null,$type=null)
|
||||||
|
{
|
||||||
$source_dir = FileHandler::getRealPath($source_dir);
|
$source_dir = FileHandler::getRealPath($source_dir);
|
||||||
$target_dir = FileHandler::getRealPath($target_dir);
|
$target_dir = FileHandler::getRealPath($target_dir);
|
||||||
if(!is_dir($source_dir)) return false;
|
if(!is_dir($source_dir)) return false;
|
||||||
|
|
@ -39,15 +42,22 @@ class FileHandler {
|
||||||
if(substr($target_dir, -1) != '/') $target_dir .= '/';
|
if(substr($target_dir, -1) != '/') $target_dir .= '/';
|
||||||
|
|
||||||
$oDir = dir($source_dir);
|
$oDir = dir($source_dir);
|
||||||
while($file = $oDir->read()) {
|
while($file = $oDir->read())
|
||||||
|
{
|
||||||
if(substr($file,0,1)=='.') continue;
|
if(substr($file,0,1)=='.') continue;
|
||||||
if($filter && preg_match($filter, $file)) continue;
|
if($filter && preg_match($filter, $file)) continue;
|
||||||
if(is_dir($source_dir.$file)){
|
if(is_dir($source_dir.$file))
|
||||||
|
{
|
||||||
FileHandler::copyDir($source_dir.$file,$target_dir.$file,$type);
|
FileHandler::copyDir($source_dir.$file,$target_dir.$file,$type);
|
||||||
}else{
|
}
|
||||||
if($type == 'force'){
|
else
|
||||||
|
{
|
||||||
|
if($type == 'force')
|
||||||
|
{
|
||||||
@unlink($target_dir.$file);
|
@unlink($target_dir.$file);
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if(!file_exists($target_dir.$file)) @copy($source_dir.$file,$target_dir.$file);
|
if(!file_exists($target_dir.$file)) @copy($source_dir.$file,$target_dir.$file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -61,8 +71,9 @@ class FileHandler {
|
||||||
* @param string $target Path of target file
|
* @param string $target Path of target file
|
||||||
* @param string $force Y: overwrite
|
* @param string $force Y: overwrite
|
||||||
* @return void
|
* @return void
|
||||||
**/
|
*/
|
||||||
function copyFile($source, $target, $force='Y'){
|
function copyFile($source, $target, $force='Y')
|
||||||
|
{
|
||||||
setlocale(LC_CTYPE, 'en_US.UTF8', 'ko_KR.UTF8');
|
setlocale(LC_CTYPE, 'en_US.UTF8', 'ko_KR.UTF8');
|
||||||
$source = FileHandler::getRealPath($source);
|
$source = FileHandler::getRealPath($source);
|
||||||
$target_dir = FileHandler::getRealPath(dirname($target));
|
$target_dir = FileHandler::getRealPath(dirname($target));
|
||||||
|
|
@ -77,8 +88,9 @@ class FileHandler {
|
||||||
*
|
*
|
||||||
* @param string $file_name Path of target file
|
* @param string $file_name Path of target file
|
||||||
* @return string The content of the file. If target file does not exist, this function returns nothing.
|
* @return string The content of the file. If target file does not exist, this function returns nothing.
|
||||||
**/
|
*/
|
||||||
function readFile($file_name) {
|
function readFile($file_name)
|
||||||
|
{
|
||||||
$file_name = FileHandler::getRealPath($file_name);
|
$file_name = FileHandler::getRealPath($file_name);
|
||||||
|
|
||||||
if(!file_exists($file_name)) return;
|
if(!file_exists($file_name)) return;
|
||||||
|
|
@ -89,8 +101,10 @@ class FileHandler {
|
||||||
|
|
||||||
$fp = fopen($file_name, "r");
|
$fp = fopen($file_name, "r");
|
||||||
$buff = '';
|
$buff = '';
|
||||||
if($fp) {
|
if($fp)
|
||||||
while(!feof($fp) && strlen($buff)<=$filesize) {
|
{
|
||||||
|
while(!feof($fp) && strlen($buff)<=$filesize)
|
||||||
|
{
|
||||||
$str = fgets($fp, 1024);
|
$str = fgets($fp, 1024);
|
||||||
$buff .= $str;
|
$buff .= $str;
|
||||||
}
|
}
|
||||||
|
|
@ -106,8 +120,9 @@ class FileHandler {
|
||||||
* @param string $buff Content to be writeen
|
* @param string $buff Content to be writeen
|
||||||
* @param string $mode a(append) / w(write)
|
* @param string $mode a(append) / w(write)
|
||||||
* @return void
|
* @return void
|
||||||
**/
|
*/
|
||||||
function writeFile($file_name, $buff, $mode = "w") {
|
function writeFile($file_name, $buff, $mode = "w")
|
||||||
|
{
|
||||||
$file_name = FileHandler::getRealPath($file_name);
|
$file_name = FileHandler::getRealPath($file_name);
|
||||||
|
|
||||||
$pathinfo = pathinfo($file_name);
|
$pathinfo = pathinfo($file_name);
|
||||||
|
|
@ -127,8 +142,9 @@ class FileHandler {
|
||||||
*
|
*
|
||||||
* @param string $file_name path of target file
|
* @param string $file_name path of target file
|
||||||
* @return bool Returns true on success or false on failure.
|
* @return bool Returns true on success or false on failure.
|
||||||
**/
|
*/
|
||||||
function removeFile($file_name) {
|
function removeFile($file_name)
|
||||||
|
{
|
||||||
$file_name = FileHandler::getRealPath($file_name);
|
$file_name = FileHandler::getRealPath($file_name);
|
||||||
return (file_exists($file_name) && @unlink($file_name));
|
return (file_exists($file_name) && @unlink($file_name));
|
||||||
}
|
}
|
||||||
|
|
@ -141,8 +157,9 @@ class FileHandler {
|
||||||
* @param string $source Path of source file
|
* @param string $source Path of source file
|
||||||
* @param string $target Path of target file
|
* @param string $target Path of target file
|
||||||
* @return bool Returns true on success or false on failure.
|
* @return bool Returns true on success or false on failure.
|
||||||
**/
|
*/
|
||||||
function rename($source, $target) {
|
function rename($source, $target)
|
||||||
|
{
|
||||||
$source = FileHandler::getRealPath($source);
|
$source = FileHandler::getRealPath($source);
|
||||||
$target = FileHandler::getRealPath($target);
|
$target = FileHandler::getRealPath($target);
|
||||||
return @rename($source, $target);
|
return @rename($source, $target);
|
||||||
|
|
@ -155,7 +172,8 @@ class FileHandler {
|
||||||
* @param string $target Path of target file
|
* @param string $target Path of target file
|
||||||
* @return bool Returns true on success or false on failure.
|
* @return bool Returns true on success or false on failure.
|
||||||
*/
|
*/
|
||||||
function moveFile($source, $target) {
|
function moveFile($source, $target)
|
||||||
|
{
|
||||||
$source = FileHandler::getRealPath($source);
|
$source = FileHandler::getRealPath($source);
|
||||||
if(!file_exists($source))
|
if(!file_exists($source))
|
||||||
{
|
{
|
||||||
|
|
@ -173,8 +191,9 @@ class FileHandler {
|
||||||
* @param string $source_dir Path of source directory
|
* @param string $source_dir Path of source directory
|
||||||
* @param string $target_dir Path of target directory
|
* @param string $target_dir Path of target directory
|
||||||
* @return void
|
* @return void
|
||||||
**/
|
*/
|
||||||
function moveDir($source_dir, $target_dir) {
|
function moveDir($source_dir, $target_dir)
|
||||||
|
{
|
||||||
FileHandler::rename($source_dir, $target_dir);
|
FileHandler::rename($source_dir, $target_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -188,15 +207,17 @@ class FileHandler {
|
||||||
* @param bool $to_lower If true, file names will be changed into lower case.
|
* @param bool $to_lower If true, file names will be changed into lower case.
|
||||||
* @param bool $concat_prefix If true, return file name as absolute path
|
* @param bool $concat_prefix If true, return file name as absolute path
|
||||||
* @return string[] Array of the filenames in the path
|
* @return string[] Array of the filenames in the path
|
||||||
**/
|
*/
|
||||||
function readDir($path, $filter = '', $to_lower = false, $concat_prefix = false) {
|
function readDir($path, $filter = '', $to_lower = false, $concat_prefix = false)
|
||||||
|
{
|
||||||
$path = FileHandler::getRealPath($path);
|
$path = FileHandler::getRealPath($path);
|
||||||
|
|
||||||
if(substr($path,-1)!='/') $path .= '/';
|
if(substr($path,-1)!='/') $path .= '/';
|
||||||
if(!is_dir($path)) return array();
|
if(!is_dir($path)) return array();
|
||||||
|
|
||||||
$oDir = dir($path);
|
$oDir = dir($path);
|
||||||
while($file = $oDir->read()) {
|
while($file = $oDir->read())
|
||||||
|
{
|
||||||
if(substr($file,0,1)=='.') continue;
|
if(substr($file,0,1)=='.') continue;
|
||||||
|
|
||||||
if($filter && !preg_match($filter, $file)) continue;
|
if($filter && !preg_match($filter, $file)) continue;
|
||||||
|
|
@ -206,7 +227,8 @@ class FileHandler {
|
||||||
if($filter) $file = preg_replace($filter, '$1', $file);
|
if($filter) $file = preg_replace($filter, '$1', $file);
|
||||||
else $file = $file;
|
else $file = $file;
|
||||||
|
|
||||||
if($concat_prefix) {
|
if($concat_prefix)
|
||||||
|
{
|
||||||
$file = sprintf('%s%s', str_replace(_XE_PATH_, '', $path), $file);
|
$file = sprintf('%s%s', str_replace(_XE_PATH_, '', $path), $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -224,14 +246,17 @@ class FileHandler {
|
||||||
*
|
*
|
||||||
* @param string $path_string Path of target directory
|
* @param string $path_string Path of target directory
|
||||||
* @return bool true if success. It might return nothing when ftp is used and connection to the ftp address failed.
|
* @return bool true if success. It might return nothing when ftp is used and connection to the ftp address failed.
|
||||||
**/
|
*/
|
||||||
function makeDir($path_string) {
|
function makeDir($path_string)
|
||||||
|
{
|
||||||
static $oFtp = null;
|
static $oFtp = null;
|
||||||
|
|
||||||
// if safe_mode is on, use FTP
|
// if safe_mode is on, use FTP
|
||||||
if(ini_get('safe_mode')) {
|
if(ini_get('safe_mode'))
|
||||||
|
{
|
||||||
$ftp_info = Context::getFTPInfo();
|
$ftp_info = Context::getFTPInfo();
|
||||||
if($oFtp == null) {
|
if($oFtp == null)
|
||||||
|
{
|
||||||
if(!Context::isFTPRegisted()) return;
|
if(!Context::isFTPRegisted()) return;
|
||||||
|
|
||||||
require_once(_XE_PATH_.'libs/ftp.class.php');
|
require_once(_XE_PATH_.'libs/ftp.class.php');
|
||||||
|
|
@ -239,7 +264,8 @@ class FileHandler {
|
||||||
if(!$ftp_info->ftp_host) $ftp_info->ftp_host = "127.0.0.1";
|
if(!$ftp_info->ftp_host) $ftp_info->ftp_host = "127.0.0.1";
|
||||||
if(!$ftp_info->ftp_port) $ftp_info->ftp_port = 21;
|
if(!$ftp_info->ftp_port) $ftp_info->ftp_port = 21;
|
||||||
if(!$oFtp->ftp_connect($ftp_info->ftp_host, $ftp_info->ftp_port)) return;
|
if(!$oFtp->ftp_connect($ftp_info->ftp_host, $ftp_info->ftp_port)) return;
|
||||||
if(!$oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password)) {
|
if(!$oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password))
|
||||||
|
{
|
||||||
$oFtp->ftp_quit();
|
$oFtp->ftp_quit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -252,15 +278,20 @@ class FileHandler {
|
||||||
$path_list = explode('/', $path_string);
|
$path_list = explode('/', $path_string);
|
||||||
|
|
||||||
$path = _XE_PATH_;
|
$path = _XE_PATH_;
|
||||||
for($i=0;$i<count($path_list);$i++) {
|
for($i=0;$i<count($path_list);$i++)
|
||||||
|
{
|
||||||
if(!$path_list[$i]) continue;
|
if(!$path_list[$i]) continue;
|
||||||
$path .= $path_list[$i].'/';
|
$path .= $path_list[$i].'/';
|
||||||
$ftp_path .= $path_list[$i].'/';
|
$ftp_path .= $path_list[$i].'/';
|
||||||
if(!is_dir($path)) {
|
if(!is_dir($path))
|
||||||
if(ini_get('safe_mode')) {
|
{
|
||||||
|
if(ini_get('safe_mode'))
|
||||||
|
{
|
||||||
$oFtp->ftp_mkdir($ftp_path);
|
$oFtp->ftp_mkdir($ftp_path);
|
||||||
$oFtp->ftp_site("CHMOD 777 ".$ftp_path);
|
$oFtp->ftp_site("CHMOD 777 ".$ftp_path);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
@mkdir($path, 0755);
|
@mkdir($path, 0755);
|
||||||
@chmod($path, 0755);
|
@chmod($path, 0755);
|
||||||
}
|
}
|
||||||
|
|
@ -275,16 +306,22 @@ class FileHandler {
|
||||||
*
|
*
|
||||||
* @param string $path Path of the target directory
|
* @param string $path Path of the target directory
|
||||||
* @return void
|
* @return void
|
||||||
**/
|
*/
|
||||||
function removeDir($path) {
|
function removeDir($path)
|
||||||
|
{
|
||||||
$path = FileHandler::getRealPath($path);
|
$path = FileHandler::getRealPath($path);
|
||||||
if(!is_dir($path)) return;
|
if(!is_dir($path)) return;
|
||||||
$directory = dir($path);
|
$directory = dir($path);
|
||||||
while($entry = $directory->read()) {
|
while($entry = $directory->read())
|
||||||
if ($entry != "." && $entry != "..") {
|
{
|
||||||
if (is_dir($path."/".$entry)) {
|
if ($entry != "." && $entry != "..")
|
||||||
|
{
|
||||||
|
if (is_dir($path."/".$entry))
|
||||||
|
{
|
||||||
FileHandler::removeDir($path."/".$entry);
|
FileHandler::removeDir($path."/".$entry);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
@unlink($path."/".$entry);
|
@unlink($path."/".$entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -298,14 +335,16 @@ class FileHandler {
|
||||||
*
|
*
|
||||||
* @param string $path Path of the target directory
|
* @param string $path Path of the target directory
|
||||||
* @return void
|
* @return void
|
||||||
**/
|
*/
|
||||||
function removeBlankDir($path) {
|
function removeBlankDir($path)
|
||||||
|
{
|
||||||
$item_cnt = 0;
|
$item_cnt = 0;
|
||||||
|
|
||||||
$path = FileHandler::getRealPath($path);
|
$path = FileHandler::getRealPath($path);
|
||||||
if(!is_dir($path)) return;
|
if(!is_dir($path)) return;
|
||||||
$directory = dir($path);
|
$directory = dir($path);
|
||||||
while($entry = $directory->read()) {
|
while($entry = $directory->read())
|
||||||
|
{
|
||||||
if ($entry == "." || $entry == "..") continue;
|
if ($entry == "." || $entry == "..") continue;
|
||||||
if (is_dir($path."/".$entry)) $item_cnt = FileHandler::removeBlankDir($path.'/'.$entry);
|
if (is_dir($path."/".$entry)) $item_cnt = FileHandler::removeBlankDir($path.'/'.$entry);
|
||||||
}
|
}
|
||||||
|
|
@ -322,16 +361,22 @@ class FileHandler {
|
||||||
*
|
*
|
||||||
* @param string $path Path of the target directory
|
* @param string $path Path of the target directory
|
||||||
* @return void
|
* @return void
|
||||||
**/
|
*/
|
||||||
function removeFilesInDir($path) {
|
function removeFilesInDir($path)
|
||||||
|
{
|
||||||
$path = FileHandler::getRealPath($path);
|
$path = FileHandler::getRealPath($path);
|
||||||
if(!is_dir($path)) return;
|
if(!is_dir($path)) return;
|
||||||
$directory = dir($path);
|
$directory = dir($path);
|
||||||
while($entry = $directory->read()) {
|
while($entry = $directory->read())
|
||||||
if ($entry != "." && $entry != "..") {
|
{
|
||||||
if (is_dir($path."/".$entry)) {
|
if ($entry != "." && $entry != "..")
|
||||||
|
{
|
||||||
|
if (is_dir($path."/".$entry))
|
||||||
|
{
|
||||||
FileHandler::removeFilesInDir($path."/".$entry);
|
FileHandler::removeFilesInDir($path."/".$entry);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
@unlink($path."/".$entry);
|
@unlink($path."/".$entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -345,8 +390,9 @@ class FileHandler {
|
||||||
* @see FileHandler::returnBytes()
|
* @see FileHandler::returnBytes()
|
||||||
* @param int $size Number of the size
|
* @param int $size Number of the size
|
||||||
* @return string File size string
|
* @return string File size string
|
||||||
**/
|
*/
|
||||||
function filesize($size) {
|
function filesize($size)
|
||||||
|
{
|
||||||
if(!$size) return '0Byte';
|
if(!$size) return '0Byte';
|
||||||
if($size === 1) return '1Byte';
|
if($size === 1) return '1Byte';
|
||||||
if($size < 1024) return $size.'Bytes';
|
if($size < 1024) return $size.'Bytes';
|
||||||
|
|
@ -368,8 +414,9 @@ class FileHandler {
|
||||||
* @param string[] $cookies Cookies key value array.
|
* @param string[] $cookies Cookies key value array.
|
||||||
* @param string $post_data Request arguments array for POST method
|
* @param string $post_data Request arguments array for POST method
|
||||||
* @return string If success, the content of the target file. Otherwise: none
|
* @return string If success, the content of the target file. Otherwise: none
|
||||||
**/
|
*/
|
||||||
function getRemoteResource($url, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array()) {
|
function getRemoteResource($url, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array())
|
||||||
|
{
|
||||||
if(version_compare(PHP_VERSION, '5.0.0', '>='))
|
if(version_compare(PHP_VERSION, '5.0.0', '>='))
|
||||||
{
|
{
|
||||||
return include _XE_PATH_ . 'classes/file/getRemoteResourcePHP5.php';
|
return include _XE_PATH_ . 'classes/file/getRemoteResourcePHP5.php';
|
||||||
|
|
@ -394,31 +441,41 @@ class FileHandler {
|
||||||
* @param string[] $cookies Cookies key value array.
|
* @param string[] $cookies Cookies key value array.
|
||||||
* @param string $post_data Request arguments array for POST method
|
* @param string $post_data Request arguments array for POST method
|
||||||
* @return string If success, the content of the target file. Otherwise: none
|
* @return string If success, the content of the target file. Otherwise: none
|
||||||
**/
|
*/
|
||||||
function _getRemoteResource($url, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array()) {
|
function _getRemoteResource($url, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array())
|
||||||
|
{
|
||||||
requirePear();
|
requirePear();
|
||||||
require_once('HTTP/Request.php');
|
require_once('HTTP/Request.php');
|
||||||
|
|
||||||
$parsed_url = parse_url(__PROXY_SERVER__);
|
$parsed_url = parse_url(__PROXY_SERVER__);
|
||||||
if($parsed_url["host"]) {
|
if($parsed_url["host"])
|
||||||
|
{
|
||||||
$oRequest = new HTTP_Request(__PROXY_SERVER__);
|
$oRequest = new HTTP_Request(__PROXY_SERVER__);
|
||||||
$oRequest->setMethod('POST');
|
$oRequest->setMethod('POST');
|
||||||
$oRequest->_timeout = $timeout;
|
$oRequest->_timeout = $timeout;
|
||||||
$oRequest->addPostData('arg', serialize(array('Destination'=>$url, 'method'=>$method, 'body'=>$body, 'content_type'=>$content_type, "headers"=>$headers, "post_data"=>$post_data)));
|
$oRequest->addPostData('arg', serialize(array('Destination'=>$url, 'method'=>$method, 'body'=>$body, 'content_type'=>$content_type, "headers"=>$headers, "post_data"=>$post_data)));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$oRequest = new HTTP_Request($url);
|
$oRequest = new HTTP_Request($url);
|
||||||
if(count($headers)) {
|
if(count($headers))
|
||||||
foreach($headers as $key => $val) {
|
{
|
||||||
|
foreach($headers as $key => $val)
|
||||||
|
{
|
||||||
$oRequest->addHeader($key, $val);
|
$oRequest->addHeader($key, $val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($cookies[$host]) {
|
if($cookies[$host])
|
||||||
foreach($cookies[$host] as $key => $val) {
|
{
|
||||||
|
foreach($cookies[$host] as $key => $val)
|
||||||
|
{
|
||||||
$oRequest->addCookie($key, $val);
|
$oRequest->addCookie($key, $val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(count($post_data)) {
|
if(count($post_data))
|
||||||
foreach($post_data as $key => $val) {
|
{
|
||||||
|
foreach($post_data as $key => $val)
|
||||||
|
{
|
||||||
$oRequest->addPostData($key, $val);
|
$oRequest->addPostData($key, $val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -435,13 +492,16 @@ class FileHandler {
|
||||||
$code = $oRequest->getResponseCode();
|
$code = $oRequest->getResponseCode();
|
||||||
$header = $oRequest->getResponseHeader();
|
$header = $oRequest->getResponseHeader();
|
||||||
$response = $oRequest->getResponseBody();
|
$response = $oRequest->getResponseBody();
|
||||||
if($c = $oRequest->getResponseCookies()) {
|
if($c = $oRequest->getResponseCookies())
|
||||||
foreach($c as $k => $v) {
|
{
|
||||||
|
foreach($c as $k => $v)
|
||||||
|
{
|
||||||
$cookies[$host][$v['name']] = $v['value'];
|
$cookies[$host][$v['name']] = $v['value'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($code > 300 && $code < 399 && $header['location']) {
|
if($code > 300 && $code < 399 && $header['location'])
|
||||||
|
{
|
||||||
return FileHandler::getRemoteResource($header['location'], $body, $timeout, $method, $content_type, $headers, $cookies, $post_data);
|
return FileHandler::getRemoteResource($header['location'], $body, $timeout, $method, $content_type, $headers, $cookies, $post_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -461,8 +521,9 @@ class FileHandler {
|
||||||
* @param string $content_type Content type header of HTTP request
|
* @param string $content_type Content type header of HTTP request
|
||||||
* @param string[] $headers Headers key vaule array.
|
* @param string[] $headers Headers key vaule array.
|
||||||
* @return bool true: success, false: failed
|
* @return bool true: success, false: failed
|
||||||
**/
|
*/
|
||||||
function getRemoteFile($url, $target_filename, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array()) {
|
function getRemoteFile($url, $target_filename, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array())
|
||||||
|
{
|
||||||
$body = FileHandler::getRemoteResource($url, $body, $timeout, $method, $content_type, $headers);
|
$body = FileHandler::getRemoteResource($url, $body, $timeout, $method, $content_type, $headers);
|
||||||
if(!$body) return false;
|
if(!$body) return false;
|
||||||
$target_filename = FileHandler::getRealPath($target_filename);
|
$target_filename = FileHandler::getRealPath($target_filename);
|
||||||
|
|
@ -518,8 +579,9 @@ class FileHandler {
|
||||||
* @param string $target_type If $target_type is set (gif, jpg, png, bmp), result image will be saved as target type
|
* @param string $target_type If $target_type is set (gif, jpg, png, bmp), result image will be saved as target type
|
||||||
* @param string $thumbnail_type Thumbnail type(crop, ratio)
|
* @param string $thumbnail_type Thumbnail type(crop, ratio)
|
||||||
* @return bool true: success, false: failed
|
* @return bool true: success, false: failed
|
||||||
**/
|
*/
|
||||||
function createImageFile($source_file, $target_file, $resize_width = 0, $resize_height = 0, $target_type = '', $thumbnail_type = 'crop') {
|
function createImageFile($source_file, $target_file, $resize_width = 0, $resize_height = 0, $target_type = '', $thumbnail_type = 'crop')
|
||||||
|
{
|
||||||
$source_file = FileHandler::getRealPath($source_file);
|
$source_file = FileHandler::getRealPath($source_file);
|
||||||
$target_file = FileHandler::getRealPath($target_file);
|
$target_file = FileHandler::getRealPath($target_file);
|
||||||
|
|
||||||
|
|
@ -534,21 +596,22 @@ class FileHandler {
|
||||||
|
|
||||||
if($width<1 || $height<1) return;
|
if($width<1 || $height<1) return;
|
||||||
|
|
||||||
switch($type) {
|
switch($type)
|
||||||
|
{
|
||||||
case '1' :
|
case '1' :
|
||||||
$type = 'gif';
|
$type = 'gif';
|
||||||
break;
|
break;
|
||||||
case '2' :
|
case '2' :
|
||||||
$type = 'jpg';
|
$type = 'jpg';
|
||||||
break;
|
break;
|
||||||
case '3' :
|
case '3' :
|
||||||
$type = 'png';
|
$type = 'png';
|
||||||
break;
|
break;
|
||||||
case '6' :
|
case '6' :
|
||||||
$type = 'bmp';
|
$type = 'bmp';
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -559,12 +622,15 @@ class FileHandler {
|
||||||
if($resize_height>0 && $height >= $resize_height) $height_per = $resize_height / $height;
|
if($resize_height>0 && $height >= $resize_height) $height_per = $resize_height / $height;
|
||||||
else $height_per = 1;
|
else $height_per = 1;
|
||||||
|
|
||||||
if($thumbnail_type == 'ratio') {
|
if($thumbnail_type == 'ratio')
|
||||||
|
{
|
||||||
if($width_per>$height_per) $per = $height_per;
|
if($width_per>$height_per) $per = $height_per;
|
||||||
else $per = $width_per;
|
else $per = $width_per;
|
||||||
$resize_width = $width * $per;
|
$resize_width = $width * $per;
|
||||||
$resize_height = $height * $per;
|
$resize_height = $height * $per;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if($width_per < $height_per) $per = $height_per;
|
if($width_per < $height_per) $per = $height_per;
|
||||||
else $per = $width_per;
|
else $per = $width_per;
|
||||||
}
|
}
|
||||||
|
|
@ -585,27 +651,28 @@ class FileHandler {
|
||||||
imagefilledrectangle($thumb,0,0,$resize_width-1,$resize_height-1,$white);
|
imagefilledrectangle($thumb,0,0,$resize_width-1,$resize_height-1,$white);
|
||||||
|
|
||||||
// create temporary image having original type
|
// create temporary image having original type
|
||||||
switch($type) {
|
switch($type)
|
||||||
|
{
|
||||||
case 'gif' :
|
case 'gif' :
|
||||||
if(!function_exists('imagecreatefromgif')) return false;
|
if(!function_exists('imagecreatefromgif')) return false;
|
||||||
$source = @imagecreatefromgif($source_file);
|
$source = @imagecreatefromgif($source_file);
|
||||||
break;
|
break;
|
||||||
// jpg
|
// jpg
|
||||||
case 'jpeg' :
|
case 'jpeg' :
|
||||||
case 'jpg' :
|
case 'jpg' :
|
||||||
if(!function_exists('imagecreatefromjpeg')) return false;
|
if(!function_exists('imagecreatefromjpeg')) return false;
|
||||||
$source = @imagecreatefromjpeg($source_file);
|
$source = @imagecreatefromjpeg($source_file);
|
||||||
break;
|
break;
|
||||||
// png
|
// png
|
||||||
case 'png' :
|
case 'png' :
|
||||||
if(!function_exists('imagecreatefrompng')) return false;
|
if(!function_exists('imagecreatefrompng')) return false;
|
||||||
$source = @imagecreatefrompng($source_file);
|
$source = @imagecreatefrompng($source_file);
|
||||||
break;
|
break;
|
||||||
// bmp
|
// bmp
|
||||||
case 'wbmp' :
|
case 'wbmp' :
|
||||||
case 'bmp' :
|
case 'bmp' :
|
||||||
if(!function_exists('imagecreatefromwbmp')) return false;
|
if(!function_exists('imagecreatefromwbmp')) return false;
|
||||||
$source = @imagecreatefromwbmp($source_file);
|
$source = @imagecreatefromwbmp($source_file);
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
return;
|
return;
|
||||||
|
|
@ -615,42 +682,48 @@ class FileHandler {
|
||||||
$new_width = (int)($width * $per);
|
$new_width = (int)($width * $per);
|
||||||
$new_height = (int)($height * $per);
|
$new_height = (int)($height * $per);
|
||||||
|
|
||||||
if($thumbnail_type == 'crop') {
|
if($thumbnail_type == 'crop')
|
||||||
|
{
|
||||||
$x = (int)($resize_width/2 - $new_width/2);
|
$x = (int)($resize_width/2 - $new_width/2);
|
||||||
$y = (int)($resize_height/2 - $new_height/2);
|
$y = (int)($resize_height/2 - $new_height/2);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$x = 0;
|
$x = 0;
|
||||||
$y = 0;
|
$y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($source) {
|
if($source)
|
||||||
|
{
|
||||||
if(function_exists('imagecopyresampled')) imagecopyresampled($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height);
|
if(function_exists('imagecopyresampled')) imagecopyresampled($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height);
|
||||||
else imagecopyresized($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height);
|
else imagecopyresized($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height);
|
||||||
} else return false;
|
}
|
||||||
|
else return false;
|
||||||
|
|
||||||
// create directory
|
// create directory
|
||||||
$path = dirname($target_file);
|
$path = dirname($target_file);
|
||||||
if(!is_dir($path)) FileHandler::makeDir($path);
|
if(!is_dir($path)) FileHandler::makeDir($path);
|
||||||
|
|
||||||
// write into the file
|
// write into the file
|
||||||
switch($target_type) {
|
switch($target_type)
|
||||||
|
{
|
||||||
case 'gif' :
|
case 'gif' :
|
||||||
if(!function_exists('imagegif')) return false;
|
if(!function_exists('imagegif')) return false;
|
||||||
$output = imagegif($thumb, $target_file);
|
$output = imagegif($thumb, $target_file);
|
||||||
break;
|
break;
|
||||||
case 'jpeg' :
|
case 'jpeg' :
|
||||||
case 'jpg' :
|
case 'jpg' :
|
||||||
if(!function_exists('imagejpeg')) return false;
|
if(!function_exists('imagejpeg')) return false;
|
||||||
$output = imagejpeg($thumb, $target_file, 100);
|
$output = imagejpeg($thumb, $target_file, 100);
|
||||||
break;
|
break;
|
||||||
case 'png' :
|
case 'png' :
|
||||||
if(!function_exists('imagepng')) return false;
|
if(!function_exists('imagepng')) return false;
|
||||||
$output = imagepng($thumb, $target_file, 9);
|
$output = imagepng($thumb, $target_file, 9);
|
||||||
break;
|
break;
|
||||||
case 'wbmp' :
|
case 'wbmp' :
|
||||||
case 'bmp' :
|
case 'bmp' :
|
||||||
if(!function_exists('imagewbmp')) return false;
|
if(!function_exists('imagewbmp')) return false;
|
||||||
$output = imagewbmp($thumb, $target_file, 100);
|
$output = imagewbmp($thumb, $target_file, 100);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -669,8 +742,9 @@ class FileHandler {
|
||||||
* @see FileHandler::writeIniFile()
|
* @see FileHandler::writeIniFile()
|
||||||
* @param string $filename Path of the ini file
|
* @param string $filename Path of the ini file
|
||||||
* @return array ini array (if the target file does not exist, it returns false)
|
* @return array ini array (if the target file does not exist, it returns false)
|
||||||
**/
|
*/
|
||||||
function readIniFile($filename){
|
function readIniFile($filename)
|
||||||
|
{
|
||||||
$filename = FileHandler::getRealPath($filename);
|
$filename = FileHandler::getRealPath($filename);
|
||||||
if(!file_exists($filename)) return false;
|
if(!file_exists($filename)) return false;
|
||||||
$arr = parse_ini_file($filename, true);
|
$arr = parse_ini_file($filename, true);
|
||||||
|
|
@ -678,7 +752,6 @@ class FileHandler {
|
||||||
else return array();
|
else return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write array into ini file
|
* Write array into ini file
|
||||||
*
|
*
|
||||||
|
|
@ -692,8 +765,9 @@ class FileHandler {
|
||||||
* @param string $filename Target ini file name
|
* @param string $filename Target ini file name
|
||||||
* @param array $arr Array
|
* @param array $arr Array
|
||||||
* @return bool if array contains nothing it returns false, otherwise true
|
* @return bool if array contains nothing it returns false, otherwise true
|
||||||
**/
|
*/
|
||||||
function writeIniFile($filename, $arr){
|
function writeIniFile($filename, $arr)
|
||||||
|
{
|
||||||
if(count($arr)==0) return false;
|
if(count($arr)==0) return false;
|
||||||
FileHandler::writeFile($filename, FileHandler::_makeIniBuff($arr));
|
FileHandler::writeFile($filename, FileHandler::_makeIniBuff($arr));
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -705,17 +779,23 @@ class FileHandler {
|
||||||
* @param array $arr Array
|
* @param array $arr Array
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function _makeIniBuff($arr){
|
function _makeIniBuff($arr)
|
||||||
|
{
|
||||||
$return = '';
|
$return = '';
|
||||||
foreach($arr as $key => $val){
|
foreach($arr as $key => $val)
|
||||||
|
{
|
||||||
// section
|
// section
|
||||||
if(is_array($val)){
|
if(is_array($val))
|
||||||
|
{
|
||||||
$return .= sprintf("[%s]\n",$key);
|
$return .= sprintf("[%s]\n",$key);
|
||||||
foreach($val as $k => $v){
|
foreach($val as $k => $v)
|
||||||
|
{
|
||||||
$return .= sprintf("%s=\"%s\"\n",$k,$v);
|
$return .= sprintf("%s=\"%s\"\n",$k,$v);
|
||||||
}
|
}
|
||||||
// value
|
// value
|
||||||
}else if(is_string($val) || is_int($val)){
|
}
|
||||||
|
else if(is_string($val) || is_int($val))
|
||||||
|
{
|
||||||
$return .= sprintf("%s=\"%s\"\n",$key,$val);
|
$return .= sprintf("%s=\"%s\"\n",$key,$val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -730,7 +810,7 @@ class FileHandler {
|
||||||
* @param string $filename Target file name
|
* @param string $filename Target file name
|
||||||
* @param string $mode File mode for fopen
|
* @param string $mode File mode for fopen
|
||||||
* @return FileObject File object
|
* @return FileObject File object
|
||||||
**/
|
*/
|
||||||
function openFile($filename, $mode)
|
function openFile($filename, $mode)
|
||||||
{
|
{
|
||||||
$pathinfo = pathinfo($filename);
|
$pathinfo = pathinfo($filename);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
* File abstraction class
|
* File abstraction class
|
||||||
*
|
*
|
||||||
* @author NHN (developers@xpressengine.com)
|
* @author NHN (developers@xpressengine.com)
|
||||||
**/
|
*/
|
||||||
class FileObject extends Object
|
class FileObject extends Object
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
@ -30,7 +30,7 @@ class FileObject extends Object
|
||||||
* @param string $path Path of target file
|
* @param string $path Path of target file
|
||||||
* @param string $mode File open mode
|
* @param string $mode File open mode
|
||||||
* @return void
|
* @return void
|
||||||
**/
|
*/
|
||||||
function FileObject($path, $mode)
|
function FileObject($path, $mode)
|
||||||
{
|
{
|
||||||
if($path != null) $this->Open($path, $mode);
|
if($path != null) $this->Open($path, $mode);
|
||||||
|
|
@ -41,7 +41,7 @@ class FileObject extends Object
|
||||||
*
|
*
|
||||||
* @param string $file_name Path of target file
|
* @param string $file_name Path of target file
|
||||||
* @return void
|
* @return void
|
||||||
**/
|
*/
|
||||||
function append($file_name)
|
function append($file_name)
|
||||||
{
|
{
|
||||||
$target = new FileObject($file_name, "r");
|
$target = new FileObject($file_name, "r");
|
||||||
|
|
@ -57,7 +57,7 @@ class FileObject extends Object
|
||||||
* Check current file meets eof
|
* Check current file meets eof
|
||||||
*
|
*
|
||||||
* @return bool true: if eof. false: otherwise
|
* @return bool true: if eof. false: otherwise
|
||||||
**/
|
*/
|
||||||
function feof()
|
function feof()
|
||||||
{
|
{
|
||||||
return feof($this->fp);
|
return feof($this->fp);
|
||||||
|
|
@ -68,7 +68,7 @@ class FileObject extends Object
|
||||||
*
|
*
|
||||||
* @param int $size Size to read
|
* @param int $size Size to read
|
||||||
* @return string Returns the read string or false on failure.
|
* @return string Returns the read string or false on failure.
|
||||||
**/
|
*/
|
||||||
function read($size = 1024)
|
function read($size = 1024)
|
||||||
{
|
{
|
||||||
return fread($this->fp, $size);
|
return fread($this->fp, $size);
|
||||||
|
|
@ -80,7 +80,7 @@ class FileObject extends Object
|
||||||
*
|
*
|
||||||
* @param string $str String to write
|
* @param string $str String to write
|
||||||
* @return int Returns the number of bytes written, or false on error.
|
* @return int Returns the number of bytes written, or false on error.
|
||||||
**/
|
*/
|
||||||
function write($str)
|
function write($str)
|
||||||
{
|
{
|
||||||
$len = strlen($str);
|
$len = strlen($str);
|
||||||
|
|
@ -119,7 +119,7 @@ class FileObject extends Object
|
||||||
* Return current file's path
|
* Return current file's path
|
||||||
*
|
*
|
||||||
* @return string Returns the path of current file.
|
* @return string Returns the path of current file.
|
||||||
**/
|
*/
|
||||||
function getPath()
|
function getPath()
|
||||||
{
|
{
|
||||||
if($this->fp != null)
|
if($this->fp != null)
|
||||||
|
|
@ -136,7 +136,7 @@ class FileObject extends Object
|
||||||
* Close file
|
* Close file
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
**/
|
*/
|
||||||
function close()
|
function close()
|
||||||
{
|
{
|
||||||
if($this->fp != null)
|
if($this->fp != null)
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,5 @@ catch(Exception $e)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
/* End of file getRemoteResourcePHP5.php */
|
||||||
|
/* Location: ./classes/file/getRemoteResourcePHP5.php */
|
||||||
|
|
|
||||||
|
|
@ -1,414 +1,414 @@
|
||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Handle front end files
|
||||||
|
* @author NHN (developers@xpressengine.com)
|
||||||
|
*/
|
||||||
|
class FrontEndFileHandler extends Handler
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Handle front end files
|
* Map for css
|
||||||
* @author NHN (developers@xpressengine.com)
|
* @var array
|
||||||
**/
|
*/
|
||||||
class FrontEndFileHandler extends Handler
|
var $cssMap = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map for Javascript at head
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $jsHeadMap = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map for Javascript at body
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $jsBodyMap = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Index for css
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $cssMapIndex = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Index for javascript at head
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $jsHeadMapIndex = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Index for javascript at body
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $jsBodyMapIndex = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check SSL
|
||||||
|
*
|
||||||
|
* @return bool If using ssl returns true, otherwise returns false.
|
||||||
|
*/
|
||||||
|
function isSsl()
|
||||||
{
|
{
|
||||||
/**
|
if ($GLOBAL['__XE_IS_SSL__']) return $GLOBAL['__XE_IS_SSL__'];
|
||||||
* Map for css
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
var $cssMap = array();
|
|
||||||
|
|
||||||
/**
|
$url_info = parse_url(Context::getRequestUrl());
|
||||||
* Map for Javascript at head
|
if ($url_info['scheme'] == 'https')
|
||||||
* @var array
|
$GLOBAL['__XE_IS_SSL__'] = true;
|
||||||
*/
|
else
|
||||||
var $jsHeadMap = array();
|
$GLOBAL['__XE_IS_SSL__'] = false;
|
||||||
|
|
||||||
/**
|
return $GLOBAL['__XE_IS_SSL__'];
|
||||||
* Map for Javascript at body
|
}
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
var $jsBodyMap = array();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Index for css
|
* Load front end file
|
||||||
* @var array
|
*
|
||||||
*/
|
* The $args is use as below. File type(js, css) is detected by file extension.
|
||||||
var $cssMapIndex = array();
|
*
|
||||||
|
* <pre>
|
||||||
|
* case js
|
||||||
|
* $args[0]: file name
|
||||||
|
* $args[1]: type (head | body)
|
||||||
|
* $args[2]: target IE
|
||||||
|
* $args[3]: index
|
||||||
|
* case css
|
||||||
|
* $args[0]: file name
|
||||||
|
* $args[1]: media
|
||||||
|
* $args[2]: target IE
|
||||||
|
* $args[3]: index
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* If $useCdn set true, use CDN instead local file.
|
||||||
|
* CDN path = $cdnPrefix . $cdnVersion . $args[0]<br />
|
||||||
|
*<br />
|
||||||
|
* i.e.<br />
|
||||||
|
* $cdnPrefix = 'http://static.xpressengine.com/core/';<br />
|
||||||
|
* $cdnVersion = 'ardent1';<br />
|
||||||
|
* $args[0] = './common/js/xe.js';<br />
|
||||||
|
* The CDN path is http://static.xprssengine.com/core/ardent1/common/js/xe.js.<br />
|
||||||
|
*
|
||||||
|
* @param array $args Arguments
|
||||||
|
* @param bool $useCdn If set true, use cdn instead local file
|
||||||
|
* @param string $cdnPrefix CDN url prefix. (http://static.xpressengine.com/core/)
|
||||||
|
* @param string $cdnVersion CDN version string (ardent1)
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function loadFile($args, $useCdn = false, $cdnPrefix = '', $cdnVersion = '')
|
||||||
|
{
|
||||||
|
if (!is_array($args)) $args = array($args);
|
||||||
|
|
||||||
/**
|
$pathInfo = pathinfo($args[0]);
|
||||||
* Index for javascript at head
|
$file->fileName = $pathInfo['basename'];
|
||||||
* @var array
|
$file->filePath = $this->_getAbsFileUrl($pathInfo['dirname']);
|
||||||
*/
|
$file->fileRealPath = FileHandler::getRealPath($pathInfo['dirname']);
|
||||||
var $jsHeadMapIndex = array();
|
$file->fileExtension = strtolower($pathInfo['extension']);
|
||||||
|
$file->fileNameNoExt = preg_replace("/\.{$file->fileExtension}$/", '', $file->fileName);
|
||||||
|
|
||||||
/**
|
// Remove .min
|
||||||
* Index for javascript at body
|
$file->fileNameNoExt = preg_replace("/\.min$/", '', $file->fileNameNoExt);
|
||||||
* @var array
|
$file->fileName = $file->keyName = "{$file->fileNameNoExt}.{$file->fileExtension}";
|
||||||
*/
|
|
||||||
var $jsBodyMapIndex = array();
|
|
||||||
|
|
||||||
/**
|
// if no debug mode load minified file
|
||||||
* Check SSL
|
if(!__DEBUG__)
|
||||||
*
|
|
||||||
* @return bool If using ssl returns true, otherwise returns false.
|
|
||||||
*/
|
|
||||||
function isSsl()
|
|
||||||
{
|
{
|
||||||
if ($GLOBAL['__XE_IS_SSL__']) return $GLOBAL['__XE_IS_SSL__'];
|
$tmp = "{$file->fileNameNoExt}.min.{$file->fileExtension}";
|
||||||
|
if(file_exists("{$file->fileRealPath}/{$tmp}"))
|
||||||
$url_info = parse_url(Context::getRequestUrl());
|
|
||||||
if ($url_info['scheme'] == 'https')
|
|
||||||
$GLOBAL['__XE_IS_SSL__'] = true;
|
|
||||||
else
|
|
||||||
$GLOBAL['__XE_IS_SSL__'] = false;
|
|
||||||
|
|
||||||
return $GLOBAL['__XE_IS_SSL__'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load front end file
|
|
||||||
*
|
|
||||||
* The $args is use as below. File type(js, css) is detected by file extension.
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* case js
|
|
||||||
* $args[0]: file name
|
|
||||||
* $args[1]: type (head | body)
|
|
||||||
* $args[2]: target IE
|
|
||||||
* $args[3]: index
|
|
||||||
* case css
|
|
||||||
* $args[0]: file name
|
|
||||||
* $args[1]: media
|
|
||||||
* $args[2]: target IE
|
|
||||||
* $args[3]: index
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* If $useCdn set true, use CDN instead local file.
|
|
||||||
* CDN path = $cdnPrefix . $cdnVersion . $args[0]<br />
|
|
||||||
*<br />
|
|
||||||
* i.e.<br />
|
|
||||||
* $cdnPrefix = 'http://static.xpressengine.com/core/';<br />
|
|
||||||
* $cdnVersion = 'ardent1';<br />
|
|
||||||
* $args[0] = './common/js/xe.js';<br />
|
|
||||||
* The CDN path is http://static.xprssengine.com/core/ardent1/common/js/xe.js.<br />
|
|
||||||
*
|
|
||||||
* @param array $args Arguments
|
|
||||||
* @param bool $useCdn If set true, use cdn instead local file
|
|
||||||
* @param string $cdnPrefix CDN url prefix. (http://static.xpressengine.com/core/)
|
|
||||||
* @param string $cdnVersion CDN version string (ardent1)
|
|
||||||
* @return void
|
|
||||||
**/
|
|
||||||
function loadFile($args, $useCdn = false, $cdnPrefix = '', $cdnVersion = '')
|
|
||||||
{
|
|
||||||
if (!is_array($args)) $args = array($args);
|
|
||||||
|
|
||||||
$pathInfo = pathinfo($args[0]);
|
|
||||||
$file->fileName = $pathInfo['basename'];
|
|
||||||
$file->filePath = $this->_getAbsFileUrl($pathInfo['dirname']);
|
|
||||||
$file->fileRealPath = FileHandler::getRealPath($pathInfo['dirname']);
|
|
||||||
$file->fileExtension = strtolower($pathInfo['extension']);
|
|
||||||
$file->fileNameNoExt = preg_replace("/\.{$file->fileExtension}$/", '', $file->fileName);
|
|
||||||
|
|
||||||
// Remove .min
|
|
||||||
$file->fileNameNoExt = preg_replace("/\.min$/", '', $file->fileNameNoExt);
|
|
||||||
$file->fileName = $file->keyName = "{$file->fileNameNoExt}.{$file->fileExtension}";
|
|
||||||
|
|
||||||
// if no debug mode load minified file
|
|
||||||
if(!__DEBUG__)
|
|
||||||
{
|
{
|
||||||
$tmp = "{$file->fileNameNoExt}.min.{$file->fileExtension}";
|
$file->fileName = $tmp;
|
||||||
if(file_exists("{$file->fileRealPath}/{$tmp}"))
|
$file->useMin = TRUE;
|
||||||
{
|
|
||||||
$file->fileName = $tmp;
|
|
||||||
$file->useMin = TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$file->useMin && !file_exists("{$file->fileRealPath}/{$file->fileName}"))
|
|
||||||
{
|
|
||||||
$file->fileName = "{$file->fileNameNoExt}.min.{$file->fileExtension}";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strpos($file->filePath, '://') == false)
|
|
||||||
{
|
|
||||||
$file->useCdn = $useCdn;
|
|
||||||
$file->cdnPath = $this->_normalizeFilePath($pathInfo['dirname']);
|
|
||||||
$file->cdnPrefix = $cdnPrefix;
|
|
||||||
$file->cdnVersion = $cdnVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
$availableExtension = array('css'=>1, 'js'=>1);
|
|
||||||
if (!isset($availableExtension[$file->fileExtension])) return;
|
|
||||||
|
|
||||||
$file->targetIe = $args[2];
|
|
||||||
$file->index = (int)$args[3];
|
|
||||||
|
|
||||||
if ($file->fileExtension == 'css')
|
|
||||||
{
|
|
||||||
$file->media = $args[1];
|
|
||||||
if (!$file->media) $file->media = 'all';
|
|
||||||
$map = &$this->cssMap;
|
|
||||||
$mapIndex = &$this->cssMapIndex;
|
|
||||||
$key = $file->filePath . $file->keyName . "\t" . $file->targetIe . "\t" . $file->media;
|
|
||||||
|
|
||||||
$this->_arrangeCssIndex($pathInfo['dirname'], $file);
|
|
||||||
}
|
|
||||||
else if ($file->fileExtension == 'js')
|
|
||||||
{
|
|
||||||
$type = $args[1];
|
|
||||||
if ($type == 'body')
|
|
||||||
{
|
|
||||||
$map = &$this->jsBodyMap;
|
|
||||||
$mapIndex = &$this->jsBodyMapIndex;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$map = &$this->jsHeadMap;
|
|
||||||
$mapIndex = &$this->jsHeadMapIndex;
|
|
||||||
}
|
|
||||||
$key = $file->filePath . $file->keyName . "\t" . $file->targetIe;
|
|
||||||
}
|
|
||||||
|
|
||||||
(is_null($file->index))?$file->index=0:$file->index=$file->index;
|
|
||||||
if (!isset($map[$file->index][$key]) || $mapIndex[$key] > $file->index)
|
|
||||||
{
|
|
||||||
$this->unloadFile($args[0], $args[2], $args[1]);
|
|
||||||
$map[$file->index][$key] = $file;
|
|
||||||
$mapIndex[$key] = $file->index;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
if(!$file->useMin && !file_exists("{$file->fileRealPath}/{$file->fileName}"))
|
||||||
* Unload front end file
|
|
||||||
*
|
|
||||||
* @param string $fileName The file name to unload
|
|
||||||
* @param string $targetIe Target IE of file to unload
|
|
||||||
* @param string $media Media of file to unload. Only use when file is css.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function unloadFile($fileName, $targetIe = '', $media = 'all')
|
|
||||||
{
|
{
|
||||||
$pathInfo = pathinfo($fileName);
|
$file->fileName = "{$file->fileNameNoExt}.min.{$file->fileExtension}";
|
||||||
$fileName = $pathInfo['basename'];
|
|
||||||
$filePath = $this->_getAbsFileUrl($pathInfo['dirname']);
|
|
||||||
$fileExtension = strtolower($pathInfo['extension']);
|
|
||||||
$key = $filePath . $fileName . "\t" . $targetIe;
|
|
||||||
|
|
||||||
if ($fileExtension == 'css')
|
|
||||||
{
|
|
||||||
if(empty($media))
|
|
||||||
{
|
|
||||||
$media = 'all';
|
|
||||||
}
|
|
||||||
|
|
||||||
$key .= "\t" . $media;
|
|
||||||
if (isset($this->cssMapIndex[$key]))
|
|
||||||
{
|
|
||||||
$index = $this->cssMapIndex[$key];
|
|
||||||
unset($this->cssMap[$index][$key]);
|
|
||||||
unset($this->cssMapIndex[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (isset($this->jsHeadMapIndex[$key]))
|
|
||||||
{
|
|
||||||
$index = $this->jsHeadMapIndex[$key];
|
|
||||||
unset($this->jsHeadMap[$index][$key]);
|
|
||||||
unset($this->jsHeadMapIndex[$key]);
|
|
||||||
}
|
|
||||||
if (isset($this->jsBodyMapIndex[$key]))
|
|
||||||
{
|
|
||||||
$index = $this->jsBodyMapIndex[$key];
|
|
||||||
unset($this->jsBodyMap[$index][$key]);
|
|
||||||
unset($this->jsBodyMapIndex[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
if(strpos($file->filePath, '://') == false)
|
||||||
* Unload all front end file
|
|
||||||
*
|
|
||||||
* @param string $type Type to unload. all, css, js
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function unloadAllFiles($type = 'all')
|
|
||||||
{
|
{
|
||||||
if ($type == 'css' || $type == 'all')
|
$file->useCdn = $useCdn;
|
||||||
{
|
$file->cdnPath = $this->_normalizeFilePath($pathInfo['dirname']);
|
||||||
$this->cssMap = array();
|
$file->cdnPrefix = $cdnPrefix;
|
||||||
$this->cssMapIndex = array();
|
$file->cdnVersion = $cdnVersion;
|
||||||
}
|
|
||||||
|
|
||||||
if ($type == 'js' || $type == 'all')
|
|
||||||
{
|
|
||||||
$this->jsHeadMap = array();
|
|
||||||
$this->jsBodyMap = array();
|
|
||||||
$this->jsHeadMapIndex = array();
|
|
||||||
$this->jsBodyMapIndex = array();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
$availableExtension = array('css'=>1, 'js'=>1);
|
||||||
* Get css file list
|
if(!isset($availableExtension[$file->fileExtension])) return;
|
||||||
*
|
|
||||||
* @return array Returns css file list. Array contains file, media, targetie.
|
$file->targetIe = $args[2];
|
||||||
*/
|
$file->index = (int)$args[3];
|
||||||
function getCssFileList()
|
|
||||||
|
if($file->fileExtension == 'css')
|
||||||
{
|
{
|
||||||
|
$file->media = $args[1];
|
||||||
|
if(!$file->media) $file->media = 'all';
|
||||||
$map = &$this->cssMap;
|
$map = &$this->cssMap;
|
||||||
$mapIndex = &$this->cssMapIndex;
|
$mapIndex = &$this->cssMapIndex;
|
||||||
|
$key = $file->filePath . $file->keyName . "\t" . $file->targetIe . "\t" . $file->media;
|
||||||
|
|
||||||
$this->_sortMap($map, $mapIndex);
|
$this->_arrangeCssIndex($pathInfo['dirname'], $file);
|
||||||
|
|
||||||
$dbInfo = Context::getDBInfo();
|
|
||||||
$useCdn = $dbInfo->use_cdn;
|
|
||||||
|
|
||||||
$result = array();
|
|
||||||
foreach($map as $indexedMap)
|
|
||||||
{
|
|
||||||
foreach($indexedMap as $file)
|
|
||||||
{
|
|
||||||
if ($this->isSsl() == false && $useCdn == 'Y' && $file->useCdn && $file->cdnVersion != '%__XE_CDN_VERSION__%')
|
|
||||||
{
|
|
||||||
$fullFilePath = $file->cdnPrefix . $file->cdnVersion . '/' . substr($file->cdnPath, 2) . '/' . $file->fileName;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$noneCache = (is_readable($file->cdnPath.'/'.$file->fileName))?'?'.date('YmdHis', filemtime($file->cdnPath.'/'.$file->fileName)):'';
|
|
||||||
$fullFilePath = $file->filePath . '/' . $file->fileName.$noneCache;
|
|
||||||
}
|
|
||||||
$result[] = array('file' => $fullFilePath, 'media' => $file->media, 'targetie' => $file->targetIe);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
else if($file->fileExtension == 'js')
|
||||||
/**
|
|
||||||
* Get javascript file list
|
|
||||||
*
|
|
||||||
* @param string $type Type of javascript. head, body
|
|
||||||
* @return array Returns javascript file list. Array contains file, targetie.
|
|
||||||
*/
|
|
||||||
function getJsFileList($type = 'head')
|
|
||||||
{
|
{
|
||||||
if ($type == 'head')
|
$type = $args[1];
|
||||||
{
|
if($type == 'body')
|
||||||
$map = &$this->jsHeadMap;
|
|
||||||
$mapIndex = &$this->jsHeadMapIndex;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
$map = &$this->jsBodyMap;
|
$map = &$this->jsBodyMap;
|
||||||
$mapIndex = &$this->jsBodyMapIndex;
|
$mapIndex = &$this->jsBodyMapIndex;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
$this->_sortMap($map, $mapIndex);
|
|
||||||
|
|
||||||
$dbInfo = Context::getDBInfo();
|
|
||||||
$useCdn = $dbInfo->use_cdn;
|
|
||||||
|
|
||||||
$result = array();
|
|
||||||
foreach($map as $indexedMap)
|
|
||||||
{
|
{
|
||||||
foreach($indexedMap as $file)
|
$map = &$this->jsHeadMap;
|
||||||
{
|
$mapIndex = &$this->jsHeadMapIndex;
|
||||||
if ($this->isSsl() == false && $useCdn == 'Y' && $file->useCdn && $file->cdnVersion != '%__XE_CDN_VERSION__%')
|
|
||||||
{
|
|
||||||
$fullFilePath = $file->cdnPrefix . $file->cdnVersion . '/' . substr($file->cdnPath, 2) . '/' . $file->fileName;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$noneCache = (is_readable($file->cdnPath.'/'.$file->fileName))?'?'.date('YmdHis', filemtime($file->cdnPath.'/'.$file->fileName)):'';
|
|
||||||
$fullFilePath = $file->filePath . '/' . $file->fileName.$noneCache;
|
|
||||||
}
|
|
||||||
$result[] = array('file' => $fullFilePath, 'targetie' => $file->targetIe);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$key = $file->filePath . $file->keyName . "\t" . $file->targetIe;
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
(is_null($file->index))?$file->index=0:$file->index=$file->index;
|
||||||
* Sort a map
|
if(!isset($map[$file->index][$key]) || $mapIndex[$key] > $file->index)
|
||||||
*
|
|
||||||
* @param array $map Array to sort
|
|
||||||
* @param array $index Not used
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function _sortMap(&$map, &$index)
|
|
||||||
{
|
{
|
||||||
ksort($map);
|
$this->unloadFile($args[0], $args[2], $args[1]);
|
||||||
}
|
$map[$file->index][$key] = $file;
|
||||||
|
$mapIndex[$key] = $file->index;
|
||||||
/**
|
|
||||||
* Normalize File path
|
|
||||||
*
|
|
||||||
* @param string $path Path to normalize
|
|
||||||
* @return string Normalized path
|
|
||||||
*/
|
|
||||||
function _normalizeFilePath($path)
|
|
||||||
{
|
|
||||||
if (strpos($path, '://') === false && $path{0} != '/' && $path{0} != '.')
|
|
||||||
{
|
|
||||||
$path = './' . $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
$path = preg_replace('@/\./|(?<!:)\/\/@', '/', $path);
|
|
||||||
|
|
||||||
while(strpos($path, '/../'))
|
|
||||||
{
|
|
||||||
$path = preg_replace('/\/([^\/]+)\/\.\.\//s', '/', $path, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get absolute file url
|
|
||||||
*
|
|
||||||
* @param string $path Path to get absolute url
|
|
||||||
* @return string Absolute url
|
|
||||||
*/
|
|
||||||
function _getAbsFileUrl($path)
|
|
||||||
{
|
|
||||||
$path = $this->_normalizeFilePath($path);
|
|
||||||
|
|
||||||
if(strpos($path, './') === 0)
|
|
||||||
{
|
|
||||||
if (dirname($_SERVER['SCRIPT_NAME']) == '/' || dirname($_SERVER['SCRIPT_NAME']) == '\\')
|
|
||||||
{
|
|
||||||
$path = '/' . substr($path, 2);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$path = dirname($_SERVER['SCRIPT_NAME']) . '/' . substr($path, 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(strpos($file, '../') === 0)
|
|
||||||
{
|
|
||||||
$path= $this->_normalizeFilePath(dirname($_SERVER['SCRIPT_NAME']) . "/{$path}");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Arrage css index
|
|
||||||
*
|
|
||||||
* @param string $dirName First directory name of css path
|
|
||||||
* @param array $file file info.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function _arrangeCssIndex($dirName, &$file)
|
|
||||||
{
|
|
||||||
if($file->index !== 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$dirName = str_replace('./', '', $dirName);
|
|
||||||
$tmp = explode('/', $dirName);
|
|
||||||
|
|
||||||
$cssSortList = array('common'=>-100000, 'layouts'=>-90000, 'modules'=>-80000, 'widgets'=>-70000, 'addons'=>-60000);
|
|
||||||
$file->index = $cssSortList[$tmp[0]];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unload front end file
|
||||||
|
*
|
||||||
|
* @param string $fileName The file name to unload
|
||||||
|
* @param string $targetIe Target IE of file to unload
|
||||||
|
* @param string $media Media of file to unload. Only use when file is css.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function unloadFile($fileName, $targetIe = '', $media = 'all')
|
||||||
|
{
|
||||||
|
$pathInfo = pathinfo($fileName);
|
||||||
|
$fileName = $pathInfo['basename'];
|
||||||
|
$filePath = $this->_getAbsFileUrl($pathInfo['dirname']);
|
||||||
|
$fileExtension = strtolower($pathInfo['extension']);
|
||||||
|
$key = $filePath . $fileName . "\t" . $targetIe;
|
||||||
|
|
||||||
|
if($fileExtension == 'css')
|
||||||
|
{
|
||||||
|
if(empty($media))
|
||||||
|
{
|
||||||
|
$media = 'all';
|
||||||
|
}
|
||||||
|
|
||||||
|
$key .= "\t" . $media;
|
||||||
|
if(isset($this->cssMapIndex[$key]))
|
||||||
|
{
|
||||||
|
$index = $this->cssMapIndex[$key];
|
||||||
|
unset($this->cssMap[$index][$key]);
|
||||||
|
unset($this->cssMapIndex[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(isset($this->jsHeadMapIndex[$key]))
|
||||||
|
{
|
||||||
|
$index = $this->jsHeadMapIndex[$key];
|
||||||
|
unset($this->jsHeadMap[$index][$key]);
|
||||||
|
unset($this->jsHeadMapIndex[$key]);
|
||||||
|
}
|
||||||
|
if(isset($this->jsBodyMapIndex[$key]))
|
||||||
|
{
|
||||||
|
$index = $this->jsBodyMapIndex[$key];
|
||||||
|
unset($this->jsBodyMap[$index][$key]);
|
||||||
|
unset($this->jsBodyMapIndex[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unload all front end file
|
||||||
|
*
|
||||||
|
* @param string $type Type to unload. all, css, js
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function unloadAllFiles($type = 'all')
|
||||||
|
{
|
||||||
|
if($type == 'css' || $type == 'all')
|
||||||
|
{
|
||||||
|
$this->cssMap = array();
|
||||||
|
$this->cssMapIndex = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
if($type == 'js' || $type == 'all')
|
||||||
|
{
|
||||||
|
$this->jsHeadMap = array();
|
||||||
|
$this->jsBodyMap = array();
|
||||||
|
$this->jsHeadMapIndex = array();
|
||||||
|
$this->jsBodyMapIndex = array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get css file list
|
||||||
|
*
|
||||||
|
* @return array Returns css file list. Array contains file, media, targetie.
|
||||||
|
*/
|
||||||
|
function getCssFileList()
|
||||||
|
{
|
||||||
|
$map = &$this->cssMap;
|
||||||
|
$mapIndex = &$this->cssMapIndex;
|
||||||
|
|
||||||
|
$this->_sortMap($map, $mapIndex);
|
||||||
|
|
||||||
|
$dbInfo = Context::getDBInfo();
|
||||||
|
$useCdn = $dbInfo->use_cdn;
|
||||||
|
|
||||||
|
$result = array();
|
||||||
|
foreach($map as $indexedMap)
|
||||||
|
{
|
||||||
|
foreach($indexedMap as $file)
|
||||||
|
{
|
||||||
|
if($this->isSsl() == false && $useCdn == 'Y' && $file->useCdn && $file->cdnVersion != '%__XE_CDN_VERSION__%')
|
||||||
|
{
|
||||||
|
$fullFilePath = $file->cdnPrefix . $file->cdnVersion . '/' . substr($file->cdnPath, 2) . '/' . $file->fileName;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$noneCache = (is_readable($file->cdnPath.'/'.$file->fileName))?'?'.date('YmdHis', filemtime($file->cdnPath.'/'.$file->fileName)):'';
|
||||||
|
$fullFilePath = $file->filePath . '/' . $file->fileName.$noneCache;
|
||||||
|
}
|
||||||
|
$result[] = array('file' => $fullFilePath, 'media' => $file->media, 'targetie' => $file->targetIe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get javascript file list
|
||||||
|
*
|
||||||
|
* @param string $type Type of javascript. head, body
|
||||||
|
* @return array Returns javascript file list. Array contains file, targetie.
|
||||||
|
*/
|
||||||
|
function getJsFileList($type = 'head')
|
||||||
|
{
|
||||||
|
if($type == 'head')
|
||||||
|
{
|
||||||
|
$map = &$this->jsHeadMap;
|
||||||
|
$mapIndex = &$this->jsHeadMapIndex;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$map = &$this->jsBodyMap;
|
||||||
|
$mapIndex = &$this->jsBodyMapIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_sortMap($map, $mapIndex);
|
||||||
|
|
||||||
|
$dbInfo = Context::getDBInfo();
|
||||||
|
$useCdn = $dbInfo->use_cdn;
|
||||||
|
|
||||||
|
$result = array();
|
||||||
|
foreach($map as $indexedMap)
|
||||||
|
{
|
||||||
|
foreach($indexedMap as $file)
|
||||||
|
{
|
||||||
|
if($this->isSsl() == false && $useCdn == 'Y' && $file->useCdn && $file->cdnVersion != '%__XE_CDN_VERSION__%')
|
||||||
|
{
|
||||||
|
$fullFilePath = $file->cdnPrefix . $file->cdnVersion . '/' . substr($file->cdnPath, 2) . '/' . $file->fileName;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$noneCache = (is_readable($file->cdnPath.'/'.$file->fileName))?'?'.date('YmdHis', filemtime($file->cdnPath.'/'.$file->fileName)):'';
|
||||||
|
$fullFilePath = $file->filePath . '/' . $file->fileName.$noneCache;
|
||||||
|
}
|
||||||
|
$result[] = array('file' => $fullFilePath, 'targetie' => $file->targetIe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort a map
|
||||||
|
*
|
||||||
|
* @param array $map Array to sort
|
||||||
|
* @param array $index Not used
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function _sortMap(&$map, &$index)
|
||||||
|
{
|
||||||
|
ksort($map);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize File path
|
||||||
|
*
|
||||||
|
* @param string $path Path to normalize
|
||||||
|
* @return string Normalized path
|
||||||
|
*/
|
||||||
|
function _normalizeFilePath($path)
|
||||||
|
{
|
||||||
|
if(strpos($path, '://') === false && $path{0} != '/' && $path{0} != '.')
|
||||||
|
{
|
||||||
|
$path = './' . $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
$path = preg_replace('@/\./|(?<!:)\/\/@', '/', $path);
|
||||||
|
|
||||||
|
while(strpos($path, '/../'))
|
||||||
|
{
|
||||||
|
$path = preg_replace('/\/([^\/]+)\/\.\.\//s', '/', $path, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get absolute file url
|
||||||
|
*
|
||||||
|
* @param string $path Path to get absolute url
|
||||||
|
* @return string Absolute url
|
||||||
|
*/
|
||||||
|
function _getAbsFileUrl($path)
|
||||||
|
{
|
||||||
|
$path = $this->_normalizeFilePath($path);
|
||||||
|
|
||||||
|
if(strpos($path, './') === 0)
|
||||||
|
{
|
||||||
|
if(dirname($_SERVER['SCRIPT_NAME']) == '/' || dirname($_SERVER['SCRIPT_NAME']) == '\\')
|
||||||
|
{
|
||||||
|
$path = '/' . substr($path, 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$path = dirname($_SERVER['SCRIPT_NAME']) . '/' . substr($path, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(strpos($file, '../') === 0)
|
||||||
|
{
|
||||||
|
$path= $this->_normalizeFilePath(dirname($_SERVER['SCRIPT_NAME']) . "/{$path}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Arrage css index
|
||||||
|
*
|
||||||
|
* @param string $dirName First directory name of css path
|
||||||
|
* @param array $file file info.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function _arrangeCssIndex($dirName, &$file)
|
||||||
|
{
|
||||||
|
if($file->index !== 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dirName = str_replace('./', '', $dirName);
|
||||||
|
$tmp = explode('/', $dirName);
|
||||||
|
|
||||||
|
$cssSortList = array('common'=>-100000, 'layouts'=>-90000, 'modules'=>-80000, 'widgets'=>-70000, 'addons'=>-60000);
|
||||||
|
$file->index = $cssSortList[$tmp[0]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* End of file FrontEndFileHandler.class.php */
|
/* End of file FrontEndFileHandler.class.php */
|
||||||
/* Location: ./classes/frontendfile/FrontEndFileHandler.class.php */
|
/* Location: ./classes/frontendfile/FrontEndFileHandler.class.php */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue