Alessio Caiazza is sharing code with you

Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.

Don't show this again

nolith / About Me http://abisso.org/index.php/projects/about-me/

Put in a widget all your social network links with this amazing Worpress plugin ;) (based on social-link http://blog.maybe5.com/?page_id=94)

Clone this repository (size: 313.2 KB): HTTPS / SSH
hg clone https://bitbucket.org/nolith/about-me
hg clone ssh://hg@bitbucket.org/nolith/about-me

About Me / aboutme.php

commit
6f118e1bf4fc
parent
79ea819c55c6
branch
default
tags
1.0.3

NEW:disqus support. closes #4

1
d0811661659f
<?php
2
d0811661659f
/*
3
d0811661659f
Plugin Name: About Me
4
d0811661659f
Plugin URI: http://abisso.org/index.php/projects/about-me/
5
d0811661659f
Description: About Me is a sidebar widget that displays icon links to your profile pages on other social networking sites. Forked from <a href="http://blog.maybe5.com/?page_id=94">Social Links</a>
6
d0811661659f
Author: Alessio Caiazza
7
6f118e1bf4fc
Version: 1.0.3
8
d0811661659f
Author URI: http://alessiocaiazza.info
9
d0811661659f
10
d0811661659f
/*  Social Links Copyright 2008  Kareem Sultan  (email : kareemsultan@gmail.com) */
11
d0811661659f
/*
12
d0811661659f
	(c) 2009 Alessio Caiazza
13
d0811661659f
This program is free software; you can redistribute it and/or modify
14
d0811661659f
it under the terms of the GNU General Public License as published by
15
d0811661659f
the Free Software Foundation; either version 2 of the License, or
16
d0811661659f
(at your option) any later version.
17
d0811661659f
18
d0811661659f
This program is distributed in the hope that it will be useful,
19
d0811661659f
but WITHOUT ANY WARRANTY; without even the implied warranty of
20
d0811661659f
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
d0811661659f
GNU General Public License for more details.
22
d0811661659f
23
d0811661659f
You should have received a copy of the GNU General Public License
24
d0811661659f
along with this program; if not, write to the Free Software
25
d0811661659f
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
26
d0811661659f
27
d0811661659f
http://www.gnu.org/licenses/gpl.txt
28
d0811661659f
29
d0811661659f
*/
30
d0811661659f
31
d0811661659f
//call install function upon activation
32
6536221ffa83
register_activation_hook(__FILE__,'social_links_install');
33
6536221ffa83
34
d0811661659f
//TO DO use these definitions instead
35
6f118e1bf4fc
define('SOCIAL_LINKS_VERSION', '1.0.3');
36
d0811661659f
define('SOCIAL_LINKS_DB_VERSION', '1.1');
37
d0811661659f
38
d0811661659f
define('KEY_SITE_ID',0);
39
d0811661659f
define('KEY_IMAGE',1);
40
d0811661659f
define('KEY_URL_TEMPLATE',2);
41
d0811661659f
define('KEY_INSTRUCTION',3);
42
d0811661659f
define('KEY_DISPLAY_NAME',4);
43
d0811661659f
  
44
6536221ffa83
//$sl_db_version = "1.0";
45
6536221ffa83
$plugindir = get_settings('home').'/wp-content/plugins/'.dirname(plugin_basename(__FILE__));
46
6536221ffa83
$pluginrelativedir = '/wp-content/plugins/'.dirname(plugin_basename(__FILE__));
47
d0811661659f
48
6536221ffa83
$definitions = array(
49
6536221ffa83
	array(0,'facebook.png','%userid%','Enter your complete Facebook profile URL','Facebook'),
50
6536221ffa83
	array(1,'myspace.png','%userid%','Enter your complete MySpace URL.','MySpace'),
51
6536221ffa83
	array(2,'linkedin.png','%userid%','Enter your complete LinkedIn URL.','LinkedIn'),
52
6536221ffa83
	array(3,'picasa.png','http://picasaweb.google.com/%userid%','Enter your Picasa(Google) username.','Picasa Web Album'),
53
6536221ffa83
	array(4,'flickr.png','http://flickr.com/photos/%userid%','Enter your flickr username','Flickr'),
54
6536221ffa83
	array(5,'youtube.png','http://www.youtube.com/%userid%','Enter your YouTube username','YouTube'),
55
6536221ffa83
	array(6,'twitter.png','http://twitter.com/%userid%','Enter your Twitter username','Twitter'),
56
6536221ffa83
	array(7,'pownce.png','http://pownce.com/%userid%','Enter your Pownce username','Pownce'),
57
6536221ffa83
	array(8,'plurk.png','http://www.plurk.com/user/%userid%','Enter your Plurk username','Plurk'),
58
6536221ffa83
	array(9,'digg.png','http://www.digg.com/users/%userid%','Enter your Digg username.','Digg'),
59
6536221ffa83
	array(10,'delicious.png','http://delicious.com/%userid%','Enter your Delicious username','Delicious'),
60
6536221ffa83
	array(11,'blogmarks.png','http://blogmarks.net/user/%userid%','Enter your BlogMarks username.','BlogMarks'),
61
6536221ffa83
	array(12,'stumbleupon.png','http://%userid%.stumbleupon.com','Enter your Stumble Upon username','Stumble Upon'),
62
6536221ffa83
	array(13,'lastfm.png','http://www.last.fm/user/%userid%','Enter your Last.fm username','Last.fm'),
63
6536221ffa83
	array(14,'amazon.png','%userid%','Enter your complete Amazon Wishlist URL','Amazon Wishlist'),
64
6536221ffa83
	array(15,'blog.png','%userid%','Enter the complete blog URL.','Blog'),
65
6536221ffa83
	array(16,'jeqq.png','http://www.jeqq.com/user/view/profile/%userid%','Enter your Jeqq username','Jeqq'),
66
6536221ffa83
	array(17,'dapx.png','%userid%','Enter your complete Dapx URL.','Dapx'),
67
6536221ffa83
	array(18,'xing.jpg','%userid%','Enter your complete Xing URL.','Xing'),
68
6536221ffa83
	array(19,'sixent.png','http://%userid%.sixent.com/','Enter your Sixent username','Sixent'),
69
6536221ffa83
	array(20,'technorati.jpg','http://technorati.com/people/technorati/%userid%/','Enter your Technorati username.','Technorati'),
70
6536221ffa83
	array(21,'friendfeed.png','http://friendfeed.com/%userid%','Enter your FriendFeed username.','FriendFeed'),
71
6536221ffa83
	array(22,'identica.png','http://identi.ca/%userid%','Enter your Identi.ca username.','Identi.ca'),
72
6536221ffa83
	array(23,'bitbucket.png','http://bitbucket.org/%userid%','Enter your Bitbucket username.','Bitbucket'),
73
6536221ffa83
	array(24,'github.png','http://github.com/%userid%','Enter your Github username.','Github'),
74
6536221ffa83
	array(25,'hellotxt.gif','http://hellotxt.com/user/%userid%','Enter your Hellotxt username.','Hellotxt'),
75
6f118e1bf4fc
	array(26,'hyves.png','http://%userid%.hyves.nl','Enter your Hyves.nl username.','Hyves.nl'),
76
6f118e1bf4fc
	array(27,'disqus.png','http://disqus.com/people/%userid%','Enter your Disqus username.','Disqus')
77
6536221ffa83
);
78
d0811661659f
79
29335354181d
//comparison based on socialnetwok name
80
29335354181d
function compare_social($s1, $s2) {
81
6536221ffa83
	return strcmp($s1[KEY_DISPLAY_NAME], $s2[KEY_DISPLAY_NAME]);
82
29335354181d
}
83
d0811661659f
84
29335354181d
//Sorts socialnetworks in alphabetical order
85
29335354181d
uasort($definitions, "compare_social");
86
d0811661659f
87
d0811661659f
88
d0811661659f
function social_links_wrapper(){
89
d0811661659f
90
d0811661659f
// This only works if the widget api is installed
91
d0811661659f
if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') )
92
d0811661659f
	return; // ...and if not, exit gracefully from the script.
93
d0811661659f
94
d0811661659f
//WPD_print('Filename: '.__FILE__);
95
d0811661659f
//WPD_print('DB version: '.get_option( "SOCIAL_LINKS_DB_VERSION" ));
96
d0811661659f
		// Displays the icons in the sidebar
97
d0811661659f
		function widget_social_links($args) {
98
d0811661659f
			global $definitions;
99
d0811661659f
			extract($args);
100
d0811661659f
					
101
d0811661659f
			$options = get_option('widget_social_links');
102
d0811661659f
				$title = empty($options['title']) ? 'About Me' : $options['title'];
103
d0811661659f
			$width =  empty($options['width']) ? 20 : $options['width'];
104
d0811661659f
		
105
d0811661659f
				echo $before_widget;
106
d0811661659f
				echo $before_title . $title . $after_title ;
107
d0811661659f
		
108
d0811661659f
			echo '<!-- About Me Version: '. SOCIAL_LINKS_VERSION .' -->';
109
d0811661659f
			echo "<div id='socialLinksContainer' style='width:$width"."px;'>";
110
d0811661659f
			echo generateSocialLinksInnerHTML();
111
d0811661659f
			echo '</div>';
112
d0811661659f
			echo $after_widget;
113
d0811661659f
			
114
d0811661659f
		}
115
d0811661659f
	
116
d0811661659f
		  //Config Panel
117
d0811661659f
		function widget_social_links_control() {
118
d0811661659f
			global $definitions;
119
d0811661659f
			$options = get_option('widget_social_links');
120
d0811661659f
	
121
d0811661659f
			if ( $_POST['social-links-submit'] ) {
122
d0811661659f
				// Clean up control form submission options
123
d0811661659f
				$newoptions['title'] = strip_tags(stripslashes($_POST['social-links-title']));
124
d0811661659f
				$newoptions['width'] = strip_tags(stripslashes($_POST['social-links-width']));
125
d0811661659f
	
126
d0811661659f
	
127
d0811661659f
				if ( $options != $newoptions ) {
128
d0811661659f
					$options = $newoptions;
129
d0811661659f
					update_option('widget_social_links', $options);
130
d0811661659f
				}
131
d0811661659f
			}
132
d0811661659f
	
133
d0811661659f
			$title = empty($options['title']) ? 'About Me' : $options['title'];
134
d0811661659f
			$width = empty($options['width']) ? 100 : $options['width'];
135
d0811661659f
	
136
d0811661659f
			?>
137
d0811661659f
			
138
d0811661659f
				<table>
139
d0811661659f
					<tr><td>
140
d0811661659f
						<label for="social-links-title">Widget title: <input type="text" id="social-links-title" name="social-links-title" value="<?php echo $title; ?>" /></label>
141
d0811661659f
					</td></tr>
142
d0811661659f
					<tr><td>
143
1a955c3effa9
						<label for="social-links-width">Width: <input type="text" id="social-links-width" name="social-links-width" size="8" value="<?php echo $width; ?>" /> pixels</label>
144
d0811661659f
					</td></tr>
145
d0811661659f
				</table>
146
d0811661659f
				<input type="hidden" name="social-links-submit" id="social-links-submit" value="1" />
147
d0811661659f
				
148
d0811661659f
			<?php
149
d0811661659f
		}//End of widget_social_links_control
150
d0811661659f
		
151
d0811661659f
		
152
d0811661659f
		function wp_ajax_social_links_add_network(){
153
d0811661659f
			// read submitted information
154
d0811661659f
			global $definitions;
155
d0811661659f
			
156
d0811661659f
			$siteID = $_POST['siteID'];
157
d0811661659f
			$data = $_POST['value'];
158
d0811661659f
			$messageId = $_POST['responseDiv'];
159
d0811661659f
			
160
d0811661659f
			$result = insertNetwork($siteID,$data);
161
d0811661659f
			if($result == 1)
162
d0811661659f
		 		$result = 'Link added.';
163
d0811661659f
		 	else
164
d0811661659f
		 		$result = 'There was a problem adding the link. Refresh the page and try again.';
165
d0811661659f
		 		
166
d0811661659f
		 	$innerHTML = generateSocialLinksPreviewInnerHTML('');
167
d0811661659f
			die('
168
d0811661659f
				$("message").innerHTML = "'.$result.'";
169
d0811661659f
				$("message").className="updated fade";
170
d0811661659f
				$("message").style.visibility = "visible";
171
d0811661659f
				document.getElementById("displayDiv").innerHTML = "'.$innerHTML.'";
172
d0811661659f
				createSortables();
173
d0811661659f
				
174
d0811661659f
				
175
d0811661659f
			');
176
d0811661659f
			
177
d0811661659f
			//Add this line to the above javascript to show the complete table.
178
d0811661659f
			//document.getElementById("editDiv").innerHTML = "' . generateSocialLinksEditInnerHTML(). '";
179
d0811661659f
		}
180
d0811661659f
		
181
d0811661659f
		//TODO: Implement the add ajax process to send data and let the javascript add child elements
182
d0811661659f
		//This is to avoid using innerHTML replacement and will then allow for more advanced client side effects
183
d0811661659f
	/*	function wp_ajax_social_links_add_network_send_data(){
184
d0811661659f
			// read submitted information
185
d0811661659f
			global $definitions;
186
d0811661659f
			
187
d0811661659f
			$selectedIndex = $_POST['networkIndex'];
188
d0811661659f
			$data = $_POST['value'];
189
d0811661659f
			
190
d0811661659f
			$result = insertNetwork($selectedIndex,$data);
191
d0811661659f
			$data = generateSocialLinksData();
192
d0811661659f
			//$result = 'fake insert';
193
d0811661659f
			die("$result
194
d0811661659f
				$('message').innerHTML = 'Database result is $result.';
195
d0811661659f
				$('message').class='updated fade';
196
d0811661659f
				$('message').style.visibility = 'visible';
197
d0811661659f
				updateSocialLinks($data);
198
d0811661659f
			");
199
d0811661659f
			
200
d0811661659f
		}
201
d0811661659f
		*/
202
d0811661659f
		function wp_ajax_social_links_delete_network(){
203
d0811661659f
			global $wpdb;
204
d0811661659f
		 	global $definitions;
205
d0811661659f
		 	
206
d0811661659f
			$linkId = $_POST['linkId'];
207
d0811661659f
		 	//WPD_print('deleting linkID='. $linkId);
208
d0811661659f
		 	$table_name = $wpdb->prefix . "social_links";
209
d0811661659f
		 	$sql = 'delete from ' .  $table_name . ' where id='.$linkId;
210
d0811661659f
		 	$result = $wpdb->query($wpdb->prepare($sql));
211
d0811661659f
		 	
212
d0811661659f
		 	if($result == 1)
213
d0811661659f
		 		$result = 'Removed link.';
214
d0811661659f
		 	else
215
d0811661659f
		 		$result = 'There was a problem deleting the link. Refresh the page and try again.'.$sql;
216
d0811661659f
		 	//WPD_print($result);
217
d0811661659f
		 	die('
218
d0811661659f
				$("message").innerHTML = "'.$result.'";
219
d0811661659f
				$("message").className="updated fade";
220
d0811661659f
				$("message").style.visibility = "visible";
221
d0811661659f
			');
222
d0811661659f
		}
223
d0811661659f
		
224
d0811661659f
		
225
d0811661659f
	
226
d0811661659f
	
227
d0811661659f
		 
228
d0811661659f
		 function insertNetwork($id,$value){
229
d0811661659f
		 
230
d0811661659f
		 	
231
d0811661659f
		 	//WPD_print('Inserting new network');
232
d0811661659f
		 	global $wpdb;
233
d0811661659f
		 	
234
d0811661659f
		 	//WPD_print('networkID='.$id.' data='.$value);
235
d0811661659f
		 	$table_name = $wpdb->prefix . "social_links";
236
d0811661659f
		 	$sql = 'Insert into ' .  $table_name . ' (network_id,user_info,sort_order) VALUES ("'.$id.'","'.$value.'",1000)';
237
d0811661659f
		 	$result = $wpdb->query($wpdb->prepare($sql));
238
d0811661659f
		 	//WPD_print($sql);
239
d0811661659f
		 	return $result;
240
d0811661659f
		 }
241
d0811661659f
		 
242
d0811661659f
		 function getSocialLinks(){
243
d0811661659f
		 	global $wpdb;
244
d0811661659f
		 	$table_name = $wpdb->prefix . "social_links";
245
d0811661659f
		 	$sql = 'Select * from ' .  $table_name . ' order by sort_order';
246
d0811661659f
		 	$results = $wpdb->get_results($sql,ARRAY_N);
247
d0811661659f
		 	////WPD_print("Select networks results: ".$results);
248
d0811661659f
		 	return $results;
249
d0811661659f
		 	
250
d0811661659f
		 }
251
d0811661659f
		 
252
6536221ffa83
		function generateSocialLinksInnerHTML(){
253
6536221ffa83
			global $definitions;
254
6536221ffa83
			global $plugindir;
255
6536221ffa83
256
6536221ffa83
			$rows = getSocialLinks();
257
6536221ffa83
			if(count($rows)==0)
258
6536221ffa83
				return;
259
6536221ffa83
			////WPD_print("Found".count($rows)." networks.");
260
6536221ffa83
261
6536221ffa83
			foreach ($rows as $row) {
262
6536221ffa83
				//WPD_print("SiteID: " . $row[1]);
263
6536221ffa83
				$linkInfoArray = $definitions[$row[1]];
264
6536221ffa83
				//WPD_print('network info '. $linkInfoArray);
265
6536221ffa83
				$url = str_replace("%userid%",$row[2],$linkInfoArray[KEY_URL_TEMPLATE]);
266
6536221ffa83
				$innerHTML = $innerHTML . "<a id='link_$row[0]' href='$url' rel='me'><img src='$plugindir/images/".$linkInfoArray[KEY_IMAGE]."' alt='".$linkInfoArray[KEY_DISPLAY_NAME]."' title='".$linkInfoArray[KEY_DISPLAY_NAME]."'/></a>";
267
d0811661659f
				if($row != $rows[count($rows)-1]){
268
d0811661659f
					$innerHTML = $innerHTML."\n";
269
d0811661659f
				}
270
d0811661659f
			}
271
6536221ffa83
272
d0811661659f
			return $innerHTML;
273
6536221ffa83
		}
274
d0811661659f
		 
275
6536221ffa83
		function generateSocialLinksPreviewInnerHTML($delimiter){
276
6536221ffa83
			global $definitions;
277
6536221ffa83
			global $plugindir;
278
6536221ffa83
279
6536221ffa83
			$rows = getSocialLinks();
280
6536221ffa83
			if(count($rows)==0)
281
6536221ffa83
				return;
282
6536221ffa83
			//WPD_print("Found ".count($rows)." networks.");
283
6536221ffa83
284
6536221ffa83
			foreach ($rows as $row) {
285
6536221ffa83
				//WPD_print("SiteID: " . $row[2]);
286
6536221ffa83
				//var_dump($row);
287
6536221ffa83
				$linkInfoArray = $definitions[$row[1]];
288
6536221ffa83
				//var_dump($linkInfoArray);
289
6536221ffa83
				//WPD_print('network info '. $linkInfoArray);
290
6536221ffa83
				$url = str_replace("%userid%",$row[2],$linkInfoArray[KEY_URL_TEMPLATE]);
291
6536221ffa83
				$innerHTML = $innerHTML . "<span id='link_$row[0]' title='$url'><img style='margin:2px' src='$plugindir/images/".$linkInfoArray[KEY_IMAGE]."' alt='".$linkInfoArray[KEY_DISPLAY_NAME]."' title='".$linkInfoArray[KEY_DISPLAY_NAME]."'/></span>";
292
d0811661659f
				if($row != $rows[count($rows)-1]){
293
d0811661659f
					$innerHTML = $innerHTML.$delimiter;
294
d0811661659f
				}
295
d0811661659f
			}
296
6536221ffa83
297
d0811661659f
			return $innerHTML;
298
6536221ffa83
		}
299
d0811661659f
		 
300
d0811661659f
		 /*
301
d0811661659f
		 function generateSocialLinksData(){
302
d0811661659f
			global $definitions;
303
d0811661659f
		 
304
d0811661659f
		 	$rows = getSocialLinks();
305
d0811661659f
		 	if(count($rows)==0)
306
d0811661659f
		 		return;
307
d0811661659f
		 	////WPD_print("Found".count($rows)." networks.");
308
d0811661659f
		 	$data = '';
309
d0811661659f
		 	foreach ($rows as $row) {
310
d0811661659f
		 		$linkInfoArray = $definitions[$row[2]];
311
d0811661659f
		 		$data += "link_$row[0],$linkInfoArray[0],$linkInfoArray[1],$linkInfoArray[4]\n";
312
d0811661659f
		 	}
313
d0811661659f
		 	return $data;
314
d0811661659f
		 	
315
d0811661659f
		 }
316
d0811661659f
		*/
317
d0811661659f
		
318
d0811661659f
		function social_links_admin_menu(){
319
d0811661659f
			global $pluginrelativedir;
320
d0811661659f
			//add_options_page('Social Links Settings', 'Social Links', 8,$pluginrelativedir.'/edit-sociallinks.php');
321
1a955c3effa9
			add_management_page('Social Links Settings - About Me', 'About Me', 8,__FILE__,'widget_social_links_settings');
322
d0811661659f
323
d0811661659f
			global $plugindir;
324
1a955c3effa9
			wp_enqueue_script('about-me', $plugindir . '/javascript.js',array('sack'));
325
d0811661659f
			wp_enqueue_script('scriptaculous');
326
d0811661659f
		}
327
d0811661659f
		
328
d0811661659f
		function addHeaderCode(){
329
d0811661659f
			//WPD_print("header code");
330
d0811661659f
			global $plugindir;
331
d0811661659f
			echo '<link type="text/css" rel="stylesheet" href="' . $plugindir . '/stylesheet.css" />' . "\n";
332
d0811661659f
			
333
d0811661659f
		}
334
d0811661659f
		
335
d0811661659f
	
336
d0811661659f
		
337
d0811661659f
			////WPD_print("Registering plugin");
338
d0811661659f
			
339
d0811661659f
			add_action('wp_head','addHeaderCode');
340
d0811661659f
			
341
d0811661659f
			
342
d0811661659f
			
343
d0811661659f
			//Add action to load sub menu
344
d0811661659f
			add_action('admin_menu', 'social_links_admin_menu');
345
d0811661659f
			
346
d0811661659f
			
347
d0811661659f
			
348
d0811661659f
			
349
d0811661659f
			//Add ajax callback action called from client side javascript
350
d0811661659f
			add_action('wp_ajax_social_links_add_network', 'wp_ajax_social_links_add_network' );
351
d0811661659f
			add_action('wp_ajax_social_links_delete_network', 'wp_ajax_social_links_delete_network' );
352
d0811661659f
			
353
1a955c3effa9
			register_sidebar_widget('About Me - Social Links', 'widget_social_links');
354
1a955c3effa9
			register_widget_control('About Me - Social Links', 'widget_social_links_control');
355
d0811661659f
		
356
d0811661659f
	}//End of SocialLinks class
357
d0811661659f
358
d0811661659f
359
d0811661659f
add_action('plugins_loaded','social_links_wrapper');
360
d0811661659f
361
d0811661659f
//todo handle auto db table update
362
d0811661659f
function social_links_install(){
363
d0811661659f
	//require_once('datastore.php');
364
d0811661659f
	//sl_install();
365
d0811661659f
	
366
d0811661659f
	global $wpdb;
367
d0811661659f
	
368
d0811661659f
	 //WPD_print("Installing Social Links Plugin");
369
d0811661659f
	 //echo '<div>Activation social links</div>';
370
d0811661659f
	 
371
d0811661659f
	$table_name = $wpdb->prefix . "social_links";
372
d0811661659f
	
373
d0811661659f
	// $installed_ver = get_option( "SOCIAL_LINKS_DB_VERSION" );
374
d0811661659f
375
d0811661659f
	if($wpdb->get_var("show tables like '$table_name'") != $table_name ) {
376
d0811661659f
		
377
d0811661659f
		$sql = "CREATE TABLE " . $table_name . " (
378
d0811661659f
		id mediumint(9) NOT NULL AUTO_INCREMENT,
379
d0811661659f
		network_id int not null,
380
d0811661659f
		user_info VARCHAR(55) NOT NULL,
381
d0811661659f
		sort_order int not null DEFAULT 0,
382
d0811661659f
		UNIQUE KEY id (id)
383
d0811661659f
		);";
384
d0811661659f
		
385
d0811661659f
		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
386
d0811661659f
		dbDelta($sql);
387
d0811661659f
		
388
d0811661659f
		
389
d0811661659f
		add_option("SOCIAL_LINKS_DB_VERSION", SOCIAL_LINKS_DB_VERSION);
390
d0811661659f
	}
391
d0811661659f
 }
392
d0811661659f
393
d0811661659f
394
d0811661659f
//Administration page
395
d0811661659f
$message;
396
d0811661659f
$messageClass;
397
d0811661659f
function widget_social_links_settings(){
398
d0811661659f
399
d0811661659f
	if (isset($_POST['saveorder']))
400
d0811661659f
	{
401
d0811661659f
		saveSortOrder();
402
d0811661659f
	}
403
d0811661659f
 
404
d0811661659f
405
d0811661659f
	global $definitions;
406
d0811661659f
	global $message;
407
d0811661659f
	global $messageClass;
408
d0811661659f
  global $plugindir;
409
d0811661659f
	
410
d0811661659f
	$visibility = 'hidden';
411
d0811661659f
	if(!empty($messageClass))
412
d0811661659f
		$visibility = 'visible';
413
d0811661659f
	
414
d0811661659f
	?>
415
d0811661659f
416
d0811661659f
417
d0811661659f
		<div class="wrap">
418
d0811661659f
			<h2>About Me</h2>
419
d0811661659f
			
420
d0811661659f
				
421
d0811661659f
				<div id="message" class="<?php echo $messageClass;  ?>" style="background-color: rgb(255, 251, 204);margin-top:10px;display:block;visibility:<?php echo $visibility;  ?>;width:300px"><?php echo $message;  ?></div>
422
d0811661659f
				<div style="position:relative;float:left;margin-right:20px;">
423
d0811661659f
					<h3>Add New Social Link</h3>
424
d0811661659f
					<select id='networkDropdown' onchange='selectionChanged()'>
425
d0811661659f
						<option>Select network...</option>
426
d0811661659f
						
427
d0811661659f
						<?php
428
d0811661659f
							
429
d0811661659f
							foreach ($definitions as $key => $linkInfoArray){
430
d0811661659f
								echo "<option value='$linkInfoArray[0]' instruction='$linkInfoArray[3]'>$linkInfoArray[4]</option>";
431
d0811661659f
							}
432
d0811661659f
						?>
433
d0811661659f
					</select>
434
d0811661659f
					
435
d0811661659f
					<label id='instruction'></label>
436
d0811661659f
					<br/>
437
d0811661659f
					<input type="text" id="addSettingInput" style="width:400px;" onkeydown="if(event.keyCode == 13){social_links_ajax_addNetwork(document.getElementById('networkDropdown').selectedIndex,document.getElementById('addSettingInput'),document.getElementById('responseDiv'));}">
438
d0811661659f
					<input type="button" id="addButton" value="Add" disabled=true
439
d0811661659f
						onclick="social_links_ajax_addNetwork(document.getElementById('networkDropdown').selectedIndex,document.getElementById('addSettingInput'),document.getElementById('responseDiv'));" />
440
d0811661659f
					<br/>
441
d0811661659f
				</div> 
442
d0811661659f
				
443
d0811661659f
			<form method="post" onSubmit="social_links_ajax_saveOrder()" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
444
d0811661659f
			
445
d0811661659f
				<div style="float:left;">
446
d0811661659f
					<h3>Preview</h3>
447
d0811661659f
					<div  id="displayDiv" style="width:100px;cursor:move;" class="drop_target">
448
d0811661659f
						<?php echo generateSocialLinksPreviewInnerHTML("\n");  ?>
449
d0811661659f
					</div>
450
d0811661659f
					
451
d0811661659f
					<input type="submit" id="saveOrderButton" name="saveorder" value="Save Order" style="margin-top:20px"/>
452
d0811661659f
					<input type="hidden" name="sortOrderData" id="sortOrderData"/>
453
d0811661659f
          <input type="hidden" name="callBackUrl" id="callBackUrl" value="<?php echo $plugindir ?>"/>
454
d0811661659f
				</div>
455
d0811661659f
				<div id="trash" style="float:left;position:relative;top:45px;left:25px;width:50px;height:50px;" class="drop_target">
456
d0811661659f
          <img src="<?php echo $plugindir ?>/images/trash.jpg"/>
457
d0811661659f
        </div>
458
d0811661659f
			</form>
459
d0811661659f
      <div style="clear: both;"> </div>
460
d0811661659f
      <div>
461
d0811661659f
        <p>
462
d0811661659f
          To add a new link select the network from the drop down, fill in the appropriate information and press enter.<br/>
463
d0811661659f
          To change the order they appear, rearrange the icons in the preview and click 'Save Order'. <br/>
464
d0811661659f
          To delete a link, simply drag it to the trash can.
465
d0811661659f
        </p>
466
d0811661659f
      </div>
467
d0811661659f
    </div>	
468
d0811661659f
		<script language="JavaScript">
469
d0811661659f
			createSortables();
470
d0811661659f
		</script>
471
d0811661659f
	<?php
472
d0811661659f
	
473
d0811661659f
	
474
d0811661659f
		}//End of widget_social_links_settings
475
d0811661659f
476
d0811661659f
function saveSortOrder(){
477
d0811661659f
	global $wpdb;
478
d0811661659f
	global $message;
479
d0811661659f
	global $messageClass;
480
d0811661659f
	//WPD_print("Action: " . $action);
481
d0811661659f
	//WPD_print("Sort Data: " . $sortDataOrder);
482
d0811661659f
	$sortDataOrder = !empty($_POST['sortOrderData']) ? $_POST['sortOrderData'] : '';
483
d0811661659f
	if(!empty($sortDataOrder))
484
d0811661659f
	{
485
d0811661659f
		//WPD_print("Saving order");
486
d0811661659f
		parse_str($sortDataOrder,$newSortorderArray);
487
d0811661659f
		if(count($newSortorderArray) != 0){
488
d0811661659f
			//WPD_print("List size: " . count($newSortorderArray));
489
d0811661659f
			$table_name = $wpdb->prefix . "social_links";
490
d0811661659f
			foreach($newSortorderArray["displayDiv"] as $order => $id){
491
d0811661659f
				//WPD_print('Order: '.$order.' Value: '.$id);
492
d0811661659f
				
493
d0811661659f
				$sql = 'Update ' .  $table_name . ' Set sort_order='.$order.' where id='.$id;
494
d0811661659f
				$result = $wpdb->query($wpdb->prepare($sql));
495
d0811661659f
				//WPD_print('Result for '.$sql.' is '.$result);
496
d0811661659f
					
497
d0811661659f
			}
498
d0811661659f
			$message = 'Saved links\' order.';
499
d0811661659f
		}
500
d0811661659f
		else{
501
d0811661659f
			$message = 'No items to save.';
502
d0811661659f
		}
503
d0811661659f
		$messageClass = 'updated fade';
504
d0811661659f
	}
505
d0811661659f
}
506
d0811661659f
507
d0811661659f
  
508
6f118e1bf4fc
?>