diff --git a/.htaccess b/.htaccess index 08219de33..a6bacc02c 100644 --- a/.htaccess +++ b/.htaccess @@ -1,268 +1,270 @@ # BEGIN Expires Don't forget to enable mod_headers and mod_expires, you can do so by running a2enmod rewrite and a2enmod headers ExpiresActive On ExpiresDefault "access plus 1 seconds" ExpiresByType text/html "access plus 1 seconds" ExpiresByType image/gif "access plus 2592000 seconds" ExpiresByType image/jpeg "access plus 2592000 seconds" ExpiresByType image/png "access plus 2592000 seconds" ExpiresByType text/css "access plus 604800 seconds" ExpiresByType text/javascript "access plus 216000 seconds" ExpiresByType application/x-javascript "access plus 216000 seconds" Order Allow,Deny Deny from all Order Allow,Deny Deny from all Order Allow,Deny Deny from all Order Allow,Deny Deny from all # Disable directory browsing Options All -Indexes # END Expires # BEGIN Caching Header set Access-Control-Allow-Origin: * Header set Cache-Control "max-age=2592000, public" Header set Cache-Control "max-age=604800, public" Header set Cache-Control "max-age=216000, private" Header set Cache-Control "max-age=216000, public, must-revalidate" Header set Cache-Control "max-age=1, private, must-revalidate" # END Caching RewriteEngine on #main Files RewriteRule ^index.php$ view/index.php [NC,L] #RewriteRule ^index.php$ /view/index.php [NC,L] #RewriteRule ^$ view/ [NC,L] RewriteRule ^bootstrap/(.+)$ view/bootstrap/$1 [NC,L] RewriteRule ^js/(.+)$ view/js/$1 [NC,L] RewriteRule ^css/(.+)$ view/css/$1 [NC,L] RewriteRule ^img/(.+)$ view/img/$1 [NC,L] RewriteRule ^videos/fonts/(.+)$ view/bootstrap/fonts/$1 [NC,L] RewriteRule ^page/([0-9]+)/?$ view/?page=$1 [QSA] RewriteRule ^videoOnly/?$ view/?type=video [NC,L] RewriteRule ^audioOnly/?$ view/?type=audio [NC,L] RewriteRule ^download$ view/downloadExternalVideo.php [NC,L] RewriteRule ^info$ view/info.php [NC,L] RewriteRule ^downloadNow$ objects/downloadVideo.php [NC,L] RewriteRule ^getDownloadProgress$ objects/downloadVideoProgress.php [NC,L] RewriteRule ^status$ objects/status.json.php [NC,L] RewriteRule ^menu/([A-Za-z0-9-_.]+)/? plugin/TopMenu/seo.php?menuSeoUrlItem=$1 [QSA,L] RewriteRule ^admin/plugin/(.+)$ plugin/$1 [NC,L] RewriteRule ^trending/?$ view/trending.php [NC,L,QSA] RewriteRule ^about$ view/about.php [NC,L] RewriteRule ^contact$ view/contact.php [NC,L] RewriteRule ^sendEmail$ objects/sendEmail.json.php [NC,L] RewriteRule ^captcha$ objects/getCaptcha.php [NC,L] RewriteRule ^monitor/(.+)$ objects/ServerMonitor/$1 [NC,L] RewriteRule ^videosList$ view/videosList.php [NC,L] RewriteRule ^videosList/video/([A-Za-z0-9-_.]+)/page/([0-9]+)/?$ view/videosList.php?videoName=$1&page=$2 [QSA] RewriteRule ^videosList/cat/([A-Za-z0-9-]+)/video/([A-Za-z0-9-_.]+)/page/([0-9]+)/?$ view/videosList.php?catName=$1&videoName=$2&page=$3 [QSA] #for the category name RewriteRule ^cat/([A-Za-z0-9-]+)/?$ view/?catName=$1 [NC,L,QSA] RewriteRule ^cat/([A-Za-z0-9-]+)/page/([0-9]+)/?$ view/?catName=$1&page=$2 [NC,L,QSA] RewriteRule ^tag/([0-9-]+)(.*)?$ view/?tags_id=$1 [NC,L,QSA] #for the video name RewriteRule ^video/([A-Za-z0-9-_.]+)/?$ view/?videoName=$1 [QSA] RewriteRule ^video/([A-Za-z0-9-_.]+)/page/([0-9]+)/??$ view/?videoName=$1&page=$2 [QSA] RewriteRule ^v/([0-9]+)/?$ view/?v=$1 [QSA] RewriteRule ^v/([0-9]+)/page/([0-9]+)/??$ view/?v=$1&page=$2 [QSA] #for the video name RewriteRule ^cat/([A-Za-z0-9-]+)/video/([A-Za-z0-9-_.]+)/?$ view/?catName=$1&videoName=$2 [QSA] RewriteRule ^cat/([A-Za-z0-9-]+)/video/([A-Za-z0-9-_.]+)/page/([0-9]+)/?$ view/?catName=$1&videoName=$2&page=$3 [QSA] #for the embeded video name RewriteRule ^videoEmbeded/([A-Za-z0-9-_.]+)/?$ view/videoEmbeded.php?videoName=$1 [QSA] RewriteRule ^cat/([A-Za-z0-9-_.]+)/videoEmbeded/([A-Za-z0-9-_.]+)/?$ view/videoEmbeded.php?catName=$1&videoName=$2 [QSA] RewriteRule ^videoEmbed/([A-Za-z0-9-_.]+)/?$ view/videoEmbeded.php?videoName=$1 [QSA] RewriteRule ^vEmbed/([0-9]+)/?$ view/videoEmbeded.php?v=$1 [QSA] RewriteRule ^plugin/([A-Za-z0-9-_.]+)/(.*)?$ plugin/$1/$2 [NC,L] RewriteRule ^upload$ view/mini-upload-form/ [NC,L] RewriteRule ^fileUpload$ view/mini-upload-form/upload.php [NC,L] RewriteRule ^uploadPoster/([0-9]+)/(jpg|gif)$ objects/uploadPoster.php?video_id=$1&type=$2 [NC,L] #edit your own user RewriteRule ^user$ view/user.php [NC,L] #manager user RewriteRule ^users$ view/managerUsers.php [NC,L] RewriteRule ^users.json$ objects/users.json.php [NC,L] RewriteRule ^updateUser$ objects/userUpdate.json.php [NC,L] RewriteRule ^savePhoto$ objects/userSavePhoto.php [NC,L] RewriteRule ^saveBackground$ objects/userSaveBackground.php [NC,L] RewriteRule ^addNewUser$ objects/userAddNew.json.php [NC,L] RewriteRule ^deleteUser$ objects/userDelete.json.php [NC,L] RewriteRule ^recoverPass$ objects/userRecoverPass.php [NC,L] RewriteRule ^saveRecoverPassword$ objects/userRecoverPassSave.json.php [NC,L] RewriteRule ^signUp$ view/signUp.php [NC,L] RewriteRule ^createUser$ objects/userCreate.json.php [NC,L] RewriteRule ^usersGroups$ view/managerUsersGroups.php [NC,L] RewriteRule ^usersGroups.json$ objects/usersGroups.json.php [NC,L] RewriteRule ^addNewUserGroups$ objects/userGroupsAddNew.json.php [NC,L] RewriteRule ^deleteUserGroups$ objects/userGroupsDelete.json.php [NC,L] #manager category RewriteRule ^categories$ view/managerCategories.php [NC,L] RewriteRule ^categories.json$ objects/categories.json.php [NC,L] RewriteRule ^addNewCategory$ objects/categoryAddNew.json.php [NC,L] RewriteRule ^deleteCategory$ objects/categoryDelete.json.php [NC,L] #manager plugin RewriteRule ^plugins$ view/managerPlugins.php [NC,L] RewriteRule ^plugins.json$ objects/plugins.json.php [NC,L] RewriteRule ^pluginsAvailable.json$ objects/pluginsAvailable.json.php [NC,L] RewriteRule ^pluginImport.json$ objects/pluginImport.json.php [NC,L] RewriteRule ^switchPlugin$ objects/pluginSwitch.json.php [NC,L] RewriteRule ^addDataObjectPlugin.json$ objects/pluginAddDataObject.json.php [NC,L] RewriteRule ^runDBScriptPlugin.json$ objects/pluginRunDatabaseScript.json.php [NC,L] #manager playList RewriteRule ^playLists.json$ objects/playlists.json.php [NC,L] RewriteRule ^playListsVideos.json$ objects/playlistsVideos.json.php [NC,L] RewriteRule ^playListsFromUser.json/([0-9]+)/?$ objects/playlistsFromUser.json.php?users_id=$1 [NC,L] RewriteRule ^addNewPlayList$ objects/playlistAddNew.json.php [NC,L] RewriteRule ^playListAddVideo.json$ objects/playListAddVideo.json.php [NC,L] RewriteRule ^playlist/([0-9]+)/([0-9]+)/?$ view/?playlist_id=$1&playlist_index=$2 [NC,L] RewriteRule ^playlist/([0-9]+)/?$ view/?playlist_id=$1 [NC,L] RewriteRule ^removeVideoFromPlaylist/?$ objects/playlistRemoveVideo.php [NC,L] RewriteRule ^removePlaylist/?$ objects/playlistRemove.php [NC,L] RewriteRule ^renamePlaylist/?$ objects/playlistRename.php [NC,L] RewriteRule ^sortPlaylist/?$ objects/playlistSort.php [NC,L] RewriteRule ^channel/([^/]+)/?$ view/channel.php?channelName=$1 [QSA] RewriteRule ^channel/([^/]+)/feed/?$ feed/index.php?channelName=$1 [QSA] RewriteRule ^channel/?$ view/channel.php [QSA] RewriteRule ^channels/?$ view/channels.php [NC,L] #manager videos RewriteRule ^orphanFiles$ view/orphanFiles.php [NC,L] RewriteRule ^mvideos$ view/managerVideos.php [NC,L] RewriteRule ^videos.json$ objects/videos.json.php [NC,L] RewriteRule ^videosAndroid.json$ objects/videosAndroid.json.php [NC,L] RewriteRule ^videoAndroid.json$ objects/videoAndroid.json.php [NC,L] RewriteRule ^deleteVideo$ objects/videoDelete.json.php [NC,L] RewriteRule ^addNewVideo$ objects/videoAddNew.json.php [NC,L] RewriteRule ^refreshVideo$ objects/videoRefresh.json.php [NC,L] RewriteRule ^setStatusVideo$ objects/videoStatus.json.php [NC,L] RewriteRule ^setCategoryVideo$ objects/videoCategory.json.php [NC,L] RewriteRule ^reencodeVideo$ objects/videoReencode.json.php [NC,L] RewriteRule ^rotateVideo$ objects/videoRotate.json.php [NC,L] # Subscribes RewriteRule ^subscribes$ view/managerSubscribes.php [NC,L] RewriteRule ^subscribes.json$ objects/subscribes.json.php [NC,L] RewriteRule ^subscribe.json$ objects/subscribe.json.php [NC,L] RewriteRule ^notifySubscribers.json$ objects/notifySubscribers.json.php [NC,L] RewriteRule ^youPHPTubeQueueEncoder.json$ objects/youPHPTubeQueueEncoder.json.php [NC,L] RewriteRule ^youPHPTubeEncoder.json$ objects/youPHPTubeEncoder.json.php [NC,L] #comment RewriteRule ^comments$ view/managerComments.php [NC,L] RewriteRule ^saveComment$ objects/commentAddNew.json.php [NC,L] RewriteRule ^comments.json/([0-9]+)$ objects/comments.json.php?video_id=$1 [NC,L] RewriteRule ^login$ objects/login.json.php [NC,L] RewriteRule ^logoff$ objects/logoff.php [NC,L] RewriteRule ^like$ objects/like.json.php?like=1 [QSA] RewriteRule ^dislike$ objects/like.json.php?like=-1 [QSA] #manager configuration RewriteRule ^update/?$ view/update.php [NC,L] RewriteRule ^siteConfigurations$ view/configurations.php [NC,L] RewriteRule ^updateConfig$ objects/configurationUpdate.json.php [NC,L] RewriteRule ^charts$ view/charts.php [NC,L] RewriteRule ^help$ view/help.php [NC,L] # YouTube Sync RewriteRule ^youtubeUpload$ objects/youtubeUpload.json.php [NC,L] RewriteRule ^googleAdView$ view/googleAdView.php [NC,L] RewriteRule ^notifications.json$ objects/notifications.json.php [NC,L] RewriteRule ^sitemap.xml$ view/sitemap.xml.php [NC,L] RewriteRule ^robots.txt$ view/robots.txt.php [NC,L] RewriteRule ^videos/(.*)/index.m3u8$ view/hls.php?videoDirectory=$1 [NC,L,QSA] + + RewriteRule ^vast.xml/?([0-9]+)?$ plugin/AD_Server/VAST.php?campaign_has_videos_id=$1 [NC,L] # It must be before image not found RewriteRule ^videos/([A-Za-z0-9-_.]+)$ view/xsendfile.php?file=$1 [QSA] # if image do not exists RewriteCond %{REQUEST_URI} \.(jpg|jpeg|gif|png|ico)$ [NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .*$ img/image404.php [NC,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule .*$ view/error.php [NC,L] # Compress HTML, CSS, JavaScript, Text, XML and fonts AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/vnd.ms-fontobject AddOutputFilterByType DEFLATE application/x-font AddOutputFilterByType DEFLATE application/x-font-opentype AddOutputFilterByType DEFLATE application/x-font-otf AddOutputFilterByType DEFLATE application/x-font-truetype AddOutputFilterByType DEFLATE application/x-font-ttf AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE font/opentype AddOutputFilterByType DEFLATE font/otf AddOutputFilterByType DEFLATE font/ttf AddOutputFilterByType DEFLATE image/svg+xml AddOutputFilterByType DEFLATE image/x-icon AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/javascript AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/xml \ No newline at end of file diff --git a/objects/playlist.php b/objects/playlist.php index d65534e3c..a370aac28 100644 --- a/objects/playlist.php +++ b/objects/playlist.php @@ -1,366 +1,368 @@ setName($name); $row = self::getFromDbFromName($this->getName()); if (empty($row)) return false; foreach ($row as $key => $value) { $this->$key = $value; } return true; } /** * * @global type $global * @param type $publicOnly * @param type $userId if not present check session * @param type $isVideoIdPresent pass the ID of the video checking * @return boolean */ static function getAllFromUser($userId, $publicOnly = true, $status = false) { global $global, $config; $formats = ""; $values = array(); $sql = "SELECT u.*, pl.* FROM " . static::getTableName() . " pl " . " LEFT JOIN users u ON u.id = users_id WHERE 1=1 "; if (!empty($status)) { $status = str_replace("'","", $status); $sql .= " AND pl.status = '{$status}' "; } else if ($publicOnly) { $sql .= " AND pl.status = 'public' "; } if (!empty($userId)) { $sql .= " AND users_id = ? "; $formats .= "i"; $values[] = $userId; } $sql .= self::getSqlFromPost("pl."); //echo $sql, $userId;exit; $res = sqlDAL::readSql($sql, $formats, $values); $fullData = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); $rows = array(); $favorite = array(); $watch_later = array(); if ($res != false) { foreach ($fullData as $row) { $row['videos'] = static::getVideosFromPlaylist($row['id']); if ($row['status'] === "favorite") { $favorite = $row; } else if ($row['status'] === "watch_later") { $watch_later = $row; } else { $rows[] = $row; } } if (empty($status) && $config->currentVersionGreaterThen("6.4")) { if (empty($favorite)) { $pl = new PlayList(0); $pl->setName("Favorite"); $pl->setStatus("favorite"); $pl->setUsers_id($userId); $id = $pl->save(); $row['id'] = $id; $row['name'] = $pl->getName(); $row['status'] = $pl->getStatus(); $row['users_id'] = $pl->getUsers_id(); $favorite = $row; } if (empty($watch_later)) { $pl = new PlayList(0); $pl->setName("Watch Later"); $pl->setStatus("watch_later"); $pl->setUsers_id($userId); $id = $pl->save(); $row['id'] = $id; $row['name'] = $pl->getName(); $row['status'] = $pl->getStatus(); $row['users_id'] = $pl->getUsers_id(); $watch_later = $row; } } if (!empty($favorite)) { array_unshift($rows, $favorite); } if (!empty($watch_later)) { array_unshift($rows, $watch_later); } } else { die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } return $rows; } static function getAllFromUserVideo($userId, $videos_id, $publicOnly = true, $status = false) { $rows = self::getAllFromUser($userId, $publicOnly, $status); foreach ($rows as $key => $value) { $videos = self::getVideosIdFromPlaylist($value['id']); $rows[$key]['isOnPlaylist'] = in_array($videos_id, $videos); } return $rows; } static function getVideosFromPlaylist($playlists_id) { global $global; $sql = "SELECT *,v.created as cre, p.`order` as video_order, v.externalOptions as externalOptions " . ", (SELECT count(id) FROM likes as l where l.videos_id = v.id AND `like` = 1 ) as likes " . " FROM playlists_has_videos p " . " LEFT JOIN videos as v ON videos_id = v.id " . " LEFT JOIN users u ON u.id = v.users_id " . " WHERE playlists_id = ? ORDER BY p.`order` ASC "; $sql .= self::getSqlFromPost(); $res = sqlDAL::readSql($sql, "i", array($playlists_id)); $fullData = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); $rows = array(); if ($res != false) { foreach ($fullData as $row) { if (!empty($_GET['isChannel'])) { $row['tags'] = Video::getTags($row['id']); $row['pluginBtns'] = YouPHPTubePlugin::getPlayListButtons($playlists_id); $row['humancreate'] = humanTiming(strtotime($row['cre'])); } $row['progress'] = Video::getVideoPogressPercent($row['videos_id']); $row['title'] = UTF8encode($row['title']); $row['description'] = UTF8encode($row['description']); + unset($row['password']); + unset($row['recoverPass']); //unset($row['description']); $rows[] = $row; } } else { die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } return $rows; } static function isVideoOnFavorite($videos_id, $users_id) { return self::isVideoOn($videos_id, $users_id, 'favorite'); } static function isVideoOnWatchLater($videos_id, $users_id) { return self::isVideoOn($videos_id, $users_id, 'watch_later'); } private static function isVideoOn($videos_id, $users_id, $status) { global $global; $status = str_replace("'","", $status); $sql = "SELECT pl.id FROM " . static::getTableName() . " pl " . " LEFT JOIN users u ON u.id = users_id " . " LEFT JOIN playlists_has_videos p ON pl.id = playlists_id" . " LEFT JOIN videos as v ON videos_id = v.id " . " WHERE videos_id = ? AND pl.users_id = ? AND pl.status = '{$status}' LIMIT 1 "; //echo $videos_id," - " ,$users_id, $sql; $res = sqlDAL::readSql($sql, "ii", array($videos_id, $users_id)); $data = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($res) { $row = $data; } else { $row = false; } return $row; } static function getFavoriteIdFromUser($users_id) { $favorite = self::getIdFromUser($users_id, "favorite"); if(empty($favorite)){ $pl = new PlayList(0); $pl->setName("Favorite"); $pl->setUsers_id($users_id); $pl->setStatus("favorite"); $pl->save(); $favorite = self::getIdFromUser($users_id, "favorite"); } return $favorite; } static function getWatchLaterIdFromUser($users_id) { $watch_later = self::getIdFromUser($users_id, "watch_later"); if(empty($watch_later)){ $pl = new PlayList(0); $pl->setName("Watch Later"); $pl->setUsers_id($users_id); $pl->setStatus("watch_later"); $pl->save(); $watch_later = self::getIdFromUser($users_id, "watch_later"); } return $watch_later; } private static function getIdFromUser($users_id, $status) { global $global; $status = str_replace("'","", $status); $sql = "SELECT * FROM " . static::getTableName() . " pl WHERE" . " users_id = ? AND pl.status = '{$status}' LIMIT 1 "; $res = sqlDAL::readSql($sql, "i", array($users_id)); $data = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($res) { $row = $data['id']; } else { $row = false; } return $row; } static function getVideosIdFromPlaylist($playlists_id) { $videosId = array(); $rows = static::getVideosFromPlaylist($playlists_id); foreach ($rows as $value) { $videosId[] = $value['videos_id']; } return $videosId; } static function sortVideos($videosList, $listIdOrder) { $list = array(); foreach ($listIdOrder as $value) { foreach ($videosList as $key => $value2) { if ($value2['id'] == $value) { $list[] = $value2; unset($videosList[$key]); } } } return $list; } public function save() { if (!User::isLogged()) { return false; } $this->clearEmptyLists(); $users_id = User::getId(); $this->setUsers_id($users_id); return parent::save(); } /** * This is just to fix errors from the update 6.4 to 6.5, where empty playlists were created before the update * @return type */ private function clearEmptyLists() { $sql = "DELETE FROM " . static::getTableName() . " WHERE status = ''"; return sqlDAL::writeSql($sql); } public function addVideo($video_id, $add, $order = 0) { global $global; $formats = ""; $values = array(); if (empty($add) || $add === "false") { $sql = "DELETE FROM playlists_has_videos WHERE playlists_id = ? AND videos_id = ? "; $formats = "ii"; $values[] = $this->id; $values[] = $video_id; } else { $this->addVideo($video_id, false); $sql = "INSERT INTO playlists_has_videos ( playlists_id, videos_id , `order`) VALUES (?, ?, ?) "; $formats = "iii"; $values[] = $this->id; $values[] = $video_id; $values[] = $order; } return sqlDAL::writeSql($sql, $formats, $values); } public function delete() { if (empty($this->id)) { return false; } global $global; $sql = "DELETE FROM playlists WHERE id = ? "; //echo $sql; return sqlDAL::writeSql($sql, "i", array($this->id)); } function getId() { return $this->id; } function getName() { return $this->name; } function getUsers_id() { return $this->users_id; } function getStatus() { return $this->status; } function setId($id) { $this->id = $id; } function setName($name) { if (strlen($name) > 45) $name = substr($name, 0, 42) . '...'; $this->name = xss_esc($name); //var_dump($name,$this->name);exit; } function setUsers_id($users_id) { $this->users_id = $users_id; } function setStatus($status) { if (!in_array($status, self::$validStatus)) { $status = 'public'; } $this->status = $status; } static function canSee($playlist_id, $users_id) { $obj = new PlayList($playlist_id); $status = $obj->getStatus(); if ($status !== 'public' && $status !== 'unlisted' && $users_id != $obj->getUsers_id()) { return false; } return true; } } diff --git a/plugin/AD_Server/Objects/VastCampaignsVideos.php b/plugin/AD_Server/Objects/VastCampaignsVideos.php old mode 100755 new mode 100644 index 88ce1974f..447159770 --- a/plugin/AD_Server/Objects/VastCampaignsVideos.php +++ b/plugin/AD_Server/Objects/VastCampaignsVideos.php @@ -1,174 +1,177 @@ $value) { $this->$key = $value; } return true; } static protected function getCampainVideo($vast_campaigns_id, $videos_id) { global $global; $vast_campaigns_id = intval($vast_campaigns_id); $videos_id = intval($videos_id); $sql = "SELECT * FROM " . static::getTableName() . " WHERE vast_campaigns_id = ? , videos_id = ? LIMIT 1"; // I had to add this because the about from customize plugin was not loading on the about page http://127.0.0.1/YouPHPTube/about $res = sqlDAL::readSql($sql,"ii",array($vast_campaigns_id, $videos_id)); $data = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($res) { $row = $data; } else { $row = false; } return $row; } static function getRandomCampainVideo($vast_campaigns_id) { global $global; $vast_campaigns_id = intval($vast_campaigns_id); if(empty($vast_campaigns_id)){ $campaings = VastCampaigns::getValidCampaigns(); + if(empty($campaings[0])){ + return false; + } $vast_campaigns_id = $campaings[0]['id']; } $sql = "SELECT * FROM " . static::getTableName() . " WHERE vast_campaigns_id = ? ORDER BY RAND() LIMIT 1"; // I had to add this because the about from customize plugin was not loading on the about page http://127.0.0.1/YouPHPTube/about $res = sqlDAL::readSql($sql,"i",array($vast_campaigns_id)); $data = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($res) { $row = $data; } else { $row = false; } return $row; } static function getAllFromCampaign($vast_campaigns_id, $getImages = false) { global $global; $vast_campaigns_id = intval($vast_campaigns_id); $sql = "SELECT v.*, c.* FROM " . static::getTableName() . " c " . " LEFT JOIN videos v ON videos_id = v.id WHERE 1=1 "; if(!empty($vast_campaigns_id)){ $sql .= " AND vast_campaigns_id=$vast_campaigns_id "; } $sql .= self::getSqlFromPost(); $res = sqlDAL::readSql($sql); $fullData = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); $rows = array(); if ($res!=false) { foreach ($fullData as $row) { if($getImages){ $row['poster'] = Video::getImageFromID($row['videos_id']); } $row['data'] = VastCampaignsLogs::getDataFromCampaign($row['vast_campaigns_id']); $rows[] = $row; } } else { die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } return $rows; } static public function getValidVideos($vast_campaigns_id){ global $global; $sql = "SELECT v.*, c.* from " . static::getTableName() . " c LEFT JOIN videos v ON v.id = videos_id WHERE vast_campaigns_id = ? AND c.status = 'a' "; $res = sqlDAL::readSql($sql,"i",array($vast_campaigns_id)); $rows = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); $r = array(); if ($res!=false) { foreach($rows as $row) { $r[] = $row; } } return $r; } function getId() { return $this->id; } function getVast_campaigns_id() { return $this->vast_campaigns_id; } function getVideos_id() { return $this->videos_id; } function getStatus() { return $this->status; } function setId($id) { $this->id = $id; } function setVast_campaigns_id($vast_campaigns_id) { $this->vast_campaigns_id = $vast_campaigns_id; } function setVideos_id($videos_id) { $this->videos_id = $videos_id; } function setStatus($status) { $this->status = $status; } function getLink() { return $this->link; } function getAd_title() { return $this->ad_title; } function setLink($link) { $this->link = $link; } function setAd_title($ad_title) { $this->ad_title = $ad_title; } function delete() { global $global; if (!empty($this->id)) { $sql = "DELETE FROM vast_campaigns_logs "; $sql .= " WHERE vast_campaigns_has_videos_id = ?"; $global['lastQuery'] = $sql; //error_log("Delete Query: ".$sql); $campaigns_video_log = sqlDAL::writeSql($sql,"i",array($this->id)); } return parent::delete(); } } diff --git a/plugin/AD_Server/VAST.php b/plugin/AD_Server/VAST.php index 8510bb582..f755c09ef 100644 --- a/plugin/AD_Server/VAST.php +++ b/plugin/AD_Server/VAST.php @@ -1,91 +1,93 @@ getVideos_id()); $files = getVideosURL($video->getFilename()); ?> GDFP External NCA1C1L1 Preroll plugin/AD_Server/log.php?label=Error&[ERRORCODE]]]> plugin/AD_Server/log.php?label=Impression&ad_mt=[AD_MT]&campaign_has_videos_id=]]> getDuration(); ?> plugin/AD_Server/log.php?label=start&ad_mt=[AD_MT]&campaign_has_videos_id=]]> plugin/AD_Server/log.php?label=firstQuartile&ad_mt=[AD_MT]&campaign_has_videos_id=]]> plugin/AD_Server/log.php?label=midpoint&ad_mt=[AD_MT]&campaign_has_videos_id=]]> plugin/AD_Server/log.php?label=thirdQuartile&ad_mt=[AD_MT]&campaign_has_videos_id=]]> plugin/AD_Server/log.php?label=complete&ad_mt=[AD_MT]&campaign_has_videos_id=]]> plugin/AD_Server/log.php?label=mute&ad_mt=[AD_MT]&campaign_has_videos_id=]]> plugin/AD_Server/log.php?label=unmute&ad_mt=[AD_MT]&campaign_has_videos_id=]]> plugin/AD_Server/log.php?label=rewind&ad_mt=[AD_MT]&campaign_has_videos_id=]]> plugin/AD_Server/log.php?label=pause&ad_mt=[AD_MT]&campaign_has_videos_id=]]> plugin/AD_Server/log.php?label=resume&ad_mt=[AD_MT]&campaign_has_videos_id=]]> plugin/AD_Server/log.php?label=fullscreen&ad_mt=[AD_MT]&campaign_has_videos_id=]]> plugin/AD_Server/log.php?label=creativeView&ad_mt=[AD_MT]&campaign_has_videos_id=]]> plugin/AD_Server/log.php?label=exitFullscreen&ad_mt=[AD_MT]&campaign_has_videos_id=]]> plugin/AD_Server/log.php?label=acceptInvitationLinear&ad_mt=[AD_MT]&campaign_has_videos_id=]]> plugin/AD_Server/log.php?label=closeLinear&ad_mt=[AD_MT]&campaign_has_videos_id=]]> getLink(); - if (filter_var($link, FILTER_VALIDATE_URL)) { - ?> - - plugin/AD_Server/log.php?label=ClickThrough&campaign_has_videos_id=]]> - - getLink(); + if (filter_var($link, FILTER_VALIDATE_URL)) { + ?> + + plugin/AD_Server/log.php?label=ClickThrough&campaign_has_videos_id=]]> + + $value) { if (!empty($files["mp4{$value}"])) { echo "\n " . ''; } if (!empty($files["webm{$value}"])) { echo "\n " . ''; } } ?> view/img/logo.png]]> plugin/AD_Server/log.php?label=creativeView&ad_mt=[AD_MT]&campaign_has_videos_id=]]> plugin/AD_Server/log.php?label=CompanionClickThrough&ad_mt=[AD_MT]&campaign_has_videos_id=]]> diff --git a/plugin/API/API.php b/plugin/API/API.php index 9283af6be..929761e0a 100644 --- a/plugin/API/API.php +++ b/plugin/API/API.php @@ -1,449 +1,453 @@ APISecret = md5($global['systemRootPath']); return $obj; } public function getPluginMenu() { global $global; $fileAPIName = $global['systemRootPath'] . 'plugin/API/pluginMenu.html'; return file_get_contents($fileAPIName); } public function set($parameters) { if (empty($parameters['APIName'])) { $object = new ApiObject("Parameter APIName can not be empty"); } else { if (!empty($parameters['pass'])) { $parameters['password'] = $parameters['pass']; } if (!empty($parameters['encodedPass']) && strtolower($parameters['encodedPass']) === 'false') { $parameters['encodedPass'] = false; } if (!empty($parameters['user']) && !empty($parameters['password'])) { $user = new User("", $parameters['user'], $parameters['password']); $user->login(false, @$parameters['encodedPass']); } $APIName = $parameters['APIName']; if (method_exists($this, "set_api_$APIName")) { $str = "\$object = \$this->set_api_$APIName(\$parameters);"; eval($str); } else { $object = new ApiObject(); } } return $object; } public function get($parameters) { if (empty($parameters['APIName'])) { $object = new ApiObject("Parameter APIName can not be empty"); } else { if (!empty($parameters['pass'])) { $parameters['password'] = $parameters['pass']; } if (!empty($parameters['user']) && !empty($parameters['password'])) { if (!empty($parameters['encodedPass']) && strtolower($parameters['encodedPass']) === 'false') { $parameters['encodedPass'] = false; } $user = new User("", $parameters['user'], $parameters['password']); $user->login(false, @$parameters['encodedPass']); } $APIName = $parameters['APIName']; if (method_exists($this, "get_api_$APIName")) { $str = "\$object = \$this->get_api_$APIName(\$parameters);"; eval($str); } else { $object = new ApiObject(); } } return $object; } private function startResponseObject($parameters) { $obj = new stdClass(); if (empty($parameters['sort']) && !empty($parameters['order'][0]['dir'])) { $index = intval($parameters['order'][0]['column']); $parameters['sort'][$parameters['columns'][$index]['data']] = $_GET['order'][0]['dir']; } $array = array('sort', 'rowCount', 'current', 'searchPhrase'); foreach ($array as $value) { if (!empty($parameters[$value])) { $obj->$value = $parameters[$value]; $_POST[$value] = $parameters[$value]; } } return $obj; } private function getToPost() { foreach ($_GET as $key => $value) { $_POST[$key] = $value; } } /** * @param type $parameters * ['sort' database sort column] * ['rowCount' max numbers of rows] * ['current' current page] * ['searchPhrase' to search on the categories] * ['parentsOnly' will bring only the parents, not children categories] * @example {webSiteRootURL}plugin/API/{getOrSet}.json.php?APIName={APIName}&rowCount=3¤t=1&sort[created]=DESC * @return \ApiObject */ public function get_api_category($parameters) { global $global; require_once $global['systemRootPath'] . 'objects/category.php'; $obj = $this->startResponseObject($parameters); $rows = Category::getAllCategories(); $totalRows = Category::getTotalCategories(); $obj->totalRows = $totalRows; $obj->rows = $rows; return new ApiObject("", false, $obj); } /** * @param type $parameters * ['APISecret' to list all videos] * ['sort' database sort column] * ['videos_id' the video id (will return only 1 or 0 video)] * ['clean_title' the video clean title (will return only 1 or 0 video)] * ['rowCount' max numbers of rows] * ['current' current page] * ['searchPhrase' to search on the categories] * ['tags_id' the ID of the tag you want to filter] * ['catName' the clean_APIName of the category you want to filter] * ['channelName' the channelName of the videos you want to filter] * @example {webSiteRootURL}plugin/API/{getOrSet}.json.php?APIName={APIName}&catName=default&rowCount=10 * @return \ApiObject */ public function get_api_video($parameters) { global $global; require_once $global['systemRootPath'] . 'objects/video.php'; $obj = $this->startResponseObject($parameters); $dataObj = $this->getDataObject(); if ($dataObj->APISecret === @$_GET['APISecret']) { $rows = Video::getAllVideos("viewable", false, true); $totalRows = Video::getTotalVideos("viewable", false, true); } else if (!empty($parameters['videos_id'])) { $rows = array(Video::getVideo($parameters['videos_id'])); $totalRows = empty($rows) ? 0 : 1; } else if (!empty($parameters['clean_title'])) { $rows = Video::getVideoFromCleanTitle($parameters['clean_title']); $totalRows = empty($rows) ? 0 : 1; } else { $rows = Video::getAllVideos(); $totalRows = Video::getTotalVideos(); } $objMob = YouPHPTubePlugin::getObjectData("MobileManager"); $SubtitleSwitcher = YouPHPTubePlugin::loadPluginIfEnabled("SubtitleSwitcher"); foreach ($rows as $key => $value) { if (is_object($value)) { $value = object_to_array($value); } if (empty($value['filename'])) { continue; } + if($value['type']=='serie'){ + require_once $global['systemRootPath'] . 'objects/playlist.php'; + $rows[$key]['playlist'] = PlayList::getVideosFromPlaylist($value['serie_playlists_id']); + } $images = Video::getImageFromFilename($rows[$key]['filename'], $rows[$key]['type']); $rows[$key]['images'] = $images; $rows[$key]['videos'] = Video::getVideosPaths($value['filename'], true); $rows[$key]['Poster'] = !empty($objMob->portraitImage) ? $images->posterPortrait : $images->poster; $rows[$key]['Thumbnail'] = !empty($objMob->portraitImage) ? $images->posterPortraitThumbs : $images->thumbsJpg; $rows[$key]['imageClass'] = !empty($objMob->portraitImage) ? "portrait" : "landscape"; $rows[$key]['createdHumanTiming'] = humanTiming(strtotime($rows[$key]['created'])); $rows[$key]['pageUrl'] = "{$global['webSiteRootURL']}video/" . $rows[$key]['clean_title']; $rows[$key]['embedUrl'] = "{$global['webSiteRootURL']}videoEmbeded/" . $rows[$key]['clean_title']; $rows[$key]['UserPhoto'] = User::getPhoto($rows[$key]['users_id']); if ($SubtitleSwitcher) { $rows[$key]['subtitles'] = getVTTTracks($value['filename'], true); } if (!empty($_REQUEST['complete'])) { require_once $global['systemRootPath'] . 'objects/comment.php'; require_once $global['systemRootPath'] . 'objects/subscribe.php'; unset($_POST['sort']); unset($_POST['current']); unset($_POST['searchPhrase']); $_POST['rowCount'] = 10; $_POST['sort']['created'] = "desc"; $rows[$key]['comments'] = Comment::getAllComments($rows[$key]['id']); $rows[$key]['commentsTotal'] = Comment::getTotalComments($rows[$key]['id']); foreach ($rows[$key]['comments'] as $key2 => $value2) { $user = new User($value2['users_id']); $rows[$key]['comments'][$key2]['userPhotoURL'] = User::getPhoto($rows[$key]['comments'][$key2]['users_id']); $rows[$key]['comments'][$key2]['userName'] = $user->getNameIdentificationBd(); } $rows[$key]['subscribers'] = Subscribe::getTotalSubscribes($rows[$key]['users_id']); } } $obj->totalRows = $totalRows; $obj->rows = $rows; return new ApiObject("", false, $obj); } /** * @param type $parameters * 'videos_id' the video ID what you want to get the likes * @example {webSiteRootURL}plugin/API/{getOrSet}.json.php?APIName={APIName}&videos_id=1 * @return \ApiObject */ public function get_api_likes($parameters) { global $global; require_once $global['systemRootPath'] . 'objects/like.php'; if (empty($parameters['videos_id'])) { return new ApiObject("Videos ID can not be empty"); } return new ApiObject("", false, Like::getLikes($parameters['videos_id'])); } /** * @param type $parameters (all parameters are mandatories) * 'videos_id' the video ID what you want to send the like * 'user' usename of the user that will like the video * 'pass' password of the user that will like the video * @example {webSiteRootURL}plugin/API/{getOrSet}.json.php?APIName={APIName}&videos_id=1&user=admin&pass=123 * @return \ApiObject */ public function set_api_like($parameters) { return $this->like($parameters, 1); } /** * @param type $parameters (all parameters are mandatories) * 'videos_id' the video ID what you want to send the like * 'user' usename of the user that will like the video * 'pass' password of the user that will like the video * @example {webSiteRootURL}plugin/API/{getOrSet}.json.php?APIName={APIName}&videos_id=1&user=admin&pass=123 * @return \ApiObject */ public function set_api_dislike($parameters) { return $this->like($parameters, -1); } /** * @param type $parameters (all parameters are mandatories) * 'videos_id' the video ID what you want to send the like * 'user' usename of the user that will like the video * 'pass' password of the user that will like the video * @example {webSiteRootURL}plugin/API/{getOrSet}.json.php?APIName={APIName}&videos_id=1&user=admin&pass=123 * @return \ApiObject */ public function set_api_removelike($parameters) { return $this->like($parameters, 0); } /** * * @param type $parameters * 'user' usename of the user * 'pass' password of the user * ['encodedPass' tell the script id the password submited is raw or encrypted] * @example {webSiteRootURL}plugin/API/{getOrSet}.json.php?APIName={APIName}&user=admin&pass=f321d14cdeeb7cded7489f504fa8862b&encodedPass=true * @return type */ public function get_api_signIn($parameters) { global $global; $this->getToPost(); require_once $global['systemRootPath'] . 'objects/login.json.php'; exit; } /** * * @param type $parameters * 'user' usename of the user * 'pass' password of the user * 'email' email of the user * 'name' real name of the user * 'APISecret' mandatory for security reasons * @example {webSiteRootURL}plugin/API/{getOrSet}.json.php?APIName={APIName}&APISecret={APISecret}&user=admin&pass=123&email=me@mysite.com&name=Yeshua * @return type */ public function set_api_signUp($parameters) { global $global; $this->getToPost(); $obj = $this->getDataObject(); if ($obj->APISecret !== @$_GET['APISecret']) { return new ApiObject("APISecret Not valid"); } $ignoreCaptcha = 1; require_once $global['systemRootPath'] . 'objects/userCreate.json.php'; exit; } private function like($parameters, $like) { global $global; require_once $global['systemRootPath'] . 'objects/like.php'; if (empty($parameters['videos_id'])) { return new ApiObject("Videos ID can not be empty"); } if (!User::isLogged()) { return new ApiObject("User must be logged"); } new Like($like, $parameters['videos_id']); return new ApiObject("", false, Like::getLikes($parameters['videos_id'])); } /** * If you do not pass the user and password, it will always show ads, if you pass it the script will check if will display ads or not * @param type $parameters * 'videos_id' the video id to calculate the ads length * ['optionalAdTagUrl' a tag number 1 or 2 or 3 or 4 to use another tag, if do not pass it will use the default tag] * ['user' usename of the user] * ['pass' password of the user] * ['encodedPass' tell the script id the password submited is raw or encrypted] * @example {webSiteRootURL}plugin/API/{getOrSet}.json.php?APIName={APIName}&videos_id=3&user=admin&pass=f321d14cdeeb7cded7489f504fa8862b&encodedPass=true&optionalAdTagUrl=2 * @return type */ public function get_api_vmap($parameters) { global $global; $this->getToPost(); require_once $global['systemRootPath'] . 'plugin/GoogleAds_IMA/VMAP.php'; exit; } /** * Return the location based on the provided IP * @param type $parameters * 'APISecret' mandatory for security reasons * 'ip' Ip to verify * @example {webSiteRootURL}plugin/API/{getOrSet}.json.php?APIName={APIName}&APISecret={APISecret}&ip=2.20.147.123 * @return type */ public function get_api_IP2Location($parameters) { global $global; $this->getToPost(); $obj = $this->getDataObject(); if ($obj->APISecret !== @$_GET['APISecret']) { return new ApiObject("APISecret Not valid"); } if (YouPHPTubePlugin::isEnabledByName("User_Location")) { $row = IP2Location::getLocation($parameters['ip']); if (!empty($row)) { return new ApiObject("", false, $row); } } return new ApiObject("IP2Location not working"); exit; } /** * Return all favorites from a user * @param type $parameters * 'user' usename of the user * 'pass' password of the user * 'encodedPass' tell the script id the password submited is raw or encrypted * @example {webSiteRootURL}plugin/API/{getOrSet}.json.php?APIName={APIName}&user=admin&pass=f321d14cdeeb7cded7489f504fa8862b&encodedPass=true * @return type */ public function get_api_favorite($parameters) { $plugin = YouPHPTubePlugin::loadPluginIfEnabled("PlayLists"); if (empty($plugin)) { return new ApiObject("Plugin disabled"); } if (!User::isLogged()) { return new ApiObject("User must be logged"); } $row = PlayList::getAllFromUser(User::getId(), false, 'favorite'); foreach ($row as $key => $value) { unset($row[$key]['password']); unset($row[$key]['recoverPass']); foreach ($value['videos'] as $key2 => $value2) { //$row[$key]['videos'][$key2] = Video::getVideo($value2['id']); unset($row[$key]['videos'][$key2]['password']); unset($row[$key]['videos'][$key2]['recoverPass']); if (!empty($row[$key]['videos'][$key2]['next_videos_id'])) { unset($_POST['searchPhrase']); $row[$key]['videos'][$key2]['next_video'] = Video::getVideo($row[$key]['videos'][$key2]['next_videos_id']); } $row[$key]['videos'][$key2]['videosURL'] = getVideosURL($row[$key]['videos'][$key2]['filename']); unset($row[$key]['videos'][$key2]['password']); unset($row[$key]['videos'][$key2]['recoverPass']); } } echo json_encode($row); exit; } /** * add a video into a user favorite play list * @param type $parameters * 'videos_id' the video id that you want to add * 'user' usename of the user * 'pass' password of the user * 'encodedPass' tell the script id the password submited is raw or encrypted * @example {webSiteRootURL}plugin/API/{getOrSet}.json.php?APIName={APIName}&videos_id=3&user=admin&pass=f321d14cdeeb7cded7489f504fa8862b&encodedPass=true * @return type */ public function set_api_favorite($parameters) { $this->favorite($parameters, true); } /** * @param type $parameters * 'videos_id' the video id that you want to remove * 'user' usename of the user * 'pass' password of the user * 'encodedPass' tell the script id the password submited is raw or encrypted * @example {webSiteRootURL}plugin/API/{getOrSet}.json.php?APIName={APIName}&videos_id=3&user=admin&pass=f321d14cdeeb7cded7489f504fa8862b&encodedPass=true * @return type */ public function set_api_removeFavorite($parameters) { $this->favorite($parameters, false); } private function favorite($parameters, $add) { global $global; $plugin = YouPHPTubePlugin::loadPluginIfEnabled("PlayLists"); if (empty($plugin)) { return new ApiObject("Plugin disabled"); } if (!User::isLogged()) { return new ApiObject("Wrong user or password"); } $_POST['videos_id'] = $parameters['videos_id']; $_POST['add'] = $add; $_POST['playlists_id'] = PlayLists::getFavoriteIdFromUser(User::getId()); require_once $global['systemRootPath'] . 'objects/playListAddVideo.json.php'; exit; } } class ApiObject { public $error; public $message; public $response; function __construct($message = "api not started or not found", $error = true, $response = array()) { $this->error = $error; $this->message = $message; $this->response = $response; } } diff --git a/plugin/YPTWallet/YPTWallet.php b/plugin/YPTWallet/YPTWallet.php index 8788bdf05..e044a7d74 100644 --- a/plugin/YPTWallet/YPTWallet.php +++ b/plugin/YPTWallet/YPTWallet.php @@ -1,499 +1,499 @@ decimalPrecision = 2; $obj->wallet_button_title = "My Wallet"; $obj->add_funds_text = "

