function Project() { $this->loadlib(); $this->db = $_SERVER['HTTP_HOST'] == "localhost" ? new Dblib("localhost", "artcmsdb", "root", "") : new Dblib(HOST, DBNAME, DBUSER, DBPASS); if ($this->db->err != "") { Errors::report($this->db->err); } $this->tp = new Template(); session_start(); }
/** * * Checks for existence, then loads template * * @param [string] Filename of the template to be loaded * @param [mixed] Variables to be passed to the template */ function load($template, $vars = array()) { global $twig, $template_vars, $config; $template_vars['stylsheets'] = self::fetch_extras("css"); $template_vars['javascript'] = self::fetch_extras("js"); if (!is_array($vars)) { Errors::report("Template vars passed were not in array format"); } if (!file_exists($config['template_dir'] . '/' . $template)) { Errors::report("Template file {$template} not found in template directory: " . $config['template_dir']); } $vars = array_merge($template_vars, $vars); echo $twig->render($template, $vars); }
<?php if (Session::is_group_user('Sustainer Admin')) { $slots = SustainerSlots::get_all(); foreach ($slots as $slot) { $compareValue = "slot-" . $slot->get_day() . "-" . $slot->get_time(); if ($compareValue == $_REQUEST["updateid"]) { $prerecordText = "Currently this hour is scheduled with the <b>" . Playlists::get_by_id($slot->get_playlist_id())->get_name() . "</b> playlist"; if ($slot->get_audio_id() != NULL) { $prerecordText .= " <i>AND</i> the prerecord <b>" . Prerecs::get_by_id($slot->get_audio_id())->get_title() . "</b> is scheduled."; } else { $prerecordText .= " <b>AND</b> there is no prerecord scheduled."; } break; } } if (Errors::occured()) { http_response_code(400); exit(json_encode(array("error" => "Something went wrong. You may have discovered a bug!", "detail" => Errors::report("array")))); Errors::clear(); } else { exit(json_encode(array('response' => 'success', 'status' => $prerecordText))); } } else { http_response_code(403); exit(json_encode(array('error' => 'Permission denied.'))); }
/** * Sets the login information of a user from cookie */ function setLoginInfo() { $islogin = false; if (!isset($_COOKIE[$ckname])) { return; } $qr = $con->db->selectData("select email, validator, ustatus, utype, pass from users where validator = '{$val}'"); if ($qr === false) { Errors::report($db->err); return $islogin; } if (count($qr) == 0) { return $islogin; } if ($qr[0]['validator'] != $_COOKIE['ZakirCookie']) { return $islogin; } if (!class_exists('Users')) { Errors::report("'Users' class do not exist"); return false; } $l = new Users(trim($qr[0]['utype']), trim($qr[0]['pass']), $con->db); if ($l->isLoged() && is_object($l)) { $_SESSION['login'] = $l; $islogin = true; } return $islogin; }
$al->tp->assign('rep', $rep); } } $al->tp->assign('islogin', $islogin); if ($l->isLoged() == true) { $_SESSION['login'] = $l; /* Setting Remember Me cookie */ $rem = $remember[0]; if ($rem == 1) { $exptime = mktime() . time() + 60 * 60 * 24 * 4; //4days $val = $l->getValidator(); setcookie($ckname, $val, $exptime); } /* Update Last login date */ $fields = array('date_lastlogin'); $values = array(date("Y-m-d G:i:s")); $isUpdated = setRow('users', $fields, $values, 'update', $al->db, $l->getId()); if (!$isUpdated) { Errors::report("Last login date was not updated."); } /* Loading user home after login */ $isExecuted = getUserHomeByUserType($l->utype, $email, $al); } if ($isExecuted === false) { $al->tp->assign('body', $body); $al->tp->assign('title', $title); $al->tp->display('main.tpl'); }
/** * This function configures the fck editor for the article editing mode */ function configFckEditMode($body, $divIdName = 'bodytxt', $toolbar = "ArticleToolbar", $width = 720, $height = 500) { if ($divIdName == "" || $toolbar == "" || $width == "" || $height == "" || $body == "") { Errors::report("Values are missing: div id: {$divIdName}, toolbarName: {$toolbar}, width: {$width} and height: {$height} "); return false; } if ($body == "") { Errors::report("Body of editor text is missing."); return false; } try { $oFCKeditor = new FCKeditor($divIdName); $oFCKeditor->BasePath = URL . '/scripts/fckeditor/'; $oFCKeditor->Config["CustomConfigurationsPath"] = 'edconfig.js'; $oFCKeditor->Config['SkinPath'] = "skins/silver/"; $oFCKeditor->Width = $width; $oFCKeditor->Height = $height; $oFCKeditor->ToolbarSet = 'ArticleToolbar'; $oFCKeditor->Value = "" . $body . ""; $fckEditor = $oFCKeditor->CreateHtml(); } catch (Exception $ex) { Errors::report($ex->getMessage()); return false; } return $fckEditor; }
/** * * Handles the current request. Fails if unmatched path or Method/Function not found */ private function handle_request() { global $paths, $redirects, $config; $req_array = explode("/", $this->REQUEST['uri']['path']); // Top level routes (/something) if ($req_array[1] && empty($req_array[2])) { // Considering the Index class to be the top dog $index_methods = get_class_methods("Index"); // Full function to test against $_function = strtolower($this->REQUEST['method']) . '_' . $req_array[1]; // Cycle through index methods, seeking a match foreach ($index_methods as $route) { // There's a match for this method_function in the Index model if ($route == $_function) { $class = "Index"; $function = $req_array[1]; } } // There wasn't a match, but there is a route set that matches if (!$class && !empty($paths[$req_array[1]])) { $class = $paths[$req_array[1]]['class']; $function = "index"; // Still no matching class } elseif (!$class) { // If a model exists, it must be the index of that model if (class_exists("{$req_array['1']}")) { $class = $req_array[1]; $function = "index"; } else { // Otherwise it's a function of the global Index model $class = "Index"; $function = $req_array[1]; } } // Nothing is set, so homepage we go } elseif (empty($req_array[1])) { $class = "Index"; $function = "index"; // All secondary routes should be pretty straightforward (/something/else = Something::method_else) } else { $class = $req_array[1]; $function = !empty($req_array[2]) ? $req_array[2] : "index"; } // Path matching for secondary routes if (isset($paths[$class]) && $function !== "index") { $match = $paths[$class]; $class = $match['class']; $function = $match['function']; foreach ($req_array as $i => $req) { if ($i > 1) { $spot = isset($match['vars'][$i]) ? $match['vars'][$i] : $i; if ($this->REQUEST['method'] == "GET") { $_GET[$spot] = $req; } $this->REQUEST['params'][$spot] = $req; } } } // Grab the uri to check for set redirects $uri = rtrim($_SERVER['REQUEST_URI'], "/"); // Redirect away if (!empty($redirects[$uri])) { header("Location: " . $redirects[$uri]); } // This route's function $function = strtolower($this->REQUEST['method']) . '_' . $function; // Make sure the class (model) exists if (class_exists("{$class}")) { // Make sure the method (method_function) exists if (method_exists("{$class}", "{$function}")) { // Build request array $this->REQUEST['class'] = $class; $this->REQUEST['function'] = $function; $config['called'] = $function; // Call the desired route's Model:method_function $class::$function($this->REQUEST); } else { // No function for the model Errors::report("Function not found: {$class}::{$function}"); } } else { // No model found for route (probably won't happen as we're reverting to the index function) Errors::report("Method not found: {$class}"); } }
$rep .= "Your article has been added."; } else { $err .= "We are sorry. Your article was not added. Please try again."; } } else { if ($action == "edit") { $fields = array("title", "subtitle", "body", "remarks", "date_updated", "category_id", "meta_tags", "url"); $values = array(addslashes($arttitle), addslashes($subtitle), addslashes($bodytxt), addslashes($remarks), date("Y-m-d H:i:s"), $cat, addslashes($keywords), $arturl); $isUpdated = setRow('articles', $fields, $values, 'update', $al->db, $art_id); if ($isUpdated) { $rep .= "Article has been updated."; } else { $err .= "Your article was not updated. Please try again."; } } else { Errors::report("Invalid value for action varriable."); return; } } $al->tp->assign('rep', $rep); $al->tp->assign('err', $err); $al->tp->assign('title', 'List of articles'); $al->tp->assign('selMenu', 'article'); $catList = getTableData('categories', $al->db); if (is_string($catList)) { $al->tp->assign('rep', $catList); $catList = null; } if ($catList === false) { $catList = null; }
if (setRow('categories', $fields, $values, 'update', $al->db, $params[3]) === false) { break; } $al->tp->assign('rep', "The category permission for id = " . $params[3] . " has been updated."); } else { Errors::report("Parameter 3: " . $params[2] . " is invalid for category toggle operation."); break; } } else { Errors::report("Second parameter of url: " . $params[1] . " is not valid."); break; } } } if (!$al->tp->template_exists($tpl)) { Errors::report("Template file: {$tpl} is missing."); break; } $data = getTableData($table, $al->db); if (is_string($data)) { $al->tp->assign('rep', $data); $data = null; } if ($data === false) { $data = null; } $al->tp->assign('data', $data); $body = $al->tp->fetch('admin_menu.tpl'); $body .= $al->tp->fetch($tpl); $al->tp->assign('body', $body); $al->tp->display('admin.tpl');
$audio->set_year($_REQUEST["year"]); } $audio->set_title($_REQUEST["title"]); $audio->set_length_smpl(shell_exec("soxi -s \"" . $path . "/inbox/" . $md5 . ".flac\"")); $audio->set_md5($md5); $audio->set_archive($current_archive); $audio->set_filetype("flac"); if (!$audio->save()) { unlink($tempfile); die(json_encode(array("error" => "Failed to save audio entry to database.", "debug" => Errors::report("array")))); } if (!isset($_REQUEST["dir"])) { $audio->move_to_music_folder(); } if (isset($_REQUEST["artist"])) { $audio->add_artists(explode(";", $_REQUEST["artist"])); } $output = rename($path . "/inbox/" . $md5 . ".flac", $path . "/" . substr($md5, 0, 1) . "/" . $md5 . ".flac"); if ($output === false) { unlink($tempfile); die(json_encode(array("error" => "could not import file to audio archive", "debug" => Errors::report("array")))); } unlink($tempfile); $output = unlink($uploaded_file); if ($output === false) { die(json_encode(array("error" => "could not remove uploaded file"))); } $audio->update_metadata(); $audio->calculate_replaygain(); echo json_encode(array("response" => "success", "id" => $audio->get_id())); }