News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Auto Tweet Embed

Started by vbgamer45, January 11, 2015, 03:21:09 PM

Previous topic - Next topic

vbgamer45

Glad to help. Probably was a cache issue. Had to wait for it to timeout.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

laboo9

I installed the auto tweet embed a couple days ago.  Everything was working until this morning when the tweets stopped embedding as they look on twitter.  Now they have the text of the tweet along with hashtags, links to video, and link to pics with the actual link to the actual tweet underneath. 

I'm using 2.0.17.  I have tried uninstalling and reinstalling without any issues but the tweets still don't embed correctly.  Any ideas?

vbgamer45

Check your forums error log.
And your tweet-cache.php file permissions.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

laboo9

the only error I'm getting is File:....../forums/Themes/default/languages/OharaYTEmbed.english.php (main sub template - eval?)

tweet-cache.php file permissions is 0666

vbgamer45

Do you have a link to the post?
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

laboo9

It's a private board.

hxxp:www.hard2bhumble.net/forums/index.php?topic=13791.msg227105#msg227105 [nonactive]

vbgamer45

Ah, that will be hard for me to check. Basically I would look in the console log to see if there are any javascript errors and also checking the response from tweet-cache in the network log.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

laboo9

I'm pretty new to this stuff but is this what you are looking for?

<?php
/*
Rough take on Twitter oEmbed for VeloRooms
by L'arri : [email protected]
27 October 2014

Packaged and modified by hxxp:smfhacks.com [nonactive] -vbgamer45
*/

// I used SMF items where possible for database interactions and required includes.
global $ssi_guest_access;
$ssi_guest_access = 1;
require(dirname(__FILE__) . '/SSI.php');

global $smcFunc;

$_GET = filter_input_array(INPUT_GET, FILTER_SANITIZE_NUMBER_INT);
$qv  = $_GET['id'];
if (!empty($qv))
{
   check_cache($qv);
}
else
{
   echo '{"html":"<p style=\"color: #666; border: 1px dotted #666; padding: 5px; width: 490px;\">' . $txt['autotwitter_blankid'] . '</p>"}';
}

function check_cache($tweet)
{
   global  $smcFunc;
   
   if (!is_numeric($tweet))
      return;
   
   $request = $smcFunc['db_query']('','SELECT
      html from
   {db_prefix}tweet_cache
   where tweetid = {raw:tweet}',
   array(
      'tweet' => $tweet
      )
   );
   
   if ($smcFunc['db_num_rows']($request) == 0)
   {
      add_cache($tweet);
   }
   else
   {
      while ($row = $smcFunc['db_fetch_row']($request))
         echo '{"html" : "' . $row[0] .'"}';
   }      
   $smcFunc['db_free_result']($request);
   
}

function add_cache($tweet)
{
   global $smcFunc, $txt, $sourcedir;

   $twitterapi_url = "[url="https://api.twitter.com/1.1/statuses/oembed.json?id=";"]https://api.twitter.com/1.1/statuses/oembed.json?id=";[/url]
   $twitterapi_url = $twitterapi_url . $tweet;
   
   if (function_exists('curl_init'))
    {
        $curl = curl_init($twitterapi_url);
       curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, FALSE);
       $response = curl_exec($curl);
       curl_close($curl);
    }
    else
    {
        require_once($sourcedir . '/Subs-Package.php');
        $response = fetch_web_data($twitterapi_url);
    }
   
   
   $json_content = json_decode($response, true);
   $json_content = preg_replace( "/\r|\n/", "", $json_content );
   
   $html = $json_content['html'];
   if (!empty($html))
   {

      $smcFunc['db_query']('', '
         SET NAMES {string:db_character_set}',
         array(
            'db_character_set' => 'utf8mb4',
         )
      );

      $request = $smcFunc['db_insert']('',
            '{db_prefix}tweet_cache',
            array(
               'tweetid' => 'raw', 'html' => 'text'
            ),
            array(
               $tweet, addslashes($html)
          ),
            array('tweetid','html')
         );
      echo '{"html" : "' . addslashes($html) .'"}';
   }
   else
   {
      echo '{"html":"<p style=\"color: #666; border: 1px dotted #666; padding: 5px; width: 490px;\">' . $txt['autotwitter_tweeterror'] . '</p>"}';
   }
   
}

?>

vbgamer45

No looking for javascript errors...
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

pocttopus

Disable the Enhanced Tracking protection to your site from your browser.


kilk

I havent had any issues with this mod, just solid af, thank you again vbgamer
Elddem The MMORPG - https://www.elddem.com | Denarius (D) Cryptocurrrency - https://www.denarius.io | BlockForums - Cryptocurrency Community Forums - https://www.blockforums.org

natcip

For whatever reason some tweets won't embed at all, like in this post, even though the link structure is identical to other posts where it did embed. :-\

vbgamer45

Looks like i get a database error are you using latest version?
http://www.brandysource.net/tweet-cache.php?id=1289643269563904002
If so post the db error from your logs
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

natcip

Yes, I've just updated it in May.
And there are no error log entries.

vbgamer45

What happens when you click that link above as admin?
I want to see the message returned.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

natcip

Incorrect string value: '\xF0\x9F\x92\x80 <...' for column `brandyso_sql1`.`brandy4f_sql1_smf_tweet_cache`.`html` at row 1
File: /home/www/brandyso/tweet-cache.php
Line: 93

Arantor

Can't store emoji... if the mod pushed it through $smcFunc['htmlspecialchars'] this would be fine.

vbgamer45

Would that break the html response? Thinking I could do that but then do  un_htmlspecialchars to get right content?


$html = $json_content['html'];
if (!empty($html))
{

$smcFunc['db_query']('', '
SET NAMES {string:db_character_set}',
array(
'db_character_set' => 'utf8mb4',
)
);

$request = $smcFunc['db_insert']('',
'{db_prefix}tweet_cache',
array(
'tweetid' => 'raw', 'html' => 'text'
),
array(
$tweet, addslashes($html)
),
array('tweetid','html')
);
echo '{"html" : "' . addslashes($html) .'"}';
}
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Arantor

You only need to htmlspecialchars it before sending to the database (because even though you have a SET NAMES call, none of that matters if the underlying table isn't also utf8mb4 - which by evidence of the above, it is not) and I *think* you can safely un_htmlspecialchars on the way back.

Alternatively, borrow the routine from $smcFunc that fixes UTF-8 (it entity encodes all emoji as numeric-form entities) and just html_entity_decode on the way back?

Though entities are valid HTML so...

vbgamer45

I had it setup on the field level on the install

ALTER TABLE {db_prefix}tweet_cache CHANGE html html text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci



Quote from: natcip on August 03, 2020, 06:21:07 AM
Incorrect string value: '\xF0\x9F\x92\x80 <...' for column `brandyso_sql1`.`brandy4f_sql1_smf_tweet_cache`.`html` at row 1
File: /home/www/brandyso/tweet-cache.php
Line: 93

Try the attached file and see if it helps
Copy to root of your SMF install and make sure right permissions are set.

Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Advertisement: