PluginProbe ʕ •ᴥ•ʔ
WPFront Scroll Top / 1.3
WPFront Scroll Top v1.3
1.5 1.6 1.6.1 1.6.2 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1 2.1.1 2.2 3.0.0 3.0.1 trunk 1.0 1.0.1 1.1 1.1.1 1.2 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5
wpfront-scroll-top / classes / class-wpfront-scroll-top.php
wpfront-scroll-top / classes Last commit date
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.php
248 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-base.php");
26 require_once("class-wpfront-scroll-top-options.php");
27
28 if (!class_exists('WPFront_Scroll_Top')) {
29
30 /**
31 * Main class of WPFront Scroll Top plugin
32 *
33 * @author Syam Mohan <syam@wpfront.com>
34 * @copyright 2013 WPFront.com
35 */
36 class WPFront_Scroll_Top extends WPFront_Base {
37
38 //Constants
39 const VERSION = '1.3';
40 const OPTIONS_GROUP_NAME = 'wpfront-scroll-top-options-group';
41 const OPTION_NAME = 'wpfront-scroll-top-options';
42 const PLUGIN_SLUG = 'wpfront-scroll-top';
43
44 //Variables
45 protected $iconsDIR;
46 protected $iconsURL;
47 protected $options;
48 protected $markupLoaded;
49 protected $scriptLoaded;
50
51 function __construct() {
52 parent::__construct(__FILE__, self::PLUGIN_SLUG);
53
54 $this->markupLoaded = FALSE;
55
56 //Root variables
57 $this->iconsDIR = $this->pluginDIRRoot . 'images/icons/';
58 $this->iconsURL = $this->pluginURLRoot . 'images/icons/';
59
60 add_action('wp_footer', array(&$this, 'write_markup'));
61 add_action('shutdown', array(&$this, 'write_markup'));
62
63 $this->add_menu($this->__('WPFront Scroll Top'), $this->__('Scroll Top'));
64 }
65
66 //add scripts
67 public function enqueue_scripts() {
68 if ($this->enabled() == FALSE)
69 return;
70
71 $jsRoot = $this->pluginURLRoot . 'js/';
72
73 wp_enqueue_script('jquery');
74 wp_enqueue_script('wpfront-scroll-top', $jsRoot . 'wpfront-scroll-top.js', array('jquery'), self::VERSION);
75
76 $this->scriptLoaded = TRUE;
77 }
78
79 //add styles
80 public function enqueue_styles() {
81 if ($this->enabled() == FALSE)
82 return;
83
84 $cssRoot = $this->pluginURLRoot . 'css/';
85
86 wp_enqueue_style('wpfront-scroll-top', $cssRoot . 'wpfront-scroll-top.css', array(), self::VERSION);
87 }
88
89 public function admin_init() {
90 register_setting(self::OPTIONS_GROUP_NAME, self::OPTION_NAME);
91
92 $this->enqueue_styles();
93 $this->enqueue_scripts();
94 }
95
96 public function enqueue_options_scripts() {
97 $this->enqueue_scripts();
98
99 $jsRoot = $this->pluginURLRoot . 'jquery-plugins/colorpicker/js/';
100 wp_enqueue_script('jquery.eyecon.colorpicker', $jsRoot . 'colorpicker.js', array('jquery'), self::VERSION);
101 }
102
103 //options page styles
104 public function enqueue_options_styles() {
105 $styleRoot = $this->pluginURLRoot . 'jquery-plugins/colorpicker/css/';
106 wp_enqueue_style('jquery.eyecon.colorpicker.colorpicker', $styleRoot . 'colorpicker.css', array(), self::VERSION);
107
108 $styleRoot = $this->pluginURLRoot . 'css/';
109 wp_enqueue_style('wpfront-scroll-top-options', $styleRoot . 'options.css', array(), self::VERSION);
110 }
111
112 public function plugins_loaded() {
113 //load plugin options
114 $this->options = new WPFront_Scroll_Top_Options(self::OPTION_NAME, self::PLUGIN_SLUG);
115 }
116
117 //writes the html and script for the bar
118 public function write_markup() {
119 if ($this->markupLoaded) {
120 return;
121 }
122
123 if ($this->scriptLoaded != TRUE) {
124 return;
125 }
126
127 if (WPFront_Static::doing_ajax()) {
128 return;
129 }
130
131 if ($this->enabled()) {
132 include($this->pluginDIRRoot . 'templates/scroll-top-template.php');
133
134 echo '<script type="text/javascript">';
135 echo 'if(typeof wpfront_scroll_top == "function") ';
136 echo 'wpfront_scroll_top(' . json_encode(array(
137 'scroll_offset' => $this->options->scroll_offset(),
138 'button_width' => $this->options->button_width(),
139 'button_height' => $this->options->button_height(),
140 'button_opacity' => $this->options->button_opacity() / 100,
141 'button_fade_duration' => $this->options->button_fade_duration(),
142 'scroll_duration' => $this->options->scroll_duration(),
143 'location' => $this->options->location(),
144 'marginX' => $this->options->marginX(),
145 'marginY' => $this->options->marginY(),
146 'hide_iframe' => $this->options->hide_iframe(),
147 'auto_hide' => $this->options->auto_hide(),
148 'auto_hide_after' => $this->options->auto_hide_after(),
149 )) . ');';
150 echo '</script>';
151 }
152
153 $this->markupLoaded = TRUE;
154 }
155
156 private function enabled() {
157 if (!$this->options->enabled())
158 return FALSE;
159
160 if ($this->options->hide_wpadmin() && is_admin())
161 return FALSE;
162
163 if(!$this->filter_pages())
164 return FALSE;
165
166 return TRUE;
167 }
168
169 private function filter_pages() {
170 if(is_admin())
171 return TRUE;
172
173 switch ($this->options->display_pages()) {
174 case 1:
175 return TRUE;
176 case 2:
177 case 3:
178 global $post;
179 $ID = FALSE;
180 $type = FALSE;
181 if (is_home()) {
182 $ID = 'home';
183 $type = 1;
184 } elseif (is_singular()) {
185 $post_type = get_post_type();
186 if ($post_type == 'page') {
187 $ID = $post->ID;
188 $type = 1;
189 } elseif ($post_type == 'post') {
190 $ID = $post->ID;
191 $type = 2;
192 }
193 }
194 if ($this->options->display_pages() == 2) {
195 if ($ID !== FALSE && $type !== FALSE) {
196 if (strpos($this->options->include_pages(), $type . '.' . $ID) === FALSE)
197 return FALSE;
198 else
199 return TRUE;
200 }
201 return FALSE;
202 }
203 if ($this->options->display_pages() == 3) {
204 if ($ID !== FALSE && $type !== FALSE) {
205 if (strpos($this->options->exclude_pages(), $type . '.' . $ID) === FALSE)
206 return TRUE;
207 else
208 return FALSE;
209 }
210 return TRUE;
211 }
212 }
213
214 return TRUE;
215 }
216
217 private function image() {
218 if ($this->options->image() == 'custom')
219 return $this->options->custom_url();
220 return $this->iconsURL . $this->options->image();
221 }
222
223 protected function get_filter_objects() {
224 $objects = array();
225
226 $objects['1.home'] = $this->__('[Page]') . ' ' . $this->__('Home');
227
228 $pages = get_pages();
229 foreach ($pages as $page) {
230 $objects['1.' . $page->ID] = $this->__('[Page]') . ' ' . $page->post_title;
231 }
232
233 $posts = get_posts();
234 foreach ($posts as $post) {
235 $objects['2.' . $post->ID] = $this->__('[Post]') . ' ' . $post->post_title;
236 }
237
238 // $categories = get_categories();
239 // foreach ($categories as $category) {
240 // $objects['3.' . $category->cat_ID] = $this->__('[Category]') . ' ' . $category->cat_name;
241 // }
242
243 return $objects;
244 }
245
246 }
247
248 }