@@ -46,38 +46,40 @@ function gitpress_widget($args, $widget_args = 1) {
4646	    $ options  = get_option ('gitpress_widget_options ' );
4747	    $ title  = $ options [$ number ]['title ' ];
4848	    $ username  = $ options [$ number ]['username ' ];
49+ 	    $ use_badge  = $ options [$ number ]['use_badge ' ];
4950
5051	    // Grab the user info using the GitHub API 
51- 	    /* 
52- 	    $curl_session = curl_init(); 
53- 	    curl_setopt($curl_session, CURLOPT_URL, 'http://github.com/api/v1/json/' . $username); 
54- 	    curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1); 
55- 	    $result = json_decode(curl_exec($curl_session)); 
56- 	    curl_close($curl_session); 
52+ 	    if  (! isset ( $ use_badge )) { 
53+ 	         $ curl_session  = curl_init ();
54+      	    curl_setopt ($ curl_session , CURLOPT_URL , 'http://github.com/api/v1/json/ '  . $ username );
55+      	    curl_setopt ($ curl_session , CURLOPT_RETURNTRANSFER , 1 );
56+      	    $ result  = json_decode (curl_exec ($ curl_session ));
57+      	    curl_close ($ curl_session );
5758
58- 	    $userinfo = $result->{"user"}; 
59- 	    $repos = $userinfo->{"repositories"}; 
59+      	    $ userinfo  = $ result ->{"user " };
60+      	    $ repos  = $ userinfo ->{"repositories " };
6061
6162
62- 	    echo $before_widget . $before_title . $title . $after_title; 
63- 	    echo "<ul id='gitpress-repo-list-" . $number . "' class='widget gitpress-repo-list'>"; 
64- 	    if (isset($repos)) { 
65- 	        foreach ($repos as $repo) { 
66-     	        $repo_name = $repo->{"name"}; 
67-     	        $repo_url = $repo->{"url"}; 
68-     	        echo "<li class='gitpress-repo'><a href='" . $repo_url . "'>" . $repo_name . "</a></li>"; 
69-     	    } 
70-         } 
71- 	    echo "</ul>"; 
72- 	    echo $after_widget; 
73- 	     */ 
63+      	    echo  $ before_widget  . $ before_title  . $ title  . $ after_title ;
64+      	    echo  "<ul id='gitpress-repo-list- "  . $ number  . "' class='widget gitpress-repo-list'> " ;
65+      	    if  (isset ($ repos )) {
66+      	        foreach  ($ repos  as  $ repo ) {
67+          	        $ repo_name  = $ repo ->{"name " };
68+          	        $ repo_url  = $ repo ->{"url " };
69+          	        echo  "<li class='gitpress-repo'><a href=' "  . $ repo_url  . "'> "  . $ repo_name  . "</a></li> " ;
70+          	    }
71+              }
72+      	    echo  "</ul> " ;
73+      	    echo  $ after_widget ;
74+         }  else  { 
7475	    ?> 
7576	    <li id="github-badge" style="list-style: none"></li>
7677        <script type="text/javascript" charset="utf-8">
7778          GITHUB_USERNAME="<?php  echo  $ username  ?> ";
7879          GITHUB_HEAD="h2";
7980        </script>
8081        <script src="http://drnicjavascript.rubyforge.org/github_badge/dist/github-badge-launcher.js" type="text/javascript"></script><?php 
82+         }
8183	}
8284
8385	function  gitpress_widget_control ($ widget_args  = 1 ) {
@@ -125,7 +127,11 @@ function gitpress_widget_control($widget_args = 1) {
125127    				    continue ;
126128    			$ title  = strip_tags (stripslashes ($ gitpress_widget_instance ['title ' ]));
127129    			$ username  = strip_tags (stripslashes ($ gitpress_widget_instance ['username ' ]));
128-     			$ options [$ widget_number ] = array ( 'title '  => $ title , 'username '  => $ username  );
130+     			if  (isset ($ gitpress_widget_instance ['use_badge ' ])) {
131+     			    $ options [$ widget_number ] = array ( 'title '  => $ title , 'username '  => $ username , 'use_badge '  => 'true ' );
132+     			} else  {
133+     			    $ options [$ widget_number ] = array ( 'title '  => $ title , 'username '  => $ username  );
134+ 			    }
129135    		}
130136
131137    		update_option ('gitpress_widget_options ' , $ options );
@@ -140,17 +146,23 @@ function gitpress_widget_control($widget_args = 1) {
140146    	} else  {
141147    		$ title  = attribute_escape ($ options [$ number ]['title ' ]);
142148    		$ username  = attribute_escape ($ options [$ number ]['username ' ]);
149+     		$ use_badge  = $ options [$ number ]['use_badge ' ];
143150    	}
144151
145152		$ title_id  = 'gitpress-title- '  . $ number ;
146153		$ title_name  = 'gitpress-widget[ '  . $ number  . '][title] ' ;
147154		$ username_id  = 'gitpress-username- '  . $ number ;
148155		$ username_name  = 'gitpress-widget[ '  . $ number  . '][username] ' ;
156+ 		$ use_badge_id  = 'gitpress-use_badge- '  . $ number ;
157+ 		$ use_badge_name  = 'gitpress-widget[ '  . $ number  . '][use_badge] ' ;
149158		$ submit_id  = 'gitpress-submit- '  . $ number ;
150159		$ submit_name  = 'gitpress-widget[ '  . $ number  . '][submit] ' ;
151160
152161		echo  '<p style="text-align:right;"><label for=" '  . $ title_id  . '"> '  . __ ('Title: ' ) . ' <input style="width: 200px;" id=" '  . $ title_id  . '" name=" '  . $ title_name  . '" type="text" value=" '  . $ title  .'" /></label></p> ' ;
153162		echo  '<p style="text-align:right;"><label for=" '  . $ username_id  . '"> '  . __ ('User: ' ) . ' <input style="width: 200px;" id=" '  . $ username_id  . '" name=" '  . $ username_name  . '" type="text" value=" '  . $ username  . '" /></label></p> ' ;
163+ 		echo  '<p style="text-align:right;"><label for=" '  . $ use_badge_id  . '"> '  . __ ('Use Dr. Nic Badge? ' ) . ' <input style="width: 200px;" id=" '  . $ use_badge_id  . '" name=" '  . $ use_badge_name  . '" type="checkbox" ' ;
164+ 		if  (isset ($ use_badge )) echo  ' checked="true"  ' ;
165+ 		echo  '/></label></p> ' ;
154166		echo  '<input type="hidden" id=" '  . $ submit_id  . '" name=" '  . $ submit_name  . '" value="1" /> ' ;
155167	}
156168
0 commit comments