Pages

Thursday, August 18, 2011

Image download using CURL - PHP

$url = 'IMAGE PATH URL';
  //$random_no = rand(10000,99999999);  // for random number
  //$file_handler = fopen($random_no.'.jpeg', 'w');  // random number image name
$file_handler = fopen('image1.jpeg', 'w');   // static image name as image1
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_FILE, $file_handler);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_exec($curl);
curl_close($curl);
fclose($file_handler);

Using this code you can download image from server where 'IMAGE PATH URL' is the url of image. Image is generated in jpeg file extension named as image1 or you can use random generated name.

Hope its help you.

Noconflict plugins in Joomla

SC jQuery plugin is used to load jQuery javascript library, and set "no conflict" mode to allow usage with mootools, and other libraries. No conflict mode removes the "$" operator from jQuery, allowing other libraries to use that operator. This plugin is use in joomla 1.5, joomla 1.6 and also in joomla 1.7 .

More usage details for jQuery no conflict mode are available at http://docs.jquery.com/Using_jQuery_with_Other_Libraries

For More detail and download plugin visit @ http://extensions.joomla.org/extensions/core-enhancements/scripts/7230

Wednesday, August 17, 2011

JQuery and Mootools conflicts in Joomla

Mootools and jQuery can conflict each other in joomla, when you load both in your joomla site because they can use same method names, therefore one of both could break.So when you create a nice Template for Joomla 1.5 and you decide to use jQuery, the hell breaks open when implementing:
<jdoc:include type="head" />
This, is because Joomla 1.5 uses MooTools and Caption javascript frameworks, for the backend admin panel, but also some components may require it.

So for no-conflict jQuery wrote the following lines in the top of my index.php template:



$headerstuff = $this->getHeadData();
$headerstuff['scripts'] = array();
$this->setHeadData($headerstuff);

Monday, August 8, 2011

Assign Different Menu for Login user and unregistered user

Sometimes you need to check whether user login or not for assign different condition to both login user and unregistered user in joomla customization. Only you have to write if else condition to check that. For example in joomla site you need to assign different menus for frontend. before login users can see a normal menu but after user login they will see another menu. you can write the code in the template index file and assign different menu.

<?php  
   $user =& JFactory::getUser(); 
   if ($user->get('id') == NULL) {   
?>   
    <jdoc:include type="modules" name="nonregister_menu" 
<?php
   } 
  elseif ($user->get('id') != NULL) {  
?>
   <jdoc:include type="modules" name="loginuser_menu">    
<?php 
   }
 ?> 

How to get current joomla User ID and Username

For joomla starter, sometime we need to get joomla user ID and username to customize in joomla component, plugins or modules. for that we have to write simple code

<?php
    $user =& JFactory::getUser();   
    $usr_id = $user->get('id');   
    echo "Current Login User Id : ".$usr_id;  // this is the log-in user ID :-)   
    
    $usr_name$user->get('username');   
    echo "Current Login User Name : ".$usr_name;  // this is the log-in username :-)  

    //after getting the user ID and username you can run your custom code
?>

Friday, August 5, 2011

Find string between two strings - PHP

This is a little function to find a string between two specified pieces of strings. This could be used to find any string between two strings.

function get_string($string, $start, $end){
 $string = " ".$string;
 $pos = strpos($string,$start);
 if ($pos == 0) return "";
 $pos += strlen($start);
 $len = strpos($string,$end,$pos) - $pos;
 return substr($string,$pos,$len);
}

$fullstring = "Find string between two strings in PHP";
$parsed = get_string($fullstring, "between ", " in PHP");

echo $parsed; 
(result = two strings)

Thursday, August 4, 2011

Assign an smarty variable to a PHP variable

Developer can use PHP code in smarty(.tpl file code) within a {php} block or an {include_php}.

when developer use a {php} block inside a Smarty template developer are inside the Smarty scope (object)
So when
developer need to reference a Smarty method developer would use $this
so when developer assign an smarty variable to a php variable it looks something like this in smarty:

Code:
{php}
   $t = $this->get_template_vars( 'foo' );
{/php}