function load($id) { parent::load($id); $rs = $this->db->execute($s = Query::generateSelectStm(array($this->table), array(), array(new WhereConstraint($this->table->getColumn(DB::COMMENT_ID), Operator::EQUAL, intval($id))), array())); if ($this->db->num_rows() != 1) { throw new Exception("L'oggetto cercato non è stato trovato."); } $row = $this->db->fetch_result(); $c = new Comment($row[DB::COMMENT_COMMENT], intval($row[DB::COMMENT_POST]), intval($row[DB::COMMENT_AUTHOR])); $c->setID(intval($row[DB::COMMENT_ID]))->setCreationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[DB::COMMENT_CREATION_DATE]))); if ($this->loadReports && AuthorizationManager::canUserDo(AuthorizationManager::READ_REPORTS, $c)) { require_once 'dao/ReportDao.php'; $redao = new ReportDao(); $redao->loadAll($c); } return $c; }
private function createFromDBRow($row) { $r = new Resource($row[DB::RESOURCE_OWNER], $row[DB::RESOURCE_PATH], $row[DB::RESOURCE_TYPE]); $r->setID($row[DB::RESOURCE_ID]); $r->setDescription($row[DB::RESOURCE_DESCRIPTION])->setCreationDate($row[DB::RESOURCE_CREATION_DATE])->setTags($row[DB::RESOURCE_TAGS]); if (!is_null($row[DB::RESOURCE_MODIFICATION_DATE])) { $mod = $row[DB::RESOURCE_MODIFICATION_DATE]; } else { $mod = $row[DB::RESOURCE_CREATION_DATE]; } $r->setModificationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $mod))); //setto lo stato $r->setEditable($row[DB::EDITABLE])->setRemovable($row[DB::REMOVABLE]); $r->setBlackContent($row[DB::BLACK_CONTENT])->setRedContent($row[DB::RED_CONTENT])->setYellowContent($row[DB::YELLOW_CONTENT])->setAutoBlackContent($row[DB::AUTO_BLACK_CONTENT]); $user = Session::getUser(); if ($this->loadReports && AuthorizationManager::canUserDo(AuthorizationManager::READ_REPORTS, $r)) { require_once 'dao/ReportDao.php'; $reportDao = new ReportDao(); $reportDao->loadAll($r); } //$r->setAccessCount($this->getAccessCount($r)); return $r; }
private function createFromDBRow($row) { $user = new User($row[DB::USER_NICKNAME], $row[DB::USER_E_MAIL], $row[DB::USER_PASSWORD]); $user->setName($row[DB::USER_NAME])->setSurname($row[DB::USER_SURNAME])->setGender($row[DB::USER_GENDER]); if (!is_null($row[DB::USER_BIRTHDAY])) { $user->setBirthday(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[DB::USER_BIRTHDAY]))); } $user->setBirthplace($row[DB::USER_BIRTHPLACE])->setLivingPlace($row[DB::USER_LIVINGPLACE])->setHobbies($row[DB::USER_HOBBIES])->setJob($row[DB::USER_JOB])->setRole($row[DB::USER_ROLE])->setVisible($row[DB::USER_VISIBLE])->setID(intval($row[DB::USER_ID]))->setCreationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[DB::USER_CREATION_DATE])))->setVerified($row[DB::USER_VERIFIED]); try { require_once "dao/ResourceDao.php"; $resourceDao = new ResourceDao(); $user->setAvatar($resourceDao->quickLoad($row[DB::USER_AVATAR])); } catch (Exception $e) { // try { // $user->setAvatar($resourceDao->quickLoad(EMPTY_AVATAR)); // } catch (Exception $e1) { // //DEBUG da togliere più avanti, quando ci saranno le immagini. // } } if ($this->loadDependences) { require_once "dao/ContactDao.php"; $contactDao = new ContactDao(); $contactDao->loadAll($user); require_once "dao/FollowDao.php"; $followDao = new FollowDao(); $followDao->loadAllFollowers($user); $followDao->loadAllFollows($user); require_once "dao/FeedbackDao.php"; $feedbackDao = new FeedbackDao(); $feedbackDao->loadAll($user); } if ($this->loadReports && AuthorizationManager::canUserDo(AuthorizationManager::READ_REPORTS, $user)) { require_once 'dao/ReportDao.php'; $reportDao = new ReportDao(); $reportDao->loadAll($user); } //setto lo stato $user->setEditable($row[DB::EDITABLE])->setRemovable($row[DB::REMOVABLE]); $user->setBlackContent($row[DB::BLACK_CONTENT])->setRedContent($row[DB::RED_CONTENT])->setYellowContent($row[DB::YELLOW_CONTENT])->setAutoBlackContent($row[DB::AUTO_BLACK_CONTENT]); if ($this->loadAccessCount) { $user->setAccessCount($this->getAccessCount($user)); } return $user; }
/** * @return $this */ protected function setAccessToken() { $this->accessToken = AuthorizationManager::getAccessToken($this->keys); return $this; }
function update($post, $editor) { parent::update($post, $editor, self::OBJECT_CLASS); if (!AuthorizationManager::canUserDo(DB::EDIT_POST, $object)) { throw new Exception("L'utente non è autorizzato ad effettuare questa operazione."); } $p_old = $this->quickLoad($post->getID()); $data = array(); if (is_null($p_old)) { throw new Exception("L'oggetto da modificare non esiste."); } //cerco le differenze e le salvo. if ($p_old->getTitle() != $post->getTitle()) { $data[DB::POST_TITLE] = $post->getTitle(); } if ($p_old->getSubtitle() != $post->getSubtitle()) { $data[DB::POST_SUBTITLE] = $post->getSubtitle(); } if ($p_old->getHeadline() != $post->getHeadline()) { $data[DB::POST_HEADLINE] = $post->getHeadline(); } if ($p_old->getContent() != $post->getContent()) { if ($post->type == Post::NEWS || $post->type == Post::VIDEOREP) { $data[DB::POST_CONTENT] = $post->getContent(); } else { $data[DB::POST_CONTENT] = serialize($post->getContent()); } } if ($p_old->getPlace() != $post->getPlace()) { $data[DB::POST_PLACE] = $post->getPlace(); } if ($p_old->getPlaceName() != $post->getPlaceName()) { $data[DB::POST_PLACE_NAME] = $post->getPlaceName(); } if ($p_old->getTags() != $post->getTags()) { $data[DB::POST_TAGS] = $post->getTags(); } if ($p_old->getCategories() != $post->getCategories()) { // check sulle categorie, eliminazione di quelle che non esistono nel sistema, se vuoto inserimento di quella di default require_once 'manager/CategoryManager.php'; $new_cat = CategoryManager::filterWrongCategories(explode(",", $post->getCategories())); if (count($new_cat) == 0) { $new_cat[] = self::DEFAULT_CATEGORY; } $post->setCategories(Filter::arrayToText($new_cat)); $data[DB::POST_CATEGORIES] = $post->getCategories(); } if ($p_old->isVisible() !== $post->isVisible()) { $data[DB::POST_VISIBLE] = $post->isVisible() ? 1 : 0; } if ($p_old->getPermalink() != $post->getPermalink()) { if ($this->permalinkExists($post->getPermalink())) { throw new Exception("Il permalink inserito esiste già. Riprova."); } $data[DB::POST_PERMALINK] = $post->getPermalink(); } if (count($data) == 0) { throw new Exception("Nessuna modifica da effettuare."); } $modDate = $_SERVER["REQUEST_TIME"]; $data[DB::POST_MODIFICATION_DATE] = date("Y/m/d G:i:s", $modDate); // se mi dicono di fare l'update, cambio modificationDate //salvo la versione precedente e ne tengo traccia. $history_id = $this->saveHistory($p_old, "UPDATED"); $post->setPreviousVersion($history_id); $data[DB::POST_PREVIOUS_VERSION] = $post->getPreviousVersion(); $rs = $this->db->execute($s = Query::generateUpdateStm($this->table, $data, array(new WhereConstraint($this->table->getColumn(DB::POST_ID), Operator::EQUAL, $post->getID()))), $this->table->getName(), $post); //aggiorno lo stato del post (se chi l'ha modificato è un redattore). if (AuthenticationManager::isEditor($editor)) { $post->setEditable(false); $post->setRemovable(false); $this->updateState($post); } if ($this->db->affected_rows() != 1) { throw new Exception("Si è verificato un errore aggiornando il dato. Riprovare."); } //salvo i tag che non esistono if (isset($data[DB::POST_TAGS]) && !is_null($data[DB::POST_TAGS]) && trim($data[DB::POST_TAGS]) != "") { require_once 'manager/TagManager.php'; TagManager::createTags(explode(",", $data[DB::POST_TAGS])); //TODO } return $post->setModificationDate($modDate); }
function edit($data) { if (isset($data[Post::TITLE])) { $this->setTitle($data[Post::TITLE]); } if (isset($data[Post::SUBTITLE])) { $this->setSubtitle($data[Post::SUBTITLE]); } if (isset($data[Post::HEADLINE])) { $this->setHeadline($data[Post::HEADLINE]); } if (isset($data[Post::TAGS])) { $this->setTags($data[Post::TAGS]); } if (isset($data[Post::CATEGORIES])) { $this->setCategories($data[Post::CATEGORIES]); } if (isset($data[Post::CONTENT])) { $this->setContent($data[Post::CONTENT]); } if (isset($data[Post::RED_CONTENT])) { $this->setContent($data[Post::RED_CONTENT]); } if (isset($data[Post::YELLOW_CONTENT])) { $this->setContent($data[Post::YELLOW_CONTENT]); } if (isset($data[Post::BLACK_CONTENT]) && AuthorizationManager::canUserDo(AuthorizationManager::SET_BLACK, $this)) { $this->setContent($data[Post::BLACK_CONTENT]); } if (isset($data[Post::VISIBLE])) { $this->setVisible($data[Post::VISIBLE]); } return $this; }
static function showNewPostForm($data = null, $error = null) { $user = Session::getUser(); require_once 'manager/AuthorizationManager.php'; if (!isset($_GET["type"])) { $_GET["type"] = Post::NEWS; } if (!AuthorizationManager::canUserDo(AuthorizationManager::CREATE, $_GET["type"])) { return; } //TODO redirect verso pagina di errore. $logger = Logger::getLogger(); $logger->debug("ResourceDao", $_GET["type"]); if (isset($_GET["phase"]) && $_GET["phase"] == 3) { if ($_GET["type"] == "photoreportage" && isset($_POST["numResources"])) { $data = array(); for ($i = 0; $i < $_POST["numResources"]; $i++) { $resourceID = $_POST["resourceID" . $i]; if (isset($_POST[$resourceID]) && $_POST[$resourceID] != '') { //$_POST[$resourceID] is the description $data['description'] = $_POST[$resourceID]; $rsUpdated = ResourceManager::editResource($resourceID, $data); } } Page::redirect("Edit"); } } else { if (is_null($error) && count($_POST) > 0) { $data = array(); if (isset($_POST["title"]) && trim($_POST["title"]) != "") { $data["title"] = $_POST["title"]; } else { $error = array("Inserire un titolo."); } if (isset($_POST["type"])) { $data["type"] = $_POST["type"]; } else { $error[] = "Scegliere il tipo di post da pubblicare."; } if ($data["type"] == "news") { //carico il testo del post if (isset($_POST["content"]) && trim($_POST["content"]) != "") { $data["content"] = $_POST["content"]; } else { $error[] = "Inserire un contenuto."; } //check if ther's not valid files $notvalid = 0; if (trim($_FILES["upfile"]["name"]) != "") { if ($_FILES["upfile"]["type"] == "image/gif" || $_FILES["upfile"]["type"] == "image/jpeg" || $_FILES["upfile"]["type"] == "image/png") { } else { $notvalid++; } } if ($notvalid == 0) { if (trim($_FILES["upfile"]["name"]) != "") { if ($_FILES["upfile"]["type"] == "image/gif" || $_FILES["upfile"]["type"] == "image/jpeg" || $_FILES["upfile"]["type"] == "image/png") { $fname = ResourceManager::editFileName($_FILES["upfile"]["name"]); $newsPhoto = ResourceManager::uploadPhoto($fname, $user->getNickname(), $user->getID(), $_FILES["upfile"]["tmp_name"], $_FILES["upfile"]["type"]); //prelevo l'id della risorsa appena salvata $data["photo"] = $newsPhoto->getID(); } } } else { $error[] = "Devi inserire un formato valido: .jpeg .jpg .gif oppure .png"; } } else { if ($data["type"] == "photoreportage") { $photo = array(); //check if ther's not valid files for ($i = 0, $notvalid = 0; $i < 10; $i++) { if (trim($_FILES["upfile{$i}"]["name"]) != "") { if ($_FILES["upfile{$i}"]["type"] == "image/gif" || $_FILES["upfile{$i}"]["type"] == "image/jpeg" || $_FILES["upfile{$i}"]["type"] == "image/png") { } else { $notvalid++; } } } if ($notvalid == 0) { for ($i = 0, $numphoto = 0; $i < 10; $i++) { if (trim($_FILES["upfile{$i}"]["name"]) != "") { if ($_FILES["upfile{$i}"]["type"] == "image/gif" || $_FILES["upfile{$i}"]["type"] == "image/jpeg" || $_FILES["upfile{$i}"]["type"] == "image/png") { $fname = ResourceManager::editFileName($_FILES["upfile{$i}"]["name"]); $photo[] = ResourceManager::uploadPhoto($fname, $user->getNickname(), $user->getID(), $_FILES["upfile{$i}"]["tmp_name"], $_FILES["upfile{$i}"]["type"]); $numphoto++; } } } if ($numphoto > 0) { $data["content"] = $photo; } else { $error[] = "Devi inserire almeno un'immagine"; } } else { $error[] = "Devi inserire un formato valido: .jpeg .jpg .gif oppure .png"; } } else { if ($data["type"] == "videoreportage") { if (isset($_POST["userUrl"]) && $_POST["userUrl"] != '') { $rs = ResourceManager::createResource($user->getID(), youtubeManager::getVideoID($_POST["userUrl"]), 'video'); $data['content'] = youtubeManager::getVideoID($_POST["userUrl"]); } } } } if (isset($_POST["cat"]) && is_array($_POST["cat"]) && count($_POST["cat"]) > 0) { $cat = ""; $first = true; foreach ($_POST["cat"] as $k => $c) { if ($first) { $first = false; } else { $cat .= ", "; } $cat .= $c; } $data["categories"] = $cat; } if (isset($_POST["place"]) && trim($_POST["place"]) != "") { $data["place"] = $_POST["place"]; } //if(isset($_POST["headline"]) && trim($_POST["headline"]) != "") // $data["headline"] = $_POST["headline"]; if (isset($_POST["subtitle"]) && trim($_POST["subtitle"]) != "") { $data["subtitle"] = $_POST["subtitle"]; } if (isset($_POST["tags"]) && trim($_POST["tags"]) != "") { $data["tags"] = $_POST["tags"]; } if (is_null($error) || is_array($error) && count($error) == 0) { $data["author"] = $user->getID(); //se photoreportage creo una collection if ($data["type"] == "news") { $post = PostManager::createPost($data); //se vi è una foto aggiorno la tabella PostResource if (isset($data['photo']) && $data['photo'] != "") { PostManager::setPostResource($post->getID(), $data['photo']); } } else { if ($data["type"] == "videoreportage") { $post = PostManager::createPost($data); } else { if ($data["type"] == "photoreportage" && $_GET["phase"] == 2) { //save only the resource ID not the whole object foreach ($data["content"] as &$resource) { $resource = $resource->getID(); } $post = CollectionManager::createCollection($data); } else { $post = false; } } } if ($post !== false) { echo ' <div class="message"> Notizia salvata: <a href="' . FileManager::appendToRootPath($post->getPermalink()) . '">Visualizza</a> </div>'; } } else { self::showNewPostForm($data, $error); return; } } } //echo serialize(isset($_GET["type"])) . "<br/>"; //DEBUG switch ($_GET["type"]) { case Post::COLLECTION: case Post::PHOTOREP: case Post::VIDEOREP: case Post::ALBUM: case Post::MAGAZINE: case Post::PLAYLIST: call_user_func(array("PostPage", "showNew" . $_GET["type"] . "Form"), $data, $error); break; case "videoreportage3": break; case Post::NEWS: default: self::showNewNewsForm($data, $error); } }