create_element_structure(); $this->extra_config( $am_elements ); $this->precreate_visual_editor(); } // reload the class again using given config array public function reload( $config ) { if(count($config)>0) { $this->config = $config; $this->precreate_visual_editor(); if(isset($this->config['popup_editor']) && $this->config['popup_editor']) { $this->parse_editor_elements(); } } } // the main method that will create the element structure, it has to be implemented in the element class. abstract function create_element_structure(); /** * Return configuratino array */ public function element_to_array() { return $this->config; } /** * additional config vars that are set automatically */ protected function extra_config( $am_elements = array() ) { $this->config['childrenId'] = array(); //if the element class contain method "popup_elements" it will be called. // if it's not then the element is not editable, i.e. no popup will be displayed when element is clicked. if( method_exists($this, 'popup_elements') ) { $this->popup_elements( $am_elements ); if( !empty($this->config['subElements']) ) { $this->config['popup_editor'] = true; //$this->parse_editor_elements(); } } } /** * Prepare the editable popup content by reading all elements subElemenet and add it to attribute "editPanel_innerHtml". */ private function parse_editor_elements() { $output = ""; $output .= "
"; foreach ( $this->config['subElements'] as $key => $element ) { if( $element['type'] == ElementTypeEnum::ADDMORE ) { $elementsCount = count ( $element['elements'][0]['value'] ); $elementsCount = ($elementsCount > 0 ? $elementsCount : 1); $output .= ''; $output .= ""; for ($i = 0; $i < $elementsCount; $i++) { $output .= ""; } $output .= ""; $output .= "
"; foreach ($element['elements'] as $dynamic_element ) { $output .= "
"; if( !empty($dynamic_element['name'])) { $output .= "".$dynamic_element['name'].""; } if( !empty($dynamic_element['desc'])) { $output .= "".$dynamic_element['desc'].""; } if ( isset ($dynamic_element['value'][$i]) ) { $dynamic_element['value'] = $dynamic_element['value'][$i]; } else { $dynamic_element['value'] = ''; } if (isset ($dynamic_element['upid'])) { $dynamic_element['upid'] = $i; } $output .= "
"; $output .="
"; $output .= $this->parseElementType($dynamic_element); $output .= "
"; $output .= "
"; } $output .="".__('Remove', 'fusion-core').""; $output .= "
".$element['buttonText']."
"; } else { $output .= "
"; $output .= "
"; if( !empty($element['name'])) { $output .= "".$element['name'].""; } if( !empty($element['desc'])) { $output .= "".$element['desc'].""; } $output .= "
"; $output .="
"; $output .= $this->parseElementType($element); $output .= "
"; $output .= "
"; } } $output .= "
"; $this->config['editPanel_innerHtml'] = $output; } /** * Check the subelement type and render it with the correct implementation * @param $element element * @return string correct implementation for the element according to its type */ private function parseElementType( $element ) { $output = ""; switch ($element['type']) { case ElementTypeEnum::COLOR: $output .= ''; break; case ElementTypeEnum::GALLERY: $output .= ''.__('Attach Images to Gallery', 'fusion-core').''; break; case ElementTypeEnum::UPLOAD: $button_class = ( $element['value'] == 'fusion-hidden-img' ? '' : 'remove-image' ); $button_text = ( $element['value'] == 'fusion-hidden-img' ? __('Upload', 'fusion-core') : __('Remove', 'fusion-core') ); $output .= '
'; $output .= 'Image'; $output .= '' . "\n"; $output .= ' '.$button_text.''; $output .= '
'; break; case ElementTypeEnum::INPUT: $output .= ''; break; case ElementTypeEnum::HIDDEN: $output .= ''; break; case ElementTypeEnum::MULTI: $output .= ''; break; case ElementTypeEnum::SELECT: $output .= ''; break; case ElementTypeEnum::RADIO: $counter = 1; foreach( $element['allowedValues'] as $key => $radiobutton ) { $checked = ""; if( $element['value'] == $key ) { $checked = 'checked = "checked"'; } $output .= ''; $output .= ''; $output .= ''; $output .= ''; $counter++; } break; case ElementTypeEnum::CHECKBOX: $counter = 1; foreach( $element['allowedValues'] as $key => $checkbox ) { $checked = ""; if( $element['value'] == $key ) { $checked = 'checked = "checked"'; } $output .= ''; $output .= ''; $output .= ''; $output .= ''; $counter++; } break; case ElementTypeEnum::TEXTAREA: $output .= ''; break; case ElementTypeEnum::HTML_EDITOR: $output .= ''; $output .= ''; break; case ElementTypeEnum::ICON_BOX: $iconsArray = Helper::GET_ICONS_LIST(); $output .= "
"; foreach ($iconsArray as $iconKey => $iconValue) { $selectedClass = ""; if($element['value'] == $iconValue) { $selectedClass = "selected-element"; } $output .= ''; } $output .= '
'; $output .= ''; break; default : break; } return $output; } /** * Cet current or default sub element values and pass it to function create_visual_editor to create the element view. */ public function precreate_visual_editor() { $content = $this->get_content(); //set the default arguments unless they were already passed $args = $this->get_args(); $params['content'] = $content; $params['args'] = $args; //fetch the parameter array from the child classes editor_element function which should descripe the html code $this->create_visual_editor( $params ); } /** * function that will create the element layout in the main editor. * This function can be override by the child class if the element has specific view, for example IconBox.php */ public function create_visual_editor( $params ) { $innerHtml = ""; if(isset($this->config['icon_url'])) { $innerHtml .= ""; } $innerHtml.= "
".$this->config['name']."
"; $this->config['innerHtml'] = $innerHtml; } /** * helper function that gets the default value of the content element * * @param array $elements * @return array $args */ private function get_content() { $content = ""; if(!empty($this->config['subElements'])) { $this->get_args(); //if there is a content element already thats the value. if not try to fetch the value if(!isset($this->args['content'])) { foreach($this->config['subElements'] as $element) { if(isset($element['value']) && isset($element['id']) && $element['id'] == "content") { $content = $element['value']; } } } else{ $content = $this->args['content']; } } return $content; } /** * helper function executed that extracts the std values from the options array and creates a shortcode argument array * * @param array $elements * @return array $args */ private function get_args() { $args = array(); if(!empty($this->config['subElements'])) { foreach($this->config['subElements'] as $element) { if(isset($element['value']) && isset($element['id'])) { $args[$element['id']] = $element['value']; } } $this->args = $args; } return $args; } }