Alex (SirShurf) Frenkel's Blog

A web log of a PHP professional

PHP 5.4 is out, and here is the list you should be watching

leave a comment »

As of today PHP team has released PHP 5.4.

Since this is a major version here is the list of things you should look at:

    • The break and continue keywords don’t accept variable argument anymore. Consider using a static constant argument.
    • Safe mode is no longer supported. Any application that rely on safe mode may need adjustements in term of security.
    • Salsa10 and Salsa20 hash algorithms have been removed.
    • In Date extension, setting the timezone with the TZ environment variable is no longer supported. The extension will no longer guess the default timezone if none is set, instead it will always fall back to “UTC”.
    • get_magic_quotes_gpc() and get_magic_quotes_runtime() now always return false. set_magic_quotes_runtime() raises an E_CORE_ERROR
    • Non-numeric string offsets – e.g. $a[‘foo’] where $a is a string – now return false on isset() and true on empty(), and produce warning if trying to use them. Offsets of types double, bool and null produce notice. Numeric strings ($a[‘2’]) still work as before. Note that offsets like ‘12.3’ and ‘5 and a half’ are considered non-numeric and produce warning, but are converted to 12 and 5 respectively for BC reasons.
    • Turning null, false or empty string into an object by adding a property will now emit a warning instead of an E_STRICT error.
    • Converting array to string now will cause E_NOTICE warning.
    • Shadowing names of superglobals for parameter names now causes a fatal error.
    • array_combine() now returns array() instead of FALSE when two empty arrays are provided as parameters.
    • call_user_func_array() no longer allows call-time pass by reference.
    • htmlentities() now emits an E_STRICT warning when used with asian characters, as in that case htmlentities() has (and already had before this version) the same functionality as htmlspecialchars().

The following keyword(s) are now reserved and may not be used in function, class, etc. names.

  • trait
  • callable
  • insteadof

The following functions have been removed from PHP :

  • define_syslog_variables()
  • import_request_variables()
  • session_is_registered(), session_register() and session_unregister()
  • mysqli_bind_param(), mysqli_bind_result(), mysqli_client_encoding(), mysqli_fetch(), mysqli_param_count(), mysqli_get_metadata(), mysqli_send_long_data(), mysqli::client_encoding() and mysqli_stmt::stmt()

Have fun coding!

Advertisement

Written by Alex (Shurf) Frenkel

March 2, 2012 at 8:53 am

WPMU Infinite SEO plugin fix

with 7 comments

As you where able to see from my previous post’s I was quite made at some of the development decisions of WPMU stuff and I was stuck with a problem that was not possible (at least I did not know how) to fix.

Well I fixed it and here is the result.
My new plugin was approved by wordpress.org and can be downloaded here: http://wordpress.org/extend/plugins/wpmu-dev-seo-addon/

This plugin fix multibite problems with the description and fixes usage of caption.

Comments are welcomed.

Written by Alex (Shurf) Frenkel

February 22, 2012 at 10:41 pm

WPMU Ultimate Facebook plugin Fix

with one comment

In addition to this post:Problem with UTF, Excepts — AND GOOD CODING PRACTICES!

I have created a fix to Ultimate Facebook:
This fix address next things:
* Facebook OpenGraph fails if the text in description is incorrect – especially in Hebrew
* Current version of the plugin sends in wall post description blog tag line. In my fix I am sending Excerpts.

The plugin can be downloaded at wordpres.org.

http://wordpress.org/extend/plugins/wpmu-dev-facebook-addon/

Written by Alex (Shurf) Frenkel

February 20, 2012 at 9:42 pm

Problem with UTF, Excepts — AND GOOD CODING PRACTICES!

with 2 comments

I am sorry if what I am going to write will offend anybody but after more then 2 days of debugging… I am getting frustrated with this.

I have no problems with plugins not working with Hebrew, since this language is not that common, but for crying out loud, PLEASE pretty PLEASE use common sense when programming!

I will show here simple example of what I mean and this is only an example, unfortunaly the same problem exist in other plugins (I have seen the same general programming problems in Ultimate Facebook too).

This plugin create a description text for the “META-Description” tag.
Now the problem in the current version I faces is that it’s not stripping out “Caption” tags and it’s splitting multi-byte strings in the middle of the letter (usage of strlen which is not multibyte safe).
I am not asking here WHY the programmer not used a built in function to get excerpt of a set length, or added ANY hooks in his plugins!!!

Here is the code used:

First lets go to: wds_onepage.php that is responsible for printing the meta to the client, in it we see next code:

if (is_singular()) {
$metadesc = wds_get_value('metadesc');
if ($metadesc == '' || !$metadesc) {
$metadesc = wds_replace_vars($wds_options['metadesc-'.$post->post_type], (array) $post );
}
}

You can see here that first we try to get metadesc value and if it’s empty we are requesting metadesc value from the option.
Lets trace “wds_replace_vars” to the source, and we find it in wds_core.php
I will not put the full function here to save some space but here is the interesting part:
'%%excerpt%%' => !empty($r['post_excerpt']) ? apply_filters('get_the_excerpt', $r['post_excerpt']) : substr(wp_trim_excerpt($r['post_content']), 0, 155),

We are checking IF excerpt exists if not we will create one using “wp_trim_excerpt” and we will substr (not MB safe!!!).
The first part of the problem is easily fixed here all I need to do is to sit in the “wp_trim_excerpt” hook of WP:

