| [ PHPXref.com ] | [ Generated: Sun Jul 20 16:35:25 2008 ] | [ bBlog 0.7.6 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 // function.blogroll.php - outputs a blogroll from your favorites at blo.gs 3 // based on php blogroll by phil ringnalda - http://philringnalda.com/phpblogroll/ 4 5 function identify_function_blogroll () { 6 $help = ' 7 <p>blogroll! 8 <p>Based on phpblogroll by phil ringnalda - http://philringnalda.com/phpblogroll/ 9 <p>You will need a blogroll account from <a href="http://www.blo.gs">blo.gs</a> to use this. 10 <p>Make sure bblog/compiled_templates/favorites.xml is writable by the webserver. 11 <p>Sign up at blo.gs and then add your favorites to your favorites list (you\'ll be happier 12 if you use a decent browser, since Opera/Mozilla will show a cute little plus in a 13 circle for things you haven\'t added, and an x in a circle for things you\'ve already added, 14 while IE will show a square box if it\'s added and "&oplus" if it isn\'t. 15 16 Once you\'ve added your favorites to your list, click "settings" and check the box to make your 17 list of favorites public. Save your settings, go back to the home page, and click "share". 18 Down at the bottom of the page is a list of links to favorites in three flavors. 19 Right click the "favorites.xml" and select "save target as" to save a copy of 20 favorites.xml on your computer (you only have to save and upload it once <b>into compiled_templates</b> 21 to prime the pump - after that it\'s automatic). 22 While you are there, make a note of the number in the url, 23 which is your user number - you\'ll need it. 24 25 <p>Once you have uploaded your favorites.xml into bblog/compiled_templates and chmod 777\'d it you 26 can put {blogroll userid=1234} in your template. Your userid being you blo.gs userid.'; 27 28 return array ( 29 'name' =>'blogroll', 30 'type' =>'function', 31 'nicename' =>'Blogroll', 32 'description' =>'Displays a blo.gs blogroll', 33 'authors' =>'phil ringnalda', 34 'licence' =>'Free', 35 'help' => $help 36 ); 37 } 38 39 40 function smarty_function_blogroll($params,&$bBlog) { 41 // ( todo: less/no globals! ) 42 global $blogroll_open_tags, $blogroll_temp, $blogroll_current_tag, $blogroll_weblog_index; 43 global $blogroll_close_tags; 44 global $blogroll_html_header, $blogroll_html_footer; 45 46 if(is_numeric($params['userid'])) $userid = $params['userid']; 47 else return "<p>You need to set your blo.gs user id like : {blogroll userid=1234}"; 48 ob_start(); 49 ?> 50 <script type="text/javascript"> 51 /* called by the blogroll select list produced by blogroll.php, 52 in a DOM-compliant browser creates a link and clicks it to 53 set the referrer, otherwise just changes location.href */ 54 function gothere(where) { 55 if(document.createElement){ 56 newLink = document.createElement("A"); 57 if (newLink.click){ 58 newLink.href = where.options[where.selectedIndex].value; 59 theBod = document.getElementsByTagName("BODY"); 60 theBod[0].appendChild(newLink); 61 newLink.click(); 62 } 63 else{ 64 location.href = where.options[where.selectedIndex].value; 65 } 66 } 67 else { 68 location.href = where.options[where.selectedIndex].value; 69 } 70 } 71 </script> 72 <?php 73 74 // local filename 75 // we know that compiled_templates will always be writable 76 $blogroll_xml_file = BBLOGROOT.'cache/favorites.xml'; 77 78 // remote file url 79 $blogroll_xml_source = 'http://blo.gs/'.$userid.'/favorites.xml'; 80 // something that will always appear in the remote file if it returns any of your favorites 81 $blogroll_xml_test = 'weblogUpdates'; 82 83 // fresh enough to use? give it a sniff 84 if ( filemtime($blogroll_xml_file) < (time()-3900) ) { // just over an hour 85 if ( $blogroll_local_fq = fopen($blogroll_xml_file,"w") ){ 86 $blogroll_remote_fp = fopen($blogroll_xml_source,"r"); 87 $blogroll_remote_data = fread($blogroll_remote_fp, 100000); 88 if (stristr($blogroll_remote_data, $blogroll_xml_test)){ 89 if ($blogroll_remote_fp && $blogroll_local_fq){ 90 fwrite($blogroll_local_fq,$blogroll_remote_data); 91 } 92 } 93 fclose($blogroll_remote_fp); 94 fclose($blogroll_local_fq); 95 } 96 } 97 98 // forget the old filemtime 99 clearstatcache(); 100 101 // what to write before the first link or option 102 $blogroll_html_header = '<form action=""><select onChange="gothere(this)" class="selectmenu">'; 103 $blogroll_html_header .= '<option value="">' . date("n/d g:ia",filemtime($blogroll_xml_file)) . '</option>'; 104 105 // what to write after the last link or option 106 $blogroll_html_footer = '</select></form>'; 107 108 109 $blogroll_open_tags = array( 110 'WEBLOGUPDATES' => '<WEBLOGUPDATES>', 111 'WEBLOG' => '<WEBLOG>'); 112 113 $blogroll_close_tags = array( 114 'WEBLOGUPDATES' => '</WEBLOGUPDATES>'); 115 116 // declare the character set - UTF-8 is the default 117 $blogroll_type = 'ISO-8859-1'; 118 119 // create our parser 120 $blogroll_xml_parser = xml_parser_create($blogroll_type); 121 122 // set some parser options 123 xml_parser_set_option($blogroll_xml_parser, XML_OPTION_CASE_FOLDING, true); 124 xml_parser_set_option($blogroll_xml_parser, XML_OPTION_TARGET_ENCODING, $blogroll_type); 125 126 // this tells PHP what functions to call when it finds an element 127 // these funcitons also handle the element's attributes 128 xml_set_element_handler($blogroll_xml_parser, 'blogrollStartElement','blogrollEndElement'); 129 130 131 if ($blogroll_fp = @fopen($blogroll_xml_file, 'r')) { 132 // loop through the file and parse baby! 133 while ($blogroll_data = fread($blogroll_fp, 4096)) { 134 if (!xml_parse($blogroll_xml_parser, $blogroll_data, feof($blogroll_fp))) { 135 die(sprintf( "XML error: %s at line %d\n\n", 136 xml_error_string(xml_get_error_code($blogroll_xml_parser)), 137 xml_get_current_line_number($blogroll_xml_parser))); 138 } 139 } 140 } 141 else { 142 143 echo"<option value=''>Temporarily 404'd</option>"; 144 } 145 146 xml_parser_free($blogroll_xml_parser); 147 $o = ob_get_contents(); 148 ob_end_clean(); 149 return $o; 150 151 } 152 function blogrollStartElement($parser, $name, $attrs=''){ 153 global $blogroll_open_tags, $blogroll_temp, $blogroll_current_tag, $blogroll_weblog_index; 154 $blogroll_current_tag = $name; 155 if ($format = $blogroll_open_tags[$name]){ 156 switch($name){ 157 case 'WEBLOGUPDATES': 158 //starting to parse 159 $blogroll_weblog_index = -1; 160 break; 161 case 'WEBLOG': 162 //indivdual blog 163 $blogroll_weblog_index++; 164 $blogroll_temp[$blogroll_weblog_index]['name'] = htmlentities(addslashes((strlen($attrs['NAME']) > 19) ? substr($attrs['NAME'], 0, 17) . "..." : $attrs['NAME'])); 165 $blogroll_temp[$blogroll_weblog_index]['url'] = $attrs['URL']; 166 break; 167 default: 168 break; 169 } 170 } 171 } 172 173 function blogrollEndElement($parser, $name, $attrs=''){ 174 global $blogroll_close_tags, $blogroll_temp, $blogroll_current_tag; 175 if ($format = $blogroll_close_tags[$name]){ 176 switch($name){ 177 case 'WEBLOGUPDATES': 178 blogrollWriteLinks(); 179 break; 180 default: 181 break; 182 } 183 } 184 } 185 186 187 function blogrollWriteLinks(){ 188 global $blogroll_temp, $blogroll_html_header, $blogroll_html_footer; 189 echo "<script type=\"text/javascript\">\n"; 190 echo "document.write('$blogroll_html_header');\n"; 191 for($i = 0; $i < sizeof($blogroll_temp); $i++){ 192 echo "document.write('<option value=\"" . $blogroll_temp[$i]['url'] . "\">" . $blogroll_temp[$i]['name'] . "</option>');\n"; 193 } 194 echo "document.write('$blogroll_html_footer');\n"; 195 echo "</script>\n"; 196 echo "<noscript>\n"; 197 for($i = 0; $i < sizeof($blogroll_temp); $i++){ 198 echo "<a href=\"" . $blogroll_temp[$i]['url']."\">" . $blogroll_temp[$i]['name'] . "</a><br>\n"; 199 } 200 echo "</noscript>\n"; 201 } 202 203 204 205 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |