*/ /** * A class to handle extra variables used in posts, member and others * * @author NAVER (developers@xpressengine.com) */ class ExtraVar { /** * sequence of module * @var int */ var $module_srl = null; /** * Current module's Set of ExtraItem * @var ExtraItem[] */ var $keys = array(); /** * Get instance of ExtraVar (singleton) * * @param int $module_srl Sequence of module * @return ExtraVar */ public static function getInstance($module_srl) { return new ExtraVar($module_srl); } /** * Constructor * * @param int $module_srl Sequence of module * @return void */ function __construct($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) < 1) { return; } foreach($extra_keys as $val) { $obj = new ExtraItem($val->module_srl, $val->idx, $val->name, $val->type, $val->default, $val->desc, $val->is_required, $val->search, $val->value ?? null, $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 NAVER (developers@xpressengine.com) */ class ExtraItem { /** * Sequence of module * @var int */ var $module_srl = 0; /** * Index of extra variable * @var int */ var $idx = 0; /** * Name of extra variable * @var string */ var $name = 0; /** * Type of extra variable * @var string text, homepage, email_address, tel, textarea, checkbox, date, select, radio, kr_zip */ var $type = 'text'; /** * Default values * @var string[] */ var $default = null; /** * Description * @var string */ var $desc = ''; /** * Whether required or not requred this extra variable * @var string Y, N */ var $is_required = 'N'; /** * Whether can or can not search this extra variable * @var string Y, N */ var $search = 'N'; /** * Value * @var string */ var $value = null; /** * Unique id of extra variable in module * @var string */ var $eid = ''; /** * Constructor * * @param int $module_srl Sequence of module * @param int $idx Index of extra variable * @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 __construct($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 * * @param string $value The value to set * @return void */ function setValue($value) { $this->value = $value; } /** * Returns a given value converted based on its type * * @param string $type Type of variable * @param string $value Value * @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 escape($value, false); case 'tel' : if(is_array($value)) { $values = $value; } elseif(strpos($value, '|@|') !== FALSE) { $values = explode('|@|', $value); } elseif(strpos($value, ',') !== FALSE) { $values = explode(',', $value); } else { $values = array($value); } $values = array_values($values); for($i = 0, $c = count($values); $i < $c; $i++) { $values[$i] = trim(escape($values[$i], false)); } return $values; case 'tel_intl' : if(is_array($value)) { $values = $value; } elseif(strpos($value, '|@|') !== FALSE) { $values = explode('|@|', $value); } elseif(strpos($value, ',') !== FALSE) { $values = explode(',', $value); } else { $values = array($value); } $values = array_values($values); for($i = 0, $c = count($values); $i < $c; $i++) { $values[$i] = trim(escape($values[$i], false)); } return $values; 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); } $values = array_values($values); for($i = 0, $c = count($values); $i < $c; $i++) { $values[$i] = trim(escape($values[$i], false)); } return $values; case 'kr_zip' : if(is_array($value)) { $values = $value; } elseif(strpos($value, '|@|') !== false) { $values = explode('|@|', $value); } else { $values = array($value); } $values = array_values($values); for($i = 0, $c = count($values); $i < $c; $i++) { $values[$i] = trim(escape($values[$i], false)); } return $values; //case 'date' : //case 'email_address' : //case 'text' : //case 'textarea' : //case 'password' : default : return escape($value, false); } } /** * Returns a value for HTML * * @return string Returns filtered value */ function getValue() { return $this->_getTypeValue($this->type, $this->value); } /** * Returns a value for HTML * * @return string Returns a value expressed in HTML. */ function getValueHTML() { $value = $this->_getTypeValue($this->type, $this->value); switch($this->type) { case 'homepage' : return ($value) ? (sprintf('%s', $value, strlen($value) > 60 ? substr($value, 0, 40) . '...' . substr($value, -10) : $value)) : ""; case 'email_address' : return ($value) ? sprintf('%s', $value, $value) : ""; case 'tel' : return $value ? implode('-', $value) : ''; case 'tel_intl' : $country_number = $value[0]; $array_slice = array_slice($value, 1); $phone_number = implode('-', $array_slice); return $value ? "+{$country_number}){$phone_number}": ''; case 'country': $country_info = Rhymix\Framework\i18n::listCountries()[$value]; $lang_type = Context::get('lang_type'); $country_name = $lang_type === 'ko' ? $country_info->name_korean : $country_info->name_english; return $country_name; case 'textarea' : return nl2br($value); case 'date' : return zdate($value, "Y-m-d"); case 'language': return Rhymix\Framework\Lang::getSupportedList()[$value]['name']; case 'timezone': return Rhymix\Framework\DateTime::getTimezoneList()[$value]; case 'checkbox' : case 'select' : case 'radio' : if(is_array($value)) { return implode(',', $value); } return $value; case 'kr_zip' : if(is_array($value)) { return implode(' ', $value); } return $value; // case 'text' : // case 'password' : default : return $value; } } /** * Returns a form based on its type * * @return string Returns a form html. */ function getFormHTML() { static $id_num = 1000; $type = $this->type; $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 = array(); switch($type) { // Homepage case 'homepage' : $buff[] = ''; break; // Email Address case 'email_address' : $buff[] = ''; break; // Phone Number case 'tel' : $buff[] = ''; $buff[] = ''; $buff[] = ''; break; // Select Country Number case 'tel_intl' : $lang_type = Context::get('lang_type'); $country_list = Rhymix\Framework\i18n::listCountries($lang_type === 'ko' ? Rhymix\Framework\i18n::SORT_NAME_KOREAN : Rhymix\Framework\i18n::SORT_NAME_ENGLISH); $buff[] = ''; $buff[] = ''; $buff[] = ''; $buff[] = ''; break; // Select Country case 'country': $lang_type = Context::get('lang_type'); $country_list = Rhymix\Framework\i18n::listCountries($lang_type === 'ko' ? Rhymix\Framework\i18n::SORT_NAME_KOREAN : Rhymix\Framework\i18n::SORT_NAME_ENGLISH); $buff[] = ''; break; // Select language case 'language': $enable_language = Rhymix\Framework\Config::get('locale.enabled_lang'); $supported_lang = Rhymix\Framework\Lang::getSupportedList(); $buff[] = ''; break; // Select timezone case 'timezone': $timezone_list = Rhymix\Framework\DateTime::getTimezoneList(); $buff[] = ''; break; // textarea case 'textarea' : $buff[] = ''; break; // multiple choice case 'checkbox' : $buff[] = ''; break; // single choice case 'select' : $buff[] = ''; break; // radio case 'radio' : $buff[] = ''; break; // date case 'date' : // datepicker javascript plugin load Context::loadJavascriptPlugin('ui.datepicker'); $buff[] = ''; $buff[] = ''; $buff[] = ''; $buff[] = ''; break; // address case "kr_zip" : if(($oKrzipModel = getModel('krzip')) && method_exists($oKrzipModel , 'getKrzipCodeSearchHtml' )) { $buff[] = $oKrzipModel->getKrzipCodeSearchHtml($column_name, $value); } break; // Password case "password" : $buff[] =' '; break; // General text default : $buff[] =' '; } if($this->desc) { $buff[] = '

' . escape(Context::replaceUserLang($this->desc), false) . '

'; } return join("\n", $buff); } } /* End of file ExtraVar.class.php */ /* Location: ./classes/extravar/ExtraVar.class.php */