/**
  * Get all the Events
  * If authentication is not provided, it shows only published events
  * If authentication is provided, it show published event for the authenticated user
  *
  * @url GET /events
  * @url GET /events/$userId
  */
 public function getEvents($userId = -1)
 {
     $authIdUser = parent::CheckAuthentication(false);
     if ($authIdUser > 0) {
         $authenticated = true;
         if ($userId <= 0) {
             $userId = $authIdUser;
         }
     }
     $filters = array();
     $notFilters = array();
     $authorsDbHandler = new AuthorsDatabaseHandler();
     if (isset($_GET['userId']) && $_GET['userId'] != "") {
         $filters[UserId] = $_GET['userId'];
     }
     if (isset($_GET['language']) && $_GET['language'] != "") {
         $filters[Language] = $_GET['language'];
     }
     if (isset($_GET['published']) && $_GET['published'] != "") {
         $filters[Published] = $_GET['published'];
     }
     if (isset($_GET['author']) && $_GET['author'] != "") {
         $filters[AuthorId] = $authorsDbHandler->AuthorByUniqueName($_GET['author'])[AuthorId];
     }
     if ($authenticated == false || isset($_GET['userId'])) {
         // If not authenticated shows only published events
         $filters[Published] = 1;
     }
     if (isset($_GET['upcoming'])) {
         $upcoming = $_GET['upcoming'];
     } else {
         $upcoming = 1;
     }
     if (isset($_GET['from'])) {
         $from = $_GET['from'];
     } else {
         $from = -1;
     }
     if (isset($_GET['count'])) {
         $count = $_GET['count'];
     } else {
         $count = -1;
     }
     if (isset($_GET['year'])) {
         $year = $_GET['year'];
     } else {
         $year = null;
     }
     if (isset($_GET['orderby'])) {
         $orderby = $_GET['orderby'];
     } else {
         $orderby = "";
     }
     return parent::Events($filters, $notFilters, $from, $count, $userId, $orderby, $upcoming, $year);
 }
 public function ArticleById($IdArticle, $IdUser = null)
 {
     $userArticlesFolder = Settings::getInstance()->p['userArticlesFolder'];
     $ArticleFieldsSql = " Article.UserId, Article.ArticleId, Article.Title, Article.Image, Article.Description AS Description, Article.DateTime, Article.YouTubeLink, Article.FlickrLink, Article.Language, Article.Published, Article.Category ";
     $sql = "SELECT {$ArticleFieldsSql}, AuthorId FROM Article WHERE ArticleId = {$IdArticle}";
     $result = $this->mysqli->query($sql);
     $recordsCount = mysqli_num_rows($result);
     $data = 0;
     if ($recordsCount >= 1 && $result != null) {
         $row = mysqli_fetch_array($result);
         $imageUrl = parent::GetImageUrl($row['UserId'], $row['Image'], $userArticlesFolder);
         $imageThumbnailUrl = parent::GetImageUrl($row['UserId'], $row['Image'], $userArticlesFolder, true);
         $ShortDescription = parent::substrwords(strip_tags($row['Description']), 120);
         $AuthorsHandler = new AuthorsDatabaseHandler();
         $data = array('ArticleId' => intval($row['ArticleId']), 'Title' => $row['Title'], 'Image' => $row['Image'], 'ImageUrl' => $imageUrl, 'ThumbnailUrl' => $imageThumbnailUrl, 'Description' => $row['Description'], 'DateTime' => $row['DateTime'], 'YouTubeLink' => $row['YouTubeLink'], 'FlickrLink' => $row['FlickrLink'], 'Language' => $row['Language'], 'Published' => intval($row['Published']), 'Category' => $row['Category'], 'ShortDescription' => $ShortDescription, 'Author' => $AuthorsHandler->AuthorById($row['AuthorId']), 'UserId' => intval($row['UserId']));
     }
     return $data;
 }
 function EventById($EventId)
 {
     $userEventsFolder = Settings::getInstance()->p['userEventsFolder'];
     $EventFieldsSql = " Event.UserId, Event.EventId, Event.Title, Event.Image, Event.Description AS Description, Event.CreationDateTime, Event.DateTime, Event.FacebookLink, Event.YouTubeLink, Event.FlickrLink, Event.Language, Event.Published, Event.Statistics ";
     $sql = "SELECT {$EventFieldsSql}, AuthorId, LocationId FROM Event WHERE Event.EventId = {$EventId}";
     $result = $this->mysqli->query($sql);
     $recordsCount = mysqli_num_rows($result);
     $data = 0;
     if ($recordsCount >= 1 && $result != null) {
         $row = mysqli_fetch_array($result);
         $imageUrl = parent::GetImageUrl($row['UserId'], $row['Image'], $userEventsFolder);
         $imageThumbnailUrl = parent::GetImageUrl($row['UserId'], $row['Image'], $userEventsFolder, true);
         $ShortDescription = parent::substrwords(strip_tags($row['Description']), 120);
         $Description = $row['Description'];
         $AuthorsDbHandler = new AuthorsDatabaseHandler();
         $LocationsDbHandler = new LocationsDatabaseHandler();
         $data = array('EventId' => $row['EventId'], 'Title' => $row['Title'], 'Image' => $row['Image'], 'ImageUrl' => $imageUrl, 'ThumbnailUrl' => $imageThumbnailUrl, 'Description' => $Description, 'CreationDateTime' => $row['CreationDateTime'], 'DateTime' => $row['DateTime'], 'FacebookLink' => $row['FacebookLink'], 'YouTubeLink' => $row['YouTubeLink'], 'FlickrLink' => $row['FlickrLink'], 'Language' => $row['Language'], 'Published' => $row['Published'], 'ShortDescription' => $ShortDescription, 'LocationId' => $row['LocationId'], 'Location' => $LocationsDbHandler->LocationById($row['LocationId']), 'AuthorId' => $row['AuthorId'], 'Author' => $AuthorsDbHandler->AuthorById($row['AuthorId']), 'UserId' => $row['UserId'], 'Statistics' => $row['Statistics']);
     }
     return $data;
 }
 private function unlinkRemovedAuthorImages($userId, $image)
 {
     $userAuthorsFolder = Settings::getInstance()->p['userAuthorsFolder'];
     $imageFileToRemove = "../../" . parent::GetImageUrl($userId, $image, $userAuthorsFolder, false, false);
     $imageThumbnailFileToRemove = "../../" . parent::GetImageUrl($userId, $image, $userAuthorsFolder, true, false);
     if (strlen($image) > 0) {
         if (file_exists($imageFileToRemove)) {
             unlink($imageFileToRemove);
         }
         if (file_exists($imageThumbnailFileToRemove)) {
             unlink($imageThumbnailFileToRemove);
         }
     }
 }