Friday, July 27, 2012

Difference between find_in_set and in MySQL

If you are confused with these functions then there is short explanation

They are both used for matching a single value again comma separated multiple values

IN: Works when you are looking for database/column value against commas separated list
e.g. WHERE id IN (1,2,3)

FIND_IN_SET: Works the other way around i.e. when you are looking for a single values against a comma separated list stored in a column
e.g. WHERE FIND_IN_SET('name',namesColumn)
where names is a column having value like ('john,paul,richard')

Thursday, July 26, 2012

HTML is stripped in Joomla component configuration / parameters filter

If you are looking to add HTML anywhere in Joomla and 'text filtering' option in 'global configuration' is failing then here is what you need to do

You need to add a filter='safehtml' in your field tag be it your component field or parameter e.g.

<field menu="hide" name="sharethisbtncode" type="textarea"  filter="SAFEHTML" label="Sharethis Buttons Code" description="HTML buttons code of the buttons needed to be displayed" />

Without it Joomla will use the default and strip HTML.

Also know that it will only work for simple HTML like in this example buttons code, if you are looking for including something like javascript like header of analytics or some other you will need to use filter="RAW"

Following is the list of all the filter options:


case 'RULES': // Used for permissions etc
case 'UNSET': // Does nothing.
case 'RAW': // No Filter.
case 'SAFEHTML': // Filter safe HTML.
case 'SERVER_UTC': // Convert a date to UTC based on the server timezone offset.
case 'USER_UTC': // Convert a date to UTC based on the user timezone offset.
default: // Check for a custom callback filter that you can write


For more details refer to:
http://docs.joomla.org/API16:JForm/filter

Include js in head tag Joomla 2.5

If you are looking for how to include javascript in the head tag of html without having to write it in the template for features like sharethis, Google analytics here is how to

Simply use the following two lines:

$document = &JFactory::getDocument();
$document->addCustomTag('<script type="text/javascript">my javascript</script>');

And it will add javascript to the head tag.

You can also include js/css files by using

$document->addStyleSheet('path');
$document->addScript('path');

Wednesday, July 25, 2012

Broken dead links checker php solution

If you want to know how to check for broken or dead links using php, following is a simple script that uses curl to check broken links, you can run it on your database if you have a table of links that you want to check for possible broken links:


            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_HEADER, true);
            curl_setopt($ch, CURLOPT_NOBODY, true);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $data = curl_exec($ch);
            curl_close($ch);

This sets nobody=true which means it doesn't request for the whole page hence speeding up the link checking. There are plenty of ways within curl to check for broken or redirecting links, I personally use this by putting a simple length check on data variable, if its 0 then it means the link is dead.

i.e.
if(strlen($data)==0)
   echo 'dead link=>'.$url;

You can do something else if you like.

Cheers.

Tuesday, July 24, 2012

[Solved] DIV background color not showing

If you have a div tag that has background-color set but it doesn't show at all because there is dynamic content in it with some further tags that have content in it and hence you can not set a fixed height e.g.

<div class="bgcolorRed">
      <div>...content....</div>
      <dl>.....content....</dl>
</div>

Just simply add 'overflow: hidden' along with you background color in CSS and it will work
i.e.

.bgcolorRed {
     background-color: red;
     overflow: hidden;
}

Hope that helps.

Sunday, July 22, 2012

Technorati API Closed

Technorati was one of the most popular used website few years back but as it started to decline sadly the team also seemed not to care much about it. They closed their API that was widely used by people and developers worldwide in 2009 promising for something new but its been three years and there is nothing which leaves a heavy doubt that probably it won't be coming ever again.

Here is the link where the announced the closure of existing API and announcement of new API and features which never came.
http://technorati.com/developers/

Here is an interesting blog article by another person who mentioned that even the founder of Technorati used the API on his blog and I checked it now and there was nothing of Technorati.
http://blog.programmableweb.com/2010/03/04/technorati-api-disappears-no-longer-representing-the-technorati/

Tuesday, July 3, 2012

[Solution] You are not permitted to use that link to directly access that page Joomla 2.5 Error

If you are having the error "You are not permitted to use that link to directly access that page" on clicking on 'cancel' button in joomla admin inside a component then try the following:


Try selecting a row with a check box and then click edit, once the page loads click cancels, if this doesn't give the error and adding a look to title to edit, something like 


index.php?option=com_myschool&view=student&layout=edit&id=1


and clicking on this and then pressing cancel gives you the error then the following is the quick and easy solution, replace the layout edit with task=subcontrollername.edit and leave rest the same, e.g.

index.php?option=com_myschool&view=student&task=student.edit&id=1
or this also works
index.php?option=com_myschool&task=student.edit&id=1

Note: You will be in a view with plural like views/students/tmpl/default.php but you have to use the subcontroller name of the single one i.e. student.

Adding javascript file in Joomla view file

If you want to use a javascript file in a view file (i.e. myComponent/views/student/tmpl/default.php) you will not be able to inlcude using

<script type="text/javascript" src="" />

As you will see it won't load the file and hence won't work. So to include a file you will need to use something like this:


$document = &JFactory::getDocument();
$document->addScript( 'myfilepath/myjsfile.js' );