public function Render($form = "", $response_location = "", $url = "", $args = "") { $errorMsg = ''; $errors = FALSE; $Load = new Load(); if (function_exists('is_empty') == FALSE) { // Load validate helper $Load->Helper('validate'); } if (is_empty($form) == FALSE) { $this->form = $form; } if (is_empty($response_location) == FALSE) { $this->response_location = $response_location; } if (is_empty($url) == FALSE) { $this->url = $url; } if (is_empty($args) == FALSE) { $this->args = $args; } if (is_empty($this->form)) { $errorMsg .= ' form requerido :$obj-> Form("id-form")<br /> '; $errors = TRUE; } if (is_empty($this->response_location)) { $errorMsg .= ' response_location requerido : $obj-> ResponseLocation("id-div-location")<br /> '; $errors = TRUE; } if (is_empty($this->url)) { $errorMsg .= ' url requerida : $obj-> Url("Controller/Action")<br /> '; $errors = TRUE; } if ($errors == TRUE) { echo 'Error:<br />' . $errorMsg; return FALSE; } else { // Crear respuesta $butonsCode = $this->RenderButtons(); $params = 'form:' . $this->form . ';url:' . $this->url . ';args:' . $this->args . ';'; $fx = new ajax('submit', $this->response_location, $params); $Result = ' <script type="text/javascript"> <!-- ' . $butonsCode . ' $("#' . $this->form . '").validate({ submitHandler: function(form) { ' . $fx->render() . ' return false; },invalidHandler: function(form, validator){ var errors = validator.numberOfInvalids(); if (errors) { alert("Por favor, llena los campos obligatorios");} } }); //--> </script>'; return $Result; } }
public function action_files() { $files = array(); $limit = arr::get($_GET, 'limit', 10); $offset = arr::get($_GET, 'offset', 0); $query = ORM::factory('File'); if (arr::get($_GET, 'tags', false)) { $tags = arr::get($_GET, 'tags'); if (arr::get($_GET, 'matchAll', false) == "true") { $tagsquery = DB::select('files_tags.file_id')->from('files_tags')->where('files_tags.tag_id', 'IN', $tags)->group_by('files_tags.file_id')->having(DB::expr('COUNT(files_tags.file_id)'), '=', count($tags))->execute(); //die(var_dump($tagsquery)); } else { $tagsquery = DB::select('files_tags.file_id')->distinct(true)->from('files_tags')->where('files_tags.tag_id', 'IN', $tags)->execute(); //die(var_dump($tagsquery)); } if ((bool) $tagsquery->count()) { $ids = array(); foreach ($tagsquery as $q) { $ids[] = arr::get($q, 'file_id'); //$files[] = ORM::factory('File', arr::get($q, 'file_id'))->info(); } $query = $query->where('id', 'IN', $ids); } else { // Empty resultset ajax::success('ok', array('files' => array())); } } $query = $query->order_by('created', 'DESC')->limit($limit)->offset($offset)->find_all(); if ((bool) $query->count()) { foreach ($query as $file) { $files[] = $file->info(); } } ajax::success('ok', array('files' => $files)); }
function app_event_test_ajax1($page, $values) { global $config; error_log("@app_event_test_ajax1 =================="); error_log(print_r($values, true)); $a = array(array("caption" => "Test1", "value" => 90), array("caption" => "Test2", "value" => 91), array("caption" => "Test3", "value" => 92)); ajax::sendJSON($a); }
public static function loadRoute() { $r = array('action' => 'default', 'values' => array(), 'method' => 'get', 'ajax' => false, 'view' => 'default'); if (isset($_SERVER['REQUEST_METHOD'])) { $method = strtoupper($_SERVER['REQUEST_METHOD']); } else { $method = 'CLI'; } if ($method == 'GET') { $r['values'] = $_GET; if (isset($_GET['_view'])) { $r['view'] = $_GET['_view']; } } elseif ($method == 'POST') { $r['values'] = $_POST; $r['method'] = 'post'; if (isset($_POST['_view'])) { $r['view'] = $_POST['_view']; } } elseif ($method == 'CLI') { global $argv; $r['method'] = 'cli'; $r['values'] = $argv; } $cfg_ajax_test = array(array('field' => 'ajax', 'data_type' => 'http', 'return_type' => 'any', 'action' => 'ajax'), array('field' => 'json', 'data_type' => 'http', 'return_type' => 'json', 'action' => 'json'), array('field' => 'jsonrpc', 'data_type' => 'jsonrpc', 'return_type' => 'json', 'action' => 'method'), array('field' => 'callback', 'data_type' => 'http', 'return_type' => 'jsonp', 'action' => 'method'), array('field' => 'jsonpCallback', 'data_type' => 'http', 'return_type' => 'jsonp', 'action' => 'method')); $ajax_type = null; if (isset($_REQUEST)) { foreach ($cfg_ajax_test as $test) { if (isset($_REQUEST[$test['field']])) { $ajax_type = $test; break; } } } if (!is_null($ajax_type)) { $r['ajax'] = true; $r['method'] = strtolower($method); $r['action'] = strtolower($_REQUEST[$ajax_type['action']]); $r['view'] = 'default'; if ($ajax_type['data_type'] == 'http') { $r['values'] = $r['method'] == 'get' ? $_GET : $_POST; } elseif ($ajax_type['data_type'] == 'jsonrpc') { $r['values'] = json_decode(file_get_contents('php://input')); $r['action'] = $r['values']['method']; } if ($ajax_type['return_type'] == 'json' || $ajax_type['return_type'] == 'jsonp') { ajax::loadAJAX($r['values']); ajax::setType($ajax_type['return_type']); } //error_log(print_r($ajax_type, true)); } if (isset($r['values']['a'])) { $r['action'] = strtolower($r['values']['a']); } return $r; }
public function initialize() { $this->template = template::getInstance(); if ($this->ajax) { $this->content = ajax::getInstance(); } else { $this->content = index::getInstance(); } $this->content->initialize(); }
function ajax() { global $user, $tenjin, $config_q; if ($_GET["vote_for"] == 1) { echo quote::vote_for(array("quote_id" => $_GET["q_id"], "user_id" => $user->data["user_id"], "ip" => $_SERVER['REMOTE_ADDR'])); } else { if ($_GET["vote_against"] == 1) { echo quote::vote_against(array("quote_id" => $_GET["q_id"], "user_id" => $user->data["user_id"], "ip" => $_SERVER['REMOTE_ADDR'])); /* $cv = new vote(array( "quote_id" => $_GET["q_id"], "user_id" => $user->data["user_id"], "ip" => $_SERVER['REMOTE_ADDR'], )); $cv->vote_for(); */ } } if ($_GET["get_quote_for_facebook"] == 1) { echo ajax::get_quote_for_facebook($_GET["q_id"]); } if ($_GET["get_quotes_for_facebook"] == 1) { quote::get_random_quotes_for_facebook(); die; } /* a strange kind of acl but ok from here on you have to have permissions */ if (!can_access()) { return true; } if ($_GET["dialog__add_quote"] == 1) { $tenjin_template = $config_q["template_dir"] . '/dialog__add_quote.phtml'; $output = $tenjin->render($tenjin_template, $context); echo $output; } elseif ($_GET["get_tags"] == 1) { /*$this->format_tags_as_links(array( "tags" => $_POST["tags"], ));*/ } elseif ($_GET["format_tags_as_links"] == 1) { $tag = new tag(); echo $tag->format_tags_as_links($_POST["tags"]); } elseif ($_GET["set_tags"] == 1) { $this->set_tags(array("tags" => $_POST["tags"], "q_id" => $_POST["q_id"])); } elseif ($_GET["get_quote"] == 1) { echo "get_quote"; } elseif ($_GET["set_quote"] == 1) { echo "set_quote"; } elseif ($_GET["get_category"] == 1) { $this->get_category(array("category_id" => $_POST["category_id"], "q_id" => $_POST["q_id"])); } elseif ($_GET["set_category"] == 1) { $this->set_category(array("category_id" => $_POST["category_id"], "q_id" => $_POST["q_id"])); } }
public function autocomplete() { $directories = array(); $path_prefix = Input::instance()->get("q"); foreach (glob("{$path_prefix}*") as $file) { if (is_dir($file) && !is_link($file)) { $directories[] = html::clean($file); } } ajax::response(implode("\n", $directories)); }
public function action_get() { $visitors = ORM::factory('Visitor')->find_all(); $varray = array(); if ((bool) $visitors->count()) { foreach ($visitors as $visitor) { $varray[] = $visitor->info(); } } ajax::success('ok', array('visitors' => $varray)); }
public function autocomplete() { $tags = array(); $tag_parts = explode(",", Input::instance()->get("term")); $tag_part = ltrim(end($tag_parts)); $tag_list = ORM::factory("tag")->where("name", "LIKE", Database::escape_for_like($tag_part) . "%")->order_by("name", "ASC")->limit(100)->find_all(); foreach ($tag_list as $tag) { $tags[] = (string) html::clean($tag->name); } ajax::response(json_encode($tags)); }
public function action_get() { $errors = ORM::factory('Error')->order_by('time', 'DESC')->limit(10)->find_all(); $errs = array(); if ((bool) $errors->count()) { foreach ($errors as $e) { $errs[] = array('id' => $e->id, 'type' => $e->type, 'ip' => $e->ip, 'when' => date('d/m/Y H:i', $e->time), 'url' => $e->url); } } ajax::success('', array('errors' => $errs)); }
public function autocomplete() { $directories = array(); $path_prefix = Input::instance()->get("term"); foreach (glob("{$path_prefix}*") as $file) { if (is_dir($file) && !is_link($file)) { $directories[] = (string) html::clean($file); } } ajax::response(json_encode($directories)); }
public function action_get() { $content = ORM::factory('Content')->order_by('hits', 'DESC')->limit(10)->find_all(); $contents = array(); if ((bool) $content->count()) { foreach ($content as $c) { $contents[] = array('id' => $c->id, 'title' => $c->title, 'type' => $c->contenttype->display, 'hits' => $c->hits); } } ajax::success('', array('contents' => $contents)); }
public function autocomplete() { $tags = array(); $tag_parts = explode(",", Input::instance()->get("q")); $limit = Input::instance()->get("limit"); $tag_part = ltrim(end($tag_parts)); $tag_list = ORM::factory("tag")->where("name", "LIKE", "{$tag_part}%")->order_by("name", "ASC")->limit($limit)->find_all(); foreach ($tag_list as $tag) { $tags[] = html::clean($tag->name); } ajax::response(implode("\n", $tags)); }
public function action_message() { $message = ORM::factory('Message', $this->request->param('id')); if (!$message->loaded()) { ajax::redirect('#/messages', __('The message wasn\'t found. Has it already been deleted?')); } $info = $message->info(); if ($message->read == 0) { $message->set_read(); } reply::ok(View::factory('Cms/Messages/message', array('message' => $message)), 'messages', array('viewModel' => 'viewModels/Messages/message', 'message' => $info)); }
protected static function BackendAjax() { $sort = type::post('array', 'array'); $sql = sql::factory(); $sql->setTable('metainfos'); foreach ($sort as $s => $id) { $sql->setWhere('id=' . $id); $sql->addPost('sort', $s + 1); $sql->update(); } ajax::addReturn(message::success(lang::get('save_sorting'), true)); }
public function action_delete() { $role = ORM::factory('Role', arr::get($_POST, 'id')); if (!$role->loaded()) { ajax::error(__('Role not found. Has it been deleted already?')); } try { $role->delete(); ajax::info(__('Deleted')); } catch (exception $e) { ajax::error(__('An uncaught error occurred: :error', array(':error' => $e->getMessage()))); } }
public function action_delete() { $vacation = ORM::factory('Vacation', arr::get($_POST, 'id', '')); if (!$vacation->loaded()) { ajax::error('Ferien blev ikke fundet. Er den allerede blevet slettet?'); } try { $vacation->delete(); ajax::success(); } catch (exception $e) { ajax::error('Der opstod en fejl: ' . $e->getMessage()); } }
public function action_toggleread() { $message = ORM::factory('Message', arr::get($_POST, 'id')); if (!$message->loaded()) { ajax::error(__('The message wasn\'t found. Has it already been deleted?')); } $message->read = arr::get($_POST, 'read', '0'); try { $message->save(); ajax::success(); } catch (exception $e) { ajax::error(__('An uncaught error occurred: :error', array(':error' => $e->getMessage()))); } }
public function action_getautosave() { if (!user::logged()) { ajax::error('You must be logged in'); } $user = user::get(); $autosave = ORM::factory('Page')->where('user_id', '=', $user->id)->where('type', '=', 'autosave')->find(); $content = ''; if ($autosave->loaded() && $autosave->content != '') { $content = $autosave->decode($autosave->content); $autosave->delete(); } ajax::success('', array('content' => $content, 'md5' => md5($content))); }
public function action_twitter() { $redirect = ''; try { $connection = new TwitterOAuth(arr::get($this->creds, 'key'), arr::get($this->creds, 'secret')); $tmp = $connection->getRequestToken('http://morningpages.net/auth/twittercallback'); Session::instance()->set('twitter_oauth_token', arr::get($tmp, 'oauth_token', '')); Session::instance()->set('twitter_oauth_token_secret', arr::get($tmp, 'oauth_token_secret', '')); $redirect = $connection->getAuthorizeURL($tmp); } catch (exception $e) { ajax::error('Oh no! Something went wrong and we couldn\'t get a hold of Twitter! They might be too busy right now. You can either wait a bit and see if Twitter wakes up or use another way of logging in.'); site::redirect(); } site::redirect($redirect); }
public function action_get() { $contenttype = ORM::factory('Contenttype', arr::get($_GET, 'id', '')); if (!$contenttype->loaded()) { ajax::error(__('Contenttype not found. Has it been deleted?')); } $items = array(); $contents = $contenttype->contents->find_all(); if ((bool) $contents->count()) { foreach ($contents as $content) { $items[] = array('id' => $content->id, 'title' => $content->title()); } } ajax::success('', array('id' => $contenttype->id, 'type' => $contenttype->type, 'slug' => $contenttype->slug, 'icon' => $contenttype->icon, 'hierarchical' => $contenttype->hierarchical, 'has_categories' => $contenttype->has_categories, 'has_tags' => $contenttype->has_tags, 'has_timestamp' => $contenttype->has_timestamp, 'has_thumbnail' => $contenttype->has_thumbnail, 'has_author' => $contenttype->has_author, 'display' => $contenttype->display, 'items' => $items)); }
public static function load() { //Define Theme depend to session define('THEME_PATH', MPATH_THEMES . Mcfg::get('theme')); //exit(THEME_PATH); $ajax = MReq::tg('ajax') == 1 ? 1 : 0; if ($ajax == 1) { //Excute app on ajax ajax::load(); } else { //Excute app on theme $theme_path = THEME_PATH; $theme = session::get('userid') == FALSE ? $theme_path . '/mainns.php' : $theme_path . '/main.php'; include $theme; } }
function app_event_coteja_nombre($page, $values) { error_log("here1"); ///codigo super complejo.... if ($values['email'] == "*****@*****.**") { $respuesta = array(); $respuesta['resultado'] = true; $respuesta['nombre'] = "Joe"; $respuesta['apellidos'] = "Cuevas"; } else { $respuesta = array(); $respuesta['resultado'] = false; $respuesta['error'] = "No lo encontre"; } error_log("me enviaron :" . $_SERVER['REMOTE_ADDR'] . ':' . print_r($values, true)); ajax::sendJSON($respuesta); }
public function action_takechallenge() { if (!user::logged()) { ajax::error('You must be logged in to sign up for the challenge!'); } $user = user::get(); if ($user->doing_challenge()) { ajax::error('You are already doing the challenge! Complete it first, then sign up again.'); } $challenge = ORM::factory('User_Challenge'); $challenge->user_id = $user->id; $challenge->start = $user->timestamp(); $challenge->progress = 0; if ($user->wrote_today()) { $challenge->progress = 1; } $challenge->save(); $user->add_event('Signed up for the 30 day challenge!'); ajax::success('Awesome! You have signed up for the challenge! Good luck!', array('progress' => $challenge->progress)); }
public function action_info() { maintenance::delete_inactive_visitors(); $messages = 0; if (user::logged()) { $user = user::get(); $messages += $user->messages->where('read', '=', '0')->count_all(); $roles = $user->roles->find_all(); $roleids = array(); if ((bool) $roles->count()) { foreach ($roles as $role) { $roleids[] = $role->id; } } if ((bool) count($roleids)) { $messages += ORM::factory('Message')->where('role_id', 'in', $roleids)->where('read', '=', '0')->where('user_id', '!=', $user->id)->count_all(); } } ajax::success('', array('current_visitors' => $visitors = ORM::factory('Visitor')->count_all(), 'unread_messages' => $messages)); }
public function action_create() { $content = ORM::factory('Content', arr::get($_POST, 'parent', '')); if (!$content->loaded()) { ajax::error('The content wasn\'t found. Has it been deleted?'); } $title = arr::get($_POST, 'title', false); if (!$title) { $title = $content->title; } $clone = $content->copy(); $clone->splittest = $content->id; $clone->splittest_title = $title; try { $clone->save(); ajax::success('Splittest created', array('splittest' => array('id' => $clone->id, 'title' => $clone->splittest_title))); } catch (exception $e) { ajax::error('An error occurred and the splittest couldn\'t be created. The site said: ' . $e->getMessage()); } }
public function action_add() { $title = arr::get($_POST, 'title', false); if (!$title || empty($title)) { ajax::error('A title is required'); } $option = ORM::factory('Option'); $option->optiongroup_id = arr::get($_POST, 'group'); $option->title = $title; $option->key = arr::get($_POST, 'key', ''); $option->type = arr::get($_POST, 'type', 'text'); $option->description = arr::get($_POST, 'description', ''); $option->editable = arr::get($_POST, 'editable', '1'); try { $option->save(); ajax::success('Option added', array('option' => $option->info())); } catch (exception $e) { ajax::error('Something went wrong: ' . $e->getMessage()); } }
static function getInstance() { if (is_null(ajax::$instance)) { $session = session::getInstance(); $zone = $session->getData('zone'); if (!$zone) { $zone = ZONE_DEFAULT; $session->setData('zone', $zone); } if ($zone && file_exists(LOCAL_PATH . LOCAL_DIR . 'module/' . $zone . '/ajax.php')) { require_once LOCAL_PATH . LOCAL_DIR . 'module/' . $zone . '/ajax.php'; } if (class_exists('module_' . $zone . '_ajax')) { $class = 'module_' . $zone . '_ajax'; ajax::$instance = new $class(); } else { ajax::$instance = new ajax(); } } return ajax::$instance; }
public function action_new() { $contenttype = $this->check_contenttype(); $content = ORM::factory('Content'); $content->user_id = user::get()->id; $content->contenttype_id = $contenttype->id; $typeid = $this->request->param('typeid'); $content->contenttypetype_id = isset($typeid) && !empty($typeid) ? $typeid : '0'; $content->title = ''; $content->status = 'draft'; $content->created = time(); try { $content->save(); $blocks = $contenttype->blocktypes->where('min', '>', 0)->where('parent', '=', 0)->where('contenttypetype_id', '=', $content->contenttypetype_id)->find_all(); if ((bool) $blocks->count()) { $loop = 0; foreach ($blocks as $block) { for ($i = 0; $i < $block->min; $i++) { $contentblock = ORM::factory('Block'); $contentblock->content_id = $content->id; $contentblock->blocktype_id = $block->id; $contentblock->order = $loop; $contentblock->save(); $loop++; } } } //cms::redirect('content/edit/'.$content->id); ajax::success('ok', array('id' => $content->id)); } catch (HTTP_Exception_Redirect $e) { throw $e; } catch (exception $e) { notes::add('error', 'Der opstod en fejl: ' . $e->getMessage()); echo 'error'; //cms::redirect('content/index/'.$contenttype->id); } }
public function action_xml() { if (!user::logged()) { ajax::error('You must be logged in to use this feature'); } $user = user::get(); $pages = $user->pages->where('type', '=', 'page')->find_all(); $xml = '<?xml version="1.0" encoding="UTF-8"?>'; $xml .= '<channel>'; $namelen = strlen($user->username); $possessive = $user->username . "'s"; if (substr($user->username, $namelen - 1, $namelen) == 's') { $possessive = $user->username . "'"; } $xml .= '<title>' . $possessive . ' morning pages</title>'; $xml .= '<language>en-US</language>'; $xml .= '<author>' . $user->username . '</author>'; $xml .= '<pages>'; if ((bool) $pages->count()) { foreach ($pages as $page) { $xml .= '<page>'; $xml .= '<published>'; $xml .= '<date>' . $page->daystamp() . '</date>'; $xml .= '<timestamp>' . $page->created . '</timestamp>'; $xml .= '</published>'; $xml .= '<content><![CDATA[' . $page->rawcontent() . ']]></content>'; $xml .= '<wordcount>' . $page->wordcount . '</wordcount>'; $xml .= '</page>'; } } $xml .= '</pages>'; $xml .= '</channel>'; $this->response->headers('Content-Type', 'text/xml'); $this->response->body($xml); $this->response->send_file(true, 'pages.xml'); }