base
12 years ago
class-wpfront-scroll-top-options.php
12 years ago
class-wpfront-scroll-top.php
12 years ago
class-wpfront-scroll-top-options.php
126 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 | require_once("base/class-wpfront-options-base.php"); |
| 26 | |
| 27 | if (!class_exists('WPFront_Scroll_Top_Options')) { |
| 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 { |
| 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)->__('Enabled'); |
| 42 | $this->addOption('scroll_offset', 'int', 100, array($this, 'validate_zero_positive'))->__('Scroll Offset'); |
| 43 | $this->addOption('button_width', 'int', 0, array($this, 'validate_zero_positive')); |
| 44 | $this->addOption('button_height', 'int', 0, array($this, 'validate_zero_positive')); |
| 45 | $this->addOption('button_opacity', 'int', 80, array($this, 'validate_range_0_100'))->__('Button Opacity'); |
| 46 | $this->addOption('button_fade_duration', 'int', 200, array($this, 'validate_zero_positive'))->__('Button Fade Duration'); |
| 47 | $this->addOption('scroll_duration', 'int', 400, array($this, 'validate_zero_positive'))->__('Scroll Duration'); |
| 48 | $this->addOption('auto_hide', 'bit', FALSE)->__('Auto Hide'); |
| 49 | $this->addOption('auto_hide_after', 'float', 2, array($this, 'validate_zero_positive'))->__('Auto Hide After'); |
| 50 | $this->addOption('hide_small_device', 'bit', FALSE)->__('Hide on Small Devices'); |
| 51 | $this->addOption('small_device_width', 'int', 640, array($this, 'validate_zero_positive'))->__('Small Device Max Width'); |
| 52 | $this->addOption('hide_small_window', 'bit', FALSE)->__('Hide on Small Window'); |
| 53 | $this->addOption('small_window_width', 'int', 640, array($this, 'validate_zero_positive'))->__('Small Window Max Width'); |
| 54 | $this->addOption('button_style', 'string', 'image', array($this, 'validate_button_style'))->__('Button Style'); |
| 55 | $this->addOption('hide_wpadmin', 'bit', FALSE)->__('Hide on WP-ADMIN'); |
| 56 | $this->addOption('hide_iframe', 'bit', FALSE)->__('Hide on iframes'); |
| 57 | |
| 58 | $this->addOption('location', 'int', 1, array($this, 'validate_range_1_4'))->__('Location'); |
| 59 | $this->addOption('marginX', 'int', 20)->__('Margin X'); |
| 60 | $this->addOption('marginY', 'int', 20)->__('Margin Y'); |
| 61 | |
| 62 | $this->addOption('text_button_text', 'string', '')->__('Text'); |
| 63 | $this->addOption('text_button_text_color', 'string', '#ffffff', array($this, 'validate_color'))->__('Text Color'); |
| 64 | $this->addOption('text_button_background_color', 'string', '#000000', array($this, 'validate_color'))->__('Background Color'); |
| 65 | $this->addOption('text_button_css', 'string', '')->__('Custom CSS'); |
| 66 | |
| 67 | $this->addOption('display_pages', 'int', '1', array($this, 'validate_display_pages'))->__('Display on Pages'); |
| 68 | $this->addOption('include_pages', 'string', ''); |
| 69 | $this->addOption('exclude_pages', 'string', ''); |
| 70 | |
| 71 | $this->addOption('image', 'string', '1.png'); |
| 72 | $this->addOption('custom_url', 'string', ''); |
| 73 | } |
| 74 | |
| 75 | protected function validate_range_0_100($arg) { |
| 76 | if ($arg < 0) |
| 77 | return 0; |
| 78 | |
| 79 | if ($arg > 100) |
| 80 | return 100; |
| 81 | |
| 82 | return $arg; |
| 83 | } |
| 84 | |
| 85 | protected function validate_range_1_4($arg) { |
| 86 | if ($arg < 1) |
| 87 | return 1; |
| 88 | |
| 89 | if ($arg > 4) |
| 90 | return 4; |
| 91 | |
| 92 | return $arg; |
| 93 | } |
| 94 | |
| 95 | protected function validate_button_style($arg) { |
| 96 | if ($arg == 'text') |
| 97 | return $arg; |
| 98 | |
| 99 | return 'image'; |
| 100 | } |
| 101 | |
| 102 | protected function validate_color($arg) { |
| 103 | if (strlen($arg) != 7) |
| 104 | return '#ffffff'; |
| 105 | |
| 106 | if (strpos($arg, '#') != 0) |
| 107 | return '#ffffff'; |
| 108 | |
| 109 | return $arg; |
| 110 | } |
| 111 | |
| 112 | protected function validate_display_pages($arg) { |
| 113 | if ($arg < 1) { |
| 114 | return 1; |
| 115 | } |
| 116 | |
| 117 | if ($arg > 3) { |
| 118 | return 3; |
| 119 | } |
| 120 | |
| 121 | return $arg; |
| 122 | } |
| 123 | |
| 124 | } |
| 125 | |
| 126 | } |