Wednesday, October 30, 2013

Find Base Path using PHP

Find base url path and absolute URL

define('ABSPATH', str_replace('\\', '/', dirname(__FILE__)) . '/');

$tempPath1 = explode('/', str_replace('\\', '/', dirname($_SERVER['SCRIPT_FILENAME'])));
$tempPath2 = explode('/', substr(ABSPATH, 0, -1));
$tempPath3 = explode('/', str_replace('\\', '/', dirname($_SERVER['PHP_SELF'])));

for ($i = count($tempPath2); $i < count($tempPath1); $i++)
    array_pop ($tempPath3);

$urladdr = $_SERVER['HTTP_HOST'] . implode('/', $tempPath3);

if ($urladdr{strlen($urladdr) - 1}== '/')
    define('URLADDR', 'http://' . $urladdr);
else
    define('URLADDR', 'http://' . $urladdr . '/');

unset($tempPath1, $tempPath2, $tempPath3, $urladdr);

Wednesday, October 9, 2013

Filter an array of objects using object's property

Iterate through the array and return true or false based on the condition

$new_array = array_filter($array, function($obj){
    if (isset($obj->admins)) {
        foreach ($obj->admins as $admin) {
            if ($admin->member == 11) return false;
        }
    }
    return true;
});

Disable Native tooltip in HTML with help of JQuery

This will remove the title attribute on mouseover and then adds the title back on mouse out.

$(document).ready(function() {
    $('[title]').mouseover(function () {
        $this = $(this);
        $this.data('title', $this.attr('title'));
        // Using null here wouldn't work in IE, but empty string will work just fine.
        $this.attr('title', '');
    }).mouseout(function () {
        $this = $(this);
        $this.attr('title', $this.data('title'));
    });
});


Friday, August 30, 2013

List of all RSS tags that can be applied

ElementDescription
<author>Specifies the email address of the author of an RSS item.
<category>Specifies a category for an entire RSS feed or for individual RSS items.
<channel>Required. Describes an RSS feed with a title, description, and a URL where the RSS can be found.
<cloud>Sets up processes that are automatically notified when a feed has been updated.
<comments>Specifies a URL where comments about an RSS item can be found.
<copyright>Sets copyright information for an RSS feed.
<description>Required. Sets a description for an RSS feed/item.
<docs>Specifies a URL where the documentation for the RSS version used in the RSS file can be found.
<enclosure>Specifies a media file to be included with an RSS item.
<generator>Specifies the program used to create your RSS feed.
<guid>Stands for Globally Unique Identifier. Sets a string that uniquely identifies an RSS item.
<image>Specifies an image to be displayed with an RSS feed (must be gif, jpeg, or png).
<item>Required. Sets items in an RSS feed.
<language>Specifies the language your RSS feed is written in.
<lastBuildDate>Specifies the most recent time the content of an RSS feed was modified.
<link>Required. Specifies the URL where an RSS feed/item content can be found.
<managingEditor>Specifies the email address of the editor of the content of the feed.
<pubDate>Specifies the publication date for an RSS feed/item.
<source>Specifies the source of an RSS item (if it came from another RSS feed)
<skipDays>Specifies the days of the week when feed readers should not update an RSS feed.
<skipHours>Specifies the hours of the day when feed readers should not update an RSS feed.
<textInput>Specifies a textbox to be displayed with an RSS feed.
<title>Required. Sets the title of an RSS feed/item.
<ttl>Stands for Time To Live. Specifies how many minutes your RSS feed can stay cached before it is refreshed.
<webMaster>Specifies the email address of the webmaster of an RSS feed.

Joomla find current page URL with query string

$uri = & JFactory::getURI();
$pageURL = $uri->toString();
echo $pageURL;


This will find the absolute path, but will not fetch query string
$pageURL = JURI::current();
echo $pageURL;


Thursday, August 8, 2013

Find whether the element in in array JQuery

Use jQuery inArray function

jQuery.inArray('value_to_find', array_var);

Delete a specific element in Javascript Array

TO delete a particular element in javascript array, find the index of that element and the use splice method

For example:

var sample_array = ['one', 'two', 'three'];
var index = sample_array.indexOf(id);
sample_array.splice(index, 1);

Note ; Splice method can be used other different cases of accessing and deleting element with help of parameters. Refer Splice() reference.