Show
Ignore:
Timestamp:
09/02/06 23:35:06 (6 years ago)
Author:
max-horvath
Message:

"2006-09-02 Max Horvath <max.horvath@…>

  • Installation script checks for PHP session extension (fixes #139)
  • Removed \"Call-time pass-by-reference has been deprecated\" warnings (fixes #239)
  • Revert changes of FCKeditor implementation (fixes #240)
  • Fix of FCKeditor implementation, now also supports FCKeditor 2.3+ (fixes #145)
  • Hotspots/Nodes? are sorted case-insensitive now (fixes #109)
  • Fix #141
  • templates/sites/index.tpl: fix wrong user count (fixes #236)
  • Added more trash mail services to the black list (fixes #149)"
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/wifidog/classes/Content/HTMLeditor/HTMLeditor.php

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