Adding money instantly from credit/debit card

Add funds on your Account Balance, to support our videos"; $obj->add_funds_success_success = "

Thank you,
Your funds has been added

"; $obj->add_funds_success_cancel = "

Ops,
You have cancel it

"; $obj->add_funds_success_fail = "

Sorry,
Your funds request has been fail

"; $obj->transfer_funds_text = "

Transfer money for other users

Transfer funds from your account to another user account"; $obj->transfer_funds_success_success = "

Thank you,
Your funds has been transfered

"; $obj->transfer_funds_success_fail = "

Sorry,
Your funds transfer request has been fail

"; $obj->withdraw_funds_text = "

Withdraw money from your

Transfer funds from your account to your credit card or bank account"; $obj->withdraw_funds_success_success = "

Thank you,
Your request was submited

"; $obj->withdraw_funds_success_fail = "

Sorry,
Your funds withdraw request has been fail

"; $obj->currency = "USD"; $obj->currency_symbol = "$"; $obj->addFundsOptions = "[5,10,20,50]"; $obj->showWalletOnlyToAdmin = false; $obj->CryptoWalletName = "Bitcoin Wallet Address"; $obj->enableAutomaticAddFundsPage = true; // add funds $obj->enableManualAddFundsPage = false; $obj->manualAddFundsMenuTitle = "Add Funds/Deposit"; $obj->manualAddFundsPageButton = "Notify Deposit Made"; $obj->manualAddFundsNotifyEmail = "yourEmail@yourDomain.com"; $obj->manualAddFundsTransferFromUserId = 1; // sell funds $obj->enableManualWithdrawFundsPage = true; $obj->withdrawFundsOptions = "[5,10,20,50,100,1000]"; $obj->manualWithdrawFundsMenuTitle = "Withdraw Funds"; $obj->manualWithdrawFundsPageButton = "Request Withdraw"; $obj->manualWithdrawFundsNotifyEmail = "yourEmail@yourDomain.com"; $obj->manualWithdrawFundsminimum = 1; $obj->manualWithdrawFundsmaximum = 100; $obj->manualWithdrawFundsTransferToUserId = 1; $plugins = self::getAvailablePlugins(); foreach ($plugins as $value) { $eval = "\$obj->enablePlugin_{$value} = false;"; eval($eval); $dataObj = self::getPluginDataObject($value); $obj = (object) array_merge((array) $obj, (array) $dataObj); } return $obj; } public function getTags() { return array('free', 'monetization'); } public function getBalance($users_id) { $wallet = $this->getWallet($users_id); return $wallet->getBalance(); } public function getBalanceText($users_id) { $balance = $this->getBalanceFormated($users_id); return self::formatCurrency($balance); } public function getBalanceFormated($users_id) { $balance = $this->getBalance($users_id); $obj = $this->getDataObject(); return number_format($balance, $obj->decimalPrecision); } static function formatCurrency($value) { $value = floatval($value); $obj = YouPHPTubePlugin::getObjectData('YPTWallet'); return "{$obj->currency_symbol} " . number_format($value, $obj->decimalPrecision) . " {$obj->currency}"; } static function formatFloat($value) { $value = floatval($value); $obj = YouPHPTubePlugin::getObjectData('YPTWallet'); return number_format($value, $obj->decimalPrecision); } public function getWallet($users_id) { $wallet = new Wallet(0); $wallet->setUsers_id($users_id); return $wallet; } public function getOrCreateWallet($users_id) { $wallet = new Wallet(0); $wallet->setUsers_id($users_id); if (empty($wallet->getId())) { $wallet_id = $wallet->save(); $wallet = new Wallet($wallet_id); } return $wallet; } function getAllUsers($activeOnly = true) { global $global; $sql = "SELECT w.*, u.*, u.id as user_id, IFNULL(balance, 0) as balance FROM users u " . " LEFT JOIN wallet w ON u.id = w.users_id WHERE 1=1 "; if ($activeOnly) { $sql .= " AND status = 'a' "; } $sql .= BootGrid::getSqlFromPost(array('name', 'email', 'user')); $res = $global['mysqli']->query($sql); $user = array(); if ($res) { while ($row = $res->fetch_assoc()) { $row['name'] = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]/u', '', $row['name']); $row['identification'] = User::getNameIdentificationById($row['user_id']); $row['identification'] = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]/u', '', $row['identification']); unset($row['about']); $row['background'] = User::getBackground($row['user_id']); $row['photo'] = User::getPhoto($row['user_id']); $row['crypto_wallet_address'] = ""; $user[] = $row; } //$user = $res->fetch_all(MYSQLI_ASSOC); } else { $user = false; die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } return $user; } static function getTotalBalance() { global $global; $sql = "SELECT sum(balance) as total FROM wallet "; $res = $global['mysqli']->query($sql); $user = array(); if ($res) { if ($row = $res->fetch_assoc()) { return $row['total']; } } else { die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } return 0; } static function getTotalBalanceText() { $value = self::getTotalBalance(); return self::formatCurrency($value); } public function getHistory($user_id) { $wallet = $this->getWallet($user_id); $log = new WalletLog(0); $rows = $log->getAllFromWallet($wallet->getId()); return $rows; } /** * * @param type $users_id * @param type $value * @param type $description * @param type $json_data * @param type $mainWallet_user_id A user ID where the money comes from and where the money goes for */ public function addBalance($users_id, $value, $description = "", $json_data = "{}", $mainWallet_user_id = 0) { global $global; $wallet = $this->getOrCreateWallet($users_id); $balance = $wallet->getBalance(); $balance += $value; $wallet->setBalance($balance); $wallet_id = $wallet->save(); WalletLog::addLog($wallet_id, $value, $description, $json_data, "success", "addBalance"); if (!empty($mainWallet_user_id)) { $wallet = $this->getOrCreateWallet($mainWallet_user_id); $balance = $wallet->getBalance(); $balance += ($value * -1); $wallet->setBalance($balance); $wallet_id = $wallet->save(); $user = new User($users_id); WalletLog::addLog($wallet_id, ($value * -1), " From user ($users_id) " . $user->getUser() . " - " . $description, $json_data, "success", "addBalance to main wallet"); } error_log("YPTWallet::addBalance $wallet_id, $value, $description, $json_data"); } public function saveBalance($users_id, $value) { if (!User::isAdmin()) { return false; } $wallet = $this->getWallet($users_id); $balance = $wallet->getBalance(); $wallet->setBalance($value); $wallet_id = $wallet->save(); $description = "Admin set your balance, from {$balance} to {$value}"; WalletLog::addLog($wallet_id, $value, $description, "{}", "success", "saveBalance"); } public function transferBalanceToSiteOwner($users_id_from, $value, $description = "", $forceTransfer = false) { $obj = $this->getDataObject(); return $this->transferBalance($users_id_from, $obj->manualWithdrawFundsTransferToUserId, $value, $description, $forceTransfer); } public function transferBalanceFromSiteOwner($users_id_from, $value, $description = "", $forceTransfer = false) { $obj = $this->getDataObject(); return $this->transferBalance($obj->manualWithdrawFundsTransferToUserId, $users_id_from, $value, $description, $forceTransfer); } public function transferBalanceFromMeToSiteOwner($value) { if (!User::isLogged()) { return false; } return $this->transferBalanceToSiteOwner(User::getId(), $value); } public function transferBalanceFromOwnerToMe($value) { if (!User::isLogged()) { return false; } return $this->transferBalanceFromSiteOwner(User::getId(), $value); } public function transferBalance($users_id_from, $users_id_to, $value, $forceDescription = "", $forceTransfer = false) { global $global; if (!User::isAdmin()) { if ($users_id_from != User::getId() && !$forceTransfer) { error_log("transferBalance: you are not admin, $users_id_from,$users_id_to, $value"); return false; } } if (!User::idExists($users_id_from) || !User::idExists($users_id_to)) { error_log("transferBalance: user does not exists, $users_id_from,$users_id_to, $value"); return false; } $value = floatval($value); if ($value <= 0) { error_log("transferBalance: invalid value, $users_id_from,$users_id_to, $value"); return false; } $wallet = $this->getWallet($users_id_from); $balance = $wallet->getBalance(); $newBalance = $balance - $value; if ($newBalance < 0) { error_log("transferBalance: you dont have balance, $users_id_from,$users_id_to, $value"); return false; } $identificationFrom = User::getNameIdentificationById($users_id_from); $identificationTo = User::getNameIdentificationById($users_id_to); $wallet->setBalance($newBalance); $wallet_id = $wallet->save(); $description = "Transfer Balance {$value} from YOU to user {$identificationTo}"; if (!empty($forceDescription)) { $description = $forceDescription; } WalletLog::addLog($wallet_id, "-".$value, $description, "{}", "success", "transferBalance to"); $wallet = $this->getWallet($users_id_to); $balance = $wallet->getBalance(); $newBalance = $balance + $value; $wallet->setBalance($newBalance); $wallet_id = $wallet->save(); $description = "Transfer Balance {$value} from user {$identificationFrom} to YOU"; if (!empty($forceDescription)) { $description = $forceDescription; } WalletLog::addLog($wallet_id, $value, $description, "{}", "success", "transferBalance from"); return true; } public function getHTMLMenuRight() { global $global; if (!User::isLogged()) { return ""; } $obj = $this->getDataObject(); if ($obj->showWalletOnlyToAdmin && !User::isAdmin()) { return ""; } include $global['systemRootPath'] . 'plugin/YPTWallet/view/menuRight.php'; } static function getAvailablePayments() { global $global; $dir = self::getPluginDir(); $plugins = self::getEnabledPlugins(); foreach ($plugins as $value) { $subdir = $dir . DIRECTORY_SEPARATOR . $value . DIRECTORY_SEPARATOR; $file = $subdir . "{$value}.php"; if (is_dir($subdir) && file_exists($file)) { require_once $file; $eval = "\$obj = new {$value}();\$obj->getAprovalButton();"; eval($eval); } } } static function getAvailableRecurrentPayments() { global $global; $dir = self::getPluginDir(); $plugins = self::getEnabledPlugins(); foreach ($plugins as $value) { $subdir = $dir . DIRECTORY_SEPARATOR . $value . DIRECTORY_SEPARATOR; $file = $subdir . "{$value}.php"; if (is_dir($subdir) && file_exists($file)) { require_once $file; $eval = "\$obj = new {$value}();\$obj->getRecurrentAprovalButton();"; eval($eval); } } } static function getAvailablePlugins() { $dir = self::getPluginDir(); $dirs = scandir($dir); $plugins = array(); foreach ($dirs as $key => $value) { if (!in_array($value, array(".", ".."))) { $subdir = $dir . DIRECTORY_SEPARATOR . $value . DIRECTORY_SEPARATOR; $file = $subdir . "{$value}.php"; if (is_dir($subdir) && file_exists($file)) { $plugins[] = $value; } } } return $plugins; } static function getEnabledPlugins() { global $global; $plugins = self::getAvailablePlugins(); $wallet = new YPTWallet(); $obj = $wallet->getDataObject(); foreach ($plugins as $key => $value) { $eval = "\$val = \$obj->enablePlugin_{$value};"; eval($eval); if (empty($val)) { unset($plugins[$key]); } } return $plugins; } static function getPluginDataObject($pluginName) { $dir = self::getPluginDir(); $file = $dir . "/{$pluginName}/{$pluginName}.php"; if (file_exists($file)) { require_once $file; $eval = "\$obj = new {$pluginName}();"; eval($eval); return $obj->getEmptyDataObject(); } return array(); } static function getPluginDir() { global $global; $dir = $global['systemRootPath'] . "plugin/YPTWallet/plugins"; return $dir; } function sendEmails($emailsArray, $subject, $message) { global $global, $config; $siteTitle = $config->getWebSiteTitle(); $footer = $config->getWebSiteTitle(); $body = $this->replaceTemplateText($siteTitle, $footer, $message); return $this->send($emailsArray, $subject, $body); } private function replaceTemplateText($siteTitle, $footer, $message) { global $global, $config; $text = file_get_contents("{$global['systemRootPath']}plugin/YPTWallet/template.html"); $words = array($siteTitle, $footer, $message); $replace = array('{siteTitle}', '{footer}', '{message}'); return str_replace($replace, $words, $text); } private function send($emailsArray, $subject, $body) { if (empty($emailsArray)) { return false; } $emailsArray = array_unique($emailsArray); global $global, $config; require_once $global['systemRootPath'] . 'objects/PHPMailer/PHPMailerAutoload.php'; //Create a new PHPMailer instance $mail = new PHPMailer; setSiteSendMessage($mail); //Set who the message is to be sent from $mail->setFrom($config->getContactEmail(), $config->getWebSiteTitle()); //Set who the message is to be sent to foreach ($emailsArray as $value) { if (empty($value)) { continue; } $mail->addBCC($value); } //Set the subject line $mail->Subject = $subject; $mail->msgHTML($body); //send the message, check for errors if (!$mail->send()) { error_log("Wallet email FAIL [{$subject}] {$mail->ErrorInfo}"); return false; } else { error_log("Wallet email sent [{$subject}]"); return true; } } /** * * @param type $wallet_log_id * @param type $new_status * return true if balance is enought */ function processStatus($wallet_log_id, $new_status) { $obj = $this->getDataObject(); $walletLog = new WalletLog($wallet_log_id); $wallet = new Wallet($walletLog->getWallet_id()); $oldStatus = $walletLog->getStatus(); if ($walletLog->getType() == self::MANUAL_WITHDRAW) { if ($new_status != $oldStatus) { if ($oldStatus == "success" || $oldStatus == "pending") { if ($new_status == "canceled") { // return the value return $this->transferBalance($obj->manualWithdrawFundsTransferToUserId, $wallet->getUsers_id(), $walletLog->getValue()); } else { // keep the value return true; } } // get the value again if ($oldStatus == "canceled") { return $this->transferBalance($wallet->getUsers_id(), $obj->manualWithdrawFundsTransferToUserId, $walletLog->getValue()); } } } else if ($walletLog->getType() == self::MANUAL_ADD) { if ($oldStatus == "pending") { if ($new_status == "canceled") { // do nothing return true; } else if ($new_status == "success") { // transfer the value return $this->transferBalance($obj->manualAddFundsTransferFromUserId, $wallet->getUsers_id(), $walletLog->getValue()); } } else if ($oldStatus == "success") { //get the money back return $this->transferBalance($wallet->getUsers_id(), $obj->manualAddFundsTransferFromUserId, $walletLog->getValue()); } else if ($oldStatus == "canceled") { if ($new_status == "pending") { // do nothing return true; } else if ($new_status == "success") { // transfer the value return $this->transferBalance($obj->manualAddFundsTransferFromUserId, $wallet->getUsers_id(), $walletLog->getValue()); } } } return true; } }