| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
|---|
| 4 | |
|---|
| 5 | // +-------------------------------------------------------------------+ |
|---|
| 6 | // | WiFiDog Authentication Server | |
|---|
| 7 | // | ============================= | |
|---|
| 8 | // | | |
|---|
| 9 | // | The WiFiDog Authentication Server is part of the WiFiDog captive | |
|---|
| 10 | // | portal suite. | |
|---|
| 11 | // +-------------------------------------------------------------------+ |
|---|
| 12 | // | PHP version 5 required. | |
|---|
| 13 | // +-------------------------------------------------------------------+ |
|---|
| 14 | // | Homepage: http://www.wifidog.org/ | |
|---|
| 15 | // | Source Forge: http://sourceforge.net/projects/wifidog/ | |
|---|
| 16 | // +-------------------------------------------------------------------+ |
|---|
| 17 | // | This program is free software; you can redistribute it and/or | |
|---|
| 18 | // | modify it under the terms of the GNU General Public License as | |
|---|
| 19 | // | published by the Free Software Foundation; either version 2 of | |
|---|
| 20 | // | the License, or (at your option) any later version. | |
|---|
| 21 | // | | |
|---|
| 22 | // | This program is distributed in the hope that it will be useful, | |
|---|
| 23 | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|---|
| 24 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|---|
| 25 | // | GNU General Public License for more details. | |
|---|
| 26 | // | | |
|---|
| 27 | // | You should have received a copy of the GNU General Public License | |
|---|
| 28 | // | along with this program; if not, contact: | |
|---|
| 29 | // | | |
|---|
| 30 | // | Free Software Foundation Voice: +1-617-542-5942 | |
|---|
| 31 | // | 59 Temple Place - Suite 330 Fax: +1-617-542-2652 | |
|---|
| 32 | // | Boston, MA 02111-1307, USA gnu@gnu.org | |
|---|
| 33 | // | | |
|---|
| 34 | // +-------------------------------------------------------------------+ |
|---|
| 35 | |
|---|
| 36 | /** |
|---|
| 37 | * @package WiFiDogAuthServer |
|---|
| 38 | * @subpackage ContentClasses |
|---|
| 39 | * @author Benoit Grégoire <bock@step.polymtl.ca> |
|---|
| 40 | * @copyright 2007 Benoit Grégoire, Technologies Coeus inc. |
|---|
| 41 | * @version Subversion $Id: $ |
|---|
| 42 | * @link http://www.wifidog.org/ |
|---|
| 43 | */ |
|---|
| 44 | |
|---|
| 45 | /** |
|---|
| 46 | * Load required classes |
|---|
| 47 | */ |
|---|
| 48 | require_once('classes/LocaleList.php'); |
|---|
| 49 | require_once('classes/Locale.php'); |
|---|
| 50 | |
|---|
| 51 | /** |
|---|
| 52 | * Represents a simple Langstring (no title, description, etc.) |
|---|
| 53 | * |
|---|
| 54 | * @package WiFiDogAuthServer |
|---|
| 55 | * @subpackage ContentClasses |
|---|
| 56 | * @author Benoit Grégoire <bock@step.polymtl.ca> |
|---|
| 57 | * @copyright 2005-2006 Benoit Grégoire, Technologies Coeus inc. |
|---|
| 58 | */ |
|---|
| 59 | class SimpleString extends Langstring |
|---|
| 60 | { |
|---|
| 61 | /** |
|---|
| 62 | * Constructor |
|---|
| 63 | * |
|---|
| 64 | * @param string $content_id Content id |
|---|
| 65 | * |
|---|
| 66 | * @return void */ |
|---|
| 67 | protected function __construct($content_id) |
|---|
| 68 | { |
|---|
| 69 | parent::__construct($content_id); |
|---|
| 70 | $this->allowed_html_tags = ""; |
|---|
| 71 | /* |
|---|
| 72 | * A SimpleString is NEVER persistent |
|---|
| 73 | */ |
|---|
| 74 | parent::setIsPersistent(false); |
|---|
| 75 | } |
|---|
| 76 | /** When a content object is set as Simple, it means that is is used merely to contain it's own data. No title, description or other metadata will be set or displayed, during display or administration |
|---|
| 77 | * @return true or false */ |
|---|
| 78 | public function isSimpleContent() { |
|---|
| 79 | return true; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | /** |
|---|
| 83 | * This method contains the interface to add an additional element to a |
|---|
| 84 | * content object. (For example, a new string in a Langstring) |
|---|
| 85 | * It is called when getNewContentUI has only a single possible object type. |
|---|
| 86 | * It may also be called by the object getAdminUI to avoid code duplication. |
|---|
| 87 | * |
|---|
| 88 | * @param string $contentId The id of the (possibly not yet created) content object. |
|---|
| 89 | * |
|---|
| 90 | * @param string $userData=null Array of contextual data optionally sent by displayAdminUI(), |
|---|
| 91 | * and only understood by the class (or subclasses) where getNewUI() is defined. |
|---|
| 92 | * The function must still function if none of it is present. |
|---|
| 93 | * |
|---|
| 94 | * @return HTML markup or false. False means that this object does not support this interface. |
|---|
| 95 | */ |
|---|
| 96 | public static function getNewUI($contentId, $userData=null) { |
|---|
| 97 | $html = ''; |
|---|
| 98 | !empty($userData['typeInterface'])?$typeInterface=$userData['typeInterface']:$typeInterface=null; |
|---|
| 99 | $name = "langstrings_" . $contentId . "_substring_new_language"; |
|---|
| 100 | $html .= "<input type='hidden' name='$name' value=''>\n"; |
|---|
| 101 | $new_substring_name = "langstrings_" . $contentId . "_substring_new_string"; |
|---|
| 102 | |
|---|
| 103 | if ($typeInterface == 'LARGE') { |
|---|
| 104 | $html .= "<textarea name='$new_substring_name' class='textarea' cols='60' rows='3'></textarea>\n"; |
|---|
| 105 | } else { |
|---|
| 106 | $html .= "<input type='text' name='$new_substring_name' class='input_text' size='44' value=''>\n"; |
|---|
| 107 | } |
|---|
| 108 | return $html; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | /** |
|---|
| 112 | * Retreives the admin interface of this object. Anything that overrides |
|---|
| 113 | * this method should call the parent method with it's output at the END of |
|---|
| 114 | * processing. |
|---|
| 115 | * @param string $subclass_admin_interface HTML content of the interface |
|---|
| 116 | * element of a children. |
|---|
| 117 | * @param string $type_interface SIMPLE pour éditer un seul champ, COMPLETE |
|---|
| 118 | * pour voir toutes les chaînes, LARGE pour |
|---|
| 119 | * avoir un textarea. |
|---|
| 120 | * @return string The HTML fragment for this interface. |
|---|
| 121 | */ |
|---|
| 122 | public function getAdminUI($subclass_admin_interface = null, $title = null, $type_interface = "LARGE") { |
|---|
| 123 | // Init values. |
|---|
| 124 | $html = ''; |
|---|
| 125 | $html .= $subclass_admin_interface; |
|---|
| 126 | $result = ""; |
|---|
| 127 | //$variantsCounter = 0; |
|---|
| 128 | //$_hideNewContent = false; |
|---|
| 129 | if (!empty ($this->allowed_html_tags)) { |
|---|
| 130 | $html .= "<div class='admin_section_hint'>" . _("Only these HTML tags are allowed : ") . htmlentities($this->allowed_html_tags) . "</div>"; |
|---|
| 131 | } |
|---|
| 132 | $html .= "<ul class='admin_element_list'>\n"; |
|---|
| 133 | $liste_languages = new LocaleList(); |
|---|
| 134 | $sql = "SELECT * FROM content_langstring_entries WHERE content_langstring_entries.langstrings_id = '$this->id' ORDER BY locales_id"; |
|---|
| 135 | $this->mBd->execSql($sql, $result, false); //echo "type_interface: $type_interface\n"; |
|---|
| 136 | |
|---|
| 137 | $exclude_array = array (); |
|---|
| 138 | if ($result != null) { |
|---|
| 139 | while (list ($key, $value) = each($result)) { |
|---|
| 140 | $exclude_array[$value['locales_id']] = $value['locales_id']; |
|---|
| 141 | |
|---|
| 142 | $html .= "<li class='admin_element_item_container'>\n"; |
|---|
| 143 | $html .= "<div class='admin_element_data'>\n"; |
|---|
| 144 | $name = "langstrings_" . $this->id . "_substring_$value[langstring_entries_id]_language"; |
|---|
| 145 | $html .= "<input type='hidden' name='$name' value=''>\n"; |
|---|
| 146 | if ($type_interface == 'LARGE') { |
|---|
| 147 | $html .= "<textarea name='langstrings_" . $this->id . "_substring_$value[langstring_entries_id]_string' class='textarea' cols='60' rows='3'>" . htmlspecialchars($value['value'], ENT_QUOTES, 'UTF-8') . "</textarea>\n"; |
|---|
| 148 | } else { |
|---|
| 149 | $html .= "<input type='text' class='input_text' name='langstrings_" . $this->id . "_substring_$value[langstring_entries_id]_string' size='44' value='" . htmlspecialchars($value['value'], ENT_QUOTES, 'UTF-8') . "'>\n"; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | $html .= "</div>\n"; |
|---|
| 153 | $html .= "</li>\n"; |
|---|
| 154 | } |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | //Nouvelles chaîne |
|---|
| 158 | if($result == null) { |
|---|
| 159 | $html .= "<li class='admin_element_item_container'>\n"; |
|---|
| 160 | $html .= "<div class='admin_element_data'>\n"; |
|---|
| 161 | $userData['typeInterface'] = $type_interface; |
|---|
| 162 | $html .= self::getNewUI($this->id, $userData); |
|---|
| 163 | $html .= "</div>\n"; |
|---|
| 164 | $html .= "</li>\n"; |
|---|
| 165 | } |
|---|
| 166 | $html .= "</ul>\n"; |
|---|
| 167 | |
|---|
| 168 | return Content :: getAdminUI($html, $title); |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | /** |
|---|
| 172 | * A short string representation of the content |
|---|
| 173 | * |
|---|
| 174 | * @return string Returns the content |
|---|
| 175 | */ |
|---|
| 176 | public function __toString($verbose = true) |
|---|
| 177 | { |
|---|
| 178 | return strip_tags($this->getString($verbose)); |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | /** |
|---|
| 182 | * Reloads the object from the database. |
|---|
| 183 | * |
|---|
| 184 | * Should normally be called after a set operation. |
|---|
| 185 | * |
|---|
| 186 | * This function is private because calling it from a subclass will call the |
|---|
| 187 | * constructor from the wrong scope |
|---|
| 188 | * |
|---|
| 189 | * @return void |
|---|
| 190 | |
|---|
| 191 | */ |
|---|
| 192 | private function refresh() |
|---|
| 193 | { |
|---|
| 194 | $this->__construct($this->id); |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | /* |
|---|
| 200 | * Local variables: |
|---|
| 201 | * tab-width: 4 |
|---|
| 202 | * c-basic-offset: 4 |
|---|
| 203 | * c-hanging-comment-ender-p: nil |
|---|
| 204 | * End: |
|---|
| 205 | */ |
|---|
| 206 | |
|---|
| 207 | |
|---|