/** * Function is called to load the requested page, check permissions and set up global Smarty variables. * * @param string $request p_page_name to find in database * @return RoutingEngine */ public function initialize($request) { $request = strtolower($request); if (substr($request, 0, 1) == "/") { $request = substr($request, 1); } if (substr($request, -1, 1) == "/") { $request = substr($request, 0, -1); } $this->_request_path = $request; $paths = explode("/", $this->_request_path); if (in_array($paths[0], self::$controllers)) { $this->controller = $paths[0]; $action = array_safe($paths, 1); $params = array_slice($paths, 2); } else { $this->controller = "home"; $action = $paths[0]; $params = array_slice($paths, 1); } $this->controller_full = "Controller_" . $this->controller; if (!empty($action) && $this->_checkAction($action)) { $this->action = $action; $this->_request_path = $this->controller . "/{$this->action}"; } else { $this->action = "index"; $this->_request_path = $this->controller . "/index"; } //$this->page = Page::getPage($this->_request_path); $this->page = new Page(); $this->page->page_name = $this->_request_path; $this->_processParamters($params); $this->start_time = $_SERVER["TIME_START"]; return $this; }
function smarty_function_modules($params, &$smarty) { $mod_con = new Controller_Module($params, RoutingEngine::getSmarty()); $mod_names = array_safe($params, "list"); $mod_list = explode(",", $mod_names); $modules = array(); $unplaced_modules = array(); $counts = array("3" => 0, "4" => 0, "5" => 0); foreach ($mod_list as $mod_code) { $mod_name = Module::$hash[$mod_code]; if (!method_exists($mod_con, $mod_name)) { continue; } $module = $mod_con->{$mod_name}(); if ($module->size) { $modules[$module->size][] = $module; $counts[$module->size]++; } else { $unplaced_modules[] = $module; } } foreach ($unplaced_modules as $module) { asort($counts); current($counts); $modules[key($counts)][] = $module; $counts[key($counts)]++; } RoutingEngine::getSmarty()->assign("modules", $modules); return RoutingEngine::getSmarty()->fetch("modules/module_master.tpl"); }
function handleNewBlock($tag) { //TODO: Consider moving modifiers to their own system. $command = $tag->command; //looks for the | (pipe) in order to determine modifier. $mod_regex = "/^(.*)[|](.*?)(?::(.*))?\$/"; $count = preg_match($mod_regex, $tag->command, $matches); if ($count) { $var = array_safe($matches, 1); $mod = array_safe($matches, 2); $param = array_safe($matches, 3); if (substr($mod, 0, 1) == "@") { $mod = substr($mod, 1); $command = $mod . "(" . $var . ")"; $allowed = false; } else { $allowed = $this->_compiler->addFunctionToSource($mod, "modifier"); if ($allowed) { if ($param) { $command = "template_modifier_" . $mod . "({$var}, {$param})"; } else { $command = "template_modifier_" . $mod . "({$var})"; } } else { $command = $var; } } } return "<?php echo {$command}; ?>"; }
/** * Function to get the directory of a template. * * @param string $template_name Template name. * @return string Resolved directory name. */ public function getTemplateDir($template_name) { //removes the ending backslash $regex = "/(.*(?:\\/|\\\\)).*\\..*\$/"; $matches = array(); preg_match($regex, $template_name, $matches); $dir = array_safe($matches, 1, ""); return $this->_template->compile_dir . "/" . $dir; }
public function update() { RoutingEngine::setPage("runnDAILY User Update", "PV__300"); $format = array_safe($_POST, "format", "html"); $user = new User($_POST); if ($user->updateUserInDB()) { if ($format == "ajax") { exit("success"); } } Page::redirect("/admin/user"); }
public function action_elevation_add_packed() { if ($_FILES["packed_hdr"]) { move_uploaded_file($_FILES["packed_hdr"]["tmp_name"], SYSTEM_ROOT . "/elev_packed.hdr"); } if ($_FILES["packed_flt"]) { move_uploaded_file($_FILES["packed_flt"]["tmp_name"], SYSTEM_ROOT . "/elev_packed.flt"); } $region = array_safe($_POST, "region_name", "Elevation data"); Elevation::addElevationToDatabase(SYSTEM_ROOT . "/elev_packed", 1, $region); unlink(SYSTEM_ROOT . "/elev_packed.hdr"); unlink(SYSTEM_ROOT . "/elev_packed.flt"); Notification::add("Elevation data has been added"); Page::redirect("/admin/elevation"); }
public function action_save() { RoutingEngine::setPage("runnDAILY Training Save", "PV__300"); $t_item = new TrainingLog($_POST); if (array_safe($_POST, "t_rid") == "") { $t_item->rid = null; } if ($t_item->createItem()) { $affected_goals = Goal::getGoalIdsForUserInRange(User::$current_user->uid, $t_item->date); if ($affected_goals) { Goal::updatePercentForList($affected_goals); } Page::redirect("/training/"); } Page::redirect("/training/"); }
/** * Constructor is the entry point to generate tag parts. * * @param string $tag The stuff inside {{here}}. * @return Template_TagData Returns itself. */ function __construct($tag) { //check for echo only $_echo = "/^((?:[\$].*)|(?:\\w::.*))/"; $echo = preg_match($_echo, $tag, $_echo_match); if ($echo) { $this->_special = '$'; $_nonBlock = $_echo_match[1]; $this->block = "echo"; } else { //parses out the tag parts. $_specialRegex = "/^(\\W)?\\s*(\\S+)(?:\\s+(.*?))?\\s*\$/s"; $_matches = array(); $_isSpecial = preg_match($_specialRegex, $tag, $_matches); $this->_special = array_safe($_matches, 1, ""); $this->block = array_safe($_matches, 2, ""); $_nonBlock = array_safe($_matches, 3, ""); } $this->_parseCommandAndParams($_nonBlock); return $this; }
error_reporting(E_ALL); ini_set('display_errors', '1'); require_once 'mysql.php'; require_once 'search_chemicalDatabase.php'; require_once 'getNames.php'; require_once 'getDatabaseIDs.php'; // $_POST['query'] contains the raw query here, split it process it boil it salt it serve it $queryString = trim(strtoupper($_POST['query']), " \t,"); $queryString = preg_replace('/;\\s+/', ';', $queryString); $queryString = preg_replace('/\\s+;/', ';', $queryString); $query = explode(";", $queryString); // Find where chemicals, genes and GOterms are in Query $chemicals = array_safe(array_intersect($query, array_map('strtoupper', getChemicalList()))); $genes = array_safe(array_intersect($query, array_map('strtoupper', getGeneList()))); $GOterms = array_safe(array_intersect($query, array_map('strtoupper', getGOList()))); $databaseIDs_chemicals = getChemicalDatabaseIDs($chemicals); $databaseIDs_genes = getGeneDatabaseIDs($genes); $databaseIDs_GOs = getGeneOntologyDatabaseIDs($GOterms); $results = array(0 => search_info_chemicals($databaseIDs_chemicals), 1 => search_info_genes($databaseIDs_genes), 2 => search_info_GO_terms($databaseIDs_GOs)); //echo $queryString; if ($queryString == "" || $queryString == "NAME OF CHEMICALS TO SEARCH GOES HERE, SEPARATED BY;") { echo "NO_SEARCH"; } else { if (count($chemicals) == 0 && count($genes) == 0 && count($GOterms) == 0) { echo "INVALID_SEARCH"; } else { if (count($results[0]) == 0 && count($results[1]) == 0 && count($results[2]) == 0) { echo "EMPTY"; } else { echo json_encode($results);
/** * Gets the permissions for the current user. * This searches the page perm code first. * Then it search for permission groups. * Finally it gets things from the user_roles table. * It does not handle do_not_allow yet. * * @return array */ function getPermissions() { $this->permissions = array(); $this->_addPermission($this->page_perm); //get the groups table first $stmt = Database::getDB()->prepare("\r\n\t\t\tSELECT pr_code, g_gid, pgr_allow\r\n\t\t\tFROM users_permission_groups\r\n\t\t\tLEFT JOIN permission_groups_roles USING(pg_id)\r\n\t\t\tWHERE\r\n\t\t\t\tu_uid = ?\r\n\t\t"); $stmt->bind_param("i", User::$current_user->uid); $stmt->execute(); $stmt->store_result(); while ($row = $stmt->fetch_assoc()) { $this->_addPermission($row["pr_code"], array_safe($row, "g_gid")); } $stmt->close(); //get the user individual ones $stmt = Database::getDB()->prepare("\r\n\t\t\tSELECT pr_code, g_gid, ur_allow\r\n\t\t\tFROM users_roles\r\n\t\t\tWHERE\r\n\t\t\t\tu_uid = ?\r\n\t\t"); $stmt->bind_param("i", User::$current_user->uid); $stmt->execute(); $stmt->store_result(); while ($row = $stmt->fetch_assoc()) { $this->_addPermission($row["pr_code"], array_safe($row, "g_gid")); } $stmt->close(); return $this->permissions; }
public static function addElevationToFile($filename, $skip = 4) { $ini = self::_readConfigFile($filename); $rows = $ini["nrows"]; $cols = $ini["ncols"]; $xll_corner = $ini["xllcorner"]; $yll_corner = $ini["yllcorner"]; $size = $ini["cellsize"]; $top = array_safe($ini, "top", $yll_corner + $size * ($rows + 1)); $left = array_safe($ini, "left", $xll_corner); //read the data file $handle = fopen("{$filename}.flt", "rb"); $handle_out = fopen("{$filename}_out.txt", "w+"); $lat = $top; $lng = $left; $elev = 0; fwrite($handle_out, "lat\tlng\telev\r\n"); set_time_limit(120); for ($i = 0; $i < $rows; $i++) { $contents = fread($handle, $cols * 4); if ($i % $skip) { continue; } //unpack is 1-indexed $arr = unpack("f*", $contents); $lng = $left; for ($j = 0; $j < $cols; $j += $skip) { $elev = round($arr[$j + 1], 5); //moving to the right on the map fwrite($handle_out, "{$lat}\t{$lng}\t{$elev}\r\n"); $lng += $size * $skip; } //moving down the map $lat -= $size * $skip; } fclose($handle); fclose($handle_out); return true; }