Category Archives: Php

Friday, 19 October, 2007

Modify WP-Cache to avoid caching Password Protected Post

This will allow the post to be seen after password is entered correctly.

Changes are made to wp-cache-phase2.php.

function wp_cache_ob_callback($buffer) {

..

/* we avoid caching incomplete files */

if (is_404() || !preg_match('/(<\/html>|<\/rss>|<\/feed>)/i',$buffer) ) {

$new_cache = false;

return $buffer;

}

// dun cache password protect post <-- add here

global $post;

if (is_single() && !empty($post->post_password)) {

$new_cache = false;

return $buffer;

}

Tags: hacking, Php, WordPress


Posted in WordPress , Php


Sunday, 3 June, 2007

Showing Digg Popular Stories

Digg Popular Stories are now shown at the bottom of some of the categories and browse tag pages.

The categories include Diversion, Game, Science, Sports, Technology, World, Php and Python. The tags include Astronomy, environment, nba, php, python, Microsoft and video.

I wrote python scripts to retrieve the popular stories provided by Digg api and format the data in html, ready to be included in my wordpress pages.

Categories:

Diversion, Game, Science, Sports, Technology, World, Php and Python.

Tags:

Astronomy, environment, nba, php, python, Microsoft and video

Archives: June, July, August, September, October, November, December.

January, February, March, April, May.

Tags: WordPress, Python, Digg, Php


Posted in Php , WordPress , Python


Saturday, 14 April, 2007

Related Tags Navigation added

I am using plugin Simple Tagging. I made a slight modification to STP_RelatedTags and outputRelatedTags functions and uses STP_RelatedTags to show the related tags to the current tag being viewed. Basically, if a post is tagged with A and B, then tag A and B are related.

I also use the below to generate the browse tags path.

Eg. navigate_tags('php+Wordpress') will produce >> php >> Wordpress

The tag navigation is equivalent to the one I used in Sky Explorer for application menu. :)

function get_tags($tag) {

return explode("+", $tag);

}

function navigate_tags($tag) {

$tags = get_tags($tag);

$tagUri = '/tag/';

$link = '';

$tagfmt = '>> <a href="%link%">%name%</a> ';

$tagvars = array("%link%", "%name%");

$nav = '';

foreach ($tags as $t) {

$link .= (($link != '')? '+' : '') . $t;

$nav .= str_replace($tagvars, array($tagUri.$link, $t), $tagfmt);

}

return $nav;

}

Tags: tagging, Php, WordPress


Posted in WordPress , Php


Saturday, 7 April, 2007

Showing Only WordPress Top Categories

My sub-categories links are not working! I decided to show only the top categories on my sidebar. The following describes how I do it:

Modify function get_categories in category.php

  • Add show_top option in $defaults.

    	$defaults = array('type' => 'post', 'child_of' => 0, 'orderby' => 'name', 'order' => 'ASC',
    

    'hide_empty' => true, 'include_last_update_time' => false, 'hierarchical' => 1, 'exclude' => '',

    'include' => '', 'number' => '', 'pad_counts' => false, 'show_top' => false);

  • Add to the sql where criteria if $show_top is true.

    	if ($show_top)
    

    $where .= ' AND category_parent = 0';

  • Modify my sidebar.php

    <?php wp_list_cats('sort_column=name&hierarchical=0&show_top=true') ?>
    

I notice the various variables used for the options (eg. $hierarchical) are never initialized anywhere. There is this odd looking statement extract($r); (see the function documentation here), now, I understand how this works! ;)

Tags: WordPress, Php


Posted in Php , WordPress


Thursday, 29 March, 2007

Zend Gdata PUT request

Reference at Zend_Gdata.

Currently, GData only allow POST as request method and not PUT, issue link

PUT is needed! We can just use the existing post method. :D Here is what I modify (for the time being)

public function post($xml, $uri = null)

{

return $this->request($xml, $uri, 'POST');

}

public function put($xml, $uri = null)

{

return $this->request($xml, $uri, 'PUT');

}

public function request($xml, $uri = null, $method = 'POST')

{

..

$response = $this->_httpClient->request($method);

The original post method is renamed to request with an additional argument $method and also replacing those 'POST' with $method.

Tags: Php


Posted in Php


Thursday, 29 March, 2007

Global variable in Drupal module

There is something different in a variable between a variable in a Drupal module and a variable in a normal php file.

normal php

$_User = "user";

function test() {

global $_User;

..

}

Drupal module

global $_User;

$_User = "user";

function test() {

global $_User;

..

}

In Drupal module, I need the additional global $_User; Why? :?

Tags: Php


Posted in Drupal , Php


Tuesday, 27 March, 2007

Php syntax check

There is an easy way to verify php syntax, which I really need! :)

php -l file

Tags: Php


Posted in Php