Ejemplo n.º 1
0
 /**
  *  format attribute
  *  
  *  @param string name
  *
  *  @param string key
  *
  *  @param array with attributes
  *
  *  @param boolean create attribute if no value
  *
  *  @return string
  */
 public static function format_attribute($attribute_name, $attribute_key, $attributes, $show_empty = false, $element_type = '')
 {
     if (isset($attributes[$attribute_key]) && strlen(trim($attributes[$attribute_key]))) {
         if (in_array($element_type, array('text_input')) && $attribute_key == 'value') {
             return ' ' . $attribute_name . '="' . otw_htmlentities(otw_stripslashes($attributes[$attribute_key])) . '"';
         } else {
             return ' ' . $attribute_name . '="' . $attributes[$attribute_key] . '"';
         }
     } elseif ($show_empty) {
         return ' ' . $attribute_name . '=""';
     }
 }
Ejemplo n.º 2
0
 /** Get shortcode by given params from editor interace
  *
  */
 public function get_code()
 {
     $response = array();
     $response['code'] = '';
     $attributes = otw_stripslashes($_POST);
     if (isset($attributes['shortcode_type']) && array_key_exists($attributes['shortcode_type'], $this->shortcodes)) {
         if ($shortcode = $this->shortcodes[$attributes['shortcode_type']]['object']->build_shortcode_code($attributes)) {
             $response['code'] = $shortcode;
         }
         if ($shortcode_attributes = $this->shortcodes[$attributes['shortcode_type']]['object']->get_shortcode_attributes($attributes)) {
             $response['shortcode_attributes'] = $shortcode_attributes;
         }
         if ($this->shortcodes[$attributes['shortcode_type']]['object']->has_error) {
             foreach ($this->shortcodes[$attributes['shortcode_type']]['object']->errors as $error) {
                 $this->add_error($error);
             }
         }
     } else {
         $this->add_error($this->get_label('Invalid shortcode'));
     }
     $response['has_error'] = $this->has_error;
     $response['errors'] = $this->errors;
     echo json_encode($response);
     die;
 }