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
cf44534165d2
parent
ae5dc470ccbf
branch
default

Added tag 1.0.7 for changeset ae5dc470ccbf

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