options = $options; $this->settings_field = $settings_field; $this->default_settings = $default_settings; } /* * function to call outside from the current page, to load the assets */ public function load_assets_files() { wp_enqueue_media(); } public function render($type, $name, $value = null, $optionsgroup = '', $classname = '', $isfiles = false, $attribs = '') { $function = 'get'.ucfirst($type); $this->name = $this->getName($name); $this->id = $this->getId($name); $this->value = $value !== null ? $value : $this->getValue($name); $this->classname = $classname; $this->optionsgroup = $optionsgroup; $this->isfiles = $isfiles; $this->attribs = $attribs; return $this->$function(); } public function getName( $name ) { return sprintf( '%s[%s]', $this->settings_field, $name ); } // public function getName($name) { // return sprintf('%s[%s]', $this->settings_field, $name); // } public function getId($name) { return trim(preg_replace('#\W#', '_', $name), '_'); } public function get($key, $default = null) { return $this->getValue($key, $default); } public function getValue( $key, $default = null, $allowEmpty = false ) { // var_dump($this->options); if (isset($this->options[$key]) && ($allowEmpty == true || ($allowEmpty == false && $this->options[$key] !== ''))) { return $this->options[$key]; } else { if ($default == null && isset($this->default_settings[$key])) return $this->default_settings[$key]; } return $default; } private function getColor() { $class = $this->classname ? ' class="color '.$this->classname.' {required:false,pickerPosition:\'top\',pickerBorder:2,pickerInset:3,hash:true}"' : ' class="color {required:false,pickerPosition:\'top\',pickerBorder:2,pickerInset:3,hash:true}"'; $html = ''; return $html; } private function getText() { $class = $this->classname ? ' class="'.$this->classname.'"' : ''; $html = ''; return $html; } private function getSelect() { $class = $this->classname ? ' class="'.$this->classname.'"' : ''; $html = 'attribs.' >'; $html .= $this->getOptions(); $html .= ''; return $html; } private function getOptions() { if (!is_array($this->optionsgroup) && $this->optionsgroup != 'boolean') { $this->getArrayFromOptions(); } if ($this->optionsgroup == 'boolean') { $this->optionsgroup = array( '1' => __('yes') , '0'=> __('no') ); } $optionshtml = array(); foreach ($this->optionsgroup as $val => $name) { if ( $this->isfiles == true ) { $val = $name; } if ((is_array($this->value) && in_array($val, $this->value)) || $val == $this->value) { $optionshtml[] = ''.$name.''; } else { $optionshtml[] = ''.$name.''; } } return implode('', $optionshtml); } private function getArrayFromOptions() { $this->optionsgroup = rtrim($this->optionsgroup, ''); $this->optionsgroup = explode('', $this->optionsgroup); $optionsgroup = array(); foreach ($this->optionsgroup as $option) { $option = explode('">', $option); $optionsgroup[str_replace( 'classname.'"' : ''; $html = array(); // Start the radio field output. $html[] = ''; // Get the field options. $options = $this->optionsgroup; // Build the radio field output. foreach ($options as $value => $name) { if (stristr($name,"img:")) $name = ''; // Initialize some option attributes. $checked = ((string) $value == (string) $this->value) ? ' checked="checked"' : ''; $class = ' class="ckradio"'; $html[] = ''; $html[] = '' . __($name, 'slideshow-ck') . ''; } // End the radio field output. $html[] = ''; return implode($html); } private function getMedia() { $class = $this->classname ? ' class="'.$this->classname.'"' : ''; $html = ''; $html .= ''. __('Select') .''; $html .= ''. __('Clear') .''; return $html; } }