Post featured news post links to Twitter.
This commit is contained in:
parent
81b0abfd91
commit
ff26ba3d0c
3 changed files with 22 additions and 6 deletions
|
@ -50,3 +50,5 @@ secret_key = change_this_or_i_will_beat_you_up
|
||||||
[Twitter]
|
[Twitter]
|
||||||
api_key = <consumer key>
|
api_key = <consumer key>
|
||||||
api_secret = <consumer secret key>
|
api_secret = <consumer secret key>
|
||||||
|
token = <token from misuzu.php twitter-auth>
|
||||||
|
token_secret = <token secret from misuz.php twitter-auth>
|
||||||
|
|
|
@ -86,12 +86,14 @@ switch ($_GET['v'] ?? null) {
|
||||||
if (!empty($_POST['post']) && csrf_verify('news_post', $_POST['csrf'] ?? '')) {
|
if (!empty($_POST['post']) && csrf_verify('news_post', $_POST['csrf'] ?? '')) {
|
||||||
$originalPostId = (int)($_POST['post']['id'] ?? null);
|
$originalPostId = (int)($_POST['post']['id'] ?? null);
|
||||||
$currentUserId = user_session_current('user_id');
|
$currentUserId = user_session_current('user_id');
|
||||||
|
$title = $_POST['post']['title'] ?? null;
|
||||||
|
$isFeatured = !empty($_POST['post']['featured']);
|
||||||
$postId = news_post_create(
|
$postId = news_post_create(
|
||||||
$_POST['post']['title'] ?? null,
|
$title,
|
||||||
$_POST['post']['text'] ?? null,
|
$_POST['post']['text'] ?? null,
|
||||||
(int)($_POST['post']['category'] ?? null),
|
(int)($_POST['post']['category'] ?? null),
|
||||||
user_session_current('user_id'),
|
user_session_current('user_id'),
|
||||||
!empty($_POST['post']['featured']),
|
$isFeatured,
|
||||||
null,
|
null,
|
||||||
$originalPostId
|
$originalPostId
|
||||||
);
|
);
|
||||||
|
@ -102,6 +104,20 @@ switch ($_GET['v'] ?? null) {
|
||||||
$currentUserId,
|
$currentUserId,
|
||||||
[$postId]
|
[$postId]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!$originalPostId && $isFeatured) {
|
||||||
|
$twitterApiKey = config_get('Twitter', 'api_key');
|
||||||
|
$twitterApiSecret = config_get('Twitter', 'api_secret');
|
||||||
|
$twitterToken = config_get('Twitter', 'token');
|
||||||
|
$twitterTokenSecret = config_get('Twitter', 'token_secret');
|
||||||
|
|
||||||
|
if (!empty($twitterApiKey) && !empty($twitterApiSecret)
|
||||||
|
&& !empty($twitterToken) && !empty($twitterTokenSecret)) {
|
||||||
|
twitter_init($twitterApiKey, $twitterApiSecret, $twitterToken, $twitterTokenSecret);
|
||||||
|
$url = url('news-post', ['post' => $postId]);
|
||||||
|
twitter_tweet_post("News :: {$title}\nhttps://{$_SERVER['HTTP_HOST']}{$url}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($postId > 0) {
|
if ($postId > 0) {
|
||||||
|
|
|
@ -55,9 +55,7 @@ function twitter_auth_complete(string $pin): array
|
||||||
|
|
||||||
function twitter_tweet_post(string $text): void
|
function twitter_tweet_post(string $text): void
|
||||||
{
|
{
|
||||||
$params = [
|
Codebird::getInstance()->statuses_update([
|
||||||
'status' => $text,
|
'status' => $text,
|
||||||
];
|
]);
|
||||||
|
|
||||||
Codebird::getInstance()->statuses_update($params);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue