New here? Read Greetings Earthling!

set/get/remove_theme_mod(s): Wordpress, something’s missing!

I was working on a bunch of plugins and realised that Wordpress is missing a function for theme mods (theme related options). Let's say I have a plugin that sets mods on all themes like this: set_theme_mod('mod', 'value); Once you set the value you can retrieve it using get_theme_mod('mod', null); and you can remove it using remove_theme_mod('mod');

These three functions all work on the current theme but a plugin can mod all themes on one blog. Do you start to notice the problem?
Read the rest of this entry »

Scrape Google Images Search Results With PHP

You could use the Ajax Search but I think it will return very few results unlike regular image search which returns 21 images per request.

The previous PHP script I published (on my old blog) to scrape Google Images has been rendered absolete by the JSONish output of images results. So I had to write another one (actually fix the old one) to scrape the JS encoded image objects and return them in a friendly way.  This function returns an array of objects, each being an image with full details.
Read the rest of this entry »

Grant Raw HTML Widgets PHP Awareness | WP 2.8+ Plugin

This is my first Wordpress 2.8 plugin I'm publishing and it does very little ... yet so much. It will allow you to add <?php ... ?> code to Wordpress stock Raw Text Widgets and it will interpret the code for you. It adds eval capabilities to stock text widgets and works only in Wordpress 2.8+.
Read the rest of this entry »

Creating PHP Classes With Dynamic Parameters

I was designing a one-size-fits-all singleton class and function which I will publish after a bit of testing but bumped into a major issue on the way. As we know PHP provides call_user_func_array to call any function with an array of parameters. Unfortunately you can not use such function to create a new class.
Read the rest of this entry »

Opera Unite | No Thanks

Today I installed Opera Unite and quickly removed it as my eyes fell upon the mind bogging logo. I'm pretty sure most of you will make fun of me but ... whatever. I'm Orthodox and this kind of shit does not fly with me.

Notice the 666 sigil. Another 666 sigil sample.

Opera Unite - 666 Sigil

I'm sorry but I won't be using this browser version. No 666 for me here. Hope you make a good choice. To take Satanism all the way ... the 666 is reversed. Woohooo! Superb.

The actual name is great: UNITE. The new age concept of unity / oneness, all together ... lovely. Can it get more blatant than this?

The Blog Post Title

On their news blog you can read this entry: Taking the Web into our own hands, one computer at a time. The title says it all!

PS: Yeah! I'm into the conspiracy theory shit. Too many coincidences ... and we know there's no such thing. The devil lies within details.
If you won't ever visit my blog again I'll understand.

MySQL Functions Stub | Easy Use Of SQL Links (link_identifier)

This function will be used in several scripts I will publish these days so make sure you set it aside. It's meant to make using sql links in mysql functions easy.

Let's say you write a function:

<?php // ------------------------------------------------------------ // function sqlQuery($query, $sqlink = null){ return is_resource($sqlink) ? mysql_query($query, $sqlink) : mysql_query($link); } /* OR */ function sqlQuery($query, $sqlink){ $args = func_get_args(); return call_user_func_array('mysql_query', $args); } // ------------------------------------------------------------ // ?>

As you can see, the above function makes calling mysql_query easy and allows you to choose whether to use a mysql link as 2nd parameter. Problem is if you call mysql_query($query, null); it will fail so you need such a helper to make the optional $sqlink easy to set. The second sample allows the optional $sqlink parameter but needs to be called using call_user_func_array as you can't directly call a function with an optional parameter.

There are more than 1 mysql_ functions that accept an optional (but not nullable) link_identifier parameter.

  1. int mysql_affected_rows
    [ resource $link_identifier ]
  2. int mysql_insert_id
    [ resource $link_identifier ]
  3. int mysql_change_user
    string $user , string $password [, string $database [, resource $link_identifier ]]
  4. string mysql_client_encoding
    [ resource $link_identifier ]
  5. bool mysql_close
    [ resource $link_identifier ]
  6. bool mysql_create_db
    string $database_name [, resource $link_identifier ]
  7. resource mysql_db_query
    string $database , string $query [, resource $link_identifier ]
  8. bool mysql_drop_db
    string $database_name [, resource $link_identifier ]
  9. int mysql_errno
    [ resource $link_identifier ]
  10. string mysql_error
    [ resource $link_identifier ]
  11. string mysql_get_host_info
    [ resource $link_identifier ]
  12. int mysql_get_proto_info
    [ resource $link_identifier ]
  13. string mysql_get_server_info
    [ resource $link_identifier ]
  14. string mysql_info
    [ resource $link_identifier ]
  15. int mysql_insert_id
    [ resource $link_identifier ]
  16. resource mysql_list_dbs
    [ resource $link_identifier ]
  17. resource mysql_list_fields
    string $database_name , string $table_name [, resource $link_identifier ]
  18. resource mysql_list_processes
    [ resource $link_identifier ]
  19. bool mysql_ping
    [ resource $link_identifier ]
  20. resource mysql_query
    string $query [, resource $link_identifier ]
  21. string mysql_real_escape_string
    string $unescaped_string [, resource $link_identifier ]
  22. bool mysql_select_db
    string $database_name [, resource $link_identifier ]
  23. bool mysql_set_charset
    string $charset [, resource $link_identifier ]
  24. string mysql_stat
    [ resource $link_identifier ]
  25. int mysql_thread_id
    [ resource $link_identifier ]
  26. resource mysql_unbuffered_query
    string $query [, resource $link_identifier ]

As you see, these functions need a valid link_identifier as parameter or none at all. NULL is not an option. That's making your choice of mentioning a sqlink parameter or null a bit difficult.
Read the rest of this entry »

Wordpress 2.8 Blows … My Mind

This is their official video. Explains things pretty throughly.


Read the rest of this entry »

Get Wordpress URL From Absolute File Path

I have not found something in Wordpress to give me an URL from a file path. site_url does not work as I need relative path to feed to it so ... I created my own. If it exists .... point it out to me :)

Zone unavailable to unregistered users.
Registration is FREE, quick, painless and worth its weight in gold.

You can use it like this: echo el_wp_fileURL(__FILE__); or like this: echo el_wp_fileURL(dirname(__FILE__).'/images/image.png');

Estimate Domain Age Using PHP & Archive.org

Got a comment today on how to get Domain Age using Archive.org and, as the comment was too flattering to resist ... here it is. It uses the XPath query and it could have been done with RegExp only too. But ... it's a case study.

I think you are aware that this estimates the age. It's not exact as not all sites get scraped / accept scraping from the archive.org robot. More accurate results can be achieved using Whois Domain Age.
Read the rest of this entry »

MultiPart Form Encoding In PHP | POST File Uploads

HTML Forms & Multipart

With POST operations, 99% of the times the data is application/x-www-form-urlencoded which is the format you get from http_build_query. But, when you upload files (large data) you need multipart forms which are built for the big items. So, to upload files using HTML forms, you need to add enctype="multipart/form-data" to your form and use input="file" inputs.

To achieve this with cURL you need to set the file POSTFIELDS like this field => @file_path. But I never enjoy letting others encode my own shit. So I needed to take control here and create a function that can Multipart Encode to a string or a local file. Outputing to a string is good for small data but outputing to a file is good for large data that should not be handled in memory. As cURL accepts INFILE and INFILESIZE for the likes of POSTs and PUTs to send data from a file (not from memory) we can combine the two functions and make file uploads dead easy.
Read the rest of this entry »