base
8 years ago
class-wpfront-scroll-top-options.php
8 years ago
class-wpfront-scroll-top.php
8 years ago
class-wpfront-scroll-top-options.php
193 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | WPFront Scroll Top Plugin |
| 5 | Copyright (C) 2013, WPFront.com |
| 6 | Website: wpfront.com |
| 7 | Contact: syam@wpfront.com |
| 8 | |
| 9 | WPFront Scroll Top Plugin is distributed under the GNU General Public License, Version 3, |
| 10 | June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin |
| 11 | St, Fifth Floor, Boston, MA 02110, USA |
| 12 | |
| 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 17 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 | */ |
| 24 | |
| 25 | namespace WPFront\Scroll_Top; |
| 26 | |
| 27 | require_once("base/class-wpfront-options-base.php"); |
| 28 | |
| 29 | /** |
| 30 | * Options class for WPFront Scroll Top plugin |
| 31 | * |
| 32 | * @author Syam Mohan <syam@wpfront.com> |
| 33 | * @copyright 2013 WPFront.com |
| 34 | */ |
| 35 | class WPFront_Scroll_Top_Options extends WPFront_Options_Base_ST { |
| 36 | |
| 37 | function __construct($optionName, $pluginSlug) { |
| 38 | parent::__construct($optionName, $pluginSlug); |
| 39 | |
| 40 | //add the options required for this plugin |
| 41 | $this->addOption('enabled', 'bit', FALSE)->label(__('Enabled', 'wpfront-scroll-top')); |
| 42 | $this->addOption('javascript_async', 'bit', FALSE)->label(__('JavaScript Async', 'wpfront-scroll-top')); |
| 43 | $this->addOption('scroll_offset', 'int', 100, array($this, 'validate_zero_positive'))->label(__('Scroll Offset', 'wpfront-scroll-top')); |
| 44 | $this->addOption('button_width', 'int', 0, array($this, 'validate_zero_positive')); |
| 45 | $this->addOption('button_height', 'int', 0, array($this, 'validate_zero_positive')); |
| 46 | $this->addOption('button_opacity', 'int', 80, array($this, 'validate_range_0_100'))->label(__('Button Opacity', 'wpfront-scroll-top')); |
| 47 | $this->addOption('button_fade_duration', 'int', 200, array($this, 'validate_zero_positive'))->label(__('Button Fade Duration', 'wpfront-scroll-top')); |
| 48 | $this->addOption('scroll_duration', 'int', 400, array($this, 'validate_zero_positive'))->label(__('Scroll Duration', 'wpfront-scroll-top')); |
| 49 | $this->addOption('auto_hide', 'bit', FALSE)->label(__('Auto Hide', 'wpfront-scroll-top')); |
| 50 | $this->addOption('auto_hide_after', 'float', 2, array($this, 'validate_zero_positive'))->label(__('Auto Hide After', 'wpfront-scroll-top')); |
| 51 | $this->addOption('hide_small_device', 'bit', FALSE)->label(__('Hide on Small Devices', 'wpfront-scroll-top')); |
| 52 | $this->addOption('small_device_width', 'int', 640, array($this, 'validate_zero_positive'))->label(__('Small Device Max Width', 'wpfront-scroll-top')); |
| 53 | $this->addOption('hide_small_window', 'bit', FALSE)->label(__('Hide on Small Window', 'wpfront-scroll-top')); |
| 54 | $this->addOption('small_window_width', 'int', 640, array($this, 'validate_zero_positive'))->label(__('Small Window Max Width', 'wpfront-scroll-top')); |
| 55 | $this->addOption('button_style', 'string', 'image', array($this, 'validate_button_style'))->label(__('Button Style', 'wpfront-scroll-top')); |
| 56 | $this->addOption('image_alt', 'string', '')->label(__('Image ALT', 'wpfront-scroll-top')); |
| 57 | $this->addOption('hide_wpadmin', 'bit', FALSE)->label(__('Hide on WP-ADMIN', 'wpfront-scroll-top')); |
| 58 | $this->addOption('hide_iframe', 'bit', FALSE)->label(__('Hide on iframes', 'wpfront-scroll-top')); |
| 59 | |
| 60 | $this->addOption('button_action', 'string', 'top', array($this, 'validate_button_action'))->label(__('Button Action', 'wpfront-scroll-top')); |
| 61 | $this->addOption('button_action_page_url', 'string', '')->label(__('Page URL', 'wpfront-scroll-top')); |
| 62 | $this->addOption('button_action_element_selector', 'string', '')->label(__('Element CSS Selector', 'wpfront-scroll-top')); |
| 63 | $this->addOption('button_action_container_selector', 'string', 'html, body', array($this, 'button_action_container_selector'))->label(__('Scroll Container CSS Selector', 'wpfront-scroll-top')); |
| 64 | $this->addOption('button_action_element_offset', 'int', 0)->label(__('Offset', 'wpfront-scroll-top')); |
| 65 | |
| 66 | $this->addOption('location', 'int', 1, array($this, 'validate_range_1_4'))->label(__('Location', 'wpfront-scroll-top')); |
| 67 | $this->addOption('marginX', 'int', 20)->label(__('Margin X', 'wpfront-scroll-top')); |
| 68 | $this->addOption('marginY', 'int', 20)->label(__('Margin Y', 'wpfront-scroll-top')); |
| 69 | |
| 70 | $this->addOption('text_button_text', 'string', '')->label(__('Text', 'wpfront-scroll-top')); |
| 71 | $this->addOption('text_button_text_color', 'string', '#ffffff', array($this, 'validate_color'))->label(__('Text Color', 'wpfront-scroll-top')); |
| 72 | $this->addOption('text_button_background_color', 'string', '#000000', array($this, 'validate_color'))->label(__('Background Color', 'wpfront-scroll-top')); |
| 73 | $this->addOption('text_button_hover_color', 'string', '', array($this, 'validate_color'))->label(__('Mouse Over Color', 'wpfront-scroll-top')); |
| 74 | $this->addOption('text_button_css', 'string', '')->label(__('Custom CSS', 'wpfront-scroll-top')); |
| 75 | |
| 76 | $this->addOption('fa_button_class', 'string', '')->label(__('Icon Class', 'wpfront-scroll-top')); |
| 77 | $this->addOption('fa_button_URL', 'string', '')->label(__('Font Awesome URL', 'wpfront-scroll-top')); |
| 78 | $this->addOption('fa_button_exclude_URL', 'bit', FALSE)->label(__('Do not include URL', 'wpfront-scroll-top')); |
| 79 | $this->addOption('fa_button_text_color', 'string', '#000000', array($this, 'validate_color'))->label(__('Icon Color', 'wpfront-scroll-top')); |
| 80 | $this->addOption('fa_button_css', 'string', '')->label(__('Custom CSS', 'wpfront-scroll-top')); |
| 81 | |
| 82 | $this->addOption('display_pages', 'int', '1', array($this, 'validate_display_pages'))->label(__('Display on Pages', 'wpfront-scroll-top')); |
| 83 | $this->addOption('include_pages', 'string', ''); |
| 84 | $this->addOption('exclude_pages', 'string', ''); |
| 85 | |
| 86 | $this->addOption('image', 'string', '1.png'); |
| 87 | $this->addOption('custom_url', 'string', ''); |
| 88 | } |
| 89 | |
| 90 | public function text_button_hover_color() { |
| 91 | $color = parent::text_button_hover_color(); |
| 92 | if(empty($color)) |
| 93 | return $this->text_button_background_color(); |
| 94 | |
| 95 | return $color; |
| 96 | } |
| 97 | |
| 98 | public function include_pages() { |
| 99 | $pages = parent::include_pages(); |
| 100 | |
| 101 | if(strpos($pages, '.') === FALSE) |
| 102 | return $pages; |
| 103 | |
| 104 | $pages = explode(',', $pages); |
| 105 | |
| 106 | for($i = 0; $i < count($pages); $i++) { |
| 107 | $e = explode('.', $pages[$i]); |
| 108 | $pages[$i] = $e[1]; |
| 109 | } |
| 110 | |
| 111 | return implode(',', $pages); |
| 112 | } |
| 113 | |
| 114 | public function exclude_pages() { |
| 115 | $pages = parent::exclude_pages(); |
| 116 | |
| 117 | if(strpos($pages, '.') === FALSE) |
| 118 | return $pages; |
| 119 | |
| 120 | $pages = explode(',', $pages); |
| 121 | |
| 122 | for($i = 0; $i < count($pages); $i++) { |
| 123 | $e = explode('.', $pages[$i]); |
| 124 | $pages[$i] = $e[1]; |
| 125 | } |
| 126 | |
| 127 | return implode(',', $pages); |
| 128 | } |
| 129 | |
| 130 | protected function validate_range_0_100($arg) { |
| 131 | if ($arg < 0) |
| 132 | return 0; |
| 133 | |
| 134 | if ($arg > 100) |
| 135 | return 100; |
| 136 | |
| 137 | return $arg; |
| 138 | } |
| 139 | |
| 140 | protected function validate_range_1_4($arg) { |
| 141 | if ($arg < 1) |
| 142 | return 1; |
| 143 | |
| 144 | if ($arg > 4) |
| 145 | return 4; |
| 146 | |
| 147 | return $arg; |
| 148 | } |
| 149 | |
| 150 | protected function validate_button_style($arg) { |
| 151 | if ($arg == 'text' || $arg == 'font-awesome') |
| 152 | return $arg; |
| 153 | |
| 154 | return 'image'; |
| 155 | } |
| 156 | |
| 157 | protected function validate_button_action($arg) { |
| 158 | if ($arg == 'element' || $arg == 'url') |
| 159 | return $arg; |
| 160 | |
| 161 | return 'top'; |
| 162 | } |
| 163 | |
| 164 | protected function validate_color($arg) { |
| 165 | if (strlen($arg) != 7) |
| 166 | return '#ffffff'; |
| 167 | |
| 168 | if (strpos($arg, '#') != 0) |
| 169 | return '#ffffff'; |
| 170 | |
| 171 | return $arg; |
| 172 | } |
| 173 | |
| 174 | protected function validate_display_pages($arg) { |
| 175 | if ($arg < 1) { |
| 176 | return 1; |
| 177 | } |
| 178 | |
| 179 | if ($arg > 3) { |
| 180 | return 3; |
| 181 | } |
| 182 | |
| 183 | return $arg; |
| 184 | } |
| 185 | |
| 186 | protected function button_action_container_selector($args) { |
| 187 | if(trim($args) === "") |
| 188 | return "html, body"; |
| 189 | |
| 190 | return $args; |
| 191 | } |
| 192 | |
| 193 | } |