From e2920dc1d91b242de1e0ab791ee10e4168059486 Mon Sep 17 00:00:00 2001 From: Puyodead1 <23562356riley@gmail.com> Date: Mon, 17 Dec 2018 16:54:39 -0500 Subject: [PATCH] SlackNotify Plugin --- plugin/DiscordNotify/DiscordNotify.php | 135 ------------------------- plugin/SlackNotify/SlackNotify.php | 75 ++++++++++++++ 2 files changed, 75 insertions(+), 135 deletions(-) delete mode 100644 plugin/DiscordNotify/DiscordNotify.php create mode 100644 plugin/SlackNotify/SlackNotify.php diff --git a/plugin/DiscordNotify/DiscordNotify.php b/plugin/DiscordNotify/DiscordNotify.php deleted file mode 100644 index fccf94aaaa..0000000000 --- a/plugin/DiscordNotify/DiscordNotify.php +++ /dev/null @@ -1,135 +0,0 @@ -webhook_url = ""; - $obj->avatar_url = ""; - $obj->bot_username = ""; - $obj->footer_image = ""; - return $obj; - } - public function afterNewVideo($videos_id) - { - global $global; - $o = $this->getDataObject(); - $users_id = Video::getOwner($videos_id); - $user = new User($users_id); - $username = $user->getNameIdentification(); - $channelName = $user->getChannelName(); - $video = new Video("","",$videos_id); - $videoName = $video->getTitle(); - $images = Video::getImageFromFilename($video->getFilename()); - $videoThumbs = $images->thumbsJpg; - $videoLink = Video::getPermaLink($videos_id); - $videoDuration = $video->getDuration(); - $videoDescription = $video->getDescription(); - $url = $o->webhook_url; - $avatar_url = $o->avatar_url; - $bot_username = $o->bot_username; - $footer_image = $o->footer_image; - -$hookObject = json_encode([ - "content" => "", - "username" => $bot_username, - "avatar_url" => $avatar_url, - "tts" => false, - "embeds" => [ - [ - "title" => $username . " just uploaded a video", - "type" => "rich", - "description" => "", - "url" => $global['webSiteRootURL'] . $channelName, - "timestamp" => "", - "color" => hexdec( "FF0000" ), - "footer" => [ - "text" => $bot_username, - "icon_url" => $footer_image - ], - - "image" => [ - "url" => $videoThumbs, - ], - - //"thumbnail" => [ - // "url" => $userThumbnail - //], - - "fields" => [ - [ - "name" => "Video Name", - "value" => $videoName, - "inline" => true - ], - [ - "name" => "Video Link", - "value" => $videoLink, - "inline" => true - ], - [ - "name" => "Video Duration", - "value" => $videoDuration, - "inline" => true - ], - [ - "name" => "Video Description", - "value" => "N/A", - "inline" => true - ] - ] - ] - ] - -], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); - -$ch = curl_init(); - -curl_setopt_array( $ch, [ - CURLOPT_URL => $url, - CURLOPT_POST => true, - CURLOPT_POSTFIELDS => $hookObject, - CURLOPT_HTTPHEADER => [ - "Length" => strlen( $hookObject ), - "Content-Type" => "application/json" - ] -]); - -return curl_exec( $ch ); - } -} diff --git a/plugin/SlackNotify/SlackNotify.php b/plugin/SlackNotify/SlackNotify.php new file mode 100644 index 0000000000..a5ac9ec29a --- /dev/null +++ b/plugin/SlackNotify/SlackNotify.php @@ -0,0 +1,75 @@ +webhook_url = ""; + return $obj; + } + public function afterNewVideo($videos_id) + { + global $global; + $o = $this->getDataObject(); + $users_id = Video::getOwner($videos_id); + $user = new User($users_id); + $username = $user->getNameIdentification(); + $channelName = $user->getChannelName(); + $video = new Video("", "", $videos_id); + $videoName = $video->getTitle(); + $images = Video::getImageFromFilename($video->getFilename()); + $videoThumbs = $images->thumbsJpg; + $videoLink = Video::getPermaLink($videos_id); + $videoDuration = $video->getDuration(); + $videoDescription = $video->getDescription(); + $url = $o->webhook_url; + $message = array( + 'payload' => json_encode(array( + 'text' => $username . " just uploaded a video\nVideo Name: " . $videoName . "\nVideo Link: " . $videoLink . "\nVideo Duration: " . $videoDuration + )) + ); + $c = curl_init($url); + curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($c, CURLOPT_POST, true); + curl_setopt($c, CURLOPT_POSTFIELDS, $message); + curl_exec($c); + curl_close($c); + } +} \ No newline at end of file