Archive for the ‘PHP’ Category

TwitterPress 0.1 preview version ready to download!

Friday, July 27th, 2007

TwitterPress is a wordpress plugin which mashup Twitter and your Wordpress blog. TwitterPress was inspired by AlexKing’s Twitter Tools.

 This is a 0.1 preview version, I was suposed to implement more features and enable more options inside it, however some plan changed and I suddenly become very busy these days.(Life is random, isn’t it?) So I have to release this preview version out just in case I was sucked in some works so TwitterPress may be delaied too long.

Features:

TwitterPress 0.1 have following features:

  • Display your twitter friends on your blog, like any other Social Network did
  • Display your friends (on twitters)’s latest update, so you and your reader can easily discover some topics inside your friends network
  • Automatically send twitter when you post new blogs, so your friends will get notified and come to read

I plan to add more in the near future:

  • More widgets, so you have more flexibilities to add twitter friends, latest updates on your blog
  • Lightbox style display of twitter friends on the blog
  • Friend of friends browser in Ajax
  • Add twitter friends directly from blog
  • Integrate twitter account with blog comment users
  • and more…

How it look like:

image

This is a screen shot from my Chinese blog, I put TwitterPress in my right side bar. (see the red arrow pointed part)

How to install:

  • Download TwitterPress (current version 0.1 preview)
  • Decompress into your wordpress’s “wp-content/plugins” directory, make sure the “cache’ directory inside ‘TwitterPress’ directory is writable by your web server (simplest way is set to 777 or ‘a+w’)
    • unzip TwitterPress-x.x.zip
    • chmod 777 TwitterPress/cache
  • In your wordpress admin page’s “plugins” tab, activate TwitterPress plugin
  • Then you will have a new Option tab named “TwitterPress”, setup your Twitter account there
  • Navigate to wordpress admin’s “presentation/widgets” tab, and you will find a “Twitter Press” widget ready to use, drag it to your sidebar.

Download

Thanks

Popularity: 71% [?]

The best analytics plugin I ever seen: Geotrack Plugin (2.0.2)

Monday, July 23rd, 2007

 

Today I found a great wordpress plugin today:

Features:

  • logs every visit on your wordpress blog in your MySQL database
  • automatic cleanup of logs in your MySQL database
  • contains the same information as Apache combined server logs with ip, referrer, method, status, uri, user agent and access time
  • additionally stores geo-ip information with country, ISO country code, city name, latitude and longitude
  • displays a list of current visitors
  • displays a top-10-list of referrers, visited pages, visitors‘ countries and visitors‘ cities
  • has functionality to prevent referrer spamming
  • ip blocking of known referrer spammers
  • contains a set of free (GNU-GPL / Creative Commons) country flags from Wikipedia
  • Google maps integration: shows your visitors‘ locations on world map
  • fast geoip retrieval through local database
  • contains installer and update scripts
  • uses MaxMind GeoLite City
  • see it in action here
  • and of course it’s free to use!

Very cool, very useful and with google maps displaying who si from where…

See it live in my site:

http://dev.robertmao.com/visitors-map/

Download it here!

Popularity: 24% [?]

A elegant simple cache class for PHP 5

Sunday, July 22nd, 2007

I am using a simple cache class for PHP5 by phpguru.

Output Cache

The OutputCache class is used for caching the generated output of your scripts, or certain sections of them. It has Start and End methods, and is used like this:

<?php
if (!OutputCache::Start(”myGroup”, “myID”, 600)) {
// Generate some output (as you do)…
OutputCache::End();
    }

?>

Data Cache

The DataCache is used to cache data structures, as opposed to script output. This allows you to cache the creation of large arrays for example, or the results of slow queries. This is helpful if your pages are rather dynamic, though some areas aren’t. Or in a recently experienced situation of mine: You have one central DB server, and multiple front end webservers. A common setup. If the load is getting high on the database, you might want to move some portion of queries (ORDER BY RAND() is a good example) to the webservers instead of the database server. Thus randomisation (eg using shuffle()) happens on one of 5 webservers, instead of your single resource limited database server. Anyway, some code:

