Commit 4c0f6f0e by Aan Choesni Herlingga

url shorter, hastags, dan title website

parent 5ad80794
......@@ -2,13 +2,14 @@
namespace App\Http\Controllers\Webprofile\Backend;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Webprofile\Categories;
use App\Repositories\Webprofile\AutopostRepository;
use App\Repositories\Webprofile\En\PostRepository as EnPostRepository;
use App\Repositories\Webprofile\PostRepository;
use App\Repositories\Webprofile\SocialSharingRepository;
use GuzzleHttp\Client;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Str;
use Statickidz\GoogleTranslate;
......@@ -68,8 +69,6 @@ class PostController extends Controller
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
......@@ -100,8 +99,22 @@ class PostController extends Controller
return redirect()->route('posts.index');
}
public function shorterUrl($long_url)
{
$client = new Client();
$URI = 'http://s.unesa.ac.id/create.php';
$params['form_params'] = ['token' => env('TOKEN_URL', 'forge'), 'url_value' => $long_url];
$response = $client->post($URI, $params);
$responseJson = json_decode($response->getBody(), true);
$url = $responseJson['url'];
return $url;
}
public function share($data, $request)
{
$setting = webprofilesetting();
$autoPost = $this->autoPostRepo->get();
if ($request->hasFile('thumbnail')) {
......@@ -110,6 +123,15 @@ class PostController extends Controller
$img = null;
}
$title = html_entity_decode($data['title']);
$url = $this->shorterUrl(url('post/'.$data['slug']));
$keys = $data['keys'];
$olhashtag = explode(', ', str_replace([', ', ','], ', ', $keys));
$hashtag = '#unesa #unesaterkini ';
foreach ($olhashtag as $value) {
$hashtag .= '#'.trim($value).' ';
}
foreach ($autoPost as $value) {
//Social Share Facebook
......@@ -132,9 +154,9 @@ class PostController extends Controller
]);
if ($img == '') {
$this->socialRepo->sendTextTweet($title.' '.url('post/'.$data['slug']));
$this->socialRepo->sendTextTweet($setting['header_admin'].'-'.$title."\n\n".$url."\n\n".$hashtag);
} else {
$this->socialRepo->sendTweetWithMedia($title.' '.url('post/'.$data['slug']), [$img]);
$this->socialRepo->sendTweetWithMedia($setting['header_admin'].'-'.$title."\n\n".$url."\n\n".$hashtag, [$img]);
}
}
}
......@@ -194,7 +216,6 @@ class PostController extends Controller
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
*
* @return \Illuminate\Http\Response
......
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