Joomla Plug-in simple Image Gallery compatible issue

Recently, my company need to modify WebSite.

Previously, we used Joomla for our site platform, it is very cool CMS, I loved it. Right now, we bought a cool template which include a plug-in from joomlaworks — simple Image Gallery. It is a free extension for adding image galleries inside Joomla! articles.

But we meet a small defect that the tips display not correctly.

Here you will see what’s wrong with the tips:

You may notice JW_SIG_NAVTIP is a very wired description, what we did just add

{gallery}********{/gallery} in our articles, the image display right, but this tip is not what we expected.

First I went to Joomla administration site, in Extensions/Plugin Manager I find Simple Image Gallery (by JoomlaWorks), but there is no parameter setting for this tips issue.

So I have go into code level.

I go through the PHP code, find here is the reason.

In plugins\content\jw_simpleImageGallery\tmpl\Polaroids\default.php

I found  JW_SIG_NAVTIP words,

rel=”lightbox” title=”<?php echo JText::_(‘JW_SIG_NAVTIP’);?> <b><?php echo $row->title; ?></b><br /><br />” target=”_blank”>

JText::_  it means, it should be a string from language config file.

So what I should do is to check the language file, I am using en-GB language which is default setting in Joomla

In plugins\content\jw_simpleImageGallery_1.5.php,

$languageLoad=JPlugin::loadLanguage(‘plg_content_’.$this->plg_name, JPATH_ADMINISTRATOR);

In plugins\content\jw_simpleImageGallery.php, you can find variable plg_name

var $plg_name = “jw_simpleImageGallery”;

So, the language for simple Image Gallery  should be

en-GB.plg_content_jw_simpleImageGallery.ini under

administrator\language\en-GB folder.

I go to the folder, found the file. Open it I found the string I am looking for

JW_SIG_NAVTIP=”<b>Navigation tip:</b> Hover mouse on top of the right or left side of the image to see the next or previous image respectively.<br /><br />You are browsing images from the article:”CLICK TO ENLARGE=”Click to enlarge”

So if everything is right, it should display the “Navigation tip:*******” things, not JW_SIG_NAVTIP. From this I know the language file is not loaded properly.

I found that this plug-in save all strings in one file either for administration setting or site setting. And I do remember that I have go in the  Extensions/Plugin Manager  to check this the strings display correctly. If you like you can compare it by yourself.

And the JPlugin::loadLanguage API should works fine, because I check other plug in which use it. So I think maybe somehow Joomla can not find the language file.

I checked the API in libraries/joomla/plugin/plugin.php

/**
	 * Loads the plugin language file
	 *
	 * @access	public
	 * @param	string 	$extension 	The extension for which a language file should be loaded
	 * @param	string 	$basePath  	The basepath to use
	 * @return	boolean	True, if the file has successfully loaded.
	 * @since	1.5
	 */
	function loadLanguage($extension = '', $basePath = JPATH_BASE)
	{
		if(empty($extension)) {
			$extension = 'plg_'.$this->_type.'_'.$this->_name;
		}

		$lang =& JFactory::getLanguage();
		return $lang->load( strtolower($extension), $basePath);
	}

Notice that “strtolower” call, and the file under language folder is

en-GB.plg_content_jw_simpleImageGallery.ini which contain two upper characters.

For Operation System, the file name maybe case sensitive maybe not. Like, for windows you can configure this sensitive issue.

