Пример #1
0
function fetchTweets($aArgs, $bEcho = true)
{
    $_sOutput = '';
    if (!class_exists('FetchTweets_Fetch')) {
        $_sOutput = __('The class has not been loaded yet. Use this function after the <code>plugins_loaded</code> hook.', 'fetch-tweets');
        if ($bEcho) {
            echo $_sOutput;
        } else {
            return $_sOutput;
        }
    }
    $_oFetch = new FetchTweets_Fetch();
    if (isset($aArgs['get']) && $aArgs['get']) {
        $aArgs = $_GET + $aArgs;
    }
    if (isset($aArgs['id']) || isset($aArgs['ids']) || isset($aArgs['q']) || isset($aArgs['screen_name'])) {
        $_sOutput = $_oFetch->getTweetsOutput($aArgs);
    } else {
        if (isset($aArgs['tag']) || isset($aArgs['tags'])) {
            $_sOutput = $_oFetch->getTweetsOutputByTag($aArgs);
        } else {
            $_sOutput = $_oFetch->getTweetsOutput($aArgs);
        }
    }
    if ($bEcho) {
        echo $_sOutput;
    } else {
        return $_sOutput;
    }
}
Пример #2
0
function fetchTweets($arrArgs)
{
    $oFetch = new FetchTweets_Fetch();
    if (isset($arrArgs['id']) || isset($arrArgs['ids'])) {
        $oFetch->drawTweets($arrArgs);
    } else {
        if (isset($arrArgs['tag']) || isset($arrArgs['tags'])) {
            $oFetch->drawTweetsByTag($arrArgs);
        }
    }
}
 /**
  * Returns an array of lists received from the previous page; otherwise, fetches lists from the set screen name.
  * 
  */
 protected function getLists($strScreenName = '')
 {
     // If the cache is set from the previous page, use that.
     $strListTransient = isset($_GET['list_cache']) ? $_GET['list_cache'] : '';
     if (!empty($strListTransient)) {
         $arrLists = (array) get_transient($strListTransient);
         delete_transient($strListTransient);
         return $arrLists;
     }
     if (empty($strScreenName)) {
         return array();
     }
     // Fetch lists from the given screen name.
     $oFetch = new FetchTweets_Fetch();
     $arrLists = $oFetch->getListNamesFromScreenName($strScreenName);
     return $arrLists;
 }
 /**
  * Re-saves the cache after adding oEmbed elements.
  * 
  * @since			1.3.0
  */
 public function addOEmbedElements($strTransientKey)
 {
     $oFetch = new FetchTweets_Fetch();
     // structure: array( 'mod' => time(), 'data' => $this->oBase64->encode( $vData ) ),
     $arrTransient = $oFetch->getTransient($strTransientKey);
     // If the mandatory keys are not set, it's broken.
     if (!isset($arrTransient['mod'], $arrTransient['data'])) {
         delete_transient($strTransientKey);
         return;
     }
     $arrTweets = (array) $this->oBase64->decode($arrTransient['data']);
     $oFetch->addEmbeddableMediaElements($arrTweets);
     // the array is passed as reference.
     // Re-save the cache.
     $oFetch->setTransient($strTransientKey, $arrTweets, $arrTransient['mod']);
     // the method handles the encoding.
 }
