|
Geschreven door mirjam
|
|
maandag, 20 februari 2012 11:58 |
|
I wanted to display only the component output of a Joomla webpage, nothing more (e.g. modules) nothing less. That can be done by adding &tmpl=component to the URL.
(Joomla 1.5 and 2.5)
|
|
Laatst aangepast op maandag, 20 februari 2012 12:11 |
|
Geschreven door mirjam
|
|
donderdag, 24 november 2011 11:54 |
Securimage is an open-source free PHP CAPTCHA script created by Drew Phillips for generating complex images and CAPTHCA codes to protect forms and abuse. The available Quickstart Guide shows how (relatively) easy it is to add a captcha image to forms. The CAPTCHA can also be easily modified: there is one file with example settings, e.g. how many characters must a CAPTHCA have and how distorted should those characters be. That one file needs to be changed to set up securimage in Joomla to get the Joomla session, and because I wanted to remember how I did that I summed up the steps here.
Let me just quickly repeat the steps from the Quickstart Guide here and how I've used them for RSGallery2's comment form (a gallery component for Joomla, users can leave a comment for images):
|
|
Laatst aangepast op donderdag, 24 november 2011 14:28 |
|
Geschreven door mirjam
|
|
woensdag, 12 oktober 2011 10:16 |
I had this query in Joomla which was set up in an 'old way':
$query = "SELECT files.*, galleries.ordering, galleries.access " //galleries.name AS category, users.name AS editor" ." FROM #__rsgallery2_files AS files" ." LEFT JOIN #__rsgallery2_galleries AS galleries ON galleries.id = files.gallery_id" ." LEFT JOIN #__users AS users ON users.id = files.checked_out" ." WHERE galleries.access IN (".$groupsIN.")" //View access levels implementation ." ORDER BY galleries.ordering, files.ordering" ." LIMIT $pageNav->limitstart, $pageNav->limit";
and I wanted to redo this query in the way explained in API16:JDatabaseQuery, e.g.
$db =& JFactory::getDBO(); $query = $db->getQuery(true); $query->select('count(*)'); $query->from('#__pt_building AS b'); $query->leftJoin('#__pt_unit AS u ON b.building_id = u.building_id'); $query->where('b.property_id = '. (int) $property_id); $db->setQuery($query); return $db->loadResult();
One problem though, ok, maybe two: How can you introduce the LIMIT part of the query? Where 'where' and 'leftJoin' etc. are methods for this class, there is no limit method. But this is done differently: via the setQuery method that actually takes three arguments:
setQuery($query, $limitstart, $limit);
Second 'problem' was having two "LEFT JOIN"-s. But that was no problem at all, just call the leftJoin method twice. What is left is this:
$query = $database->getQuery(true); $query->select('files.*, galleries.ordering, galleries.access'); $query->from('#__rsgallery2_files AS files'); $query->leftJoin('#__rsgallery2_galleries AS galleries ON galleries.id = files.gallery_id'); $query->leftJoin('#__users AS users ON users.id = files.checked_out'); $query->where('galleries.access IN ('.$groupsIN.')'); $query->order('galleries.ordering, files.ordering'); $database->setQuery($query, $pageNav->limitstart, $pageNav->limit);
Of course, #__ is the prefix, and I wanted to use some condition for whether or not to include the where clause, but this works fine. With Joomla Debug on I can check the query:
SELECT files.*, galleries.ordering, galleries.access FROM jos_rsgallery2_files AS files LEFT JOIN jos_rsgallery2_galleries AS galleries ON galleries.id = files.gallery_id LEFT JOIN jos_users AS users ON users.id = files.checked_out WHERE galleries.access IN (1, 2, 3) ORDER BY galleries.ordering, files.ordering LIMIT 0, 20
And for the next page of max. 20 items:
SELECT files.*, galleries.ordering, galleries.access FROM jos_rsgallery2_files AS files LEFT JOIN jos_rsgallery2_galleries AS galleries ON galleries.id = files.gallery_id LEFT JOIN jos_users AS users ON users.id = files.checked_out WHERE galleries.access IN (1, 2, 3) ORDER BY galleries.ordering, files.ordering LIMIT 20, 20
Works nicely!
(This post: http://groups.google.com/group/joomla-dev-general/msg/3fc281dbd7176ba0?hl=en-GB is what lead me to realising how to work with the LIMIT.)
|
|
Laatst aangepast op woensdag, 12 oktober 2011 10:51 |
|
Geschreven door mirjam
|
|
dinsdag, 11 oktober 2011 15:11 |
|
Brilliant! I was looking for a way to determine whether code in a Joomla component is called for from the backend or the frontend. Finding out if a user is logged in is easy, quite enough code snippets can be found, but finding out if a user is logged in in the frontend or the backend...
But, here we go: We use the JApplication class which has methods isSite and isAdmin. You've guessed it: the first one returns true if the interface is the site, e.g. a user calls for content from the frontend, the second one returns true if the interface is 'admin', e.g. a user calls for content from the backend.
Now we can use:
if ($app->isSite()) { //content/logic for frontend } if ($app->isAdmin()) { //content/logic for backend }
And on the off chance that you got here to find out how to see whether or not a user is logged in:
$user =& JFactory::getUser(); if($user->id) { //if no user is logged in you won't go here sinde $user->id is 0, which is false }
|
|
Laatst aangepast op woensdag, 12 oktober 2011 10:52 |
|
Geschreven door mirjam
|
|
woensdag, 27 april 2011 08:37 |
|
Just got a strange error message: "Class 'JHtmlSelect' not found" whicht refers to a line
$mitems[] = JHtmlSelect::option( '0', JText::_('COM_YADAYADAYADA') );
The strange thing is not really the error, but that in Joomla 1.6 I get the error for a user with no configure permission whereas if the user has configure permission I don't get this error. But this has nothing directly to do with any configure permission, as far as I can tell...
Then I found a post ''JHTMLSelect, JHTMLMenu, etc results in class not found" where it says "...people should use the proxy methods such as JHTML::_().".
This is explainedby whurley: "The JHTML widgets are lazily included depending on usage. In other words, if none of the code has a need for a particular JHTML widget the source file will not be added to the execution environment. When JTHML::_ is called it imports the appropriate file using jimport (I would imagine) and then executes the appropriate function. The reason for this is optimization. If you want to use the direct calls, something that I imagine is not recommended, you could manually call jimport with the appropriate path to ensure it's included.".
Based on that I changed
$mitems[] = JHtmlSelect::option( '0', JText::_('COM_YADAYADAYADA') );
to
$mitems[] = JHtml::_('select.option', '0', JText::_('COM_YADAYADAYADA') );
and the error is gone!
|
|
Laatst aangepast op woensdag, 27 april 2011 08:50 |
|
|