Skip to content

Instantly share code, notes, and snippets.

@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
{
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: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 ';
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);
<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>
@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
<?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;
diff --git a/components/com_content/models/article.php b/components/com_content/models/article.php
index 081b936..205a3da 100644
--- a/components/com_content/models/article.php
+++ b/components/com_content/models/article.php
@@ -55,6 +55,8 @@
$this->setState('filter.published', 1);
$this->setState('filter.archived', 2);
}
+
+ $this->setState('filter.language', JLanguageMultilang::isEnabled());
--- a/plugins/system/languagefilter/languagefilter.php
+++ b/plugins/system/languagefilter/languagefilter.php
@@ -30,6 +30,8 @@
public function __construct(&$subject, $config)
{
+ parent::__construct($subject, $config);
+
// Ensure that constructor is called one time
self::$cookie = SID == '';

Keybase proof

I hereby claim:

  • I am elinw on github.
  • I am elinwaring (https://keybase.io/elinwaring) on keybase.
  • I have a public key whose fingerprint is 5A0F 7149 F237 2F79 725A 2A99 0381 44C6 B3DA BBB0

To claim this, I am signing this object: