web/tweet_ajax.php
changeset 1581 2d713fdd532f
parent 1577 96a6eada7982
equal deleted inserted replaced
1580:2b0cb7c8f34d 1581:2d713fdd532f
     9 function sendTwitter()
     9 function sendTwitter()
    10 {
    10 {
    11     $token = unserialize($_SESSION['SOCIAL_ACCESS_TOKEN']);
    11     $token = unserialize($_SESSION['SOCIAL_ACCESS_TOKEN']);
    12     $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $token['oauth_token'], $token['oauth_token_secret']);
    12     $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $token['oauth_token'], $token['oauth_token_secret']);
    13 
    13 
    14     $data = $connection->post("statuses/update", ["status" => $_POST['status']]);
    14     $status = addHashtagTwitter($_POST['status'], ltrim($_POST['hashtag'], '#'));
       
    15 
       
    16     $data = $connection->post("statuses/update", ["status" => $status]);
    15 
    17 
    16     // $token = unserialize($_SESSION['SOCIAL_ACCESS_TOKEN']);
    18     // $token = unserialize($_SESSION['SOCIAL_ACCESS_TOKEN']);
    17     // $client = $token->getHttpClient($configuration);
    19     // $client = $token->getHttpClient($configuration);
    18     // $client->setUri('https://api.twitter.com/1.1/statuses/update.json');
    20     // $client->setUri('https://api.twitter.com/1.1/statuses/update.json');
    19     // $client->setMethod(Zend_Http_Client::POST);
    21     // $client->setMethod(Zend_Http_Client::POST);
    34     /**
    36     /**
    35      * Tweet sent (hopefully), redirect back home...
    37      * Tweet sent (hopefully), redirect back home...
    36      */
    38      */
    37     //header('Location: ' . URL_ROOT . '?result=' . $result);
    39     //header('Location: ' . URL_ROOT . '?result=' . $result);
    38     echo ($result);
    40     echo ($result);
       
    41 }
       
    42 
       
    43 function addHashtagTwitter($status, $hashtag) : string {
       
    44     $res = $status;
       
    45     $to_add = "";
       
    46 
       
    47     if(!str_contains($status, "#$hashtag")) {
       
    48         $to_add .= " #$hashtag";
       
    49     }
       
    50 
       
    51     return mb_substr($status,0, 280-mb_strlen($to_add)).$to_add;
    39 }
    52 }
    40 
    53 
    41 function addHashtagMastodon($status, $hashtag, $group) : string {
    54 function addHashtagMastodon($status, $hashtag, $group) : string {
    42     $res = $status;
    55     $res = $status;
    43     $to_add = "";
    56     $to_add = "";