Esempio n. 1
0
 public static function get_setting($block, $setting, $default = null)
 {
     return HeadwayBlocksData::get_block_setting($block, $setting, $default);
 }
Esempio n. 2
0
 public function render_input($input)
 {
     //Fill defaults
     $defaults = array('tooltip' => false, 'default' => false, 'callback' => null);
     //Merge defaults
     $input = array_merge($defaults, $input);
     //Fix up inputs
     $input = $this->parse_function_args($input);
     if (!isset($input['name']) || !isset($input['type'])) {
         return;
     }
     /* Set up main input variables */
     $input['name'] = strtolower($input['name']);
     $input['group'] = isset($input['group']) ? $input['group'] : $this->options_group;
     $input['tooltip'] = isset($input['tooltip']) && $input['tooltip'] != false ? $input['tooltip'] : false;
     /* Populate the value */
     $input['default'] = isset($input['default']) ? $input['default'] : null;
     if (isset($this->wrapper) && $this->wrapper && !isset($input['value'])) {
         $input['value'] = HeadwayWrappers::get_wrapper_setting($this->wrapper, $input['name'], $input['default']);
     } else {
         if (isset($this->block) && $this->block && !isset($input['value'])) {
             $input['value'] = HeadwayBlocksData::get_block_setting($this->block, $input['name'], $input['default']);
         } else {
             if (!isset($input['value'])) {
                 $input['value'] = HeadwayOption::get($input['name'], $input['group'], $input['default']);
             }
         }
     }
     /* Setup Attributes */
     $attributes_array = array('id' => isset($this->block) && $this->block ? 'input-' . $this->block['id'] . '-' . $input['name'] : 'input-' . $input['group'] . '-' . $input['name'], 'name' => $input['name'], 'data-group' => $input['group']);
     /* Set up the callback attribute */
     $attributes_array['data-callback'] = htmlspecialchars('(function(args){var input=args.input;var value=args.value;var block=args.block || null;' . $input['callback'] . '})');
     /* Set up data handler override if it's used */
     if (headway_get('data-handler-callback', $input)) {
         $attributes_array['data-data-handler-callback'] = htmlspecialchars('(function(args){' . $input['data-handler-callback'] . '})');
     }
     /* Set up toggle attribute */
     if (headway_get('toggle', $input)) {
         $attributes_array['data-toggle'] = htmlspecialchars(json_encode($input['toggle']));
     }
     /* No save attribute */
     if (headway_get('no-save', $input, false)) {
         $attributes_array['data-no-save'] = 'true';
     }
     /* Turn attributes array into a string for HTML */
     $input['attributes'] = '';
     foreach ($attributes_array as $attribute => $attribute_value) {
         $input['attributes'] .= $attribute . '="' . $attribute_value . '" ';
     }
     $input['attributes'] = trim($input['attributes']);
     /* If it's a repeater then handle it before it's handled as an input */
     if ($input['type'] == 'repeater') {
         return $this->repeater($input);
     }
     /* Handle regular input */
     if (method_exists($this, 'input_' . str_replace('-', '_', $input['type']))) {
         /* Handle all types except for raw HTML input */
         if ($input['type'] != 'raw-html') {
             echo '<div class="input input-' . $input['type'] . '" id="input-' . $input['name'] . '">';
             if ($input['tooltip']) {
                 echo '<div class="tooltip-button" title="' . htmlspecialchars($input['tooltip']) . '"></div>';
             }
             call_user_func(array($this, 'input_' . str_replace('-', '_', $input['type'])), $input);
             echo '</div><!-- #input-' . $input['name'] . ' -->';
         } else {
             call_user_func(array($this, 'input_' . str_replace('-', '_', $input['type'])), $input);
         }
     }
     /* End regular input handling */
 }