Commit 02efc466 by Aan Choesni Herlingga

auto post in twitter

parent ba6c8dc7
......@@ -7,6 +7,8 @@ use App\Http\Controllers\Controller;
use App\Models\Webprofile\Categories;
use App\Repositories\Webprofile\En\PostRepository as EnPostRepository;
use App\Repositories\Webprofile\PostRepository;
use App\Repositories\Webprofile\SocialSharingRepository;
use Illuminate\Support\Facades\Config;
use Statickidz\GoogleTranslate;
class PostController extends Controller
......@@ -19,10 +21,12 @@ class PostController extends Controller
public function __construct(
PostRepository $repo,
EnPostRepository $repoEn
EnPostRepository $repoEn,
SocialSharingRepository $socialRepo
) {
$this->repo = $repo;
$this->repoEn = $repoEn;
$this->socialRepo = $socialRepo;
}
/**
......@@ -87,9 +91,47 @@ class PostController extends Controller
$this->createEn($data, $save);
}
$this->share($data, $request);
return redirect()->route('posts.index');
}
public function share($data, $request)
{
$setting = webprofilesetting();
if ($request->hasFile('thumbnail')) {
$img = $request->file('thumbnail')->getRealPath();
} else {
$img = null;
}
$title = html_entity_decode($data['title']);
//Social Share Facebook
// Config::set('larasap.facebook', [
// 'app_id' => $setting['facebook_app_id'],
// 'app_secret' => $setting['facebook_app_secret'],
// 'default_graph_version' => null,
// 'page_access_token' => null,
// ]);
// $this->socialRepo->sendLinkToFacebook(url('post/'.$data['slug']), $data['content']);
//Social Share Twitter
Config::set('larasap.twitter', [
'consurmer_key' => $setting['twitter_consurmer_key'],
'consurmer_secret' => $setting['twitter_consurmer_secret'],
'access_token' => $setting['twitter_access_token'],
'access_token_secret' => $setting['twitter_access_token_secret'],
]);
if ($img == '') {
$this->socialRepo->sendTextTweet($title.' '.url('post/'.$data['slug']));
} else {
$this->socialRepo->sendTweetWithMedia($title.' '.url('post/'.$data['slug']), [$img]);
}
}
private function createEn($data, $post)
{
$trans = new GoogleTranslate();
......
<?php
namespace App\Repositories\Webprofile;
use Toolkito\Larasap\SendTo;
class SocialSharingRepository
{
/**
* Function For Telegram.
*/
public function sendTextMessageToTelegram()
{
SendTo::Telegram('Hello, This is testing Laravel social auto posting');
dd('Youe message send successfully!!');
}
public function sendPhotoToTelegram()
{
SendTo::Telegram(
'Hello, Im testing Laravel social auto posting', // Photo caption (Optional)
[
'type' => 'photo', // Message type (Required)
'file' => 'https://i.imgur.com/j6bzKQc.jpg', // Image url (Required)
],
'' // Inline keyboard (Optional)
);
dd('Youe message send successfully!!');
}
public function sendAudioToTelegram()
{
SendTo::Telegram(
'Hello, Im testing Laravel social auto posting', // Audio caption (Optional)
[
'type' => 'audio', // Message type (Required)
'file' => 'http://example.com/let-me-be-your-lover.mp3', // Audio url (Required)
'duration' => 208, // Duration of the audio in seconds (Optional)
'performer' => 'Enrique Iglesias', // Performer (Optional)
'title' => 'Let Me Be Your Lover', // Track name (Optional)
],
'' // Inline keyboard (Optional)
);
dd('Youe message send successfully!!');
}
public function sendDocumentToTelegram()
{
SendTo::Telegram(
'Hello, Im testing Laravel social auto posting', // Document caption
[
'type' => 'document', // Message type (Required)
'file' => 'http://example.com/larasap.pdf', // Document url (Required)
],
'' // Inline keyboard (Optional)
);
dd('Youe message send successfully!!');
}
public function sendVideoToTelegram()
{
SendTo::Telegram(
'Hello, Im testing Laravel social auto posting', // Video caption (Optional)
[
'type' => 'video', // Message type (Required)
'file' => 'http://example.com/let-me-be-your-lover.mp4', // Audio url (Required)
'duration' => 273, // Duration of sent video in seconds (Optional)
'width' => 1920, // Video width (Optional)
'height' => 1080, // Video height (Optional)
],
'' // Inline keyboard (Optional)
);
dd('Youe message send successfully!!');
}
public function sendVoiceToTelegram()
{
SendTo::Telegram(
'Hello, Im testing Laravel social auto posting', // Voice message caption (Optional)
[
'type' => 'voice', // Message type (Required)
'file' => 'https://upload.wikimedia.org/wikipedia/en/9/9f/Sample_of_%22Another_Day_in_Paradise%22.ogg', // Audio url (Required)
'duration' => 28, // Duration of the voice message in seconds (Optional)
],
'' // Inline keyboard (Optional)
);
dd('Youe message send successfully!!');
}
public function sendMediaGroupToTelegram()
{
SendTo::Telegram(
null,
[
'type' => 'media_group', // Message type (Required)
'files' => // Array describing photos and videos to be sent, must include 2–10 items
[
[
'type' => 'photo', // Media type (Required)
'media' => 'https://i.imgur.com/j6bzKQc.jpg', // Media url (Required)
'caption' => 'Laravel sccial auto posting', // Media caption (Optional)
],
[
'type' => 'video', // Media type (Required)
'media' => 'http://example.com/let-me-be-your-lover.mp4', // Media url (Required)
'caption' => 'Let me be your lover', // Media caption (Optional)
],
],
]
);
dd('Youe message send successfully!!');
}
public function sendPointOnTheMapToTelegram()
{
SendTo::Telegram(
null,
[
'type' => 'location', // Message type (Required)
'latitude' => 36.1664345, // Latitude of the location (Required)
'longitude' => 58.8209904, // Longitude of the location (Required)
'live_period' => 86400, // Period in seconds for which the location will be updated (Optional)
// '' // Inline keyboard (Optional)
]
);
dd('Youe message send successfully!!');
}
public function sendInformationAboutVenueToTelegram()
{
SendTo::Telegram(
null,
[
'type' => 'venue', // Message type (Required)
'latitude' => 36.166048, // Latitude of the location (Required)
'longitude' => 58.822121, // Longitude of the location (Required)
'title' => 'Khayyam', // Name of the venue (Required)
'address' => 'Neyshabur, Razavi Khorasan Province, Iran', // Address of the venue (Required)
'foursquare_id' => '', // Foursquare identifier of the venue (Optional)
// '', // Inline keyboard (Optional)
]
);
dd('Youe message send successfully!!');
}
public function sendMessageWithInlineButtonToTelegram()
{
SendTo::Telegram(
'Laravel social auto posting',
'',
[
[
[
'text' => 'Github',
'url' => 'https://github.com/toolkito/laravel-social-auto-posting',
],
],
[
[
'text' => 'Download',
'url' => 'https://github.com/toolkito/laravel-social-auto-posting/archive/master.zip',
],
],
]
);
// OR
SendTo::Telegram(
'Laravel social auto posting',
'',
[
[
[
'text' => 'Github',
'url' => 'https://github.com/toolkito/laravel-social-auto-posting',
],
[
'text' => 'Download',
'url' => 'https://github.com/toolkito/laravel-social-auto-posting/archive/master.zip',
],
],
]
);
dd('Youe message send successfully!!');
}
/**
* Function For Twitter.
*/
public function sendTextTweet($twit)
{
SendTo::Twitter($twit);
// dd('Youe message send successfully!!');
}
public function sendTweetWithMedia($twit, $img)
{
SendTo::Twitter(
$twit, $img
);
// dd('Youe message send successfully!!');
}
/**
* Function For Facebook.
*/
public function sendLinkToFacebook($link, $message)
{
SendTo::Facebook(
'link',
[
'link' => $link,
'message' => $message,
]
);
dd('Youe message send successfully!!');
}
public function sendPhotoToFacebook($image_url, $message)
{
SendTo::Facebook(
'photo',
[
'photo' => $image_url,
'message' => $message,
]
);
dd('Youe message send successfully!!');
}
public function sendVideoToFacebook($video_url, $title, $description)
{
SendTo::Facebook(
'video',
[
'video' => $video_url,
'title' => $title,
'description' => $description,
]
);
dd('Youe message send successfully!!');
}
}
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "9c68facdf749909bd9a37e534700e060",
"content-hash": "58b660faa54f724bff327d673b4851f0",
"packages": [
{
"name": "anhskohbo/no-captcha",
......@@ -509,6 +509,64 @@
"time": "2019-03-17T18:48:37+00:00"
},
{
"name": "facebook/graph-sdk",
"version": "5.7.0",
"source": {
"type": "git",
"url": "https://github.com/facebook/php-graph-sdk.git",
"reference": "2d8250638b33d73e7a87add65f47fabf91f8ad9b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/facebook/php-graph-sdk/zipball/2d8250638b33d73e7a87add65f47fabf91f8ad9b",
"reference": "2d8250638b33d73e7a87add65f47fabf91f8ad9b",
"shasum": ""
},
"require": {
"php": "^5.4|^7.0"
},
"require-dev": {
"guzzlehttp/guzzle": "~5.0",
"mockery/mockery": "~0.8",
"phpunit/phpunit": "~4.0"
},
"suggest": {
"guzzlehttp/guzzle": "Allows for implementation of the Guzzle HTTP client",
"paragonie/random_compat": "Provides a better CSPRNG option in PHP 5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "5.x-dev"
}
},
"autoload": {
"psr-4": {
"Facebook\\": "src/Facebook/"
},
"files": [
"src/Facebook/polyfills.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Facebook Platform"
],
"authors": [
{
"name": "Facebook",
"homepage": "https://github.com/facebook/php-graph-sdk/contributors"
}
],
"description": "Facebook SDK for PHP",
"homepage": "https://github.com/facebook/php-graph-sdk",
"keywords": [
"facebook",
"sdk"
],
"time": "2018-12-11T22:56:31+00:00"
},
{
"name": "fideloper/proxy",
"version": "4.2.1",
"source": {
......@@ -860,6 +918,7 @@
"email": "jakub.onderka@gmail.com"
}
],
"abandoned": "php-parallel-lint/php-console-color",
"time": "2018-09-29T17:23:10+00:00"
},
{
......@@ -906,6 +965,7 @@
}
],
"description": "Highlight PHP code in terminal",
"abandoned": "php-parallel-lint/php-console-highlighter",
"time": "2018-09-29T18:48:56+00:00"
},
{
......@@ -4172,6 +4232,62 @@
"time": "2019-10-24T08:53:34+00:00"
},
{
"name": "toolkito/larasap",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/alihesari/laravel-social-auto-posting.git",
"reference": "10eff7059fb2b248b4219fa229d1afe79f3aba7a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/alihesari/laravel-social-auto-posting/zipball/10eff7059fb2b248b4219fa229d1afe79f3aba7a",
"reference": "10eff7059fb2b248b4219fa229d1afe79f3aba7a",
"shasum": ""
},
"require": {
"facebook/graph-sdk": "^5.6.1",
"php": "~7.0"
},
"require-dev": {
"phpunit/phpunit": "~4.8"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Toolkito\\Larasap\\LarasapServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Toolkito\\Larasap\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Ali Hesari",
"email": "alihesari.com@gmail.com",
"homepage": "https://alihesari.com",
"role": "Developer"
}
],
"description": "Laravel social auto posting (Larasap) lets you automatically post all your content to social networks such as Telegram Channel and Twitter.",
"keywords": [
"facebook",
"laravel",
"social network",
"telegram",
"twitter"
],
"time": "2020-06-21T07:09:13+00:00"
},
{
"name": "unisharp/laravel-filemanager",
"version": "v1.9.2",
"source": {
......
<?php
return [
'telegram' => [
'api_token' => '',
'bot_username' => '',
'channel_username' => '', // Channel username to send message
'channel_signature' => '', // This will be assigned in the footer of message
'proxy' => false, // True => Proxy is On | False => Proxy Off
],
'twitter' => [
'consurmer_key' => env('TWITTER_KEY', 'forge'),
'consurmer_secret' => env('TWITTER_SECRET_KEY', 'forge'),
'access_token' => env('TWITTER_TOKEN', 'forge'),
'access_token_secret' => env('TWITTER_TOKEN_SECRET', 'forge'),
],
'facebook' => [
'app_id' => env('FACEBOOK_ID', 'forge'),
'app_secret' => env('FACEBOOK_SECRET', 'forge'),
'default_graph_version' => env('FACEBOOK_GRAPH_VERSION', 'forge'),
'page_access_token' => env('FACEBOOK_ACCESS_TOKEN', 'forge'),
],
// Set Proxy for Servers that can not Access Social Networks due to Sanctions or ...
'proxy' => [
'type' => '', // 7 for Socks5
'hostname' => '', // localhost
'port' => '', // 9050
'username' => '', // Optional
'password' => '', // Optional
],
];
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment