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

Tuesday, 24 March 2009

Javascipt onload confclits

Normally there are two ways to run javascipt when html page is loaded:

  1. window.onload=INLINE_FUNCTION_NAME, is normally used to make specific javascript runnable when the html document is loaded.
  2. general javascript function, like "function FUNCTION_NAME() {... }; FUNCTION_NAME();"
The problem of method 1) is that one page only can have one onload function. there are always conflicts in Joomla or drupal which use a lot of javascript for functions.

The problem of method 2) is that when the function started, maybe the html document is not fully loaded.

FIX
===============================
To solve this, 'domready' from mootools helps a lot and improves the loading speed very much. See domready vs load.
Insert mootool.js (optional for Joomla, But required for local html test)
---------------------------------------------------
<script type="text/javascript" src="mootools.js">
</script>

---------------------------------------------------
You should go to mootools.net to download the latest mootools.js.

Monday, 23 March 2009

HOWTO: Joomla CSS drop-down menu (javascript for IE6)

Prolog
===================

At beginning, I compared the two drop-down menu raw methods:
http://docs.joomla.org/Creating_a_CSS_Drop_down_Menu
http://www.alistapart.com/articles/dropdowns

Both of them are using suckerfish CSS methods to diminish javascript usage from DHTML.
Because IE doesn't support 'hover' status on 'li', only on 'a'. to solve this problem, there is some javascript for IE, using 'onmouseover'.

The difference between the above two javascript methods, one uses 1)'document.THECLASSOFTAG.getElementsByTagName("LI")' to retrieve <li>, while 2) the other uses 'navRoot.childNodes......' with loop to find out all <li> within the range, which defined by 'document.getElementById("THEIDOFTAG")'.

Javascript in method 1) is NOT supported by IE 6 and 7, even Firefox. This only affect IE 6, others don't need javascript to achieve this drop-down menu.

But, the 'hiding method', which uses 'left:-98%' to hide the submenu from screen is very good and secure, compared with the method using 'display: none', which used in method 2).

Method 2) is just traditional way to parse the html document. But it's for pure HTML practice, not exactly for Joomla.

Therefore, I modified above 2 methods, to make it easily setup on Joomla 1.5.


Make Joomla Drop-Down Menu without install anything
===================================

1. Create your Menu with the following Hierarchy:

Menu 1( globalnews ).

– Menu 1 Sub Menu 1 (test).

– Menu 1 Sub Menu 2 (test).

Menu 2( uknews ). // this menu have no submenu

2. Make sure the parameters are set to.

• Menu Style is set to List.

• Always show sub-menu Items is set to Yes.

• Menu Class Suffix is set to -nav - you can pick you own, but then make sure you change it in CSS & JS files. So you will get your menu within

All the menu strcture will be like this ( this can be found from your scource from IE or Firefox:
-------------------------------------------------

<div class="pill_m">
<div id="pillmenu">
<ul class="menu-nav">
<li class="parent item63"><a href="/globalnews"><span>Globalnews</span></a>
<ul>
<li class="item75"><a href="/uknews"><span>test</span></a></li>
<li class="item76"><a href="/uknews"><span>testtest</span></a></li>
</ul>
</li>

<li class="item61"><a href="/uknews"><span>uknews</span></a></li>

</ul>
</div>
</div>


---------------------------------------
here, the 'div class="pill_m"' and 'div id="pillmenu"' is what I put in the templates/MYTEMPLATE/index.php to help me setup the css style.

3. Insert this piece of JS in your template index.php 'head' tag, or in java script file that’s called from index.php.
---------------------------------------
<!--[if IE]>
<script type="text/javascript">
window.addEvent('domready', function()
{
if (document.getElementById) {
//navRoot = document.getElementById("pillmenu");
ulTag = pillmenu.childNodes(0);//navRoot==pillmenu, which is a 'id'.
for (i=0; i<ulTag.childNodes.length; i++) {
node = ulTag.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
temp_cn=this.className;
this.className=temp_cn.replace(temp_cn, "sfhover")
//this.className+="sfhover";
}
node.onmouseout=function() {
this.className=this.className.replace("sfhover", temp_cn);
}
}
}
}
}
);
</script>
<![endif]-->
----------------------------------------
Note:
  • Here <!--[if IE]> make this script just work for IE, to improve the performance of Fifrefox,safari, they do need such javascript to make the dorp-down menu.
  • window.onload=INLINE_FUNCTION_NAME, is normally used to make specific javascript runnable when the html document is loaded, BUT, in joomla, there always a lot of javascript block in the pages, and one page only can have one onload function. To solve this, 'domready' from mootools helps a lot and improves the loading speed very much. See domready vs load.
  • Even using general javascript function, like "function FUNCTION_NAME() {... }; FUNCTION_NAME();", will not work properly, because when the function started, maybe the html document is not fully loaded. Still, mootools domready event helps.
