LAMP How To – Open Source At Work

Only Passion Matters

uploading files outside of wordpress admin

if i have 4 images (called add_image1, add_image2, add_image3 and add_image4) to be uploaded outside of wordpress admin and wants to use wordpress file uploading functionality,

if (isset($_FILES)) {
for ($i = 0; $i < 4; $i ++) { $name = ‘add_image’.$i; if ($_FILES[$name]['size'][$k] > 2000000) {
exit(‘Each image uploaded must be less than 2 Megabytes.’);
}
elseif (!$_FILES[$name]['error']) {
require_once(ABSPATH . “wp-admin” . ‘/includes/image.php’);
require_once(ABSPATH . “wp-admin” . ‘/includes/file.php’);
require_once(ABSPATH . “wp-admin” . ‘/includes/media.php’);
$id = media_handle_sideload( $_FILES[$name], $post_id, ‘uploaded image ‘.$i );
$content .= ‘<img src=”‘.wp_get_attachment_url($id).’” alt=”" />’;
}
}
}

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Technorati
  • LinkedIn
  • MySpace
  • Slashdot
  • TwitThis
  • Yahoo! Buzz

Steps to take to upgrade vbulletin

Assuming you are running vbulletin upgrade in staging before production and that staging has a different domain name… Here are some useful tips:

I use chrome as the preferred browser when doing vbulletin upgrades. firefox is notorious for caching which might result in hours of debugging time.

1. Backup Database.

2. login to /admincp and put the site in maintenance mode, ie options -> turn vbulletin off

3. Export production db and update staging DB with that of production.

4. Deploy code changes to staging.

5. Run queries in staging,

// your staging homepage might be something like http://yoursite/forums

// update forum domain
mysql_query("UPDATE `setting` SET `value` = 'staging_forum_homepage' WHERE `varname` = 'bburl';");

mysql_query("UPDATE `setting` SET `value` = 'staging_forum_homepage' WHERE `varname` = 'homeurl';");

// update forum title
mysql_query("UPDATE `setting` SET `value` = 'Your Forums (Staging)' WHERE `varname` = 'bbtitle';");

// update links in posts
mysql_query("UPDATE post SET pagetext = REPLACE(pagetext,'production_forum_homepage', 'staging_forum_homepage');");

6. In staging,

copy do_not_upload/tools.php (found in do_not_upload folder) to forums_root/admincp

click on “reset cookie domain”

remove tools.php in forum_root/admincp after that

login to admincp -> settings -> options -> Site name /URL/Contact Details. Change all options to reflect the staging url.

7. Now is the crucial part: If you are running multiple servers in load balancing environment, change your host file to point to just one server. Then go to forum_root/install/upgrade.php and enter the customer number from vbulletin. Then upgrade. If this doesn’t work for whatever reason, backup plan: run the upgrade from command line, ie cd forum_root/install/;php -f upgrade.php. After that, run the upgrade from the web again.

8. In admincp, to upload new styles, templates -> upload styles -> select “create a new style” and “ignore style version”

9. In To switch styles, options -> style and language -> choose style. Verify the changes in the homepage.

10. To upload new plugins or products, manage product -> add/import product -> upload plugin -> set “allow overwrite” to yes.

11. Go back to admincp control panel and run post upgrade instructions.

12. Turn maintenance mode off.

13. Get people to test the website.

To deploy to production, go thru steps 1, 3, 6, 7, 8, 9, 10 and 11 again

other tips: time the upgrade process. Document the upgrading steps on a piece of paper.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Technorati
  • LinkedIn
  • MySpace
  • Slashdot
  • TwitThis
  • Yahoo! Buzz

ruby dependencies in ubuntu

Other than installing rvm and rails. ubuntu users will have to install the dependencies, “rvm requirements” will give you a list like this

/usr/bin/apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion

After that, we need to install readline

rvm package install readline
cd $HOME/.rvm/src/ruby-1.9.x/ext/readline
ruby extconf.rb -- --with-readline-dir="$HOME/.rvm/usr"
make install
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Technorati
  • LinkedIn
  • MySpace
  • Slashdot
  • TwitThis
  • Yahoo! Buzz

Why I think Rails Cannot Be Enterprise Ready

When one uses rails, it is not about just learning a new syntax, it is about embracing a new culture, the culture of “willingness to adapt and change”. You can see this from rails iteration cycle. The amount of change packed into a version update is huge and update happens very often. This is all good but it means that all gems dependencies have to upgraded as well to follow the pace. As such, it is very hard to develop a stable system.

Well, we can lock down a version of ruby, rails and gems for the software but the fast updates of rails will make the developers hungry for upgrade as every update is so exciting… Update is not as challenging if the complexity of the software is low with low gems dependencies, ie perhaps apps like twitter or a simple cms system. Upgrading very complex system like a shopping cart would be very hard. That is why ruby developers run test so frequently as chances of things breaking during an update is high.

I have nothing against rails but the entrepreneur spirit that it embraces makes it hard to create a stable, enterprise application. I would still use rails as a platform to create quick prototypes, demo or simple applications. The turn around would be fast. For complex, enterprise ready applications, I would still prefer java, .net or php.

In that sense, it don’t think that ruby is the language and rails is the framework of the future as many ruby supporters claimed. Rails will still have a fair share in the market but many framework written in other languages will still be there in 5 years time. Many framework will learn from the technologies incubated from the rails playground. I think that programming languages will become more and more diversify, with each having their own supporters.

I would continue doing what I am doing and be really good at it. Whichever language that builds an absolutely stunning application that people cannot live without will win the war.

This is of course just my personal opinion.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Technorati
  • LinkedIn
  • MySpace
  • Slashdot
  • TwitThis
  • Yahoo! Buzz

3rd party ads spacing issues in your website

ads are good but can be annoying at times as they usually bring in some extra html or css that might mess with your layout. take google ads for example, it sometimes inject a fix height and width to an ad even if it doesnt pull in any ads.

so the solution is to implement a custom javascript fix to counter the ads styling:

<script type=”text/javascript”>
jQuery(window).load(function() {
googleFrame = jQuery(‘iframe[id^="google_ads_iframe_"]‘);
googleFrame.each( function () {
if (jQuery(this).contents().find(‘body’).html() == ”) {
jQuery(this).attr(‘height’, ‘0′);
if (jQuery(this).css(‘display’) != ‘none’) {
jQuery(this).closest(‘div’).toggle();
}
}
});
});
</script>

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Technorati
  • LinkedIn
  • MySpace
  • Slashdot
  • TwitThis
  • Yahoo! Buzz