| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* SOFTWARE LICENSE INFORMATION |
| 5 |
* |
| 6 |
* Copyright (c) 2017 Buttonizer, all rights reserved. |
| 7 |
* |
| 8 |
* This file is part of Buttonizer |
| 9 |
* |
| 10 |
* For detailed information regarding to the licensing of |
| 11 |
* this software, please review the license.txt or visit: |
| 12 |
* https://buttonizer.pro/license/ |
| 13 |
*/ |
| 14 |
namespace Buttonizer\Legacy\Frontend\Group\Button; |
| 15 |
|
| 16 |
use Buttonizer\Legacy\Frontend\Buttonizer; |
| 17 |
class Button { |
| 18 |
private $groupObject; |
| 19 |
|
| 20 |
private $data; |
| 21 |
|
| 22 |
// private $styling = StylingObject; |
| 23 |
/** |
| 24 |
* Buttons constructor. |
| 25 |
* @param $groupObject |
| 26 |
* @param $data |
| 27 |
*/ |
| 28 |
public function __construct( $groupObject, $data ) { |
| 29 |
$this->groupObject = $groupObject; |
| 30 |
$this->data = $data; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Return option data |
| 35 |
* |
| 36 |
* @param $key |
| 37 |
* @param $default null |
| 38 |
* @return string |
| 39 |
*/ |
| 40 |
private function getOption( $key, $default = '' ) { |
| 41 |
return ( isset( $this->data[$key] ) ? $this->data[$key] : $default ); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Return option data as boolean |
| 46 |
* |
| 47 |
* @param $key |
| 48 |
* @param $default false |
| 49 |
* @return boolean |
| 50 |
*/ |
| 51 |
public function getBoolean( $key, $default = false ) { |
| 52 |
return ( isset( $this->data[$key] ) ? filter_var( $this->data[$key], FILTER_VALIDATE_BOOLEAN, [ |
| 53 |
'options' => [ |
| 54 |
'default' => false, |
| 55 |
], |
| 56 |
] ) === true : $default ); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* @param $key |
| 61 |
* @param $value |
| 62 |
* @return bool |
| 63 |
*/ |
| 64 |
public function setOption( $key, $value ) { |
| 65 |
$this->data[$key] = $value; |
| 66 |
return true; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Show buttons, based on their settings |
| 71 |
* @return bool |
| 72 |
*/ |
| 73 |
public function showButton() { |
| 74 |
// Button not in use |
| 75 |
if ( !$this->getBoolean( "show_desktop" ) && !$this->getBoolean( "show_mobile" ) ) { |
| 76 |
Buttonizer::addEvent( [ |
| 77 |
"id" => $this->getOption( 'id', null ), |
| 78 |
"group_id" => $this->groupObject->getId(), |
| 79 |
"name" => $this->getOption( 'name', "Unnamed" ), |
| 80 |
"button_type" => "button", |
| 81 |
"message" => __( 'The button is hidden on all devices', 'buttonizer-multifunctional-button' ), |
| 82 |
"type" => "all_devices_hidden", |
| 83 |
] ); |
| 84 |
return false; |
| 85 |
} |
| 86 |
return true; |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* @return array |
| 91 |
*/ |
| 92 |
public function generate() { |
| 93 |
// Action is a link to a page |
| 94 |
if ( $this->getOption( 'type', 'url' ) === "page" ) { |
| 95 |
$pageUrl = get_page_link( $this->getOption( 'action', 0 ) ); |
| 96 |
$this->data['action'] = ( $pageUrl ? $pageUrl : "" ); |
| 97 |
} |
| 98 |
// Return data |
| 99 |
return $this->data; |
| 100 |
} |
| 101 |
|
| 102 |
} |
| 103 |
|