4. Insert mootool.js (optional for Joomla, But required for local html test)
---------------------------------------------------

<script type="text/javascript" src="mootools.js">

</script>

---------------------------------------------------
You should go to mootools.net to download the latest mootools.js.

5. Here the corresponding CSS
----------------------------------------------------
<style type="text/css">
/*****************************************/
/*** Copied menu ***/
/*****************************************/
.pill_m {
text-align: center;
margin: 0 auto;
padding: 0;
background: url(../images/menu.jpg) top center repeat-x;
width: 100%;
height: 41px;
}
#pillmenu {
margin:0 auto;
width:960px;
}
#pillmenu ul {
margin: 0;
padding: 0 22px;
list-style: none;
}
#pillmenu li {
float: left;
margin: 0;
padding: 0;
height: 49px;
background: url(../images/menu_li.jpg) top right no-repeat;
}
#pillmenu li:hover {
}
#pillmenu li a#active_menu-nav {
}
#pillmenu li a {
font-family: Verdana,Helvetica,Arial,sans-serif;
font-size: 13px;
/* float: left;*/
display: block;
line-height: 39px;
padding: 0 24px 0 16px;
color: #111111;/*color: #FFFFFF;*/
text-decoration: none;
font-weight: bold;
text-transform:uppercase;
}
#pillmenu li a:hover {
color: #CCCCCC;
}
.pill_m li ul { /* second-level lists */
position: absolute;
left: -98%; /* using left instead of display to hide menus because display: none isn’t read by screen readers */
}
.pill_m li:hover ul, .pill_m li.sfhover ul { /* lists nested under hovered list items */
left: auto; /* change is to 10px, 20px, etc for indenting the sub menue */
z-index: 100;
}
#pillmenu li.parent ul li, #pillmenu li.sfhover ul li{
height:20px;
background: url(../images/menu.jpg) top center repeat-x;
}
#pillmenu li.parent ul li a, #pillmenu li.sfhover ul li a{
font-size: 10px;
line-height: 20px;
}
</style>
----------------------------------------------------
Here the background can be changed as you want, or set it 'none' or other colors.
Have a try, If you got any problems, comment here to let me know.

Tuesday, 17 March 2009

Which CMS? Drupal vs. Joomla vs. Wordpress

Here is a video from 5th Ultra Light Startups. There are 3 people from Drupal, Joomla and Wordpress, who are introducing these 3 CMSes.

A basic idea can be got when you see this video, more details can be found on http://www.packtpub.com/open-source-cms-award-previous-winners.





Friday, 13 March 2009

Php, Joomla: alphacontent(joomla component) show youtube thumbnail

A very good frontpage component for joomla, AlphaContent, can pick up photos from article as thumbnail on the article list. However, it just pick up thumbnail for articles, which have photos inside, not for those only embed video object.

Modify the 'function findIMG( $contenttext, $showfirstimg)', in /components/com_alphacontent/assets/includes/alphacontent.functions.php, will solve this problem.

Solution:
=====================

<?php

$contenttext = <<<youtube
<div><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="425" height="350"><param name="width" value="425" /><param name="height" value="350" /><param name="src" value="http://www.youtube.com/v/e_0oqGy0OyY" /><embed type="application/x-shockwave-flash" width="425" height="350"
src="http://www.youtube.com/v/e_0oqGy0OyY"></embed></object></div>

youtube
;
$showfirstimg = '1';

//<img width="20" src="http://cnfeed.co.uk/images/stories/screenshot.png"></img>

