80ada540 |
1 | <?php\r |
2 | /*\r |
3 | Plugin Name: danixland User Panel\r |
4 | Plugin URI: http://danixland.net/blog/2010/603-danixland-user-panel-plugin/\r |
5 | Description: A modified version of the meta widget which gives more info about the user.\r |
6 | Version: 1.4.2\r |
7 | Author: Danilo 'danix' Macri\r |
8 | Author URI: http://danixland.net\r |
9 | Text Domain: dnxup\r |
10 | \r |
11 | This program is distributed in the hope that it will be useful,\r |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of\r |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r |
14 | */\r |
15 | \r |
16 | /**************************************************************************************\r |
17 | Since Version 1.1.1 this plugin uses some code and inspiration from the sidebar-login\r |
18 | plugin by Mike Jolley < http://blue-anvil.com > < http://mikejolley.com >\r |
19 | big kudos to him!!!\r |
20 | **************************************************************************************/\r |
21 | \r |
22 | /**\r |
23 | * Add plugin i18n domain: dnxup\r |
24 | * @since 1.1.1\r |
25 | */\r |
26 | load_plugin_textdomain('dnxup', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');\r |
27 | \r |
28 | /**\r |
29 | * Include settings options for our plugin\r |
30 | * @since 1.1.1\r |
31 | */\r |
32 | function dnxup_settings() {\r |
33 | add_options_page('danixland User Panel Settings', __('User Panel Options', 'dnxup'), 'manage_options', 'dnxup_options', 'dnxup_settings_display');\r |
34 | }\r |
35 | add_action('admin_menu', 'dnxup_settings' );\r |
36 | \r |
37 | /**\r |
38 | * The function that outputs our admin page\r |
39 | * @since 1.1.1\r |
40 | */\r |
41 | function dnxup_settings_display() {\r |
42 | ?>\r |
43 | <div class="wrap">\r |
44 | <h2><?php _e('danixland User Panel Settings', 'dnxup') ?></h2>\r |
45 | <form method="post" action="options.php">\r |
46 | <?php\r |
47 | settings_fields('dnxup_options');\r |
48 | do_settings_sections('dnxup_settings_sections');\r |
49 | ?>\r |
50 | <p class="submit">\r |
51 | <input name="dnxup_options[submit]" type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes', 'dnxup') ?>" />\r |
52 | <input name="dnxup_options[reset]" type="submit" class="button-secondary" value="<?php esc_attr_e('Reset Defaults', 'dnxup'); ?>" />\r |
53 | </p>\r |
54 | </form>\r |
55 | </div>\r |
56 | <?php\r |
57 | }\r |
58 | \r |
59 | /**\r |
60 | * Settings API options initilization and validation\r |
61 | * @since 1.1.1\r |
62 | */\r |
63 | function dnxup_register_options() {\r |
64 | require( dirname( __FILE__ ) . '/include/options-register.php' );\r |
65 | }\r |
66 | add_action('admin_init', 'dnxup_register_options');\r |
67 | \r |
68 | /**\r |
69 | * DataBase initilization and update procedure\r |
70 | * @since 1.1.2\r |
71 | */\r |
72 | \r |
73 | // helper function that returns DB defaults\r |
74 | function dnxup_db_defaults() {\r |
75 | $defaults = array(\r |
76 | 'show_gravatar' => true,\r |
77 | 'logged_out_heading' => 'Howdy Guest',\r |
78 | 'logged_in_heading' => 'Howdy %username%',\r |
79 | 'logged_in_links' => "<a href=\"" . admin_url() . "\">" . __('Dashboard','dnxup') . "</a>\n<a href=\"" . admin_url('profile.php') . "\">" . __('Profile','dnxup') . "</a>",\r |
80 | // database version\r |
81 | 'dnxup_DB_VERSION' => '1'\r |
82 | );\r |
83 | return $defaults;\r |
84 | }\r |
85 | \r |
86 | // helper function that starts up the DB\r |
87 | function dnxup_db_init() {\r |
88 | global $dnxup_options;\r |
89 | $dnxup_options = get_option('dnxup_options');\r |
90 | if( false === $dnxup_options ) {\r |
91 | $dnxup_options = dnxup_db_defaults();\r |
92 | }\r |
93 | update_option('dnxup_options', $dnxup_options);\r |
94 | }\r |
95 | \r |
96 | // helper function that performs a DB version update when needed\r |
97 | function dnxup_db_update($db_version) {\r |
98 | global $dnxup_options;\r |
99 | $db_defaults = dnxup_db_defaults();\r |
100 | $merge = wp_parse_args( $dnxup_options, $db_defaults );\r |
101 | // update DB version\r |
102 | $merge['dnxup_DB_VERSION'] = $db_version;\r |
103 | update_option('dnxup_options', $merge);\r |
104 | }\r |
105 | \r |
106 | // helper function that performs a DB check and then an init/update action\r |
107 | function dnxup_db_check() {\r |
108 | global $dnxup_options;\r |
109 | if(false === $dnxup_options) {\r |
110 | dnxup_db_init();\r |
111 | }\r |
112 | $old_db_version = $dnxup_options['dnxup_DB_VERSION'];\r |
113 | $new_db_version = DNXUP_CURRENT_DB_VERSION;\r |
114 | if(empty($old_db_version)) {\r |
115 | dnxup_db_init();\r |
116 | }\r |
117 | if( intval($old_db_version) < intval($new_db_version) ) {\r |
118 | dnxup_db_update( $new_db_version );\r |
119 | }\r |
120 | }\r |
121 | function dnxup_set_db_version() {\r |
122 | // Define plugin database version. This should only change when new settings are added.\r |
123 | if ( ! defined( 'DNXUP_CURRENT_DB_VERSION' ) ) {\r |
124 | define( 'DNXUP_CURRENT_DB_VERSION', 2 );\r |
125 | }\r |
126 | }\r |
127 | /**\r |
128 | * Add function on plugin activation that'll set our DB version and perform a check for update\r |
129 | * @since 1.1.3\r |
130 | */\r |
131 | register_activation_hook( __FILE__, 'dnxup_set_db_version' );\r |
132 | register_activation_hook( __FILE__, 'dnxup_db_check' );\r |
133 | \r |
134 | \r |
135 | /**\r |
136 | * function that returns the actual url for redirection after logout\r |
137 | * as seen on sidebar-login by Mike Jolley with small modifications\r |
138 | * @since 1.1.3\r |
139 | */\r |
140 | function dnxup_current_url($url = '') {\r |
141 | \r |
142 | global $wpdb, $post, $cat, $tag, $author, $year, $monthnum, $day, $wp_query;\r |
143 | $pageURL = "";\r |
144 | \r |
145 | if ( is_home() && $wp_query->is_posts_page==1)\r |
146 | {\r |
147 | $pageURL = get_permalink(get_option('page_for_posts'));\r |
148 | }\r |
149 | elseif (is_home() || is_front_page())\r |
150 | {\r |
151 | $pageURL = get_bloginfo('url');\r |
152 | }\r |
153 | elseif (is_post_type_archive())\r |
154 | {\r |
155 | $pageURL = get_post_type_archive_link( get_query_var('post_type') );\r |
156 | }\r |
157 | elseif (is_single() || is_page())\r |
158 | {\r |
159 | $pageURL = get_permalink($wp_query->post->ID);\r |
160 | }\r |
161 | elseif (is_category())\r |
162 | {\r |
163 | $pageURL = get_category_link($cat);\r |
164 | }\r |
165 | elseif (is_tag())\r |
166 | {\r |
167 | $tag_id = $wpdb->get_var("SELECT ".$wpdb->terms.".term_id FROM $wpdb->term_taxonomy\r |
168 | LEFT JOIN $wpdb->terms\r |
169 | ON (".$wpdb->term_taxonomy.".term_id = ".$wpdb->terms.".term_id)\r |
170 | WHERE ".$wpdb->terms.".slug = '$tag'\r |
171 | AND ".$wpdb->term_taxonomy.".taxonomy = 'post_tag' LIMIT 1");\r |
172 | $pageURL = get_tag_link($tag_id);\r |
173 | }\r |
174 | elseif (is_author())\r |
175 | {\r |
176 | $pageURL = get_author_posts_url($author);\r |
177 | }\r |
178 | elseif (is_date())\r |
179 | {\r |
180 | \r |
181 | if ($day)\r |
182 | {\r |
183 | $pageURL = get_day_link( $year, $monthnum, $day);\r |
184 | }\r |
185 | elseif ($monthnum)\r |
186 | {\r |
187 | $pageURL = get_month_link( $year, $monthnum, $day);\r |
188 | }\r |
189 | elseif ($year)\r |
190 | {\r |
191 | $pageURL = get_year_link( $year, $monthnum, $day);\r |
192 | }\r |
193 | \r |
194 | }\r |
195 | elseif (is_search())\r |
196 | {\r |
197 | $pageURL = get_bloginfo('wpurl');\r |
198 | if ("/" != substr($pageURL, -1)) $pageURL = $pageURL . "/";\r |
199 | $pageURL .= '?s='.stripslashes(strip_tags($_REQUEST['s'])).'';\r |
200 | }\r |
201 | \r |
202 | if (!$pageURL || $pageURL=="" || !is_string($pageURL)) {\r |
203 | $pageURL = "";\r |
204 | $pageURL = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';\r |
205 | \r |
206 | if ($_SERVER["SERVER_PORT"] != "80") {\r |
207 | $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];\r |
208 | } else {\r |
209 | $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];\r |
210 | }\r |
211 | \r |
212 | //————–added by mick\r |
213 | if (!strstr(get_bloginfo('url'),'www.')) $pageURL = str_replace('www.','', $pageURL );\r |
214 | //——————–\r |
215 | }\r |
216 | if ($pageURL && !is_search()) if ("/" != substr($pageURL, -1)) $pageURL = $pageURL . "/";\r |
217 | \r |
218 | \r |
219 | return $pageURL;\r |
220 | }\r |
221 | \r |
222 | /**\r |
223 | * Add function to widgets_init that'll load our widget.\r |
224 | * @since 0.1\r |
225 | */\r |
226 | add_action( 'widgets_init', 'danixland_user_panel' );\r |
227 | \r |
228 | /**\r |
229 | * Register our widget.\r |
230 | * 'User_Panel' is the widget class used below.\r |
231 | *\r |
232 | * @since 0.1\r |
233 | */\r |
234 | function danixland_user_panel() {\r |
235 | register_widget( 'User_Panel' );\r |
236 | }\r |
237 | \r |
238 | /**\r |
239 | * User_Panel class.\r |
240 | * This class handles everything that needs to be handled with the widget:\r |
241 | * the settings, form, display, and update. Nice!\r |
242 | *\r |
243 | * @since 0.1\r |
244 | */\r |
245 | class User_Panel extends WP_Widget {\r |
246 | \r |
247 | /**\r |
248 | * Widget setup.\r |
249 | */\r |
250 | function __construct() {\r |
251 | parent::__construct(\r |
252 | 'dnx-user-panel', // id_base\r |
253 | __('danixland User Panel', 'dnxup' ), // Name\r |
254 | array( 'description' => __('An improved version of the meta widget', 'dnxup') )\r |
255 | );\r |
256 | }\r |
257 | \r |
258 | /**\r |
259 | * How to display the widget on the public side of the site.\r |
260 | */\r |
261 | public function widget( $args, $instance ) {\r |
262 | extract( $args );\r |
263 | global $user_ID, $current_user;\r |
264 | $dnxup_options = get_option('dnxup_options');\r |
265 | extract( $dnxup_options );\r |
266 | \r |
267 | // Let's use our title\r |
268 | if($user_ID != '') { // if user is logged in let's greet him good\r |
269 | $current_user = wp_get_current_user();\r |
270 | if( '' != $logged_in_heading ) {\r |
271 | $title = apply_filters('widget_title', str_replace('%username%',ucwords($current_user->display_name),$logged_in_heading));\r |
272 | } else {\r |
273 | $title = false;\r |
274 | }\r |
275 | } else { // user is not logged in, let's treat him as a guest\r |
276 | if( '' != $logged_out_heading ) {\r |
277 | $title = apply_filters('widget_title', str_replace('%username%',ucwords($current_user->display_name),$logged_out_heading));\r |
278 | } else {\r |
279 | $title = false;\r |
280 | }\r |
281 | }\r |
282 | \r |
283 | \r |
284 | /* Before widget (defined by themes). */\r |
285 | echo $before_widget;\r |
286 | \r |
287 | /* Display the widget title if one was input (before and after defined by themes). */\r |
288 | if ( $title )\r |
289 | echo $before_title . $title . $after_title;\r |
290 | \r |
291 | /**\r |
292 | * if user is logged in to your site\r |
293 | * @since 0.8\r |
294 | */\r |
295 | if( $user_ID != '' ) {\r |
296 | /* If show_gravatar was selected, show the User's Gravatar. */\r |
297 | if ( $show_gravatar ) {\r |
298 | echo get_avatar($user_ID, 75);\r |
299 | }\r |
300 | echo '<ul id="dnxup_login_links" class="user_logged_in">';\r |
301 | echo '<li id="dashboard"><a href="' . get_bloginfo('url') . '/wp-admin/">' . __('Dashboard', 'dnxup') . '</a></li>';\r |
302 | echo '<li id="profile"><a href="' . get_bloginfo('url') . '/wp-admin/profile.php">' . __('Profile and personal options', 'dnxup') . '</a></li>';\r |
303 | \r |
304 | /**\r |
305 | * custom links functionality\r |
306 | * @since 1.1.4\r |
307 | */\r |
308 | $links = do_shortcode(trim($logged_in_links));\r |
309 | $links = explode("\n", $links);\r |
310 | if (sizeof($links)>0) {\r |
311 | foreach ($links as $l) {\r |
312 | $l = trim($l);\r |
313 | if (!empty($l)) {\r |
314 | $link = explode('|',$l);\r |
315 | if (isset($link[1])) {\r |
316 | $cap = strtolower(trim($link[1]));\r |
317 | if ($cap=='true') {\r |
318 | if (!current_user_can( 'manage_options' )) continue;\r |
319 | } else {\r |
320 | if (!current_user_can( $cap )) continue;\r |
321 | }\r |
322 | }\r |
323 | // Parse %USERNAME%\r |
324 | $link[0] = str_replace('%USERNAME%',$current_user->user_login,$link[0]);\r |
325 | $link[0] = str_replace('%username%',$current_user->user_login,$link[0]);\r |
326 | // Parse %USERID%\r |
327 | $link[0] = str_replace('%USERID%',$current_user->ID,$link[0]);\r |
328 | $link[0] = str_replace('%userid%',$current_user->ID,$link[0]);\r |
329 | echo '<li class="dnxup_custom_link">'.$link[0].'</li>';\r |
330 | }\r |
331 | }\r |
332 | }\r |
333 | \r |
334 | echo('<li id="logout"><a href="' . wp_logout_url( dnxup_current_url() ) . '">' . __('Exit', 'dnxup') . '</a></li>');\r |
335 | echo '</ul>';\r |
336 | /**\r |
337 | * else if user is logged out and registration is disabled\r |
338 | * @since 0.8\r |
339 | */\r |
340 | } else {\r |
341 | if( ! get_option('users_can_register') ) {\r |
342 | echo '<ul id="dnxup_login_links" class="logged_out_noreg">';\r |
343 | echo '<li id="login"><a href="' . wp_login_url( dnxup_current_url() ) . '">' . __('Login', 'dnxup') . '</a></li>';\r |
344 | echo '<li id="lostpassword"><a href="' . wp_lostpassword_url( dnxup_current_url() ) . '">' . __('Forgot your password?', 'dnxup') . '</a></li>';\r |
345 | echo '</ul>';\r |
346 | /**\r |
347 | * or if user is still logged out but user registration is enabled\r |
348 | * @since 0.9\r |
349 | */\r |
350 | } else {\r |
351 | echo '<ul id="dnxup_login_links" class="logged_out_yesreg">';\r |
352 | echo '<li id="register"><a href="' . get_option('siteurl') . '/wp-register.php">' . __('Register', 'dnxup') . '</a></li>';\r |
353 | echo '<li id="login"><a href="' . wp_login_url( dnxup_current_url() ) . '">' . __('Login', 'dnxup') . '</a></li>';\r |
354 | echo '<li id="lostpassword"><a href="' . wp_lostpassword_url( dnxup_current_url() ) . '">' . __('Forgot your password?', 'dnxup') . '</a></li>';\r |
355 | echo '</ul>';\r |
356 | }\r |
357 | }\r |
358 | /* After widget (defined by themes). */\r |
359 | echo $after_widget;\r |
360 | }\r |
361 | \r |
362 | /**\r |
363 | * Displays just a quick notice with a link to the Settings page\r |
364 | */\r |
365 | public function form( $instance ) {\r |
366 | ?>\r |
367 | \r |
368 | <!-- No settings here, -->\r |
369 | <p>\r |
370 | <?php echo sprintf( __('Nothing to set here, already had a look at the <a href="%1$s">Settings Page</a>?', 'dnxup'),\r |
371 | admin_url('options-general.php?page=dnxup_options')\r |
372 | ); ?>\r |
373 | </p>\r |
374 | <?php\r |
375 | }\r |
376 | }\r |
377 | \r |
378 | ?>\r |