| 86 | | /** |
|---|
| 87 | | * setValue() - sets configuration data |
|---|
| 88 | | * |
|---|
| 89 | | * @access public |
|---|
| 90 | | * @param string|boolean $key |
|---|
| 91 | | * @param mixed $value |
|---|
| 92 | | * @return mixed |
|---|
| 93 | | */ |
|---|
| 94 | | function setValue($key, $value) { |
|---|
| 95 | | $this->d[strtolower($key)] = $value; |
|---|
| 96 | | } |
|---|
| 97 | | |
|---|
| 98 | | /** |
|---|
| 99 | | * importDataByConstants() |
|---|
| 100 | | * |
|---|
| 101 | | * imports data from global constats starting with JLOG_ prefix |
|---|
| 102 | | * |
|---|
| 103 | | * @access public |
|---|
| 104 | | * @return void |
|---|
| 105 | | */ |
|---|
| 106 | | function importDataByConstants() { |
|---|
| 107 | | # no return |
|---|
| 108 | | // this is a blacklist of constats which are not to be written in settings.inc.php |
|---|
| 109 | | $search = array( |
|---|
| 110 | | 'JLOG_ADMIN', |
|---|
| 111 | | 'JLOG_DB_CONTENT', |
|---|
| 112 | | 'JLOG_DB_COMMENTS', |
|---|
| 113 | | 'JLOG_DB_CATASSIGN', |
|---|
| 114 | | 'JLOG_DB_CATEGORIES', |
|---|
| 115 | | 'JLOG_DB_ATTRIBUTES', |
|---|
| 116 | | 'JLOG_UPDATE', |
|---|
| 117 | | 'JLOG_LOGIN', |
|---|
| 118 | | 'JLOG_SOFTWARE_VERSION', |
|---|
| 119 | | 'JLOG_SOFTWARE_URL', |
|---|
| 120 | | 'JLOG_SOFTWARE_PHPV', |
|---|
| 121 | | 'JLOG_SOFTWARE_MYSQLV', |
|---|
| 122 | | 'JLOG_ADMIN_PASSWORD_AGAIN' |
|---|
| 123 | | ); |
|---|
| 124 | | |
|---|
| 125 | | // get all needed constants and put it into the class |
|---|
| 126 | | $constants = get_defined_constants(); |
|---|
| 127 | | foreach($constants as $key => $value) { |
|---|
| 128 | | if(!in_array($key, $search) AND strpos($key, "JLOG_") !== false) { |
|---|
| 129 | | $this->setValue($key, $value); |
|---|
| 130 | | } |
|---|
| 131 | | } |
|---|
| 132 | | } |
|---|
| 133 | | |
|---|
| 134 | | /** |
|---|
| 135 | | * importDataByArray() - sets configuration data |
|---|
| 136 | | * |
|---|
| 137 | | * Sets configuration data according to $d. If working in |
|---|
| 138 | | * non-exclusive mode (the default), $d is merged into the current |
|---|
| 139 | | * configuration, otherwise the current configuration is discared |
|---|
| 140 | | * and $d is set as the new configuration. |
|---|
| 141 | | * |
|---|
| 142 | | * @access public |
|---|
| 143 | | * @param array $d |
|---|
| 144 | | * @param boolean $exclusiv |
|---|
| 145 | | * @return void |
|---|
| 146 | | */ |
|---|
| 147 | | function importDataByArray($d = false, $exclusiv = false) { |
|---|
| 148 | | |
|---|
| 149 | | // get the data from users $d array and put it into the class |
|---|
| 150 | | if($d !== false) { |
|---|
| 151 | | if($exclusiv) $this->d = $d; |
|---|
| 152 | | else $this->d = array_merge($this->d, $d); |
|---|
| 153 | | } |
|---|
| 154 | | |
|---|
| 155 | | if(JLOG_ADMIN === true) { |
|---|
| 156 | | $this->d['jlog_db'] = JLOG_DB; |
|---|
| 157 | | $this->d['jlog_db_url'] = JLOG_DB_URL; |
|---|
| 158 | | $this->d['jlog_db_user'] = JLOG_DB_USER; |
|---|
| 159 | | $this->d['jlog_db_pwd'] = JLOG_DB_PWD; |
|---|
| 160 | | $this->d['jlog_db_prefix'] = JLOG_DB_PREFIX; |
|---|
| 161 | | $this->d['jlog_start_year'] = JLOG_START_YEAR; |
|---|
| 162 | | $this->d['jlog_path'] = JLOG_PATH; |
|---|
| 163 | | $this->d['jlog_basepath'] = JLOG_BASEPATH; |
|---|
| 164 | | if($this->d['jlog_admin_password'] == '') { |
|---|
| 165 | | $this->jlog_admin_password = JLOG_ADMIN_PASSWORD; |
|---|
| 166 | | } |
|---|
| 167 | | else { |
|---|
| 168 | | $this->d['jlog_admin_password'] = md5($this->d['jlog_admin_password']); |
|---|
| 169 | | $this->d['jlog_admin_password_again'] = md5($this->d['jlog_admin_password_again']); |
|---|
| 170 | | } |
|---|
| 171 | | $this->d['jlog_installed_version'] = JLOG_INSTALLED_VERSION; |
|---|
| 172 | | $this->d['jlog_installed_url'] = JLOG_INSTALLED_URL; |
|---|
| 173 | | $this->d['jlog_installed_phpv'] = JLOG_INSTALLED_PHPV; |
|---|
| 174 | | $this->d['jlog_installed_mysqlv'] = JLOG_INSTALLED_MYSQLV; |
|---|
| 175 | | } |
|---|
| 176 | | else { |
|---|
| 177 | | $this->d['jlog_admin_password'] = md5($this->d['jlog_admin_password']); |
|---|
| 178 | | $this->d['jlog_admin_password_again'] = md5($this->d['jlog_admin_password_again']); |
|---|
| 179 | | } |
|---|
| 180 | | |
|---|
| 181 | | if((defined('JLOG_SETUP') AND JLOG_SETUP === true)) |
|---|
| 182 | | { |
|---|
| 183 | | $this->d['jlog_installed_version'] = JLOG_SOFTWARE_VERSION; |
|---|
| 184 | | $this->d['jlog_installed_url'] = JLOG_SOFTWARE_URL; |
|---|
| 185 | | $this->d['jlog_installed_phpv'] = JLOG_SOFTWARE_PHPV; |
|---|
| 186 | | $this->d['jlog_installed_mysqlv'] = JLOG_SOFTWARE_MYSQLV; |
|---|
| 187 | | } |
|---|
| 188 | | } |
|---|
| 189 | | |
|---|
| 190 | | /** |
|---|
| 191 | | * importSuggestedData() - preallocates configuration data |
|---|
| 192 | | * |
|---|
| 193 | | * Initialises the configuration with useful settings during |
|---|
| 194 | | * the installation process. |
|---|
| 195 | | * |
|---|
| 196 | | * @access public |
|---|
| 197 | | * @return void |
|---|
| 198 | | */ |
|---|
| 199 | | function importSuggestedData() { |
|---|
| 200 | | |
|---|
| 201 | | // suggest some data for setup |
|---|
| 202 | | $this->d['jlog_path'] = $this->getSuggestPath(); |
|---|
| 203 | | $this->d['jlog_basepath'] = dirname(dirname( __FILE__ )).DIRECTORY_SEPARATOR; |
|---|
| 204 | | $date = getdate(); |
|---|
| 205 | | $this->d['jlog_start_year'] = $date['year']; |
|---|
| 206 | | $this->d['jlog_max_blog_orginal'] = 1; |
|---|
| 207 | | $this->d['jlog_max_blog_big'] = 4; |
|---|
| 208 | | $this->d['jlog_max_blog_small'] = 15; |
|---|
| 209 | | $this->d['jlog_sub_current'] = 6; |
|---|
| 210 | | $this->d['jlog_date'] = $this->l['date_format']; |
|---|
| 211 | | $this->d['jlog_date_comment'] = $this->l['date_format_comment']; |
|---|
| 212 | | $this->d['jlog_date_subcurrent'] = $this->l['date_format_subcurrent']; |
|---|
| 213 | | $this->d['jlog_info_by_comment'] = '1'; |
|---|
| 214 | | $this->d['jlog_db_url'] = 'localhost'; |
|---|
| 215 | | $this->d['jlog_db_prefix'] = 'jlog_'; |
|---|
| 216 | | $this->d['jlog_blogservices'] = 'http://rpc.pingomatic.com/'; |
|---|
| 217 | | $this->d['jlog_language'] = defined('JLOG_LANGUAGE') ? JLOG_LANGUAGE : 'de'; |
|---|
| 218 | | } |
|---|
| 219 | | |
|---|
| 220 | | |
|---|
| 221 | | /** |
|---|
| 222 | | * getSuggestPath() - generate a suggestion for JLOG_PATH |
|---|
| 223 | | * |
|---|
| 224 | | * @access private |
|---|
| 225 | | * @return string |
|---|
| 226 | | */ |
|---|
| 227 | | function getSuggestPath() { |
|---|
| 228 | | $host = empty($_SERVER['HTTP_HOST']) |
|---|
| 229 | | ? (empty($_SERVER['SERVER_NAME']) |
|---|
| 230 | | ? $_SERVER['SERVER_ADDR'] |
|---|
| 231 | | : $_SERVER['SERVER_NAME']) |
|---|
| 232 | | : $_SERVER['HTTP_HOST']; |
|---|
| 233 | | $proto = (empty($_SERVER['HTTPS']) OR $_SERVER['HTTPS'] == 'off') |
|---|
| 234 | | ? 'http' |
|---|
| 235 | | : 'https'; |
|---|
| 236 | | $port = $_SERVER['SERVER_PORT']; |
|---|
| 237 | | |
|---|
| 238 | | $uri = $proto . '://' . $host; |
|---|
| 239 | | if ((('http' == $proto) and (80 != $port)) |
|---|
| 240 | | or (('https' == $proto) and (443 != $port))) |
|---|
| 241 | | { |
|---|
| 242 | | $uri .= ':' . $port; |
|---|
| 243 | | } |
|---|
| 244 | | $uri .= dirname($_SERVER['SCRIPT_NAME']); |
|---|
| 245 | | |
|---|
| 246 | | return $uri; |
|---|
| 247 | | } |
|---|
| 248 | | |
|---|
| 249 | | /** |
|---|
| 250 | | * defaultValue() - gets a value of an array |
|---|
| 251 | | * |
|---|
| 252 | | * Look for index $key in the array $array and return |
|---|
| 253 | | * the corresponding value if it exists or the default |
|---|
| 254 | | * value $default if it doesn't. |
|---|
| 255 | | * |
|---|
| 256 | | * @access public |
|---|
| 257 | | * @param array $array |
|---|
| 258 | | * @param mixed $key |
|---|
| 259 | | * @param mixed $default |
|---|
| 260 | | * @return mixed |
|---|
| 261 | | */ |
|---|
| 262 | | function defaultValue($array, $key, $default = '') { |
|---|
| 263 | | |
|---|
| 264 | | if(isset($array[$key])) { |
|---|
| 265 | | return $array[$key]; |
|---|
| 266 | | } |
|---|
| 267 | | else { |
|---|
| 268 | | return $default; |
|---|
| 269 | | } |
|---|
| 270 | | } |
|---|
| 271 | | |
|---|
| 272 | | /** |
|---|
| 273 | | * form_output() - generates HTML output for formular |
|---|
| 274 | | * |
|---|
| 275 | | * @access public |
|---|
| 276 | | * @return string |
|---|
| 277 | | */ |
|---|
| 278 | | function form_output() { |
|---|
| 279 | | # returns the filled form |
|---|
| 280 | | |
|---|
| 281 | | $data = array_htmlspecialchars($this->d); |
|---|
| 282 | | |
|---|
| 283 | | if(isset($data['jlog_clean_url']) AND ($data['jlog_clean_url'] === 'true' OR $data['jlog_clean_url'] === '1')) |
|---|
| 284 | | $d['clean_url_yes'] = " checked='checked'"; |
|---|
| 285 | | else $d['clean_url_no'] = " checked='checked'"; |
|---|
| 286 | | |
|---|
| 287 | | if(isset($data['jlog_info_by_comment'])) $d['info_by_comment'] = " checked='checked'"; |
|---|
| 288 | | else $d['info_by_comment'] = ""; |
|---|
| 289 | | |
|---|
| 290 | | if(isset($data['jlog_bs_weblogs_com']) AND ($data['jlog_bs_weblogs_com'] === 'true' OR $data['jlog_bs_weblogs_com'] === '1')) |
|---|
| 291 | | $d['bs_weblogs_com'] = " checked='checked' "; |
|---|
| 292 | | |
|---|
| 293 | | if(defined("JLOG_ADMIN") AND JLOG_ADMIN === true) $admincenter_password = " ".$this->l['admin']['m_admin_password_admin']; |
|---|
| 294 | | else $admincenter_password = ''; |
|---|
| 295 | | |
|---|
| 296 | | // get available languages |
|---|
| 297 | | $dir = opendir(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'lang'); |
|---|
| 298 | | $languages = array(); |
|---|
| 299 | | while(($file = readdir($dir)) !== false) { |
|---|
| 300 | | if($file == '.' OR $file == '..') continue; |
|---|
| 301 | | if(!preg_match('/lang\.([a-zA-z0-9]+)\.inc\.php/', $file, $matches)) continue; |
|---|
| 302 | | $languages[] = $matches[1]; |
|---|
| 303 | | } |
|---|
| 304 | | |
|---|
| 305 | | // do the form |
|---|
| 306 | | $form = " |
|---|
| 307 | | <form action='".$_SERVER['SCRIPT_NAME']."' method='post'> |
|---|
| 308 | | <fieldset><legend>".$this->l['admin']['m_metadata']."</legend> |
|---|
| 309 | | <p><label for='language'>".$this->l['admin']['m_language']."</label><br />"; |
|---|
| 310 | | |
|---|
| 311 | | if(defined("JLOG_ADMIN") AND JLOG_ADMIN === true) $form .= add_session_id_input_tag(); |
|---|
| 312 | | |
|---|
| 313 | | $form .= "<select class='userdata' id='language' name='jlog_language'>"; |
|---|
| 314 | | foreach($languages as $lang) { |
|---|
| 315 | | $form .= "<option"; |
|---|
| 316 | | if((isset($_POST['jlog_language']) AND $lang = $_POST['jlog_language']) OR $lang == JLOG_LANGUAGE) |
|---|
| 317 | | $form .= " selected='selected'"; |
|---|
| 318 | | $form .= ">$lang</option>"; |
|---|
| 319 | | } |
|---|
| 320 | | |
|---|
| 321 | | $form .= "</select> |
|---|
| 322 | | </p> |
|---|
| 323 | | |
|---|
| 324 | | <p><label for='website'>".$this->l['admin']['m_website']."</label><br /> |
|---|
| 325 | | <input class='userdata' id='website' name='jlog_website' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_website')."' /></p> |
|---|
| 326 | | <p><label for='publisher'>".$this->l['admin']['m_publisher']."</label><br /> |
|---|
| 327 | | <input class='userdata' id='publisher' name='jlog_publisher' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_publisher')."' /></p> |
|---|
| 328 | | <p><label for='admin_password'>".$this->l['admin']['m_admin_password'].$admincenter_password."</label><br /> |
|---|
| 329 | | <input class='userdata' id='admin_password' name='jlog_admin_password' type='password' size='20' maxlength='255' /></p> |
|---|
| 330 | | <p><label for='admin_password_again'>".$this->l['admin']['m_admin_password_again'].$admincenter_password."</label><br /> |
|---|
| 331 | | <input class='userdata' id='admin_password_again' name='jlog_admin_password_again' type='password' size='20' maxlength='255' /></p> |
|---|
| 332 | | <p><label for='email'>".$this->l['admin']['m_email']."</label><br /> |
|---|
| 333 | | <input class='userdata' id='email' name='jlog_email' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_email')."' /></p> |
|---|
| 334 | | <p><label for='description'>".$this->l['admin']['m_description']."</label><br /> |
|---|
| 335 | | <textarea class='small' id='description' name='jlog_description' rows='2' cols='60'>".$this->defaultValue($data, 'jlog_description')."</textarea></p> |
|---|
| 336 | | </fieldset> |
|---|
| 337 | | |
|---|
| 338 | | <fieldset><legend>".$this->l['admin']['m_behavior']."</legend> |
|---|
| 339 | | <p><label>".$this->l['admin']['m_clean_url']."</label><br /> |
|---|
| 340 | | <input id='clean_url_yes' name='jlog_clean_url' type='radio' value='true'".$d['clean_url_yes']." /><label class='nobreak' for='clean_url_yes'>".$this->l['admin']['yes']."</label> |
|---|
| 341 | | <input id='clean_url_no' name='jlog_clean_url' type='radio' value='false'".$d['clean_url_no']." /><label class='nobreak' for='clean_url_no'>".$this->l['admin']['no']."</label></p> |
|---|
| 342 | | <p><label for='max_blog_orginal'>".$this->l['admin']['m_max_blog_orginal']."</label><br /> |
|---|
| 343 | | <input class='short' id='max_blog_orginal' name='jlog_max_blog_orginal' type='text' maxlength='3' size='3' value='".$this->defaultValue($data, 'jlog_max_blog_orginal')."' /></p> |
|---|
| 344 | | <p><label for='max_blog_big'>".$this->l['admin']['m_max_blog_big']."</label><br /> |
|---|
| 345 | | <input class='short' id='max_blog_big' name='jlog_max_blog_big' type='text' size='3' maxlength='3' value='".$this->defaultValue($data, 'jlog_max_blog_big')."' /></p> |
|---|
| 346 | | <p><label for='max_blog_small'>".$this->l['admin']['m_max_blog_small']."</label><br /> |
|---|
| 347 | | <input class='short' id='max_blog_small' name='jlog_max_blog_small' type='text' size='3' maxlength='3' value='".$this->defaultValue($data, 'jlog_max_blog_small')."' /></p> |
|---|
| 348 | | <p><label for='sub_current'>".$this->l['admin']['m_sub_current']."</label><br /> |
|---|
| 349 | | <input class='short' id='sub_current' name='jlog_sub_current' type='text' size='3' maxlength='3' value='".$this->defaultValue($data, 'jlog_sub_current')."' /></p> |
|---|
| 350 | | <p><input id='info_by_comment' name='jlog_info_by_comment' type='checkbox' value='true'".$d['info_by_comment']."/> <label for='info_by_comment' class='nobreak'>".$this->l['admin']['m_info_by_comment']."</label></p> |
|---|
| 351 | | <p><label for='date'>".$this->l['admin']['m_date']."</label></p> |
|---|
| 352 | | <p><input class='userdata' id='date' name='jlog_date' type='text' value='".$this->defaultValue($data, 'jlog_date')."' size='20' /> <label for='date' class='nobreak'>".$this->l['admin']['m_date_posting']."</label></p> |
|---|
| 353 | | <p><input class='userdata' id='date_comment' name='jlog_date_comment' type='text' value='".$this->defaultValue($data, 'jlog_date_comment')."' size='20' /> <label for='date_comment' class='nobreak'>".$this->l['admin']['m_date_comment']."</label></p> |
|---|
| 354 | | <p><input class='userdata' id='date_subcurrent' name='jlog_date_subcurrent' type='text' value='".$this->defaultValue($data, 'jlog_date_subcurrent')."' size='20' /> <label for='date_subcurrent' class='nobreak'>".$this->l['admin']['m_date_subcurrent']."</label></p> |
|---|
| 355 | | <p><label for='blogservices'>".$this->l['admin']['m_bs']."</label></p> |
|---|
| 356 | | <p><textarea class='small' id='blogservices' name='jlog_blogservices' rows='2' cols='60'>".$this->defaultValue($data, 'jlog_blogservices')."</textarea></p> |
|---|
| 357 | | </fieldset> |
|---|
| 358 | | "; |
|---|
| 359 | | |
|---|
| 360 | | if(defined('JLOG_SETUP') AND JLOG_SETUP === true) { |
|---|
| 361 | | $form .= |
|---|
| 362 | | " |
|---|
| 363 | | <fieldset><legend>".$this->l['admin']['m_database']."</legend> |
|---|
| 364 | | <p><label for='db'>".$this->l['admin']['m_db']."</label><br /> |
|---|
| 365 | | <input class='userdata' id='db' name='jlog_db' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db')."' /></p> |
|---|
| 366 | | <p><label for='db_url'>".$this->l['admin']['m_db_url']."</label><br /> |
|---|
| 367 | | <input class='userdata' id='db_url' name='jlog_db_url' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db_url')."' /></p> |
|---|
| 368 | | <p><label for='db_user'>".$this->l['admin']['m_db_user']."</label><br /> |
|---|
| 369 | | <input class='userdata' id='db_user' name='jlog_db_user' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db_user')."' /></p> |
|---|
| 370 | | <p><label for='db_pwd'>".$this->l['admin']['m_db_pwd']."</label><br /> |
|---|
| 371 | | <input class='userdata' id='db_pwd' name='jlog_db_pwd' type='password' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db_pwd')."' /></p> |
|---|
| 372 | | <p><label for='db_prefix'>".$this->l['admin']['m_db_prefix']."</label><br /> |
|---|
| 373 | | <input class='userdata' id='db_prefix' name='jlog_db_prefix' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db_prefix')."' /> |
|---|
| 374 | | <input name='jlog_start_year' type='hidden' value='".$this->defaultValue($data, 'jlog_start_year', date("Y"))."' /></p> |
|---|
| 375 | | <input name='jlog_path' type='hidden' value='".$this->defaultValue($data, 'jlog_path')."' /> |
|---|
| 376 | | <input name='jlog_basepath' type='hidden' value='".$this->defaultValue($data, 'jlog_basepath')."' /> |
|---|
| 377 | | </fieldset> |
|---|
| 378 | | "; |
|---|
| 379 | | } |
|---|
| 380 | | |
|---|
| 381 | | $form .= " |
|---|
| 382 | | <p><input type='submit' class='button' value='".$this->l['admin']['submit']."' /></p> |
|---|
| 383 | | </form> |
|---|
| 384 | | "; |
|---|
| 385 | | |
|---|
| 386 | | return $form; |
|---|
| 387 | | } |
|---|
| 388 | | |
|---|
| 389 | | /** |
|---|
| 390 | | * validate() - validates the current configuration |
|---|
| 391 | | * |
|---|
| 392 | | * If the current configuration is valid, an empty array is returned. |
|---|
| 393 | | * Otherwise the returned array containes all errors, described in the |
|---|
| 394 | | * current language. |
|---|
| 395 | | * |
|---|
| 396 | | * @access public |
|---|
| 397 | | * @return array |
|---|
| 398 | | */ |
|---|
| 399 | | function validate() { |
|---|
| 400 | | # if everything validate then return true |
|---|
| 401 | | # otherwise return the $errors array |
|---|
| 402 | | |
|---|
| 403 | | $errors = array(); |
|---|
| 404 | | |
|---|
| 405 | | // paths |
|---|
| 406 | | if(empty($this->d['jlog_path']) OR (check_url($this->d['jlog_path'], array ('http')) === false)) $errors[] = $this->l['admin']['e_path']; |
|---|
| 407 | | if(empty($this->d['jlog_basepath']) OR !is_dir($this->d['jlog_basepath'])) $errors[] = $this->l['admin']['e_basepath']; |
|---|
| 408 | | if($this->d['jlog_clean_url'] != 'true') $this->d['jlog_clean_url'] = 'false'; |
|---|
| 409 | | // metadata |
|---|
| 410 | | if(empty($this->d['jlog_website'])) $errors[] = $this->l['admin']['e_website']; |
|---|
| 411 | | if(empty($this->d['jlog_publisher'])) $errors[] = $this->l['admin']['e_publisher']; |
|---|
| 412 | | if(defined('JLOG_SETUP') AND JLOG_SETUP) { |
|---|
| 413 | | if($this->d['jlog_admin_password'] == md5("")) |
|---|
| 414 | | $errors[] = $this->l['admin']['e_admin_password']; |
|---|
| 415 | | elseif($this->d['jlog_admin_password'] !== $this->d['jlog_admin_password_again']) |
|---|
| 416 | | $errors[] = $this->l['admin']['e_admin_password_again']; |
|---|
| 417 | | } |
|---|
| 418 | | elseif(!empty($this->d['jlog_admin_password']) AND $this->d['jlog_admin_password'] !== $this->d['jlog_admin_password_again']) { |
|---|
| 419 | | $errors[] = $this->l['admin']['e_admin_password_again']; |
|---|
| 420 | | } |
|---|
| 421 | | // Fix of bug #148 |
|---|
| 422 | | if(isset($this->d['jlog_admin_password_again'])) |
|---|
| 423 | | unset($this->d['jlog_admin_password_again']); |
|---|
| 424 | | |
|---|
| 425 | | if(empty($this->d['jlog_email']) OR !strpos($this->d['jlog_email'], '@')) $errors[] = $this->l['admin']['e_email']; |
|---|
| 426 | | if(empty($this->d['jlog_description'])) $errors[] = $this->l['admin']['e_description']; |
|---|
| 427 | | // behavour |
|---|
| 428 | | if(!is_numeric($this->d['jlog_max_blog_orginal']) OR intval($this->d['jlog_max_blog_orginal']) < 0) $errors[] = $this->l['admin']['e_max_blog_orginal']; |
|---|
| 429 | | if(!is_numeric($this->d['jlog_max_blog_big']) OR intval($this->d['jlog_max_blog_big']) < 0) $errors[] = $this->l['admin']['e_max_blog_big']; |
|---|
| 430 | | if(!is_numeric($this->d['jlog_max_blog_small']) OR intval($this->d['jlog_max_blog_small']) < 0) $errors[] = $this->l['admin']['e_max_blog_small']; |
|---|
| 431 | | if(!is_numeric($this->d['jlog_sub_current']) OR intval($this->d['jlog_sub_current']) < 0) $errors[] = $this->l['admin']['e_sub_current']; |
|---|
| 432 | | if(!is_numeric($this->d['jlog_start_year'])) $errors[] = $this->l['admin']['e_start_year']; |
|---|
| 433 | | if($this->d['jlog_info_by_comment'] != 'true') $this->d['jlog_info_by_comment'] = 'false'; |
|---|
| 434 | | // database |
|---|
| 435 | | if(empty($this->d['jlog_db'])) $errors[] = $this->l['admin']['e_db']; |
|---|
| 436 | | if(empty($this->d['jlog_db_url'])) $errors[] = $this->l['admin']['e_db_url']; |
|---|
| 437 | | // Fix of bug #196, prefix should only contain alphanumeric values, can be empty! |
|---|
| 438 | | if(!preg_match('/^[a-zA-Z0-9_]*$/', $this->d['jlog_db_prefix'])) $errors[] = $this->l['admin']['e_db_prefix']; |
|---|
| 439 | | |
|---|
| 440 | | return $errors; |
|---|
| 441 | | } |
|---|
| 442 | | |
|---|
| 443 | | /** |
|---|
| 444 | | * do_settings() - save configuration |
|---|
| 445 | | * |
|---|
| 446 | | * Saves the current configuration to the settings.inc.php file |
|---|
| 447 | | * in the personal folder. Return an empty array if configuration |
|---|
| 448 | | * was saved successfully, or an array containing descriptions of |
|---|
| 449 | | * the errors that occured otherwise. |
|---|
| 450 | | * |
|---|
| 451 | | * @access public |
|---|
| 452 | | * @return array |
|---|
| 453 | | */ |
|---|
| 454 | | function do_settings() { |
|---|
| 455 | | # if it's all done return true |
|---|
| 456 | | # otherwise return the $errors array |
|---|
| 457 | | |
|---|
| 458 | | $errors = array(); |
|---|
| 459 | | |
|---|
| 460 | | // if there is no new password set the old |
|---|
| 461 | | if(JLOG_ADMIN AND empty($this->d['jlog_admin_password'])) $this->d['jlog_admin_password'] = JLOG_ADMIN_PASSWORD; |
|---|
| 462 | | |
|---|
| 463 | | // remove slashes at the end of JLOG_PATH if present |
|---|
| 464 | | $this->d['jlog_path'] = rtrim($this->d['jlog_path'], '/'); |
|---|
| 465 | | // make shure JLOG_BASEPATH ends with a slash!! |
|---|
| 466 | | $this->d['jlog_basepath'] = rtrim($this->d['jlog_basepath'], '/\\') . DIRECTORY_SEPARATOR; |
|---|
| 467 | | |
|---|
| 468 | | // no quotes for bolean and numbers |
|---|
| 469 | | $no_quotes = array ( |
|---|
| 470 | | 'jlog_clean_url' => 'bool', |
|---|
| 471 | | 'jlog_max_blog_orginal' => 'int', |
|---|
| 472 | | 'jlog_max_blog_big' => 'int', |
|---|
| 473 | | 'jlog_max_blog_small' => 'int', |
|---|
| 474 | | 'jlog_sub_current' => 'int', |
|---|
| 475 | | 'jlog_start_year' => 'int', |
|---|
| 476 | | 'jlog_info_by_comment' => 'bool' |
|---|
| 477 | | ); |
|---|
| 478 | | |
|---|
| 479 | | // serialize data to file format |
|---|
| 480 | | $file_content = '<?php' . PHP_EOL . '// generated at ' . date('Y-m-d, h:i:s') . PHP_EOL; |
|---|
| 481 | | |
|---|
| 482 | | foreach($this->d as $key => $value) { |
|---|
| 483 | | $output = ''; |
|---|
| 484 | | if(isset($no_quotes[$key])) { |
|---|
| 485 | | // boolean values |
|---|
| 486 | | if($no_quotes[$key] == 'bool') { |
|---|
| 487 | | if($value == 'true' OR $value === true) $output = 'true'; |
|---|
| 488 | | else $output = 'false'; |
|---|
| 489 | | } |
|---|
| 490 | | // numeric values |
|---|
| | 86 | /** |
|---|
| | 87 | * setValue() - sets configuration data |
|---|
| | 88 | * |
|---|
| | 89 | * @access public |
|---|
| | 90 | * @param string|boolean $key |
|---|
| | 91 | * @param mixed $value |
|---|
| | 92 | * @return mixed |
|---|
| | 93 | */ |
|---|
| | 94 | function setValue($key, $value) { |
|---|
| | 95 | $this->d[strtolower($key)] = $value; |
|---|
| | 96 | } |
|---|
| | 97 | |
|---|
| | 98 | /** |
|---|
| | 99 | * importDataByConstants() |
|---|
| | 100 | * |
|---|
| | 101 | * imports data from global constats starting with JLOG_ prefix |
|---|
| | 102 | * |
|---|
| | 103 | * @access public |
|---|
| | 104 | * @return void |
|---|
| | 105 | */ |
|---|
| | 106 | function importDataByConstants() { |
|---|
| | 107 | # no return |
|---|
| | 108 | // this is a blacklist of constats which are not to be written in settings.inc.php |
|---|
| | 109 | $search = array( |
|---|
| | 110 | 'JLOG_ADMIN', |
|---|
| | 111 | 'JLOG_DB_CONTENT', |
|---|
| | 112 | 'JLOG_DB_COMMENTS', |
|---|
| | 113 | 'JLOG_DB_CATASSIGN', |
|---|
| | 114 | 'JLOG_DB_CATEGORIES', |
|---|
| | 115 | 'JLOG_DB_ATTRIBUTES', |
|---|
| | 116 | 'JLOG_UPDATE', |
|---|
| | 117 | 'JLOG_LOGIN', |
|---|
| | 118 | 'JLOG_SOFTWARE_VERSION', |
|---|
| | 119 | 'JLOG_SOFTWARE_URL', |
|---|
| | 120 | 'JLOG_SOFTWARE_PHPV', |
|---|
| | 121 | 'JLOG_SOFTWARE_MYSQLV', |
|---|
| | 122 | 'JLOG_ADMIN_PASSWORD_AGAIN' |
|---|
| | 123 | ); |
|---|
| | 124 | |
|---|
| | 125 | // get all needed constants and put it into the class |
|---|
| | 126 | $constants = get_defined_constants(); |
|---|
| | 127 | foreach($constants as $key => $value) { |
|---|
| | 128 | if(!in_array($key, $search) AND strpos($key, "JLOG_") !== false) { |
|---|
| | 129 | $this->setValue($key, $value); |
|---|
| | 130 | } |
|---|
| | 131 | } |
|---|
| | 132 | } |
|---|
| | 133 | |
|---|
| | 134 | /** |
|---|
| | 135 | * importDataByArray() - sets configuration data |
|---|
| | 136 | * |
|---|
| | 137 | * Sets configuration data according to $d. If working in |
|---|
| | 138 | * non-exclusive mode (the default), $d is merged into the current |
|---|
| | 139 | * configuration, otherwise the current configuration is discared |
|---|
| | 140 | * and $d is set as the new configuration. |
|---|
| | 141 | * |
|---|
| | 142 | * @access public |
|---|
| | 143 | * @param array $d |
|---|
| | 144 | * @param boolean $exclusiv |
|---|
| | 145 | * @return void |
|---|
| | 146 | */ |
|---|
| | 147 | function importDataByArray($d = false, $exclusiv = false) { |
|---|
| | 148 | |
|---|
| | 149 | // get the data from users $d array and put it into the class |
|---|
| | 150 | if($d !== false) { |
|---|
| | 151 | if($exclusiv) $this->d = $d; |
|---|
| | 152 | else $this->d = array_merge($this->d, $d); |
|---|
| | 153 | } |
|---|
| | 154 | |
|---|
| | 155 | if(JLOG_ADMIN === true) { |
|---|
| | 156 | $this->d['jlog_db'] = JLOG_DB; |
|---|
| | 157 | $this->d['jlog_db_url'] = JLOG_DB_URL; |
|---|
| | 158 | $this->d['jlog_db_user'] = JLOG_DB_USER; |
|---|
| | 159 | $this->d['jlog_db_pwd'] = JLOG_DB_PWD; |
|---|
| | 160 | $this->d['jlog_db_prefix'] = JLOG_DB_PREFIX; |
|---|
| | 161 | $this->d['jlog_start_year'] = JLOG_START_YEAR; |
|---|
| | 162 | $this->d['jlog_path'] = JLOG_PATH; |
|---|
| | 163 | $this->d['jlog_basepath'] = JLOG_BASEPATH; |
|---|
| | 164 | if($this->d['jlog_admin_password'] == '') { |
|---|
| | 165 | $this->jlog_admin_password = JLOG_ADMIN_PASSWORD; |
|---|
| | 166 | } |
|---|
| | 167 | else { |
|---|
| | 168 | $this->d['jlog_admin_password'] = md5($this->d['jlog_admin_password']); |
|---|
| | 169 | $this->d['jlog_admin_password_again'] = md5($this->d['jlog_admin_password_again']); |
|---|
| | 170 | } |
|---|
| | 171 | $this->d['jlog_installed_version'] = JLOG_INSTALLED_VERSION; |
|---|
| | 172 | $this->d['jlog_installed_url'] = JLOG_INSTALLED_URL; |
|---|
| | 173 | $this->d['jlog_installed_phpv'] = JLOG_INSTALLED_PHPV; |
|---|
| | 174 | $this->d['jlog_installed_mysqlv'] = JLOG_INSTALLED_MYSQLV; |
|---|
| | 175 | } |
|---|
| 492 | | $output = (int) $value; |
|---|
| 493 | | } |
|---|
| 494 | | } |
|---|
| 495 | | // string values |
|---|
| 496 | | else { |
|---|
| 497 | | $output = '\'' . $this->escapeForPhp($value) . '\''; |
|---|
| 498 | | } |
|---|
| 499 | | $key = '\'' . $this->escapeForPhp(strtoupper($key)) . '\''; |
|---|
| 500 | | $file_content .= 'define(' . $key . ', ' . $output . ');' . PHP_EOL; |
|---|
| 501 | | } |
|---|
| 502 | | |
|---|
| 503 | | $file_content .= '// eof'; |
|---|
| 504 | | |
|---|
| 505 | | // write to settings.inc.php |
|---|
| 506 | | if(!$handle = fopen(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."settings.inc.php", "w")) $errors[] = $this->l['admin']['can_not_open']." /personal/settings.inc.php"; |
|---|
| 507 | | if(!fwrite($handle, $file_content)) $errors[] = $this->l['admin']['can_not_write']." /personal/settings.inc.php"; |
|---|
| 508 | | fclose($handle); |
|---|
| 509 | | |
|---|
| 510 | | return $errors; |
|---|
| 511 | | } |
|---|
| | 177 | $this->d['jlog_admin_password'] = md5($this->d['jlog_admin_password']); |
|---|
| | 178 | $this->d['jlog_admin_password_again'] = md5($this->d['jlog_admin_password_again']); |
|---|
| | 179 | } |
|---|
| | 180 | |
|---|
| | 181 | if((defined('JLOG_SETUP') AND JLOG_SETUP === true)) |
|---|
| | 182 | { |
|---|
| | 183 | $this->d['jlog_installed_version'] = JLOG_SOFTWARE_VERSION; |
|---|
| | 184 | $this->d['jlog_installed_url'] = JLOG_SOFTWARE_URL; |
|---|
| | 185 | $this->d['jlog_installed_phpv'] = JLOG_SOFTWARE_PHPV; |
|---|
| | 186 | $this->d['jlog_installed_mysqlv'] = JLOG_SOFTWARE_MYSQLV; |
|---|
| | 187 | } |
|---|
| | 188 | } |
|---|
| | 189 | |
|---|
| | 190 | /** |
|---|
| | 191 | * importSuggestedData() - preallocates configuration data |
|---|
| | 192 | * |
|---|
| | 193 | * Initialises the configuration with useful settings during |
|---|
| | 194 | * the installation process. |
|---|
| | 195 | * |
|---|
| | 196 | * @access public |
|---|
| | 197 | * @return void |
|---|
| | 198 | */ |
|---|
| | 199 | function importSuggestedData() { |
|---|
| | 200 | // suggest some data for setup |
|---|
| | 201 | $this->setValue('jlog_path', $this->getSuggestPath()); |
|---|
| | 202 | $this->setValue('jlog_basepath', dirname(dirname( __FILE__ )).DIRECTORY_SEPARATOR); |
|---|
| | 203 | $date = getdate(); |
|---|
| | 204 | $this->setValue('jlog_start_year', $date['year']); |
|---|
| | 205 | $this->setValue('jlog_max_blog_orginal', 1); |
|---|
| | 206 | $this->setValue('jlog_max_blog_big', 4); |
|---|
| | 207 | $this->setValue('jlog_max_blog_small', 15); |
|---|
| | 208 | $this->setValue('jlog_sub_current', 6); |
|---|
| | 209 | $this->setValue('jlog_date', $this->l['date_format']); |
|---|
| | 210 | $this->setValue('jlog_date_comment', $this->l['date_format_comment']); |
|---|
| | 211 | $this->setValue('jlog_date_subcurrent', $this->l['date_format_subcurrent']); |
|---|
| | 212 | $this->setValue('jlog_info_by_comment', true); |
|---|
| | 213 | $this->setValue('jlog_db_url', 'localhost'); |
|---|
| | 214 | $this->setValue('jlog_db_prefix', 'jlog_'); |
|---|
| | 215 | $this->setValue('jlog_blogservices', 'http://rpc.pingomatic.com/'); |
|---|
| | 216 | $this->setValue('jlog_language', (defined('JLOG_LANGUAGE') ? JLOG_LANGUAGE : 'de')); |
|---|
| | 217 | } |
|---|
| | 218 | |
|---|
| | 219 | |
|---|
| | 220 | /** |
|---|
| | 221 | * getSuggestPath() - generate a suggestion for JLOG_PATH |
|---|
| | 222 | * |
|---|
| | 223 | * @access private |
|---|
| | 224 | * @return string |
|---|
| | 225 | */ |
|---|
| | 226 | function getSuggestPath() { |
|---|
| | 227 | $host = empty($_SERVER['HTTP_HOST']) |
|---|
| | 228 | ? (empty($_SERVER['SERVER_NAME']) |
|---|
| | 229 | ? $_SERVER['SERVER_ADDR'] |
|---|
| | 230 | : $_SERVER['SERVER_NAME']) |
|---|
| | 231 | : $_SERVER['HTTP_HOST']; |
|---|
| | 232 | $proto = (empty($_SERVER['HTTPS']) OR $_SERVER['HTTPS'] == 'off') |
|---|
| | 233 | ? 'http' |
|---|
| | 234 | : 'https'; |
|---|
| | 235 | $port = $_SERVER['SERVER_PORT']; |
|---|
| | 236 | |
|---|
| | 237 | $uri = $proto . '://' . $host; |
|---|
| | 238 | if ((('http' == $proto) and (80 != $port)) |
|---|
| | 239 | or (('https' == $proto) and (443 != $port))) |
|---|
| | 240 | { |
|---|
| | 241 | $uri .= ':' . $port; |
|---|
| | 242 | } |
|---|
| | 243 | $uri .= dirname($_SERVER['SCRIPT_NAME']); |
|---|
| | 244 | |
|---|
| | 245 | return $uri; |
|---|
| | 246 | } |
|---|
| | 247 | |
|---|
| | 248 | /** |
|---|
| | 249 | * defaultValue() - gets a value of an array |
|---|
| | 250 | * |
|---|
| | 251 | * Look for index $key in the array $array and return |
|---|
| | 252 | * the corresponding value if it exists or the default |
|---|
| | 253 | * value $default if it doesn't. |
|---|
| | 254 | * |
|---|
| | 255 | * @access public |
|---|
| | 256 | * @param array $array |
|---|
| | 257 | * @param mixed $key |
|---|
| | 258 | * @param mixed $default |
|---|
| | 259 | * @return mixed |
|---|
| | 260 | */ |
|---|
| | 261 | function defaultValue($array, $key, $default = '') { |
|---|
| | 262 | if(isset($array[$key])) { |
|---|
| | 263 | return $array[$key]; |
|---|
| | 264 | } |
|---|
| | 265 | else { |
|---|
| | 266 | return $default; |
|---|
| | 267 | } |
|---|
| | 268 | } |
|---|
| | 269 | |
|---|
| | 270 | /** |
|---|
| | 271 | * form_output() - generates HTML output for formular |
|---|
| | 272 | * |
|---|
| | 273 | * @access public |
|---|
| | 274 | * @return string |
|---|
| | 275 | */ |
|---|
| | 276 | function form_output() { |
|---|
| | 277 | # returns the filled form |
|---|
| | 278 | |
|---|
| | 279 | $data = array_htmlspecialchars($this->d); |
|---|
| | 280 | |
|---|
| | 281 | if(isset($data['jlog_clean_url']) AND ($data['jlog_clean_url'] === 'true' OR $data['jlog_clean_url'] === '1')) |
|---|
| | 282 | $d['clean_url_yes'] = " checked='checked'"; |
|---|
| | 283 | else $d['clean_url_no'] = " checked='checked'"; |
|---|
| | 284 | |
|---|
| | 285 | if(isset($data['jlog_info_by_comment'])) $d['info_by_comment'] = " checked='checked'"; |
|---|
| | 286 | else $d['info_by_comment'] = ""; |
|---|
| | 287 | |
|---|
| | 288 | if(isset($data['jlog_bs_weblogs_com']) AND ($data['jlog_bs_weblogs_com'] === 'true' OR $data['jlog_bs_weblogs_com'] === '1')) |
|---|
| | 289 | $d['bs_weblogs_com'] = " checked='checked' "; |
|---|
| | 290 | |
|---|
| | 291 | if(defined("JLOG_ADMIN") AND JLOG_ADMIN === true) $admincenter_password = " ".$this->l['admin']['m_admin_password_admin']; |
|---|
| | 292 | else $admincenter_password = ''; |
|---|
| | 293 | |
|---|
| | 294 | // get available languages |
|---|
| | 295 | $dir = opendir(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'lang'); |
|---|
| | 296 | $languages = array(); |
|---|
| | 297 | while(($file = readdir($dir)) !== false) { |
|---|
| | 298 | if($file == '.' OR $file == '..') continue; |
|---|
| | 299 | if(!preg_match('/lang\.([a-zA-z0-9]+)\.inc\.php/', $file, $matches)) continue; |
|---|
| | 300 | $languages[] = $matches[1]; |
|---|
| | 301 | } |
|---|
| | 302 | |
|---|
| | 303 | // do the form |
|---|
| | 304 | $form = " |
|---|
| | 305 | <form action='".$_SERVER['SCRIPT_NAME']."' method='post'> |
|---|
| | 306 | <fieldset><legend>".$this->l['admin']['m_metadata']."</legend> |
|---|
| | 307 | <p><label for='language'>".$this->l['admin']['m_language']."</label><br />"; |
|---|
| | 308 | |
|---|
| | 309 | if(defined("JLOG_ADMIN") AND JLOG_ADMIN === true) $form .= add_session_id_input_tag(); |
|---|
| | 310 | |
|---|
| | 311 | $form .= "<select class='userdata' id='language' name='jlog_language'>"; |
|---|
| | 312 | foreach($languages as $lang) { |
|---|
| | 313 | $form .= "<option"; |
|---|
| | 314 | if((isset($_POST['jlog_language']) AND $lang = $_POST['jlog_language']) OR $lang == JLOG_LANGUAGE) |
|---|
| | 315 | $form .= " selected='selected'"; |
|---|
| | 316 | $form .= ">$lang</option>"; |
|---|
| | 317 | } |
|---|
| | 318 | |
|---|
| | 319 | $form .= "</select> |
|---|
| | 320 | </p> |
|---|
| | 321 | |
|---|
| | 322 | <p><label for='website'>".$this->l['admin']['m_website']."</label><br /> |
|---|
| | 323 | <input class='userdata' id='website' name='jlog_website' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_website')."' /></p> |
|---|
| | 324 | <p><label for='publisher'>".$this->l['admin']['m_publisher']."</label><br /> |
|---|
| | 325 | <input class='userdata' id='publisher' name='jlog_publisher' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_publisher')."' /></p> |
|---|
| | 326 | <p><label for='admin_password'>".$this->l['admin']['m_admin_password'].$admincenter_password."</label><br /> |
|---|
| | 327 | <input class='userdata' id='admin_password' name='jlog_admin_password' type='password' size='20' maxlength='255' /></p> |
|---|
| | 328 | <p><label for='admin_password_again'>".$this->l['admin']['m_admin_password_again'].$admincenter_password."</label><br /> |
|---|
| | 329 | <input class='userdata' id='admin_password_again' name='jlog_admin_password_again' type='password' size='20' maxlength='255' /></p> |
|---|
| | 330 | <p><label for='email'>".$this->l['admin']['m_email']."</label><br /> |
|---|
| | 331 | <input class='userdata' id='email' name='jlog_email' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_email')."' /></p> |
|---|
| | 332 | <p><label for='description'>".$this->l['admin']['m_description']."</label><br /> |
|---|
| | 333 | <textarea class='small' id='description' name='jlog_description' rows='2' cols='60'>".$this->defaultValue($data, 'jlog_description')."</textarea></p> |
|---|
| | 334 | </fieldset> |
|---|
| | 335 | |
|---|
| | 336 | <fieldset><legend>".$this->l['admin']['m_behavior']."</legend> |
|---|
| | 337 | <p><label>".$this->l['admin']['m_clean_url']."</label><br /> |
|---|
| | 338 | <input id='clean_url_yes' name='jlog_clean_url' type='radio' value='true'".$d['clean_url_yes']." /><label class='nobreak' for='clean_url_yes'>".$this->l['admin']['yes']."</label> |
|---|
| | 339 | <input id='clean_url_no' name='jlog_clean_url' type='radio' value='false'".$d['clean_url_no']." /><label class='nobreak' for='clean_url_no'>".$this->l['admin']['no']."</label></p> |
|---|
| | 340 | <p><label for='max_blog_orginal'>".$this->l['admin']['m_max_blog_orginal']."</label><br /> |
|---|
| | 341 | <input class='short' id='max_blog_orginal' name='jlog_max_blog_orginal' type='text' maxlength='3' size='3' value='".$this->defaultValue($data, 'jlog_max_blog_orginal')."' /></p> |
|---|
| | 342 | <p><label for='max_blog_big'>".$this->l['admin']['m_max_blog_big']."</label><br /> |
|---|
| | 343 | <input class='short' id='max_blog_big' name='jlog_max_blog_big' type='text' size='3' maxlength='3' value='".$this->defaultValue($data, 'jlog_max_blog_big')."' /></p> |
|---|
| | 344 | <p><label for='max_blog_small'>".$this->l['admin']['m_max_blog_small']."</label><br /> |
|---|
| | 345 | <input class='short' id='max_blog_small' name='jlog_max_blog_small' type='text' size='3' maxlength='3' value='".$this->defaultValue($data, 'jlog_max_blog_small')."' /></p> |
|---|
| | 346 | <p><label for='sub_current'>".$this->l['admin']['m_sub_current']."</label><br /> |
|---|
| | 347 | <input class='short' id='sub_current' name='jlog_sub_current' type='text' size='3' maxlength='3' value='".$this->defaultValue($data, 'jlog_sub_current')."' /></p> |
|---|
| | 348 | <p><input id='info_by_comment' name='jlog_info_by_comment' type='checkbox' value='true'".$d['info_by_comment']."/> <label for='info_by_comment' class='nobreak'>".$this->l['admin']['m_info_by_comment']."</label></p> |
|---|
| | 349 | <p><label for='date'>".$this->l['admin']['m_date']."</label></p> |
|---|
| | 350 | <p><input class='userdata' id='date' name='jlog_date' type='text' value='".$this->defaultValue($data, 'jlog_date')."' size='20' /> <label for='date' class='nobreak'>".$this->l['admin']['m_date_posting']."</label></p> |
|---|
| | 351 | <p><input class='userdata' id='date_comment' name='jlog_date_comment' type='text' value='".$this->defaultValue($data, 'jlog_date_comment')."' size='20' /> <label for='date_comment' class='nobreak'>".$this->l['admin']['m_date_comment']."</label></p> |
|---|
| | 352 | <p><input class='userdata' id='date_subcurrent' name='jlog_date_subcurrent' type='text' value='".$this->defaultValue($data, 'jlog_date_subcurrent')."' size='20' /> <label for='date_subcurrent' class='nobreak'>".$this->l['admin']['m_date_subcurrent']."</label></p> |
|---|
| | 353 | <p><label for='blogservices'>".$this->l['admin']['m_bs']."</label></p> |
|---|
| | 354 | <p><textarea class='small' id='blogservices' name='jlog_blogservices' rows='2' cols='60'>".$this->defaultValue($data, 'jlog_blogservices')."</textarea></p> |
|---|
| | 355 | </fieldset> |
|---|
| | 356 | "; |
|---|
| | 357 | |
|---|
| | 358 | if(defined('JLOG_SETUP') AND JLOG_SETUP === true) { |
|---|
| | 359 | $form .= |
|---|
| | 360 | " |
|---|
| | 361 | <fieldset><legend>".$this->l['admin']['m_database']."</legend> |
|---|
| | 362 | <p><label for='db'>".$this->l['admin']['m_db']."</label><br /> |
|---|
| | 363 | <input class='userdata' id='db' name='jlog_db' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db')."' /></p> |
|---|
| | 364 | <p><label for='db_url'>".$this->l['admin']['m_db_url']."</label><br /> |
|---|
| | 365 | <input class='userdata' id='db_url' name='jlog_db_url' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db_url')."' /></p> |
|---|
| | 366 | <p><label for='db_user'>".$this->l['admin']['m_db_user']."</label><br /> |
|---|
| | 367 | <input class='userdata' id='db_user' name='jlog_db_user' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db_user')."' /></p> |
|---|
| | 368 | <p><label for='db_pwd'>".$this->l['admin']['m_db_pwd']."</label><br /> |
|---|
| | 369 | <input class='userdata' id='db_pwd' name='jlog_db_pwd' type='password' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db_pwd')."' /></p> |
|---|
| | 370 | <p><label for='db_prefix'>".$this->l['admin']['m_db_prefix']."</label><br /> |
|---|
| | 371 | <input class='userdata' id='db_prefix' name='jlog_db_prefix' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db_prefix')."' /> |
|---|
| | 372 | <input name='jlog_start_year' type='hidden' value='".$this->defaultValue($data, 'jlog_start_year', date("Y"))."' /></p> |
|---|
| | 373 | <input name='jlog_path' type='hidden' value='".$this->defaultValue($data, 'jlog_path')."' /> |
|---|
| | 374 | <input name='jlog_basepath' type='hidden' value='".$this->defaultValue($data, 'jlog_basepath')."' /> |
|---|
| | 375 | </fieldset> |
|---|
| | 376 | "; |
|---|
| | 377 | } |
|---|
| | 378 | |
|---|
| | 379 | $form .= " |
|---|
| | 380 | <p><input type='submit' class='button' value='".$this->l['admin']['submit']."' /></p> |
|---|
| | 381 | </form> |
|---|
| | 382 | "; |
|---|
| | 383 | |
|---|
| | 384 | return $form; |
|---|
| | 385 | } |
|---|
| | 386 | |
|---|
| | 387 | /** |
|---|
| | 388 | * validate() - validates the current configuration |
|---|
| | 389 | * |
|---|
| | 390 | * If the current configuration is valid, an empty array is returned. |
|---|
| | 391 | * Otherwise the returned array containes all errors, described in the |
|---|
| | 392 | * current language. |
|---|
| | 393 | * |
|---|
| | 394 | * @access public |
|---|
| | 395 | * @return array |
|---|
| | 396 | */ |
|---|
| | 397 | function validate() { |
|---|
| | 398 | # if everything validate then return true |
|---|
| | 399 | # otherwise return the $errors array |
|---|
| | 400 | |
|---|
| | 401 | $errors = array(); |
|---|
| | 402 | |
|---|
| | 403 | // paths |
|---|
| | 404 | if(empty($this->d['jlog_path']) OR (check_url($this->d['jlog_path'], array ('http')) === false)) $errors[] = $this->l['admin']['e_path']; |
|---|
| | 405 | if(empty($this->d['jlog_basepath']) OR !is_dir($this->d['jlog_basepath'])) $errors[] = $this->l['admin']['e_basepath']; |
|---|
| | 406 | if($this->d['jlog_clean_url'] != 'true') $this->d['jlog_clean_url'] = 'false'; |
|---|
| | 407 | // metadata |
|---|
| | 408 | if(empty($this->d['jlog_website'])) $errors[] = $this->l['admin']['e_website']; |
|---|
| | 409 | if(empty($this->d['jlog_publisher'])) $errors[] = $this->l['admin']['e_publisher']; |
|---|
| | 410 | if(defined('JLOG_SETUP') AND JLOG_SETUP) { |
|---|
| | 411 | if($this->d['jlog_admin_password'] == md5("")) |
|---|
| | 412 | $errors[] = $this->l['admin']['e_admin_password']; |
|---|
| | 413 | elseif($this->d['jlog_admin_password'] !== $this->d['jlog_admin_password_again']) |
|---|
| | 414 | $errors[] = $this->l['admin']['e_admin_password_again']; |
|---|
| | 415 | } |
|---|
| | 416 | elseif(!empty($this->d['jlog_admin_password']) AND $this->d['jlog_admin_password'] !== $this->d['jlog_admin_password_again']) { |
|---|
| | 417 | $errors[] = $this->l['admin']['e_admin_password_again']; |
|---|
| | 418 | } |
|---|
| | 419 | // Fix of bug #148 |
|---|
| | 420 | if(isset($this->d['jlog_admin_password_again'])) |
|---|
| | 421 | unset($this->d['jlog_admin_password_again']); |
|---|
| | 422 | |
|---|
| | 423 | if(empty($this->d['jlog_email']) OR !strpos($this->d['jlog_email'], '@')) $errors[] = $this->l['admin']['e_email']; |
|---|
| | 424 | if(empty($this->d['jlog_description'])) $errors[] = $this->l['admin']['e_description']; |
|---|
| | 425 | // behavour |
|---|
| | 426 | if(!is_numeric($this->d['jlog_max_blog_orginal']) OR intval($this->d['jlog_max_blog_orginal']) < 0) $errors[] = $this->l['admin']['e_max_blog_orginal']; |
|---|
| | 427 | if(!is_numeric($this->d['jlog_max_blog_big']) OR intval($this->d['jlog_max_blog_big']) < 0) $errors[] = $this->l['admin']['e_max_blog_big']; |
|---|
| | 428 | if(!is_numeric($this->d['jlog_max_blog_small']) OR intval($this->d['jlog_max_blog_small']) < 0) $errors[] = $this->l['admin']['e_max_blog_small']; |
|---|
| | 429 | if(!is_numeric($this->d['jlog_sub_current']) OR intval($this->d['jlog_sub_current']) < 0) $errors[] = $this->l['admin']['e_sub_current']; |
|---|
| | 430 | if(!is_numeric($this->d['jlog_start_year'])) $errors[] = $this->l['admin']['e_start_year']; |
|---|
| | 431 | if($this->d['jlog_info_by_comment'] != 'true') $this->d['jlog_info_by_comment'] = 'false'; |
|---|
| | 432 | // database |
|---|
| | 433 | if(empty($this->d['jlog_db'])) $errors[] = $this->l['admin']['e_db']; |
|---|
| | 434 | if(empty($this->d['jlog_db_url'])) $errors[] = $this->l['admin']['e_db_url']; |
|---|
| | 435 | // Fix of bug #196, prefix should only contain alphanumeric values, can be empty! |
|---|
| | 436 | if(!preg_match('/^[a-zA-Z0-9_]*$/', $this->d['jlog_db_prefix'])) $errors[] = $this->l['admin']['e_db_prefix']; |
|---|
| | 437 | |
|---|
| | 438 | return $errors; |
|---|
| | 439 | } |
|---|
| | 440 | |
|---|
| | 441 | /** |
|---|
| | 442 | * do_settings() - save configuration |
|---|
| | 443 | * |
|---|
| | 444 | * Saves the current configuration to the settings.inc.php file |
|---|
| | 445 | * in the personal folder. Return an empty array if configuration |
|---|
| | 446 | * was saved successfully, or an array containing descriptions of |
|---|
| | 447 | * the errors that occured otherwise. |
|---|
| | 448 | * |
|---|
| | 449 | * @access public |
|---|
| | 450 | * @return array |
|---|
| | 451 | */ |
|---|
| | 452 | function do_settings() { |
|---|
| | 453 | # if it's all done return true |
|---|
| | 454 | # otherwise return the $errors array |
|---|
| | 455 | |
|---|
| | 456 | $errors = array(); |
|---|
| | 457 | |
|---|
| | 458 | // if there is no new password set the old |
|---|
| | 459 | if(JLOG_ADMIN AND empty($this->d['jlog_admin_password'])) $this->d['jlog_admin_password'] = JLOG_ADMIN_PASSWORD; |
|---|
| | 460 | |
|---|
| | 461 | // remove slashes at the end of JLOG_PATH if present |
|---|
| | 462 | $this->d['jlog_path'] = rtrim($this->d['jlog_path'], '/'); |
|---|
| | 463 | // make shure JLOG_BASEPATH ends with a slash!! |
|---|
| | 464 | $this->d['jlog_basepath'] = rtrim($this->d['jlog_basepath'], '/\\') . DIRECTORY_SEPARATOR; |
|---|
| | 465 | |
|---|
| | 466 | // no quotes for bolean and numbers |
|---|
| | 467 | $no_quotes = array ( |
|---|
| | 468 | 'jlog_clean_url' => 'bool', |
|---|
| | 469 | 'jlog_max_blog_orginal' => 'int', |
|---|
| | 470 | 'jlog_max_blog_big' => 'int', |
|---|
| | 471 | 'jlog_max_blog_small' => 'int', |
|---|
| | 472 | 'jlog_sub_current' => 'int', |
|---|
| | 473 | 'jlog_start_year' => 'int', |
|---|
| | 474 | 'jlog_info_by_comment' => 'bool' |
|---|
| | 475 | ); |
|---|
| | 476 | |
|---|
| | 477 | // serialize data to file format |
|---|
| | 478 | $file_content = '<?php' . PHP_EOL . '// generated at ' . date('Y-m-d, h:i:s') . PHP_EOL; |
|---|
| | 479 | |
|---|
| | 480 | foreach($this->d as $key => $value) { |
|---|
| | 481 | $output = ''; |
|---|
| | 482 | if(isset($no_quotes[$key])) { |
|---|
| | 483 | // boolean values |
|---|
| | 484 | if($no_quotes[$key] == 'bool') { |
|---|
| | 485 | if($value == 'true' OR $value === true) $output = 'true'; |
|---|
| | 486 | else $output = 'false'; |
|---|
| | 487 | } |
|---|
| | 488 | // numeric values |
|---|
| | 489 | else { |
|---|
| | 490 | $output = (int) $value; |
|---|
| | 491 | } |
|---|
| | 492 | } |
|---|
| | 493 | // string values |
|---|
| | 494 | else { |
|---|
| | 495 | $output = '\'' . $this->escapeForPhp($value) . '\''; |
|---|
| | 496 | } |
|---|
| | 497 | $key = '\'' . $this->escapeForPhp(strtoupper($key)) . '\''; |
|---|
| | 498 | $file_content .= 'define(' . $key . ', ' . $output . ');' . PHP_EOL; |
|---|
| | 499 | } |
|---|
| | 500 | |
|---|
| | 501 | $file_content .= '// eof'; |
|---|
| | 502 | |
|---|
| | 503 | // write to settings.inc.php |
|---|
| | 504 | if(!$handle = fopen(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."settings.inc.php", "w")) $errors[] = $this->l['admin']['can_not_open']." /personal/settings.inc.php"; |
|---|
| | 505 | if(!fwrite($handle, $file_content)) $errors[] = $this->l['admin']['can_not_write']." /personal/settings.inc.php"; |
|---|
| | 506 | fclose($handle); |
|---|
| | 507 | |
|---|
| | 508 | return $errors; |
|---|
| | 509 | } |
|---|