add_filter( 'wp_trim_excerpt', array($objClass,'seo'));
...
function seo($strText){

$strText = strip_shortcodes( $strText );
$strText = strip_tags ( $strText );

return $strText;
}

That way we are getting text only and not all of the HTML junk the plugin is giving GOOGLE.

But now I am getting blank description, so lets trace it further, we have striped the text, and cutted it not MB safe to 155 characters. next things we have is this:

echo "\t".''."\n";

OUCH, now, we are stripping tags and using esc_attr on our cutted text. the first is stupid since the HTML we had was cutted to 155 in the middle so the strip_tags would not work, but that I have fixed using the hook above (I am stripping tags on the original text before the substr call).

But the biggest problem is the esc_attr call, since it’s checking for the CORRECT UTF text, and since we cutted the text in the middle of a letter it is not a VALID UTF!

to fix that lets change the hook above:

add_filter( 'wp_trim_excerpt', array($objClass,'seo'));
...
function seo($strText){

$strText = strip_shortcodes( $strText );
$strText = strip_tags ( $strText );
$strText = apply_filters('the_content', $strText);
$strText = str_replace(']]>', ']]>', $strText);
$excerpt_length = apply_filters('excerpt_length', 55);
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
$strText = wp_trim_words( $strText, $excerpt_length, $excerpt_more );

return $strText;
}

This time I am responsible for the shortening of the text (I am making it only 55 characters to fit in 155 that will be cutted later), and using wp_trim_words in order to have only full words in the description (Google dont like paritial words).

This has taken ceare of the first part the client part, but what about the Admin part?

Well this is the one that got me to write this post, in the admin part for some reason the creation of the text does not uses the same function at all!!!!

The parameter here is $desc in wds-core-metabox.php and is acheaved by this code:

$desc = wds_get_value('metadesc');
if (empty($desc))
$desc = substr(strip_tags($post->post_content), 0, 130).' ...';
if (empty($desc))
$desc = 'temp description';

Now here there is NO hooks and no methods for me to catch.
Currently as of writing this post, I have not yet found an answere of how to bypass this and ANY ideas will be welcomed.

In any way, my fix for this plugin will be availible at this location as soon as wordpress.org approve it:
http://wordpress.org/extend/plugins/wpmu-dev-seo-addon/

Written by Alex (Shurf) Frenkel

February 20, 2012 at 5:22 pm

Gravity Forms Popup Widget updated to version 0.5 – Supports open on button click.

with 16 comments

On the WordPress.org forum I was asked, can my plugin be opened only on pressing a button.

Since it was requested by 2 people I desided to add this functionality so here is an update to version 0.5 of the Gravity Forms Popup Widget Plugin.

Have fun 🙂

Written by Alex (Shurf) Frenkel

February 11, 2012 at 2:27 pm

WPMU MarketPress and “Comments are closed” – or a new WordPress plugin

with 3 comments

Laitly I desided to try and to move form Magento to a something simplier.

Since I had an account on WPMU I desided on MarketPress, a plugin that adds eCommerce to WordPress, but came to a problem that I had a “Comments are closed” on the theme they provided (at first I desided no to make a custom theme)

Searching the forum gave me nothing usefull (except a notification that “it is planned”) so I desided to hack it a bit.

The conclution of this hack us a plugin that re enables a comment on a product listing: WPMU MarketPress Allow Comments

Well, have fun 🙂

Written by Alex (Shurf) Frenkel

February 6, 2012 at 10:36 pm

Zopim Live Chat Addon – WordPress Plugin – Updated

with 3 comments

One of the users of my Zopim Live Chat Addon, activated the addon before he activated the Zopim itself.

What it did was adding a submenu before the menu was created and as such it was not working.

I have added a code that is allways moving this plugin to be the last on the list.

Good luck.

Written by Alex (Shurf) Frenkel

January 12, 2012 at 1:36 am

Zopim Live Chat Addon – WordPress Plugin

with 4 comments

A few weeks ago I have found a nice chat that can be installed in a website.

I called a client that I think can be interested in and we tested the chat on the clients WordPress.

One of the thigs that was missing was an option to exclude special pages from the chat and from that a new plugin came up.

I give you the Zopim Live Chat Addon Plugin (Zopim Live Chat Addon – WordPress Plugin).

P.S. If you consider to get you a new Zopim Live Chat please use my reference for a referal: Zopim Free registration page

Written by Alex (Shurf) Frenkel

December 24, 2011 at 12:30 am

Gravity Forms Popup Widget ver. 0.2

leave a comment »

Per a couple of requests I have updated Gravity Forms Popup Widget to a version 0.2.

The changes in this version are:
* Updated to work with WordPress 3.3.
* Added an option to set a position for the window location on opening.

As a side note, by the help of Andy here is a working installation of the plugin:
http://gatehouserental.com/house-houses-4-bedroom-house-for-rent-in-sawtry-close-to-huntingdon/4053/

Thank you Andy for you link and for your feedback.

Written by Alex (Shurf) Frenkel

December 21, 2011 at 7:03 pm

Ubuntu 11.10 (Oneiric Ocelot) and MySQL Workbench gpl, fix plus deb repository

with 3 comments

Since the install of Ubuntu 11.10 (Oneiric Ocelot) my MySQL Workbench was mostly unusable. I could not open it normally and Query Browser was not accessible. Finally a few days ago a patch was summited to the MySQL forum, but it was for a self compile version only.

Today I found a debian repository that maintains MySQL Workbench gpl and the fix is already implemented there. In order to update it use next commands:

Written by Alex (Shurf) Frenkel

November 7, 2011 at 9:46 am