Пример #5
0
 /**
  * Re-saves the cache after adding oEmbed elements.
  * 
  * @since            1.3.0
  */
 public function _replyToAddOEmbedElements($sRequestURI)
 {
     $strTransientKey = FetchTweets_Commons::TransientPrefix . "_" . md5($sRequestURI);
     // Check if the transient is locked
     $strLockTransient = FetchTweets_Commons::TransientPrefix . '_' . md5("LockOEm_" . trim($strTransientKey));
     // up to 40 characters, the prefix can be up to 8 characters
     if (false !== FetchTweets_WPUtilities::getTransient($strLockTransient)) {
         return;
         // it means the cache is being modified.
     }
     // Set a lock flag transient that indicates the transient is being renewed.
     FetchTweets_WPUtilities::setTransient($strLockTransient, true, FetchTweets_Utilities::getAllowedMaxExecutionTime());
     // Perform oEmbed caching - no API request will be performed
     $oFetch = new FetchTweets_Fetch();
     // structure: array( 'mod' => time(), 'data' => $this->oBase64->encode( $vData ) ),
     $arrTransient = $oFetch->getTransient($strTransientKey);
     // If the mandatory keys are not set, it's broken.
     if (!isset($arrTransient['mod'], $arrTransient['data'])) {
         FetchTweets_WPUtilities::deleteTransient($strTransientKey);
         return;
     }
     $arrTweets = (array) $this->oBase64->decode($arrTransient['data']);
     $oFetch->addEmbeddableMediaElements($arrTweets);
     // the array is passed as reference.
     // Re-save the cache.
     // FetchTweets_Debug::logArray( 'saving oembed transient' );
     $oFetch->setTransient($sRequestURI, $arrTweets, $arrTransient['mod'], true);
     // the method handles the encoding.
     // Delete the lock transient
     FetchTweets_WPUtilities::deleteTransient($strLockTransient);
 }
 /**
  * Validation Methods
  * 
  * @since   unknown
  * @since   2.3.8       Allowed 0 for the `item_count` argument.
  */
 public function validation_FetchTweets_MetaBox_List($aInput)
 {
     // validation_ + extended class name
     $aInput['item_count'] = $this->oUtil->fixNumber($aInput['item_count'], 20, 0, 200);
     $_oOption =& $GLOBALS['oFetchTweets_Option'];
     $_aCredentials = $_oOption->getCredentialsByID($aInput['account_id']);
     $_oFetch = new FetchTweets_Fetch($_aCredentials['consumer_key'], $_aCredentials['consumer_secret'], $_aCredentials['access_token'], $_aCredentials['access_secret']);
     $_aLists = $_oFetch->getListsByScreenName($aInput['screen_name'], $aInput['account_id']);
     foreach ($_aLists as $_aList) {
         if ($_aList['id'] == $aInput['list_id']) {
             $aInput['mode'] = $_aList['mode'];
         }
     }
     return $aInput;
 }
 /**
  * Validates submitted form data of the page. 
  * @remark validation_{page slug}
  * 
  * @since       unknown
  * @since       2.4.5       Changed the name from 'validation_fetch_tweets_add_rule_by_list'.
  */
 public function validatePageFormData($aInput, $aOldInput, $oFactory, $aSubmitInformation)
 {
     // Check if the input has been properly sent.
     if (!isset($aInput['add_rule_by_list']['list_owner_screen_name'], $aInput['add_rule_by_list']['list_owner_accounts'])) {
         $oFactory->setSettingNotice(__('Something went wrong. Your input could not be received. Try again and if this happens again, contact the developer.', 'fetch-tweets'));
         return $aOldInput;
     }
     $_aCredentials = $this->_getCredentiaslByAccountID($aInput['add_rule_by_list']['list_owner_accounts']);
     // Variables
     $_aErrors = array();
     // error array
     $_iAccountID = $aInput['add_rule_by_list']['list_owner_accounts'] == -1 ? 0 : $aInput['add_rule_by_list']['list_owner_accounts'];
     $_sOwnerScreenName = $aInput['add_rule_by_list']['list_owner_accounts'] == '-1' ? $aInput['add_rule_by_list']['list_owner_screen_name'] : $_aCredentials['screen_name'];
     // The list owner screen name must be provided.
     if (empty($_sOwnerScreenName)) {
         $_aErrors['add_rule_by_list']['list_owner_screen_name'] = __('The screen name of the list owner must be specified: ') . $_sOwnerScreenName;
         $oFactory->setFieldErrors($_aErrors);
         $oFactory->setSettingNotice(__('There was an error in your input.', 'fetch-tweets'));
         return $aOldInput;
     }
     // Fetch the lists by the screen name.
     $_oFetch = new FetchTweets_Fetch($_aCredentials['consumer_key'], $_aCredentials['consumer_secret'], $_aCredentials['access_token'], $_aCredentials['access_secret']);
     $_aLists = $_oFetch->getListNamesFromScreenName($_sOwnerScreenName, $_iAccountID);
     if (empty($_aLists)) {
         $oFactory->setSettingNotice(__('No list found.', 'fetch-tweets'));
         return $aOldInput;
     }
     // Set the transient of the fetched IDs. This will be used right next page load.
     $_sListCacheID = uniqid();
     FetchTweets_WPUtilities::setTransient($_sListCacheID, $_aLists, 60);
     exit(wp_redirect(add_query_arg(array('post_type' => FetchTweets_Commons::PostTypeSlug, 'tweet_type' => 'list', 'list_cache' => $_sListCacheID, 'screen_name' => $_sOwnerScreenName, 'account_id' => $_iAccountID), admin_url('post-new.php'))));
 }
 public function validation_fetch_tweets_add_rule_by_list($arrInput, $arrOriginal)
 {
     // Check if the input has been properly sent.
     if (!isset($arrInput['fetch_tweets_add_rule_by_list']['add_rule_by_list']['list_owner_screen_name'])) {
         $this->setSettingNotice(__('Something went wrong. Your input could not be received. Try again and if this happens again, contact the developer.', 'fetch-tweets'));
         return $arrOriginal;
     }
     // Variables
     $fVerified = true;
     // flag
     $arrErrors = array();
     // error array
     $strOwnerScreenName = $arrInput['fetch_tweets_add_rule_by_list']['add_rule_by_list']['list_owner_screen_name'];
     // The list owner screen name must be provided.
     if (empty($strOwnerScreenName)) {
         $arrErrors['add_rule_by_list']['list_owner_screen_name'] = __('The screen name of the list owner must be specified: ') . $strOwnerScreenName;
         $this->setFieldErrors($arrErrors);
         $this->setSettingNotice(__('There was an error in your input.', 'fetch-tweets'));
         return $arrOriginal;
     }
     // Fetch the lists by the screen name.
     $oFetch = new FetchTweets_Fetch();
     $arrLists = $oFetch->getListNamesFromScreenName($strOwnerScreenName);
     if (empty($arrLists)) {
         $this->setSettingNotice(__('No list found.', 'fetch-tweets'));
         return $arrOriginal;
     }
     // Set the transient of the fetched IDs. This will be used right next page load.
     $strListCacheID = uniqid();
     set_transient($strListCacheID, $arrLists, 60);
     $this->oUtil->goRedirect(admin_url("post-new.php?post_type=fetch_tweets&tweet_type=list&list_cache={$strListCacheID}&screen_name={$strOwnerScreenName}"));
 }