AudioPreset.php
1 month ago
Block.php
10 months ago
CurrentUser.php
1 year ago
EmailCollection.php
1 year ago
Model.php
3 weeks ago
ModelInterface.php
1 year ago
Player.php
3 weeks ago
Post.php
1 year ago
Preset.php
1 month ago
ReusableVideo.php
1 month ago
Setting.php
1 year ago
Video.php
1 month ago
Webhook.php
1 year ago
Preset.php
232 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Preset model. |
| 4 | * |
| 5 | * @package PrestoPlayer\Models |
| 6 | */ |
| 7 | |
| 8 | namespace PrestoPlayer\Models; |
| 9 | |
| 10 | /** |
| 11 | * Preset model for video presets stored in the presto_player_presets table. |
| 12 | * |
| 13 | * @property int $id |
| 14 | * @property string $name |
| 15 | * @property string $slug |
| 16 | */ |
| 17 | class Preset extends Model { |
| 18 | |
| 19 | /** |
| 20 | * Table used to access db |
| 21 | * |
| 22 | * @var string |
| 23 | */ |
| 24 | protected $table = 'presto_player_presets'; |
| 25 | |
| 26 | /** |
| 27 | * Model Schema |
| 28 | * |
| 29 | * @var array |
| 30 | */ |
| 31 | public function schema() { |
| 32 | return array( |
| 33 | 'id' => array( |
| 34 | 'type' => 'integer', |
| 35 | ), |
| 36 | 'name' => array( |
| 37 | 'type' => 'string', |
| 38 | 'sanitize_callback' => 'wp_kses_post', |
| 39 | ), |
| 40 | 'slug' => array( |
| 41 | 'type' => 'string', |
| 42 | 'sanitize_callback' => 'sanitize_title', |
| 43 | ), |
| 44 | 'icon' => array( |
| 45 | 'type' => 'string', |
| 46 | 'sanitize_callback' => 'sanitize_text_field', |
| 47 | ), |
| 48 | 'skin' => array( |
| 49 | 'type' => 'string', |
| 50 | 'sanitize_callback' => 'sanitize_text_field', |
| 51 | ), |
| 52 | 'caption_style' => array( |
| 53 | 'type' => 'string', |
| 54 | 'sanitize_callback' => 'sanitize_text_field', |
| 55 | ), |
| 56 | 'caption_background' => array( |
| 57 | 'type' => 'string', |
| 58 | 'sanitize_callback' => 'sanitize_hex_color', |
| 59 | ), |
| 60 | 'play' => array( |
| 61 | 'type' => 'boolean', |
| 62 | 'default' => false, |
| 63 | ), |
| 64 | 'play-large' => array( |
| 65 | 'type' => 'boolean', |
| 66 | 'default' => false, |
| 67 | ), |
| 68 | 'rewind' => array( |
| 69 | 'type' => 'boolean', |
| 70 | 'default' => false, |
| 71 | ), |
| 72 | 'fast-forward' => array( |
| 73 | 'type' => 'boolean', |
| 74 | 'default' => false, |
| 75 | ), |
| 76 | 'progress' => array( |
| 77 | 'type' => 'boolean', |
| 78 | 'default' => false, |
| 79 | ), |
| 80 | 'current-time' => array( |
| 81 | 'type' => 'boolean', |
| 82 | 'default' => false, |
| 83 | ), |
| 84 | 'mute' => array( |
| 85 | 'type' => 'boolean', |
| 86 | 'default' => false, |
| 87 | ), |
| 88 | 'volume' => array( |
| 89 | 'type' => 'boolean', |
| 90 | 'default' => false, |
| 91 | ), |
| 92 | 'speed' => array( |
| 93 | 'type' => 'boolean', |
| 94 | 'default' => false, |
| 95 | ), |
| 96 | 'pip' => array( |
| 97 | 'type' => 'boolean', |
| 98 | 'default' => false, |
| 99 | ), |
| 100 | 'fullscreen' => array( |
| 101 | 'type' => 'boolean', |
| 102 | 'default' => false, |
| 103 | ), |
| 104 | 'captions' => array( |
| 105 | 'type' => 'boolean', |
| 106 | 'default' => false, |
| 107 | ), |
| 108 | 'reset_on_end' => array( |
| 109 | 'type' => 'boolean', |
| 110 | 'default' => false, |
| 111 | ), |
| 112 | 'auto_hide' => array( |
| 113 | 'type' => 'boolean', |
| 114 | 'default' => false, |
| 115 | ), |
| 116 | 'show_time_elapsed' => array( |
| 117 | 'type' => 'boolean', |
| 118 | 'default' => false, |
| 119 | ), |
| 120 | 'captions_enabled' => array( |
| 121 | 'type' => 'boolean', |
| 122 | 'default' => false, |
| 123 | ), |
| 124 | 'sticky_scroll' => array( |
| 125 | 'type' => 'boolean', |
| 126 | 'default' => false, |
| 127 | ), |
| 128 | 'sticky_scroll_position' => array( |
| 129 | 'type' => 'string', |
| 130 | 'default' => 'bottom right', |
| 131 | ), |
| 132 | 'on_video_end' => array( |
| 133 | 'type' => 'string', |
| 134 | 'default' => 'select', |
| 135 | ), |
| 136 | 'play_video_viewport' => array( |
| 137 | 'type' => 'boolean', |
| 138 | 'default' => false, |
| 139 | ), |
| 140 | 'save_player_position' => array( |
| 141 | 'type' => 'boolean', |
| 142 | 'default' => false, |
| 143 | ), |
| 144 | 'hide_youtube' => array( |
| 145 | 'type' => 'boolean', |
| 146 | 'default' => false, |
| 147 | ), |
| 148 | 'lazy_load_youtube' => array( |
| 149 | 'type' => 'boolean', |
| 150 | 'default' => false, |
| 151 | ), |
| 152 | 'hide_logo' => array( |
| 153 | 'type' => 'boolean', |
| 154 | 'default' => false, |
| 155 | ), |
| 156 | 'border_radius' => array( |
| 157 | 'type' => 'integer', |
| 158 | 'default' => 0, |
| 159 | ), |
| 160 | 'cta' => array( |
| 161 | 'type' => 'array', |
| 162 | ), |
| 163 | 'watermark' => array( |
| 164 | 'type' => 'array', |
| 165 | ), |
| 166 | 'search' => array( |
| 167 | 'type' => 'array', |
| 168 | ), |
| 169 | 'email_collection' => array( |
| 170 | 'type' => 'array', |
| 171 | ), |
| 172 | 'action_bar' => array( |
| 173 | 'type' => 'array', |
| 174 | ), |
| 175 | 'is_locked' => array( |
| 176 | 'type' => 'boolean', |
| 177 | 'default' => false, |
| 178 | ), |
| 179 | 'created_by' => array( |
| 180 | 'type' => 'integer', |
| 181 | 'default' => get_current_user_id(), |
| 182 | ), |
| 183 | 'created_at' => array( |
| 184 | 'type' => 'string', |
| 185 | ), |
| 186 | 'updated_at' => array( |
| 187 | 'type' => 'string', |
| 188 | 'default' => current_time( 'mysql' ), |
| 189 | ), |
| 190 | 'deleted_at' => array( |
| 191 | 'type' => 'string', |
| 192 | ), |
| 193 | ); |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * These attributes are queryable |
| 198 | * |
| 199 | * @var array |
| 200 | */ |
| 201 | protected $queryable = array( 'slug' ); |
| 202 | |
| 203 | /** |
| 204 | * Get the preset name. |
| 205 | * |
| 206 | * @return string |
| 207 | */ |
| 208 | public function getName() { |
| 209 | $name = $this->name; |
| 210 | return ! empty( $name ) ? (string) $name : ''; |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Create a preset in the db. |
| 215 | * |
| 216 | * @param array $args Preset data. |
| 217 | * @return integer |
| 218 | */ |
| 219 | public function create( $args = array() ) { |
| 220 | // Name is required. |
| 221 | if ( empty( $args['name'] ) ) { |
| 222 | return new \WP_Error( 'missing_parameter', __( 'You must enter a name for the preset.', 'presto-player' ) ); |
| 223 | } |
| 224 | |
| 225 | // Generate slug on the fly. |
| 226 | $args['slug'] = ! empty( $args['slug'] ) ? $args['slug'] : sanitize_title( $args['name'] ); |
| 227 | |
| 228 | // Create. |
| 229 | return parent::create( $args ); |
| 230 | } |
| 231 | } |
| 232 |