PageRenderTime 45ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 1ms

/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

Large files files are truncated, but you can click here to view the full file

  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. }

Large files files are truncated, but you can click here to view the full file