/** * Returns the formatted argument array. * * @since 2.4.6 */ protected function _getFormattedArguments(array $aArgs) { $aArgs = FetchTweets_Utilities::uniteArrays($aArgs, $this->oOption->aOptions['default_values'] + $this->oOption->aStructure_DefaultParams + $this->oOption->aStructure_DefaultTemplateOptions); $aArgs['id'] = isset($aArgs['ids']) && !empty($aArgs['ids']) ? $aArgs['ids'] : $aArgs['id']; // backward compatibility $aArgs['id'] = is_array($aArgs['id']) ? $aArgs['id'] : preg_split("/[,]\\s*/", trim((string) $aArgs['id']), 0, PREG_SPLIT_NO_EMPTY); return $aArgs; }
$strUserName = $arrDetail['user']['name']; $strUserLang = $arrDetail['user']['lang']; $strDescription = $arrDetail['user']['description']; break; // the first iteration item is only necessary } // Set the default template option values. $arrDefaultTemplateValues = array('fetch_tweets_template_single_avatar_size' => 48, 'fetch_tweets_template_single_avatar_position' => 'left', 'fetch_tweets_template_single_width' => array('size' => 100, 'unit' => '%'), 'fetch_tweets_template_single_height' => array('size' => 400, 'unit' => 'px'), 'fetch_tweets_template_single_background_color' => 'transparent', 'fetch_tweets_template_single_intent_buttons' => 2, 'fetch_tweets_template_single_intent_script' => 1, 'fetch_tweets_template_single_follow_button_elements' => array('screen_name' => 0, 'follower_count' => 0), 'fetch_tweets_template_single_visibilities' => array('avatar' => true, 'user_name' => true, 'follow_button' => true, 'user_description' => true, 'time' => true, 'intent_buttons' => true), 'fetch_tweets_template_single_margins' => array('top' => array('size' => '', 'unit' => 'px'), 'left' => array('size' => '', 'unit' => 'px'), 'bottom' => array('size' => '', 'unit' => 'px'), 'right' => array('size' => '', 'unit' => 'px')), 'fetch_tweets_template_single_paddings' => array('top' => array('size' => '', 'unit' => 'px'), 'left' => array('size' => '', 'unit' => 'px'), 'bottom' => array('size' => '', 'unit' => 'px'), 'right' => array('size' => '', 'unit' => 'px'))); // Retrieve the template option values. if (!isset($arrOptions['fetch_tweets_templates']['fetch_tweets_template_single'])) { // for the fist time of calling the template. $arrOptions['fetch_tweets_templates']['fetch_tweets_template_single'] = $arrDefaultTemplateValues; update_option(FetchTweets_Commons::AdminOptionKey, $arrOptions); } // Some new setting items are not be stored in the database, so merge the saved options with the defined default values. $arrTemplateOptions = FetchTweets_Utilities::uniteArrays($arrOptions['fetch_tweets_templates']['fetch_tweets_template_single'], $arrDefaultTemplateValues); // unites arrays recursively. // Set the template option values. $arrArgs['avatar_size'] = isset($arrArgs['avatar_size']) ? $arrArgs['avatar_size'] : $arrTemplateOptions['fetch_tweets_template_single_avatar_size']; $arrArgs['avatar_position'] = isset($arrArgs['avatar_position']) ? $arrArgs['avatar_position'] : $arrTemplateOptions['fetch_tweets_template_single_avatar_position']; $arrArgs['width'] = isset($arrArgs['width']) ? $arrArgs['width'] : $arrTemplateOptions['fetch_tweets_template_single_width']['size']; $arrArgs['width_unit'] = isset($arrArgs['width_unit']) ? $arrArgs['width_unit'] : $arrTemplateOptions['fetch_tweets_template_single_width']['unit']; $arrArgs['height'] = isset($arrArgs['height']) ? $arrArgs['height'] : $arrTemplateOptions['fetch_tweets_template_single_height']['size']; $arrArgs['height_unit'] = isset($arrArgs['height_unit']) ? $arrArgs['height_unit'] : $arrTemplateOptions['fetch_tweets_template_single_height']['unit']; $arrArgs['background_color'] = isset($arrArgs['background_color']) ? $arrArgs['background_color'] : $arrTemplateOptions['fetch_tweets_template_single_background_color']; $arrArgs['visibilities'] = isset($arrArgs['visibilities']) ? $arrArgs['visibilities'] : $arrTemplateOptions['fetch_tweets_template_single_visibilities']; $arrArgs['margin_top'] = isset($arrArgs['margin_top']) ? $arrArgs['margin_top'] : $arrTemplateOptions['fetch_tweets_template_single_margins']['top']['size']; $arrArgs['margin_top_unit'] = isset($arrArgs['margin_top_unit']) ? $arrArgs['margin_top_unit'] : $arrTemplateOptions['fetch_tweets_template_single_margins']['top']['unit']; $arrArgs['margin_right'] = isset($arrArgs['margin_right']) ? $arrArgs['margin_right'] : $arrTemplateOptions['fetch_tweets_template_single_margins']['right']['size']; $arrArgs['margin_right_unit'] = isset($arrArgs['margin_right_unit']) ? $arrArgs['margin_right_unit'] : $arrTemplateOptions['fetch_tweets_template_single_margins']['right']['unit']; $arrArgs['margin_bottom'] = isset($arrArgs['margin_bottom']) ? $arrArgs['margin_bottom'] : $arrTemplateOptions['fetch_tweets_template_single_margins']['bottom']['size'];
/** * Updates the format of options of v1 to v2. */ private function _convertV1OptionsToV2($aOptions) { // Drop the page slug dimension. $_aOptions = FetchTweets_Utilities::uniteArrays(isset($aOptions['fetch_tweets_settings']) ? $aOptions['fetch_tweets_settings'] : array(), isset($aOptions['fetch_tweets_templates']) ? $aOptions['fetch_tweets_templates'] : array()); unset($aOptions['fetch_tweets_settings'], $aOptions['fetch_tweets_templates']); // For template options if (isset($_aOptions['fetch_tweets_template_plain']['fetch_tweets_template_plain_paddings']['top'])) { $_aOptions['fetch_tweets_template_plain']['fetch_tweets_template_plain_paddings'][0] = $_aOptions['fetch_tweets_template_plain']['fetch_tweets_template_plain_paddings']['top']; unset($_aOptions['fetch_tweets_template_plain']['fetch_tweets_template_plain_paddings']['top']); } if (isset($_aOptions['fetch_tweets_template_plain']['fetch_tweets_template_plain_paddings']['right'])) { $_aOptions['fetch_tweets_template_plain']['fetch_tweets_template_plain_paddings'][1] = $_aOptions['fetch_tweets_template_plain']['fetch_tweets_template_plain_paddings']['right']; unset($_aOptions['fetch_tweets_template_plain']['fetch_tweets_template_plain_paddings']['right']); } if (isset($_aOptions['fetch_tweets_template_plain']['fetch_tweets_template_plain_paddings']['bottom'])) { $_aOptions['fetch_tweets_template_plain']['fetch_tweets_template_plain_paddings'][2] = $_aOptions['fetch_tweets_template_plain']['fetch_tweets_template_plain_paddings']['bottom']; unset($_aOptions['fetch_tweets_template_plain']['fetch_tweets_template_plain_paddings']['bottom']); } if (isset($_aOptions['fetch_tweets_template_plain']['fetch_tweets_template_plain_paddings']['left'])) { $_aOptions['fetch_tweets_template_plain']['fetch_tweets_template_plain_paddings'][3] = $_aOptions['fetch_tweets_template_plain']['fetch_tweets_template_plain_paddings']['left']; unset($_aOptions['fetch_tweets_template_plain']['fetch_tweets_template_plain_paddings']['left']); } if (isset($_aOptions['fetch_tweets_template_single']['fetch_tweets_template_single_paddings']['top'])) { $_aOptions['fetch_tweets_template_single']['fetch_tweets_template_single_paddings'][0] = $_aOptions['fetch_tweets_template_single']['fetch_tweets_template_single_paddings']['top']; unset($_aOptions['fetch_tweets_template_single']['fetch_tweets_template_single_paddings']['top']); } if (isset($_aOptions['fetch_tweets_template_single']['fetch_tweets_template_single_paddings']['right'])) { $_aOptions['fetch_tweets_template_single']['fetch_tweets_template_single_paddings'][1] = $_aOptions['fetch_tweets_template_single']['fetch_tweets_template_single_paddings']['right']; unset($_aOptions['fetch_tweets_template_single']['fetch_tweets_template_single_paddings']['right']); } if (isset($_aOptions['fetch_tweets_template_single']['fetch_tweets_template_single_paddings']['bottom'])) { $_aOptions['fetch_tweets_template_single']['fetch_tweets_template_single_paddings'][2] = $_aOptions['fetch_tweets_template_single']['fetch_tweets_template_single_paddings']['bottom']; unset($_aOptions['fetch_tweets_template_single']['fetch_tweets_template_single_paddings']['bottom']); } if (isset($_aOptions['fetch_tweets_template_single']['fetch_tweets_template_single_paddings']['left'])) { $_aOptions['fetch_tweets_template_single']['fetch_tweets_template_single_paddings'][3] = $_aOptions['fetch_tweets_template_single']['fetch_tweets_template_single_paddings']['left']; unset($_aOptions['fetch_tweets_template_single']['fetch_tweets_template_single_paddings']['left']); } // Credentials if (isset($_aOptions['authentication_keys'])) { $_aOptions['authentication_keys']['is_connected'] = $_aOptions['authentication_keys']['consumer_key'] && $_aOptions['authentication_keys']['consumer_secret'] && $_aOptions['authentication_keys']['access_token'] && $_aOptions['authentication_keys']['access_secret']; $_aOptions['authentication_keys']['connect_method'] = 'manual'; } if (isset($_aOptions['twitter_connect'])) { $_aOptions['twitter_connect']['is_connected'] = $_aOptions['twitter_connect']['access_token'] && $_aOptions['twitter_connect']['access_secret']; $_aOptions['twitter_connect']['connect_method'] = 'oauth'; } return $_aOptions + $aOptions; }
/* * Available variables passed from the caller script * - $aTweets : the fetched tweet arrays. * - $aArgs : the passed arguments such as item count etc. * - $aOptions : the plugin options saved in the database. * */ // Set the default template option values. $aDefaultTemplateValues = array('fetch_tweets_template_plain_avatar_size' => 48, 'fetch_tweets_template_plain_avatar_position' => 'left', 'fetch_tweets_template_plain_width' => array('size' => 100, 'unit' => '%'), 'fetch_tweets_template_plain_height' => array('size' => 400, 'unit' => 'px'), 'fetch_tweets_template_plain_background_color' => 'transparent', 'fetch_tweets_template_plain_intent_buttons' => 2, 'fetch_tweets_template_plain_intent_script' => 1, 'fetch_tweets_template_plain_visibilities' => array('avatar' => true, 'user_name' => true, 'follow_button' => false, 'time' => true, 'intent_buttons' => true), 'fetch_tweets_template_plain_margins' => array(0 => array('size' => '', 'unit' => 'px'), 1 => array('size' => '', 'unit' => 'px'), 2 => array('size' => '', 'unit' => 'px'), 3 => array('size' => '', 'unit' => 'px')), 'fetch_tweets_template_plain_paddings' => array(0 => array('size' => '', 'unit' => 'px'), 1 => array('size' => '', 'unit' => 'px'), 2 => array('size' => '', 'unit' => 'px'), 3 => array('size' => '', 'unit' => 'px')), 'fetch_tweets_template_plain_follow_button_elements' => array('screen_name' => 0, 'follower_count' => 0)); // Retrieve the default template option values. if (!isset($aOptions['fetch_tweets_template_plain'])) { // for the first time of calling the template. $aOptions['fetch_tweets_template_plain'] = $aDefaultTemplateValues; update_option(FetchTweets_Commons::AdminOptionKey, $aOptions); } // Some new setting items are not stored in the database, so merge the saved options with the defined default values. $aTemplateOptions = FetchTweets_Utilities::uniteArrays($aOptions['fetch_tweets_template_plain'], $aDefaultTemplateValues); // unites arrays recursively. // Finalize the template option values. $aArgs['avatar_size'] = isset($aArgs['avatar_size']) ? $aArgs['avatar_size'] : $aTemplateOptions['fetch_tweets_template_plain_avatar_size']; $aArgs['avatar_position'] = isset($aArgs['avatar_position']) ? $aArgs['avatar_position'] : $aTemplateOptions['fetch_tweets_template_plain_avatar_position']; $aArgs['width'] = isset($aArgs['width']) ? $aArgs['width'] : $aTemplateOptions['fetch_tweets_template_plain_width']['size']; $aArgs['width_unit'] = isset($aArgs['width_unit']) ? $aArgs['width_unit'] : $aTemplateOptions['fetch_tweets_template_plain_width']['unit']; $aArgs['height'] = isset($aArgs['height']) ? $aArgs['height'] : $aTemplateOptions['fetch_tweets_template_plain_height']['size']; $aArgs['height_unit'] = isset($aArgs['height_unit']) ? $aArgs['height_unit'] : $aTemplateOptions['fetch_tweets_template_plain_height']['unit']; $aArgs['background_color'] = isset($aArgs['background_color']) ? $aArgs['background_color'] : $aTemplateOptions['fetch_tweets_template_plain_background_color']; $aArgs['visibilities'] = isset($aArgs['visibilities']) ? $aArgs['visibilities'] : $aTemplateOptions['fetch_tweets_template_plain_visibilities']; $aArgs['margin_top'] = isset($aArgs['margin_top']) ? $aArgs['margin_top'] : $aTemplateOptions['fetch_tweets_template_plain_margins'][0]['size']; $aArgs['margin_top_unit'] = isset($aArgs['margin_top_unit']) ? $aArgs['margin_top_unit'] : $aTemplateOptions['fetch_tweets_template_plain_margins'][0]['unit']; $aArgs['margin_right'] = isset($aArgs['margin_right']) ? $aArgs['margin_right'] : $aTemplateOptions['fetch_tweets_template_plain_margins'][1]['size']; $aArgs['margin_right_unit'] = isset($aArgs['margin_right_unit']) ? $aArgs['margin_right_unit'] : $aTemplateOptions['fetch_tweets_template_plain_margins'][1]['unit']; $aArgs['margin_bottom'] = isset($aArgs['margin_bottom']) ? $aArgs['margin_bottom'] : $aTemplateOptions['fetch_tweets_template_plain_margins'][2]['size'];
/** * * @param array|integer $vPostIDs The target post ID of the Fetch Tweet rule post type. * @param array $aArgs The argument array. It is passed by reference to let assign post meta options. */ protected function _getTweetsAsArrayByPostIDs($vPostIDs, &$aArgs, $aRawArgs) { $_aTweets = array(); foreach ((array) $vPostIDs as $_iPostID) { $aArgs['tweet_type'] = get_post_meta($_iPostID, 'tweet_type', true); $aArgs['count'] = get_post_meta($_iPostID, 'item_count', true); $aArgs['include_rts'] = get_post_meta($_iPostID, 'include_rts', true); $aArgs['cache'] = get_post_meta($_iPostID, 'cache', true); $_aRetrievedTweets = array(); switch ($aArgs['tweet_type']) { case 'search': $aArgs['q'] = get_post_meta($_iPostID, 'search_keyword', true); $aArgs['result_type'] = get_post_meta($_iPostID, 'result_type', true); $aArgs['lang'] = get_post_meta($_iPostID, 'language', true); $aArgs['until'] = get_post_meta($_iPostID, 'until', true); $aArgs['geocentric_coordinate'] = get_post_meta($_iPostID, 'geocentric_coordinate', true); $aArgs['geocentric_radius'] = get_post_meta($_iPostID, 'geocentric_radius', true); $_sGeoCode = ''; if (is_array($aArgs['geocentric_coordinate']) && is_array($aArgs['geocentric_radius']) && isset($aArgs['geocentric_coordinate']['latitude'], $aArgs['geocentric_radius']['size']) && $aArgs['geocentric_coordinate']['latitude'] !== '' && $aArgs['geocentric_coordinate']['longitude'] !== '' && $aArgs['geocentric_radius']['size'] !== '') { // "latitude,longitude,radius", $_sGeoCode = trim($aArgs['geocentric_coordinate']['latitude']) . "," . trim($aArgs['geocentric_coordinate']['longitude']) . "," . trim($aArgs['geocentric_radius']['size']) . $aArgs['geocentric_radius']['unit']; } $aArgs = FetchTweets_Utilities::uniteArrays($aRawArgs, $aArgs); // The direct input takes its precedence. $_aRetrievedTweets = $this->getTweetsBySearch($aArgs['q'], $aArgs['count'], $aArgs['lang'], $aArgs['result_type'], $aArgs['until'], $_sGeoCode, $aArgs['cache']); break; case 'list': $aArgs['account_id'] = get_post_meta($_iPostID, 'account_id', true); $aArgs['mode'] = get_post_meta($_iPostID, 'mode', true); $aArgs['list_id'] = get_post_meta($_iPostID, 'list_id', true); $aArgs = FetchTweets_Utilities::uniteArrays($aRawArgs, $aArgs); // The direct input takes its precedence. $_aRetrievedTweets = $this->_getTweetsByListID($aArgs['list_id'], $aArgs['include_rts'], $aArgs['cache'], $aArgs['account_id'], $aArgs['mode']); break; case 'home_timeline': $aArgs['account_id'] = get_post_meta($_iPostID, 'account_id', true); $aArgs['exclude_replies'] = get_post_meta($_iPostID, 'exclude_replies', true); $aArgs = FetchTweets_Utilities::uniteArrays($aRawArgs, $aArgs); // The direct input takes its precedence. $_aRetrievedTweets = $this->_getTweetsByHomeTimeline($aArgs['account_id'], $aArgs['exclude_replies'], $aArgs['include_rts'], $aArgs['cache']); break; case 'feed': $aArgs['json_url'] = get_post_meta($_iPostID, 'json_url', true); $aArgs = FetchTweets_Utilities::uniteArrays($aRawArgs, $aArgs); // The direct input takes its precedence. $_aRetrievedTweets = $this->_getTweetsByJSONFeed($aArgs['json_url'], $aArgs['cache']); break; case 'custom_query': $aArgs['custom_query'] = get_post_meta($_iPostID, 'custom_query', true); $aArgs['response_key'] = get_post_meta($_iPostID, 'response_key', true); $aArgs = FetchTweets_Utilities::uniteArrays($aRawArgs, $aArgs); // The direct input takes its precedence. $_aRetrievedTweets = $this->_getResponseWithCustomRequest($aArgs['custom_query'], $aArgs['response_key'], $aArgs['cache']); break; case 'tweet_id': $aArgs['tweet_id'] = get_post_meta($_iPostID, 'tweet_id', true); $aArgs = FetchTweets_Utilities::uniteArrays($aRawArgs, $aArgs); // The direct input takes its precedence. $_aRetrievedTweets = $this->_getResponseByTweetID($aArgs['tweet_id'], $aArgs['cache']); break; case 'screen_name': default: $aArgs['screen_name'] = get_post_meta($_iPostID, 'screen_name', true); $aArgs['exclude_replies'] = get_post_meta($_iPostID, 'exclude_replies', true); $aArgs = FetchTweets_Utilities::uniteArrays($aRawArgs, $aArgs); // The direct input takes its precedence. $_aRetrievedTweets = $this->getTweetsByScreenNames($aArgs['screen_name'], $aArgs['count'], $aArgs['include_rts'], $aArgs['exclude_replies'], $aArgs['cache']); break; } $_aTweets = array_merge($_aRetrievedTweets, $_aTweets); } return $_aTweets; }
protected function getTweetsAsArrayByPostID($vPostIDs, $arrArgs, $arrRawArgs) { $arrTweets = array(); foreach ((array) $vPostIDs as $intPostID) { $arrArgs['tweet_type'] = get_post_meta($intPostID, 'tweet_type', true); $arrArgs['count'] = get_post_meta($intPostID, 'item_count', true); $arrArgs['include_retweets'] = get_post_meta($intPostID, 'include_retweets', true); $arrArgs['cache'] = get_post_meta($intPostID, 'cache', true); switch ($arrArgs['tweet_type']) { case 'search': $arrArgs['q'] = get_post_meta($intPostID, 'search_keyword', true); $arrArgs['result_type'] = get_post_meta($intPostID, 'result_type', true); $arrArgs['lang'] = get_post_meta($intPostID, 'language', true); $arrArgs = FetchTweets_Utilities::uniteArrays($arrRawArgs, $arrArgs); // The direct input takes its precedence. $arrRetrievedTweets = $this->getTweetsBySearch($arrArgs['q'], $arrArgs['count'], $arrArgs['lang'], $arrArgs['result_type'], $arrArgs['cache']); break; case 'list': $arrArgs['list_id'] = get_post_meta($intPostID, 'list_id', true); $arrArgs = FetchTweets_Utilities::uniteArrays($arrRawArgs, $arrArgs); // The direct input takes its precedence. $arrRetrievedTweets = $this->getTweetsByListID($arrArgs['list_id'], $arrArgs['count'], $arrArgs['include_retweets'], $arrArgs['cache']); break; case 'screen_name': default: $arrArgs['screen_name'] = get_post_meta($intPostID, 'screen_name', true); $arrArgs['exclude_replies'] = get_post_meta($intPostID, 'exclude_replies', true); $arrArgs = FetchTweets_Utilities::uniteArrays($arrRawArgs, $arrArgs); // The direct input takes its precedence. $arrRetrievedTweets = $this->getTweetsByScreenName($arrArgs['screen_name'], $arrArgs['count'], $arrArgs['include_retweets'], $arrArgs['exclude_replies'], $arrArgs['cache']); break; } $arrTweets = array_merge($arrRetrievedTweets, $arrTweets); } return $arrTweets; }