Commit 5ad80794 by Aan Choesni Herlingga

looping autopost

parent 7f539aef
...@@ -5,10 +5,12 @@ namespace App\Http\Controllers\Webprofile\Backend; ...@@ -5,10 +5,12 @@ namespace App\Http\Controllers\Webprofile\Backend;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Webprofile\Categories; use App\Models\Webprofile\Categories;
use App\Repositories\Webprofile\AutopostRepository;
use App\Repositories\Webprofile\En\PostRepository as EnPostRepository; use App\Repositories\Webprofile\En\PostRepository as EnPostRepository;
use App\Repositories\Webprofile\PostRepository; use App\Repositories\Webprofile\PostRepository;
use App\Repositories\Webprofile\SocialSharingRepository; use App\Repositories\Webprofile\SocialSharingRepository;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Str;
use Statickidz\GoogleTranslate; use Statickidz\GoogleTranslate;
class PostController extends Controller class PostController extends Controller
...@@ -22,11 +24,13 @@ class PostController extends Controller ...@@ -22,11 +24,13 @@ class PostController extends Controller
public function __construct( public function __construct(
PostRepository $repo, PostRepository $repo,
EnPostRepository $repoEn, EnPostRepository $repoEn,
SocialSharingRepository $socialRepo SocialSharingRepository $socialRepo,
AutopostRepository $autoPostRepo
) { ) {
$this->repo = $repo; $this->repo = $repo;
$this->repoEn = $repoEn; $this->repoEn = $repoEn;
$this->socialRepo = $socialRepo; $this->socialRepo = $socialRepo;
$this->autoPostRepo = $autoPostRepo;
} }
/** /**
...@@ -74,7 +78,7 @@ class PostController extends Controller ...@@ -74,7 +78,7 @@ class PostController extends Controller
array_key_exists('post_status', $data) ? $data['post_status'] = 1 : $data['post_status'] = 0; array_key_exists('post_status', $data) ? $data['post_status'] = 1 : $data['post_status'] = 0;
array_key_exists('cover_status', $data) ? $data['cover_status'] = 1 : $data['cover_status'] = 0; array_key_exists('cover_status', $data) ? $data['cover_status'] = 1 : $data['cover_status'] = 0;
$data['slug'] = str_slug($request->input('title')); $data['slug'] = Str::slug($request->input('title'));
$save = $this->repo->store($data); $save = $this->repo->store($data);
...@@ -98,7 +102,7 @@ class PostController extends Controller ...@@ -98,7 +102,7 @@ class PostController extends Controller
public function share($data, $request) public function share($data, $request)
{ {
$setting = webprofilesetting(); $autoPost = $this->autoPostRepo->get();
if ($request->hasFile('thumbnail')) { if ($request->hasFile('thumbnail')) {
$img = $request->file('thumbnail')->getRealPath(); $img = $request->file('thumbnail')->getRealPath();
...@@ -107,28 +111,32 @@ class PostController extends Controller ...@@ -107,28 +111,32 @@ class PostController extends Controller
} }
$title = html_entity_decode($data['title']); $title = html_entity_decode($data['title']);
//Social Share Facebook foreach ($autoPost as $value) {
// Config::set('larasap.facebook', [ //Social Share Facebook
// 'app_id' => $setting['facebook_app_id'], // Config::set('larasap.facebook', [
// 'app_secret' => $setting['facebook_app_secret'], // 'app_id' => $setting['facebook_app_id'],
// 'default_graph_version' => null, // 'app_secret' => $setting['facebook_app_secret'],
// 'page_access_token' => null, // 'default_graph_version' => null,
// ]); // 'page_access_token' => null,
// ]);
// $this->socialRepo->sendLinkToFacebook(url('post/'.$data['slug']), $data['content']);
// $this->socialRepo->sendLinkToFacebook(url('post/'.$data['slug']), $data['content']);
//Social Share Twitter
Config::set('larasap.twitter', [ if ($value->type == 'twitter') {
'consurmer_key' => $setting['twitter_consurmer_key'], //Social Share Twitter
'consurmer_secret' => $setting['twitter_consurmer_secret'], Config::set('larasap.twitter', [
'access_token' => $setting['twitter_access_token'], 'consurmer_key' => $value->key_1,
'access_token_secret' => $setting['twitter_access_token_secret'], 'consurmer_secret' => $value->key_2,
]); 'access_token' => $value->key_3,
'access_token_secret' => $value->key_4,
if ($img == '') { ]);
$this->socialRepo->sendTextTweet($title.' '.url('post/'.$data['slug']));
} else { if ($img == '') {
$this->socialRepo->sendTweetWithMedia($title.' '.url('post/'.$data['slug']), [$img]); $this->socialRepo->sendTextTweet($title.' '.url('post/'.$data['slug']));
} else {
$this->socialRepo->sendTweetWithMedia($title.' '.url('post/'.$data['slug']), [$img]);
}
}
} }
} }
...@@ -198,7 +206,7 @@ class PostController extends Controller ...@@ -198,7 +206,7 @@ class PostController extends Controller
array_key_exists('post_status', $data) ? $data['post_status'] = 1 : $data['post_status'] = 0; array_key_exists('post_status', $data) ? $data['post_status'] = 1 : $data['post_status'] = 0;
array_key_exists('cover_status', $data) ? $data['cover_status'] = 1 : $data['cover_status'] = 0; array_key_exists('cover_status', $data) ? $data['cover_status'] = 1 : $data['cover_status'] = 0;
$data['slug'] = str_slug($request->input('title')); $data['slug'] = Str::slug($request->input('title'));
$post = $this->repo->findId($id, ['rEn']); $post = $this->repo->findId($id, ['rEn']);
$edit = $this->repo->update($data, $post); $edit = $this->repo->update($data, $post);
......
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