Skip to main content

Posts

Joomla ARTIO SEF set default Itemid for new posts

A small hack to set the default Itemid for new posts added into the admin panel can be done at 2 places in the file:  components/com_sef/joomsef.php Line: 1462                     if (isset($Itemid) && ($Itemid != '')) {                         $col = ', `Itemid`';                         $val = ", '171'";                      // Itemid of the menu item, which is included for almost all modules in our site                     } Line: 1567  ...

Joomla jquery conflicts

Sometimes, we face certain jquery conflicts in Joomla. These can be avoided by using jQuery instead of $ in your code. For example, instead of: $(function() {         $( "#tabs" ).tabs();     }); Use this: jQuery(function() {         jQuery( "#tabs" ).tabs();     }); And in your template index (or head includes script file), add a js file (noconflict.js) with just this content: jQuery.noConflict(); For example: $this->addScript($this->baseurl."/templates/".$this->template."/js/jquery-1.7.1.js"); $this->addScript($this->baseurl."/templates/".$this->template."/js/noconflict.js");

Joomla redirection

Example of URL Redirection in joomla: Suppose the user visits our component view page without logging in. Then we want to force the user to login page (if he is not already logged in) and then redirect back to our page after logging in, and show a custom logout button. This is a sample code in our component view: <?php $user =& JFactory::getUser(); global $mainframe; if($user->id == 0) { $return_url = 'index.php?option=com_comments'; $return_url = urlencode(base64_encode($return_url)); $redirect_url = '&return='.$return_url; $login_url = 'index.php?option=com_user&view=login'; $finalUrl = $login_url . $redirect_url; $mainframe->redirect( $finalUrl, 'Please login or register before you post comment' ); } else {  ?> <table width="800"> <tr><td><?php echo 'Welcome <b>'.$user->name; ?></b></td> <td align="right"> <form id="l...

Detecting the flash player version

If a user is using a browser with a flash player that is not upgraded, we can show him a message to upgrade his flash player.... using the swfobject javascript. The below code can show the upgrade message over the video, which is run using the jwplayer. <html> <head> <script type='text/javascript' src='jwplayer.js'></script> <script type="text/javascript" src="swfobject.js"></script> </head> <body> <div id="video_player"></div> <script type="text/javascript">     var so = new SWFObject('player.swf','flashContent','280','240','11');     so.useExpressInstall('expressInstall.swf');     so.addParam('allowfullscreen','true');     so.addParam('allowscriptaccess','always');     so.addParam('bgcolor','#FFFFFF');     so.addParam('allowfullscreen','true...

php debugging

The simplest way to debug our php code is to write the data to a log file. For example, this code prints an array to a text file.... <?php $myFile = "logFile.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = '';                foreach($elem as $k=>$v) $stringData .= $k.'=>'.$v."\n";                fwrite($fh, $stringData); fclose($fh); ?> Dont forget to view the file in its stored location...

php array to xml example

This is an example of generating an xml output format from the database. This code is creating a sample rss feed from the joomla articles (which can be added to a rss.xml file). <?php     $dbhost = "localhost";     $dbuser = "root";     $dbpass = "";     $dbname = "joomla";     mysql_connect($dbhost,$dbuser,$dbpass);     mysql_select_db($dbname);     mysql_query("SET NAMES 'utf8'"); // to get proper format         $sql = "SELECT id, title, alias, title_alias, metadesc FROM `jos_content`     where catid=12 limit 3";     $q   = mysql_query($sql) or die(mysql_error());     $xml = "";     while($r = mysql_fetch_array($q)){       $xml .= "<item>";       $xml .= "<title>".trim($r['title'])."</title>";  ...

php validate image type

You can validate image in php, this way: <?php     $img = "banner.gif"; // an image     $info = getimagesize($img);     print image_type_to_mime_type($info[2]); ?> The outout will generally be: image/jpeg or image/gif or image/png But if it is: application/octet-stream, then the file is not an image.