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}

print_r in Smarty development

{$foo|@print_r}

The @ tells smarty to pass the entire array to the modifier rather than calling the modifier for each element of the array. 


Smarty also print array like php print_r() function: {$foo|@debug_print_var}

Developer may also consider smarty's debug facility (which developer can enable in-template by inserting a {debug} tag).

Wednesday, August 3, 2011

Upload Video in JomSocial

Now, you can upload your video on JomSocial site. Video-related configuration is located under JomSocial Configuration > Media tab.
  • Enable Videos: Enable or disable the videos functionality in JomSocial.
  • Enable guest search: Option to disallow guests from searching videos.
  • Enable profile videos: Allow users to select a video for their profile.
  • Enable videos upload: Enable or disable the videos uploading feature in JomSocial.
  • Video creation limit: Set a limit to creation of videos per user.
  • Delete original videos: If enabled, original videos are deleted once the videos are converted to the appropriate formats.
  • Videos root folder: Set the path to where videos are stored.
  • Maximum video upload size: Set the maximum uploaded video size allowed in Megabytes (MB)
  • FFMPEG Path: Set the absolute path to FFMPEG binary. If the binary is not found, JomSocial will not be able to convert videos into .flv formats.
  • FLVTool2 Path: Set the absolute path to FLVTool2 binary to enable flash video metadata injections.
  • Video Quantizer Scale: Select the video quality from a scale of 1 (Excellent) to 31 (Worst). 5, 9 and 11 are recommended settings.
  • Videos Size: Set the video frame size in width X height format.
  • Custom Command: Specify additional commands for FFMPEG ( Advanced Users )
  • Pseudo streaming: Allow users to skip to specific section of the video.
visit : http://www.jomsocial.com/support/docs/item/759-configuring-video-upload-and-linking.html

Tuesday, August 2, 2011

Second Highest Value SQL query

select max(FIELDNAME)
from TABLENAME
where FIELDNAME not in
(select max(FIELDNAME)
from TABLENAME);

MVC Structure Basics, MVC Architecture, Joomla

For starters, MVC stands for Model, View, Controller. It is a programing structure used in developing web apps. This structure isolates the user interface and backend (i.e. database interaction from each other. A successful implementation of this lets developers modify their user interface or backend with out affecting the other. MVC structure also increases the flexibly of an application by being able to resuse models or views over again). Below is a description of MVC structure.
  • Model: The model deals with the raw data and database interaction and will contain functions like adding records to a database or selecting specific database records.
  • View: The view deals with displaying the data and interface controls to the user with.
  • Controller: The controller acts as the in between of view and model and, as the name suggests, it controls what is sent to the view from the model.
An example of a MVC structure approach would be for a contact form.
  1. The user interacts with the view by filling in a form and submitting it.
  2. The controller receives the POST data from the form, the controller sends this data to the model which updates in the database.
  3. The model then sends the result of the database to the controller.
  4. This result is updated in the view and displayed to the user.
This may sound like alot of work to do. But, trust me; when you’re working with a large application, being able to reuse models or views saves a great deal of time.

Monday, August 1, 2011

SQL Server - An identity feild can have negative seed value and negative increments also

Always everyone will start identity value from 1 and increment by 1. However, an identity column can have negative seed value and can be negatively also incremented. Suppose below table will have 4 rows with id values -100,-101,-102,-103

declare @t table
(
Id int identity(-100,-1),
Col1 int
)
insert into @t values (1),(2),(3),(4)
select * from @t