[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZContentLanguage class 4 // 5 // Created on: <08-Feb-2006 10:23:51 jk> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 include_once ( 'kernel/classes/ezpersistentobject.php' ); 30 include_once ( 'lib/ezlocale/classes/ezlocale.php' ); 31 32 define( 'CONTENT_LANGUAGES_MAX_COUNT', 30 ); 33 34 class eZContentLanguage extends eZPersistentObject 35 { 36 /** 37 * Constructor. 38 * 39 * \param row Parameter passed to the constructor of eZPersistentObject. 40 */ 41 function eZContentLanguage( $row = array() ) 42 { 43 $this->eZPersistentObject( $row ); 44 } 45 46 /** 47 * Persistent object's definition. 48 */ 49 function definition() 50 { 51 return array( 'fields' => array( 'id' => array( 'name' => 'ID', 52 'datatype' => 'integer', 53 'required' => true ), 54 'name' => array( 'name' => 'Name', 55 'datatype' => 'string', 56 'required' => true ), 57 'locale' => array( 'name' => 'Locale', 58 'datatype' => 'string', 59 'required' => true ), 60 'disabled' => array( 'name' => 'Disabled', /* disabled is reserved for the future */ 61 'datatype' => 'integer', 62 'default' => 0, 63 'required' => false ) ), 64 'keys' => array( 'id' ), 65 'function_attributes' => array( 'translation' => 'translation', 66 'locale_object' => 'localeObject', 67 'object_count' => 'objectCount' ), 68 'sort' => array( 'name' => 'asc' ), 69 'class_name' => 'eZContentLanguage', 70 'name' => 'ezcontent_language' ); 71 } 72 73 /** 74 * Adds new language to the site. 75 * 76 * \param locale Locale code (e.g. 'slk-SK') of language to add. 77 * \param name Optional. Name of the language. If not specified, the international language name for the $locale locale 78 * will be used. 79 * \return eZContentLanguage object of the added language (or the existing one if specified language has been already used) 80 * or false in case of any error (invalid locale code or already reached CONTENT_LANGUAGES_MAX_COUNT languages). 81 * \static 82 */ 83 function addLanguage( $locale, $name = null ) 84 { 85 $localeObject = eZLocale::instance( $locale ); 86 if ( !$localeObject ) 87 { 88 eZDebug::writeError( "No such locale $locale!", 'eZContentLanguage::addLanguage' ); 89 return false; 90 } 91 92 if ( $name === null ) 93 { 94 $name = $localeObject->attribute( 'intl_language_name' ); 95 } 96 97 $db =& eZDB::instance(); 98 99 $languages = eZContentLanguage::fetchList( true ); 100 101 if ( ( $existingLanguage = eZContentLanguage::fetchByLocale( $locale ) ) ) 102 { 103 eZDebug::writeWarning( "Language '$locale' already exists!", 'eZContentLanguage::addLanguage' ); 104 return $existingLanguage; 105 } 106 107 if ( count( $languages ) >= CONTENT_LANGUAGES_MAX_COUNT ) 108 { 109 eZDebug::writeError( 'Too many languages, cannot add more!', 'eZContentLanguage::addLanguage' ); 110 return false; 111 } 112 113 $db->lock( 'ezcontent_language' ); 114 115 $idSum = 0; 116 foreach( $languages as $language ) 117 { 118 $idSum += $language->attribute( 'id' ); 119 } 120 121 // ID 1 is reserved 122 $candidateId = 2; 123 while ( $idSum & $candidateId ) 124 { 125 $candidateId *= 2; 126 } 127 128 $newLanguage = new eZContentLanguage( array( 129 'id' => $candidateId, 130 'locale' => $locale, 131 'name' => $name, 132 'disabled' => 0 ) ); 133 $newLanguage->store(); 134 135 $db->unlock(); 136 137 eZContentLanguage::fetchList( true ); 138 139 // clear the cache 140 include_once ( 'kernel/classes/ezcontentcachemanager.php' ); 141 eZContentCacheManager::clearAllContentCache(); 142 143 return $newLanguage; 144 } 145 146 /** 147 * Removes the language specified by ID. 148 * 149 * \param id ID of the language to be removed. 150 * \return True if the language was removed from the site, false otherwise. 151 * \static 152 */ 153 function removeLanguage( $id ) 154 { 155 $language = eZContentLanguage::fetch( $id ); 156 if ( $language ) 157 { 158 return $language->remove(); 159 } 160 else 161 { 162 return false; 163 } 164 } 165 166 /** 167 * Removes the language if there is no object having translation in it. 168 * 169 * \return True if the language was removed from the site, false otherwise. 170 */ 171 function remove() 172 { 173 if ( $this->objectCount() > 0 ) 174 { 175 return false; 176 } 177 178 eZPersistentObject::remove(); 179 180 include_once ( 'kernel/classes/ezcontentcachemanager.php' ); 181 eZContentCacheManager::clearAllContentCache(); 182 183 eZContentLanguage::fetchList( true ); 184 185 return true; 186 } 187 188 /** 189 * Fetches the list of the languages used on the site. 190 * 191 * \param forceReloading Optional. If true, the list will be fetched from database even if it is cached in memory. 192 * Default value is false. 193 * \return Array of the eZContentLanguage objects of languages used on the site. 194 * \static 195 */ 196 function fetchList( $forceReloading = false ) 197 { 198 if ( !isset( $GLOBALS['eZContentLanguageList'] ) || $forceReloading ) 199 { 200 $mask = 1; // we want have 0-th bit set too! 201 $languages = eZPersistentObject::fetchObjectList( eZContentLanguage::definition() ); 202 203 unset( $GLOBALS['eZContentLanguageList'] ); 204 unset( $GLOBALS['eZContentLanguageMask'] ); 205 $GLOBALS['eZContentLanguageList'] = array(); 206 foreach ( $languages as $language ) 207 { 208 $GLOBALS['eZContentLanguageList'][$language->attribute( 'id' )] = $language; 209 $mask += $language->attribute( 'id' ); 210 } 211 212 $GLOBALS['eZContentLanguageMask'] = $mask; 213 } 214 215 return $GLOBALS['eZContentLanguageList']; 216 } 217 218 /** 219 * Fetches the array with names and IDs of the languages used on the site. This method is used by the permission system. 220 * 221 * \param forceReloading Optional. If true, the list will be fetched from database even if it is cached in memory. 222 * Default value is false. 223 * \return Array with names and IDs of the languages used on the site. 224 * \static 225 */ 226 function fetchLimitationList( $forceReloading = false ) 227 { 228 $languages = array(); 229 foreach ( $this->fetchList( $forceReloading ) as $language ) 230 { 231 $languages[] = array( 'name' => $language->attribute( 'name' ), 232 'id' => $language->attribute( 'locale' ) ); 233 } 234 return $languages; 235 } 236 237 /** 238 * Fetches the array of locale codes of the languages used on the site. 239 * 240 * \return Array of locale codes of the languages used on the site. 241 * \static 242 */ 243 function fetchLocaleList() 244 { 245 $languages = eZContentLanguage::fetchList(); 246 $localeList = array(); 247 248 foreach ( $languages as $language ) 249 { 250 $localeList[] = $language->attribute( 'locale' ); 251 } 252 253 return $localeList; 254 } 255 256 /** 257 * Fetches the language identified by ID. 258 * 259 * \param id Identifier of the language to fetch. 260 * \return eZContentLanguage object of language identified by ID $id. 261 * \static 262 */ 263 function fetch( $id ) 264 { 265 $languages = eZContentLanguage::fetchList(); 266 267 return isset( $languages[$id] )? $languages[$id]: false; 268 } 269 270 /** 271 * Fetches the language identified by locale code. 272 * 273 * \param locale Locale of the language to fetch, e. g. 'slk-SK'. 274 * \return eZContentLanguage object identified by locale code $locale. 275 */ 276 function fetchByLocale( $locale ) 277 { 278 $languages = eZContentLanguage::fetchList(); 279 280 foreach ( $languages as $language ) 281 { 282 if ( $language->attribute( 'locale' ) == $locale ) 283 { 284 return $language; 285 } 286 } 287 288 return false; 289 } 290 291 /** 292 * Fetches the list of the prioritized languages (in the correct order). 293 * 294 * \param languageList Optional. If specified, this array of locale codes with will override the INI 295 * settings. Usage of this parameter is restricted to methods of this class! 296 * See eZContentLanguage::setPrioritizedLanguages(). 297 * \return Array of the eZContentLanguage objects of the prioritized languages. 298 * \static 299 */ 300 function prioritizedLanguages( $languageList = false ) 301 { 302 if ( !isset( $GLOBALS['eZContentLanguagePrioritizedLanguages'] ) ) 303 { 304 $GLOBALS['eZContentLanguagePrioritizedLanguages'] = array(); 305 306 $ini =& eZINI::instance(); 307 308 $languageListAsParameter = false; 309 if ( $languageList ) 310 { 311 $languageListAsParameter = true; 312 } 313 314 if ( !$languageList && $ini->hasVariable( 'RegionalSettings', 'SiteLanguageList' ) ) 315 { 316 $languageList = $ini->variable( 'RegionalSettings', 'SiteLanguageList' ); 317 } 318 319 if ( !$languageList ) 320 { 321 $languageList = array( $ini->variable( 'RegionalSettings', 'ContentObjectLocale' ) ); 322 } 323 324 $processedLocaleCodes = array(); 325 foreach ( $languageList as $localeCode ) 326 { 327 if ( in_array( $localeCode, $processedLocaleCodes ) ) 328 { 329 continue; 330 } 331 $processedLocaleCodes[] = $localeCode; 332 $language = eZContentLanguage::fetchByLocale( $localeCode ); 333 if ( $language ) 334 { 335 $GLOBALS['eZContentLanguagePrioritizedLanguages'][] = $language; 336 } 337 else 338 { 339 eZDebug::writeWarning( "Language '$localeCode' does not exist or is not used!", 'eZContentLanguage::prioritizedLanguages' ); 340 } 341 } 342 343 if ( ( !$languageListAsParameter && $ini->variable( 'RegionalSettings', 'ShowUntranslatedObjects' ) == 'enabled' ) || 344 ( isset( $GLOBALS['eZContentLanguageCronjobMode'] ) && $GLOBALS['eZContentLanguageCronjobMode'] ) ) 345 { 346 $completeList = eZContentLanguage::fetchList(); 347 foreach ( $completeList as $language ) 348 { 349 if ( !in_array( $language->attribute( 'locale' ), $languageList ) ) 350 { 351 $GLOBALS['eZContentLanguagePrioritizedLanguages'][] = $language; 352 } 353 } 354 } 355 } 356 357 return $GLOBALS['eZContentLanguagePrioritizedLanguages']; 358 } 359 360 /** 361 * Returns the array of the locale codes of the prioritized languages (in the correct order). 362 * 363 * \return Array of the locale codes of the prioritized languages (in the correct order). 364 * \see eZContentLanguage::prioritizedLanguages() 365 * \static 366 */ 367 function prioritizedLanguageCodes() 368 { 369 $languages = eZContentLanguage::prioritizedLanguages(); 370 $localeList = array(); 371 372 foreach ( $languages as $language ) 373 { 374 $localeList[] = $language->attribute( 'locale' ); 375 } 376 377 return $localeList; 378 } 379 380 /** 381 * Overrides the prioritized languages set by INI settings with the specified languages. 382 * 383 * \param languages Locale codes of the languages which will override the prioritized languages 384 * (the order is relevant). 385 * \static 386 */ 387 function setPrioritizedLanguages( $languages ) 388 { 389 unset( $GLOBALS['eZContentLanguagePrioritizedLanguages'] ); 390 eZContentLanguage::prioritizedLanguages( $languages ); 391 } 392 393 /** 394 * Clears the prioritized language list set by eZContentLanguage::setPrioritizedLanguages and reloading 395 * the list from INI settings. 396 * 397 * \static 398 */ 399 function clearPrioritizedLanguages() 400 { 401 eZContentLanguage::setPrioritizedLanguages( false ); 402 } 403 404 /** 405 * Returns the most prioritized language. 406 * 407 * \return eZContentLanguage object for the most prioritized language. 408 * \static 409 */ 410 function topPriorityLanguage() 411 { 412 $prioritizedLanguages = eZContentLanguage::prioritizedLanguages(); 413 if ( $prioritizedLanguages ) 414 { 415 return $prioritizedLanguages[0]; 416 } 417 else 418 { 419 return false; 420 } 421 } 422 423 /** 424 * \return Locale object for this language. 425 */ 426 function &localeObject() 427 { 428 include_once ( 'lib/ezlocale/classes/ezlocale.php' ); 429 430 $locale =& eZLocale::instance( $this->Locale ); 431 return $locale; 432 } 433 434 /** 435 * Returns array of languages which have set the corresponding bit in the mask. 436 * 437 * \param mask Bitmap specifying which languages should be returned. 438 * \return Array of eZContentLanguage objects of languages which have set the corresponding bit in $mask. 439 */ 440 function languagesByMask( $mask ) 441 { 442 $result = array(); 443 444 $languages = eZContentLanguage::fetchList(); 445 foreach ( $languages as $key => $language ) 446 { 447 if ( (int) $key & (int) $mask ) 448 { 449 $result[$language->attribute( 'locale' )] = $language; 450 } 451 } 452 453 return $result; 454 } 455 456 /** 457 * Returns array of prioritized languages which have set the corresponding bit in the mask. 458 * 459 * \param mask Bitmap specifying which languages should be returned. 460 * \return Array of eZContentLanguage objects of prioritized languages which have set the corresponding bit in $mask. 461 */ 462 function prioritizedLanguagesByMask( $mask ) 463 { 464 $result = array(); 465 466 $languages = eZContentLanguage::prioritizedLanguages(); 467 foreach ( $languages as $language ) 468 { 469 if ( ( (int) $language->attribute( 'id' ) & (int) $mask ) > 0 ) 470 { 471 $result[$language->attribute( 'locale' )] = $language; 472 } 473 } 474 475 return $result; 476 } 477 478 /** 479 * Returns array of prioritized languages which are listed in \a $languageLocaleList. 480 * The function does the same as 'prioritizedLanguagesByMask' but uses language locale list instead of language mask. 481 * 482 * \param languageLocaleList List of language locales to choose from. 483 * \return Array of eZContentLanguage objects of prioritized languages which have set the corresponding bit in $mask. 484 */ 485 function prioritizedLanguagesByLocaleList( $languageLocaleList ) 486 { 487 $result = array(); 488 489 if ( is_array( $languageLocaleList ) && count( $languageLocaleList ) > 0 ) 490 { 491 $languages = eZContentLanguage::prioritizedLanguages(); 492 foreach ( $languages as $language ) 493 { 494 if ( in_array( $language->attribute( 'locale' ), $languageLocaleList ) ) 495 { 496 $result[$language->attribute( 'locale' )] = $language; 497 } 498 } 499 } 500 501 return $result; 502 } 503 504 /** 505 * Returns the most prioritized language which has set the corresponding bit in the mask. 506 * 507 * \param mask Bitmap specifying which languages should be checked. 508 * \return eZContentLanguage object of the most prioritized language which have set the corresponding bit in $mask. 509 */ 510 function topPriorityLanguageByMask( $mask ) 511 { 512 $languages = eZContentLanguage::prioritizedLanguages(); 513 foreach ( $languages as $language ) 514 { 515 if ( ( (int) $language->attribute( 'id' ) & (int) $mask ) > 0 ) 516 { 517 return $language; 518 } 519 } 520 return false; 521 } 522 523 /** 524 * Returns the most prioritized language from specified by \a $languageLocaleList list of language locales. 525 * The function does the same as 'topPriorityLanguageByMask' but uses language locale list instead of language mask. 526 * 527 * \param languageLocaleList List of language locales to choose from. 528 * \return eZContentLanguage object of the most prioritized language. 529 */ 530 function topPriorityLanguageByLocaleList( $languageLocaleList ) 531 { 532 if ( is_array( $languageLocaleList ) && count( $languageLocaleList ) > 0 ) 533 { 534 $languages = eZContentLanguage::prioritizedLanguages(); 535 foreach ( $languages as $language ) 536 { 537 if ( in_array( $language->attribute( 'locale' ), $languageLocaleList ) ) 538 { 539 return $language; 540 } 541 } 542 } 543 544 return false; 545 } 546 547 /** 548 * Returns bitmap mask for the specified languages. 549 * 550 * \param locales Array of strings or a string specifying locale codes of the languages, e. g. 'slk-SK' or array( 'eng-GB', 'nor-NO' ) 551 * \param setZerothBit Optional. Specifies if the 0-th bit of mask should be set. False by default. 552 * \return Bitmap mask having set the corresponding bits for the specified languages. 553 */ 554 function maskByLocale( $locales, $setZerothBit = false ) 555 { 556 if ( !$locales ) 557 { 558 return 0; 559 } 560 561 if ( !is_array( $locales ) ) 562 { 563 $locales = array( $locales ); 564 } 565 566 $mask = 0; 567 if ( $setZerothBit ) 568 { 569 $mask = 1; 570 } 571 572 foreach( $locales as $locale ) 573 { 574 $language = eZContentLanguage::fetchByLocale( $locale ); 575 if ( $language ) 576 { 577 $mask += $language->attribute( 'id' ); 578 } 579 } 580 581 return (int) $mask; 582 } 583 584 /** 585 * \static 586 * Returns id of the language specified. 587 * 588 * \param locale String specifying locale code of the language, e. g. 'slk-SK' 589 * \return ID of the language specified by locale or false if the language is not set on the site. 590 */ 591 function idByLocale( $locale ) 592 { 593 $language = eZContentLanguage::fetchByLocale( $locale ); 594 if ( $language ) 595 { 596 return (int)$language->attribute( 'id' ); 597 } 598 else 599 { 600 return false; 601 } 602 } 603 604 /** 605 * Returns the SQL where-condition for selecting the rows (objects, object versions) which exist in any 606 * of prioritized languages or are always available. 607 * 608 * \param languageListTable Name of the table 609 * \param languageListAttributeName Optional. Name of the attribute in the table which contains the bitmap mask. 'language_mask' by default. 610 * \return SQL where-condition described above. 611 * \static 612 */ 613 function languagesSQLFilter( $languageListTable, $languageListAttributeName = 'language_mask' ) 614 { 615 $prioritizedLanguages = eZContentLanguage::prioritizedLanguages(); 616 $mask = 1; // 1 - always available objects 617 foreach( $prioritizedLanguages as $language ) 618 { 619 $mask += $language->attribute( 'id' ); 620 } 621 622 $db =& eZDB::instance(); 623 if ( $db->databaseName() == 'oracle' ) 624 { 625 return "\n bitand( $languageListTable.$languageListAttributeName, $mask ) > 0 \n"; 626 } 627 else 628 { 629 return "\n $languageListTable.$languageListAttributeName & $mask > 0 \n"; 630 } 631 } 632 633 /** 634 * Returns the SQL where-condition for selecting the rows (with object names, attributes etc.) in the correct language, 635 * i. e. in the most prioritized language from those in which an object exists. 636 * 637 * \param languageTable Name of the table containing the attribute with bitmaps. 638 * \param languageListTable Name of the table containing the attribute with language id. 639 * \param languageAttributeName Optional. Name of the attribute in $languageTable which contains 640 * the language id. 'language_id' by default. 641 * \param languageListAttributeName Optional. Name of the attribute in $languageListTable which contains 642 * the bitmap mask. 'language_mask' by default. 643 * \return SQL where-condition described above. 644 */ 645 function sqlFilter( $languageTable, $languageListTable = null, $languageAttributeName = 'language_id', $languageListAttributeName = 'language_mask' ) 646 { 647 $db =& eZDB::instance(); 648 649 if ( $languageListTable === null ) 650 { 651 $languageListTable = $languageTable; 652 } 653 654 $prioritizedLanguages = eZContentLanguage::prioritizedLanguages(); 655 if ( $db->databaseName() == 'oracle' ) 656 { 657 $leftSide = "bitand( $languageListTable.$languageListAttributeName - bitand( $languageListTable.$languageListAttributeName, $languageTable.$languageAttributeName ), 1 )\n"; 658 $rightSide = "bitand( $languageTable.$languageAttributeName, 1 )\n"; 659 } 660 else 661 { 662 $leftSide = " ( ( $languageListTable.$languageListAttributeName - ( $languageListTable.$languageListAttributeName & $languageTable.$languageAttributeName ) ) & 1 )\n"; 663 $rightSide = " ( $languageTable.$languageAttributeName & 1 )\n"; 664 } 665 666 for ( $index = count( $prioritizedLanguages ) - 1, $multiplier = 2; $index >= 0; $index--, $multiplier *= 2 ) 667 { 668 $id = $prioritizedLanguages[$index]->attribute( 'id' ); 669 670 if ( $db->databaseName() == 'oracle' ) 671 { 672 $leftSide .= " + bitand( $languageListTable.$languageListAttributeName - bitand( $languageListTable.$languageListAttributeName, $languageTable.$languageAttributeName ), $id )"; 673 $rightSide .= " + bitand( $languageTable.$languageAttributeName, $id )"; 674 } 675 else 676 { 677 $leftSide .= " + ( ( ( $languageListTable.$languageListAttributeName - ( $languageListTable.$languageListAttributeName & $languageTable.$languageAttributeName ) ) & $id )"; 678 $rightSide .= " + ( ( $languageTable.$languageAttributeName & $id )"; 679 } 680 681 if ( $multiplier > $id ) 682 { 683 $factor = $multiplier / $id; 684 if ( $db->databaseName() == 'oracle' ) 685 { 686 $factorTerm = ' * ' . $factor; 687 } 688 else 689 { 690 for ( $shift = 0; $factor > 1; $factor = $factor / 2, $shift++ ) ; 691 $factorTerm = ' << '. $shift; 692 } 693 $leftSide .= $factorTerm; 694 $rightSide .= $factorTerm; 695 } 696 else if ( $multiplier < $id ) 697 { 698 $factor = $id / $multiplier; 699 if ( $db->databaseName() == 'oracle' ) 700 { 701 $factorTerm = ' / ' . $factor; 702 } 703 else 704 { 705 for ( $shift = 0; $factor > 1; $factor = $factor / 2, $shift++ ) ; 706 $factorTerm = ' >> '. $shift; 707 } 708 $leftSide .= $factorTerm; 709 $rightSide .= $factorTerm; 710 } 711 if ( $db->databaseName() != 'oracle' ) 712 { 713 $leftSide .= " )\n"; 714 $rightSide .= " )\n"; 715 } 716 } 717 718 if ( $db->databaseName() == 'oracle' ) 719 { 720 $sql = "bitand( $languageTable.$languageAttributeName, $languageListTable.$languageListAttributeName ) > 0"; 721 } 722 else 723 { 724 $sql = "$languageTable.$languageAttributeName & $languageListTable.$languageListAttributeName > 0"; 725 } 726 727 return "\n ( $sql AND\n $leftSide <\n $rightSide ) \n"; 728 } 729 730 /** 731 * \return The count of objects containing the translation in this language. 732 */ 733 function &objectCount() 734 { 735 $db =& eZDB::instance(); 736 737 $languageID = $this->ID; 738 if ( $db->databaseName() == 'oracle' ) 739 { 740 $whereSQL = "bitand( language_mask, $languageID ) > 0"; 741 } 742 else 743 { 744 $whereSQL = "language_mask & $languageID > 0"; 745 } 746 747 $count = $db->arrayQuery( "SELECT COUNT(*) AS count FROM ezcontentobject WHERE $whereSQL" ); 748 $count = $count[0]['count']; 749 750 return $count; 751 } 752 753 /** 754 * \return The count of objects having this language as the initial/main one. 755 */ 756 function objectInitialCount() 757 { 758 $db =& eZDB::instance(); 759 760 $languageID = $this->ID; 761 $count = $db->arrayQuery( "SELECT COUNT(*) AS count FROM ezcontentobject WHERE initial_language_id = '$languageID'" ); 762 $count = $count[0]['count']; 763 764 return $count; 765 } 766 767 /** 768 * \return Reference to itself. Kept because of the backward compatibility. 769 */ 770 function &translation() 771 { 772 return $this; 773 } 774 775 /** 776 * \deprecated 777 */ 778 function updateObjectNames() 779 { 780 } 781 782 /** 783 * Switches on the cronjob mode. In this mode, the languages which are not in the list of the prioritized languages 784 * will be automatically added to it. 785 * 786 * \param enable Optional. If false, it will switch off the cronjob mode. True by default. 787 */ 788 function setCronjobMode( $enable = true ) 789 { 790 $GLOBALS['eZContentLanguageCronjobMode'] = true; 791 unset( $GLOBALS['eZContentLanguagePrioritizedLanguages'] ); 792 } 793 794 /** 795 * Switches off the cronjob mode. 796 * 797 * \see eZContentLanguage::setCronjobMode() 798 */ 799 function clearCronjobMode() 800 { 801 eZContentLanguage::setCronjobMode( false ); 802 } 803 804 /** 805 * Returns the Javascript array with locale codes and names of the languages which have set the corresponding 806 * bit in specified mask. 807 * 808 * \param mask Bitmap mask specifying which languages should be considered. 809 * \return JavaScript array described above. 810 */ 811 function jsArrayByMask( $mask ) 812 { 813 $jsArray = array(); 814 $languages = eZContentLanguage::prioritizedLanguagesByMask( $mask ); 815 foreach ( $languages as $key => $language ) 816 { 817 $jsArray[] = "{ locale: '".$language->attribute( 'locale' ). 818 "', name: '".$language->attribute( 'name' )."' }"; 819 } 820 821 if ( $jsArray ) 822 { 823 return '[ '.implode( ', ', $jsArray ).' ]'; 824 } 825 else 826 { 827 return false; 828 } 829 } 830 831 /** 832 * \return The bitmap mask containing all languages, i. e. the sum of the IDs of all languages. (The 0-th bit is set.) 833 */ 834 function maskForRealLanguages() 835 { 836 if ( !isset( $GLOBALS['eZContentLanguageMask'] ) ) 837 { 838 eZContentLanguage::fetchList( true ); 839 } 840 return $GLOBALS['eZContentLanguageMask']; 841 } 842 843 /** 844 * Removes all memory cache forcing it to read from database again for next method calls. 845 * 846 * \static 847 */ 848 function expireCache() 849 { 850 unset( $GLOBALS['eZContentLanguageList'], 851 $GLOBALS['eZContentLanguagePrioritizedLanguages'], 852 $GLOBALS['eZContentLanguageMask'], 853 $GLOBALS['eZContentLanguageCronjobMode'] ); 854 } 855 } 856 857 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |