コード例 #1
0
 public function __construct($id, $option, $data)
 {
     $this->id = $id;
     $this->option = $option;
     $this->data = $data;
     /**
      * Generate random editor_id that will be used.
      * Using a hash of combination of $option and $id is not enough. It
      * usually repeats itself on the page pretty often.
      */
     $this->editor_id = fw()->backend->option_type('wp-editor')->get_id_prefix() . fw_rand_md5();
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function get_value_from_items($items)
 {
     if (!is_array($items)) {
         return array();
     }
     static $recursion_level = 0;
     /** prevent duplicate shortcodes */
     static $found_shortcodes = array();
     /**
      * @var FW_Option_Type_Builder_Item[] $item_types
      */
     $item_types = $this->get_item_types();
     $fixed_items = array();
     foreach ($items as $item_attributes) {
         if (!isset($item_attributes['type']) || !isset($item_types[$item_attributes['type']])) {
             // invalid item type
             continue;
         }
         $fixed_item_attributes = $item_types[$item_attributes['type']]->get_value_from_attributes($item_attributes);
         if (empty($fixed_item_attributes['shortcode']) || isset($found_shortcodes[$fixed_item_attributes['shortcode']])) {
             $fixed_item_attributes['shortcode'] = sanitize_key(str_replace('-', '_', $item_attributes['type']) . '_' . substr(fw_rand_md5(), 0, 7));
         }
         $found_shortcodes[$fixed_item_attributes['shortcode']] = true;
         if (isset($fixed_item_attributes['_items'])) {
             // item leaved _items key, this means that it has/accepts items in it
             $recursion_level++;
             $fixed_item_attributes['_items'] = $this->get_value_from_items($fixed_item_attributes['_items']);
             $recursion_level--;
         }
         $fixed_items[] = $fixed_item_attributes;
         unset($fixed_item_attributes);
     }
     /**
      * this will be real return (not inside a recursion)
      * make some clean up
      */
     if (!$recursion_level) {
         $found_shortcodes = array();
     }
     return $fixed_items;
 }
コード例 #3
0
ファイル: simple.php プロジェクト: isatrio/Unyson
 /**
  * @param null|int $length_limit
  * @return string
  */
 protected function generate_id($length_limit = null)
 {
     $id = fw_rand_md5();
     if ($length_limit) {
         $id = substr($id, 0, (int) $length_limit);
     }
     return $id;
 }
 /**
  * @param string $id
  */
 public function __construct($id = null)
 {
     $this->id = (string) (is_null($id) ? fw_rand_md5() : $id);
 }
コード例 #5
0
				<div class="fw-option-box-options fw-force-xs">
					<?php 
    echo fw()->backend->render_options($box_options, $values, array('id_prefix' => $data['id_prefix'] . $id . '-' . $i . '-', 'name_prefix' => $data['name_prefix'] . '[' . $id . '][' . $i . ']'));
    ?>
				</div>
				<?php 
    echo fw()->backend->render_box($data['id_prefix'] . $id . '-' . $i . '-box', '&nbsp;', ob_get_clean(), array('html_after_title' => $controls_html, 'attr' => array('class' => 'fw-option-type-addable-box-pending-title-update')));
    ?>
			</div>
		<?php 
}
unset($values);
?>
	</div>
	<br class="default-box-template fw-hidden" data-template="<?php 
/**
 * Place template in attribute to prevent it to be treated as html
 * when this option will be used inside another option template
 */
$values = array();
// must contain characters that will remain the same after htmlspecialchars()
$increment_placeholder = '###-addable-box-increment-' . fw_rand_md5() . '-###';
echo fw_htmlspecialchars('<div class="fw-option-box" data-name-prefix="' . fw_htmlspecialchars($data['name_prefix'] . '[' . $id . '][' . $increment_placeholder . ']') . '">' . fw()->backend->render_box($data['id_prefix'] . $id . '-' . $increment_placeholder . '-box', '&nbsp;', '<div class="fw-option-box-options fw-force-xs">' . fw()->backend->render_options($box_options, $values, array('id_prefix' => $data['id_prefix'] . $id . '-' . $increment_placeholder . '-', 'name_prefix' => $data['name_prefix'] . '[' . $id . '][' . $increment_placeholder . ']')) . '</div>', array('html_after_title' => $controls_html)) . '</div>');
?>
">
	<div class="fw-option-boxes-controls">
		<?php 
echo fw_html_tag('button', array('type' => 'button', 'onclick' => 'return false;', 'class' => 'button fw-option-boxes-add-button', 'data-increment' => ++$i, 'data-increment-placeholder' => $increment_placeholder, 'data-limit' => intval($option['limit'])), __('Add', 'fw'));
?>
	</div>
</div>
コード例 #6
0
ファイル: backend.php プロジェクト: joelgarciajr84/Unyson
 /**
  * @param int $post_id
  * @param WP_Post $post
  * @param bool $update
  */
 public function _action_save_post($post_id, $post, $update)
 {
     if (isset($_POST['post_ID']) && intval($_POST['post_ID']) === intval($post_id) && !empty($_POST[FW_Option_Type::get_default_name_prefix()])) {
         /**
          * This happens on regular post form submit
          * All data from $_POST belongs this $post
          * so we save them in its post meta
          */
         static $post_options_save_happened = false;
         if ($post_options_save_happened) {
             /**
              * Prevent multiple options save for same post
              * It can happen from a recursion or wp_update_post() for same post id
              */
             return;
         } else {
             $post_options_save_happened = true;
         }
         $old_values = (array) fw_get_db_post_option($post_id);
         $current_values = fw_get_options_values_from_input(fw()->theme->get_post_options($post->post_type));
         fw_set_db_post_option($post_id, null, array_diff_key($current_values, $this->process_options_handlers(fw()->theme->get_post_options($post->post_type), $current_values)));
         /**
          * @deprecated
          * Use the 'fw_post_options_update' action
          */
         do_action('fw_save_post_options', $post_id, $post, $old_values);
     } elseif ($original_post_id = wp_is_post_revision($post_id)) {
         /**
          * Do nothing, the
          * - '_wp_put_post_revision'
          * - 'wp_restore_post_revision'
          * - 'wp_creating_autosave'
          * actions will handle this
          */
     } elseif ($original_post_id = wp_is_post_autosave($post_id)) {
         // fixme: I don't know how to test this. The execution never entered here
         FW_Flash_Messages::add(fw_rand_md5(), 'Unhandled auto-save');
     } else {
         /**
          * This happens on:
          * - post add (auto-draft): do nothing
          * - revision restore: do nothing, that is handled by the 'wp_restore_post_revision' action
          */
     }
 }
コード例 #7
0
ファイル: simple.php プロジェクト: kreapress/Unyson
 protected function _get_value_from_input($option, $input_value)
 {
     if (is_null($input_value)) {
         $id = empty($option['value']) ? fw_rand_md5() : $option['value'];
     } else {
         $id = $input_value;
     }
     if (empty($id) || !is_string($id)) {
         $id = fw_rand_md5();
     }
     global $post;
     if ($post) {
         $post_id = $post->ID;
     } else {
         $post_id = '~';
     }
     if (!isset(self::$ids[$post_id])) {
         self::$ids[$post_id] = array();
     }
     while (isset(self::$ids[$post_id][$id])) {
         $id = fw_rand_md5();
     }
     self::$ids[$post_id][$id] = true;
     return $id;
 }