get_version_info.php

Locked
User avatar
jalil
Joomla! Guru
Joomla! Guru
Posts: 925
Joined: Wed Jul 04, 2007 4:54 am
Location: Kuala Lumpur, Malaysia
Contact:

get_version_info.php

Post by jalil » Sun Jun 22, 2008 9:29 pm

If you wish to code for any Joomla version, this is one way to go, and it is hoped that this can be adopted as standard so that it makes life a little less painful for developers.

Note also that if you use this file, you must know what you are doing.
File is released as GPL and open source.


File get_version_info.php
This version information is intended and the main version detector, for joomla and joomla extension programs.
The use is simple enough...

Constant _J1 represents Joomla 1.X Series,
Constant _J5 represents Joomla 1.5 Series.

Values of the Constants defined are as per attached HTML file.


Example Usage
--------------------------------------------------------------------------------
Example (1)

Variables $mosConfig_live_site & $mosConfig_absolute_path; are very important variables for the correct functioning of Joomla. The example below restores the variables for your use, regardless of the version of Joomla running.

//...............................................................................
global $mainframe;

if (constant('_J1'))
{
global $mainframe,$mosConfig_live_site,$mosConfig_absolute_path;
}
else if (constant('_J5'))
{
$mosConfig_live_site=JURI::root();
$mosConfig_absolute_path = JPATH_SITE;
}
//...............................................................................

->at this point, you have both variables from 1.0 and 1.5 at your disposal to code peacefully.


--------------------------------------------------------------------------------
Example (2)


When and if you need to detect and cater for Legacy mode, use the value of the constant, instead of just its trueness. The following example obtains template information. In Legacy mode, template information cannot be obtained using Joomla 1.0 method, the thus

extensions written to read templates need to use Joomla 1.5 services when operating in Legacy mode.

//...............................................................................
if (constant('_J1')==1)
{
$rows=page_getTemplates( 0 );
}
else if (constant('_J5') OR constant('_J1')==2)
{
global $mainframe;
$template_server=new TemplatesHelper();
$templateBaseDir=MYROOTDIR.DS."templates";
$rows=$template_server->parseXMLTemplateFiles($templateBaseDir);
}
//...............................................................................

Example 2 puts get_Template function into Joomla 1.5 object function call while in Joomla 1.5 environment, regardless
of wether users opts for Native or Legacy Mode.




Other variables and constants declared.

Constant Joomla will now carry textual information about the specific Joomla install. It spits out the following info in the format below


Joomla (evolution) (generation) (breed) (Legacy Mode)

Thus, echo Joomla will yield the text " Joomla 1.0.15 " when executed on Joomla 1.0.15.

Note that a constant is global.

( excerpt taken from PHP Manual : Chapter 13 : Thu Feb 15 00:43:49 2007
" Like superglobals, the scope of a constant is global. You can access constants anywhere in your script without regard to scope. For more information on scope, read the manual section on variable scope. " )




--------------------------------------------------------------------------------

This get_version.php file is intended to provide a way out for developers who are faced with the challenge of producing single file codes that can tun on any version of Joomla. An example of such a version i have made, in the form of a rather interesting application extension (component/module) called myJSpace. In that project the codes can be installed and run in any Joomla version.



Thank You and Have Fun coding.

~ jalil ~


04:41 2008-06-23

--------------------------------------------------------------------------------
You do not have the required permissions to view the files attached to this post.
Last edited by jalil on Thu Jun 26, 2008 1:42 pm, edited 1 time in total.

Jobbie
Joomla! Intern
Joomla! Intern
Posts: 81
Joined: Thu Mar 09, 2006 2:27 am
Location: Sydney, Australia
Contact:

Re: get_version_info.php

Post by Jobbie » Thu Jun 26, 2008 4:35 am

Thanks :)

This is exactly the kind of thing I needed to work out and your script has helped a lot.
jTips - Your Ultimate Tipping System - http://www.jtips.com.au
Follow me on Twitter http://twitter.com/joomux

User avatar
jalil
Joomla! Guru
Joomla! Guru
Posts: 925
Joined: Wed Jul 04, 2007 4:54 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: get_version_info.php

Post by jalil » Thu Jun 26, 2008 1:43 pm

you're most welcomed.
add and subtract as you please.


Locked

Return to “Joombie Think Tank”