public function handleRequests() { //add sections to allowed_sections $sections = tdb::getInstance()->getAll('sections', 'section_level', '1', 'order_num', 'asc'); foreach ($sections as $k => $v) { $this->allowed_sections[] = $v['section_name']; } array_pop($this->allowed_sections); //remove empty last item //add hidden sections to allowed_sections $hidden = tdb::getInstance()->getAll('sections', 'section_level', '-1', 'order_num', 'asc'); array_pop($hidden); //remove empty last item foreach ($hidden as $k => $v) { $this->allowed_sections[] = $v['section_name']; } //check GET [0] if ($_GET['g0'] == 'ajax') { //do nothing so url can use .getjson $this->section['section_name'] = 'ajax'; } elseif ($_GET['g0'] == 'cron' || $_GET[1] == 'cron') { //$_SERVER ['argv'] [0] is the script that calls the cron job //when running a CRON job, $_GET [ 1 ], , $_GET [ 2 ], , $_GET [ 3 ] are set from $argv via definitions.php $g1 = isset($_GET['g1']) ? $_GET['g1'] : $_GET[2]; $g2 = isset($_GET['g2']) ? $_GET['g2'] : $_GET[3]; $this->section['section_name'] = 'cron'; if ($g1 == 'batch' && $g2 == CRON_BATCH_PASSWORD) { $this->section['action'] = 'batch'; } elseif ($g1 == 'updateDbImageSizes') { $this->section['action'] = 'updateDbImageSizes'; } } elseif (!isset($_GET['g0'])) { $this->section['section_name'] = 'home'; $this->is_faulty_getvar = false; } else { if (in_array($_GET['g0'], $this->allowed_sections)) { // genFuncs::getInstance()->spit ( 'sub name: ' + $this->s [ 'subsect' ] [ 'section_name' ] ); $this->section = tdb::getInstance()->getRow('sections', 'section_name', $_GET['g0']); } if ($_GET['g1']) { //only allow the subsects for the current section $result = tdb::getInstance()->getAll('sections', 'parent_id', $this->section['section_id']); foreach ($result as $k => $v) { $this->allowed_subsects[] = $v['section_name']; if ($_GET['g1'] == $v['section_name']) { $this->section['subsect'] = tdb::getInstance()->getRow('sections', 'section_id', $v['section_id']); } } } } if (isset($_GET['g2'])) { $this->section['2'] = $_GET['g2']; } if (isset($_GET['g3'])) { $this->section['3'] = $_GET['g3']; } if (isset($_GET['g4'])) { $this->section['4'] = $_GET['g4']; } }
public function goCron() { $this->allImages = tdb::getInstance()->getAll('images'); array_pop($this->allImages); genFuncs::getInstance()->spit('sizeOf: ' . sizeOf($this->allImages)); if ($this->s['action'] == 'batch') { $this->batchPhotos(); } elseif ($this->s['action'] == 'updateDbImageSizes') { $this->updateDbImageSizes(); } }
public function startup() { require_once 'classloader.php'; smartClassMapper::getInstance(); spl_autoload_register(array('smartClassMapper', 'autoloadClass')); sectionsOb::getInstance()->handleRequests(); $this->s = sectionsOb::getInstance()->section; browser::getInstance(); require_once T_CLASS_DIR . '/Mobile_Detect.php'; $this->detect = new Mobile_Detect(); $this->deviceType = $this->detect->isMobile() ? $this->detect->isTablet() ? 'tablet' : 'phone' : 'computer'; $this->scriptVersion = $this->detect->getScriptVersion(); if (T_USE_DB) { tdb::getInstance(); } if ($this->s['section_name'] == 'login' || $this->s['section_name'] == 'logout') { $this->login = new loginOb(); $this->login->checkLogin(); } elseif ($this->s['section_name'] == 'cron') { $this->cron = new cron(); } elseif ($this->s['section_name'] == 'cms') { if ($_SESSION['user']['access'] == '2') { $this->cms = new cms(); $this->cms->showCms(); } else { header('Location: ' . T_HOME_URL . 'login'); } } elseif ($this->s['section_name'] == 'ajax') { $this->ajax = new ajax(); $this->ajax->deviceType = $this->deviceType; $this->ajax->processRequest(); } else { if (!DISABLE_FRONT_END) { $this->site = new site(); $this->site->navCase = 'upper'; $this->site->detect = $this->detect; $this->site->deviceType = $this->deviceType; $this->site->scriptVersion = $this->scriptVersion; $this->site->showSite(); } } }
public function showGallery() { // genFuncs::getInstance()->spit ( $this->imageIds ); // $subsectVerbose = genFuncs::getInstance()->makeurl ( $this->s [ 'subsect' ], false ); $this->galleryRow = tdb::getInstance()->getRow('sections', 'section_name', $this->s['subsect']['section_name']); $this->images = tdb::getInstance()->getAll('images', 'section_id', $this->galleryRow['section_id'], 'order_num', 'asc', 0, 9999, 'active_status', '1'); array_pop($this->images); foreach ($this->images as $k => $v) { $this->imageIds[] = array($v['image_id'], $v['image_orig_width'], $v['image_orig_height'], $v['image_has_sizes']); } $this->numTotalImages = sizeOf($this->imageIds); //tdb::getInstance()->getRows ( 'images', 'section_id', $this->galleryRow [ 'section_id' ] ); // genFuncs::getInstance()->spit ( 'imageIds: ' . $this->imageIds ); // $this->totalPages = ceil ( $this->numTotalImages / GALLERY_THUMBS_PER_PAGE ); $this->heroId = -1; if ($this->s['2'] > 0) { $this->heroId = $this->s['2']; } else { $this->heroId = $this->images[0]['image_id']; } $this->switch_link = '<a href="' . DEFAULT_CMS_PAGE . '/' . $this->s['subsect']['section_name'] . '/' . $this->heroId . '">Edit Site ></a>'; $ratios = unserialize(SCREEN_HERO_RATIOS); //mark //set assumed desiredheight for js too //genFuncs::getInstance()->spit ( 'size of ratios: ' . sizeOf($ratios) ); $i = 0; $targetScreenDimension = $_SESSION['screen']['targetScreenDimension'] ? $_SESSION['screen']['targetScreenDimension'] : ASSUMED_SCREEN_HEIGHT; foreach ($ratios as $k => $v) { $this->screenHeroRatios[$i] = array(); $this->screenHeroRatios[$i][0] = $k; $this->screenHeroRatios[$i][1] = (int) $v; $i++; if ($k >= $targetScreenDimension) { $desired_height = $v; break; } } //allow for no match $this->targetHeroHeight = $desired_height; //this is only for server loaded heros: not used currently //$this->hero = img::getInstance()->getImage ( $this->heroId, false, $desired_height, false, 'array' ); }
private function processForm() { $hash_predb = tdb::getInstance()->getHash($_POST['password']); $row = tdb::getInstance()->getRow('user', 'email', $_POST['email']); //echo $hash_predb . '<br>vs:<br>' . $row [ 'password' ]; //pasted the returned hash value in phpmyadmin - needed strip slashes in the tdb class if ($hash_predb == $row['password']) { // genFuncs::getInstance()->spit ( 'match' ); session_regenerate_id(true); $_SESSION['user'] = $row; unset($_SESSION['user']['password']); if ($_SESSION['user']['access'] == '2') { unset($_POST); header('Location: ' . DEFAULT_CMS_PAGE); } } else { genFuncs::getInstance()->spit('unmatch'); foreach ($this->fdata['elements'] as $k => $v) { $this->fdata['elements'][$k]['error'] = true; $this->fdata['elements'][$k]['class'] = 'error'; } $this->showForm(); } }
public function updateDbWithAllSizesForOneImage() { $has_sizes_string = ''; foreach ($this->imageData['has_sizes'] as $k => $v) { $has_sizes_string .= $v[0] . ':' . $v[1] . ':' . $v[2] . '.'; } $has_sizes_string = substr($has_sizes_string, 0, strlen($has_sizes_string) - 1); $q = 'update images set image_has_sizes = "' . $has_sizes_string . '" where image_id="' . $this->imageId . '"'; $result = tdb::getInstance()->queryNoResult($q); }
public function getSiteData() { //get the SECTIONS (parent id of -1 is not specified and 11 is for the CMS ) //sections selected in order with all top level sections ordered first, then all 2nd level sections next $q = 'SELECT section_id, section_name, section_level, section_id, parent_id, order_num, active FROM sections where page_type_id="1" or page_type_id="2" order by section_level, order_num'; $sections = tdb::getInstance()->getFromQ($q); array_pop($sections); $sections_hierachy = array(); //$sectionIndexById is an associative array where you can find the index of a section in the $secions array by using the section_id as the array key $sectionIndexById = array(); foreach ($sections as $k => $v) { //if this is a top level section / menu item if ($v['section_level'] == '1') { //store its index in $sections_hierachy so it can be called using it's section_id as a key $sectionIndexById[$v['section_id']] = $k; //this section goes straight in the final array $sections_hierachy[$k] = $v; } elseif ($v['section_level'] == '2') { //get the index of this sections parent in $sections_hierachy by using this sections PARENT_ID (corresponds to the section_id stored above) $parent_index = $sectionIndexById[$v['parent_id']]; if (!$sections_hierachy[$parent_index]['subsections']) { //create the array if it doesn't exists $sections_hierachy[$parent_index]['subsections'] = array(); } //store the subsection $sections_hierachy[$parent_index]['subsections'][] = $v; } } $this->jsonSend['sections'] = $sections_hierachy; //get the IMAGE DATA $q = 'select images.image_id, images.section_id, images.order_num, images.image_orig_width, images.image_orig_height, images.image_has_sizes, sections.section_name from images inner join sections on sections.section_id=images.section_id where active_status="1" order by section_name, images.order_num limit 0,9999'; $images = tdb::getInstance()->getFromQ($q); array_pop($images); $this->jsonSend['image_ids'] = array(); foreach ($images as $k => $v) { //$this->jsonSend [] = array ( $v [ 'image_id'], $v ['image_orig_width'], $v ['image_orig_height'], $v [ 'image_has_sizes'], $v [ 'section_name'] ); $this->jsonSend['image_ids'][] = array($v['image_id'], $v['image_has_sizes'], $v['section_name']); } $this->sendJson(); }
private function processUpload() { $this->upload_error = false; $right_type = false; $types = preg_split('/:/', IMG_ALLOWED_TYPES, -1, PREG_SPLIT_NO_EMPTY); echo '<br>sizeOf: ' . sizeOf($_FILES['images']); foreach ($_FILES["images"] as $k => $v) { echo '<br>images: ' . $k . ': ' . $v; } foreach ($types as $k => $v) { if ($_FILES["image0"]["type"] == $v) { $right_type = true; break; } } if (!$right_type) { $this->upload_error = 'Error - That image is the wrong type of file'; } $sizeKb = $_FILES["image0"]["size"] / 1024; if ($sizeKb > IMG_MAX_SIZE) { $this->upload_error = 'Error: That image larger than the maximum size of ' . $sizeKb . ' Kb'; } if ($_FILES["image0"]["error"] > 0) { if ($_FILES["image0"]["error"] == 4) { $this->upload_error = 'Error: no file submitted.'; } else { $this->upload_error = 'Error: ' . $_FILES["image0"]["error"]; } } if ($this->upload_error == false) { $q = 'insert into images set active_status="1", section_id="' . $_POST['gallery_id'] . '"'; tdb::getInstance()->queryNoResult($q); //genFuncs::getInstance()->spit ( 'post q: ' . $q); if (move_uploaded_file($_FILES["image0"]["tmp_name"], IMG_UPLOAD_DIR . '/' . tdb::getInstance()->ob->insert_id . '.jpg')) { $this->confirm_msg = 'Image uploaded successfully'; } else { $this->upload_error = 'There was a problem uploading your image. Please try again.'; } } // echo "Upload: " . $_FILES["image0"]["name"] . "<br />"; }
public function buildNav($section_level, $table, $order, $base_url, $url_match, $case, $parent_id) { $case = $this->navCase; //change to return an array - do formatting in html $nav = array(); if ($parent_id) { $result = tdb::getInstance()->getAll($table, 'section_level', $section_level, 'order_num', $order, false, false, 'parent_id', $parent_id); } else { $result = tdb::getInstance()->getAll($table, 'section_level', $section_level, 'order_num', $order); } array_pop($result); $singular_table = substr($table, 0, -1); foreach ($result as $k => $v) { $name = $v[$singular_table . '_name']; if (strlen($name) > 0) { $nav[$k] = array(); $nav[$k]['name'] = strtoupper($name); if ($case == 'camel') { $nav[$k]['name'] = ucwords($name); } elseif ($case == 'lower') { $nav[$k]['name'] = strtolower($name); } if ($url_match == strtolower($name)) { $nav[$k]['selected'] = 'selected'; $nav[$k]['link'] = ''; } else { $nav[$k]['selected'] = ''; $nav[$k]['link'] = $base_url . strtolower($name); //check for default subsect if ($section_level == '1') { $q = 'select * from sections where parent_id = "' . $v['section_id'] . '" order by order_num limit 1'; $cur_default_sub = tdb::getInstance()->query($q); if (is_array($cur_default_sub)) { array_pop($cur_default_sub); if ($cur_default_sub['section_name']) { $nav[$k]['link'] .= '/' . $cur_default_sub['section_name']; } } } } } if (empty($nav[$k]['name'])) { unset($nav[$k]); } } return $nav; }
private function processUpload() { $types = preg_split('/:/', IMG_ALLOWED_TYPES, -1, PREG_SPLIT_NO_EMPTY); $images = array(); foreach ($_FILES['files'] as $key => $value) { foreach ($value as $index => $val) { $images[$index][$key] = $val; } } foreach ($images as $index => $cur_array) { // echo ( '<br>: ' . $index ); //$files is one $_FILE array // echo ( '<br> array[name]: ' . $cur_array [ 'name' ] ); // echo ( '<br> array[size]: ' . $cur_array [ 'size' ] ); //start single image code $right_type = false; foreach ($types as $tk => $tv) { if ($cur_array["type"] == $tv) { $right_type = true; break; } } if (!$right_type) { $this->upload_error[$index] = 'Error - ' . $cur_array['name'] . ' is the wrong type of file'; } $sizeKb = $cur_array["size"] / 1024; if ($sizeKb > IMG_MAX_SIZE) { $this->upload_error[$index] .= 'Error - ' . $cur_array['name'] . ' is larger than the maximum size of ' . $sizeKb . ' Kb'; } if ($cur_array["error"] > 0) { if ($cur_array["error"] == 4) { $this->upload_error[$index] .= 'Error: no file submitted'; } else { $this->upload_error[$index] .= 'Error - ' . $cur_array["name"] . ': ' . $cur_array["error"] . ''; } } //$q = 'SELECT MAX( order_num) as order_num FROM images where section_id="' . $_POST['gallery_id'] . '"'; $q = 'select order_num, section_id from images where section_id="' . $_POST['gallery_id'] . '" order by order_num desc limit 1'; $max_order_row = tdb::getInstance()->query($q); $max_order = $max_order_row['order_num']; $new_order = $max_order + 1; if ($this->upload_error[$index] == false) { $info = getimagesize($cur_array["tmp_name"]); $q = 'insert into images set active_status="1", section_id="' . $_POST['gallery_id'] . '", order_num="' . $new_order . '", image_orig_width="' . $info[0] . '", image_orig_height="' . $info[1] . '"'; // genFuncs::getInstance()->spit ( 'q: ' . $q ); tdb::getInstance()->queryNoResult($q); if (move_uploaded_file($cur_array["tmp_name"], IMG_UPLOAD_DIR . '/' . tdb::getInstance()->ob->insert_id . '.jpg')) { $this->confirm_msg[$index] = $cur_array['name'] . ' uploaded successfully'; } else { $this->upload_error[$index] = 'There was a problem uploading image/s. Please try again.'; } } } //end mutliple images loop }