function findIMG( $contenttext, $showfirstimg ) {
$image = "";

// check is there any img tag/images
if (preg_match_all('#<img(.*)>#', $contenttext, $match0) ) {
//print_r($match0);
if ( count($match0) ) {
$n = sizeof($match0[1]);
if ( $showfirstimg=='2' ) {
$contenttext = $match0[1][$n-1];
} else $contenttext = $match0[1][0];
}
// else $contenttext may just host video 'src'

// for image search
if ( preg_match_all('#src="(.*)"#Uis', $contenttext, $match ) ) {
//print_r($match);
if ( count($match) ) {
$n = sizeof($match[1]);
if ( $showfirstimg=='2' ) {
$image = $match[1][$n-1];
} else $image = $match[1][0];
}
return $image;
}
}

// for youtube video search, just the first video thumbnail
if ( preg_match('#src="(.*)"#Uis', $contenttext, $match_video ) ) {
//print_r($match_video);
if ( count($match_video) ) {
if (preg_match('#youtube#i', $match_video[0], $match_temp) ) {
$youtube_src = $match_video[1];
//print_r($youtube_src);
if (preg_match('/v[\=\/][a-zA-Z0-9_]{1,}&/',$youtube_src, $image_0)) {
preg_match('/v[\=\/](.*)&/',$image_0[0], $image_1);
} else {
preg_match('/v[\=\/](.*)/',$youtube_src, $image_1);
}

//print_r($image_1);
$vid = ( $image_0 === null ) ? Vj9ChXA9y8I : $image_1[1];
$image = "http://img.youtube.com/vi/".$vid."/0.jpg";
}

// for other video search, static image to inform others: othervideo.png
else {
$image = "http://cnfeed.co.uk/images/othervideo.png";
}
}
}

if ($image == ''){
$image = "http://cnfeed.co.uk/images/noimage.png";
}

return $image;
}

echo findIMG( $contenttext, $showfirstimg );
?>

Tuesday, 10 March 2009

HOWTO: joomla template

What's in joomla template directory?

FOLDERS:
==================
  • /css:(requied)  all kinds of css files.
  • /images:(requied) all the images will be used by the template.
  • /html: (optional) for component/module override. details: http://developer.joomla.org/tutorials/165-understanding-output-overrides-in-joomla.html

FILES:
=================
  • index.php(requied): template html+php file
  • index.html(requied): blank files
  • params.ini(requied): joomla need this file as writeable, to save configuration about his template.
  • template_thumbnail.png(requied): joomla need this file for preview
  • templateDetails.xml(requied): joomla need this file for template installation.
  • favicon.ico: (optional) favicon file.
  • component.php : (optional) for article printable layout, only display selected parts.


Friday, 6 March 2009

&, in Joomla api, return reference to existing object

Most of joomla api return reference, such as:

In this example, the current date and time is retrieved and output in the current default locale format.

=========================
$date =& JFactory::getDate();
echo 'Current date and time is: ' . $date->toFormat() . "\n";
If the current language is English then this will output something like
Current date and time is: 2008-11-22 18:14:08
=========================


This is because the returned object will update the existing one, while not creating new global one, except the object not created yet.
As explained here, in api.joomla.org:

=========================
getApplication (line 34)
Get a application object
Returns a reference to the global JApplication object, only creating it if it doesn't already exist.
=========================

Friday, 6 February 2009

Joomla Issue: phoca gallery menu display issue in IE6

phocagallery has some display issue in ie6: the menu will be placed in wrong way from firefox and ie7, when mouse 'hover' on the menu.

1) in the view of categories list, under the page of gallery menu.
The corresponding css file is located in /components/com_phocagallery/assets/phocagallery.css
* Solution:
=======
.phocagallery-box-file:hover, .phocagallery-box-file.hover {
border:1px solid #135cae;
background:#f5f5f5;
text-decoration:none;
}

modify 'border:1px' into 'border:0px';


2) In the view of every category:
From the 'header' part in the html codes, there are some embeded css codes, which are from the file, /administrator/components/com_phocagallery/helpers/phocagalleryrender.php
* Solution:
=======