(http://technet.microsoft.com/en-us/library/cc725747.aspx)

so I tried to change en-GB.plg_content_jw_simpleImageGallery.ini into

en-GB.plg_content_jw_simpleimagegallery.ini

I do not have the change “GB”, since this language prefix it appended in

JLanguage::load() function (libraries/joomla/language/language.php)

which is called by $lang->load( strtolower($extension), $basePath); code.

So I got the expected view for my site.

But for the display of simple image in Extensions/Plugin Manager is missing.

Since in plugins\content\jw_simpleImageGallery.xml is using upper case file, as you can see below

<language tag=”en-GB”>en-GB.plg_content_jw_simpleImageGallery.ini</language>

So we should modify both of it to lower case, so that everything works fine.

But for me, I decide separate back-end and front-end setting.

So I copy en-GB.plg_content_jw_simpleImageGallery.ini as

en-GB.plg_content_jw_simpleimagegallery.ini to language\en-GB folder, be careful, it the not under administrator folder, it should be the path under your site root folder.

So what I have to modify just one line of code

In plugins\content\jw_simpleImageGallery_1.5.php,

From :

$languageLoad=JPlugin::loadLanguage(‘plg_content_’.$this->plg_name, JPATH_ADMINISTRATOR);

To:

$languageLoad=JPlugin::loadLanguage(‘plg_content_’.$this->plg_name)

To make simple image gallery load from site’s language setting not administrator language setting.

Next, if any one wish to modify the tips content, just modify the string value in language file.

Django Dairy 2: It works~

The little foolish boy come back to struggle with Django.

Today, I do not have much time to work on it. I have to write a Help file for my application which is a boring issue…… but no one will help me in my company, I have to work on it myself…… using my poor poor English. Fortunately, this time nobody will spend their time on the stupid Help File…… well, in this case, my working on Help File will worth nothing… Anyway… Let’s go back to my little Django Project~~~

Today, I should work on PHP issue.

The installation works fine. But my Apache will not recognize PHP…

Well, first I found while I try to start Apache, there will be some warning like:

Warning: DocumentRoot [/opt/local/apache2/docs/dummy-host.example.com] does not exist
Warning: DocumentRoot [/opt/local/apache2/docs/dummy-host2.example.com] does not exist

I know it is the problem of

httpd-vhosts.conf

I delete the useless virtual hosts in the file, and only left one host for testing. This warning gone.

But I still got 404 error, whatever I tried http://127.0.0.1/index.html or http://127.0.0.1/index in my FireFox…

Not Found

The requested URL /index was not found on this server.

http://kanstech.blogspot.com/2010/12/apache-error-phpmotion-requested-url.html

The site listed above gave me the hint.

When you setup PHPMotion video website you will encounter the following error first,

The requested URL /upload-media was not found on this server.

It happens due to the error in Apache Config. Add the following Directory Element to the config file.

<Directory "/var/www/htdocs/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

If you face the problem like me, I think this time I can say some trick about it

Just go to httpd.conf of your Apache, mine is at /opt/local/apache2/conf/

Type

sudo vi /opt/local/apache2/conf/httpd.conf

in your shell, and search for the Directory you use for web root, see if you give the right permission, for my case, I gave “deny from all” to my root directory, now I changed it to “Allow from all”.

Finally, my index.html in the DoucmentRoot of Apache works fine.

I saw It works~~~, really happy.

Next, what’s going on of my PHP testing file phpinfo.php?

<?phpphpinfo();?>

I found everywhere, at beginning I thought my PHP is not installed correctly.

But it should installed well. Next, I found the point, I use TextWrangler to edit phpinfo.php file at first, but now I try to use vi to open it, I found lots of unexpected characters exists at the top of the file. So I remove it, and phpinfo.php works well.

Here, I tell everybody a trick, I think maybe I am the last one know it, haha~~

Here, if you do not like vi, and you have to use root user permission to open a text file, you can use TextEdit for example:

sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit phpinfo.php

Till now, Apache works, MySql works, PHP works,

So next, I tried to install phpMyAdmin
another problem came out, Chris Gilmer said to modify config.inc.php like this:

<?php
$i = 0;

$i++;
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'config';  // Authentication method (config, http or cookie based)?
$cfg['Servers'][$i]['user'] = 'root';         // MySQL User
$cfg['Servers'][$i]['password'] = 'mypassword';  // MySQL Password (only needed with 'config' auth_type)

/* Server parameters */
$cfg['Servers'][$i]['host'] = '127.0.0.1'; // was 'localhost';
$cfg['Servers'][$i]['port'] = '3306';
$cfg['Servers'][$i]['connect_type'] = 'socket'; // was 'tcp';
$cfg['Servers'][$i]['compress'] = false;

/* Select mysqli if your server has it */
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['socket'] = '/tmp/mysql.sock';

$cfg['UploadDir'] = ;
$cfg['SaveDir'] = ;

?>

But it does not work for me, my phpMyAdmin said 2002 error, complaining about the ‘mysql.sock’ issue.

But, I know my MySql works fine the socket is working. So that I use nestat -ln|grep mysql to look for the TCP status.

System told me:

8a5c5f0 stream 0 0 f745b2c 0 0 0 /opt/local/var/run/mysql5/mysqld.sock

I noticed that it is using /opt/local/var/run/mysql5/mysqld.sock

And I also check by

mysqladmin5 -u root -p variables

mysqladmin5 -p version

All of them told me the location of .sock is not $cfg[‘Servers’][$i][‘socket’] = ‘/tmp/mysql.sock’;

So I change it to $cfg[‘Servers’][$i][‘socket’] = ‘/opt/local/var/run/mysql5/mysqld.sock’;

And also used

sudo vi /opt/local/etc/php5/php.ini

to change the mysql.default_socket.

mysql.default_socket = '/opt/local/var/run/mysql5/mysqld.sock'

And still phpMyAdmin is not working correctly.

Finally, I changed config.inc.php to the content followed:

sudo vi /opt/local/www/phpmyadmin/config.inc.php

$i = 0;

/*
* First server
*/
$i++;
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie'; //Authentication method(config, http or cookie based)?
$cfg['Servers'][$i]['user']='root'; //mysql user
$cfg['Servers'][$i]['password'] = '';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost'; // was 'localhost'
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['connect_type'] = ''; // was 'tcp'
$cfg['Servers'][$i]['compress'] = false;

/* Select mysqli if your server has it */
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['socket'] = '';

Everything is ok. phpMyAdmin works.

The next step is very easy just follow the article. And my mod_wsgi works well.

After I installed Django, I use django-admin.py startproject mysite

and python manage.py runserver to test django. Yes, it works fine.

Now, what I should do is to hook django with Apache to finish all my environment setup.

But it is still not a easy task for me.

I read various article talking about it

http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

http://blog.stannard.net.au/2010/12/11/installing-django-with-apache-and-mod_wsgi-on-ubuntu-10-04/

And all of them can not solve my problem, I always got ImportError: No module named django.core.handlers.wsgi by using

tail /opt/local/apache2/logs/error_log

to check the error log.

Finally, I found a solution. Here I list all my setting for it

/opt/local/apache2/conf/extra/apache_django_wsgi.conf (this file is used for httpd.conf as VirtualHost referenced file)

<VirtualHost *:80>
ServerName simpleknow.djangoserver
DocumentRoot "/Users/zsspkx/workingspace/web/simpleknow"

<Directory "/Users/zsspkx/workingspace/web/simpleknow">
Order deny,allow
Allow from all
</Directory>

Alias /media/ "/Users/zsspkx/workingspace/web/simpleknow/media/"
<Directory "/Users/zsspkx/workingspace/web/simpleknow/media">
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias / "/Users/zsspkx/workingspace/web/simpleknow/apache/django.wsgi"

<Directory "/Users/zsspkx/workingspace/web/simpleknow/apache">
Order deny,allow
Allow from all
</Directory>

</VirtualHost>

/workingspace/web/simpleknow/apache/django.wsgi (this file is created by me to help apache to load WSGI handler)

import os
import sys
sys.path.append ('/Library/Python/2.6/site-packages/')
path = '/Users/zsspkx/workingspace/web'
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'simpleknow.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

You can see the file above, I add sys.path.append (‘/Library/Python/2.6/site-packages/’) to this file, since for MAC, django is installed under this path.

So now my Django can run on Apache.

However, I still have one problem left, after I modify setting under my site folder

DATABASES = {
'default': {
'ENGINE': 'mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'simpleknow',                      # Or path to database file if using sqlite3.
'USER': 'root',                      # Not used with sqlite3.
'PASSWORD': 'mysql',                  # Not used with sqlite3.
'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
}
}

try to use mysql through Python, My site is wrong. It told me Error loading MySQLdb module: No module named MySQLdb

I download MySQLdb and follow README
$ tar xfz MySQL-python-1.2.1.tar.gz
$ cd MySQL-python-1.2.1
$ # edit site.cfg if necessary
$ python setup.py build
$ sudo python setup.py install # or su first

build will fail. And I check Google, found I should do this way:

http://cd34.com/blog/programming/python/mysql-python-and-snow-leopard/

tar xzf MySQL-python-1.2.3c1.tar.gz
cd MySQL-python-1.2.3c1
ARCHFLAGS=’-arch x86_64′ python setup.py build
ARCHFLAGS=’-arch x86_64′ python setup.py install

The build and install passed, but my problem is not solved, I still face the warning.

Maybe this have to leave tomorrow, since it is very late today.

Django Dairy 1

Here is a new story, I try to use my poor English to record the days struggling with Django and related Web Technology. A big challenge for me~~

Some days before, I meet a programmer in a start-up meet. and heard about Django. A really interesting web framework using python.

At that time, I just wished to create a new site, and I think this is the time to learn new things.

However, the story between me and Django is not so sweat at the beginning. Since I am not a web guy, I do not familiar with Python, MySql also Apache, or anything related with Web……

I am a C programmer, and after that I used C++, C# and so on, but just for embedded system or window application. I only did some Joomla issue or HTML coding before. Now I can say I am facing a totally new world. This is the most exciting news for me!

Before, my trip of Django, I have to set up the environment of it, I have one laptop, one MAC mini, one windows desktop. I am newbie for MAC, and being attracted by it. So now, I turn to MAC world. I decide to set up a MAMP environment on MAC. I heard of that I should stop MAC default web server, and installed a new one, I do not know is it right or not, but I just followed.

My habit, go the Google type in MAMP, and I saw a very fantastic work, MAMP(http://www.mamp.info/en/index.html), and first tried to use it, but I got stuck… while I am trying add

LoadModule wsgi_module modules/mod_wsgi.so

in httpd.conf to load wsgi module for Apache which is recommended by Django.

It is not working. Either my Apache will not work, or my MySql. I can not get through it. So that I drop this way, and decided to installed it separately.

I found a article writing about Django working on MAMP by just put MAMP Django two words in Google searching box.

It is a blog written by Chris Gilmer, it is really helpful. I followed this article to setup everything up.

But it mostly depends on Mac Port, forgive my ignorant, I know nothing about it before. What can I do is just following the words it said.

But, things will not work in this way.

It will really good till I come this step:

To improve security of the mysql server configuration, please run mysql_secure_installation5 script and configure mysql password for root, network access, etc:

$cd /opt/local/bin

$mysql_secure_installation5

System asked me to input password……, I do not remember I have set up any password before, I tried everything I can come through, and system still do not let me go…

Finally I found a way to resetting the root password of MySql at

http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

I used the Generic Instructions to pass my problem.

At the step of Starting/Stopping Apache and MySQL, I got to know what a fool I am……

first, I followed the way article told me, nothing happened……

After that my teacher Google told me that I should modify the file named ~/.tcshrc not ~/.cshrc so I did it. And it will not work, and bring me more error, at last I got to know, the syntax of alias is not right.

The article write like this

#
# Apache Aliases
#
alias apache2ctl 'sudo /opt/local/apache2/bin/apachectl'

#
# MySQL Aliases
#
#alias mysqlstart 'sudo /opt/local/bin/mysqld_safe5 &'
alias mysqlstart 'sudo /opt/local/share/mysql5/mysql5/mysql/mysql.server start'
alias mysqlstop '/opt/local/bin/mysqladmin5 -u root -p shutdown'

#
# PHP Aliases
#
alias php ”/opt/local/bin/php”

But what works for me is following this format:

#
# Apache Aliases
#
alias apache2ctl="sudo /opt/local/apache2/bin/apachectl"

#
# MySQL Aliases
#
#alias mysqlstart 'sudo /opt/local/bin/mysqld_safe5 &'
alias mysqlstart="sudo /opt/local/share/mysql5/mysql5/mysql/mysql.server start"
alias mysqlstop="/opt/local/bin/mysqladmin5 -u root -p shutdown"

#
# PHP Aliases
#
alias php=”/opt/local/bin/php”

I know I am not familiar with all the things I faced, maybe I made a stupid mistake, but anyway I got this point, And I will continue try it tomorrow.