<?php
if (!$data = DataCache::Get(”myGroup”, “myOtherID”)) {
$result = $db->query(”SELECT BIG_ASS_QUERY()”);
DataCache::Put(”myGroup”, “myOtherID”, 600, $result);
    }
// Do something useful with $result
?>

Miscellaneous Bits

There’s a few configuration bits and bobs you can twiddle with if you like twiddling. setPrefix() as you can well imagine sets the prefix used in the cache data filenames. This defaults to “cache_”. setStore() sets where the data files themselves are stored. This defaults to “/dev/shm/”, since this is a convenient way to store the data files in shared memory. If you don’t have this, try changing the path to “/tmp/”. Must be given with a trailing slash.

And last, and least (so as not to be a corny ass), there’s the static variable Cache::$enabled.

Popularity: 9% [?]

A twitter based social network inside wordpress

Sunday, July 22nd, 2007

image

I am now working on an experiment: a wordpress plugin to turn wordpress into a social network, you can have friends lists, the latest updates of friends, the lastest posts of friends in your wordpress page.

This social network is based on Twitter, and it was inspired by AlexKing’s TwitterTools.

I will tweak it these days, when it’s ready I will release it so every one can play with it.

The original idea was here: Twitter+wordpress = SNS enabled wordpress

Popularity: 15% [?]

IP to country/location libraries

Saturday, July 21st, 2007

Save here for future use.

PHP & Java version

Link: http://firestats.cc/wiki/ip2c

IP2C

IP2C is a small library that provides IP to country resolution using a binary file.
The binary file is compiled f2rom ip-to-country free database and takes only about 500kb (the CSV takes about 3.5mb).

License

IP2C is released under the terms GPL v2.

Supports

  • Command line
  • Java
  • PHP

Performance

All tests done on an Athlon XP 3200+.
PHP:

  • No cache: About 1200 searches in a second.
  • Cache: not implemented (Want to help?)

Java:

  • No cache: About 8000 searches/second.
  • Memory cache: About 180,000 searches/second.

Download

ip2c 1.4.3 (Database version : 2007.3.5)

C# version

http://www.extremeoptimization.com/resources/Concept/

Source download: http://www.codeproject.com/csharp/IPLookupOptimise.asp

Popularity: 19% [?]

PHP code to fix invalid UTF-8 data inside a string

Monday, July 16th, 2007

I wrote A wordpress plugin to fix the invalid UTF-8 data inside the feed, in that plugin the core purpose is to  fix invalid UTF-8 data inside a string.

It’s pretty simple to do so in PHP, I learned from here:

the following iconv line gets rid of all invalid UTF-8 characters.

 $t = iconv("UTF-8","UTF-8//IGNORE",$t);

Problem solved ;)

Popularity: 7% [?]

A wordpress plugin to fix the invalid UTF-8 data inside the feed

Monday, July 16th, 2007

Yesterday, I decided to host my feeds with FeedBurner like many bloggers do. There is no problem to create a feed of this blog, however when i tried to create a feed for my Chinese blog, FeedBurner refuse to continue because it said that my feed can’t be validated:

http://feedvalidator.org/check.cgi?url=http%3a%2f%2frobertmao.com%2ffeed

Sorry

This feed does not validate.

line 167, column 77: ‘utf8′ codec can’t decode bytes in position 10676-10678: invalid data (maybe a high-bit character?) [help]

In addition, this feed has issues that may cause problems for some users.
We recommend fixing these issues.

line 115, column 21: description contains bad characters [help]