function renderCategoryCSS($font_color, $background_color, $border_color, $imageBgCSS, $border_color_hover, $background_color_hover, $ol_fg_color, $ol_bg_color, $ol_tf_color, $ol_cf_color, $margin_box, $padding_box, $opacity = 0.8) {
$opacityPer = (float)$opacity * 100;
$tag = "<style type=\"text/css\">\n"
." #phocagallery .name {color: $font_color ;}\n"
." .phocagallery-box-file {background: $background_color ; border:1px solid $border_color;margin: ".$margin_box."px;padding: ".$padding_box."px;}\n"
." .phocagallery-box-file-first { $imageBgCSS }\n"
." .phocagallery-box-file:hover, .phocagallery-box-file.hover {border:1px solid $border_color_hover ; background: $background_color_hover ;}\n"
...
}


modify 'border:1px' into 'border:0px';

Or in the template.css for ie, put such codes in:
#top .hover {
border: 0px;
}

Sunday, 1 February 2009

Mysql usages comparison in php, joomla and drupal



## php_mysql: ####

<?
$username="username";
$password="password";
$database="your_database";

$link = mysql_connect(localhost,$username,$password);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';

@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM contacts";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<b><center>Database Output</center></b><br><br>";

$i=0;
while ($i < $num) {

$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");
$web=mysql_result($result,$i,"web");

echo "<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>";

$i++;
}

?>


## Joomla_mysql: ####
## Normally in a helper class ####
<?php
/**
* Helper class for Hello World! module
*
* @package    Joomla.Tutorials
* @subpackage Modules
*/
class modHelloWorldHelper
{
function getHello( $userCount ){
        
        //$db = &JFactory::getDBO();
        $username="gigibri1_cross";
$password="zhengxin";
$database="gigibri1_dev";
        
        mysql_connect(localhost,$username,$password);
        @mysql_select_db($database) or die( "Unable to select database");

// get a list of all users
$query = 'SELECT * FROM jos_users';
//$db->setQuery($query);
$result = mysql_query($query);

$items = ($items = $db->loadObjectList())?$items:array();
// create a new array and fill it up with random users
$actualCount = count($items);
if ($actualCount < $userCount) {
    $userCount = $actualCount;
}
$items2 = array();
$rands = array_rand($items, $userCount);
foreach ($rands as $rand) {
     $items2[] = $items[$rand];
}
return $items2;

mysql_close();
return $result;
    }    
}

## Drupal_mysql: ####
## Normally in a module file ####
  $result_sell_price = db_fetch_object(db_query('SELECT i.sell_price FROM {image} i WHERE i.vid = %d', $node->vid));
  $node->sell_price=$result_sell_price->sell_price;
  
  
  
$result = db_query("SELECT i.image_size, f.filepath FROM {image} i INNER JOIN {files} f ON i.fid = f.fid WHERE i.nid = %d", $node->nid);
$node->images = array();
while ($file = db_fetch_object($result)) {
    $node->images[$file->image_size] = file_create_path($file->filepath);
}




Wednesday, 28 January 2009

how Virtuemart present the shop page

1) virtuemart.php:
if( file_exists( PAGEPATH.$modulename.".".$pagename.".php" )) {
...
include( PAGEPATH.$modulename.".".$pagename.".php" );
// this file is: administrator/components/com_virtuemart/html/shop.index.php

2) shop.index.php:
$tpl = new $GLOBALS['VM_THEMECLASS']();
...
$tpl->set( 'categories', $category_childs );
...
$tpl->set('ps_product',$ps_product);
...
echo $tpl->fetch( 'common/shopIndex.tpl.php');
// to theme the output, the template file, components/com_virtuemart/themes/default/templates/common/shopIndex.tpl.php, is needed.

3) shopIndex.tpl.php:

you can remove the shop description/the word of 'categories',
or remove the featured prodcuts in codes, but this also can be done in admin-components-virtuemart-admin-configuration-site-layout-Select the theme for your Shop-default-configuration)

if( $this->get_cfg( 'showFeatured', 1 )) {
/* featuredproducts(random, no_of_products,category_based) no_of_products 0 = all else numeric amount
edit featuredproduct.tpl.php to edit layout */
echo $ps_product->featuredProducts(true,10,false);
}
// ./featuredproduct.tpl.php will determine the layout for featured products.

My photo
London, United Kingdom
twitter.com/zhengxin

Facebook & Twitter