Skip to content

Instantly share code, notes, and snippets.

View rdeutz's full-sized avatar

Robert Deutz rdeutz

  • Robert Deutz Business Solution
  • Aachen, Germany
View GitHub Profile
@rdeutz
rdeutz / gist:4444404
Created January 3, 2013 15:46
Something I can't get into my head and remember
// Echo a query
echo nl2br(str_replace('#__','jos_',$query));
@rdeutz
rdeutz / gist:6146981
Created August 3, 2013 16:07
adding form fields on the fly
Manipulation a JForm is easy the best place to add fields is to use the preprocessForm function
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
// Add some needed hidden fields
$fields = array('id','cid');
foreach ($fields AS $field)
{
$element = new SimpleXMLElement('<field></field>');
@rdeutz
rdeutz / gist:6988153
Last active December 25, 2015 13:59
Multilanguage Frontpage check
/**
* frontpage check
*/
$menu = JFactory::getApplication()->getMenu();
$defaultmenuitems = array($menu->getDefault()->id, $menu->getDefault(JFactory::getLanguage()->getTag())->id);
$isFrontpage = in_array($menu->getActive()->id, $defaultmenuitems);
@rdeutz
rdeutz / log_data.php
Created December 19, 2013 14:08
two functions to log $data into a file using JLog
protected function logData($data, $type="ERROR")
{
jimport('joomla.log.log');
$types = array(
'EMERGENCY',
'ALERT',
'CRITICAL',
'ERROR',
'WARNING',
'NOTICE',
@rdeutz
rdeutz / gist:9058277
Last active February 23, 2016 15:00
Show a number of modules form a larger number of modules randomly
<?php
$modlist=array('modpos01','modpos02','modpos03','modpos04','modpos05');
$allMods=count($modlist);
$show=array();
$elephantInCairo=0;
while(count($show) < 4 && $elephantInCairo < 100)
{
$c = rand (0 , $allMods-1);
if (!in_array($modlist[$c], $show))
@rdeutz
rdeutz / gist:9109236
Created February 20, 2014 08:34
TypeHint replacement
public function getRowData(JTable $table)
{
....
}
replacing with:
public function getRowData($table)
{
if (!(get_class($table) == 'JTable' || is_subclass_of($table, 'JTable')))
@rdeutz
rdeutz / gist:9252368
Created February 27, 2014 15:31
FOF: Don't overwrite values in the db when fields are not within the form
class whatModelever extends FOFModel
{
.....
/**
* This method runs before the $data is saved to the $table. Return false to
* stop saving.
*
* @param array &$data The data to save
@rdeutz
rdeutz / remove-scripts
Last active August 29, 2015 14:15
removing scripts from the head
// that is bad hack, I am accessing a by convention as private maked class variable.
// But you can not set the head to an empty array so that is the only way to allow to remove all scripts
// I am adding one script, this should have all the scripts merged into one file
// KEEP IN MIND THAT'S WORKING NOW (VERSION 3.3.6) BUT THAT DOES NOT MEAN IT WILL WORK ALWAYS
$tpath = $this->baseurl.'/templates/'.$this->template;
$scripts = $doc->_scripts;
$doc->_scripts = array();
@rdeutz
rdeutz / gist:dd6f7e4597f288a4628c
Created July 17, 2015 14:09
Joomla CLI script for fixing **something**
<?php
/**
* Cleanup Script
*
* @package ABITDIRTY
* @author Robert Deutz <rdeutz@googlemail.com>
*
* @copyright 2015 Robert Deutz
* @license GNU General Public License version 2 or later
**/
<?php
// ISO-3166-1
$data = array(
4 => array('name' => 'Afghanistan','numeric-codes' => 4,'alpha-2-codes' => 'AF','alpha-3-codes' => 'AFG'),
248 => array('name' => 'Åland Islands','numeric-codes' => 248,'alpha-2-codes' => 'AX','alpha-3-codes' => 'ALA'),
8 => array('name' => 'Albania','numeric-codes' => 8,'alpha-2-codes' => 'AL','alpha-3-codes' => 'ALB'),
12 => array('name' => 'Algeria','numeric-codes' => 12,'alpha-2-codes' => 'DZ','alpha-3-codes' => 'DZA'),
16 => array('name' => 'American Samoa','numeric-codes' => 16,'alpha-2-codes' => 'AS','alpha-3-codes' => 'ASM'),