LAMP How To – Open Source At Work

Only Passion Matters

Entries for the ‘Think PHP’ Category

Magento: Removing SSL After Installation

use magento_db;
UPDATE core_config_data SET value = 0 WHERE path=’web/secure/use_in_frontend’;
UPDATE core_config_data SET value = 0 WHERE path=’web/secure/use_in_adminhtml’;
might need to clear the cache and do hard refresh after that.

Magento: Adding Downloadable Product To A Bundle

After googling for ages, I could not find an answer to bundling downloadable product, as in the downloadable product will not appear under the bundle items search section. After some tough digging, I noticed magento community version 1.6 only accepts virtual and simple product in a bundle.
the config is at app/code/core/Mage/Bundle/etc/config.xml, about line 103.
To get [...]

vbulletin: getting user ip behind a proxy

if vbulletin is behind a proxy, the ip of the user would be the ip of the proxy server instead of the ip of the user. Instead of hacking the includes/class_core.php file we can install the runkit extension, ie http://www.php.net/manual/en/runkit.installation.php
then create a plugin consisting of the following:

$vbulletin->ipaddress = $vbulletin->alt_ip;
runkit_constant_redefine(‘IPADDRESS’, $vbulletin->ipaddress);

change primary domain name in wordpress

sometimes it may be necessary to change the domain name of your wordpress blog. Instead of reinstalling wordpress, we can modify the current database to accomodate the changes. run the following query:
Back up your db. then

use wordpress_db;
update wp_site set domain=’newdomain.com’;
update wp_blogs set domain=’newdomain.com’;
update wp_options SET option_value = ‘http://newdomain.com’ WHERE wp_options.option_id =1;
update wp_options SET option_value = [...]

simple function to truncate string to closest word

as the title implies… this is in wordpress though. preg_replace is the trick here.
function trim_excerpt() {
$text = get_the_excerpt();
$limit = 200;
if (strlen($text) > $limit) {
$text =  preg_replace(‘/\s+?(\S+)?$/’, ”, substr($text, 0, $limit)).’… ‘;
}
return $text;
}

add_filter(“the_excerpt”, “trim_excerpt”);