PageRenderTime 72ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_joomfish/joomfish.class.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 2305 lines | 1500 code | 291 blank | 514 comment | 294 complexity | a2483cecbbfa5c1625c4899ea7a685ff 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: joomfish.class.php 789 2007-12-16 16:24:05Z akede $
  29. *
  30. */
  31. // Don't allow direct linking
  32. defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  33. /**
  34. * The JoomFishManager controls all important configuration and information
  35. * of the content elements. These information might be cached in the session
  36. * settings if necessary in furture.
  37. *
  38. * @package joomfish
  39. * @subpackage administrator
  40. * @copyright 2003-2007 Think Network GmbH
  41. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
  42. * @version 1.0, 2003-10-16 $Revision: 789 $
  43. * @author Alex Kempkens <joomfish@thinknetwork.com>
  44. */
  45. class JoomFishManager {
  46. /** Array of all known content elements and the reference to the XML file */
  47. var $_contentElements;
  48. /** Path to the administration dir of the component */
  49. var $_adminPath='';
  50. /** string Content type which can use default values */
  51. var $DEFAULT_CONTENTTYPE="content";
  52. /** @var config Configuration of the map */
  53. var $_config=null;
  54. /** PrimaryKey Data */
  55. var $_primaryKeys = null;
  56. var $allLanguagesCache;
  57. var $allLanguagesCacheByID;
  58. var $activeLanguagesCache;
  59. var $activeLanguagesCacheByID;
  60. /** Standard constructor */
  61. function JoomFishManager($adminPath=null) {
  62. global $mosConfig_admin_path;
  63. if( $adminPath===null ) {
  64. $adminPath = dirname( __FILE__ );
  65. }
  66. $this->_adminPath = $adminPath;
  67. $this->_loadConfiguration( $adminPath );
  68. //$this->_loadContentElements( $adminPath );
  69. $this->_loadPrimaryKeyData();
  70. $this->activeLanguagesCache = array();
  71. $this->activeLanguagesCacheByID = array();
  72. // get all languages and split out active below
  73. $langlist = $this->getLanguages(false);
  74. foreach ($langlist as $alang){
  75. if ($alang->active){
  76. $this->activeLanguagesCache[$alang->code] = $alang;
  77. $this->activeLanguagesCacheByID[$alang->id] = $alang;
  78. }
  79. $this->allLanguagesCache[$alang->code] = $alang;
  80. $this->allLanguagesCacheByID[$alang->id] = $alang;
  81. }
  82. }
  83. function & getInstance($adminPath=null){
  84. static $instance;
  85. if (!isset($instance)){
  86. $instance = new JoomFishManager($adminPath);
  87. }
  88. return $instance;
  89. }
  90. /** Loading of component configuration
  91. */
  92. function _loadConfiguration() {
  93. $this->_config = new stdClass();
  94. require( "$this->_adminPath/config.joomfish.php" );
  95. $this->_config->componentAdminLang = $joomfish_componentAdminLang;
  96. $this->_config->noTranslation = $joomfish_noTranslation;
  97. $this->_config->defaultText = $joomfish_defaultText;
  98. $this->_config->frontEndPublish = $joomfish_frontEndPublish;
  99. $this->_config->frontEndPreview = $joomfish_frontEndPreview;
  100. $this->_config->storageOfOriginal = $joomfish_storageOfOriginal;
  101. $this->_config->showCPanels = $joomfish_showCPanels;
  102. $this->_config->mbfupgradeDone = $joomfish_mbfupgradeDone;
  103. $this->_config->qacaching = $joomfish_qacaching;
  104. $this->_config->qalogging = $joomfish_qalogging;
  105. }
  106. /**
  107. * Load Primary key data from database
  108. *
  109. */
  110. function _loadPrimaryKeyData() {
  111. if ($this->_primaryKeys==null){
  112. global $database;
  113. $database->setQuery( "SELECT joomlatablename,tablepkID FROM `#__jf_tableinfo`");
  114. $rows = $database->loadObjectList();
  115. $this->_primaryKeys = array();
  116. if( $rows ) {
  117. foreach ($rows as $row) {
  118. $this->_primaryKeys[$row->joomlatablename]=$row->tablepkID;
  119. }
  120. }
  121. }
  122. }
  123. /**
  124. * Get primary key given table name
  125. *
  126. * @param string $tablename
  127. * @return string primarykey
  128. */
  129. function getPrimaryKey($tablename){
  130. if ($this->_primaryKeys==null) $this->_loadPrimaryKeyData();
  131. if (array_key_exists($tablename,$this->_primaryKeys)) return $this->_primaryKeys[$tablename];
  132. else return "id";
  133. }
  134. /**
  135. * Saving of the file based configurations
  136. */
  137. function saveConfiguration () {
  138. global $option;
  139. $configfile = "$this->_adminPath/config.joomfish.php";
  140. @chmod ($configfile, 0766);
  141. $permission = is_writable($configfile);
  142. if (!$permission) {
  143. $mosmsg = JText::_('CONFIG_WRITE_ERROR');
  144. return false;
  145. }
  146. $config = "<?php\n";
  147. $config .= '$joomfish_componentAdminLang = "' .$this->_config->componentAdminLang. '"; // Which language the component admini should have' ."\n";
  148. $config .= '$joomfish_noTranslation = ' .$this->_config->noTranslation. '; // What to show when no translation available' ."\n";
  149. $config .= '$joomfish_defaultText = "' .$this->_config->defaultText. '"; // Standard text if no translation - only for certain content elements!' ."\n";
  150. $config .= '$joomfish_frontEndPublish = "' .$this->_config->frontEndPublish. '"; // Whether publishers and above can publish from the frontend' ."\n";
  151. $config .= '$joomfish_frontEndPreview = "' .$this->_config->frontEndPreview. '"; // Whether managers and above can see inactive languages in the frontend' ."\n";
  152. $config .= '$joomfish_storageOfOriginal = "' .$this->_config->storageOfOriginal. '"; // md5 := only md5 values (default); both := md5 and clean text' ."\n";
  153. $config .= '$joomfish_showCPanels = "' .$this->_config->showCPanels. '"; // binary encoded information which panles to show' ."\n";
  154. $config .= '$joomfish_mbfupgradeDone = "' .$this->_config->mbfupgradeDone. '"; // Flag showing if the upgrade was done already. modify manually if you need to do the upgrade again' ."\n";
  155. $config .= '$joomfish_qacaching = "' .$this->_config->qacaching. '"; // Flag showing if experimental query analysis caching is enabled' ."\n";
  156. $config .= '$joomfish_qalogging = "' .$this->_config->qalogging. '"; // Flag showing if query analysis logging is enabled' ."\n";
  157. $config .= "?>";
  158. if ($fp = fopen("$configfile", "w")) {
  159. fputs($fp, $config, strlen($config));
  160. fclose ($fp);
  161. }
  162. $this->_loadConfiguration( $this->_adminPath );
  163. return true;
  164. }
  165. /**
  166. * Loading of related XML files
  167. *
  168. * TODO This is very wasteful of processing time so investigate caching some how
  169. * built in Joomla cache will not work because of the class structere of the results
  170. * we get lots of incomplete classes from the unserialisation
  171. */
  172. function _loadContentElements() {
  173. // XML library
  174. require_once( mosMainFrame::getBasePath() . "/includes/domit/xml_domit_lite_include.php" );
  175. // Try to find the XML file
  176. $filesindir = mosReadDirectory($this->_adminPath ."/contentelements" ,".xml");
  177. if(count($filesindir) > 0)
  178. {
  179. $this->_contentElements = array();
  180. foreach($filesindir as $file)
  181. {
  182. $xmlDoc =& new DOMIT_Lite_Document();
  183. $xmlDoc->resolveErrors( true );
  184. if ($xmlDoc->loadXML( $this->_adminPath . "/contentelements/" . $file, false, true )) {
  185. $element = &$xmlDoc->documentElement;
  186. if ($element->getTagName() == 'joomfish') {
  187. if ( $element->getAttribute('type')=='contentelement' ) {
  188. $nameElements =& $element->getElementsByTagName('name', 1);
  189. $nameElement =& $nameElements->item(0);
  190. $name = strtolower( trim($nameElement->getText()) );
  191. $contentElement =& new ContentElement( $xmlDoc );
  192. $this->_contentElements[$contentElement->getTableName()] =& $contentElement;
  193. }
  194. }
  195. }
  196. }
  197. }
  198. }
  199. /**
  200. * Method to return the content element files
  201. *
  202. * @param boolean $reload forces to reload the element files
  203. * @return unknown
  204. */
  205. function getContentElements( $reload=false ) {
  206. if( !isset( $this->_contentElements ) || $reload ) {
  207. $this->_loadContentElements();
  208. }
  209. return $this->_contentElements;
  210. }
  211. /** gives you one content element
  212. * @param key of the element
  213. */
  214. function getContentElement( $key ) {
  215. if( !isset($this->_contentElements) ) {
  216. $this->_loadContentElements();
  217. }
  218. $element = null;
  219. if( array_key_exists( strtolower($key), $this->_contentElements ) ) {
  220. $element = $this->_contentElements[ strtolower($key) ];
  221. }
  222. return $element;
  223. }
  224. /**
  225. * @param string The name of the variable (from configuration.php)
  226. * @return mixed The value of the configuration variable or null if not found
  227. */
  228. function getCfg( $varname , $default=null) {
  229. if (isset( $this->_config->$varname )) {
  230. return $this->_config->$varname;
  231. } else {
  232. return $default;
  233. }
  234. }
  235. /**
  236. * @param string The name of the variable (from configuration.php)
  237. * @param mixed The value of the configuration variable
  238. */
  239. function setCfg( $varname, $newValue ) {
  240. if (isset( $this->_config->$varname )) {
  241. $this->_config->$varname = get_magic_quotes_gpc() ? stripslashes($newValue) : $newValue;
  242. }
  243. }
  244. /** Creates an array with all the active languages for the JoomFish
  245. *
  246. * @return Array of languages
  247. */
  248. function getActiveLanguages() {
  249. /* if signed in as Manager or above include inactive languages too */
  250. global $my;
  251. if ( isset($this) && $this->getCfg("frontEndPreview") && isset($my) && (strtolower($my->usertype)=="manager" || strtolower($my->usertype)=="administrator" || strtolower($my->usertype)=="super administrator")) {
  252. if (isset($this) && isset($this->allLanguagesCache)) return $this->allLanguagesCache;
  253. }
  254. else {
  255. if (isset($this) && isset($this->activeLanguagesCache)) return $this->activeLanguagesCache;
  256. }
  257. return JoomFishManager::getLanguages( true );
  258. }
  259. /** Creates an array with all languages for the JoomFish
  260. *
  261. * @param boolean indicates if those languages must be active or not
  262. * @return Array of languages
  263. */
  264. function getLanguages( $active=true ) {
  265. global $database;
  266. $langActive=null;
  267. $sql = 'SELECT * FROM #__languages';
  268. if( $active ) {
  269. $sql .= ' WHERE active=1';
  270. }
  271. $sql .= ' ORDER BY ordering';
  272. $database->setQuery( $sql );
  273. $rows = $database->loadObjectList('id',false);
  274. if( $rows ) {
  275. foreach ($rows as $row) {
  276. $lang = new jfLanguage($database);
  277. $lang->bind($row);
  278. $langActive[] = $lang;
  279. }
  280. }
  281. return $langActive;
  282. }
  283. /** Retrieves the language ID from the given language name
  284. *
  285. * @param string Code language name (normally $mosConfig_lang
  286. * @return int Database id of this language
  287. */
  288. function getLanguageID( $codeLangName="" ) {
  289. global $database;
  290. $langID = -1;
  291. if ($codeLangName != "" ) {
  292. if (isset($this) && isset($this->activeLanguagesCache) && array_key_exists($codeLangName,$this->activeLanguagesCache))
  293. return $this->activeLanguagesCache[$codeLangName]->id;
  294. else {
  295. $database->setQuery( "SELECT id FROM #__languages WHERE active=1 and code = '$codeLangName' order by ordering" );
  296. $langID = $database->loadResult(false);
  297. }
  298. }
  299. return $langID;
  300. }
  301. /** Retrieves the language code (for URL) from the given language name
  302. *
  303. * @param string Code language name (normally $mosConfig_lang
  304. * @return int Database id of this language
  305. */
  306. function getLanguageCode( $codeLangName="" ) {
  307. global $database;
  308. $langID = -1;
  309. if ($codeLangName != "" ) {
  310. if (isset($this) && isset($this->activeLanguagesCache) && array_key_exists($codeLangName,$this->activeLanguagesCache))
  311. return $this->activeLanguagesCache[$codeLangName]->shortcode;
  312. else {
  313. $database->setQuery( "SELECT shortcode FROM #__languages WHERE active=1 and code = '$codeLangName' order by ordering" );
  314. $langID = $database->loadResult(false);
  315. }
  316. }
  317. return $langID;
  318. }
  319. /** Delivers the actual version of the component
  320. */
  321. function getVersion() {
  322. return "V1.8.2 (2007-12-16)";
  323. }
  324. function getVersionFooter() {
  325. return "1.8.2";
  326. }
  327. }
  328. /**
  329. * Content element class based on the xml file
  330. *
  331. * @package joomfish
  332. * @subpackage administrator
  333. * @copyright 2003-2007 Think Network GmbH
  334. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
  335. * @version $Revision: 789 $
  336. * @author Alex Kempkens <joomfish@thinknetwork.com>
  337. */
  338. class ContentElement extends StdClass {
  339. var $_xmlFile;
  340. var $checked_out=false;
  341. var $Name='';
  342. var $Author='';
  343. var $Version='';
  344. var $Description='';
  345. var $PrimaryKey = "id";
  346. var $referenceInformation;
  347. /** field (if any) that keyword filters apply to*/
  348. var $_keywordFilter=null;
  349. var $_categoryFilter=null;
  350. var $_authorFilter=null;
  351. /** Standard constructor, which loads already standard information
  352. * for easy and direct access
  353. */
  354. function ContentElement ( $xmlDoc ) {
  355. $this->_xmlFile = $xmlDoc;
  356. if( isset($this->_xmlFile) ) {
  357. $valueElement = $this->_xmlFile->getElementsByPath('name', 1);
  358. $this->Name = trim($valueElement->getText());
  359. $valueElement = $this->_xmlFile->getElementsByPath('author', 1);
  360. $this->Author = trim($valueElement->getText());
  361. $valueElement = $this->_xmlFile->getElementsByPath('version', 1);
  362. $this->Version = trim($valueElement->getText());
  363. $valueElement = $this->_xmlFile->getElementsByPath('description', 1);
  364. $this->Description = trim($valueElement->getText());
  365. }
  366. }
  367. /** Type of reference
  368. */
  369. function getReferenceType() {
  370. if( !isset($this->referenceInformation["type"]) && isset($this->_xmlFile) ) {
  371. $tableElement = $this->_xmlFile->getElementsByPath('reference', 1);
  372. $tableName = trim($tableElement->getAttribute( 'type' ));
  373. $this->referenceInformation["type"] = $tableName;
  374. }
  375. return $this->referenceInformation["type"];
  376. }
  377. /**
  378. * Public function to return array of filters included in contentelement file
  379. */
  380. function getAllFilters(){
  381. $allFilters = array();
  382. if(isset($this->_xmlFile) ) {
  383. $fElement = $this->_xmlFile->getElementsByPath('translationfilters', 1);
  384. if (!isset($fElement) || !$fElement->hasChildNodes()){
  385. return $allFilters;
  386. }
  387. foreach ($fElement->childNodes as $child){
  388. $type = $child->nodeName;
  389. $filter = "_$type"."Filter";
  390. $this->$filter=$child->getText();
  391. $allFilters[$type]=trim($this->$filter);
  392. }
  393. }
  394. return $allFilters;
  395. }
  396. /**
  397. * function that returns filter string and handles getting filter info from xmlfile if needed
  398. *
  399. */
  400. function getFilter($type){
  401. $filter = "_$type"."Filter";
  402. if( !isset($this->$filter) && isset($this->_xmlFile) ) {
  403. $fElement = $this->_xmlFile->getElementsByPath('translationfilters/'.$type, 1);
  404. if (!isset($fElement)){
  405. $this->$filter=false;
  406. return $this->$filter;
  407. }
  408. $this->$filter=trim($fElement->getText());
  409. }
  410. return $this->$filter;
  411. }
  412. /**
  413. * returns translation filter keyword field (if any)
  414. */
  415. function getKeywordFilter() {
  416. return $this->_getFilter("keyword");
  417. }
  418. /**
  419. * returns category filter fieldname (if any)
  420. */
  421. function getCategoryFilter() {
  422. return $this->_getFilter("category");
  423. }
  424. /**
  425. * returns author filter fieldname (if any)
  426. */
  427. function getAuthorFilter() {
  428. return $this->_getFilter("author");
  429. }
  430. /** Name of the refering table
  431. */
  432. function getTableName() {
  433. if( !isset($this->referenceInformation["tablename"]) && isset($this->_xmlFile) ) {
  434. $tableElement = $this->_xmlFile->getElementsByPath('reference/table', 1);
  435. $tableName = trim($tableElement->getAttribute( 'name' ));
  436. $this->referenceInformation["tablename"] = strtolower($tableName);
  437. }
  438. return $this->referenceInformation["tablename"];
  439. }
  440. /**
  441. * Name of reference id (in other words the primary key)
  442. */
  443. function getReferenceId() {
  444. if( isset($this->referenceInformation["tablename"]) && isset($this->_xmlFile) ) {
  445. $tableElement = $this->_xmlFile->getElementsByPath('reference/table', 1);
  446. $tableFields = $tableElement->getElementsByTagName('field');
  447. $tableFields = $tableFields->toArray();
  448. foreach ($tableFields as $field) {
  449. if (trim($field->getAttribute('type'))=="referenceid") {
  450. $refid = trim($field->getAttribute('name'));
  451. if ($refid!=null) return $refid;
  452. else return "id";
  453. }
  454. }
  455. }
  456. return "id";
  457. }
  458. /** Array of the field elements in the table
  459. */
  460. function & getTable($join = 0) {
  461. if( !isset($this->referenceInformation["table"]) && isset($this->_xmlFile) ) {
  462. $tableElement = $this->_xmlFile->getElementsByPath('reference/table', 1);
  463. $this->referenceInformation["table"] = new ContentElementTable( $tableElement );
  464. }
  465. if( !isset($this->referenceInformation["join"]) && isset($this->_xmlFile) ) {
  466. $joinElement = $this->_xmlFile->getElementsByPath('reference/join', 1);
  467. $this->referenceInformation["join"] = $joinElement ? new ContentElementTable( $joinElement ) : null;
  468. }
  469. return $this->referenceInformation[ $join ? 'join' : "table"];
  470. }
  471. /** Generating the sql statement to retrieve the information
  472. * from the database
  473. */
  474. function createContentSQL( $idLanguage=-1, $contentid=null, $limitStart=-1, $maxRows=-1 , $filters=array()) {
  475. $sqlFields=null;
  476. $where=array();
  477. $order=null;
  478. $join=null;
  479. $contentTable = $this->getTable();
  480. $joinTable = $this->getTable(1);
  481. foreach ($filters as $filter) {
  482. $sqlFilter= $filter->_createFilter($this);
  483. if ($sqlFilter!="") $where[]=$sqlFilter;
  484. }
  485. foreach( $contentTable->Fields as $tableField ) {
  486. // Based on the types we might want to have special names ;-)
  487. switch ($tableField->Type) {
  488. case "referenceid":
  489. $contentid_exist = (isset($contentid) && $contentid!=-1 );
  490. if( strtolower($tableField->Name) != "id" ) {
  491. $sqlFields[] = 'c.' .$tableField->Name. ' as id';
  492. if( $contentid_exist) $where[] = 'c.' .$tableField->Name. '=' .$contentid ;
  493. }
  494. else {
  495. if( $contentid_exist ) $where[] = 'c.id=' .$contentid ;
  496. }
  497. $join[] = 'c.' .$tableField->Name. '=jfc.reference_id';
  498. break;
  499. case "titletext":
  500. if( strtolower($tableField->Name) != "title" ) {
  501. $sqlFields[] = 'c.' .$tableField->Name. ' as title';
  502. }
  503. $join[] = "jfc.reference_field='" .$tableField->Name. "'";
  504. $order[] = 'c.' .$tableField->Name;
  505. break;
  506. case "modified_date":
  507. if( strtolower($tableField->Name) != "modified_date" ) {
  508. $sqlFields[] = 'c.' .$tableField->Name. ' as modified_date';
  509. }
  510. break;
  511. case "checked_out_by":
  512. if( strtolower($tableField->Name) != "check_out" ) {
  513. $sqlFields[] = 'c.' .$tableField->Name. ' as check_out';
  514. }
  515. break;
  516. }
  517. // I want to have each field with his original name in the select
  518. // so the special fields will be only addon's!
  519. // Reason: To grap the data later it's more easy to refer to the original names of the XML file
  520. $sqlFields[] = 'c.' .$tableField->Name. '';
  521. }
  522. $joinTables = array();
  523. if($joinTable){
  524. $keyField = null;
  525. $joinField = null;
  526. foreach( $joinTable->Fields as $tableField ) {
  527. switch ($tableField->Type) {
  528. case "keyfield":
  529. $keyField = $tableField->Name;
  530. break;
  531. case "joinfield":
  532. $joinField = $tableField->Name;
  533. break;
  534. case "titletext":
  535. $sqlFields[] = 'j.' .$tableField->Name. ' as title';
  536. break;
  537. }
  538. }
  539. if($keyField && $joinField) $joinTables[] = "#__$joinTable->Name AS j ON j.$keyField = c.$joinField";
  540. }
  541. $sqlFields[] = "jfc.id as jfc_id";
  542. $sqlFields[] = "jfc.value as titleTranslation";
  543. $sqlFields[] = "jfc.modified as lastchanged";
  544. $sqlFields[] = 'jfc.published as published';
  545. $sqlFields[] = 'jfc.language_id';
  546. $sqlFields[] = 'jfl.name as language';
  547. $sqlFields[] = "jfc.reference_id as jfc_refid";
  548. $join[] = "jfc.reference_table='$contentTable->Name'";
  549. // Now redundant
  550. /*
  551. if( isset($contentid) && $contentid!=-1 ) {
  552. $where[] = 'c.id=' .$contentid;
  553. }
  554. */
  555. if( isset($idLanguage) && $idLanguage!="" && $idLanguage!=-1 ) {
  556. if( $idLanguage=="NULL" ) {
  557. $where[] = "jfc.language_id IS NULL";
  558. } else {
  559. $join[] = "jfc.language_id=$idLanguage";
  560. }
  561. }
  562. if( $contentTable->Filter != '' ) {
  563. $where[] = $contentTable->Filter;
  564. }
  565. $sql = "SELECT " .implode( ",\n", $sqlFields )
  566. . "\nFROM #__" .$contentTable->Name. ' as c'
  567. . "\nLEFT JOIN #__jf_content as jfc ON " .implode( ' AND ', $join )
  568. . "\nLEFT JOIN #__languages as jfl ON jfc.language_id=jfl.id"
  569. . ($joinTables ? "\nLEFT JOIN ".implode("\nLEFT JOIN ", $joinTables) : '')
  570. . (count( $where ) ? "\nWHERE " . implode( ' AND ', $where ) : "")
  571. . (count( $order ) ? "\nORDER BY " . implode( ', ', $order ) : "");
  572. if( $limitStart!=-1 ) {
  573. $sql .= "\nLIMIT $limitStart, $maxRows";
  574. }
  575. //echo "sql = >$sql<<br />";
  576. return $sql;
  577. }
  578. /** Generating the sql statement to retrieve the orphans information from the database
  579. */
  580. function createOrphanSQL( $idLanguage=-1, $contentid=null, $limitStart=-1, $maxRows=-1 , $filters=array()) {
  581. $sqlFields=null;
  582. $sqlFields[] = "jfc.id as jfc_id";
  583. $sqlFields[] = "jfc.reference_id as jfc_refid";
  584. $sqlFields[] = "jfc.value as titleTranslation";
  585. $sqlFields[] = "jfc.modified as lastchanged";
  586. $sqlFields[] = 'jfc.published as published';
  587. $sqlFields[] = 'jfc.language_id';
  588. $sqlFields[] = 'jfl.name as language';
  589. $where=array();
  590. $order=null;
  591. $join=null;
  592. $contentTable = $this->getTable();
  593. foreach ($filters as $filter) {
  594. $sqlFilter= $filter->_createFilter($this);
  595. if ($sqlFilter!="") $where[]=$sqlFilter;
  596. }
  597. foreach( $contentTable->Fields as $tableField ) {
  598. // Based on the types we might want to have special names ;-)
  599. switch ($tableField->Type) {
  600. case "referenceid":
  601. $contentid_exist = (isset($contentid) && $contentid!=-1 );
  602. if( strtolower($tableField->Name) != "id" ) {
  603. $sqlFields[] = 'c.' .$tableField->Name. ' as id';
  604. if( $contentid_exist) $where[] = 'c.' .$tableField->Name. '=' .$contentid ;
  605. }
  606. else {
  607. if( $contentid_exist ) $where[] = 'c.id=' .$contentid ;
  608. }
  609. $join[] = 'c.' .$tableField->Name. '=jfc.reference_id ';
  610. $where[] = 'c.' .$tableField->Name. ' IS NULL ';
  611. $sqlFields[] = 'c.' .$tableField->Name. '';
  612. break;
  613. case "titletext":
  614. if( strtolower($tableField->Name) != "title" ) {
  615. $sqlFields[] = 'c.' .$tableField->Name. ' as title';
  616. }
  617. //$join[] = "jfc.reference_field='" .$tableField->Name. "'";
  618. $where[] = "jfc.reference_field='" .$tableField->Name. "'";
  619. $sqlFields[] = 'c.' .$tableField->Name. '';
  620. // $order[] = 'c.' .$tableField->Name;
  621. break;
  622. }
  623. }
  624. //$join[] = "jfc.reference_table='$contentTable->Name'";
  625. $where[] = "jfc.reference_table='$contentTable->Name'";
  626. if( !isset($idLanguage) || ($idLanguage!="" && $idLanguage!=-1 )) {
  627. $where[] = "jfc.language_id=$idLanguage";
  628. }
  629. $sql = "SELECT " .implode( ', ', $sqlFields )
  630. . "\nFROM #__jf_content as jfc"
  631. . "\nLEFT JOIN #__" .$contentTable->Name. ' as c ON '.implode( ' AND ', $join )
  632. . "\nLEFT JOIN #__languages as jfl ON jfc.language_id=jfl.id"
  633. . (count( $where ) ? "\nWHERE " . implode( ' AND ', $where ) : "")
  634. . (count( $order ) ? "\nORDER BY " . implode( ', ', $order ) : "");
  635. if( $limitStart!=-1 ) {
  636. $sql .= "\nLIMIT $limitStart, $maxRows";
  637. }
  638. //echo "orphansql = $sql<br />";
  639. return $sql;
  640. }
  641. /** Generating the sql statement to count the information
  642. */
  643. function countContentSQLOLD($idLanguage=-1) {
  644. $contentTable = $this->getTable();
  645. $join=null;
  646. $where=null;
  647. $order=null;
  648. $group=null;
  649. foreach( $contentTable->Fields as $tableField ) {
  650. // Based on the types we might want to have special names ;-)
  651. if ( $tableField->Type == "referenceid" ) {
  652. $join[] = 'c.' .$tableField->Name. '=jfc.reference_id';
  653. $group[] = 'c.' .$tableField->Name;
  654. $group[] = "jfc.language_id";
  655. }
  656. }
  657. $sqlFields[] = "c.*, jfc.language_id";
  658. $join[] = "jfc.reference_table='$contentTable->Name'";
  659. if( isset($idLanguage) && $idLanguage!=-1 ) {
  660. if( $idLanguage=='NULL' ) {
  661. $where[] = "jfc.language_id IS NULL";
  662. } else {
  663. $join[] = "jfc.language_id=$idLanguage";
  664. }
  665. }
  666. if( $contentTable->Filter != '' ) {
  667. $where[] = $contentTable->Filter;
  668. }
  669. $sql = "SELECT " .implode( ', ', $sqlFields )
  670. . "\nFROM #__" .$contentTable->Name. ' as c'
  671. . "\nLEFT JOIN #__jf_content as jfc ON " .implode( ' AND ', $join )
  672. . (count( $where ) ? "\nWHERE " . implode( ' AND ', $where ) : "")
  673. . (count( $group ) ? "\nGROUP BY " . implode( ', ', $group ) : "")
  674. . (count( $order ) ? "\nORDER BY " . implode( ', ', $order ) : "");
  675. return $sql;
  676. }
  677. /** Generating the sql statement to count the information
  678. */
  679. function countContentSQL($idLanguage=-1, $filters=array()) {
  680. $contentTable = $this->getTable();
  681. $where=null;
  682. // Add standard filters
  683. foreach ($filters as $filter) {
  684. $sqlFilter= $filter->_createFilter($this);
  685. if ($sqlFilter!="") $where[]=$sqlFilter;
  686. }
  687. if( $contentTable->Filter != '' ) {
  688. $where[] = $contentTable->Filter;
  689. }
  690. $sql = "SELECT count(*)"
  691. . "\nFROM #__" .$contentTable->Name. ' as c'
  692. . (count( $where ) ? "\nWHERE " . implode( ' AND ', $where ) : "");
  693. /* Try to simplify the count queries.
  694. Check only on original table including the standard filters as we assume that
  695. $join=null;
  696. $where=null;
  697. $order=null;
  698. $group=null;
  699. foreach( $contentTable->Fields as $tableField ) {
  700. // Based on the types we might want to have special names ;-)
  701. if ( $tableField->Type == "referenceid" ) {
  702. $join[] = 'c.' .$tableField->Name. '=jfc.reference_id';
  703. $group[] = 'c.' .$tableField->Name;
  704. $group[] = "jfc.language_id";
  705. }
  706. }
  707. $sqlFields[] = "c.*, jfc.language_id";
  708. $join[] = "jfc.reference_table='$contentTable->Name'";
  709. if( isset($idLanguage) && $idLanguage!=-1 ) {
  710. if( $idLanguage=='NULL' ) {
  711. $where[] = "jfc.language_id IS NULL";
  712. } else {
  713. $join[] = "jfc.language_id=$idLanguage";
  714. }
  715. }
  716. foreach ($filters as $filter) {
  717. $sqlFilter= $filter->_createFilter($this);
  718. if ($sqlFilter!="") $where[]=$sqlFilter;
  719. }
  720. if( $contentTable->Filter != '' ) {
  721. $where[] = $contentTable->Filter;
  722. }
  723. $sql = "SELECT " .implode( ', ', $sqlFields )
  724. . "\nFROM #__" .$contentTable->Name. ' as c'
  725. . "\nLEFT JOIN #__jf_content as jfc ON " .implode( ' AND ', $join )
  726. . (count( $where ) ? "\nWHERE " . implode( ' AND ', $where ) : "")
  727. . (count( $group ) ? "\nGROUP BY " . implode( ', ', $group ) : "")
  728. . (count( $order ) ? "\nORDER BY " . implode( ', ', $order ) : "");
  729. */
  730. //echo "count-sql = >$sql<<br />";
  731. return $sql;
  732. }
  733. /**
  734. * Returing the number of elements corresponding with the information of the class
  735. * @return total number of elements
  736. */
  737. function countReferences( $idLanguage=-1, $filters=array() ) {
  738. global $database;
  739. /*
  740. $database->setQuery( $this->countContentSQL($idLanguage, $filters) );
  741. $result = $database->loadObjectList();
  742. echo $database->getErrorMsg();
  743. return count( $result );
  744. */
  745. $database->setQuery( $this->countContentSQL( $idLanguage, $filters ) );
  746. return $database->loadResult();
  747. }
  748. }
  749. /**
  750. * Description of a content element table.
  751. *
  752. * @package joomfish
  753. * @subpackage administrator
  754. * @copyright 2003-2007 Think Network GmbH
  755. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
  756. * @version $Revision: 789 $
  757. * @author Alex Kempkens <joomfish@thinknetwork.com>
  758. */
  759. class ContentElementTable {
  760. var $Name;
  761. var $Fields;
  762. var $Filter;
  763. /** Standard constructor
  764. */
  765. function ContentElementTable( $tableElement ) {
  766. $this->Name = trim( $tableElement->getAttribute( 'name' ) );
  767. $tableFields = $tableElement->getElementsByTagName( 'field' );
  768. $tableFields = $tableFields->toArray();
  769. $this->Fields = null;
  770. foreach( $tableFields as $tablefieldElement ) {
  771. $this->Fields[] = new ContentElementTablefield( $tablefieldElement );
  772. }
  773. $filterElement = $tableElement->getElementsByPath('filter', 1);
  774. if( $filterElement ) {
  775. $this->Filter = $filterElement->getText();
  776. }
  777. }
  778. /** Retrieves one field based on the name
  779. * @param string Fieldname
  780. * @return object field
  781. */
  782. function getField( $name ) {
  783. $ret_field = null;
  784. foreach( $this->Fields as $field ) {
  785. if ($field->Name == $name ) {
  786. $ret_field = $field;
  787. break;
  788. }
  789. }
  790. return $ret_field;
  791. }
  792. }
  793. /**
  794. * Description of a table field
  795. *
  796. * @package joomfish
  797. * @subpackage administrator
  798. * @copyright 2003-2007 Think Network GmbH
  799. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
  800. * @version $Revision: 789 $
  801. * @author Alex Kempkens <joomfish@thinknetwork.com>
  802. */
  803. class ContentElementTablefield {
  804. var $Type='';
  805. var $Name='';
  806. var $Lable='';
  807. var $Translate=false;
  808. var $Option='';
  809. var $Length=30;
  810. var $MaxLength=80;
  811. var $Rows=15;
  812. var $Columns=30;
  813. /** originalValue value of the corresponding content table */
  814. var $originalValue;
  815. /** translationContent reference to the actual translation db object */
  816. var $translationContent;
  817. /** changed Flag that says if a field is changed or not */
  818. var $changed=false;
  819. /** this Flag explains if the original is empty or not */
  820. var $originalEmpty=false;
  821. /** Standard constructur
  822. */
  823. function ContentElementTablefield( $tablefieldElement ) {
  824. $this->Type = trim( $tablefieldElement->getAttribute( 'type' ) );
  825. $this->Name = trim( $tablefieldElement->getAttribute( 'name' ) );
  826. $this->Lable = trim( $tablefieldElement->getText() );
  827. $this->Translate = trim( $tablefieldElement->getAttribute( 'translate' ) );
  828. $this->Option = trim( $tablefieldElement->getAttribute( 'option' ) );
  829. $this->Length = intval( $tablefieldElement->getAttribute( 'length' ) );
  830. $this->MaxLength = intval( $tablefieldElement->getAttribute( 'maxlength' ) );
  831. $this->Rows = intval( $tablefieldElement->getAttribute( 'rows' ) );
  832. $this->Columns = intval( $tablefieldElement->getAttribute( 'columns' ) );
  833. }
  834. }
  835. /**
  836. * Representation of one content with his translation.
  837. * The object includes information from the original object and
  838. * the refering translation. Based on that information it is
  839. * able to handle all necessary interactions with the tranlsation.
  840. * Each instance of this object represents only one translation in
  841. * on specified language, but it handles all the fields within the
  842. * ContentElement.
  843. *
  844. * @package joomfish
  845. * @subpackage administrator
  846. * @copyright 2003-2007 Think Network GmbH
  847. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
  848. * @version $Revision: 789 $
  849. * @author Alex Kempkens <joomfish@thinknetwork.com>
  850. */
  851. class ContentObject {
  852. /** @var _contentElement Reference to the ContentElement definition of the instance */
  853. var $_contentElement;
  854. /** @var id ID of the based content */
  855. var $id;
  856. /** @var translation_id translation id value */
  857. var $translation_id=0;
  858. /** @var checked_out User who checked out this content if any */
  859. var $checked_out;
  860. /** @var title Title of the object; used from the field configured as titletext */
  861. var $title;
  862. /** @var titleTranslation the actual translation of the title */
  863. var $titleTranslation;
  864. /** @var language_id language for the translation */
  865. var $language_id;
  866. /** @var language Language name of the content */
  867. var $language;
  868. /** @var lastchanged Date when the translation was last modified */
  869. var $lastchanged;
  870. /** @var modified_date Date of the last modification of the content - if existing */
  871. var $modified_date;
  872. /** @var state State of the translation
  873. * -1 := for at least one field of the content the translation is missing
  874. * 0 := the translation exists but the original content was changed
  875. * 1 := the translation is valid
  876. */
  877. var $state=-1;
  878. /** @var int Number of changed fields */
  879. var $_numChangedFields=0;
  880. /** @var int Number of new fields, with an original other than NULL */
  881. var $_numNewAndNotNullFields=0;
  882. /** @var int Number for fields unchanged */
  883. var $_numUnchangedFields=0;
  884. /** published Flag if the translation is published or not */
  885. var $published=false;
  886. /** Standard constructor
  887. *
  888. * @param languageID ID of the associated language
  889. * @param elementTable Reference to the ContentElementTable object
  890. */
  891. function ContentObject( $languageID,& $contentElement, $id=-1 ) {
  892. global $database;
  893. if($id>0) $this->id = $id;
  894. $this->language_id = $languageID;
  895. // active languages are cached in $_JOOMFISH_MANAGER - use these if possible
  896. global $_JOOMFISH_MANAGER;
  897. if (isset($_JOOMFISH_MANAGER) && $_JOOMFISH_MANAGER->activeLanguagesCacheByID && array_key_exists($languageID,$_JOOMFISH_MANAGER->activeLanguagesCacheByID)){
  898. $lang = $_JOOMFISH_MANAGER->activeLanguagesCacheByID[$languageID];
  899. }
  900. else {
  901. $lang = new jfLanguage($database);
  902. $lang->load( $languageID );
  903. }
  904. $this->language = $lang->name;
  905. $this->_contentElement = $contentElement;
  906. }
  907. /** Loads the information based on a certain content ID
  908. */
  909. function loadFromContentID( $id=null ) {
  910. global $database;
  911. if( $id!=null && isset($this->_contentElement) ) {
  912. $database->setQuery( $this->_contentElement->createContentSQL( $this->language_id, $id ) );
  913. $row=null;
  914. $database->loadObject( $row );
  915. $this->id = $id;
  916. $this->readFromRow( $row );
  917. }
  918. }
  919. /** Reads the information from the values of the form
  920. * The content element will be loaded first and then the values of the override
  921. * what is actually in the element
  922. *
  923. * @param array The values which should be bound to the object
  924. * @param string The field prefix
  925. * @param string An optional field
  926. * @param boolean try to bind the values to the object
  927. * @param boolean store original values too
  928. */
  929. function bind( $formArray, $prefix="", $suffix="", $tryBind=true, $storeOriginalText=false ) {
  930. global $my, $database;
  931. if( $tryBind ) {
  932. mosBindArrayToObject( $formArray, $this );
  933. }
  934. if( $this->published=="" ) $this->published=0;
  935. // Go thru all the fields of the element and try to copy the content values
  936. $elementTable =& $this->_contentElement->getTable();
  937. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  938. $field =& $elementTable->Fields[$i];
  939. $fieldName=$field->Name;
  940. if( isset($formArray[$prefix ."refField_". $fieldName .$suffix]) ) {
  941. $translationValue = $formArray[$prefix ."refField_". $fieldName .$suffix];
  942. $originalValue = $formArray[$prefix ."origValue_". $fieldName .$suffix];
  943. $originalText = ($storeOriginalText) ? $formArray[$prefix ."origText_". $fieldName .$suffix] : null;
  944. $fieldContent = new jfContent($database);
  945. mosBindArrayToObject( $formArray, $fieldContent );
  946. // code cleaner for xhtml transitional compliance
  947. if( $field->Type == 'titletext' || $field->Type == 'text') {
  948. $translationValue = ampReplace( $translationValue );
  949. }
  950. if( $field->Type == 'htmltext' ) {
  951. $translationValue = str_replace( '<br>', '<br />', $translationValue );
  952. // remove <br /> take being automatically added to empty fulltext
  953. $length = strlen( $translationValue ) < 9;
  954. $search = strstr( $translationValue, '<br />');
  955. if ( $length && $search ) {
  956. $translationValue = NULL;
  957. }
  958. }
  959. if ($field->Type == "params" && is_array($translationValue)){
  960. $txt = array();
  961. foreach ($translationValue as $k=>$v) {
  962. $txt[] = "$k=$v";
  963. }
  964. $translationValue = mosParameters::textareaHandling( $txt );
  965. }
  966. $fieldContent->id=$formArray[$prefix . "id_" .$fieldName .$suffix];
  967. $fieldContent->reference_id = (intval($formArray[$prefix . "reference_id" .$suffix]) > 0) ? intval($formArray[$prefix . "reference_id" .$suffix]) : $this->id;
  968. $fieldContent->language_id = $this->language_id;
  969. $fieldContent->reference_table= $database->getEscaped( $elementTable->Name );
  970. $fieldContent->reference_field= $database->getEscaped( $fieldName );
  971. $fieldContent->value = (get_magic_quotes_gpc()) ? mosStripslashes( $translationValue ) : $translationValue;
  972. //$fieldContent->original_value = (get_magic_quotes_gpc()) ? stripslashes( $originalValue ) : $originalValue;
  973. // original value will be already md5 encoded - based on that any encoding isn't needed!
  974. $fieldContent->original_value = $originalValue;
  975. $fieldContent->original_text = $originalText;
  976. $fieldContent->modified = date( "Y-m-d H:i:s" );
  977. $fieldContent->modified_by = $my->id;
  978. $fieldContent->published=$this->published;
  979. $field->translationContent = $fieldContent;
  980. }
  981. }
  982. }
  983. /** Reads the information out of an existing mosDBTable object into the contentObject.
  984. *
  985. * @param object instance of an mosDBTable object
  986. */
  987. function updateMLContent( &$dbObject ) {
  988. global $database;
  989. if( $dbObject === null ) return;
  990. if( $this->published=="" ) $this->published=0;
  991. // retriev the original untranslated object for references
  992. // this MUST be copied by value and not by reference!
  993. $origObject = clone($dbObject);
  994. $key = $dbObject->get( '_tbl_key' );
  995. $database->setQuery( "SELECT * FROM " .$dbObject->get('_tbl'). " WHERE " .$key. "='" .$dbObject->$key. "'" );
  996. $database->loadObject( $origObject, false );
  997. $this->copyContentToTranslation( $dbObject, $origObject );
  998. }
  999. /**
  1000. * This method copies a currect database object into the translations
  1001. * The original object might be the same kind of object and it is not required that
  1002. * both objects are of the type mosDBTable!
  1003. *
  1004. * @param object $dbObject new values for the translation
  1005. * @param object $origObject original values based on the db for reference
  1006. */
  1007. function copyContentToTranslation( &$dbObject, $origObject ) {
  1008. global $my;
  1009. // Go thru all the fields of the element and try to copy the content values
  1010. $elementTable =& $this->_contentElement->getTable();
  1011. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  1012. $field =& $elementTable->Fields[$i];
  1013. $fieldName=$field->Name;
  1014. if( isset($dbObject->$fieldName) && $field->Translate ) {
  1015. $translationValue = $dbObject->$fieldName;
  1016. $fieldContent =& $field->translationContent;
  1017. $fieldContent->value = $translationValue;
  1018. $dbObject->$fieldName = $origObject->$fieldName;
  1019. $fieldContent->original_value = md5( $origObject->$fieldName );
  1020. // ToDo: Add handling of original text!
  1021. $fieldContent->modified = date( "Y-m-d H:i:s" );
  1022. $fieldContent->modified_by = $my->id;
  1023. }
  1024. }
  1025. }
  1026. /** Reads some of the information from the overview row
  1027. */
  1028. function readFromRow( $row ) {
  1029. $this->id = $row->id;
  1030. $this->translation_id = $row->jfc_id;
  1031. $this->title = $row->title;
  1032. $this->titleTranslation = $row->titleTranslation;
  1033. if( !isset($this->language_id) || $this->language_id == -1 ) {
  1034. $this->language_id = $row->language_id;
  1035. $this->language = $row->language;
  1036. }
  1037. $this->lastchanged = $row->lastchanged;
  1038. $this->published = $row->published;
  1039. if( isset($row->modified_date) ) $this->modified_date = $row->modified_date;
  1040. if( isset($row->checked_out) ) $this->checked_out = $row->checked_out;
  1041. // Go thru all the fields of the element and try to copy the content values
  1042. $elementTable =& $this->_contentElement->getTable();
  1043. $fieldContent = new jfContent($database);
  1044. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  1045. $field =& $elementTable->Fields[$i];
  1046. $fieldName = $field->Name;
  1047. if( isset($row->$fieldName) ) {
  1048. $field->originalValue = $row->$fieldName;
  1049. }
  1050. }
  1051. $this->_loadContent();
  1052. }
  1053. /** Reads all translation information from the database
  1054. *
  1055. */
  1056. function _loadContent() {
  1057. global $database;
  1058. $elementTable = $this->getTable();
  1059. $sql = "select * "
  1060. ."\n from #__jf_content"
  1061. ."\n where reference_id='" .$this->id."'"
  1062. ."\n and reference_table='" .$elementTable->Name. "'";
  1063. if( isset($this->language_id) && $this->language_id!="" ) {
  1064. $sql .= "\n and language_id=" .$this->language_id;
  1065. }
  1066. //echo "load sql=>$sql<<br />";
  1067. $database->setQuery( $sql );
  1068. $rows = $database->loadObjectList(false);
  1069. echo $database->getErrorMsg();
  1070. $translationFields=null;
  1071. if( count($rows) > 0 ) {
  1072. foreach( $rows as $row ) {
  1073. $fieldContent = new jfContent($database);
  1074. if( !$fieldContent->bind( $row ) ) {
  1075. echo $fieldContent->getError();
  1076. }
  1077. $translationFields[$fieldContent->reference_field] = $fieldContent;
  1078. }
  1079. }
  1080. // Check fields and their state
  1081. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  1082. $field =& $elementTable->Fields[$i];
  1083. if( isset($translationFields[$field->Name]) ) {
  1084. $fieldContent = $translationFields[$field->Name];
  1085. } else {
  1086. $fieldContent = null;
  1087. }
  1088. if( $field->Translate) {
  1089. if(isset($fieldContent) ) {
  1090. $field->changed= (md5($field->originalValue) != $fieldContent->original_value);
  1091. if( $field->changed ) {
  1092. $this->_numChangedFields ++;
  1093. }
  1094. else $this->_numUnchangedFields++;
  1095. }
  1096. else{
  1097. $fieldContent = new jfContent($database);
  1098. $fieldContent->reference_id = $this->id;
  1099. $fieldContent->reference_table = $elementTable->Name;
  1100. $fieldContent->reference_field = $field->Name;
  1101. $fieldContent->language_id = $this->language_id;
  1102. $fieldContent->original_value = $field->originalValue;
  1103. $field->changed =false;
  1104. if ( $field->originalValue != '' ) {
  1105. $this->_numNewAndNotNullFields ++;
  1106. }
  1107. }
  1108. }
  1109. $field->translationContent = $fieldContent;
  1110. }
  1111. // Checking the record state based on the fields. If one field is changed the record is modifed
  1112. if( $this->_numChangedFields == 0 && $this->_numNewAndNotNullFields == 0 ) {
  1113. $this->state = 1;
  1114. } elseif ( $this->_numChangedFields == 0 && $this->_numNewAndNotNullFields > 0 && $this->_numUnchangedFields==0) {
  1115. $this->state = -1;
  1116. } else {
  1117. $this->state = 0;
  1118. }
  1119. }
  1120. /** Returns the content element fields which are text and can be translated
  1121. *
  1122. * @param boolean onle translateable fields?
  1123. * @return array of fieldnames
  1124. */
  1125. function getTextFields( $translation = true ) {
  1126. $elementTable =& $this->_contentElement->getTable();
  1127. $textFields = null;
  1128. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  1129. $field =& $elementTable->Fields[$i];
  1130. $fieldType = $field->Type;
  1131. if( $field->Translate == $translation && ($fieldType=="htmltext" || $fieldType=="text") ) {
  1132. $textFields[] = $field->Name;
  1133. }
  1134. }
  1135. return $textFields;
  1136. }
  1137. /**
  1138. * Returns the field type of a field
  1139. *
  1140. * @param string $fieldname
  1141. */
  1142. function getFieldType($fieldname){
  1143. $elementTable =& $this->_contentElement->getTable();
  1144. $textFields = null;
  1145. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  1146. if ($elementTable->Fields[$i]->Name == $fieldname) return $elementTable->Fields[$i]->Type;
  1147. }
  1148. return "text";
  1149. }
  1150. /** Sets all fields of this content object to a certain published state
  1151. */
  1152. function setPublished( $published ) {
  1153. $elementTable =& $this->_contentElement->getTable();
  1154. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  1155. $field =& $elementTable->Fields[$i];
  1156. $fieldContent =& $field->translationContent;
  1157. $fieldContent->published = $published;
  1158. }
  1159. }
  1160. /** Updates the reference id of all included fields. This
  1161. * Happens e.g when the reference object was created new
  1162. *
  1163. * @param referenceID new reference id
  1164. */
  1165. function updateReferenceID( $referenceID ) {
  1166. if( intval($referenceID) <= 0 ) return;
  1167. $elementTable =& $this->_contentElement->getTable();
  1168. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  1169. $field =& $elementTable->Fields[$i];
  1170. $fieldContent =& $field->translationContent;
  1171. $fieldContent->reference_id = $referenceID;
  1172. }
  1173. }
  1174. /** Stores all fields of the content element
  1175. */
  1176. function store() {
  1177. $elementTable =& $this->_contentElement->getTable();
  1178. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  1179. $field =& $elementTable->Fields[$i];
  1180. $fieldContent =& $field->translationContent;
  1181. if( $field->Translate ) {
  1182. if( isset($fieldContent->reference_id) ) {
  1183. if ( isset($fieldContent->value) && $fieldContent->value!='' ) {
  1184. $fieldContent->store(true);
  1185. } else {
  1186. $fieldContent->delete();
  1187. }
  1188. }
  1189. }
  1190. }
  1191. }
  1192. /** Checkouts all fields of this content element
  1193. */
  1194. function checkout( $who, $oid=null ) {
  1195. $elementTable =& $this->_contentElement->getTable();
  1196. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  1197. $field =& $elementTable->Fields[$i];
  1198. $fieldContent =& $field->translationContent;
  1199. if( $field->Translate ) {
  1200. if( isset($fieldContent->reference_id) ) {
  1201. $fieldContent->checkout( $who, $oid );
  1202. echo $fieldContent->getError();
  1203. }
  1204. }
  1205. }
  1206. }
  1207. /** Checkouts all fields of this content element
  1208. */
  1209. function checkin( $oid=null ) {
  1210. $elementTable =& $this->_contentElement->getTable();
  1211. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  1212. $field =& $elementTable->Fields[$i];
  1213. $fieldContent =& $field->translationContent;
  1214. if( $field->Translate ) {
  1215. if( isset($fieldContent->reference_id) ) {
  1216. $fieldContent->checkin( $oid );
  1217. echo $fieldContent->getError();
  1218. }
  1219. }
  1220. }
  1221. }
  1222. /** Delets all translations (fields) of this content element
  1223. */
  1224. function delete( $oid=null ) {
  1225. $elementTable =& $this->_contentElement->getTable();
  1226. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  1227. $field =& $elementTable->Fields[$i];
  1228. $fieldContent =& $field->translationContent;
  1229. if( $field->Translate ) {
  1230. if( isset($fieldContent->reference_id) ) {
  1231. if( !$fieldContent->delete( $oid ) ) {
  1232. echo $fieldContent->getError() ."<br />";
  1233. }
  1234. }
  1235. }
  1236. }
  1237. }
  1238. /** Returns the content element table this content is based on
  1239. */
  1240. function getTable() {
  1241. return $this->_contentElement->getTable();
  1242. }
  1243. }
  1244. /**
  1245. * Database class for handling the mambe fish contents
  1246. *
  1247. * @package joomfish
  1248. * @subpackage administrator
  1249. * @copyright 2003-2007 Think Network GmbH
  1250. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
  1251. * @version $Revision: 789 $
  1252. * @author Alex Kempkens <joomfish@thinknetwork.com>
  1253. */
  1254. class jfContent extends mosDBTable {
  1255. /** @var int Primary ke */
  1256. var $id=null;
  1257. /** @var int Reference id for the language */
  1258. var $language_id=null;
  1259. /** @var int Reference id for the original content */
  1260. var $reference_id=null;
  1261. /** @var int Reference table of the original content */
  1262. var $reference_table=null;
  1263. /** @var int Reference field of the original content */
  1264. var $reference_field=null;
  1265. /** @var string translated value*/
  1266. var $value=null;
  1267. /** @var string original value for equals check*/
  1268. var $original_value=null;
  1269. /** @var string original value for equals check*/
  1270. var $original_text=null;
  1271. /** @var int user that checked out the jfContent*/
  1272. // var $checked_out=null; // not yet supported
  1273. /** @var datetime time when the checkout was done*/
  1274. // var $checked_out_time=null; // not yet supported
  1275. /** @var date Date of last modification*/
  1276. var $modified=null;
  1277. /** @var string Last translator*/
  1278. var $modified_by=null;
  1279. /** @var boolean Flag of the translation publishing status*/
  1280. var $published=false;
  1281. /** Standard constructur
  1282. */
  1283. function jfContent( &$db ) {
  1284. $this->mosDBTable( '#__jf_content', 'id', $db );
  1285. }
  1286. /**
  1287. * Bind the content of the newValues to the object. Overwrite to make it possible
  1288. * to use also objects here
  1289. */
  1290. function bind( $newValues ) {
  1291. if (is_array( $newValues )) {
  1292. return parent::bind( $newValues );
  1293. } else {
  1294. foreach (get_object_vars($this) as $k => $v) {
  1295. if ( isset($newValues->$k) ) {
  1296. $this->$k = $newValues->$k;
  1297. }
  1298. }
  1299. }
  1300. return true;
  1301. }
  1302. /**
  1303. * Validate language information
  1304. * Name and Code name are mandatory
  1305. * activated will automatically set to false if not set
  1306. */
  1307. function check() {
  1308. if (trim( $this->language_id ) == '') {
  1309. $this->_error = JText::_('NO_LANGUAGE_DBERROR');
  1310. return false;
  1311. }
  1312. return true;
  1313. }
  1314. function toString() {
  1315. $retString = "<p>content field:<br />";
  1316. $retString .= "id=$this->id; language_id=$this->language_id<br>";
  1317. $retString .= "reference_id=$this->reference_id, reference_table=$this->reference_table, reference_field=$this->reference_field<br>";
  1318. $retString .= "value=>" .htmlspecialchars($this->value). "<<br />";
  1319. $retString .= "original_value=>" .htmlspecialchars($this->original_value). "<<br />";
  1320. $retString .="modified=$this->modified, modified_by=$this->modified_by, published=$this->published</p>";
  1321. return $retString;
  1322. }
  1323. }
  1324. /**
  1325. * Database class for handling the languages within the component
  1326. *
  1327. * @package joomfish
  1328. * @subpackage administrator
  1329. * @copyright 2003-2007 Think Network GmbH
  1330. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
  1331. * @version $Revision: 789 $
  1332. * @author Alex Kempkens <joomfish@thinknetwork.com>
  1333. */
  1334. class jfLanguage extends mosDBTable {
  1335. /** @var int Primary key */
  1336. var $id=null;
  1337. /** @var string The full name of the language*/
  1338. var $name=null;
  1339. /** @var int Flag if the language is activated for this site*/
  1340. var $active=false;
  1341. /** @var string iso/locale code of the language*/
  1342. var $iso=null;
  1343. /** @var string short code for URL or language switching */
  1344. var $shortcode=null;
  1345. /** @var string The name Joomla is using for this language*/
  1346. var $code=null;
  1347. /** @var string Order of the languages within the lists*/
  1348. var $ordering=0;
  1349. /** @var string Image reference if there is any*/
  1350. var $image="";
  1351. /** @var string optional code of language to fall back on if translation is missing */
  1352. var $fallback_code=0;
  1353. /** @var string parameter set base on key=value pairs */
  1354. var $params=null;
  1355. /** Standard constructur
  1356. */
  1357. function jfLanguage( &$db ) {
  1358. $this->mosDBTable( '#__languages', 'id', $db );
  1359. }
  1360. /**
  1361. * Loads the language by it's iso name
  1362. * @param str…

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