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

Tag
1.0.3
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
<?php
/*
Plugin Name: About Me
Plugin URI: http://abisso.org/index.php/projects/about-me/
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>
Author: Alessio Caiazza
Version: 1.0.3
Author URI: http://alessiocaiazza.info

/*  Social Links Copyright 2008  Kareem Sultan  (email : kareemsultan@gmail.com) */
/*
        (c) 2009 Alessio Caiazza
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

http://www.gnu.org/licenses/gpl.txt

*/

//call install function upon activation
register_activation_hook(__FILE__,'social_links_install');

//TO DO use these definitions instead
define('SOCIAL_LINKS_VERSION', '1.0.3');
define('SOCIAL_LINKS_DB_VERSION', '1.1');

define('KEY_SITE_ID',0);
define('KEY_IMAGE',1);
define('KEY_URL_TEMPLATE',2);
define('KEY_INSTRUCTION',3);
define('KEY_DISPLAY_NAME',4);
  
//$sl_db_version = "1.0";
$plugindir = get_settings('home').'/wp-content/plugins/'.dirname(plugin_basename(__FILE__));
$pluginrelativedir = '/wp-content/plugins/'.dirname(plugin_basename(__FILE__));

$definitions = array(
        array(0,'facebook.png','%userid%','Enter your complete Facebook profile URL','Facebook'),
        array(1,'myspace.png','%userid%','Enter your complete MySpace URL.','MySpace'),
        array(2,'linkedin.png','%userid%','Enter your complete LinkedIn URL.','LinkedIn'),
        array(3,'picasa.png','http://picasaweb.google.com/%userid%','Enter your Picasa(Google) username.','Picasa Web Album'),
        array(4,'flickr.png','http://flickr.com/photos/%userid%','Enter your flickr username','Flickr'),
        array(5,'youtube.png','http://www.youtube.com/%userid%','Enter your YouTube username','YouTube'),
        array(6,'twitter.png','http://twitter.com/%userid%','Enter your Twitter username','Twitter'),
        array(7,'pownce.png','http://pownce.com/%userid%','Enter your Pownce username','Pownce'),
        array(8,'plurk.png','http://www.plurk.com/user/%userid%','Enter your Plurk username','Plurk'),
        array(9,'digg.png','http://www.digg.com/users/%userid%','Enter your Digg username.','Digg'),
        array(10,'delicious.png','http://delicious.com/%userid%','Enter your Delicious username','Delicious'),
        array(11,'blogmarks.png','http://blogmarks.net/user/%userid%','Enter your BlogMarks username.','BlogMarks'),
        array(12,'stumbleupon.png','http://%userid%.stumbleupon.com','Enter your Stumble Upon username','Stumble Upon'),
        array(13,'lastfm.png','http://www.last.fm/user/%userid%','Enter your Last.fm username','Last.fm'),
        array(14,'amazon.png','%userid%','Enter your complete Amazon Wishlist URL','Amazon Wishlist'),
        array(15,'blog.png','%userid%','Enter the complete blog URL.','Blog'),
        array(16,'jeqq.png','http://www.jeqq.com/user/view/profile/%userid%','Enter your Jeqq username','Jeqq'),
        array(17,'dapx.png','%userid%','Enter your complete Dapx URL.','Dapx'),
        array(18,'xing.jpg','%userid%','Enter your complete Xing URL.','Xing'),
        array(19,'sixent.png','http://%userid%.sixent.com/','Enter your Sixent username','Sixent'),
        array(20,'technorati.jpg','http://technorati.com/people/technorati/%userid%/','Enter your Technorati username.','Technorati'),
        array(21,'friendfeed.png','http://friendfeed.com/%userid%','Enter your FriendFeed username.','FriendFeed'),
        array(22,'identica.png','http://identi.ca/%userid%','Enter your Identi.ca username.','Identi.ca'),
        array(23,'bitbucket.png','http://bitbucket.org/%userid%','Enter your Bitbucket username.','Bitbucket'),
        array(24,'github.png','http://github.com/%userid%','Enter your Github username.','Github'),
        array(25,'hellotxt.gif','http://hellotxt.com/user/%userid%','Enter your Hellotxt username.','Hellotxt'),
        array(26,'hyves.png','http://%userid%.hyves.nl','Enter your Hyves.nl username.','Hyves.nl'),
        array(27,'disqus.png','http://disqus.com/people/%userid%','Enter your Disqus username.','Disqus')
);

//comparison based on socialnetwok name
function compare_social($s1, $s2) {
        return strcmp($s1[KEY_DISPLAY_NAME], $s2[KEY_DISPLAY_NAME]);
}

//Sorts socialnetworks in alphabetical order
uasort($definitions, "compare_social");


