function index() { include ROOT . "/library/browser/Browser.php"; $browser = new Browser(); if ($browser->getBrowser() == Browser::BROWSER_IE && $browser->getVersion() < 7) { flash_error(lang("ie browser outdated")); } if (is_ajax_request()) { $timezone = array_var($_GET, 'utz'); if ($timezone && $timezone != '') { $usu = logged_user(); if ($usu instanceof Contact && $usu->isUser() && !$usu->getDisabled()) { $usu->setTimezone($timezone); $usu->save(); } } $this->redirectTo('dashboard', 'main_dashboard'); } else { if (!(logged_user() instanceof Contact && logged_user()->isUser())) { $this->redirectTo('access', 'login'); } $this->setLayout("website"); $this->setTemplate(get_template_path("empty")); } }
<?php include 'include/function.php'; include 'include/config.php'; include 'include/db.php'; if (!is_logged() or !isset($_GET['id'])) { header("location: {$config['base_url']}"); exit; } $db = new DB(); if (isset($_POST['update'])) { $id = $db->escape_string($_POST['id']); $title = $db->escape_string($_POST['title']); $artist = $db->escape_string($_POST['artist']); $url = $db->escape_string($_POST['url']); $db->query("UPDATE songs SET title='{$title}', artist='{$artist}', path='{$url}' WHERE id={$id}"); header('Location: ' . $config['base_url'] . 'dashboard?msg=update_success'); exit; } $db = new DB(); $row = $db->query("SELECT * FROM songs WHERE id={$_GET['id']}"); $row = $row->fetch_array(); $title = 'Update ' . $row['title']; if (!is_ajax_request()) { include './views/header.php'; } include './views/update.php'; if (!is_ajax_request()) { include './views/footer.php'; } $db->close();
function info_page($info, $title = '系统消息') { if (is_ajax_request()) { $layout = 'ajax'; } else { $layout = 'web'; } $data['top_title'] = $data['title'] = $title; $data['info'] = $info; render($data, $layout, 'info'); }
function render($view) { $viewFile = DUP_VIEWS_DIR . "/" . $view . ".php"; if (file_exists($viewFile)) { if (!empty($this->layout) && !is_ajax_request()) { ob_start(); include $viewFile; $content_for_page = ob_get_contents(); ob_end_clean(); $layoutFile = DUP_VIEWS_DIR . "/layouts/" . $this->layout . ".php"; include $layoutFile; } else { include $viewFile; } } }
function output() { global $lang; if ($_SERVER['REQUEST_METHOD'] == 'POST' && method_exists($this, 'output_onpost_' . $_POST['form_name'])) { return call_user_func(array($this, 'output_onpost_' . $_POST['form_name'])); } $this->tpl['lang'] = $lang; $this->tpl['link_restore_password'] = make_ref('/users', array("action" => "restore")); $this->tpl['form_submit_url'] = make_ref('/users/loginform'); $output = template($this->tpl, __FILE__); if (is_ajax_request()) { print $output; exit; } else { return $output; } }
public function render($data = NULL, $layout = NULL, $sharp = 'default') { if ($layout == null) { if (is_ajax_request()) { $layout = 'ajax'; } elseif (is_mobile_request()) { //$layout = 'mobile'; $layout = 'web'; } else { $layout = 'web'; } } $layout_file = AROOT . 'view/layout/' . $layout . '/' . $sharp . '.tpl.html'; if (file_exists($layout_file)) { @extract($data); require $layout_file; } }
//Define the OS file path separator define('DS', DIRECTORY_SEPARATOR); //Define the base file system path to MicroMVC define('SYSTEM_PATH', realpath(dirname(__FILE__)) . DS); //Define the base file system path to libraries define('LIBRARY_PATH', SYSTEM_PATH . 'libraries' . DS); //Define the base file system path to functions define('FUNCTION_PATH', SYSTEM_PATH . 'functions' . DS); //Define the base file system path to modules define('MODULE_PATH', SYSTEM_PATH . 'modules' . DS); //Define the base file system path to logs define('LOG_PATH', SYSTEM_PATH . 'logs' . DS); //Include the common file to continue loading require_once FUNCTION_PATH . 'common.php'; //Discover whether this is an AJAX request or not define('AJAX_REQUEST', is_ajax_request()); //Discover the current domain for the whole script define('DOMAIN', current_domain()); //Define the file system path to the current site define('SITE_PATH', SYSTEM_PATH . DOMAIN . DS); //The file system path of the site's cache folder define('CACHE_PATH', SITE_PATH . 'cache' . DS); //The file system path of the site's config folder define('CONFIG_PATH', SITE_PATH . 'config' . DS); //The file system path of the site's models folder define('MODEL_PATH', SITE_PATH . 'models' . DS); //The file system path of the site's uploads folder define('UPLOAD_PATH', SITE_PATH . 'uploads' . DS); //The file system path of the site's views folder define('VIEW_PATH', SITE_PATH . 'views' . DS); //Override the PHP error handler
<?php session_start(); define('DS', DIRECTORY_SEPARATOR); define('PATH', dirname(__FILE__) . DS); define('DOC_ROOT', str_replace(DS, '/', realpath($_SERVER['DOCUMENT_ROOT']))); header("Content-type:text/html; charset=utf-8"); mb_internal_encoding('UTF-8'); date_default_timezone_set('UTC'); $default_lang = 'uk'; if (isset($_REQUEST['lang'])) { $_SESSION['install']['lang'] = $_REQUEST['lang']; header('Location: ' . $_SERVER['SCRIPT_NAME']); } $is_lang_selected = isset($_SESSION['install']['lang']); $lang = $is_lang_selected ? $_SESSION['install']['lang'] : $default_lang; define('LANG', $lang); include PATH . "functions.php"; include PATH . DS . 'languages' . DS . LANG . DS . "language.php"; $steps = array(array('id' => 'start', 'title' => LANG_STEP_START), array('id' => 'license', 'title' => LANG_STEP_LICENSE), array('id' => 'php', 'title' => LANG_STEP_PHP_CHECK), array('id' => 'paths', 'title' => LANG_STEP_PATHS), array('id' => 'database', 'title' => LANG_STEP_DATABASE), array('id' => 'site', 'title' => LANG_STEP_SITE), array('id' => 'admin', 'title' => LANG_STEP_ADMIN), array('id' => 'config', 'title' => LANG_STEP_CONFIG), array('id' => 'cron', 'title' => LANG_STEP_CRON), array('id' => 'finish', 'title' => LANG_STEP_FINISH)); $current_step = 0; if (is_ajax_request()) { $step = $steps[(int) $_POST['step']]; $is_submit = isset($_POST['submit']); echo json_encode(run_step($step, $is_submit)); exit; } $step_result = run_step($steps[$current_step], false); echo render('main', array('steps' => $steps, 'is_lang_selected' => $is_lang_selected, 'lang' => LANG, 'current_step' => $current_step, 'step_html' => $step_result['html']));
function execute_questions() { $game = R::load('game', $_SESSION['quiz_id']); if (quiz_has_expired($game)) { finish_game($game); redirect('result'); } if (($question_id = find_first_unanswered_question(unserialize($game->answers))) == null) { redirect('result'); } $question = R::load('question', $question_id); $answers = R::find('answer', 'question_id = ? ORDER BY RAND()', array($question_id)); $seconds_left = strtotime($game->started_at) - time() + QUIZ_TIMELIMIT; ob_start(); if (is_ajax_request()) { include_once dirname(__FILE__) . '/views/_question.php'; } else { include_once dirname(__FILE__) . '/views/test-middle.php'; } $content = ob_get_clean(); echo $content; }
/** * @return Model $this * @throws Exception */ public function makeProperties() { if ($this->getStoredAql()) { $this->makeAqlArray(); $i = 0; foreach ($this->getStoredAqlArray() as $table) { if ($i == 0) { $this->_primary_table = $table['table']; $this->addProperty($this->_primary_table . '_id'); } $this->tableMakeProperties($table); $i++; } } else { $e = sprintf(self::E_INVALID_MODEL, $this->_model_name); if (!is_ajax_request()) { throw new Exception($e); return $this; } else { exit_json(array('status' => 'Error', 'errors' => array($e))); } } return $this; }
/** * Create the page object and set if this is an ajax request * Optionally set other properties * @param array $config */ public function __construct(array $config = array()) { $this->is_ajax_request = \is_ajax_request(); $this->uri = $_SERVER['REQUEST_URI']; foreach ($config as $k => $v) { $this->{$k} = $v; } }
/** * Redirect to referer * * @access public * @param string $alternative Alternative URL is used if referer is not valid URL * @return null */ function redirect_to_referer($alternative = nulls) { $referer = get_referer(); if (true || !is_valid_url($referer)) { if (is_ajax_request()) { $alternative = make_ajax_url($alternative); } redirect_to($alternative); } else { if (is_ajax_request()) { $referer = make_ajax_url($referer); } redirect_to($referer); } // if }
<?php function is_ajax_request() { return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'BAWXMLHttpRequest'; } $ajax = is_ajax_request(); if (!$ajax) { ?> <html> <head> <style> img { display: block; max-width: 100%; height: auto; background-size: cover; backface-visibility: hidden; } section { width: 50%; } main { display: flex; opacity: 1; transition: opacity 0.5s ease-out; } main.loading { opacity: 0;
function smart_box($info) { if (is_json_request()) { $array = array(); $array['error_code'] = intval(20001); $array['error_message'] = $info; return ajax_echo(json_encode($array)); } elseif (is_ajax_request()) { return ajax_echo($info); } else { return info_page($info); } }
public function initFolder($refresh = false) { $path = is_object($this->folder) ? $this->folder->folders_path : $this->folder; $e = $refresh || is_ajax_request() ? array('refresh_memcached' => true) : null; return $this->folder = vf::getFolder($path, array('limit' => $this->limit), $e); }
function send_error($type, $info = null, $force_json = false) { if ($error = get_error($type)) { if ($info != null) { $error['message'] = $error['message'] . ' -' . $info; } } else { $error['message'] = $info; } //print_r( $error ); //send_json($error); if (is_json_request() || $force_json) { return send_json($error); } elseif (is_ajax_request()) { return render_ajax($error, 'info'); } else { return render_web($error, 'info'); } }
/** * Save a notification message for displaying on the subsequent page view * * Optionally supply a url for redirecting to before displaying the message * and/or an options array. * * Currently the options array only supports a 'class' entry for passing as * the second parameter to notification() * * @param string $message Message to display * @param string $redirect Url to redirect to (optional) * @param array $options Options array (optional) * @return void */ function set_notification($message, $redirect = null, $options = array()) { // Check options is an array if (!is_array($options)) { print_error('error:notificationsparamtypewrong', 'local_core'); } // Add message to options array $options['message'] = $message; // Add to notifications queue queue_append('notifications', $options); // Redirect if requested if ($redirect !== null) { // Cancel redirect for AJAX scripts. if (is_ajax_request($_SERVER)) { ajax_result(true, queue_shift('notifications')); } else { redirect($redirect); } exit(); } }
/** * Contruct controller and execute specific action * * @access public * @param string $controller_name * @param string $action * @return null */ static function executeAction($controller_name, $action) { $max_users = config_option('max_users'); if ($max_users && Users::count() > $max_users) { echo lang("error") . ": " . lang("maximum number of users exceeded error"); return; } ajx_check_login(); if (isset($_GET['active_project']) && logged_user() instanceof User) { $dont_update = false; if (GlobalCache::isAvailable()) { $option_value = GlobalCache::get('user_config_option_' . logged_user()->getId() . '_lastAccessedWorkspace', $success); if ($success) { $dont_update = $option_value == $_GET['active_project']; } } if (!$dont_update) { set_user_config_option('lastAccessedWorkspace', $_GET['active_project'], logged_user()->getId()); if (GlobalCache::isAvailable()) { GlobalCache::update('user_config_option_' . logged_user()->getId() . '_lastAccessedWorkspace', $_GET['active_project']); } } } Env::useController($controller_name); $controller_class = Env::getControllerClass($controller_name); if (!class_exists($controller_class, false)) { throw new ControllerDnxError($controller_name); } // if $controller = new $controller_class(); if (!instance_of($controller, 'Controller')) { throw new ControllerDnxError($controller_name); } // if if (is_ajax_request()) { // if request is an ajax request return a json response // execute the action $controller->setAutoRender(false); $controller->execute($action); // fill the response $response = AjaxResponse::instance(); if (!$response->hasCurrent()) { // set the current content $response->setCurrentContent("html", $controller->getContent(), page_actions(), ajx_get_panel()); } $response->setEvents(evt_pop()); $error = flash_pop('error'); $success = flash_pop('success'); if (!is_null($error)) { $response->setError(1, clean($error)); } else { if (!is_null($success)) { $response->setError(0, clean($success)); } } // display the object as json tpl_assign("object", $response); $content = tpl_fetch(Env::getTemplatePath("json")); tpl_assign("content_for_layout", $content); TimeIt::start("Transfer"); if (is_iframe_request()) { tpl_display(Env::getLayoutPath("iframe")); } else { tpl_display(Env::getLayoutPath("json")); } TimeIt::stop(); } else { return $controller->execute($action); } }
/** * Add an inline javascript * @return unknown_type */ function add_inline_script($script) { if (is_ajax_request()) { AjaxResponse::instance()->addInlineScript($script); } }
/** * Contruct controller and execute specific action * * @access public * @param string $controller_name * @param string $action * @return null */ static function executeAction($controller_name, $action) { $max_users = config_option('max_users'); if ($max_users && Contacts::count() > $max_users) { echo lang("error").": ".lang("maximum number of users exceeded error"); return; } ajx_check_login(); Env::useController($controller_name); $controller_class = Env::getControllerClass($controller_name); if(!class_exists($controller_class, false)) { throw new ControllerDnxError($controller_name); } // if $controller = new $controller_class(); if(!instance_of($controller, 'Controller')) { throw new ControllerDnxError($controller_name); } // if if (is_ajax_request()) { // if request is an ajax request return a json response // execute the action $controller->setAutoRender(false); $controller->execute($action); // fill the response $response = AjaxResponse::instance(); if (!$response->hasCurrent()) { // set the current content $response->setCurrentContent("html", $controller->getContent(), page_actions(), ajx_get_panel()); } $response->setEvents(evt_pop()); $error = flash_pop('error'); $success = flash_pop('success'); if (!is_null($error)) { $response->setError(1, clean($error)); } else if (!is_null($success)) { $response->setError(0, clean($success)); } // display the object as json tpl_assign("object", $response); $content = tpl_fetch(Env::getTemplatePath("json")); tpl_assign("content_for_layout", $content); TimeIt::start("Transfer"); if (is_iframe_request()) { tpl_display(Env::getLayoutPath("iframe")); } else { tpl_display(Env::getLayoutPath("json")); } TimeIt::stop(); } else { return $controller->execute($action); } } // executeAction
function send_error($type, $info = null, $force_json = false) { if ($type == null) { $error['message'] = $info; } elseif ($error = get_error($type)) { if ($info != null) { $error['message'] = $error['message'] . ' -' . $info; } } $error['created'] = date("Y-m-d H:i:s"); //print_r( $error ); //send_json($error); if (is_json_request() || $force_json || c('api_server_only')) { return send_json($error); } elseif (is_ajax_request()) { return render_ajax($error, 'info'); } else { return render_web($error, 'info'); } }