Friday, May 14, 2010

Get Last Value using PHP explode

 $hostname = "http://localhost/test/123.jpg";
                                 $expname = explode ("/", $hostname);
                                 // Point to the last element of array
                                 $lastV =  end($expname);
                                 // Get the current element of array
                               $lastV =  pos($expname);

Thursday, May 6, 2010

How to make onclick automatically through onload function

$().ready(function() {
$('#someLinkId').click();
});

or 

$().ready(function() {
$('#someLinkId').trigger("click");
});

Wednesday, May 5, 2010

Google address search & recursion sample

function address_search() {
global $languageCode; //search result in English/deutch/..etc., lang
//for English - "en" is d code

//search key from the form
$inAddr = $_REQUEST['address'];
//echo 'inn';exit;
$items = array();
$code = strtolower($languageCode);
if(!$code) $code = 'en';
$googleCode = 'xyz..';//here add ur google api key
if($inAddr) {
$json = json_decode(file_get_contents('http://maps.google.com/maps/geo?output=json&oe=utf8&sensor=false&hl='.$code.'&key='.$googleCode.'&q='.urlencode($inAddr)));
if(!empty($json->Placemark)){
foreach($json->Placemark as $value){
if(!empty($value->AddressDetails)) {
$address = getAddressDetails($value->AddressDetails);
$items[$address] = $address;
}
}
}
}else {
//echo 'else';
}
//print drupal_to_js($items);
// exit;
echo '
';print_r($items);exit;
}

function getAddressDetails(&$addressDetails) {
static $country;
static $state;
static $city;
static $zipCode;
static $street;
if(!empty($addressDetails) && count($addressDetails) > 0 && @is_object($addressDetails)) {
//echo '
';print_r($addressDetails);exit;
foreach ($addressDetails as $addrKey => $addrVal) {
//echo $addrKey.'@@
';
switch (strtolower($addrKey)) {
case 'addressdetails':
//getAddressDetails($addrVal);
break;
case 'country':
$country = $addrVal->CountryName;
//echo '
';
//getAddressDetails($addrVal);
break;
case 'administrativearea':
$state = $addrVal->AdministrativeAreaName;
//getAddressDetails($addrVal);
break;
case 'subadministrativearea':
$street .= $addrVal->SubAdministrativeArea;
break;
case 'locality':
$city = $addrVal->LocalityName;
//getAddressDetails($addrVal);
break;
case 'thoroughfare':
$street = $addrVal->ThoroughfareName;
//getAddressDetails($addrVal);
break;
case 'dependentlocality':
$street = ' '.$addrVal->AddressLine[0];
//getAddressDetails($addrVal);
break;
case 'postalcode':
$zipCode = $addrVal->PostalCodeNumber;
//getAddressDetails($addrVal);
break;
default:
break;
}
if(!empty($addrVal) && @isset($addrVal)) {
//echo '
---';print_r($addrVal);exit;
getAddressDetails($addrVal);
}
}
}
return $addrKey = $street.', '.$city.', '.$state.', '.$country.', '.$zipCode;
}

Weird gwProxy code is inserted in WYSIWYG textareas


Weird gwProxy code is inserted in WYSIWYG textareas

 



When I edit a textarea that has a WYSIWYG editor like FCKeditor or JCE Editor 
a code is inserted at the end. It happened to me with websites using drupal, but it seems it also happens with sites using Joomla and other CMS and blogs 
This is the code:
It does not happen with IE or Safari or when the textarea is not using one of the editors.
This is the code:
It does not happen with IE or Safari or when the textarea is not using one of the editors
You can start Firefox in Safe Mode to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes). 
See Troubleshooting extensions and themes 
If it does work in Safe-mode then disable all your extensions and then try to find which is causing it by enabling one at a time until the problem reappears. 
You can use "Disable all add-ons" on the Safe mode start window. 
You have to close and restart Firefox after each change (File > Exit).


Note: Problem add on  is -> Browser Highlighter was the Bugger... Remove this addon

 

 

Tuesday, May 4, 2010

serialize and unserialize in PHP

<?php 
$a = array();  
$a[0] = "blah"
 $a[1] =& $a
 $a[1][0] = "pleh"; // $a[0] === "pleh"  
$b = unserialize(serialize($a));  
// $b[0] == "pleh", $b[1][0] == "pleh"
$b[1][0] = "blah"; 
?>

now $b[1][0] == "blah", but $b[0] == "pleh"
after serializing and unserializing, slice 1 is no longer a reference to the array itself... I have found no way around this problem... even manually modifying the serialized string from
'a:2:{i:0;s:4:"pleh";i:1;a:2:{i:0;s:4:"pleh";i:1;R:3;}}'
to
'a:2:{i:0;s:4:"pleh";i:1;R:1;}'

to force the second slice to be a reference to the first element of the serialization (the array itself), it seemed to work at first glance, but then unreferences it when you alter it again, observe:

<?php
    $testser
= 'a:2:{i:0;s:4:"pleh";i:1;R:1;}';

   
$tmp = unserialize($testser);

   
print_r($tmp);

    print
"\n-----------------------\n";

   
$tmp[1][0] = "blah";

   
print_r($tmp);
 
?>

outputs:
Array
(
    [0] => pleh
    [1] => Array
 *RECURSION*
)