function social_links_wrapper(){

// This only works if the widget api is installed
if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') )
        return; // ...and if not, exit gracefully from the script.

//WPD_print('Filename: '.__FILE__);
//WPD_print('DB version: '.get_option( "SOCIAL_LINKS_DB_VERSION" ));
                // Displays the icons in the sidebar
                function widget_social_links($args) {
                        global $definitions;
                        extract($args);
                                        
                        $options = get_option('widget_social_links');
                                $title = empty($options['title']) ? 'About Me' : $options['title'];
                        $width =  empty($options['width']) ? 20 : $options['width'];
                
                                echo $before_widget;
                                echo $before_title . $title . $after_title ;
                
                        echo '<!-- About Me Version: '. SOCIAL_LINKS_VERSION .' -->';
                        echo "<div id='socialLinksContainer' style='width:$width"."px;'>";
                        echo generateSocialLinksInnerHTML();
                        echo '</div>';
                        echo $after_widget;
                        
                }
        
                  //Config Panel
                function widget_social_links_control() {
                        global $definitions;
                        $options = get_option('widget_social_links');
        
                        if ( $_POST['social-links-submit'] ) {
                                // Clean up control form submission options
                                $newoptions['title'] = strip_tags(stripslashes($_POST['social-links-title']));
                                $newoptions['width'] = strip_tags(stripslashes($_POST['social-links-width']));
        
        
                                if ( $options != $newoptions ) {
                                        $options = $newoptions;
                                        update_option('widget_social_links', $options);
                                }
                        }
        
                        $title = empty($options['title']) ? 'About Me' : $options['title'];
                        $width = empty($options['width']) ? 100 : $options['width'];
        
                        ?>
                        
                                <table>
                                        <tr><td>
                                                <label for="social-links-title">Widget title: <input type="text" id="social-links-title" name="social-links-title" value="<?php echo $title; ?>" /></label>
                                        </td></tr>
                                        <tr><td>
                                                <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>
                                        </td></tr>
                                </table>
                                <input type="hidden" name="social-links-submit" id="social-links-submit" value="1" />
                                
                        <?php
                }//End of widget_social_links_control
                
                
                function wp_ajax_social_links_add_network(){
                        // read submitted information
                        global $definitions;
                        
                        $siteID = $_POST['siteID'];
                        $data = $_POST['value'];
                        $messageId = $_POST['responseDiv'];
                        
                        $result = insertNetwork($siteID,$data);
                        if($result == 1)
                                $result = 'Link added.';
                        else
                                $result = 'There was a problem adding the link. Refresh the page and try again.';
                                
                        $innerHTML = generateSocialLinksPreviewInnerHTML('');
                        die('
                                $("message").innerHTML = "'.$result.'";
                                $("message").className="updated fade";
                                $("message").style.visibility = "visible";
                                document.getElementById("displayDiv").innerHTML = "'.$innerHTML.'";
                                createSortables();
                                
                                
                        ');
                        
                        //Add this line to the above javascript to show the complete table.
                        //document.getElementById("editDiv").innerHTML = "' . generateSocialLinksEditInnerHTML(). '";
                }
                
                //TODO: Implement the add ajax process to send data and let the javascript add child elements
                //This is to avoid using innerHTML replacement and will then allow for more advanced client side effects
        /*      function wp_ajax_social_links_add_network_send_data(){
                        // read submitted information
                        global $definitions;
                        
                        $selectedIndex = $_POST['networkIndex'];
                        $data = $_POST['value'];
                        
                        $result = insertNetwork($selectedIndex,$data);
                        $data = generateSocialLinksData();
                        //$result = 'fake insert';
                        die("$result
                                $('message').innerHTML = 'Database result is $result.';
                                $('message').class='updated fade';
                                $('message').style.visibility = 'visible';
                                updateSocialLinks($data);
                        ");
                        
                }
                */
                function wp_ajax_social_links_delete_network(){
                        global $wpdb;
                        global $definitions;
                        
                        $linkId = $_POST['linkId'];
                        //WPD_print('deleting linkID='. $linkId);
                        $table_name = $wpdb->prefix . "social_links";
                        $sql = 'delete from ' .  $table_name . ' where id='.$linkId;
                        $result = $wpdb->query($wpdb->prepare($sql));
                        
                        if($result == 1)
                                $result = 'Removed link.';
                        else
                                $result = 'There was a problem deleting the link. Refresh the page and try again.'.$sql;
                        //WPD_print($result);
                        die('
                                $("message").innerHTML = "'.$result.'";
                                $("message").className="updated fade";
                                $("message").style.visibility = "visible";
                        ');
                }
                
                
        
        
                 
                 function insertNetwork($id,$value){
                 
                        
                        //WPD_print('Inserting new network');
                        global $wpdb;
                        
                        //WPD_print('networkID='.$id.' data='.$value);
                        $table_name = $wpdb->prefix . "social_links";
                        $sql = 'Insert into ' .  $table_name . ' (network_id,user_info,sort_order) VALUES ("'.$id.'","'.$value.'",1000)';
                        $result = $wpdb->query($wpdb->prepare($sql));
                        //WPD_print($sql);
                        return $result;
                 }
                 
                 function getSocialLinks(){
                        global $wpdb;
                        $table_name = $wpdb->prefix . "social_links";
                        $sql = 'Select * from ' .  $table_name . ' order by sort_order';
                        $results = $wpdb->get_results($sql,ARRAY_N);
                        ////WPD_print("Select networks results: ".$results);
                        return $results;
                        
                 }
                 
                function generateSocialLinksInnerHTML(){
                        global $definitions;
                        global $plugindir;

                        $rows = getSocialLinks();
                        if(count($rows)==0)
                                return;
                        ////WPD_print("Found".count($rows)." networks.");

                        foreach ($rows as $row) {
                                //WPD_print("SiteID: " . $row[1]);
                                $linkInfoArray = $definitions[$row[1]];
                                //WPD_print('network info '. $linkInfoArray);
                                $url = str_replace("%userid%",$row[2],$linkInfoArray[KEY_URL_TEMPLATE]);
                                $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>";
                                if($row != $rows[count($rows)-1]){
                                        $innerHTML = $innerHTML."\n";
                                }
                        }

                        return $innerHTML;
                }
                 
                function generateSocialLinksPreviewInnerHTML($delimiter){
                        global $definitions;
                        global $plugindir;

                        $rows = getSocialLinks();
                        if(count($rows)==0)
                                return;
                        //WPD_print("Found ".count($rows)." networks.");

                        foreach ($rows as $row) {
                                //WPD_print("SiteID: " . $row[2]);
                                //var_dump($row);
                                $linkInfoArray = $definitions[$row[1]];
                                //var_dump($linkInfoArray);
                                //WPD_print('network info '. $linkInfoArray);
                                $url = str_replace("%userid%",$row[2],$linkInfoArray[KEY_URL_TEMPLATE]);
                                $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>";
                                if($row != $rows[count($rows)-1]){
                                        $innerHTML = $innerHTML.$delimiter;
                                }
                        }

                        return $innerHTML;
                }
                 
                 /*
                 function generateSocialLinksData(){
                        global $definitions;
                 
                        $rows = getSocialLinks();
                        if(count($rows)==0)
                                return;
                        ////WPD_print("Found".count($rows)." networks.");
                        $data = '';
                        foreach ($rows as $row) {
                                $linkInfoArray = $definitions[$row[2]];
                                $data += "link_$row[0],$linkInfoArray[0],$linkInfoArray[1],$linkInfoArray[4]\n";
                        }
                        return $data;
                        
                 }
                */
                
                function social_links_admin_menu(){
                        global $pluginrelativedir;
                        //add_options_page('Social Links Settings', 'Social Links', 8,$pluginrelativedir.'/edit-sociallinks.php');
                        add_management_page('Social Links Settings - About Me', 'About Me', 8,__FILE__,'widget_social_links_settings');

                        global $plugindir;
                        wp_enqueue_script('about-me', $plugindir . '/javascript.js',array('sack'));
                        wp_enqueue_script('scriptaculous');
                }
                
                function addHeaderCode(){
                        //WPD_print("header code");
                        global $plugindir;
                        echo '<link type="text/css" rel="stylesheet" href="' . $plugindir . '/stylesheet.css" />' . "\n";
                        
                }
                
        
                
                        ////WPD_print("Registering plugin");
                        
                        add_action('wp_head','addHeaderCode');
                        
                        
                        
                        //Add action to load sub menu
                        add_action('admin_menu', 'social_links_admin_menu');
                        
                        
                        
                        
                        //Add ajax callback action called from client side javascript
                        add_action('wp_ajax_social_links_add_network', 'wp_ajax_social_links_add_network' );
                        add_action('wp_ajax_social_links_delete_network', 'wp_ajax_social_links_delete_network' );
                        
                        register_sidebar_widget('About Me - Social Links', 'widget_social_links');
                        register_widget_control('About Me - Social Links', 'widget_social_links_control');
                
        }//End of SocialLinks class


add_action('plugins_loaded','social_links_wrapper');

//todo handle auto db table update
function social_links_install(){
        //require_once('datastore.php');
        //sl_install();
        
        global $wpdb;
        
         //WPD_print("Installing Social Links Plugin");
         //echo '<div>Activation social links</div>';
         
        $table_name = $wpdb->prefix . "social_links";
        
        // $installed_ver = get_option( "SOCIAL_LINKS_DB_VERSION" );

        if($wpdb->get_var("show tables like '$table_name'") != $table_name ) {
                
                $sql = "CREATE TABLE " . $table_name . " (
                id mediumint(9) NOT NULL AUTO_INCREMENT,
                network_id int not null,
                user_info VARCHAR(55) NOT NULL,
                sort_order int not null DEFAULT 0,
                UNIQUE KEY id (id)
                );";
                
                require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
                dbDelta($sql);
                
                
                add_option("SOCIAL_LINKS_DB_VERSION", SOCIAL_LINKS_DB_VERSION);
        }
 }


//Administration page
$message;
$messageClass;
function widget_social_links_settings(){

        if (isset($_POST['saveorder']))
        {
                saveSortOrder();
        }
 

        global $definitions;
        global $message;
        global $messageClass;
  global $plugindir;
        
        $visibility = 'hidden';
        if(!empty($messageClass))
                $visibility = 'visible';
        
        ?>


                <div class="wrap">
                        <h2>About Me</h2>
                        
                                
                                <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>
                                <div style="position:relative;float:left;margin-right:20px;">
                                        <h3>Add New Social Link</h3>
                                        <select id='networkDropdown' onchange='selectionChanged()'>
                                                <option>Select network...</option>
                                                
                                                <?php
                                                        
                                                        foreach ($definitions as $key => $linkInfoArray){
                                                                echo "<option value='$linkInfoArray[0]' instruction='$linkInfoArray[3]'>$linkInfoArray[4]</option>";
                                                        }
                                                ?>
                                        </select>
                                        
                                        <label id='instruction'></label>
                                        <br/>
                                        <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'));}">
                                        <input type="button" id="addButton" value="Add" disabled=true
                                                onclick="social_links_ajax_addNetwork(document.getElementById('networkDropdown').selectedIndex,document.getElementById('addSettingInput'),document.getElementById('responseDiv'));" />
                                        <br/>
                                </div> 
                                
                        <form method="post" onSubmit="social_links_ajax_saveOrder()" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
                        
                                <div style="float:left;">
                                        <h3>Preview</h3>
                                        <div  id="displayDiv" style="width:100px;cursor:move;" class="drop_target">
                                                <?php echo generateSocialLinksPreviewInnerHTML("\n");  ?>
                                        </div>
                                        
                                        <input type="submit" id="saveOrderButton" name="saveorder" value="Save Order" style="margin-top:20px"/>
                                        <input type="hidden" name="sortOrderData" id="sortOrderData"/>
          <input type="hidden" name="callBackUrl" id="callBackUrl" value="<?php echo $plugindir ?>"/>
                                </div>
                                <div id="trash" style="float:left;position:relative;top:45px;left:25px;width:50px;height:50px;" class="drop_target">
          <img src="<?php echo $plugindir ?>/images/trash.jpg"/>
        </div>
                        </form>
      <div style="clear: both;"> </div>
      <div>
        <p>
          To add a new link select the network from the drop down, fill in the appropriate information and press enter.<br/>
          To change the order they appear, rearrange the icons in the preview and click 'Save Order'. <br/>
          To delete a link, simply drag it to the trash can.
        </p>
      </div>
    </div>      
                <script language="JavaScript">
                        createSortables();
                </script>
        <?php
        
        
                }//End of widget_social_links_settings

function saveSortOrder(){
        global $wpdb;
        global $message;
        global $messageClass;
        //WPD_print("Action: " . $action);
        //WPD_print("Sort Data: " . $sortDataOrder);
        $sortDataOrder = !empty($_POST['sortOrderData']) ? $_POST['sortOrderData'] : '';
        if(!empty($sortDataOrder))
        {
                //WPD_print("Saving order");
                parse_str($sortDataOrder,$newSortorderArray);
                if(count($newSortorderArray) != 0){
                        //WPD_print("List size: " . count($newSortorderArray));
                        $table_name = $wpdb->prefix . "social_links";
                        foreach($newSortorderArray["displayDiv"] as $order => $id){
                                //WPD_print('Order: '.$order.' Value: '.$id);
                                
                                $sql = 'Update ' .  $table_name . ' Set sort_order='.$order.' where id='.$id;
                                $result = $wpdb->query($wpdb->prepare($sql));
                                //WPD_print('Result for '.$sql.' is '.$result);
                                        
                        }
                        $message = 'Saved links\' order.';
                }
                else{
                        $message = 'No items to save.';
                }
                $messageClass = 'updated fade';
        }
}

  
?>