| 102 | | } |
| 103 | | |
| 104 | | /** |
| 105 | | * Return string in the language requested by the user. |
| 106 | | * |
| 107 | | * @return string UTF-8 string of content. |
| 108 | | * |
| 109 | | * @access private |
| 110 | | */ |
| 111 | | private function getString() |
| 112 | | { |
| 113 | | // Init values |
| 114 | | $_retval = null; |
| 115 | | $_row = null; |
| 116 | | $_useCache = false; |
| 117 | | $_cachedData = null; |
| 118 | | |
| 119 | | // Create new cache objects |
| 120 | | $_cacheLanguage = new Cache('langstrings_' . $this->id . '_substring_' . substr(Locale::getCurrentLocale()->getId(), 0, 2) . '_string', $this->id); |
| 121 | | $_cache = new Cache('langstrings_' . $this->id . '_substring__string', $this->id); |
| 122 | | |
| 123 | | // Check if caching has been enabled. |
| 124 | | if ($_cacheLanguage->isCachingEnabled) { |
| 125 | | $_cachedData = $_cacheLanguage->getCachedData(); |
| 126 | | |
| 127 | | if ($_cachedData) { |
| 128 | | // Return cached data. |
| 129 | | $_useCache = true; |
| 130 | | $_retval = $_cachedData; |
| 131 | | } else { |
| 132 | | // Language specific cached data has not been found. |
| 133 | | // Try to get language independent cached data. |
| 134 | | $_cachedData = $_cache->getCachedData(); |
| 135 | | |
| 136 | | if ($_cachedData) { |
| 137 | | // Return cached data. |
| 138 | | $_useCache = true; |
| 139 | | $_retval = $_cachedData; |
| 140 | | } |
| 141 | | } |
| 142 | | } |
| 143 | | |
| 144 | | if (!$_useCache) { |
| 145 | | // Get string in the prefered language of the user |
| 146 | | $_sql = "SELECT value, locales_id, \n"; |
| 147 | | $_sql .= Locale::getSqlCaseStringSelect(Locale::getCurrentLocale()->getId()); |
| 148 | | $_sql .= " as score FROM content_langstring_entries WHERE content_langstring_entries.langstrings_id = '{$this->id}' AND value!='' ORDER BY score LIMIT 1"; |
| 149 | | $this->mBd->execSqlUniqueRes($_sql, $_row, false); |
| 150 | | |
| 151 | | if ($_row == null) { |
| 152 | | // String has not been found |
| 153 | | $_retval = "(Empty string)"; |
| 154 | | } else { |
| 155 | | // String has been found |
| 156 | | $_retval = $_row['value']; |
| 157 | | |
| 158 | | // Check if caching has been enabled. |
| 159 | | if ($_cache->isCachingEnabled) { |
| 160 | | // Save data into cache, because it wasn't saved into cache before. |
| 161 | | $_cache->saveCachedData($_retval); |
| 162 | | } |
| 163 | | } |
| 164 | | } |
| 165 | | |
| 166 | | return $_retval; |
| 167 | | } |
| 168 | | |
| 169 | | /** |
| 170 | | * Adds the string associated with the locale. |
| 171 | | * |
| 172 | | * @param string $string String to be added |
| 173 | | * @param string $locale Locale of string (i.e. 'fr_CA') - can |
| 174 | | * be NULL |
| 175 | | * @param bool $allow_empty_string Defines if string may be empty |
| 176 | | * |
| 177 | | * @return bool True if string has been added, otherwise false. |
| 178 | | * |
| 179 | | * @access private |
| 180 | | */ |
| 181 | | private function addString($string, $locale, $allow_empty_string = false) |
| 182 | | { |
| 183 | | // Init values |
| 184 | | $_retval = false; |
| 185 | | $_id = 'NULL'; |
| 186 | | $_idSQL = $_id; |
| 187 | | |
| 188 | | if ($locale) { |
| 189 | | // Set locale of string |
| 190 | | $_language = new Locale($locale); |
| 191 | | |
| 192 | | $_id = $_language->GetId(); |
| 193 | | $_idSQL = "'" . $_id . "'"; |
| 194 | | } |
| 195 | | |
| 196 | | if ($allow_empty_string || ($string != null && $string != '')) { |
| 197 | | // Save string in database |
| 198 | | $string = $this->mBd->escapeString($string); |
| 199 | | $this->mBd->execSqlUpdate("INSERT INTO content_langstring_entries (langstring_entries_id, langstrings_id, locales_id, value) VALUES ('" . get_guid() . "', '$this->id', $_idSQL , '$string')", FALSE); |
| 200 | | |
| 201 | | // Create new cache object. |
| 202 | | $_cache = new Cache('langstrings_' . $this->id . '_substring_' . $_id . '_string', $this->id); |
| 203 | | |
| 204 | | // Check if caching has been enabled. |
| 205 | | if ($_cache->isCachingEnabled) { |
| 206 | | // Remove old cached data. |
| 207 | | $_cache->eraseCachedData(); |
| 208 | | |
| 209 | | // Save data into cache. |
| 210 | | $_cache->saveCachedData($string); |
| 211 | | } |
| 212 | | |
| 213 | | $_retval = true; |
| 214 | | } |
| 215 | | |
| 216 | | return $_retval; |
| 217 | | } |
| 218 | | |
| 219 | | /** |
| 220 | | * Updates the string associated with the locale. |
| 221 | | * |
| 222 | | * @param string $string String to be updated. |
| 223 | | * @param string $locale Locale of string (i.e. 'fr_CA') - can be NULL. |
| 224 | | * |
| 225 | | * @return bool True if string has been updated, otherwise false. |
| 226 | | * |
| 227 | | * @access private |
| 228 | | */ |
| 229 | | private function UpdateString($string, $locale) |
| 230 | | { |
| 231 | | // Init values |
| 232 | | $_retval = false; |
| 233 | | $_id = 'NULL'; |
| 234 | | $_row = null; |
| 235 | | |
| 236 | | if ($locale) { |
| 237 | | // Set locale of string |
| 238 | | $_language = new Locale($locale); |
| 239 | | |
| 240 | | $_id = $_language->GetId(); |
| 241 | | $_idSQL = "'" . $_id . "'"; |
| 242 | | } |
| 243 | | |
| 244 | | if ($string != null && $string != '') { |
| 245 | | $string = $this->mBd->escapeString($string); |
| 246 | | |
| 247 | | // If the update returns 0 (no update), try inserting the record |
| 248 | | $this->mBd->execSqlUniqueRes("SELECT * FROM content_langstring_entries WHERE locales_id = $_idSQL AND langstrings_id = '$this->id'", $_row, false); |
| 249 | | |
| 250 | | if ($_row != null) { |
| 251 | | $this->mBd->execSqlUpdate("UPDATE content_langstring_entries SET value = '$string' WHERE langstrings_id = '$this->id' AND locales_id = $_idSQL", false); |
| 252 | | |
| 253 | | // Create new cache object. |
| 254 | | $_cache = new Cache('langstrings_' . $this->id . '_substring_' . $_id . '_string', $this->id); |
| 255 | | |
| 256 | | // Check if caching has been enabled. |
| 257 | | if ($_cache->isCachingEnabled) { |
| 258 | | // Remove old cached data. |
| 259 | | $_cache->eraseCachedData(); |
| 260 | | |
| 261 | | // Save data into cache. |
| 262 | | $_cache->saveCachedData($string); |
| 263 | | } |
| 264 | | } else { |
| 265 | | $this->addString($string, $locale); |
| 266 | | } |
| 267 | | |
| 268 | | $_retval = true; |
| 269 | | } |
| 270 | | return $_retval; |
| 396 | | // Init values |
| 397 | | $_result = null; |
| 398 | | |
| 399 | | if ($this->isOwner(User::getCurrentUser()) || User::getCurrentUser()->isSuperAdmin()) { |
| 400 | | parent::processAdminUI(); |
| 401 | | |
| 402 | | $_form_select = new FormSelectGenerator(); |
| 403 | | |
| 404 | | $_sql = "SELECT * FROM content_langstring_entries WHERE content_langstring_entries.langstrings_id = '$this->id'"; |
| 405 | | $this->mBd->execSql($_sql, $_result, FALSE); |
| 406 | | |
| 407 | | if ($_result != null) { |
| 408 | | while (list($_key, $_value) = each($_result)) { |
| 409 | | $_language = $_form_select->getResult("langstrings_" . $this->id . "_substring_" . $_value["langstring_entries_id"] . "_language", 'Langstring::AfficherInterfaceAdmin'); |
| 410 | | |
| 411 | | if (empty ($_language)) { |
| 412 | | $_language = ''; |
| 413 | | $_languageSQL = 'NULL'; |
| 414 | | } else { |
| 415 | | $_languageSQL = "'" . $_language . "'"; |
| 416 | | } |
| 417 | | |
| 418 | | if (!empty ($_REQUEST["langstrings_" . $this->id . "_substring_" . $_value["langstring_entries_id"] . "_erase"]) && $_REQUEST["langstrings_" . $this->id . "_substring_" . $_value["langstring_entries_id"] . "_erase"] == true) { |
| 419 | | $this->mBd->execSqlUpdate("DELETE FROM content_langstring_entries WHERE langstrings_id = '$this->id' AND langstring_entries_id='" . $_value["langstring_entries_id"] . "'", FALSE); |
| 420 | | |
| 421 | | // Create new cache object. |
| 422 | | $_cache = new Cache('langstrings_' . $this->id . '_substring_' . $_language . '_string', $this->id); |
| 423 | | |
| 424 | | // Check if caching has been enabled. |
| 425 | | if ($_cache->isCachingEnabled) { |
| 426 | | // Remove old cached data. |
| 427 | | $_cache->eraseCachedData(); |
| 428 | | } |
| 429 | | } else { |
| 430 | | // Strip HTML tags! |
| 431 | | $string = $_REQUEST["langstrings_" . $this->id . "_substring_" . $_value["langstring_entries_id"] . "_string"]; |
| 432 | | $string = $this->mBd->escapeString(strip_tags($string, self::ALLOWED_HTML_TAGS)); |
| 433 | | |
| 434 | | // If PEAR::HTML_Safe is available strips down all potentially dangerous content |
| 435 | | $_HtmlSafe = new HtmlSafe(); |
| 436 | | |
| 437 | | if ($_HtmlSafe->isHtmlSafeEnabled) { |
| 438 | | $string = $_HtmlSafe->parseHtml($string); |
| 439 | | } |
| 440 | | |
| 441 | | $this->mBd->execSqlUpdate("UPDATE content_langstring_entries SET locales_id = " . $_languageSQL . " , value = '$string' WHERE langstrings_id = '$this->id' AND langstring_entries_id='" . $_value["langstring_entries_id"] . "'", FALSE); |
| 442 | | |
| 443 | | // Create new cache object. |
| 444 | | $_cache = new Cache('langstrings_' . $this->id . '_substring_' . $_language . '_string', $this->id); |
| 445 | | |
| 446 | | // Check if caching has been enabled. |
| 447 | | if ($_cache->isCachingEnabled) { |
| 448 | | // Remove old cached data. |
| 449 | | $_cache->eraseCachedData(); |
| 450 | | |
| 451 | | // Save data into cache. |
| 452 | | $_cache->saveCachedData($string); |
| 453 | | } |
| 454 | | } |
| 455 | | } |
| 456 | | } |
| 457 | | |
| 458 | | $_new_substring_name = "langstrings_" . $this->id . "_substring_new_string"; |
| 459 | | $_new_substring_submit_name = "langstrings_" . $this->id . "_add_new_entry"; |
| 460 | | if ((isset ($_REQUEST[$_new_substring_submit_name]) && $_REQUEST[$_new_substring_submit_name] == true) || !empty ($_REQUEST[$_new_substring_name])) { |
| 461 | | $_language = $_form_select->getResult("langstrings_" . $this->id . "_substring_new_language", 'Langstring::AfficherInterfaceAdmin'); |
| 462 | | |
| 463 | | if (empty($_language)) { |
| 464 | | $_language = null; |
| 465 | | } |
| 466 | | |
| 467 | | $this->addString($_REQUEST[$_new_substring_name], $_language, true); |
| 468 | | } |
| 469 | | } |
| | 225 | return parent::processAdminUI(); |
| 472 | | |
| 473 | | /** |
| 474 | | * Retreives the user interface of this object. Anything that overrides |
| 475 | | * this method should call the parent method with it's output at the |
| 476 | | * END of processing. |
| 477 | | * |
| 478 | | * @param string $subclass_admin_interface HTML content of the interface |
| 479 | | * element of a children. |
| 480 | | * |
| 481 | | * @return string The HTML fragment for this interface. |
| 482 | | * |
| 483 | | * @access public |
| 484 | | */ |
| 485 | | public function getUserUI($subclass_user_interface = null) |
| 486 | | { |
| 487 | | // Init values |
| 488 | | $_html = ""; |
| 489 | | |
| 490 | | $_html .= "<div class='user_ui_container ".get_class($this)."'>\n"; |
| 491 | | $_html .= "<div class='langstring'>\n"; |
| 492 | | |
| 493 | | // Check FCKeditor support |
| 494 | | if ($this->_FCKeditorAvailable) { |
| 495 | | $_html .= $this->getString(); |
| 496 | | } else { |
| 497 | | $_html .= _("FCKeditor is not installed"); |
| 498 | | } |
| 499 | | |
| 500 | | $_html .= $subclass_user_interface; |
| 501 | | $_html .= "</div>\n"; |
| 502 | | $_html .= "</div>\n"; |
| 503 | | |
| 504 | | return parent::getUserUI($_html); |
| 505 | | } |
| 506 | | |
| 507 | | /** |
| 508 | | * Reloads the object from the database. Should normally be called after |
| 509 | | * a set operation. This function is private because calling it from a |
| 510 | | * subclass will call the constructor from the wrong scope. |
| 511 | | * |
| 512 | | * @return void |
| 513 | | * |
| 514 | | * @access private |
| 515 | | */ |
| 516 | | private function refresh() |
| 517 | | { |
| 518 | | $this->__construct($this->id); |
| 519 | | } |
| 520 | | |
| 521 | | /** |
| 522 | | * Deletes a HTMLeditor object |
| 523 | | * |
| 524 | | * @param string $errmsg Reference to error message |
| 525 | | * |
| 526 | | * @return bool True if deletion was successful |
| 527 | | * |
| 528 | | * @access public |
| 529 | | * @internal Persistent content will not be deleted |
| 530 | | */ |
| 531 | | public function delete(& $errmsg) { |
| 532 | | // Init values. |
| 533 | | $_retval = false; |
| 534 | | |
| 535 | | if ($this->isPersistent()) { |
| 536 | | $errmsg = _("Content is persistent (you must make it non persistent before you can delete it)"); |
| 537 | | } else { |
| 538 | | global $db; |
| 539 | | |
| 540 | | if ($this->isOwner(User::getCurrentUser()) || User::getCurrentUser()->isSuperAdmin()) { |
| 541 | | $_sql = "DELETE FROM content WHERE content_id='$this->id'"; |
| 542 | | $db->execSqlUpdate($_sql, false); |
| 543 | | $_retval = true; |
| 544 | | |
| 545 | | // Create new cache object. |
| 546 | | $_cache = new Cache('all', $this->id); |
| 547 | | |
| 548 | | // Check if caching has been enabled. |
| 549 | | if ($_cache->isCachingEnabled) { |
| 550 | | // Remove old cached data. |
| 551 | | $_cache->eraseCachedGroupData(); |
| 552 | | } |
| 553 | | } else { |
| 554 | | $errmsg = _("Access denied (not owner of content)"); |
| 555 | | } |
| 556 | | } |
| 557 | | |
| 558 | | return $_retval; |
| 559 | | } |
| 560 | | |