Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* @package Joomla.Site
* @subpackage com_content
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
@elinw
elinw / gist:3074763
Created July 9, 2012 07:15
Replacement for truncate method tracker_item_id=28795
/**
* Method to truncate introtext
*
* The goal is to get the proper length plain text string with as much of
* the html intact as possible with all tags properly closed.
*
* @param string $html The content of the introtext to be truncated
* @param integer $maxLength The maximum number of charactes to render
*
* @return string The truncated string
<field name="address1" type="checkboxes"
label="COM_CONTACT_FIELD_INFORMATION_SUBURB_LABEL"
description="COM_CONTACT_FIELD_INFORMATION_SUBURB_DESC"
multiple="true" default= "(array) blue,red"
>
<option value="red">red</option>
<option value="blue">blue</option>
</field>
if ($lang === 'jp')
{
// Iterate through the terms and test if they contain Chinese.
for ($i = 0, $n = count($terms); $i < $n; $i++)
{
$charMatches = array();
$charCount = preg_match_all('#[\x{4E00}-\x{9FBF}]#mui', $terms[$i], $charMatches);
$charCount += preg_match_all('#[\x{3040–\x{309F}]#mui', $terms[$i], $charMatches);
$charCount += preg_match_all('#[\x{30A0}-\x{30FF}]#mui', $terms[$i], $charMatches);
@elinw
elinw / gist:1443077
Created December 7, 2011 14:48
Case When Example
$db = $this->getDbo();
$query = $db->getQuery(true);
//sqlsrv changes
$case_when = ' CASE WHEN ';
$case_when .= $query->charLength('a.alias');
$case_when .= ' THEN ';
$a_id = $query->castAsChar('a.id');
$case_when .= $query->concatenate(array($a_id, 'a.alias'), ':');
$case_when .= ' ELSE ';
I put this in a layout
jimport('joomla.database.database');
jimport('joomla.database.databasequery');
$this->tablePrefix = '';
$newname = JDatabase::replacePrefix('#__somename');
var_dump($newname);
int(0) int(638) int(0) int(638) int(0) int(143) int(0) int(11) string(8) "somename"
@elinw
elinw / gist:1172723
Created August 26, 2011 04:51
CLI App that gives an infinite loop
<?php
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__));
require_once ( JPATH_BASE.'/libraries/import.php' );
jimport( 'joomla.application.cli' );
class JoomlaRocks extends JCli
{