Showing posts with label joomla. Show all posts
Showing posts with label joomla. Show all posts

Sunday, April 16, 2017

A Joomla CLI script to send database query output as a CSV attachment via email





image from: https://pixabay.com/en/linux-window-terminal-command-154766/

This Joomla CLI script lets you send a DB query output as a CSV attachment via Email.

You need to have a working Joomla website instance with emails setup done.

PHP Joomla CLI Script:
To use this:
1. Open terminal, Browse to Joomla root

cd /var/www/my-joomla-site

2. Execute PHP file 


php cli/joomla-cli-script-email-csv-attachment.php

3. You will see this as o/p on successful email sending 


Email sent

You can also setup cronjob to automate email sending.

Monday, September 14, 2015

Joomla Component Options: How to call custom javascript function before the component options form is posted


Joomla component options
Joomla component options
Ever wondered how to call custom javascript function before the component options form is posted when working with Joomla backend?

So, I had a situation when I wanted to call my own Javascript function before the component options form is submitted in Joomla backend.

So here is a one way that I found.
1. First find the "Save" and "Save and Close" buttons from toolbar
2. Change their "onclick" attributes to call your custom javascript code before form is submitted.

Here is a quick code snippet for that-

jQuery(document).ready(function(){
 /*Let's trick Joomla toolbar buttons Joomla 3.x*/
 
 /*Find Save button and change its onclick attribute
 by prepending its value with a call to your own javascript function*/
 jQuery("button[onclick=\"Joomla.submitbutton('config.save.component.apply')\"]").attr("onclick", "customFieldsValidation();Joomla.submitbutton('config.save.component.apply')");

 /*Find Save and close button and change its onclick attribute
 by prepending its value with a call to your own javascript function*/
 jQuery("button[onclick=\"Joomla.submitbutton('config.save.component.save')\"]").attr("onclick", "customFieldsValidation();Joomla.submitbutton('config.save.component.save')");
});

I hope this helps!

Monday, April 9, 2012

How to load a language file for a joomla plugin

Loading a language file for a joomla plugin-
If this is how your xml code looks for including a language file
myPlugin.xml
<languages folder="language/en-GB">
<language tag="en-GB">en-GB.plg_pluginType_myPlugin.ini</language>
</languages>

PHP code below
myPlugin.php
/*load language file for plugin frontend*/
$lang = JFactory::getLanguage();
$lang->load('plg_pluginType_myPlugin', JPATH_ADMINISTRATOR);

This will load your language file for the plugin and you can use language constants in the plugin.

Thursday, September 8, 2011

Generate correct SEF urls in joomla

I was constructing links like below in JmailAlerts plugins to generate SEF urls
$link=JRoute::_(JURI::root().'index.php?option=com_eventlist&view=details&id='.$row->id);
But it was not generating SEF urls at all.
I found this solution for generating SEF urls on joomla forum.
$link=JURI::root().substr(JRoute::_('index.php?option=com_eventlist&view=details&id='.$row->id),strlen(JURI::base(true))+1);
This generates absoulte SEF urls you need as per SEO settings in Global Configuration. 

Tuesday, February 1, 2011

The Right way to fetch media in JomSocial (in Joomla) when using Amazon S3

When using Amazon S3, here's some easy to use code snippets to fetch JomSocial Photo thumbnails, Video thumbnails, Group Avatar thumbnails etc..This is missing in the JomSocial Docs...

/*TO GET THUMBNAILS FOR JOMSOCIAL PHOTOS*/
//first get photo ids from local database
$query="SELECT  a.id, a.thumbnail FROM  jos_community_photos AS a”;
$db->setQuery($query);
$row  = $db->loadObjectList();
//JS API - this is used or getting thumbnails for JS photos
CFactory::load( 'models' , 'photos' );
$photo =& JTable::getInstance( 'Photo' , 'CTable' );
if(!empty($row))
{
    foreach($row as $data)
    {
     $photo->load( $data->id );
     $thumbnail    = $photo->getThumbURI();
     $data->thumbnail=$thumbnail;
    }      
}
//now $row will be having thumnails from local OR amazon s3 whatever applicable

/*TO GET THUMBNAILS FOR JOMSOCIAL VIDEOES*/
//first get video ids from local database
$query = "SELECT v.id,v.thumb FROM #__community_videos as v”;
$db->setQuery($query);
$video_result = $db->loadObjectList();
//JS API - this is used for getting thumbnails for JS videos
CFactory::load('models' , 'videos');
$video    =& JTable::getInstance( 'Video' , 'CTable' );
if(!empty($video_result))
{
foreach($video_result as $data)
    {
     if(($video->load($data->id)) && ($data->thumb)){
      $data->thumb=$video->getThumbnail();
     }
     else{
$data->thumb=JURI::root().'components'.DS.'com_community'.DS.'assets'.DS.'video_thumb.png';
   }
     }      
   }
//now $video_result  will be having video thumnails from local OR amazon s3 whatever applicable
/*TO GET GROUP-AVATAR FOR JOMSOCIAL GROUPS*/
//suppose you want to get a group avatar thumbnail for a group having groupid=3
//then use following code
$gid=3;
CFactory::load( 'models' , 'groups' );
$group=& JTable::getInstance( 'Group' , 'CTable' );
$group->load( $gid);
$avatar_img_source=$group->getThumbAvatar('avatar');
//now $avatar_img_source will be having the image source for group avatar thumbnail

/*TO GET USER-AVATAR FOR JOMSOCIAL USER*/
//suppose you want to get a user avatar thumbnail for a user having userid=3
//then use following code
$userid=62;
$user=&CFactory::getUser($userid);
$uimage = $user->getThumbAvatar();
//now $uimage will be having the image source for user avatar thumbnail