| 1 |
<?php |
| 2 |
namespace MaxButtons; |
| 3 |
defined('ABSPATH') or die('No direct access permitted'); |
| 4 |
|
| 5 |
$blockClass["meta"] = "metaBlock"; |
| 6 |
$blockOrder[100][] = "meta"; |
| 7 |
|
| 8 |
class metaBlock extends maxBlock |
| 9 |
{ |
| 10 |
protected $blockname = "meta"; |
| 11 |
protected $fields = array("created" => array("default" => 0), |
| 12 |
"modified" => array("default" => 0), |
| 13 |
"user_created" => array("default" => ''), // user logged in on creation |
| 14 |
"user_modified" => array("default" => ''), |
| 15 |
"created_source" => array("default" => 'unknown'), // from editor / pack / collection ? |
| 16 |
"user_edited" => array("default" => false), // did a user ever edit this button? |
| 17 |
"in_collections" => array("default" => array() ), // map collections this button is in. |
| 18 |
"is_virtual" => array("default" => false), // this button is not really in the database |
| 19 |
); |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
/*function __construct() |
| 24 |
{ |
| 25 |
parent::__construct(); |
| 26 |
|
| 27 |
} */ |
| 28 |
|
| 29 |
public function save_fields($data, $post) |
| 30 |
{ |
| 31 |
$data = parent::save_fields($data,$post); |
| 32 |
|
| 33 |
$blockdata = $data[$this->blockname]; |
| 34 |
$button_id = isset($data["id"]) ? $data["id"] : 0; |
| 35 |
$user = wp_get_current_user(); |
| 36 |
|
| 37 |
|
| 38 |
if ($button_id == 0) |
| 39 |
{ |
| 40 |
$blockdata["created"] = time(); |
| 41 |
$blockdata["user_created"] = $user->user_login; |
| 42 |
} |
| 43 |
|
| 44 |
$blockdata["modified"] = time(); |
| 45 |
$blockdata["user_modified"] = $user->user_login; |
| 46 |
|
| 47 |
|
| 48 |
$data[$this->blockname] = $blockdata; |
| 49 |
|
| 50 |
return $data; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
public function admin_fields() |
| 55 |
{ |
| 56 |
//return false; |
| 57 |
$data = (isset($this->data[$this->blockname]) && is_array($this->data[$this->blockname])) ? $this->data[$this->blockname] : array(); |
| 58 |
|
| 59 |
foreach($this->fields as $field => $options) |
| 60 |
{ |
| 61 |
$default = (isset($options["default"])) ? $options["default"] : ''; |
| 62 |
$$field = (isset($data[$field])) ? $data[$field] : $default; |
| 63 |
${$field . "_default"} = $default; |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
if(! isset($data["id"]) || $data["id"] == 0) |
| 69 |
$created_source = 'editor'; // button born at the editor |
| 70 |
|
| 71 |
|
| 72 |
?> |
| 73 |
<input type="hidden" name="created" value="<?php echo $created ?>"> |
| 74 |
<input type="hidden" name="user_created" value="<?php echo $user_created ?>"> |
| 75 |
|
| 76 |
<input type='hidden' name='created_source' value="<?php echo $created_source ?>"> |
| 77 |
<input type='hidden' name='user_edited' value='true'> |
| 78 |
|
| 79 |
<?php if (is_array($in_collections)) { |
| 80 |
foreach ($in_collections as $collection_id) |
| 81 |
{ |
| 82 |
?> |
| 83 |
<input type="hidden" name="in_collections[]" value="<?php echo $collection_id ?>"> |
| 84 |
<?php |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
} ?> |
| 90 |
<input type="hidden" name="is_virtual" value="<?php echo $is_virtual; ?>"> |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
<?php |
| 96 |
if (defined("MAXBUTTONS_DEBUG") && MAXBUTTONS_DEBUG): |
| 97 |
|
| 98 |
?> |
| 99 |
<div class="option-container mb_tab"> |
| 100 |
<div class="title"><?php _e('Meta', 'maxbuttons') ?></div> |
| 101 |
<div class="inside"> |
| 102 |
<?php foreach($data as $key => $val) { |
| 103 |
if (! is_array($val)) |
| 104 |
{ |
| 105 |
$try_json = json_decode($val); |
| 106 |
if (! is_null($try_json)) |
| 107 |
$val = $try_json; |
| 108 |
} |
| 109 |
echo "<div class='option'> <label>$key</label>"; |
| 110 |
echo "<div>" . print_r($val,true) . " </div></div>"; |
| 111 |
} |
| 112 |
?> |
| 113 |
|
| 114 |
|
| 115 |
</div> |
| 116 |
</div> |
| 117 |
<?php |
| 118 |
endif; |
| 119 |
} // admin_display |
| 120 |
|
| 121 |
} // class |
| 122 |
|
| 123 |
?> |
| 124 |
|