-----------------------
Array
(
    [0] => pleh
    [1] => Array
        (
            [0] => blah
            [1] => Array
                (
                    [0] => pleh
                    [1] => Array
 *RECURSION*
                )

        )

)

Show something only on home page in WordPress

Show some Contents only on home page in WordPress 
 
Here is the solution to show content only in home page 
 
<?php if( is_front_page() ) : ?>
     ///Your Content Here 
<?php endif;?>



Monday, May 3, 2010

Firefox Add-ons for Web Developers & Designers

    ffaddons.PNG
Firefox has cool add-ons which make the job of website designers and developers much easier. Here is our list of 30+ excellent Firefox add-ons that every web developer and designer should know about.
CSS
Aardvark (Aardvark) – A cool extension for web developers and designers, allows them to view CSS attributes, id, class by highlighting page element individually.
chromEdit – Alter the appearance of any page by editing CSS and Javascript files with this extension.
CSSMate – Firefox extension to edit CSS files.
CSS validator – Check the validity of your webpage using this CSS validator extension.
CSSViewer – See the CSS properties of page elements with this extension.
EditCSS – Play around with loaded CSS, Web Developer extension also provides this functionality.
IE Tab – Designers and developers can view their CSS projects on Internet Explorer () using this extension.
Style Sheet Chooser II – Users can pick and choose alternate style sheets for a website.
Debugging and Analysis
    firebug.PNG
FireBug – A console for debugging JavaScript, HTML, and Ajax code snippets.
HTML Validator – Cool extension to validate web pages with HTML standards of W3C.
JavaScript Debugger – JavaScript debugging extension enables a strong debugging environment.

Link Checker
– Check the links on a webpage for validity. Color to each link explains its current status.

Load Time Analyzer
– View detailed graphs of the loading time of web pages in firefox. The graphs display events like page requests, image loading times etc.
View Dependencies – Find out all files that were loaded in a webpage with the view dependencies tab in page info.
Others
    xul.PNG

Clipmarks
– Easily save portions of webpage with this extension.

Codetech
– Excellent extension for web page designers, codetech is a web page editor with the look and feel of Dreamweaver.

ColorZilla
– A nice extension for web designers and developers. Colorzilla helps users to select colors which can be adjusted and put in any other program.
FirePHP – Find out what PHP () code in the backend does to pages on display in Firefox browsers.

Flash Switcher
– Use this extension to avoid reloading between flash plugins.

Greasemonkey – Control any aspect of web page behavior by adding Javascript code to any webpage using this Firefox extension.

Measureit
– Users can calculate the measurement specifications of tables, paragraphs on internet.

Platypus
– One of the best Firefox extensions for modifying a webpage. Users can modify a webpage, save their changes as a Greasemonkey script and their saved page would be loaded the next time they visit the page.

Poster
– A must have tool for web developers enabling them to interact with web services and other web resources.

Professor X
– Check out the contents of the head of page without getting into source code.
Screen grab – Capture screenshot of any webpage and save it as an image file with this extension.
TestGen4Web – Save the webpage activities users (entry of text, web page clicks) in xml file. These actions can later on be replayed and converted to scripts for automated test tools.
View Source Chart – View the source code of any webpage as Firefox sees it.

Web Developer
– Add a menu of various web development tools with web developer extension.

Saturday, May 1, 2010

How to Delete Test Orders from Magento

Deleting your test orders currently requires running a script directly on your Database. Make sure you fully backup your database before doing anything! This script will delete all orders in the database and reset all order counters!



SET FOREIGN_KEY_CHECKS=0;
TRUNCATE `sales_order`;
TRUNCATE `sales_order_datetime`;
TRUNCATE `sales_order_decimal`;
TRUNCATE `sales_order_entity`;
TRUNCATE `sales_order_entity_datetime`;
TRUNCATE `sales_order_entity_decimal`;
TRUNCATE `sales_order_entity_int`;
TRUNCATE `sales_order_entity_text`;
TRUNCATE `sales_order_entity_varchar`;
TRUNCATE `sales_order_int`;
TRUNCATE `sales_order_text`;
TRUNCATE `sales_order_varchar`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;
ALTER TABLE `sales_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;
-- reset customers
TRUNCATE `customer_address_entity`;
TRUNCATE `customer_address_entity_datetime`;
TRUNCATE `customer_address_entity_decimal`;
TRUNCATE `customer_address_entity_int`;
TRUNCATE `customer_address_entity_text`;
TRUNCATE `customer_address_entity_varchar`;
TRUNCATE `customer_entity`;
TRUNCATE `customer_entity_datetime`;
TRUNCATE `customer_entity_decimal`;
TRUNCATE `customer_entity_int`;
TRUNCATE `customer_entity_text`;
TRUNCATE `customer_entity_varchar`;
TRUNCATE `log_customer`;
TRUNCATE `log_visitor`;
TRUNCATE `log_visitor_info`;
ALTER TABLE `customer_address_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `log_customer` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor_info` AUTO_INCREMENT=1;
-- Reset all ID counters
TRUNCATE `eav_entity_store`;
ALTER TABLE  `eav_entity_store` AUTO_INCREMENT=1;
SET FOREIGN_KEY_CHECKS=1;
 

Followers