plugin_twitter: Recreate sidebar timeline cache on saving config.
This commit is contained in:
parent
b551e50db8
commit
588e48843d
2 changed files with 31 additions and 34 deletions
|
@ -24,7 +24,7 @@ require_once dirname(__FILE__) . '/classes/TwitterPluginFileAccess.php';
|
|||
require_once dirname(__FILE__) . '/classes/twitter_entry_defs.include.php';
|
||||
|
||||
// writes a debug log into templates_c
|
||||
@define('PLUGIN_TWITTER_DEBUG', TRUE);
|
||||
@define('PLUGIN_TWITTER_DEBUG', FALSE);
|
||||
|
||||
// Consumer settings for the S9Y webapp
|
||||
@define('PLUGIN_TWITTER_OAUTH_TWITTER_CONSUMERKEY', 'ScXsM6UiDU1nDl8u6tacrw');
|
||||
|
@ -1755,19 +1755,13 @@ a.twitter_update_time {
|
|||
global $serendipity;
|
||||
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
|
||||
|
||||
$this->log("parts: " . print_r($parts,true));
|
||||
|
||||
if (count($parts)<5) return time() + (60 * 60); // params corrupted next try allowed one minute later
|
||||
|
||||
// Do we need to do OAuth?
|
||||
if (count($parts)>6) {
|
||||
$this->log("NEW OUATH FETCH");
|
||||
$idx_twitter = $parts[5];
|
||||
$this->log("idx: $idx_twitter");
|
||||
$idxmd5 = $parts[6];
|
||||
$this->log("idxmd5: $idxmd5");
|
||||
$idxmd5_test = md5(serendipity_event_twitter::pluginSecret() . "_{$idx_twitter}");
|
||||
$this->log("$idxmd5=?=$idxmd5_test");
|
||||
if ($idxmd5_test != $idxmd5) { // Seems to be a hack!
|
||||
return time() + (60 * 60); // params corrupted next try allowed one minute later
|
||||
}
|
||||
|
@ -1797,14 +1791,12 @@ a.twitter_update_time {
|
|||
$error=200; // Default is: All OK
|
||||
|
||||
if (!empty($idx_twitter)) {
|
||||
$this->log("Loading timeline via OAUTH");
|
||||
$search_twitter_uri = 'http://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=' . $username . '&count=' . $number . '&trim_user=true';
|
||||
if (!$show_rt) $search_twitter_uri .= '&include_rts=false';
|
||||
if ($idx_twitter=='1') $idx_twitter=''; // First cfg is saved with empty suffix!
|
||||
$connection = $this->twitteroa_connect($idx_twitter);
|
||||
$connection->decode_json = false;
|
||||
$response = $connection->get($search_twitter_uri);
|
||||
$this->log(print_r(json_decode($response), true));
|
||||
}
|
||||
else {
|
||||
if ($service == 'identi.ca')
|
||||
|
|
|
@ -225,6 +225,12 @@ class serendipity_plugin_twitter extends serendipity_plugin {
|
|||
|
||||
// Remove Cachefile
|
||||
@unlink($cachefile);
|
||||
|
||||
// Recreate cache
|
||||
serendipity_request_start();
|
||||
$title = "#caching#";
|
||||
$this->generate_content($title);
|
||||
serendipity_request_end();
|
||||
}
|
||||
|
||||
function output($out) {
|
||||
|
@ -237,7 +243,9 @@ class serendipity_plugin_twitter extends serendipity_plugin {
|
|||
|
||||
function generate_content(&$title) {
|
||||
global $serendipity;
|
||||
|
||||
|
||||
$hideDisplay = "#caching#" == $title;
|
||||
|
||||
$number = $this->get_config('number');
|
||||
$service = $this->get_config('service', 'twitter.com');
|
||||
$username = $this->get_config('username');
|
||||
|
@ -269,11 +277,6 @@ class serendipity_plugin_twitter extends serendipity_plugin {
|
|||
$timelineurl = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=' . $username . '&count=' . $number . '&callback=' . $JSONcallback;
|
||||
$api = new Twitter(false);
|
||||
}
|
||||
/*
|
||||
else {
|
||||
$api = new Twitter(false); // We only need Twitter object for replacements
|
||||
}
|
||||
*/
|
||||
|
||||
if (!$dateformat || strlen($dateformat) < 1) {
|
||||
$dateformat = '%A, %B %e %Y';
|
||||
|
@ -338,30 +341,34 @@ class serendipity_plugin_twitter extends serendipity_plugin {
|
|||
}
|
||||
$str_output[] = '</ul>';
|
||||
// Display only, if we have something meaningful:
|
||||
if (count($str_output)>2) {
|
||||
if (!$hideDisplay && count($str_output)>2) {
|
||||
$output = implode('', $str_output);
|
||||
$this->output($output);
|
||||
}
|
||||
|
||||
} else {
|
||||
echo '<ul id="twitter_update_list"><li style="display: none"></li></ul>' . "\n";
|
||||
echo '<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>' . "\n";
|
||||
echo '<script type="text/javascript" src="' . $timelineurl . '"></script>';
|
||||
}
|
||||
if (serendipity_db_bool($this->get_config('followme_link', false))) {
|
||||
echo '<p id="twitter_follow_me"><a href="' . $followme_url . '" class="twitter_follow_me">' . PLUGIN_TWITTER_FOLLOWME_LINK_TEXT . '</a></p>' . "\n";
|
||||
}
|
||||
if ($service == 'twitter.com' && serendipity_db_bool($this->get_config('followme_widget', false))) {
|
||||
$extra_style = '';
|
||||
if (serendipity_db_bool($this->get_config('followme_widget_dark', false))) {
|
||||
$extra_style .= ' data-button="grey" data-text-color="#FFFFFF" data-link-color="#00AEFF"';
|
||||
if (!$hideDisplay) {
|
||||
echo '<ul id="twitter_update_list"><li style="display: none"></li></ul>' . "\n";
|
||||
echo '<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>' . "\n";
|
||||
echo '<script type="text/javascript" src="' . $timelineurl . '"></script>';
|
||||
}
|
||||
if (!serendipity_db_bool($this->get_config('followme_widget_counter', true))) {
|
||||
$extra_style .= ' data-show-count="false"';
|
||||
}
|
||||
if (!$hideDisplay) {
|
||||
if (serendipity_db_bool($this->get_config('followme_link', false))) {
|
||||
echo '<p id="twitter_follow_me"><a href="' . $followme_url . '" class="twitter_follow_me">' . PLUGIN_TWITTER_FOLLOWME_LINK_TEXT . '</a></p>' . "\n";
|
||||
}
|
||||
echo '<a href="https://twitter.com/'.$username.'" class="twitter-follow-button"'.$extra_style.'>Follow @'.$username.'</a><script src="//platform.twitter.com/widgets.js" type="text/javascript"></script>';
|
||||
if ($service == 'twitter.com' && serendipity_db_bool($this->get_config('followme_widget', false))) {
|
||||
$extra_style = '';
|
||||
if (serendipity_db_bool($this->get_config('followme_widget_dark', false))) {
|
||||
$extra_style .= ' data-button="grey" data-text-color="#FFFFFF" data-link-color="#00AEFF"';
|
||||
}
|
||||
if (!serendipity_db_bool($this->get_config('followme_widget_counter', true))) {
|
||||
$extra_style .= ' data-show-count="false"';
|
||||
}
|
||||
echo '<a href="https://twitter.com/'.$username.'" class="twitter-follow-button"'.$extra_style.'>Follow @'.$username.'</a><script src="//platform.twitter.com/widgets.js" type="text/javascript"></script>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($showformat == 'PHP') {
|
||||
// If the twitter event plugin is installed, too, save cache file in background.
|
||||
// When twitter is blocking, the blog isn't when using this background caching.
|
||||
|
@ -372,10 +379,8 @@ class serendipity_plugin_twitter extends serendipity_plugin {
|
|||
$png_url = $pluginurl . '/cacheplugintwitter' .$this->cache_img_link_pars();
|
||||
echo '<img src="' . $png_url . '" width="1" height="1" alt="" class="twitter_plugin_cache_png" style="float:right;"/>';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (serendipity_db_bool($this->get_config('backup')) && $service == 'twitter.com') {
|
||||
$last_backup = $this->get_config('last_backup', 0);
|
||||
if (date('Ymd') == date('Ymd', $last_backup)) {
|
||||
|
|
Loading…
Reference in a new issue