After I check the error message, it seemed that the problem is from my blog post content, I did copy/paste some text from some other website in some of my posts, but how could I know those text may contain invalid UTF-8 char? It seemed to be a serious problem. :(

I can’t believe that why FeedBurner can’t handle this, since my feed can be read correctly in Firefox, Google Reader, Bloglines, and a bunch of other RSS readers, aggregators. But since it can’t handle, and my feed did have problem to pass validation, it’s my job to fix it.

I wrote a very simple wordpress plugin to fix this problem, it will correct all possible invalid UTF-8 data inside the feed content. After I activate my plugin, my feed can pass the validation correctly, so I have no problem to use FeedBurner any more.

I release this simple wordpress plugin here, just in case someone else have similar problem as I had.

Download: wordpress plugin to fix the invalid UTF-8 data inside the feed

Version: 1.0

Install: Download and unzip the file in your wp-content/plugins directory, and then “activate” the plugin in your admin panel’s “plugins” menu.

Popularity: 18% [?]

Add Google Search box to blog post plugin

Monday, July 16th, 2007

I wrote a new simple wordpress plugin for my own use, but I guess maybe someone else may need it, so I release it here.

This plugin is very simple, it put a google search box right behind your blog post, and it fill this post’s title in the search box for you.  With this search box, you and your reader can search the related information easier, they no longer need to open a window, browse to google and type in some words… now all they need is click the button.

The search box will only show up in single post display, it will not show in front page,  category,  search results, …

This version I  only add standard google search form, in the future, if required, it can be configured to support site search, or google co-op search, and use user’s Adsense account to make some money from the search result.   If anyone think such feature is important, let me know I may add it.

Download Here: Wordpress Plugin - Add Google Search box to blog posts

Version : 0.1

Install:  uncompress it in your wordpress plugin directory, and activate this plugin.

Popularity: 100% [?]

Wordpress MU plugin: Widgetize-AnyHTML, Enable Javascript and any HTML tags in wordpress MU siderbar

Saturday, July 14th, 2007

Wordpress MU is great, however Wordpress MU’s authors think it’s not safe to enable the html tags in the default text widget. Unfortunately, today many excellent widget require Javascript, if we can’t enable Javascript support, those widget will not able to appear in the blog sider bar.

There are some blogs talked about hacking the code to enable HTML tags in the widget, however it’s not a standard way and may not compatible in the next version. That’s the reason why I made this plugin: Widgetize-AnyHTML. With this plugin, you can add anything you want unfiltered in the sidebar…of course AT YOUR OWN RISK, wrong code may break you page and even bring in vulnerabilities.

This is my first wordpress plugin, and actually it’s just changed slightly from Erik’s great “widgetize anything”, which enable you to add any PHP code directly in the siderbar. I found his plugin when I am trying to find out a solution to enable WPMU’s javascript enabled widget support, his plugin is not what I want, but very close, actually I change very few lines to make this plugin. (Note: I am not sure if my plugin’s using Erik’s code has break Erik’s license agreement or not, Erik, if you think I shouldn’t do that, pls. let me know, I will remove it)

Download Here: Widgetize Any HTML Plugin for Wordpress MU

Version: 0.0.1

Install:

Download the zip file uncompress to Wordpress MU’s wp-content/plugin directory, then enable this plugin in the “plugin” menu, you will have some “Widgetize Any HTML” widgets in your “Presentation / widgets” screen. You can set as many as widgets in the “Option / Widgetize Any Html” screen.

Popularity: 36% [?]

Install Lilina 0.7 on PHP 5.0 linux box

Wednesday, June 27th, 2007

Lilina is great open source server side RSS aggregator written in PHP, the latest stable version at this time is 0.7. I just installed it and found some problem.

After install Lilina 0.7 and following it’s INSTALL instruction, it just didn’t work after all:  all the web page is empty with nothing.  I didn’t touch PHP stuff for many years, so just fix this issue by “what I feel”. :)

1. Debug

Fortunately debug PHP is simple, just run those PHP pages in command line, the output will display in console, so I will not have to look inside the logs. The problem quickly show up:

PHP Fatal error:  Cannot redeclare class soapclient in /var/www/html/lilina-0.7/inc/nusoap.php on line 4096

2. Problem

Google it, the problem is clear, because PHP5 already have a class named “soapclient“. A solution was found here.

3. Quick & dirty fix

Quickly browsed the code, the only place use nusoap.php is inc/google.php, this is used for:

Enabling Google Web APIs support:
———————————
lilina is now able to automatically query Google for the title of each item
and show the top 10 results. To do so you must have a “Google Web APIs key” that
you can obtai for free from http://www.google.com/apis/.

I don’t think I need this, so I just edit lib.php, comment out the include of “google.php”,  and search “google” and find the line:

        $out .=   google_get_res($title,0) ;

change it to:

        $out .=  “”; // google_get_res($title,0) ;

Then it works.

Popularity: 10% [?]

Close
E-mail It
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License.