'inc-db/triggers/config.before', 'after' => 'inc-db/triggers/config.after', ); /* }}} */ $ezin_admin_config_flags_array = array( /* {{{ */ 'disabled_eval' => true, 'select' => 'F', 'values' => array( 'B' => 'line break wraps', 'P' => 'paragraph wraps', '' => '', 'H' => 'http:// links', 'W' => 'WWW links', 'E' => 'e-mail links' )); /* }}} */ $ezin_admin_config_items = array( /* {{{ */ 'theme' => array( 'disabled_eval' => true, 'select' => 'D', 'keys_are_values' => true, 'values' => ezin_admin_config_get_themes()), 'user_create_role_id' => array( 'disabled_eval' => true, 'select' => 'D', 'values' => ezin_admin_config_get_roles()), 'encoding' => array( 'disabled_eval' => true, 'select' => 'D', 'keys_are_values' => true, 'values' => array('utf-8', 'us-ascii', 'iso-8859-1', 'iso-8859-2', 'windows-1250')), 'antispam_flags' => array( 'disabled_eval' => true, 'select' => 'F', 'values' => array('M' => 'messages', 'F' => 'feedbacks', 'N' => 'newsletters', 'A' => 'new users')), 'admin_buttons_pos' => array( 'disabled_eval' => true, 'select' => 'D', 'values' => array('U' => 'up', 'D' => 'down', 'UD' => 'up and down')), 'admin_navigation' => array( 'disabled_eval' => true, 'select' => 'F', 'values' => array('B' => 'buttons', 'G' => 'graphic links', 'T' => 'text links')), 'debug_level' => array( 'disabled_eval' => false, 'select' => 'D', 'values' => range(0, 10)), 'mail_method' => array( 'disabled_eval' => true, 'select' => 'D', 'values' => array( 'mail' => 'mail() function', 'sendmail' => 'sendmail binary', 'smtp' => 'SMTP connection')), 'flags_article_hometext' => $ezin_admin_config_flags_array, 'flags_article_bodytext' => $ezin_admin_config_flags_array, 'flags_editorial' => $ezin_admin_config_flags_array, 'flags_author' => $ezin_admin_config_flags_array, 'flags_message' => $ezin_admin_config_flags_array, 'feedback_save_redirect' => array( 'disabled_eval' => true, 'select' => 'R', 'values' => array('0' => 'disabled', '1' => 'enabled')), 'message_save_redirect' => array( 'disabled_eval' => true, 'select' => 'R', 'values' => array('0' => 'disabled', '1' => 'enabled')), 'link_file_type' => array( 'disabled_eval' => true, 'select' => 'R', 'values' => array('0' => 'index.php only', '1' => 'additional files usage', '2' => 'mod_rewrite url')), 'link_redirect' => array( 'disabled_eval' => true, 'select' => 'D', 'values' => array('0' => 'disabled', '1' => '301 Moved Permanently', '2' => '302 Found', '3' => '303 See Other')), 'redirect_index' => array('disabled_eval' => true, 'select' => 'DB_items'), 'redirect_others' => array('disabled_eval' => true, 'select' => 'DB_items'), 'order_articles_desc' => array( 'disabled_eval' => true, 'select' => 'R', 'values' => array('0' => 'ascending', '1' => 'descending')), 'order_messages_desc' => array( 'disabled_eval' => true, 'select' => 'R', 'values' => array('0' => 'ascending', '1' => 'descending')), 'gallery_type' => array( 'disabled_eval' => true, 'select' => 'D', 'values' => array( 'default' => 'Default', 'javascript' => 'JavaScript')), 'calendar_popup_display' => array( 'disabled_eval' => true, 'select' => 'D', 'values' => array( 'right' => 'Right', 'left' => 'Left')), 'calendar' => array( 'disabled_eval' => true, 'select' => 'R', 'values' => array('0' => 'disabled', '1' => 'enabled')), 'featured_articles' => array( 'disabled_eval' => true, 'select' => 'R', 'values' => array('0' => 'disabled', '1' => 'enabled')), 'soap_server_enabled' => array( 'disabled_eval' => true, 'select' => 'R', 'values' => array('0' => 'disabled', '1' => 'enabled')), 'platon_newsletter_enabled' => array( 'disabled_eval' => true, 'select' => 'R', 'values' => array('0' => 'disabled', '1' => 'enabled')), 'antispam_type' => array( 'disabled_eval' => true, 'select' => 'D', 'values' => array( 'default' => 'Question-Answer (Default)', 'rotate' => 'RotateAntispam (JavaScript)', 'empty' => 'Empty answer', 'timetoken' => 'Time token', )), 'redirect_equal_url' => array( 'disabled_eval' => true, 'select' => 'R', 'values' => array('0' => 'disabled', '1' => 'enabled')), 'https_admin' => array( 'disabled_eval' => true, 'select' => 'D', 'values' => array( '0' => 'Always OFF', '1' => 'Auto-detect (default)', '2' => 'Always ON')), 'article_datetime_filter' => array( 'disabled_eval' => true, 'select' => 'R', 'values' => array('0' => 'disabled', '1' => 'enabled')), 'article_items_loadmore' => array( 'disabled_eval' => true, 'select' => 'R', 'values' => array('0' => 'disabled', '1' => 'enabled')), ); /* }}} */ /* * ezin_admin_config_main() */ function ezin_admin_config_main($restricted = 0) /* {{{ */ { global $ezin_cfg; global $ezin_sys; global $ezin_db_handle; global $ezin_admin_config_items; $action = Platon::get_cgi_var('action'); $cancel = Platon::get_cgi_var('cancel'); $cancel_view = Platon::get_cgi_var('cancel_view'); $cancel_help = Platon::get_cgi_var('cancel_help'); $save = Platon::get_cgi_var('save'); $saved = Platon::get_cgi_var('saved'); if ($cancel) { $message = 'Operation canceled'; $action = ''; } elseif ($cancel_view) { $message = 'View canceled'; $action = ''; } elseif ($cancel_help) { $message = 'Help canceled'; $action = ''; } if (isset($saved)) { $message = $saved > 0 ? 'Configuration was sucessfully saved' : 'Configuration was NOT saved'; } else { $saved = 0; } if ($save) { if ($restricted) { $message = 'Insufficient privileges'; } else { $saved = ezin_admin_config_save(); if (0) { $ezin_cfg = ezin_get_config(); } else { header('Location: http://'.$_SERVER['HTTP_HOST'] .$_SERVER['SCRIPT_NAME'].'?saved='.$saved); exit; } } } echo '
',"\n"; switch ($action) { case 'create': case 'edit': case 'delete': if ($restricted) break; case 'view': case 'help': $option = Platon::get_cgi_var('option'); $query = sprintf('SELECT' .' info.a_key, info.ord, info.name, info.description,' .' data.type, data.value' .' FROM %s AS info LEFT JOIN %s AS data' .' ON info.a_key = data.a_key' .' WHERE info.a_key = "%s"' .' ORDER BY info.ord', $ezin_sys['db']['tables']['config_info'], $ezin_sys['db']['tables']['config_data'], $option); $result = mysqli_query($ezin_db_handle, $query); if ($result == false) { ezin_db_error('ezin_admin_config_main() [1]'); return false; } $row = mysqli_fetch_array($result, MYSQLI_ASSOC); mysqli_free_result($result); if ($row == null) break; if (stristr($ezin_cfg['admin_buttons_pos'], 'U')) { switch ($action) { case 'delete': echo '',"\n"; echo '',"\n"; ezin_admin_config_delete_button(); break; case 'view': echo '',"\n"; echo '',"\n"; ezin_admin_config_view_button($restricted); break; case 'help': ezin_admin_config_help_button(); break; default: echo '',"\n"; ezin_admin_config_edit_button(); break; } echo '
',"\n"; } echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n",''; if ($action == 'help') { echo ''; echo ''; echo ''; echo ''; echo ''; } else { if ($action == 'delete' || $action == 'view') { echo '',"\n",''; echo '',"\n",'',"\n"; echo ''; echo ''; } else { echo ''; } } echo '',"\n"; echo '
Option',$row['name'],'
Key',$row['a_key'],'
Description
'; echo $row['description'],'
Dynamic code'; echo '
';
					if ($restricted <= 1) {
						if (0) { // to enable syntax highlighting
							//@highlight_string('<'.'?PHP'."\n".$row['value']."\n".'?'.'>');
						} else {
							echo Platon::htmlspecialchars2('<'.'?PHP'."\n".$row['value']."\n".'?'.'>');
						}
					} else {
						echo 'not available';
					}
					echo '
Value'; $evalued_value = ezin_eval($row['value']); echo Platon::htmlspecialchars2($evalued_value); echo '
Variable dump'; var_dump($evalued_value); echo 'Dynamic code'; echo ''; echo '<?PHP
'; echo '       '; echo ''; echo '
?>'; echo '
',"\n"; if (stristr($ezin_cfg['admin_buttons_pos'], 'D') || ! stristr($ezin_cfg['admin_buttons_pos'], 'U')) { echo '
',"\n"; switch ($action) { case 'delete': ezin_admin_config_delete_button(); break; case 'view': ezin_admin_config_view_button($restricted); break; case 'help': ezin_admin_config_help_button(); break; default: ezin_admin_config_edit_button(); break; } } break; default: $query = sprintf('SELECT' .' info.a_key, info.ord, info.name, info.description,' .' data.type, data.value' .' FROM %s AS info LEFT JOIN %s AS data' .' ON info.a_key = data.a_key' .' ORDER BY info.ord', $ezin_sys['db']['tables']['config_info'], $ezin_sys['db']['tables']['config_data']); $result = mysqli_query($ezin_db_handle, $query); if ($result == false) { ezin_db_error('ezin_admin_config_main() [2]'); return false; } if (stristr($ezin_cfg['admin_buttons_pos'], 'U')) { ezin_admin_config_save_button($restricted, $message); echo '
',"\n"; $message = ''; } ezin_admin_config_check_rewritebase(); echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; $count = 0; while (($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) != null) { echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n"; $count++; } mysqli_free_result($result); echo '
OptionValueDynamic code
',"\n"; echo Platon::htmlspecialchars2($row['name']); //echo '
'.$row['a_key'].''; echo '
',"\n"; if ($restricted) { switch ($ezin_admin_config_items[$row['a_key']]['select']) { case 'R': // radio case 'D': // drop-down $val_idx = $ezin_admin_config_items[$row['a_key']]['keys_are_values'] ? array_search($row['value'], $ezin_admin_config_items[$row['a_key']]['values']) : $row['value']; echo $ezin_admin_config_items[$row['a_key']]['values'][$val_idx]; break; case 'F': // flags $printed = false; foreach (array_keys($ezin_admin_config_items[$row['a_key']]['values']) as $flag) { if (strlen($flag) <= 0 || ! strstr($row['value'], $flag)) continue; $printed && print(', '); $printed = true; echo $ezin_admin_config_items[$row['a_key']]['values'][$flag]; } break; case 'DB_items': // database elements ezin_admin_config_db_items('data_'.$row['a_key'], $row['value'], 1); break; default: if ($row['type'] == 1) { // eval echo '',Platon::htmlspecialchars2(ezin_eval($row['value'])),''; } else { echo Platon::htmlspecialchars2($row['value']); } if (strlen($row['value']) <= 0) { echo ' '; } break; } } else { switch ($ezin_admin_config_items[$row['a_key']]['select']) { case 'R': // radio foreach ($ezin_admin_config_items[$row['a_key']]['values'] as $key => $val) { if ($ezin_admin_config_items[$row['a_key']]['keys_are_values']) $key = $val; echo '',Platon::htmlspecialchars2($val),'',"\n"; } break; case 'D': // drop-down echo '',"\n"; break; case 'F': // flags $i = 0; foreach ($ezin_admin_config_items[$row['a_key']]['values'] as $flag => $text) { if (strlen($flag) <= 0) { echo '
',"\n"; //'
'."\n"; continue; } echo $i ? ' ' : ''; echo ''; echo Platon::htmlspecialchars2($text); $i++; } echo '',"\n"; break; case 'DB_items': // database elements ezin_admin_config_db_items('data_'.$row['a_key'], $row['value']); break; default: if ($row['type'] == 1) { // eval echo '',Platon::htmlspecialchars2(ezin_eval($row['value'])),''; } else { echo ''; } break; } } echo '
',"\n"; echo ''; echo 'Help'; if (1 && $ezin_admin_config_items[$row['a_key']]['disabled_eval']) { } else { if ($row['type'] == 1) { if (! $restricted) { echo ' | '; echo ''; echo 'Edit'; } echo ' | '; echo ''; echo 'View'; if (! $restricted) { echo ' | '; echo ''; echo 'Delete'; } } else { if (! $restricted) { echo ' | '; echo ''; echo 'Create'; } } } echo ' 
',"\n"; if (stristr($ezin_cfg['admin_buttons_pos'], 'D') || ! stristr($ezin_cfg['admin_buttons_pos'], 'U')) { echo '
',"\n"; ezin_admin_config_save_button($restricted, $message); } break; } echo '
',"\n"; return; } /* }}} */ function ezin_admin_config_save_button($restricted, $message = '') /* {{{ */ { echo '',"\n"; echo '',"\n"; echo '
',"\n"; echo '',"\n"; echo '',"\n"; if (strlen($message) > 0) { echo '',$message; } echo '
',"\n"; } /* }}} */ function ezin_admin_config_edit_button() /* {{{ */ { echo '',"\n"; echo '
',"\n"; echo '',"\n"; echo '',"\n"; echo '
',"\n"; } /* }}} */ function ezin_admin_config_view_button($restricted) /* {{{ */ { echo '',"\n"; echo '
',"\n"; if (! $restricted) { echo '',"\n"; } echo '',"\n"; echo '
',"\n"; } /* }}} */ function ezin_admin_config_help_button() /* {{{ */ { echo '',"\n"; echo '
',"\n"; echo '',"\n"; echo '
',"\n"; } /* }}} */ function ezin_admin_config_delete_button() /* {{{ */ { echo '',"\n"; echo '
',"\n"; echo '',"\n"; echo '',"\n"; echo '
',"\n"; } /* }}} */ function ezin_admin_config_check_rewritebase() /* {{{ */ { global $ezin_cfg; $htaccess_filename = dirname(__FILE__).'/../../.htaccess'; if (!file_exists($htaccess_filename)) { echo '
File "'.$htaccess_filename.'" not exist
'; return false; } $lines = file($htaccess_filename); $rewritebase_command = 'rewritebase'; $rewritebase_enabled = true; $rewritebase_path = null; foreach ($lines as $line) { $line = trim($line); $line_formed = strtolower($line); if (strstr($line_formed, $rewritebase_command) !== false) { $rewritebase_path = trim(substr($line, strpos($line_formed, $rewritebase_command) + strlen($rewritebase_command))); if (strstr($rewritebase_path, '#') !== false) { // remove comment $rewritebase_path = trim(substr($rewritebase_path, strpos($line_formed, '#'))); } if (strstr($line_formed, '#') !== false && strpos($line_formed, '#') < strpos($line_formed, $rewritebase_command)) { $rewritebase_enabled = false; continue; } $rewritebase_enabled = true; } } if (is_null($rewritebase_path)) { echo '
Not defined RewriteBase in .htaccess
'; return false; } if (!is_null($rewritebase_path) && $rewritebase_enabled == false) { echo '
Defined RewriteBase in .htaccess ('.$rewritebase_path.') is disabled
'; return false; } if ($ezin_cfg['url'] != $rewritebase_path) { echo '
Defined RewriteBase in .htaccess ('.$rewritebase_path.') is not equal with URL in config ('.$ezin_cfg['url'].')
'; return false; } return true; } /* }}} */ function ezin_admin_config_get_themes() /* {{{ */ { global $ezin_sys; $output_ar = array(); $themes_dir = '../'.$ezin_sys['dir']['themes']; $directory = dir($themes_dir); while ($entry = $directory->read()) { if (! @is_dir(Platon::append_slash($themes_dir).$entry)) continue; if ($entry == '.' || $entry == '..' || $entry == '.svn' || $entry == 'CVS') continue; array_push($output_ar, $entry); } sort($output_ar); return $output_ar; } /* }}} */ function ezin_admin_config_get_roles() /* {{{ */ { global $ezin_sys, $ezin_db_handle; ezin_check_db_handle(); $query = sprintf('SELECT id, name FROM %s ORDER BY name ASC', $ezin_sys['db']['tables']['roles']); $result = mysqli_query($ezin_db_handle, $query) or ezin_db_error('ezin_admin_config_get_roles()'); $array = array(0 => '-- no role --'); while (($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) != null) { $array[$row['id']] = $row['name']; } mysqli_free_result($result); return $array; } /* }}} */ function ezin_admin_config_db_items($name, $value, $restricted = 0) /* {{{ */ { global $ezin_sys; global $ezin_db_handle; static $elements = ''; $checked = $value[0] == '+'; $value = $checked ? substr($value, 1) : $value; if ($elements == '') { $elements = array('' => $restricted ? 'none' : '-- nothing selected --'); foreach (array('sections', 'articles') as $table_type) { $query = 'SELECT id, access_key' .' FROM '.$ezin_sys['db']['tables'][$table_type] .' ORDER BY id DESC'; $result = mysqli_query($ezin_db_handle, $query); if ($result === false) { ezin_db_error('ezin_admin_config_main() [3]'); return -1; } while (($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) != null) { $elements[($table_type == 'sections' ? 'S' : 'A').$row['id']] = ($table_type == 'sections' ? 'section' : 'article') .' '.$row['id'] .(!empty($row['access_key']) ? ' ('.$row['access_key'].')' : ''); // ) } } } if ($restricted) { echo $elements[$value]; if ($checked) { echo ' using HTTP/1.1'; } } else { echo '',"\n"; echo ''; echo 'use HTTP/1.1',"\n"; } return true; } /* }}} */ function ezin_admin_config_save() /* {{{ */ { global $ezin_sys, $ezin_cfg; global $ezin_db_handle; global $ezin_admin_config_items; global $ezin_admin_config_triggers; $ret = 1; $query = sprintf('SELECT a_key FROM %s', $ezin_sys['db']['tables']['config_info']); $result = mysqli_query($ezin_db_handle, $query); if ($result == false) { ezin_db_error('ezin_admin_config_main() [4]'); return -1; } if (file_exists($ezin_admin_config_triggers['before'])) { $trigger_ret = include $ezin_admin_config_triggers['before']; if ($trigger_ret == false) { return -1; } } while (($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) != null) { $key = $row['a_key']; $value = $_POST["data_$key"]; $type_f = $_POST["eval_$key"] ? true : false; $type = $_POST["eval_$key"] ? '"1"' : 'NULL'; if ($ezin_admin_config_items[$key]['disabled_eval'] && isset($_POST["eval_$key"])) { $ret = -1; continue; } if (! isset($value)) { continue; } /* Now if value is array, we will merge it into string. */ if (is_array($value)) { ksort($value); $value = implode('', $value); } $value = stripslashes($value); // Browser space hack // http://lua-users.org/lists/lua-l/2008-10/msg00244.html $value = str_replace(chr(0xC2).chr(0xA0), chr(32), $value); // Special "space" hack (for non-utf only) if (strncasecmp($ezin_cfg['encoding'], 'utf', 3)) { $value = str_replace(chr(160), chr(32), $value); } /* We are going to try evalcode, if it is correct and without errors. If error occured, default error handler will stop execution and no data will be saved into database. Than administrator has possibility to go back and change/fix evalcode. */ if ($type_f) { ezin_eval($value); } if (strlen($value) > 0) { $value = function_exists('mysqli_escape_string') ? mysqli_escape_string($ezin_db_handle, $value) : addslashes($key); $value = '"'.$value.'"'; } else { $value = 'NULL'; } $query = sprintf('SELECT a_key FROM %s WHERE a_key = "%s"', $ezin_sys['db']['tables']['config_data'], $key); $sub_result = mysqli_query($ezin_db_handle, $query); if ($sub_result == false) return -1; $num_rows = mysqli_num_rows($sub_result); mysqli_free_result($sub_result); if ($num_rows == 0) { $query = sprintf('INSERT INTO %s' .' (a_key, type, value) VALUES ("%s", %s, %s)', $ezin_sys['db']['tables']['config_data'], $key, $type, $value); } else { $query = sprintf('UPDATE %s' .' SET type = %s, value = %s' .' WHERE a_key = "%s"', $ezin_sys['db']['tables']['config_data'], $type, $value, $key); } // If you don't see query on page, it's due to HTTP reload above //echo $query,'
'; if (mysqli_query($ezin_db_handle, $query) === false) { return -1; } } mysqli_free_result($result); if (file_exists($ezin_admin_config_triggers['after'])) { $trigger_ret = include $ezin_admin_config_triggers['after']; if ($trigger_ret == false) { return -1; } } return $ret; } /* }}} */ /* * Main stuff */ if (strstr($ezin_user['role_config'], 'C')) { ezin_check_db_handle(); ezin_admin_config_main(0); ezin_close_db_connection(); } elseif (ezin_admin_check_full_list_privileges($ezin_user['role_config'])) { ezin_check_db_handle(); ezin_admin_config_main(1); ezin_close_db_connection(); } elseif (ezin_admin_check_restricted_list_privileges($ezin_user['role_config'])) { ezin_check_db_handle(); ezin_admin_config_main(2); ezin_close_db_connection(); } /* Modeline for ViM {{{ * vim: set ts=4: * vim600: fdm=marker fdl=0 fdc=0: * }}} */ ?>