Advertisement
pusatdata

Fixing Joomla 1.0 for php 5.3.x

Jul 19th, 2014
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.61 KB | None | 0 0
  1. Sumber:
  2. http://lightquick.co.uk/fixing-joomla-1.0-for-php-5.3.x.html
  3.  
  4. If you are running Joomla 1.0.15 and your provider upgrades from PHP 5.2 to 5.3 you will be faced with a lot of error messages of the type:
  5.  
  6. Assigning the return value of new by reference is deprecated
  7. Function eregi() is deprecated
  8. Function eregi_replace() is deprecated
  9. Function split() is deprecated
  10. Deprecated: Function set_magic_quotes_runtime() is deprecated
  11.  
  12.  
  13. To fix this situation if you are going to continue run Joomla 1.0.15 on PHP 5.3 you have several choices: Firstly, find a friendly host that will continue to run PHP 5.2 for you. This is possible but let us be honest this is only a temporary solution as PHP 5.2 will eventually be shelved by everyone and when 5.3 is rolled out everywhere, you will be left out in the cold. It is only a matter of time. However, if you do need such a friendly host then contact me and I'll provide the details.
  14.  
  15. programs.pngSecondly, upgrade your Joomla 1.0.15 website, extensions and applications to the latest version of Joomla 2.5. This is a fine and laudable idea but in reality it is rather a lot of work, probably several days and of course, an upgrade - it isn't. It is a straight site rebuild from scratch which may end up looking just the same as the old site but for a lot of work and a lot of cash. To perform a Joomla site migration you have to migrate to 1.5 first and then of course you have to migrate to 1.6/7 then to Joomla 2.5 and again to 3.0 when it comes out, bearing in mind the current frequency of Joomla releases means that you could be rebuilding your site every year to eighteen months...and this does not even take into account all the 3rd party application data you will also need to migrate.
  16.  
  17. Thirdly, you could migrate to Joostina 1.3, Joostina was Joomla 1.0.15 on steroids and is fully compatible with PHP 5.3 (Joostina is dead now). The upgrade from Joomla 1.0.15 to Joostina 1.2 was very simple, you just needed to copy the PHP code over the old joomla code and then you had a fully Joomla 1.0 compatible site that ran all your Joomla extensions. All you needed to do was to change the language files from Russian to English.
  18.  
  19. The upgrade from Joostina 1.2 to 1.3 (to obtain PHP 5.3 compatibility) is merely an upgrade and not a whole migration as is the 'upgrade' from joomla 1.0 to 1.5. Apart from copying the code the only significant changes being a few extra columns in certain tables. The good thing about Joostina 1.3 is that it is fully PHP 5.3 compatible. As long as your joomla extensions are all PHP 5.3 compatible then you are laughing! The only major obstacle is that Joostina is still a Russian CMS and the English translations are lagging behind. I can now easily install an English version of Joostina 1.2 and with the English language translation files in place you could easily use the backend, seeing only a very few remaining untranslated items. Joostina 1.3 is fully PHP 5.3 compatible but as yet it seems that no-one has been able to find the time to convert the backend language files to English. Give me time though and I intend to do it so this route will finally be a realistic option. (Note that support for Joostina has been pulled after the team fragmented and dissipated, I no longer recommend it.)
  20.  
  21. Option no.4 - Make Joomla 1.0 installation PHP5.3 compatible
  22. So, that brings us to the main choice, you can simply make changes to your Joomla 1.0 installation to make it PHP 5.3 compatible. This is probably the easiest option and it will take approximately 2-3 hours per site to complete. This is the route that I have chosen for all my joomla 1.0 sites. The site you are reading this article on now is an example of a Joomla 1.0.15 site running on PHP 5.3. It runs quickly and well with no errors.
  23.  
  24. So, how do you achieve this change to PHP 5.3?
  25.  
  26. You will need a good ftp tool such as WinSCP to transfer the files to your PC where you will be making the changes, a good search and replace tool such as Ecobyte's "Replace Text 2.2" , a good search tool such as 'baregrep ' and a good code editor such as 'context '. You will be searching for occurrences of deprecated PHP 5.2 functions such as eregi, eregi_replace, ereg, &new and split and you will be amending them so that they stop generating any errors when your PHP is upgraded to 5.3. Baregrep can make it very easy to see where these functions occur in the Joomla code, simply search all *.PHP files for the deprecated functions. When you are confident about making the changes, Ecobyte's search and replace tool will make it very easy to actually make the changes to the code without any accidentally making any mistakes.
  27.  
  28. The first task is to transfer the files down to your PC so you can make the changes locally. Either take a backup, transfer the backup down and restore it locally or simply transfer all the site files down manually. I transferred not only Joomla but all my 3rd party components, modules and mambots, the lot, as I was prepared to make changes to them all at the same time.
  29.  
  30. Replacing ereg
  31.  
  32. When you have a local copy of the site ready for change, use baregrep and search for 'ereg' in all PHP files. All occurrences of any function starting with 'ereg' must be changed to '@ereg', this will suppress any error messages generated when PHP is using these functions. You can't do the changes manually as there may be many occurrences of the text to change, you'll need a bulk text changer like Ecobyte's "Replace Text 2.2" or a similar tool to make the changes.
  33.  
  34. Ecobyte's "Replace Text 2.2" isn't the easiest tool to use but you'll need to get the hang of the tool as it does the job well.You have to configure it to search a whole folder, to use *.php as its input filter and to only make backups of files it has changed. It has log feature but sometimes it reports nothing has been modified... a small bug but the tool is still usable. I use it in conjunction with baregrep to determine changes before and after a search and replace operation.
  35.  
  36. So, here is the text to search for. Note that you must search for the exact text as specified below along with preceding or following spaces.
  37.  
  38. look for: ereg
  39.  
  40. note that is " ereg" complete with a preceding space and replace with: @ereg
  41. note that is " @ereg" complete with a preceding space.
  42.  
  43. look for: (ereg
  44.  
  45. and replace with: (@ereg
  46.  
  47. look for: !ereg
  48.  
  49. and replace with: !@ereg
  50.  
  51. A final manual search using baregrep for ereg and eregi and the other strings will uncover any other hidden functions.
  52.  
  53. The file \includes\sef.php has one occurrence of eregi that needs to be manually changed near line 533.
  54.  
  55. eregi("^(https?:[\/]+[^\/]+)(.*$)", $mosConfig_live_site, $live_site_parts);
  56.  
  57. to be changed to :
  58.  
  59. @eregi("^(https?:[\/]+[^\/]+)(.*$)", $mosConfig_live_site, $live_site_parts);
  60.  
  61. or if you want to do it properly:
  62.  
  63. preg_match("/^(https?:[\/]+[^\/]+)(.*$)/i", $mosConfig_live_site, $live_site_parts);
  64.  
  65. -oOo-
  66.  
  67. Replacing split
  68.  
  69. The second task is to search for use of the function 'split' and replace it with the new PHP 5.3 function 'explode'. It is a straight like-for-like swap, easy to do. Be careful of replacing every occurrence of split as this is also a commonly used word and is likely to be used elsewhere in 3rd party code, possibly as a variable, just look for all uses of the split text and be prepared to exclude files that make use of the word split in other ways.
  70.  
  71. look for: split (
  72.  
  73. note that is " split (" complete with preceding and subsequent spaces before the word split and before the '('.
  74.  
  75. and replace with explode (
  76. note that is " explode (" complete with preceding and subsequent spaces. You probably won't find many instances of this but some 3rd party components may use this version.
  77.  
  78. split(
  79.  
  80. note that is " split(" complete with a preceding space before the word split.
  81.  
  82. and replace with explode(
  83. note that is " explode(" complete with preceding space.
  84.  
  85. .split(
  86.  
  87. and replace with .explode(
  88.  
  89. Note that the word split is used in other functions such as preg_split so don't just do a general search and replace on the word 'split', ensure that you replace exactly as specified above.
  90.  
  91. Replacing &new / & new
  92.  
  93. The third and final task you will need to perform is to look for all occurrences of '& new' and '&new' statements and replace them simply with 'new'. Once again, be careful and selective where you make changes as '&new' may also appear as part of a hard-coded URL especially in 3rd party components that build URLs such as virtuemart.
  94.  
  95. & new
  96.  
  97. and replace with new
  98.  
  99. &new
  100.  
  101. and replace with new
  102.  
  103. -oOo-
  104. Removing set_magic_quotes_runtime errors
  105.  
  106. The magic quotes runtime was previously used to ensure that any functions that returned data from any sort of external source including databases and text files would have quotes escaped with a backslash, it was also deprecated in PHP 5.3. As a result the following error will occur many times when you have Joomla cacheing switched ON:
  107.  
  108. Deprecated: Function set_magic_quotes_runtime() is deprecated in Cache/Lite.php on line 524
  109.  
  110. Some changes need to be made to this file /includes/Cache/Lite.php
  111.  
  112. All occurrences of the set_magic_quotes_runtime function need to be replaced by a conditional if statement.
  113.  
  114. for example change this line near line 524:
  115.  
  116. set_magic_quotes_runtime(0);
  117.  
  118. to this:
  119.  
  120. // Check if magic_quotes_runtime is active
  121. if(get_magic_quotes_runtime())
  122. {
  123. // Deactivate
  124. set_magic_quotes_runtime(0);
  125. }
  126.  
  127. The function occurs three times in various forms within the file, simply change each occurrence and add a wrapper to each. When you turn cacheing back on the error will no longer occur.
  128.  
  129. -oOo-
  130.  
  131. If the site generates the following error after the PHP 5.3 upgrade :
  132.  
  133. Warning: Parameter 2 to frontpage() expected to be a reference, value given in C:\home\web\content\includes\Cache\Lite\Function.php
  134.  
  135. Some changes need to be made to this file /includes/Cache/Lite/Function.php
  136.  
  137. Line 72:
  138.  
  139. Change this:
  140.  
  141. function call()
  142. {
  143. $arguments = func_get_args();
  144. $id = serialize($arguments); // Generate a cache id
  145.  
  146. To this:
  147.  
  148. function call()
  149. {
  150. $arguments = func_get_args();
  151. $numargs = func_num_args();
  152. for($i=1; $i < $numargs; $i++){
  153. $arguments[$i] = &$arguments[$i];
  154. }
  155. $id = serialize($arguments); // Generate a cache id
  156.  
  157. -oOo-
  158. Com_contact vcard.class.php error
  159.  
  160. When you click on the contact page of your site if you are using the Joomla 1.0 contact component, the following error may occur:
  161.  
  162. Fatal error: Cannot redeclare quoted_printable_encode() in includes/vcard.class.php on line 74
  163. In vcard.class.php at line 36 you will find the function 'quoted_printable_encode'. This function is declared twice. To avoid the error add some code to check if the function already exists. Add the if statement and subsequent closing curly bracket } around the function.
  164.  
  165. Change this:
  166.  
  167. function quoted_printable_encode($input, $line_max=76) {
  168. $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
  169. $lines = preg_split("/(?:\r\n|\r|\n)/", $input);
  170. $eol = "\r\n";
  171. $linebreak = '=0D=0A';
  172. $escape = '='; $output = '';
  173. .
  174. .
  175. .
  176. }
  177.  
  178. To this:
  179. if(!function_exists('quoted_printable_encode')) {
  180. function quoted_printable_encode($input, $line_max=76) {
  181. $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
  182. $lines = preg_split("/(?:\r\n|\r|\n)/", $input);
  183. $eol = "\r\n";
  184. $linebreak = '=0D=0A';
  185. $escape = '=';
  186. $output = '';
  187. .
  188. .
  189. .
  190. }
  191. }
  192.  
  193. I do hope you realise that the dot, dot, dots in the example above represent the code continuing... you need to enclose the lot.
  194.  
  195. -oOo-
  196.  
  197. Joostina 1.2 (Joomla 1.0.15 clone)
  198.  
  199. If you are running Joostina 1.2 then all of the above steps apply just as they would do for Joomla 1.0.15. The only other file you are likely to have to change manually is:
  200.  
  201. \includes\frontend.php
  202.  
  203. Line 298 has a single strip statement that needs to be changed to an explode statement.
  204.  
  205. $keys = implode(', ',array_unique(explode(', ',$keys)));
  206.  
  207. -oOo-
  208.  
  209. Tidying up:
  210.  
  211. This will account for 99.9% of all occurrences of the deprecated functions in the core joomla code. If you are using a multitude of components written by 3rd party developers then the above searches will still account for approx. 95% or more of all occurrences. A final manual search using baregrep for ereg and eregi and the other strings will uncover any other hidden functions.
  212.  
  213. -oOo-
  214.  
  215.  
  216.  
  217. Things to watch out for:
  218.  
  219. If you have carried the above replacements correctly and exactly as suggested then that is all the deprecated functions removed. However, if you decide to do it your own way just take care not to replace any other occurrences of the text strings in help messages or in text/code elsewhere. For example in the Dutch translation of some components the word Geregistreerd is used regularly and it contains 'ereg'. Also some daft programmers use the text 'ereg' in their variables, joomlaXplorer does this using a variable $ereg.
  220.  
  221. Basically, you will need to review all your changes to ensure that only changes to deprecated code are made.If you have followed my instructions above to the letter then the chances of this occurring will be minimised,
  222.  
  223. You should watch out for the geshi library files \libraries\geshi\php-brief.php and \libraries\geshi\php.php - don't make any changes in these two files as it is simply referring to the utilities and not calling them.
  224.  
  225. file-properties-250.pngPurists will state that suppressing the errors is not the right thing to do and instead you should be replacing the 'ereg' functions with PHP 5.3 'preg' functions. This is the 'ideal' thing to do in an ideal world but in reality the number of changes you would be making and the amount of testing you would have to do makes this a little impractical. Be aware that these 'deprecated' errors are just warnings in any case, their job is to make the site owner aware that these 5.2 functions will one day be removed from future versions of PHP. The good news is that regardless of the messages, they work perfectly well in PHP 5.3 and 5.4, so for the medium term, usage of these functions is secure for your Joomla 1.0 site. We are not talking months but several years here regarding the availability of PHP 5.3 alone. Web hosts first started running PHP 5.2 in 2007 and it is stll here in late 2013. PHP 5.3 arrived in mid-2009 and will be available until 2015-2016.
  226.  
  227. -oOo-
  228.  
  229. That's it, that is the changes made. So how do we test? Many professional hosts can turn on PHP 5.3 selectively, so if you are running WHM and CPANEL then each of your domains can simply be toggled between PHP 5.2 and 5.3.
  230.  
  231. It might also be wise to build a duplicate site and switch that to 5.3 as a trial.
  232.  
  233. You could simply inform your users and switch your target site to PHP 5.3 - but that might be just asking for trouble. I suggest you build a duplicate, switch it to PHP 5.3, make the changes. At first it will still generate hundreds of error messages of the type:
  234.  
  235. Assigning the return value of new by reference is deprecated
  236. Function eregi() is deprecated
  237. Function eregi_replace() is deprecated
  238. Function split() is deprecated
  239. Deprecated: Function set_magic_quotes_runtime() is deprecated
  240.  
  241. But as you selectively apply your code changes to the site you can watch as the errors disappear... When the site is complete it will be ready to go live.
  242.  
  243. If you have made the changes locally (on your PC) then you should then start to migrate them back to the live site using an FTP tool such as WinSCP. I recommend that you copy chunks of the code up, folder by folder. First the /public_html/administrator/ folders: components, modules, templates &c, then the folders under public_html.
  244.  
  245. For example, what I do is the following:
  246.  
  247. i. After you have made all the changes, locally on the PC, rename the updated modules folder to modules.2
  248. ii. Copy the new modules.2 folder across to the server via ftp.
  249. iii. When complete, on the server rename the modules folder to modules.1
  250. iv. Rename new modules.2 folder to modules
  251.  
  252. This will make the folder changes go live pretty much instantaneously. This means there is only 1 or 2 seconds of downtime whilst you rename the folders and you will also have the old unchanged folder to hand on the server just in case you need to restore a file or two. The following image might explain it better than words...
  253.  
  254. renaming.jpg
  255.  
  256. Then check the backend works as you copy each folder in turn. Any errors introduced will be easier to diagnose if done bit by bit. Check the standard Joomla back end and then the components, includes, modules and templates. Check the errors as they occur and fix them as they crop up. Most will be caused by accidental or mistaken replacements. Remember, you have the backups and can restore any file you need.
  257.  
  258. Then turn off all cacheing, go to the public_html folder and start to copy the main include folder, front end mambots, modules and components folders as described above, taking care to test as you copy. In this way it should be possible to make and migrate all the changes within the span of one day's hard work, even including time spent diagnosing mistakes made in the replacement code.
  259.  
  260. -oOo-
  261.  
  262. It will take an hour or two but the end result will be a Joomla 1.0.15 site that is fully functional in PHP 5.3, a site that will be able to run for three/four more years, this will give you time to replace those ereg functions with the correct 'preg' functions so that the site will be fully compatible with even later versions of PHP beyond 6.0.
  263.  
  264. Bear in mind that there is a real concrete benefit from running Joomla 1.0.15 in PHP 5.3 - the site will run significantly faster as PHP5.3 is definitely quicker than 5.2. It will run faster than an equivalent Joomla 1.5 site and that one benefit alone benefit cannot be dismissed.
  265.  
  266. https://github.com/micheas/Joomla-1.0/downloads Lastly, a kind soul called Micheas Herman has created an unofficial patch of Joomla 1.0 to take it to 1.0.16. What he has done is to replace a lot of the deprecated functions with updated code that is now compatible with PHP 5.3. However, the changes are incomplete and as a result there are still occurrences of deprecated code in the code base and so errors will occur. I estimate that the job is approx. 70% complete and I am guessing that Michaes simply made changes to prevent any errors that were occurring on his site. These may well correct the majority of errors in the majority of sites - so the patch may well be suitable for you. However I consider it a work in progress but a good base from which to continue to make the changes. I making the remainder of the changes myself and will offer an unoffical 1.0.17 patch to download when it is ready. Michaes 1.0.16 patch is here and my Joomla 1.0.17 patch will be here when it is ready - it is currently untried and untested but the changes have been made to the code.
  267.  
  268. -oOo-
  269.  
  270. Joomla 1.5 deprecated code errors
  271.  
  272. Whilst this article is for Joomla 1.0 systems, Joomla 1.5 is not immune from errors after an upgrade to PHP 5.3. The same deprecated code errors will start to occur due to some Joomla 1.5 code being incompatible. Also, 3rd party code written for Joomla 1.5 will certainly be using some deprecated functions, it's all down to the sloppiness of the developer. By following the above processes for a Joomla 1.0 site, you'll have 99% of the deprecated functions handled in any joomla 1.5 site too.
  273.  
  274. For example: the icon that creates a PDF version of the page content on all Joomla 1.5 articles uses the magic quotes function, you will need to modify:
  275.  
  276. /public_html/libraries/tcpdf/tcpdf.php
  277.  
  278. in the same way as you modified lite.php above.
  279.  
  280. -oOo-
  281.  
  282. To show you that running a Joomla 1.0.15 site on PHP 5.3 is possible, here is an example of a modified Joomla 1.0.15 site running Virtuemart 1.0.15 on PHP5.3 - carstuffdirect.co.uk. This site has had all the deprecated ereg, split and new functions replaced by preg_match and explode functions. The site is an un-cached and un-optimised site that runs efficiently and definitely faster than a comparative Joomla 1.5 site. So, if you want your Joomla 1.0.15 site to be transplanted deeper into the 21st century without having to incur all the work to migrate and rebuild a new site from scratch - then this is a workable alternative. None of this work is beyond a Joomla specialist and you could possibly do it yourself if you are an Joomla enthusiast - with some technical competence, some confidence and the free tools listed above.
  283.  
  284. -oOo-
  285.  
  286. padlock-large.pngFinally, make sure that your Joomla/Joostina site is secure. Joomla 1.0.15/Joostina 1.2 both have two vulnerabilities that a hacker could use to exploit the system and inject file. Both have solutions which can be found here: Is Joomla 1.0.15 still secure?
  287.  
  288. -oOo-
  289.  
  290. If you want someone else to carry out the work to fix the above for you then it could be done for a mere day's pay ... contact me here:
  291.  
  292. Timezones
  293.  
  294. Another PHP 5.3 change is to how the timezones are set.
  295.  
  296. The easiest solution I've found for fixing that aspect is to place some timezone code in the .htaccess file for your site. Assuming you're using it for SEF URLs already, it will have been renamed from htaccess.txt, so you should just need to edit your .htaccess file.
  297.  
  298. Add the following, changing your timezone to your required timezone:
  299.  
  300. # set the server timezone SetEnv TZ Australia/Victoria
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement