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

04 February 2011

Cufon not working on Opera

This is an interesting issue: Opera 10.63 for Windows couldn't show the Cufon web font effect, but it worked across all the other browsers. Some research revealed a known issue: If any of your CSS files aren't found, Opera will not be able to apply the Cufon effect.

How do you determine if any of your CSS files are missing? Firefox' Web Developer Toolbar comes to the rescue. Go to the CSS button > View CSS. Now ensure that all the files are expanded so you can see the details. Look for a block similar to the following:
http://localhost:8090/joomla/templates/system/css/system9.css

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>

<title>Object not found!</title>

<link rev="made" href="mailto:postmaster@localhost" />

<style type="text/css"><!--/*--><![CDATA[/*><!--*/

body { color: #000000; background-color: #FFFFFF; }

a:link { color: #0000CC; }

p, address {margin-left: 3em;}

span {font-size: smaller;}

/*]]>*/--></style>

</head>

<body>

<h1>Object not found!</h1>

<p>

The requested URL was not found on this server.

The link on the

<a href="http://localhost:8090/joomla/">referring

page</a> seems to be wrong or outdated. Please inform the author of

<a href="http://localhost:8090/joomla/">that page</a>

about the error.

</p>

<p>

If you think this is a server error, please contact

the <a href="mailto:postmaster@localhost">webmaster</a>.

</p>

<h2>Error 404</h2>

<address>

<a href="/">localhost</a><br />

<span>02/04/11 15:48:16<br />

Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1</span>

</address>

</body>

</html>
Note the text "Object not found" (Error 404); Cufon can't handle missing CSS files on Opera and will not render your web font.

31 August 2010

Joomla: Read custom article parameters from a module

In implementing a web site on Joomla, I came across a common issue: I needed to pass additional parameters with an article into a 3rd-party module. In this case, the module was the Joomla AnythingSlider, a very slick and flexible content slider/carousel.

The initial task of creating the custom parameters wasn't so bad; the first thread in this post covers that. You add the parameter to the advanced section of the file administrator/components/com_content/models/article.xml:

<param name="article_type" type="radio" default="default" 
label="Article Type" description="article type">
<option value="default">Default</option>
<option value="picture">Picture (rotator)</option>
<option value="video">Video (rotator)</option>
</param>
However, reading the values in a module is a different story. Here's the syntax to fetch all the parameters from article.xml:
$paramsdefs = JPATH_COMPONENT.DS.'models'.DS.'article.xml';
$myparams = new JParameter( $paramsdata, $paramsdefs );
And here's how a specific custom parameter is read (in this case, it's called article_type):
echo "Article type: ". $myparams->get('article_type');
This is thanks to another reply to the same post on the Joomla forums, but page 2.

UPDATE:
A good quested was raised about one of the variables used in the above code: $paramdata. Where was it defined? Well, it's not in the above code, but in the AnythingSlider Joomla extension, mod_anythingslider; you can download it from here.

The mod_anythingslider has a helper.php file, which defines the class ModSlideShow:
<?php
/**
* AnythingSlider Helper Classes
*
* @package Joomla 1.5.0
* @subpackage Modules
* @Copyright Copyright (c)2010 Dnote Software
* @license GNU/GPL, see http://www.gnu.org/copyleft/gpl.html
*
* mod_anythingslider is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Parts of this software are based on AnythingSlider By Chris Coyier: http://css-tricks.com
**/

defined('_JEXEC') or die('Direct Access to this location is not allowed.');

class ModSlideShow
{
/**
* Returns a list of articles
*/
function getSlideshow(&$params, &$access)
{
global $mainframe;

$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$aid = $user->get('aid', 0);

$catid = (int) $params->get('catid', 0);
$items = (int) $params->get('items', 0);

$contentConfig = &JComponentHelper::getParams( 'com_content' );
$noauth = !$contentConfig->get('show_noauth');
$date =& JFactory::getDate();
$now = $date->toMySQL();

$nullDate = $db->getNullDate();

// Ordering
switch ($params->get( 'ordering' ))
{
case 'o_asc':
$ordering = 'a.ordering';
break;
case 'o_dsc':
$ordering = 'a.ordering DESC';
break;
case 'm_dsc':
$ordering = 'a.modified DESC, a.created DESC';
break;
case 'c_dsc':
default:
$ordering = 'a.created DESC';
break;
}

// query to determine article count
$query = 'SELECT a.*,' .
' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,'.
' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug'.
' FROM #__content AS a' .
' INNER JOIN #__categories AS cc ON cc.id = a.catid' .
' INNER JOIN #__sections AS s ON s.id = a.sectionid' .
' WHERE a.state = 1 ' .
($noauth ? ' AND a.access <= ' .(int) $aid. ' AND cc.access <= ' .(int) $aid. ' AND s.access <= ' .(int) $aid : '').
' AND (a.publish_up = '.$db->Quote($nullDate).' OR a.publish_up <= '.$db->Quote($now).' ) ' .
' AND (a.publish_down = '.$db->Quote($nullDate).' OR a.publish_down >= '.$db->Quote($now).' )' .
' AND cc.id = '. (int) $catid .
' AND cc.section = s.id' .
' AND cc.published = 1' .
' AND s.published = 1' .
' ORDER BY '.$ordering ;
$db->setQuery($query, 0, $items);
$rows = $db->loadObjectList();

return $rows;
}

}
?>
Then in the mod_anythingslider.php, we define a few more variables:
$params->set('intro_only', 1);
$params->set('hide_author', 1);
$params->set('hide_createdate', 0);
$params->set('hide_modifydate', 1);

// Disable edit ability icon
$access = new stdClass();
$access->canEdit = 0;
$access->canEditOwn = 0;
$access->canPublish = 0;
// Other code here...
$slideShow = ModSlideShow::getSlideshow($params, $access);
Now we bring it all together in the default.php, which generates the HTML for the slider:
/* 
Variables used throughout the main foreach loop.
Don't define these in the loop b/c they'll get
created for each article in the carousel.
*/
$paramsdefs = JPATH_COMPONENT.DS.'models'.DS.'article.xml';
$limitstart = JRequest::getVar('limitstart', 0, '', 'int');
$dispatcher =& JDispatcher::getInstance();

/*
Main foreach loop of the carousel component. Runs
once for each article in the slideshow.
*/
foreach ($slideShow as $item){
echo "<li>";
$aparams =& $item->parameters;
$params->merge($aparams);

$item->text = $item->introtext;
$results = $dispatcher->trigger('onPrepareContent', array (& $item, & $params, $limitstart));

$paramsdata = $item->attribs;
$myparams = new JParameter( $paramsdata, $paramsdefs );
$article_type = $myparams->get('article_type');
// More processing inside the foreach...
}
Hope this helps those confused by the $paramdata variable.

03 August 2010

How to install Joomla on Windows

For development purposes, I needed Joomla installed on my Windows XP system. However, Joomla has some infrastructure requirements often not found on Windows boxes. Here are some steps on how to successfully install Joomla on your PC:
  1. Download the XAMPP for Windows package. I downloaded the EXE and installed it at the root C: in the XAMPP folder.
  2. If you also have IIS running on your system, after the installation, change the default port used by Apache.
  3. The XAMPP installation will automatically ask you if you want to launch its control panel. If it's not already running, go to Start > XAMPP for Windows > XAMPP Control Panel.
  4. Click to start the Apache and MySql services (if they're not already running). When they successfully start, you'll see a green indicator saying "Running" next to each service. [Note: If the services take too long to start, it's more than likely because port 80 is being used by IIS; follow Step 2 above to change the Apache port to something else and try to start the services again.]

  5. Download the latest version of Joomla.
  6. Create a folder named joomla under C:\xampp\htdocs\
  7. Unzip the contents of the Joomla ZIP file into this new folder.
  8. Open your browser and navigate to http://localhost/ or, if you changed the Apache port, to http://localhost:xx/, where xx is the port number you assigned to Apache in Step 2.
  9. Click the phpMyAdmin link and go to "Privileges" on the MySQL database.
  10. Choose "Add a new User" and give it a name and password you can remember.
  11. Under "Global privileges" for this user, click "Check All" to grant all rights to this user.
  12. Click Go to create the user.
  13. Go to the Databases tab and create a database for Joomla (could be called joomla).
  14. Open your browser and navigate to http://localhost/joomla/ or, if you changed the Apache port, to http://localhost:xx/joomla/, where xx is the port number you assigned to Apache.
  15. Follow the wizard until you get to the database screen. Here, enter the information for the database and user you just created. For the host, use localhost. Important: Do not enter the port number after the host name, such as localhost:xx because this will not work and it won't generate an error; enter only the word localhost into the Host Name field.
  16. Upon successful completion, Joomla asks you to delete the installation folder. Go ahead and do that.
  17. To see the Joomla home page, reload http://localhost/joomla/ or, if you changed the Apache port, http://localhost:xx/joomla/, where xx is the port number you assigned to Apache.



Additional resources on installing Joomla with XAMPP on Windows and other platforms can be found on the Joomla docs site.