public function setPageNo($pgno) { error_log('setPageNo'); //$this->dirIterator->rewind(); error_log($pgno); $this->pageNo = $pgno < 0 ? 0 : $pgno; //check min boundary if ($this->pageNo > ($pages = round($this->getFilesCount() / $this->pageSize))) { error_log("pages:" . $pages); $this->pageNo = $pages; //check max boundary @todo when not rounded floating point value caused nice aligning to last page... why? } $_SESSION[$this->instanceId] = $this->pageNo; error_log("===" . $this->pageNo); $i = 0; foreach (new LimitIterator(new CallbackFilterIterator($this->dirIterator, $this->ftype), $this->pageNo * $this->pageSize, $this->pageSize) as $item) { error_log($item->getFilename()); $items[$i++] = $item->getFilename(); } if (!empty($items)) { dbgmp($items); $this->list = $items; } elseif ($this->pageNo > 0) { $this->setPageNo(--$this->pageNo); } elseif ($this->pageNo < 0) { $this->setPageNo(0); } // @todo wacth it! recursive !!! test when no images! check of max boundary }
function set_version_of_name(&$afile) { error_log("set_version_of_name"); // if (!file_exists($afile)) return false;//checked before call of this function $ext = explode('.', $afile); dbgmp($ext); $extension = end($ext); if (is_numeric($prev = prev($ext))) { $prev = strval($prev + 1); $ext[key($ext)] = $prev; } else { array_pop($ext); array_push($ext, "0"); array_push($ext, $extension); } dbgmp($ext); $afile = implode('.', $ext); return true; }
public function getJSON() { $files = $this->source->getList(); dbgmp($files); echo json_encode($files); }
public function process() { if (!isset($_POST["submit"])) { return; } if (empty($_FILES['files']['name'][0])) { return; } //no file chosen-> no response or warning $_SESSION['message'] = ""; $_SESSION['message'] .= "Uploaded?: "; foreach ($_FILES['files']['name'] as $it => $mmm) { $namehandle = basename($_FILES["files"]["name"][$it]); $_SESSION['message'] .= $namehandle; $target_file = $this->target_dir . $namehandle; $uploadOk = 1; $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION); // Check if image file is a actual image or fake image $check = @getimagesize($_FILES["files"]["tmp_name"][$it]); if ($check !== false) { error_log("File is an image - " . $check["mime"] . "."); $uploadOk = 1; } else { error_log("File is not an image."); $_SESSION['message'] .= " noIMG "; $uploadOk = 0; break; } // Check file size if ($_FILES["files"]["size"][$it] > 20000000) { $_SESSION['message'] .= " >20MB! "; $uploadOk = 0; break; } $validextensions = array("jpeg", "jpg", "png", "gif"); //Extensions which are allowed $ext = explode('.', $namehandle); //explode file name from dot(.) dbgmp($_FILES); $file_extension = end($ext); //store extensions in the variable error_log($file_extension); // Allow certain file formats if ($imageFileType != "jpg" && $imageFileType != "JPG" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") { error_log("Sorry, only JPG, JPEG, PNG & GIF files are allowed."); $_SESSION['message'] .= " noFMT "; $uploadOk = 0; break; } // Check if file already exists $storedSHA = sha1_file($_FILES["files"]["tmp_name"][$it]); $storedfile = $storedSHA . "." . $ext[count($ext) - 1]; $target_file = $this->target_dir . $storedfile; //set the target path with a new name of image $newitem = false; //for rss feed and name conflict if (file_exists($target_file)) { error_log("Sorry, file already exists."); $_SESSION['message'] .= " dupl! "; $uploadOk = 0; } else { $newitem = true; //for rss feed and name conflict } error_log('mkdir?'); if (!file_exists($this->target_category . '/' . $_POST['category'])) { error_log('mkdir!'); mkdir($this->target_category . '/' . $_POST['category']); $_SESSION['category'] = $_POST['category']; } if (move_uploaded_file($_FILES["files"]["tmp_name"][$it], $target_file)) { error_log("The file " . $namehandle . " has been uploaded."); $_SESSION['message'] .= " OK "; $allPath = '../' . appdataDir . '/' . categoriesDir . '/' . all; nextsearch: if (file_exists($allPath . '/' . $namehandle) && $storedSHA != sha1_file($allPath . '/' . $namehandle) && set_version_of_name($namehandle)) { goto nextsearch; } // adds or increments numbering to the file error_log("renaming it to:" . $namehandle); /////////////CATEGORIZE categories\categorize($storedfile, all, $namehandle); if (!($_SESSION['category'] == all)) { categories\categorize($storedfile, $_POST['category'], $namehandle); } //////////////RSS update if ($newitem) { new RssUpdater(dirname(dirname($_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'])) . '/' . appdataDir . '/' . categoriesDir . '/' . all . '/' . $namehandle); } } else { error_log("Sorry, there was an error uploading your file."); $_SESSION['message'] .= " error "; } } header("Location: " . url); exit; }
public function additem($imagefile) { $nodelist = $this->doc->getElementsByTagName('item'); // search for first <item> $timestamp = time(); //latest time to compare with dbgmp($timestamp); $eldest = null; $count = 0; if ($nodelist) { //find the eldest to remove foreach ($nodelist as $element) { $count++; $elem = $element; $el = $elem->getElementsByTagName('pubDate')->item(0); // search for <pubDate> under given <item> $time0 = new DateTime($el->nodeValue); $ts = $time0->getTimestamp(); if ($ts < $timestamp) { $timestamp = $ts; $eldest = $elem; } } } $nodelist = $this->doc->getElementsByTagName('channel'); //take <channel> $channel_node = $nodelist->item(0); if ($count > max_number_of_rss_items) { dbgmp($eldest->nodeValue); $channel_node->removeChild($eldest->previousSibling); // removing tab ident before <item> $channel_node->removeChild($eldest); //remove eldest <item> from this <channel> } $date_f = date("D, d M Y H:i:s T", time()); //current time to add $date_rfc = gmdate(DATE_RFC2822, strtotime($date_f)); $channel_node->removeChild($channel_node->lastChild); //removing tab ident before </channel> $text_node = $channel_node->appendChild($this->doc->createTextNode("\n ")); $item_node = $channel_node->appendChild($this->doc->createElement("item")); //create and append a new <item> $title_node = $item_node->appendChild($this->doc->createElement("title", basename($imagefile))); //<title> of a new image $link_node = $item_node->appendChild($this->doc->createElement("link", "http://" . $imagefile)); //<link> to this image $pub_date = $this->doc->createElement("pubDate", $date_rfc); $pub_date_node = $item_node->appendChild($pub_date); //<pubDate> of the this <item> $text_node = $channel_node->appendChild($this->doc->createTextNode("\n ")); // adds removed tab ident before </channel> $nodelist = $this->doc->getElementsByTagName('link'); //find first whole <channel> <link> $nodelist->item(0)->nodeValue = 'http://' . dirname($_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']); //and change it $nodelist = $this->doc->getElementsByTagName('pubDate'); //find whole <channel> <pubDate> $nodelist->item(0)->nodeValue = $date_rfc; //and change it $this->doc->save($this->rssfile); }