Skip to content

Instantly share code, notes, and snippets.

View amilabandara's full-sized avatar

Amila Bandara amilabandara

View GitHub Profile
@amilabandara
amilabandara / gist:bd37dcaf3d01f43c9b8e
Last active August 29, 2015 14:14
Add Bootstrap 3 to Wordpress theme
<?php
//add this function to Wordpress theme function.php file
function loadBootstrap() {
wp_register_script( 'bootstrap-js', 'http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js', array('jquery'), NULL, true );
wp_register_style( 'bootstrap-css', 'http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css', false, NULL, 'all' );
wp_enqueue_script( 'bootstrap-js' );
wp_enqueue_style( 'bootstrap-css' );
}
@amilabandara
amilabandara / gist:1a69e6fec88ec6c2c01f
Created February 5, 2015 12:38
Remove Core Libraries from Joomla
<?php
$doc = JFactory::getDocument();
unset($doc->_scripts[JURI::root(true).'/media/jui/js/jquery.min.js']);
unset($doc->_scripts[JURI::root(true).'/media/jui/js/bootstrap.min.js']);
unset($doc->_scripts[JURI::root(true).'/media/jui/js/jquery-migrate.min.js']);
unset($doc->_styleSheets[JURI::root(true).'/media/jui/css/bootstrap.min.css']);
unset($doc->_styleSheets[JURI::root(true).'/media/jui/css/bootstrap-responsive.min.css']);
unset($doc->_styleSheets[JURI::root(true).'/media/jui/css/bootstrap-extended.css']);
?>
@amilabandara
amilabandara / Joomla-essential-snippets.php
Last active August 29, 2015 14:15
Joomla essentials
<?php
#set variable from view
$this->form->setValue('image_name', null, $this->item->image);
#update dropdown
$('selector').val('value').trigger("liszt:updated");
#call any model from any component , any location
JModelLegacy::addIncludePath (JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_component' . DIRECTORY_SEPARATOR . 'models');
#add jtable if needs to call core functions
@amilabandara
amilabandara / mysql-essencials.sql
Created February 11, 2015 09:35
mysql Essentials
#get age to current date
select timestampdiff(YEAR, dob, curdate()) AS age from table name
@amilabandara
amilabandara / gist:ca90d526ac9af11ee0fe
Created February 19, 2015 06:51
separate first name last name from string
$name = "aaa bbb ccc ddd";
$parts = explode(" ", $name);
$lastname = array_pop($parts);
$firstname = implode(" ", $parts);
echo "Lastname: $lastname";
echo "Firstname: $firstname";
@amilabandara
amilabandara / text.php
Created March 20, 2015 13:44
modified Joomla text.php form field
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
@amilabandara
amilabandara / form-fragment.xml
Last active August 29, 2015 14:17
Joomla sample form definition with custom attributes
<field name="customer_name" label="Customer Name" description="Name of the customer"
type="text"
maxlength="10"
class="input-xxlarge input-large-text disabled_field"
tabindex="1"
/>
@amilabandara
amilabandara / gist:15bd92ede905a397c824
Last active December 17, 2015 06:27
Joomla load module inside article
You will usually want to associate modules with articles in some way. The modules are allocated to module positions and the module positions appear somewhere on the Web page as determined by the template. However, it is sometimes useful to have a module actually embedded within the article. Joomla core provides two ways to do that: loadposition and loadmodule.
Syntax:
{loadposition position[, style]}
{loadmodule module[, title[, style]]}
loadposition
To insert a module inside an article, you publish the module to a position and load that position in the article as follows:
@amilabandara
amilabandara / gist:5b98bafff4caf8c36558
Created October 5, 2015 13:22
stop bandwidth steel
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.mydomain.com/angryman.gif [R,L]
<?php
//add this function to your page
//after creation of file run the function in order to change the permission
function insertPermission($service, $fileId, $value, $type, $role) {
$newPermission = new Google_Service_Drive_Permission();
$newPermission->setValue($value);
$newPermission->setType($type);
$newPermission->setRole($role);
try {