PageRenderTime 34ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_joomfish/controler.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 2074 lines | 1459 code | 305 blank | 310 comment | 253 complexity | 7e5b56ecde90c396f155207855684a33 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Joom!Fish - Multi Lingual extention and translation manager for Joomla!
  4. * Copyright (C) 2003-2007 Think Network GmbH, Munich
  5. *
  6. * All rights reserved. The Joom!Fish project is a set of extentions for
  7. * the content management system Joomla!. It enables Joomla!
  8. * to manage multi lingual sites especially in all dynamic information
  9. * which are stored in the database.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version 2
  14. * of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
  24. *
  25. * The "GNU General Public License" (GPL) is available at
  26. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  27. * -----------------------------------------------------------------------------
  28. * $Id: admin.joomfish.php 445 2007-04-13 18:15:17Z akede $
  29. *
  30. */
  31. defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  32. /**
  33. * The JoomFish Tasker manages the general tasks within the Joom!Fish admin interface
  34. *
  35. */
  36. class JoomfishControler extends mosAbstractTasker {
  37. /** @var string current used task */
  38. var $task=null;
  39. /** @var string action within the task */
  40. var $act=null;
  41. /** @var array int or array with the choosen list id */
  42. var $cid=null;
  43. /** @var string file code */
  44. var $fileCode = null;
  45. /**
  46. * @var object reference to the Joom!Fish manager
  47. * @access private
  48. */
  49. var $_joomfishManager=null;
  50. /**
  51. * PHP 4 constructor for the tasker
  52. *
  53. * @return joomfishTasker
  54. */
  55. function JoomfishControler( ){
  56. parent::mosAbstractTasker( 'showCPanel' );
  57. $this->act = mosGetParam( $_REQUEST, 'act', '' );
  58. $this->task = mosGetParam( $_REQUEST, 'task', '' );
  59. $this->cid = mosGetParam( $_REQUEST, 'cid', array(0) );
  60. if (!is_array( $this->cid )) {
  61. $this->cid = array(0);
  62. }
  63. $this->fileCode = mosGetParam( $_REQUEST, 'fileCode', '' );
  64. $this->_joomfishManager =& $GLOBALS['joomFishManager'];
  65. $this->registerTask( 'postInstall', 'postInstall' );
  66. $this->registerTask( 'upgrade', 'upgradeMambelFish' );
  67. $this->registerTask( 'check', 'showCheckStatusInformation' );
  68. $this->registerTask( 'copy', 'showCopyInformation' );
  69. }
  70. function showCPanel() {
  71. $panelStates = array();
  72. $systemState = $this->_checkSystemState();
  73. $panelStates['directory_state'] = $systemState['directory_state'];
  74. $panelStates['directory'] = $systemState['directory'];
  75. $panelStates['extension_state'] = $systemState['extension_state'];
  76. $panelStates['extension'] = $systemState['extension'];
  77. $panelStates['mbfInstall'] = $this->_testOldInstall();
  78. $panelStates['system'] = $this->_getSystemInfo();
  79. $contentInfo = array();
  80. $contentInfo['unpublished'] = $this->_testUnpublisedTranslations();
  81. //$contentInfo['orphans'] = $this->_testOrphans( );
  82. //$contentInfo = $this->_testContentElements();
  83. HTML_joomfish::showCPanel( $panelStates, $contentInfo );
  84. }
  85. /**
  86. * Generic method to process the back toolbar icon
  87. */
  88. function processBack() {
  89. switch ($this->act) {
  90. case 'config_elements':
  91. $this->showElementOverview();
  92. break;
  93. }
  94. }
  95. /**
  96. * presenting the translation dialog
  97. *
  98. */
  99. function showTranslate() {
  100. global $language_id, $select_language_id, $catid, $contentid, $jfc_id;
  101. $this->_setupContentElementCache();
  102. if( $this->_message != '' ) {
  103. echo "<div class=\"message\">" .$this->_message. "</div>";
  104. }
  105. if( !$this->_testSystemBotState() ) {;
  106. echo "<div style='font-size:16px;font-weight:bold;color:red'>".JText::_('MAMBOT_ERROR')."</div>";
  107. }
  108. $this->showTranslationOverview( $select_language_id, $catid );
  109. }
  110. function showHelp() {
  111. if( $this->task == "home" ) {
  112. $this->_redirect = "index2.php?option=com_joomfish";
  113. return;
  114. }
  115. HTML_joomfish_help::showHelp();
  116. }
  117. function showCredits() {
  118. if( $this->task == "home" ) {
  119. $this->_redirect = "index2.php?option=com_joomfish";
  120. return;
  121. }
  122. HTML_joomfish_help::showWelcome();
  123. }
  124. function showInformation() {
  125. if( $this->task == "home" ) {
  126. $this->_redirect = "index2.php?option=com_joomfish";
  127. return;
  128. }
  129. HTML_joomfish::showInformation( $this->fileCode );
  130. }
  131. function postInstall () {
  132. if( $this->task == "home" ) {
  133. $this->_redirect = "index2.php?option=com_joomfish";
  134. return;
  135. }
  136. HTML_joomfish_help::showPostInstall();
  137. }
  138. function showComponentConfig() {
  139. global $database;
  140. $languages = array();
  141. $langDirs = $this->_findDirectories( mosMainFrame::getBasePath() . 'components/com_joomfish/language/' );
  142. foreach($langDirs as $language ) {
  143. $languages[] = mosHTML::makeOption( $language, ucfirst( $language ) );
  144. }
  145. HTML_joomfish::showComponentConfiguration( $this->_joomfishManager, $languages);
  146. }
  147. function saveComponentConfiguration() {
  148. $this->_joomfishManager->setCfg( 'componentAdminLang' , mosGetParam( $_REQUEST, 'frmComponentAdminLanguage', 'english' ) );
  149. $this->_joomfishManager->setCfg( 'noTranslation' , mosGetParam( $_REQUEST, 'frmTranslationMode', 0 ) );
  150. $this->_joomfishManager->setCfg( 'defaultText', mosGetParam( $_REQUEST, 'frmTranslationDefaultText', "" ) );
  151. $this->_joomfishManager->setCfg( 'storageOfOriginal', mosGetParam( $_REQUEST, 'frmStorageOfOriginal', "md5" ) );
  152. $this->_joomfishManager->setCfg( 'frontEndPublish' , mosGetParam( $_REQUEST, 'frmPublish',1));
  153. $this->_joomfishManager->setCfg( 'frontEndPreview' , mosGetParam( $_REQUEST, 'frmFrontEndPreview',1));
  154. $this->_joomfishManager->setCfg( 'qacaching' , mosGetParam( $_REQUEST, 'qacaching',0));
  155. $this->_joomfishManager->setCfg( 'qalogging' , mosGetParam( $_REQUEST, 'qalogging',0));
  156. $frmShowCPanels = mosGetParam( $_REQUEST, 'frmShowCPanels', 0);
  157. if(is_array($frmShowCPanels)) {
  158. $total = 0;
  159. foreach ($frmShowCPanels as $cpanelMod) {
  160. $total += $cpanelMod;
  161. }
  162. $frmShowCPanels = $total;
  163. }
  164. $this->_joomfishManager->setCfg( 'showCPanels' , $frmShowCPanels);
  165. $configSaved = $this->_joomfishManager->saveConfiguration();
  166. if( $configSaved ) {
  167. if( $this->task == 'save' ) {
  168. $this->_redirect = "index2.php?option=com_joomfish&amp;hidemainmenu=0";
  169. } else {
  170. $this->_redirect = "index2.php?option=com_joomfish&amp;task=show&amp;act=config_component&amp;hidemainmenu=1";
  171. }
  172. $this->_message = JText::_('CONFIG SAVED');
  173. } else {
  174. $this->_redirect = "index2.php?option=com_joomfish&amp;task=config_component";
  175. $this->_message = JText::_('CONFIG_PROBLEMS');
  176. }
  177. }
  178. function showCElementConfig() {
  179. global $database;
  180. $this->_setupContentElementCache();
  181. switch ($this->task) {
  182. case "uploadfile":
  183. if( $this->_installContentElement() ) {
  184. $this->_message = JText::_('Fileupload successful');
  185. } else {
  186. $this->_message = JText::_('Fileupload not successful');
  187. }
  188. $cElements = $this->_joomfishManager->getContentElements(true);
  189. HTML_joomfish::showContentElementInstaller( $cElements, $this->_message );
  190. break;
  191. default:
  192. $this->showElementOverview();
  193. break;
  194. }
  195. }
  196. /**
  197. * Installs the uploaded file
  198. *
  199. */
  200. function _installContentElement() {
  201. if (@is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
  202. $installer = new jfInstaller();
  203. return $installer->install( $_FILES["userfile"] );
  204. } else {
  205. return false;
  206. }
  207. }
  208. /**
  209. * method to remove all selected content element files
  210. */
  211. function removeContentElement() {
  212. if( $this->_deleteContentElement($this->cid[0]) ) {
  213. $this->_message =JText::_('Elementfile deleted');
  214. }
  215. $cElements = $this->_joomfishManager->getContentElements(true);
  216. HTML_joomfish::showContentElementInstaller( $cElements, $this->_message );
  217. }
  218. /**
  219. * Method deletes one content element file
  220. * @param filename
  221. */
  222. function _deleteContentElement( $filename = null ) {
  223. global $mosConfig_absolute_path;
  224. $elementfolder = mosPathName( $mosConfig_absolute_path . '/administrator/components/com_joomfish/contentelements' );
  225. $filename .= '.xml';
  226. return @unlink( $elementfolder . $filename );
  227. }
  228. /**
  229. * shows the language configuration
  230. *
  231. */
  232. function showLanguageConfig() {
  233. global $database;
  234. if ( $this->task == 'cancel' ) {
  235. $this->_redirect = "index2.php?option=com_joomfish&hidemainmenu=0";
  236. } elseif ( $this->task == 'site_config' ) {
  237. $this->_redirect = "index2.php?option=com_config&hidemainmenu=1";
  238. } else {
  239. if( $this->_message != '' ) {
  240. echo "<div class=\"message\">" .$this->_message. "</div>";
  241. }
  242. // 1. read all known languages from the database
  243. $languages=null;
  244. $database->setQuery( "SELECT l.*"
  245. . "\nFROM #__languages AS l"
  246. . "\nORDER BY l.active desc, l.ordering, l.name"
  247. );
  248. $languages = $database->loadObjectList();
  249. // Read the languages dir to find new installed languages
  250. $languageBaseDir = mosPathName(mosPathName(mosMainFrame::getBasePath()) . "language");
  251. $xmlFilesInDir = mosReadDirectory($languageBaseDir,".xml");
  252. $dirName = $languageBaseDir;
  253. $activeFiles = null;
  254. // XML library
  255. require_once( mosMainFrame::getBasePath() . "/includes/domit/xml_domit_lite_include.php" );
  256. //mosDebugVar($xmlFilesInDir);
  257. foreach($xmlFilesInDir as $xmlfile) {
  258. // Read the file to see if it's a valid template XML file
  259. $xmlDoc =& new DOMIT_Lite_Document();
  260. $xmlDoc->resolveErrors( true );
  261. if (!$xmlDoc->loadXML( $dirName . $xmlfile, false, true )) {
  262. continue;
  263. }
  264. $element = &$xmlDoc->documentElement;
  265. if ($element->getTagName() != 'mosinstall') {
  266. continue;
  267. }
  268. if ($element->getAttribute( "type" ) != "language") {
  269. continue;
  270. }
  271. $language = $this->_getLanguageFromXML( $xmlfile );
  272. // Let's see if we find the language already
  273. $languageFound=false;
  274. foreach($languages as $dbLang) {
  275. if ($dbLang->code == $language->code) {
  276. $languageFound=true;
  277. break;
  278. }
  279. }
  280. if( !$languageFound ) {
  281. $languages[] = $language;
  282. }
  283. }
  284. /*elseif (!$languagesSaved) {
  285. $this->_redirect = "index2.php?option=com_joomfish&task=config_component";
  286. $this->_message = JText::_('CONFIG_PROBLEMS');
  287. mosRedirect("index2.php?option=com_joomfish&task=config_component", JText::_('LANG_PROBLEMS') ." - " .$jfLang->getError());
  288. }*/
  289. HTML_joomfish::showLanguageConfiguration( $this->_joomfishManager, $languages );
  290. }
  291. }
  292. function saveLanguageConfig() {
  293. global $database;
  294. $languagesSaved=false;
  295. $frmLanguageID = mosGetParam( $_REQUEST, 'frmLanguageID', '' );
  296. $frmLanguageName = mosGetParam( $_REQUEST, 'frmLanguageName', '' );
  297. $frmLanguageActive = mosGetParam( $_REQUEST, 'frmLanguageActive', '' );
  298. $frmLanguageISO = mosGetParam( $_REQUEST, 'frmLanguageISO', '' );
  299. $frmLanguageShortCode = mosGetParam( $_REQUEST, 'frmLanguageShortCode', '' );
  300. $frmLanguageCode = mosGetParam( $_REQUEST, 'frmLanguageCode', '' );
  301. $frmLanguageImage = mosGetParam( $_REQUEST, 'frmLanguageImage', '' );
  302. $frmLanguageOrder = mosGetParam( $_REQUEST, 'frmLanguageOrder', '' );
  303. $frmLanguageFallbackCode = mosGetParam( $_REQUEST, 'frmLanguageFallbackCode', '' );
  304. if( is_array($frmLanguageID) ) {
  305. $languagesSaved = true;
  306. for ($i=0; $i<count($frmLanguageID); $i++) {
  307. $jfLang = new jfLanguage($database);
  308. $jfLang->id =$frmLanguageID[$i];
  309. $jfLang->name = $frmLanguageName[$i];
  310. // The checkbox is only filled when it was active - so we have to check if
  311. // one box is fitting to your language
  312. if( isset($frmLanguageActive) ) {
  313. foreach( $frmLanguageActive as $langid ) {
  314. if( $langid == $jfLang->id ) {
  315. $jfLang->active = true;
  316. break;
  317. }
  318. }
  319. }
  320. $jfLang->iso = $frmLanguageISO[$i];
  321. $jfLang->shortcode = $frmLanguageShortCode[$i];
  322. $jfLang->code = $frmLanguageCode[$i];
  323. $jfLang->image = $frmLanguageImage[$i];
  324. $jfLang->ordering = $frmLanguageOrder[$i];
  325. $jfLang->fallback_code = $frmLanguageFallbackCode[$i];
  326. if( !$jfLang->store() ) {
  327. echo "Error: ".$jfLang->getError()."<br />";
  328. $languagesSaved=false;
  329. }
  330. }
  331. }
  332. if( $languagesSaved ) {
  333. if( $this->task == 'save' ) {
  334. $this->_redirect = "index2.php?option=com_joomfish&hidemainmenu=0";
  335. } else {
  336. $this->_redirect = "index2.php?option=com_joomfish&amp;task=show&amp;act=config_language&amp;hidemainmenu=1";
  337. }
  338. $this->_message = JText::_('CONFIG SAVED');
  339. } else {
  340. $this->_redirect = "index2.php?option=com_joomfish&amp;task=show&amp;act=config_language";
  341. $this->_message = JText::_('CONFIG_PROBLEMS');
  342. }
  343. }
  344. /**
  345. * Translate config settings
  346. */
  347. function saveTranslateConfig(){
  348. $lang = intval(mosGetParam($_REQUEST,"lang",-1));
  349. if ($lang>0){
  350. global $database;
  351. // confirm this is a valid language
  352. $database->setQuery( "SELECT l.*"
  353. . "\nFROM #__languages AS l"
  354. . "\nWHERE id=$lang");
  355. $language = null;
  356. $database->loadObject($language);
  357. if (!isset($language)){
  358. echo JText::_("No such language id");
  359. exit();
  360. }
  361. $registry = JRegistry::getInstance("fred","translateconfig");
  362. $filename = dirname(__FILE__)."/contentelements/mosconfig.ini";
  363. if (file_exists( $filename ) && $content = @file_get_contents( $filename )) {
  364. $registry->loadINI($content);
  365. $itemsToTranslate = $registry->toArray();
  366. $params = new mosParameters( $language->params );
  367. foreach ($itemsToTranslate as $item=>$type) {
  368. // TODO only handles text types!!!
  369. $params->set($item,mosGetParam($_REQUEST,"transConf".$item,""));
  370. }
  371. // param handling
  372. $saveparams = "";
  373. if (is_array( $params->toArray() )) {
  374. $txt = array();
  375. foreach ( $params->toArray() as $k=>$v) {
  376. if ($v!=""){
  377. $txt[] = "$k=$v";
  378. }
  379. }
  380. $saveparams = implode( "\n", $txt );
  381. }
  382. $database->setQuery( "UPDATE #__languages SET params='".$saveparams."' WHERE id=$lang");
  383. if ($database->query()){
  384. $this->_message = JText::_('Translation saved');
  385. }
  386. else {
  387. $this->_message = JText::_('Translation NOT saved !!');
  388. }
  389. }
  390. }
  391. else {
  392. echo JText::_("Bad language id");
  393. exit();
  394. }
  395. }
  396. /**
  397. * Method to remove languages
  398. */
  399. function removeLanguages() {
  400. global $database;
  401. $frmLanguageDelete = mosGetParam( $_REQUEST, 'frmLanguageDelete', '' );
  402. if( $frmLanguageDelete != null && count($frmLanguageDelete)>0) {
  403. foreach ($frmLanguageDelete as $langid) {
  404. $jfLang = new jfLanguage($database);
  405. // This removes all jf_contents for this language as well!
  406. $jfLang->delete($langid);
  407. $this->_message = JText::_('DEL_SUCESSFUL');
  408. }
  409. }
  410. $this->showLanguageConfig();
  411. }
  412. /**
  413. * Translate config settings
  414. */
  415. function translateConfig(){
  416. // warning if mambot is not enabled for config setting translation
  417. global $database;
  418. $database->setQuery( "SELECT * FROM #__mambots WHERE element='jfdatabase.systembot'");
  419. $database->query();
  420. $mambot = null;
  421. $database->loadObject($mambot);
  422. $botParams = new mosParameters( $mambot->params );
  423. if ($botParams->get("overwriteGlobalConfig",0)!=1){
  424. $this->_message.=JText::_("OVERWRITE_GLOBAL_CONFIG_DISABLED");
  425. }
  426. $lang = intval(mosGetParam($_REQUEST,"lang",-1));
  427. if ($lang>0){
  428. if( $this->_message != '' ) {
  429. echo "<div class=\"message\">" .$this->_message. "</div>";
  430. }
  431. global $database;
  432. // confirm this is a valid language
  433. $database->setQuery( "SELECT l.*"
  434. . "\nFROM #__languages AS l"
  435. . "\nWHERE id=$lang");
  436. $language = null;
  437. $database->loadObject($language);
  438. if (!isset($language)){
  439. echo JText::_("No such language id");
  440. exit();
  441. }
  442. $registry = JRegistry::getInstance("fred","translateconfig");
  443. $filename = dirname(__FILE__)."/contentelements/mosconfig.ini";
  444. if (file_exists( $filename ) && $content = @file_get_contents( $filename )) {
  445. $registry->loadINI($content);
  446. $itemsToTranslate = $registry->toArray();
  447. HTML_joomfish::translateConfig( $itemsToTranslate, $language );
  448. }
  449. else{
  450. // mic
  451. echo JText::_( 'FILE MOSCONFIGINI MISSING' );
  452. }
  453. }
  454. else {
  455. echo JText::_("Bad language id");
  456. exit();
  457. }
  458. }
  459. /**
  460. * Provides a basic upgrade functionallity based
  461. */
  462. function showUpgrade() {
  463. $upgradeSucessful = false;
  464. $upgradeDone = $this->_joomfishManager->getCfg( 'jfupgradeDone' );
  465. $lists = array();
  466. $lists['confirmDelete'] = mosGetParam( $_REQUEST, 'confirmDelete', 0 );
  467. $lists['backupTables'] = mosGetParam( $_REQUEST, 'backupTables', 1 );
  468. $lists['renameTables'] = mosGetParam( $_REQUEST, 'renameTables', 1 );
  469. HTML_joomfish::showUpgradeInstall( $this->_joomfishManager, $upgradeSucessful, $upgradeDone, $lists );
  470. }
  471. /**
  472. * Method to execute the MambelFish upgrade
  473. */
  474. function upgradeMambelFish() {
  475. $upgradeSucessful = false;
  476. $upgradeDone = $this->_joomfishManager->getCfg( 'mbfupgradeDone', '0' );
  477. $lists = array();
  478. $lists['confirmDelete'] = mosGetParam( $_REQUEST, 'confirmDelete', 0 );
  479. $lists['backupTables'] = mosGetParam( $_REQUEST, 'backupTables', 1 );
  480. $lists['renameTables'] = mosGetParam( $_REQUEST, 'renameTables', 1 );
  481. if( !$lists [ 'confirmDelete'] ) {
  482. $this->_message = JText::_('UPGRADE_ERROR_CONFIRM');
  483. $this->_redirect = "index2.php?option=com_joomfish&amp;task=show&amp;act=upgrade_install&amp;hidemainmenu=1";
  484. } else {
  485. $summary = $this->_upgradeInstallation( $lists['backupTables'], $lists['renameTables'] );
  486. if( !$summary['state'] ) {
  487. $upgradeSucessful = false;
  488. $upgradeDone = 1;
  489. $summary['message'] = JText::_('UPGRADE_ERROR_UPGRADE');
  490. $this->_message = JText::_('UPGRADE_ERROR_UPGRADE');
  491. $lists['summary'] = $summary;
  492. } else {
  493. $upgradeSucessful = true;
  494. $upgradeDone = 1;
  495. $this->_joomfishManager->setCfg( 'mbfupgradeDone', $upgradeDone );
  496. $this->_joomfishManager->saveConfiguration();
  497. $lists['summary'] = $summary;
  498. }
  499. HTML_joomfish::showUpgradeInstall( $this->_joomfishManager, $upgradeSucessful, $upgradeDone, $lists );
  500. }
  501. }
  502. /**
  503. * Helperfunction to retriev the language information from the XML files
  504. */
  505. function _getLanguageFromXML( $xmlfile ) {
  506. global $database;
  507. // Read the language dir to find languages
  508. $languageBaseDir = mosPathName(mosPathName(mosMainFrame::getBasePath()) . "language");
  509. $dirName = $languageBaseDir;
  510. // XML library
  511. require_once( mosMainFrame::getBasePath() . "/includes/domit/xml_domit_lite_include.php" );
  512. $xmlDoc =& new DOMIT_Lite_Document();
  513. $xmlDoc->resolveErrors( true );
  514. if ($xmlDoc->loadXML( $dirName . $xmlfile, false, true )) {
  515. $lang = new jfLanguage($database);
  516. $lang->code = substr($xmlfile,0,-4);
  517. $element = &$xmlDoc->getElementsByPath('name', 1);
  518. $lang->name = $element->getText();
  519. $lang->active=false;
  520. }
  521. return $lang;
  522. }
  523. /** Presentation of the content element list
  524. */
  525. function showElementOverview() {
  526. global $database, $mainframe;
  527. $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', 10 );
  528. $limitstart = $mainframe->getUserStateFromRequest( "view{com_joomfish}limitstart", 'limitstart', 0 );
  529. $total=count($this->_joomfishManager->getContentElements());
  530. require_once( mosMainFrame::getBasePath() . "/administrator/includes/pageNavigation.php");
  531. $pageNav = new mosPageNav( $total, $limitstart, $limit );
  532. HTML_joomfish::showElementOverview( $this->_joomfishManager, $pageNav );
  533. }
  534. /** Detailinformation about one specific content element */
  535. function showElementConfiguration( $id ) {
  536. global $database, $mainframe;
  537. HTML_joomfish::showElementConfiguration( $this->_joomfishManager, $id );
  538. }
  539. /**
  540. * Method to install content element files
  541. *
  542. */
  543. function showContentElementsInstaller() {
  544. $cElements = $this->_joomfishManager->getContentElements(true);
  545. HTML_joomfish::showContentElementInstaller( $cElements, $this->_message );
  546. }
  547. /** Presentation of the content's that must be translated
  548. */
  549. function showTranslationOverview( $language_id, $catid) {
  550. global $database, $mainframe;
  551. $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', 10 );
  552. $limitstart = $mainframe->getUserStateFromRequest( "view{com_joomfish}limitstart", 'limitstart', 0 );
  553. $search = $mainframe->getUserStateFromRequest( "search{com_joomfish}", 'search', '' );
  554. $search = $database->getEscaped( trim( strtolower( $search ) ) );
  555. // Build up the rows for the table
  556. $rows=null;
  557. $total=0;
  558. $filterHTML=array();
  559. if( $language_id != -1 && isset($catid) && $catid!="" ) {
  560. $contentElement = $this->_joomfishManager->getContentElement( $catid );
  561. $tranFilters = getTranslationFilters($catid,$contentElement);
  562. $database->setQuery( $contentElement->createContentSQL( $language_id, null, $limitstart, $limit,$tranFilters ) );
  563. $rows = $database->loadObjectList();
  564. if ($database->getErrorNum()) {
  565. echo $database->stderr();
  566. return false;
  567. }
  568. $total = $contentElement->countReferences($language_id, $tranFilters);
  569. // Manipulation of result based on further information
  570. for( $i=0; $i<count($rows); $i++ ) {
  571. $contentObject = new ContentObject( $language_id, $contentElement );
  572. $contentObject->readFromRow( $rows[$i] );
  573. $rows[$i] = $contentObject;
  574. }
  575. foreach ($tranFilters as $tranFilter){
  576. $afilterHTML=$tranFilter->_createFilterHTML();
  577. if (isset($afilterHTML)) $filterHTML[$tranFilter->filterType] = $afilterHTML;
  578. }
  579. }
  580. require_once( mosMainFrame::getBasePath() . "/administrator/includes/pageNavigation.php");
  581. $pageNav = new mosPageNav( $total, $limitstart, $limit );
  582. // get list of active languages
  583. $langOptions[] = mosHTML::makeOption( '-1', JText::_('Select Language') );
  584. $langOptions[] = mosHTML::makeOption( 'NULL', JText::_('Select no Translation'));
  585. $langActive = $this->_joomfishManager->getLanguages( false ); // all languages even non active once
  586. if ( count($langActive)>0 ) {
  587. foreach( $langActive as $language )
  588. {
  589. $langOptions[] = mosHTML::makeOption( $language->id, $language->name );
  590. }
  591. }
  592. $langlist = mosHTML::selectList( $langOptions, 'select_language_id', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 'value', 'text', $language_id );
  593. // get list of element names
  594. $elementNames[] = mosHTML::makeOption( '', JText::_('Please select') );
  595. //$elementNames[] = mosHTML::makeOption( '-1', '- All Content elements' );
  596. $elements = $this->_joomfishManager->getContentElements();
  597. foreach( $elements as $key => $element )
  598. {
  599. $elementNames[] = mosHTML::makeOption( $key, $element->Name );
  600. }
  601. $clist = mosHTML::selectList( $elementNames, 'catid', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 'value', 'text', $catid );
  602. HTML_joomfish::showTranslationOverview( $rows, $search, $pageNav, $langlist, $clist, $catid ,$language_id,$filterHTML );
  603. }
  604. /** Details of one content for translation
  605. */
  606. function editTranslation( $translation_id, $language_id, $catid, $contentid, $select_language_id ) {
  607. global $database, $mainframe, $my,$mosConfig_live_site;
  608. $actContentObject=null;
  609. if( $this->_message != '' ) {
  610. echo "<div class=\"message\">" .$this->_message. "</div>";
  611. }
  612. if( isset($catid) && $catid!="" ) {
  613. $contentElement = $this->_joomfishManager->getContentElement( $catid );
  614. $actContentObject = new ContentObject( $language_id, $contentElement );
  615. $actContentObject->loadFromContentID( $contentid );
  616. }
  617. // fail if checked out not by 'me'
  618. if ($actContentObject->checked_out && $actContentObject->checked_out <> $my->id) {
  619. mosRedirect( "index2.php?option=option=com_joomfish&task=translate",
  620. "The content item $actContentObject->title is currently being edited by another administrator" );
  621. }
  622. // get list of active languages
  623. $langOptions[] = mosHTML::makeOption( 'NULL', JText::_('Select no translation') );
  624. $langActive = $this->_joomfishManager->getLanguages( false ); // all languages even non active once
  625. if ( count($langActive)>0 ) {
  626. foreach( $langActive as $language )
  627. {
  628. $langOptions[] = mosHTML::makeOption( $language->id, $language->name );
  629. }
  630. }
  631. $confirm="";
  632. if ($actContentObject->language_id!=0){
  633. $confirm="onchange=\"confirmChangeLanguage('".$actContentObject->language."','".$actContentObject->language_id."')\"";
  634. }
  635. $langlist = mosHTML::selectList( $langOptions, 'language_id', 'class="inputbox" size="1" '.$confirm, 'value', 'text', $actContentObject->language_id );
  636. // get existing filters so I can remember them!
  637. $tranFilters = getTranslationFilters($catid,$contentElement);
  638. HTML_joomfish::showTranslation( $actContentObject, $langlist, $catid, $select_language_id , $tranFilters );
  639. }
  640. /** Saves the information of one translation
  641. */
  642. function saveTranslation( $language_id, $catid, $id, $jfc_id ) {
  643. global $database, $mainframe, $select_language_id;
  644. $actContentObject=null;
  645. if( isset($catid) && $catid!="" ) {
  646. $contentElement = $this->_joomfishManager->getContentElement( $catid );
  647. $actContentObject = new ContentObject( $language_id, $contentElement );
  648. // get's the config settings on how to store original files
  649. $storeOriginalText = ($this->_joomfishManager->getCfg('storageOfOriginal') == 'md5') ? false : true;
  650. $actContentObject->bind( $_POST, '', '', true, $storeOriginalText);
  651. $actContentObject->store();
  652. }
  653. $this->_message = JText::_('Translation saved');
  654. }
  655. /**
  656. * method to remove a translation
  657. */
  658. function removeTranslation() {
  659. global $language_id, $select_language_id, $catid, $contentid, $jfc_id;
  660. $this->_removeTranslation( $catid, $this->cid );
  661. $this->showTranslationOverview($language_id, $catid);
  662. }
  663. /** Presentation of translations that have been orphaned
  664. */
  665. function showOrphanOverview( $language_id, $catid) {
  666. global $database, $mainframe;
  667. $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', 10 );
  668. $limitstart = $mainframe->getUserStateFromRequest( "view{com_joomfish}limitstart", 'limitstart', 0 );
  669. $search = $mainframe->getUserStateFromRequest( "search{com_joomfish}", 'search', '' );
  670. $search = $database->getEscaped( trim( strtolower( $search ) ) );
  671. $tranFilters=array();
  672. $filterHTML=array();
  673. // Build up the rows for the table
  674. $rows=null;
  675. $total=0;
  676. if( isset($catid) && $catid!="" ) {
  677. $contentElement = $this->_joomfishManager->getContentElement( $catid );
  678. $database->setQuery( $contentElement->createOrphanSQL( $language_id, null, $limitstart, $limit,$tranFilters ) );
  679. $rows = $database->loadObjectList();
  680. if ($database->getErrorNum()) {
  681. echo $database->stderr();
  682. return false;
  683. }
  684. $total = count($rows);
  685. for( $i=0; $i<count($rows); $i++ ) {
  686. //$contentObject = new ContentObject( $language_id, $contentElement );
  687. //$contentObject->readFromRow( $row );
  688. //$rows[$i] = $contentObject ;
  689. $rows[$i]->state=null;
  690. $rows[$i]->title="original missing";
  691. $rows[$i]->checked_out=false;
  692. }
  693. }
  694. require_once( mosMainFrame::getBasePath() . "/administrator/includes/pageNavigation.php");
  695. $pageNav = new mosPageNav( $total, $limitstart, $limit );
  696. // get list of active languages
  697. $langlist = "";
  698. $langOptions[] = mosHTML::makeOption( '-1', JText::_('Select language') );
  699. //$langOptions[] = mosHTML::makeOption( '-2', JText::_('SELECT_NOTRANSLATION') );
  700. $langActive = $this->_joomfishManager->getLanguages( false ); // all languages even non active once
  701. if ( count($langActive)>0 ) {
  702. foreach( $langActive as $language )
  703. {
  704. $langOptions[] = mosHTML::makeOption( $language->id, $language->name );
  705. }
  706. }
  707. $langlist = mosHTML::selectList( $langOptions, 'select_language_id', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 'value', 'text', $language_id );
  708. // get list of element names
  709. $elementNames[] = mosHTML::makeOption( '', JText::_('PLEASE SELECT') );
  710. //$elementNames[] = mosHTML::makeOption( '-1', '- All Content elements' );
  711. $elements = $this->_joomfishManager->getContentElements();
  712. foreach( $elements as $key => $element )
  713. {
  714. $elementNames[] = mosHTML::makeOption( $key, $element->Name );
  715. }
  716. $clist = mosHTML::selectList( $elementNames, 'catid', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 'value', 'text', $catid );
  717. HTML_joomfish::showOrphanOverview( $rows, $search, $pageNav, $langlist, $clist, $catid ,$language_id,$filterHTML );
  718. }
  719. /**
  720. * method to show orphan translation details
  721. *
  722. * @param unknown_type $jfc_id
  723. * @param unknown_type $contentid
  724. * @param unknown_type $tablename
  725. * @param unknown_type $lang
  726. */
  727. function showOrphanDetail( $jfc_id, $contentid, $tablename, $lang){
  728. global $database;
  729. // read details of orphan translation
  730. //$sql = "SELECT * FROM #__jf_content WHERE id=$mbfc_id AND reference_id=$contentid AND reference_table='".$tablename."'";
  731. $sql = "SELECT * FROM #__jf_content WHERE reference_id=$contentid AND language_id='".$lang."' AND reference_table='".$tablename."'"; //print "sql = $sql<br>contentid=$contentid , mbfc_id= $mbfc_id from $tablename<br>";
  732. $database->setQuery($sql);
  733. $rows = null;
  734. $rows=$database->loadObjectList();
  735. //print_r($row);
  736. HTML_joomfish::showOrphan($rows, $tablename);
  737. }
  738. /**
  739. * Reload all translations and publish/unpublish them
  740. */
  741. function publishTranslation( $catid, $cid, $publish ) {
  742. foreach( $cid as $cid_row ) {
  743. list($translation_id, $contentid, $language_id) = explode('|', $cid_row);
  744. $contentElement = $this->_joomfishManager->getContentElement( $catid );
  745. $actContentObject = new ContentObject( $language_id, $contentElement );
  746. $actContentObject->loadFromContentID( $contentid );
  747. if( $actContentObject->state>=0 ) {
  748. $actContentObject->setPublished($publish);
  749. $actContentObject->store();
  750. $this->_message = ($publish ? JText::_('Translation published') : JText::_('Translation unpublished') );
  751. }
  752. }
  753. }
  754. /** This method prepares the managment overview of the system
  755. * Within the view it is possible to execute several management functions for the Joom!Fish
  756. */
  757. function showManagementOverview( $language_id, $catid) {
  758. global $database, $mainframe;
  759. if( !$this->_testSystemBotState() ) {;
  760. echo "<div style='font-size:16px;font-weight:bold;color:red'>".JText::_('MAMBOT_ERROR')."</div>";
  761. }
  762. $type = mosGetParam( $_REQUEST, 'type', '' );
  763. HTML_joomfish::showManagementOverview($type);
  764. }
  765. /**
  766. * This method performce a general status check for various types
  767. *
  768. */
  769. function showCheckStatusInformation() {
  770. global $mainframe;
  771. $type = mosGetParam( $_REQUEST, 'type', '' );
  772. $phase = intval( mosGetParam( $_REQUEST, 'phase', 1 ) );
  773. $statecheck_i = intval( mosGetParam( $_REQUEST, 'statecheck_i', -1 ) );
  774. $htmlResult = JText::_('MANAGEMENT_INTRO');
  775. $link = '';
  776. switch ($type) {
  777. case 'translation_status':
  778. $message = '';
  779. $translationStatus = $mainframe->getUserState('translationState', 'translationState', array());
  780. $translationStatus = $this->_testTranslationStatus($translationStatus, $phase, $statecheck_i, $message);
  781. $mainframe->setUserState('translationState', $translationStatus );
  782. $htmlResult = HTML_joomfish::renderTranslationStatusTable($translationStatus, $message);
  783. if( $phase<=3 ) {
  784. $link = 'index3.php?option=com_joomfish&task=check&act=manage&type=translation_status&phase=' .$phase;
  785. if( $statecheck_i > -1) {
  786. $link .= '&statecheck_i='.$statecheck_i;
  787. }
  788. } else {
  789. $mainframe->setUserState('translationState', null );
  790. }
  791. break;
  792. case 'original_status':
  793. $message = '';
  794. $originalStatus = $mainframe->getUserState('originalStatus', 'originalStatus', array());
  795. $langCodes = array();
  796. $languages = $this->_joomfishManager->getLanguages(false);
  797. foreach ($languages as $lang) {
  798. $langCodes[] = $lang->getLanguageCode();
  799. }
  800. $originalStatus = $this->_testOriginalStatus($originalStatus, $phase, $statecheck_i, $message, $languages);
  801. $mainframe->setUserState('originalStatus', $originalStatus );
  802. $htmlResult = HTML_joomfish::renderOriginalStatusTable($originalStatus, $message, $langCodes);
  803. if( $phase<=2 ) {
  804. $link = 'index3.php?option=com_joomfish&task=check&act=manage&type=original_status&phase=' .$phase;
  805. if( $statecheck_i > -1) {
  806. $link .= '&statecheck_i='.$statecheck_i;
  807. }
  808. } else {
  809. $mainframe->setUserState('originalStatus', null );
  810. }
  811. break;
  812. }
  813. HTML_joomfish::showManagementResult( $htmlResult, $link );
  814. }
  815. /**
  816. * this method creates the iframe information for the copy process
  817. *
  818. */
  819. function showCopyInformation () {
  820. global $mainframe;
  821. $type = mosGetParam( $_REQUEST, 'type', '' );
  822. $phase = intval( mosGetParam( $_REQUEST, 'phase', 1 ) );
  823. $state_catid = mosGetParam( $_REQUEST, 'state_catid', '' );
  824. $language_id = intval( mosGetParam( $_REQUEST, 'language_id', null ) );
  825. $overwrite = intval( mosGetParam($_REQUEST, 'overwrite', 0) );
  826. $htmlResult = JText::_('MANAGEMENT_INTRO');
  827. $link = '';
  828. $languages = $this->_joomfishManager->getLanguages( false ); // all languages even non active once
  829. $langOptions = array();
  830. $langOptions[] = mosHTML::makeOption( -1, JText::_('Do not copy') );
  831. if ( count($languages)>0 ) {
  832. foreach( $languages as $language )
  833. {
  834. $langOptions[] = mosHTML::makeOption( $language->id, $language->name );
  835. }
  836. }
  837. $langlist = mosHTML::selectList( $langOptions, 'select_language', 'id="select_language" class="inputbox" size="1"', 'value', 'text', -1 );
  838. switch ($type) {
  839. case 'original_language':
  840. $message = '';
  841. $original2languageInfo = $mainframe->getUserState('original2languageInfo', 'original2languageInfo', array());
  842. $original2languageInfo = $this->_copyOriginalToLanguage($original2languageInfo, $phase, $state_catid, $language_id, $overwrite, $message);
  843. $mainframe->setUserState('original2languageInfo', $original2languageInfo );
  844. if($phase == 1) {
  845. $htmlResult = HTML_joomfish::renderCopyInformation($original2languageInfo, $message, $langlist);
  846. } elseif( $phase == 2 || $phase == 3 ) {
  847. $htmlResult = HTML_joomfish::renderCopyProcess($original2languageInfo, $message);
  848. $link = 'index3.php?option=com_joomfish&task=copy&act=manage&type=original_language&phase=' .$phase. '&language_id=' .$language_id. '&state_catid=' .$state_catid. '&overwrite=' .$overwrite;
  849. } else {
  850. $htmlResult = HTML_joomfish::renderCopyProcess($original2languageInfo, $message);
  851. $mainframe->setUserState('original2languageInfo', null );
  852. }
  853. break;
  854. }
  855. HTML_joomfish::showManagementResult( $htmlResult, $link );
  856. }
  857. /**
  858. * Deletes the selected translations (only the translations of course)
  859. */
  860. function _removeTranslation( $catid, $cid ) {
  861. global $database;
  862. foreach( $cid as $cid_row ) {
  863. list($translationid, $contentid, $language_id) = explode('|', $cid_row);
  864. $contentElement = $this->_joomfishManager->getContentElement( $catid );
  865. $contentTable = $contentElement->getTableName();
  866. $contentid= intval($contentid);
  867. $translationid = intval($translationid);
  868. // safety check -- complete overkill but better to be safe than sorry
  869. // get the translation details
  870. $translation = new jfContent($database);
  871. $translation->load($translationid);
  872. if (!isset($translation)) {
  873. JText::sprintf('NO_SUCH_TRANSLATION', $translationid);
  874. continue;
  875. }
  876. // make sure translation matches the one we wanted
  877. if ($contentid != $translation->reference_id){
  878. echo JText::_('Something dodgy going on here');
  879. continue;
  880. }
  881. // ??? This line doesn't make sense!
  882. $sql= "SELECT * from #__$contentTable WHERE id=".$translationid;
  883. $database->setQuery($sql);
  884. $rows = $database->loadObjectList("");
  885. if (count($rows)>0) {
  886. echo "ID $contentid is not an orphan translation - it has not been deleted<br/>";
  887. continue;
  888. }
  889. // ???
  890. $sql= "DELETE from #__jf_content WHERE reference_table='$catid' and language_id=$language_id and reference_id=$contentid";
  891. $database->setQuery($sql);
  892. $database->query();
  893. if( $database->getErrorNum() != 0 ) {
  894. echo JText::_('Something dodgy going on here');
  895. echo $database->getErrorMsg();
  896. continue;
  897. }
  898. }
  899. }
  900. /**
  901. * Sets up ContentElement Cache - mainly used for data to determine primary key id for tablenames ( and for
  902. * future use to allow tables to be dropped from translation even if contentelements are installed )
  903. */
  904. function _setupContentElementCache()
  905. {
  906. global $database;
  907. // Make usre table exists otherwise create it.
  908. $database->setQuery( "CREATE TABLE IF NOT EXISTS `#__jf_tableinfo` ( `id` int(11) NOT NULL auto_increment, `joomlatablename` varchar(100) NOT NULL default '', `tablepkID` varchar(100) NOT NULL default '', PRIMARY KEY (`id`)) TYPE=MyISAM");
  909. $database->query();
  910. // clear out existing data
  911. $database->setQuery( "DELETE FROM `#__jf_tableinfo`");
  912. $database->query();
  913. $contentElements = $this->_joomfishManager->getContentElements();
  914. $sql = "INSERT INTO `#__jf_tableinfo` (joomlatablename,tablepkID) VALUES ";
  915. $firstTime = true;
  916. foreach ($contentElements as $contentElement){
  917. $tablename = $contentElement->getTableName();
  918. // populate cache
  919. include_once( mosMainFrame::getBasePath().'/components/com_joomfish/includes/joomfish.class.php' );
  920. JoomFish::_contentElementFields($tablename);
  921. $refId = $contentElement->getReferenceID();
  922. $sql .= $firstTime?"":",";
  923. $sql .= " ('".$tablename."', '".$refId."')";
  924. $firstTime = false;
  925. }
  926. $database->setQuery( $sql);
  927. $database->query();
  928. }
  929. /**
  930. * This method checks the different system states based on the definition in the component XML file.
  931. * @return array with rows of the different component states
  932. *
  933. */
  934. function _checkSystemState() {
  935. global $database, $mosConfig_Livesite;
  936. require_once( mosMainFrame::getBasePath() . "/includes/domit/xml_domit_lite_include.php" );
  937. $checkResult = array();
  938. // Read the file to see if it's a valid template XML file
  939. $xmlDoc =& new DOMIT_Lite_Document();
  940. $xmlDoc->resolveErrors( true );
  941. $xmlfile = JOOMFISH_ADMINPATH .DS. 'joomfish.xml';
  942. if (!$xmlDoc->loadXML( $xmlfile, false, true )) {
  943. return $checkResult;
  944. }
  945. $element = &$xmlDoc->documentElement;
  946. if ($element->getTagName() != 'mosinstall') {
  947. return $checkResult;
  948. }
  949. if ($element->getAttribute( "type" ) != "component") {
  950. return $checkResult;
  951. }
  952. $checkElements = $xmlDoc->getElementsByPath('check', 1);
  953. if (!isset($checkElements) || !$checkElements->hasChildNodes()){
  954. return $checkResult;
  955. }
  956. // Default values of different master states
  957. $checkResult['directory_state'] = true;
  958. $checkResult['extension_state'] = true;
  959. foreach ($checkElements->childNodes as $child){
  960. $type = $child->nodeName;
  961. $check = new stdClass();
  962. switch ($type) {
  963. case "directory":
  964. $check->description = $child->getText();
  965. $check->result = is_writable(mosMainFrame::getBasePath() .DS. $check->description) ? true : false;
  966. $check->resultText = $check->result ? JText::_('writable') : JText::_('not writable');
  967. $check->link = '';
  968. $checkResult[$type][] = $check;
  969. $checkResult[$type. '_state'] = $checkResult[$type. '_state'] & $check->result;
  970. break;
  971. case "extension":
  972. $check->description = JText::_($child->getAttribute('name'));
  973. $table = $child->getAttribute('type');
  974. $field = $child->getAttribute('field');
  975. $value = $child->getAttribute('value');
  976. $condition = $child->getText();
  977. $sql = "SELECT $field, id FROM #__$table WHERE $condition";
  978. $database->setQuery($sql);
  979. $resultValue = $database->loadRow();
  980. if( $resultValue != null ) {
  981. $check->result = ($value == $resultValue[0]) ? true : false;
  982. $check->resultText = $check->result ? JText::_($field) : JText::_('un'.$field);
  983. $check->link = 'index2.php?option=com_'.$table.'&amp;client=&amp;task=editA&amp;hidemainmenu=1&amp;id='.$resultValue[1];
  984. } else {
  985. $check->result = false;
  986. $check->resultText = JText::_('not installed');
  987. $check->link = '';
  988. }
  989. $checkResult[$type][] = $check;
  990. $checkResult[$type. '_state'] = $checkResult[$type. '_state'] & $check->result;
  991. break;
  992. }
  993. }
  994. return $checkResult;
  995. }
  996. /**
  997. * Testing state of the system bot
  998. *
  999. */
  1000. function _testSystemBotState()
  1001. {
  1002. global $database;
  1003. $botState = false;
  1004. $database->setQuery( "SELECT * FROM #__mambots WHERE element='jfdatabase.systembot'");
  1005. $database->query();
  1006. $database->loadObject($mambot);
  1007. if ($mambot != null && $mambot->published == "1") {
  1008. $botState = $mambot->id;
  1009. }
  1010. return $botState;
  1011. }
  1012. /**
  1013. * Testing state of the system bot
  1014. *
  1015. */
  1016. function _testSearchBotState()
  1017. {
  1018. global $database;
  1019. $botState = false;
  1020. $database->setQuery( "SELECT * FROM #__mambots WHERE element='jfcontent.searchbot'");
  1021. $database->query();
  1022. $database->loadObject($mambot);
  1023. if ($mambot != null && $mambot->published == "1") {
  1024. $botState = $mambot->id;
  1025. }
  1026. return $botState;
  1027. }
  1028. /**
  1029. * Testing state of the system bot
  1030. *
  1031. */
  1032. function _testModuleState()
  1033. {
  1034. global $database;
  1035. $moduleState = false;
  1036. $database->setQuery( "SELECT * FROM #__modules WHERE module='mod_jflanguageselection'");
  1037. $database->query();
  1038. $database->loadObject($module);
  1039. if ($module != null && $module->published == "1") {
  1040. $moduleState = $module->id;
  1041. }
  1042. return $moduleState;
  1043. }
  1044. /**
  1045. * Testing if old installation is found and upgraded?
  1046. * @return int 0 := component not installed, 1 := installed but not upgraded, 2 := installed and upgraded
  1047. */
  1048. function _testOldInstall()
  1049. {
  1050. global $database;
  1051. $oldInstall = 0;
  1052. $database->setQuery( "SHOW TABLES LIKE '%mbf_%'" );
  1053. $database->query();
  1054. $rows = $database->loadResultArray();
  1055. foreach ($rows as $row) {
  1056. if( ereg( 'mbf_content', $row ) ) {
  1057. $oldInstall = 1;
  1058. break;
  1059. }
  1060. }
  1061. if( $oldInstall == 1 && $this->_joomfishManager->getCfg( 'mbfupgradeDone' ) ) {
  1062. $oldInstall = 2;
  1063. }
  1064. return $oldInstall;
  1065. }
  1066. /**
  1067. * This method gethers certain information of the system which can be used for presenting
  1068. * @return array with inforation about the system
  1069. */
  1070. function _getSystemInfo() {
  1071. global $database;
  1072. $database->setQuery( 'SELECT count(*) FROM #__jf_content');
  1073. $database->query();
  1074. $translations = $database->loadResult();
  1075. $res = array( 'translations' => $translations );
  1076. return $res;
  1077. }
  1078. /**
  1079. * Start of a function to obtain overview summary of orphan translations
  1080. *
  1081. * @return array of orphan tables or nothing if no orphans found
  1082. */
  1083. function _testOrphans( ) {
  1084. global $database, $mainframe, $mosConfig_dbprefix;
  1085. $orphans = array();
  1086. $tranFilters=array();
  1087. $filterHTML=array();
  1088. $query = "select distinct CONCAT('".$mosConfig_dbprefix."',reference_table) from #__jf_content";
  1089. $database->setQuery( $query );
  1090. $tablesWithTranslations = $database->loadResultArray();
  1091. $query = "SHOW TABLES";
  1092. $database->setQuery( $query );
  1093. $tables = $database->loadResultArray();
  1094. $allContentElements = $this->_joomfishManager->getContentElements();
  1095. foreach ($allContentElements as $catid=>$ce){
  1096. $tablename = $mosConfig_dbprefix.$ce->referenceInformation["tablename"];
  1097. if (in_array($tablename,$tables) &&
  1098. in_array($tablename,$tablesWithTranslations)){
  1099. $database->setQuery( $ce->createOrphanSQL( -1, null, -1, -1,$tranFilters ) );
  1100. $rows = $database->loadObjectList();
  1101. if ($database->getErrorNum()) {
  1102. $this->_message = $database->stderr();
  1103. return false;
  1104. }
  1105. $total = count($rows);
  1106. if ($total>0) {
  1107. $orphans[] = array( 'catid' => $catid, 'name' => $ce->Name, 'total' => $total);
  1108. }
  1109. }
  1110. }
  1111. foreach ($tablesWithTranslations as $twv) {
  1112. if (!in_array($twv,$tables)) {
  1113. $this->_message = "Translations exists for table <b>$twv</b> which is no longer in the database<br/>";
  1114. }
  1115. }
  1116. return $orphans;
  1117. }
  1118. /**
  1119. * This method tests for the content elements and their original/translation status
  1120. * It will return an array listing all content element names including information about how may originals
  1121. *
  1122. * @param array $originalStatus array with original state values if exist
  1123. * @param int $phase which phase of the status check
  1124. * @param string $statecheck_i running row number starting with -1!
  1125. * @param string $message system message
  1126. * @param array $languages array of availabe languages
  1127. * @return array with resulting rows
  1128. */
  1129. function _testOriginalStatus($originalStatus, &$phase, &$statecheck_i, &$message, $languages) {
  1130. global $database, $mosConfig_dbprefix;
  1131. $tranFilters=array();
  1132. $filterHTML=array();
  1133. $sql = '';
  1134. switch ($phase) {
  1135. case 1:
  1136. $originalStatus = array();
  1137. $sql = "select distinct CONCAT('".$mosConfig_dbprefix."',reference_table) from #__jf_content";
  1138. $database->setQuery( $sql );
  1139. $tablesWithTranslations = $database->loadResultArray();
  1140. $sql = "SHOW TABLES";
  1141. $database->setQuery( $sql );
  1142. $tables = $database->loadResultArray();
  1143. $allContentElements = $this->_joomfishManager->getContentElements();
  1144. foreach ($allContentElements as $catid=>$ce){
  1145. $ceInfo = array();
  1146. $ceInfo['name'] = $ce->Name;
  1147. $ceInfo['catid'] = $catid;
  1148. $ceInfo['total'] = '??';
  1149. $ceInfo['missing_table'] = false;
  1150. $ceInfo['message'] = '';
  1151. $tablename = $mosConfig_dbprefix.$ce->referenceInformation["tablename"];
  1152. if (in_array($tablename,$tables)){
  1153. // get total count of table entries
  1154. $database->setQuery( 'SELECT COUNT(*) FROM ' .$tablename );
  1155. $ceInfo['total'] = $database->loadResult();
  1156. if( in_array($tablename,$tablesWithTranslations) ) {
  1157. // get orphans
  1158. $database->setQuery( $ce->createOrphanSQL( -1, null, -1, -1,$tranFilters ) );
  1159. $rows = $database->loadObjectList();
  1160. if ($database->getErrorNum()) {
  1161. $this->_message = $database->stderr();
  1162. return false;
  1163. }
  1164. $ceInfo['orphans'] = count($rows);
  1165. // get number of valid translations
  1166. $ceInfo['valid'] = 0;
  1167. // get number of outdated translations
  1168. $ceInfo['outdated'] = $ceInfo['total'] - $ceInfo['orphans'] - $ceInfo['valid'];
  1169. }else {
  1170. $ceInfo['orphans'] = '0';
  1171. }
  1172. } elseif (!in_array($tablename, $tables)) {
  1173. $ceInfo['missing_table'] = true;
  1174. $ceInfo['message'] = JText::sprintf(TABLE_DOES_NOT_EXIST, $tablename );
  1175. }
  1176. $originalStatus[] = $ceInfo;
  1177. }
  1178. $message = JText::sprintf('ORIGINAL_PHASE1_CHECK', '');
  1179. $phase ++;
  1180. $statecheck_i = 0;
  1181. break;
  1182. case 2:
  1183. if( is_array($originalStatus) && count ($originalStatus)>0 ) {
  1184. if( $statecheck_i>=0 && $statecheck_i<count($originalStatus)) {
  1185. $stateRow =& $originalStatus[$statecheck_i];
  1186. foreach ($languages as $lang) {
  1187. $sql = "SELECT * FROM #__jf_content as jfc" .
  1188. "\n WHERE jfc.language_id=" .$lang->id .
  1189. "\n AND jfc.reference_table='" .$stateRow['catid'] ."'".
  1190. "\n AND jfc.published=1" .
  1191. "\n GROUP BY reference_id";
  1192. $database->setQuery($sql);
  1193. $rows = $database->loadRowList();
  1194. $key = 'langentry_' .$lang->getLanguageCode();
  1195. $stateRow[$key] = count($rows);
  1196. }
  1197. }
  1198. if ($statecheck_i<count($originalStatus)-1) {
  1199. $statecheck_i ++;
  1200. $message = JText::sprintf('ORIGINAL_PHASE1_CHECK', ' ('. $originalStatus[$statecheck_i]['name'] .')');
  1201. } else {
  1202. $message = JText::_('ORIGINAL_PHASE2_CHECK');
  1203. $phase = 3; // exit
  1204. }
  1205. } else {
  1206. $phase = 3; // exit
  1207. $message = JText::_('ORIGINAL_PHASE2_CHECK');
  1208. }
  1209. break;
  1210. }
  1211. return $originalStatus;
  1212. }
  1213. /**
  1214. * This method checks the translation status
  1215. * The process follows goes through out all existing translations and checks their individual status.
  1216. * The output is a summary information based grouped by content element files and the languages
  1217. *
  1218. * @param array $translationStatus array with translation state values
  1219. * @param int $phase which phase of the status check
  1220. * @param string $statecheck_i running row number starting with -1!
  1221. * @param string $message system message
  1222. */
  1223. function _testTranslationStatus( $translationStatus, &$phase, &$statecheck_i, &$message ) {
  1224. global $database;
  1225. $sql = '';
  1226. switch ($phase) {
  1227. case 1:
  1228. $sql = "SELECT jfc.reference_table, jfc.language_id, jfl.name AS language" .
  1229. "\n FROM #__jf_content AS jfc" .
  1230. "\n JOIN #__languages AS jfl ON jfc.language_id = jfl.id" .
  1231. "\n GROUP BY jfc.reference_table, jfc.language_id";
  1232. $database->setQuery($sql);
  1233. $rows = $database->loadObjectList();
  1234. $translationStatus = array();
  1235. if( is_array($rows) && count($rows)>0 ) {
  1236. foreach ($rows as $row) {
  1237. $status = array();
  1238. $contentElement = $this->_joomfishManager->getContentElement( $row->reference_table );
  1239. $status['content'] = $contentElement->Name;
  1240. $status['catid'] = $row->reference_table;
  1241. $status['language_id'] = $row->language_id;
  1242. $status['language'] = $row->language;
  1243. $status['total'] = '';
  1244. $status['state_valid'] = '';
  1245. $status['state_unvalid'] = '';
  1246. $status['state_missing'] = '';
  1247. $status['state'] = '';
  1248. $status['published'] = '';
  1249. $sql = "SELECT * FROM #__jf_content" .
  1250. "\n WHERE reference_table='" .$row->reference_table. "'" .
  1251. "\n AND language_id=" .$row->language_id .
  1252. "\n GROUP BY reference_id";
  1253. $database->setQuery($sql);
  1254. $totalrows = $database->loadRowList();
  1255. if( $totalrows = $database->loadRowList() ) {
  1256. $status['total'] = count($totalrows);
  1257. }
  1258. $translationStatus[] = $status;
  1259. }
  1260. $message = JText::_('TRANSLATION_PHASE1_GENERALCHECK');
  1261. $phase ++;
  1262. } else {
  1263. $message = JText::_('No Translation available');
  1264. $phase = 4; // exit
  1265. }
  1266. break;
  1267. case 2:
  1268. if( is_array($translationStatus) && count ($translationStatus)>0 ) {
  1269. for ($i=0; $i<count($translationStatus); $i++) {
  1270. $stateRow =& $translationStatus[$i];
  1271. $sql = "select *" .
  1272. "\n from #__jf_content as jfc" .
  1273. "\n where published=1" .
  1274. "\n and reference_table='" .$stateRow['catid']. "'".
  1275. "\n and language_id=" .$stateRow['language_id'].
  1276. "\n group by reference_ID";
  1277. $database->setQuery($sql);
  1278. if( $rows = $database->loadRowList() ) {
  1279. $stateRow['published'] = count($rows);
  1280. } else {
  1281. $stateRow['published'] = 0;
  1282. }
  1283. }
  1284. }
  1285. $message = JText::sprintf('TRANSLATION_PHASE2_PUBLISHEDCHECK', '');
  1286. $phase ++;
  1287. break;
  1288. case 3:
  1289. if( is_array($translationStatus) && count ($translationStatus)>0 ) {
  1290. if( $statecheck_i>=0 && $statecheck_i<count($translationStatus)) {
  1291. $stateRow =& $translationStatus[$statecheck_i];
  1292. $contentElement = $this->_joomfishManager->getContentElement( $stateRow['catid'] );
  1293. $filters = array();
  1294. // trap missing content element files
  1295. if (is_null($contentElement)){
  1296. $message = JText::_('TRANSLATION_PHASE3_STATECHECK');
  1297. $stateRow['state_valid'] = 0;
  1298. $stateRow['state_unvalid'] = 0;
  1299. $stateRow['state_missing'] = 0;
  1300. $statecheck_i ++;
  1301. break;
  1302. }
  1303. // we need to find an end, thats why the filter is at 10.000!
  1304. $database->setQuery( $contentElement->createContentSQL( $stateRow['language_id'], null, 0, 10000,$filters ) );
  1305. if( $rows = $database->loadObjectList() ) {
  1306. $stateRow['state_valid'] = 0;
  1307. $stateRow['state_unvalid'] = 0;
  1308. $stateRow['state_missing'] = 0;
  1309. for( $i=0; $i<count($rows); $i++ ) {
  1310. $contentObject = new ContentObject( $stateRow['language_id'], $contentElement );
  1311. $contentObject->readFromRow( $rows[$i] );
  1312. $rows[$i] = $contentObject;
  1313. switch( $contentObject->state ) {
  1314. case 1:
  1315. $stateRow['state_valid'] ++;
  1316. break;
  1317. case 0:
  1318. $stateRow['state_unvalid'] ++;
  1319. break;
  1320. case -1:
  1321. default:
  1322. $stateRow['state_missing'] ++;
  1323. break;
  1324. }
  1325. }
  1326. }
  1327. }
  1328. if ($statecheck_i<count($translationStatus)-1) {
  1329. $statecheck_i ++;
  1330. $message = JText::sprintf('TRANSLATION_PHASE2_PUBLISHEDCHECK', ' ('. $translationStatus[$statecheck_i]['content'] .'/' .$translationStatus[$statecheck_i]['language'].')');
  1331. } else {
  1332. $message = JText::_('TRANSLATION_PHASE3_STATECHECK');
  1333. $phase = 4; // exit
  1334. }
  1335. } else {
  1336. $message = JText::_('TRANSLATION_PHASE3_STATECHECK');
  1337. $phase = 4; // exit
  1338. }
  1339. break;
  1340. }
  1341. return $translationStatus;
  1342. }
  1343. /**
  1344. * This method creates an overview of unpublished translations independed of the content element
  1345. * @return array of unpublished translations or null
  1346. */
  1347. function _testUnpublisedTranslations() {
  1348. global $database;
  1349. $unpublishedTranslations = null;
  1350. $sql = "select jfc.reference_table, jfc.reference_id, jfc.language_id, jfl.name as language" .
  1351. "\n from #__jf_content as jfc, #__languages as jfl" .
  1352. "\n where published=0 and jfc.language_id = jfl.id" .
  1353. "\n group by jfc.reference_table, jfc.reference_id, jfc.language_id" .
  1354. "\n limit 0, 50";
  1355. $database->setQuery($sql);
  1356. if( $rows = $database->loadObjectList() ) {
  1357. foreach ($rows as $row) {
  1358. $unpublished = array();
  1359. $unpublished['reference_table'] = $row->reference_table;
  1360. $unpublished['catid'] = $row->reference_table;
  1361. $unpublished['reference_id'] = $row->reference_id;
  1362. $unpublished['language_id'] = $row->language_id;
  1363. $unpublished['language'] = $row->language;
  1364. $unpublishedTranslations[] = $unpublished;
  1365. }
  1366. }
  1367. return $unpublishedTranslations;
  1368. }
  1369. /**
  1370. * This method copies originals content items to one selected language
  1371. *
  1372. * @param unknown_type $original2languageInfo
  1373. * @param unknown_type $phase
  1374. * @param unknown_type $statecheck_i
  1375. * @param unknown_type $message
  1376. * @return array Information result array
  1377. */
  1378. function _copyOriginalToLanguage($original2languageInfo, &$phase, &$state_catid, $language_id, $overwrite, &$message) {
  1379. global $database, $mosConfig_dbprefix;
  1380. $sql = '';
  1381. switch ($phase) {
  1382. case 1:
  1383. $original2languageInfo = array();
  1384. $sql = "select distinct CONCAT('".$mosConfig_dbprefix."',reference_table) from #__jf_content";
  1385. $database->setQuery( $sql );
  1386. $tablesWithTranslations = $database->loadResultArray();
  1387. $sql = "SHOW TABLES";
  1388. $database->setQuery( $sql );
  1389. $tables = $database->loadResultArray();
  1390. $allContentElements = $this->_joomfishManager->getContentElements();
  1391. foreach ($allContentElements as $catid=>$ce){
  1392. $ceInfo = array();
  1393. $ceInfo['name'] = $ce->Name;
  1394. $ceInfo['catid'] = $catid;
  1395. $ceInfo['total'] = '??';
  1396. $ceInfo['existing'] = '??';
  1397. $ceInfo['processed'] = '0';
  1398. $ceInfo['copied'] = '0';
  1399. $ceInfo['copy'] = false;
  1400. $contentTable = $ce->getTable();
  1401. $tablename = $mosConfig_dbprefix.$contentTable->Name;
  1402. if (in_array($tablename,$tables)){
  1403. // get total count of table entries
  1404. $sql = 'SELECT COUNT(*) FROM ' .$tablename. ' AS c';
  1405. if( $contentTable->Filter != ''){
  1406. $sql .= ' WHERE ' .$contentTable->Filter;
  1407. }
  1408. $database->setQuery( $sql );
  1409. $ceInfo['total'] = $database->loadResult();
  1410. }
  1411. $original2languageInfo[$catid] = $ceInfo;
  1412. }
  1413. $phase = 1; // stays with 1 as the second phase needs the bottom to be clicked
  1414. $message = JText::_('COPY2LANGUAGE_INFO');
  1415. break;
  1416. case 2:
  1417. if( $state_catid != '' ) {
  1418. // removing all content information which are not to be copied!
  1419. $celements = explode(',', $state_catid);
  1420. if( count($celements) < count($original2languageInfo)) {
  1421. $shortList = array();
  1422. foreach ($celements as $element) {
  1423. $shortList[$element] = $original2languageInfo[$element];
  1424. }
  1425. $original2languageInfo = $shortList;
  1426. }
  1427. }
  1428. $phase = 3;
  1429. case 3:
  1430. if( $state_catid != '' ) {
  1431. $celements = explode(',', $state_catid);
  1432. // copy the information per content element file, starting with the first in the list
  1433. $catid = array_shift($celements);
  1434. $catidCompleted = false;
  1435. // coyping the information from the selected content element
  1436. if($catid!='' && $language_id!=0) {
  1437. // get's the config settings on how to store original files
  1438. $storeOriginalText = ($this->_joomfishManager->getCfg('storageOfOriginal') == 'md5') ? false : true;
  1439. // make sure we are only transfering data within parts (max 100 items at a time)
  1440. $ceInfo =& $original2languageInfo[$catid];
  1441. if(intval($ceInfo['processed']) < intval($ceInfo['total'])) {
  1442. $contentElement = $this->_joomfishManager->getContentElement( $catid );
  1443. $database->setQuery( $contentElement->createContentSQL( $language_id, null, $ceInfo['processed'], 10,array() ) );
  1444. $rows = $database->loadObjectList();
  1445. if ($database->getErrorNum()) {
  1446. echo $database->stderr();
  1447. return false;
  1448. } else {
  1449. for( $i=0; $i<count($rows); $i++ ) {
  1450. $contentObject = new ContentObject( $language_id, $contentElement );
  1451. $contentObject->readFromRow($rows[$i]);
  1452. if( $overwrite || $contentObject->translation_id == 0) {
  1453. $contentObject->copyContentToTranslation( $rows[$i], $rows[$i] );
  1454. $contentObject->store();
  1455. $ceInfo['copied'] += 1;
  1456. }
  1457. $rows[$i] = $contentObject;
  1458. }
  1459. $ceInfo['processed'] += $i;
  1460. if($ceInfo['processed'] >= $ceInfo['total']) {
  1461. $catidCompleted = true;
  1462. }
  1463. }
  1464. }
  1465. }
  1466. if( $catidCompleted ) {
  1467. if(count($celements)>0) {
  1468. $state_catid = implode(',', $celements);
  1469. } else {
  1470. $state_catid = '';
  1471. }
  1472. }
  1473. }
  1474. $message = JText::_('COPY2LANGUAGE_PROCESS');
  1475. if( $state_catid == '') {
  1476. $phase = 4; // Successfully finished phase 3
  1477. $message = JText::_('COPY2LANGUAGE_COMPLETED');
  1478. }
  1479. break;
  1480. }
  1481. return $original2languageInfo;
  1482. }
  1483. /**
  1484. * Upgrades the database tables from one version to another
  1485. *
  1486. * @param int $backupTables
  1487. * @param int $renameTables
  1488. * @return array sumamry Information
  1489. *
  1490. */
  1491. function _upgradeInstallation( $backupTables, $renameTables ) {
  1492. global $database;
  1493. $summary = array();
  1494. $summary['state'] = false;
  1495. // Default values
  1496. $summary['mbf_module_unpublished'] = false;
  1497. $summary['mbf_module_unpublished_error'] = '';
  1498. $summary['mbf_bot_unpublished'] = false;
  1499. $summary['mbf_bot_unpublished_error'] = '';
  1500. $summary['jf_content_backup'] = false;
  1501. $summary['jf_content_backup_error'] = '';
  1502. $summary['jf_languages_backup'] = false;
  1503. $summary['jf_languages_backup_error'] = '';
  1504. $summary['jf_content_deleted'] = false;
  1505. $summary['jf_content_deleted_error'] = '';
  1506. $summary['jf_content_copied'] = false;
  1507. $summary['jf_content_copied_error'] = '';
  1508. $summary['jf_languages_deleted'] = false;
  1509. $summary['jf_languages_deleted_error'] = '';
  1510. $summary['jf_languages_copied'] = false;
  1511. $summary['jf_languages_copied_error'] = '';
  1512. // unpublish mambelfish mambots and modules
  1513. $database->setQuery( "UPDATE #__modules SET published = 0 WHERE LOWER(module) = 'mod_mambelfish'");
  1514. if( !$summary['mbf_module_unpublished'] = $database->query() ) {
  1515. $summary['mbf_module_unpublished_error'] = $database->getErrorMsg();
  1516. return $summary;
  1517. }
  1518. $database->setQuery( "UPDATE #__mambots SET published = 0 WHERE LOWER(element) = 'mbfcontent.searchbot'");
  1519. if( !$summary['mbf_bot_unpublished'] = $database->query() ) {
  1520. $summary['mbf_bot_unpublished_error'] = $database->getErrorMsg();
  1521. return $summary;
  1522. }
  1523. if( $backupTables ) {
  1524. // renaming existing JoomFish tables
  1525. $database->setQuery( 'DROP TABLE IF EXISTS #__jf_content_bak;');
  1526. $database->query();
  1527. $sql = "CREATE TABLE `#__jf_content_bak` ("
  1528. . "\n `id` int( 10 ) unsigned NOT NULL AUTO_INCREMENT ,"
  1529. . "\n `language_id` int( 11 ) NOT NULL default '0',"
  1530. . "\n `reference_id` int( 11 ) NOT NULL default '0',"
  1531. . "\n `reference_table` varchar( 100 ) NOT NULL default '',"
  1532. . "\n `reference_field` varchar( 100 ) NOT NULL default '',"
  1533. . "\n `value` mediumtext NOT NULL ,"
  1534. . "\n `original_value` varchar( 255 ) default NULL ,"
  1535. . "\n `original_text` text default NULL ,"
  1536. . "\n `modified` datetime NOT NULL default '0000-00-00 00:00:00',"
  1537. . "\n `modified_by` int( 11 ) unsigned NOT NULL default '0',"
  1538. . "\n `published` tinyint( 1 ) unsigned NOT NULL default '0',"
  1539. . "\n PRIMARY KEY ( `id` )"
  1540. . "\n )";
  1541. $database->setQuery( $sql );
  1542. if( !$summary['jf_content_backup'] = $database->query() ) {
  1543. $summary[ 'jf_content_backup_error' ] = $database->getErrorMsg();
  1544. return $summary;
  1545. }
  1546. $sql = "INSERT INTO `#__jf_content_bak` SELECT * FROM `#__jf_content`";
  1547. $database->setQuery( $sql );
  1548. if( !$summary['jf_content_backup'] = $database->query() ) {
  1549. $summary[ 'jf_content_backup_error' ] = $database->getErrorMsg();
  1550. return $summary;
  1551. }
  1552. // language table update
  1553. $database->setQuery( 'DROP TABLE IF EXISTS #__languages_bak;');
  1554. $database->query();
  1555. $sql = "CREATE TABLE `#__languages_bak` ("
  1556. . "\n `id` int(11) NOT NULL auto_increment,"
  1557. . "\n `name` varchar(100) NOT NULL default '',"
  1558. . "\n `active` tinyint(1) NOT NULL default '0',"
  1559. . "\n `iso` varchar(10) default NULL,"
  1560. . "\n `code` varchar(20) NOT NULL default '',"
  1561. . "\n `shortcode` varchar(20) NOT NULL default '',"
  1562. . "\n `image` varchar(100) default NULL,"
  1563. . "\n `fallback_code` varchar(20) NOT NULL default '',"
  1564. . "\n `params` text NOT NULL default '',"
  1565. . "\n `ordering` int(11) NOT NULL default '0',"
  1566. . "\n PRIMARY KEY ( `id` )"
  1567. . "\n )";
  1568. $database->setQuery( $sql );
  1569. if( !$summary['jf_languages_backup'] = $database->query() ) {
  1570. $summary[ 'jf_languages_backup_error' ] = $database->getErrorMsg();
  1571. return $summary;
  1572. }
  1573. $sql = "INSERT INTO `#__languages_bak` SELECT * FROM `#__languages`";
  1574. $database->setQuery( $sql );
  1575. if( !$summary['jf_languages_backup'] = $database->query() ) {
  1576. $summary[ 'jf_languages_backup_error' ] = $database->getErrorMsg();
  1577. return $summary;
  1578. }
  1579. }
  1580. $database->setQuery( "SHOW TABLES LIKE '%mbf_%'" );
  1581. $database->query();
  1582. $rows = $database->loadResultArray();
  1583. $oldContentTable = '';
  1584. $oldLanguageTable = '';
  1585. foreach ($rows as $row) {
  1586. if( ereg( 'mbf_content', $row ) ) {
  1587. $oldContentTable = $row;
  1588. } elseif ( ereg( 'mbf_language', $row ) ) {
  1589. $oldLanguageTable = $row;
  1590. }
  1591. }
  1592. if( $oldContentTable != '' ) {
  1593. // Delete existing records
  1594. $database->setQuery( 'DELETE FROM #__jf_content');
  1595. if( !$summary['jf_content_deleted'] = $database->query() ) {
  1596. $summary[ 'jf_content_deleted_error' ] = $database->getErrorMsg();
  1597. return $summary;
  1598. }
  1599. // copy data over (doing md5 at the same time!)
  1600. $database->setQuery( "INSERT INTO #__jf_content "
  1601. . "\n(id, language_id, reference_id, reference_table, reference_field, value, original_value, modified, modified_by, published)"
  1602. . "\n SELECT id, language_id, reference_id, reference_table, reference_field, value, md5(original_value), modified, modified_by, published"
  1603. . "\nFROM " .$oldContentTable );
  1604. if( !$summary['jf_content_copied'] = $database->query() ) {
  1605. $summary[ 'jf_content_copied_error' ] = $database->getErrorMsg();
  1606. return $summary;
  1607. }
  1608. $summary['state'] = true;
  1609. }
  1610. if( $oldLanguageTable != '' ) {
  1611. // Delete existing records
  1612. $database->setQuery( 'DELETE FROM #__languages');
  1613. if( !$summary['jf_languages_deleted'] = $database->query() ) {
  1614. $summary[ 'jf_languages_deleted_error' ] = $database->getErrorMsg();
  1615. return $summary;
  1616. }
  1617. // copy data over (doing md5 at the same time!)
  1618. $database->setQuery( "INSERT INTO #__languages "
  1619. . "\n(`id`, `name`, `active`, `iso`, `code`, `image`, `ordering`)"
  1620. . "\n SELECT `id`, `name`, `active`, `iso`, `mambo`, `image`, `ordering`"
  1621. . "\nFROM " .$oldLanguageTable );
  1622. if( !$summary['jf_languages_copied'] = $database->query() ) {
  1623. $summary[ 'jf_languages_copied_error' ] = $database->getErrorMsg();
  1624. return $summary;
  1625. }
  1626. $summary['state'] = true;
  1627. }
  1628. return $summary;
  1629. }
  1630. /**
  1631. * Utility function find all directories within a parent directory
  1632. * @param string The parent directory path
  1633. * @param boolean True if to prepend the full path to the file name
  1634. */
  1635. function _findDirectories( $path, $fullpath=false ) {
  1636. $arr = array();
  1637. if (!@is_dir( $path )) {
  1638. return $arr;
  1639. }
  1640. $handle = opendir( $path );
  1641. while ($file = readdir($handle)) {
  1642. $dir = mosPathName( $path.'/'.$file, false );
  1643. if (is_dir( $dir ) && substr($file, 0, 1) != '.' ) {
  1644. if( $fullpath ) {
  1645. $arr[] = trim( $dir );
  1646. } else {
  1647. $arr[] = trim( $file );
  1648. }
  1649. }
  1650. }
  1651. closedir($handle);
  1652. asort($arr);
  1653. return $arr;
  1654. }
  1655. }
  1656. /**
  1657. * This class allows general installation of files related to the Joom!Fish project
  1658. * It is a light version of the mosInstaller class without the particular handling of
  1659. * special package XML files within the archieves. All XML files are automatically
  1660. * interpreterted as content element files and installed in the related directories
  1661. *
  1662. */
  1663. class jfInstaller {
  1664. var $_iswin = false;
  1665. var $errno = 0;
  1666. var $error = "";
  1667. var $_unpackdir = "";
  1668. /** @var string The directory where the element is to be installed */
  1669. var $_elementdir = '';
  1670. var $_uploadfile = null;
  1671. var $_realname = null;
  1672. var $_contentelements = array();
  1673. /**
  1674. * Constructor
  1675. */
  1676. function jfInstaller() {
  1677. global $mosConfig_absolute_path;
  1678. $this->_iswin = (substr(PHP_OS, 0, 3) == 'WIN');
  1679. $this->_elementdir = mosPathName( $mosConfig_absolute_path . '/administrator/components/com_joomfish/contentelements' );
  1680. }
  1681. /**
  1682. * Installation of a single file or archive for the joomfish files
  1683. * @param array uploadfile retrieved information transferred by the upload form
  1684. */
  1685. function install( $uploadfile = null ) {
  1686. if( $uploadfile === null ) {
  1687. return false;
  1688. }
  1689. $this->_uploadfile = $uploadfile['tmp_name'];
  1690. $this->_realname = $uploadfile['name'];
  1691. return $this->upload();
  1692. }
  1693. /**
  1694. * Uploads and unpacks a file
  1695. * @return boolean True on success, False on error
  1696. */
  1697. function upload() {
  1698. if( !eregi( '.xml$', $this->_realname ) ) {
  1699. if(! $this->extractArchive() ) {
  1700. return false;
  1701. }
  1702. }
  1703. if( !is_array( $this->_uploadfile ) ) {
  1704. if(! @copy($this->_uploadfile, $this->_elementdir . $this->_realname) ) {
  1705. $this->errno = 2;
  1706. $this->error = JText::_('FILEUPLOAD_ERROR');
  1707. return false;
  1708. }
  1709. } else {
  1710. foreach ($this->_uploadfile as $file ) {
  1711. if(! @copy($this->_unpackdir . $file, $this->_elementdir . $file) ) {
  1712. $this->errno = 2;
  1713. $this->error = JText::_('FILEUPLOAD_ERROR');
  1714. return false;
  1715. }
  1716. }
  1717. }
  1718. return true;
  1719. }
  1720. /**
  1721. * Extracts the package archive file
  1722. * @return boolean True on success, False on error
  1723. */
  1724. function extractArchive() {
  1725. global $mosConfig_absolute_path;
  1726. $base_Dir = mosPathName( $mosConfig_absolute_path . '/media' );
  1727. $archivename = $base_Dir . $this->_realname;
  1728. $tmpdir = uniqid( 'install_' );
  1729. $extractdir = mosPathName( $base_Dir . $tmpdir );
  1730. $archivename = mosPathName( $archivename, false );
  1731. $this->_unpackdir = $extractdir;
  1732. if (eregi( '.zip$', $archivename )) {
  1733. // Extract functions
  1734. require_once( $mosConfig_absolute_path . '/administrator/includes/pcl/pclzip.lib.php' );
  1735. require_once( $mosConfig_absolute_path . '/administrator/includes/pcl/pclerror.lib.php' );
  1736. $zipfile = new PclZip( $this->_uploadfile );
  1737. if($this->_iswin) {
  1738. define('OS_WINDOWS',1);
  1739. } else {
  1740. define('OS_WINDOWS',0);
  1741. }
  1742. $ret = $zipfile->extract( PCLZIP_OPT_PATH, $extractdir );
  1743. if($ret == 0) {
  1744. $this->errno = 1;
  1745. $this->error = 'Unrecoverable error "'.$zipfile->errorName(true).'"';
  1746. return false;
  1747. }
  1748. } else {
  1749. require_once( $mosConfig_absolute_path . '/includes/Archive/Tar.php' );
  1750. $archive = new Archive_Tar( $this->_uploadfile );
  1751. $archive->setErrorHandling( PEAR_ERROR_PRINT );
  1752. if (!$archive->extractModify( $extractdir, '' )) {
  1753. $this->setError( 1, 'Extract Error' );
  1754. return false;
  1755. }
  1756. }
  1757. // Try to find the correct install dir. in case that the package have subdirs
  1758. // Save the install dir for later cleanup
  1759. $this->_uploadfile = mosReadDirectory( $extractdir, '' );
  1760. if (count( $this->_uploadfile ) == 1) {
  1761. if (is_dir( $extractdir . $this->_uploadfile[0] )) {
  1762. $this->_unpackdir = mosPathName( $extractdir . $this->_uploadfile[0] );
  1763. $this->_uploadfile = mosReadDirectory( $extractdir, '' );
  1764. }
  1765. }
  1766. return true;
  1767. }
  1768. }
  1769. ?>