/** * * @return string */ private function _getListOfFeedItems() { $_oFeed = new FetchTweets_Extensions(); $_aFeedItems = $_oFeed->fetchFeed($this->_sFeedURL); if (empty($_aFeedItems)) { return "<h3>" . __('No template has been found.', 'fetch-tweets') . "</h3>"; } $_aOutput = array(); $_iMaxCols = 3; $_aColumnInfo = array('bIsRowTagClosed' => false, 'iCurrRowPos' => 0, 'iCurrColPos' => 0); $_aColumnOption = array('sClassAttr' => 'fetch_tweets_multiple_columns', 'sClassAttrGroup' => 'fetch_tweets_multiple_columns_box', 'sClassAttrRow' => 'fetch_tweets_multiple_columns_row', 'sClassAttrCol' => 'fetch_tweets_multiple_columns_col', 'sClassAttrFirstCol' => 'fetch_tweets_multiple_columns_first_col'); foreach ($_aFeedItems as $_sTitle => $_aItem) { // Increment the position $_aColumnInfo['iCurrColPos']++; // Enclose the item buffer into the item container $_sItem = '<div class="' . $_aColumnOption['sClassAttrCol'] . ' ftws_col_element_of_' . $_iMaxCols . ' ' . ' ftws_extension ' . (1 == $_aColumnInfo['iCurrColPos'] ? $_aColumnOption['sClassAttrFirstCol'] : '') . '"' . '>' . '<div class="ftws_extension_item">' . "<h4>{$_aItem['title']}</h4>" . $_aItem['description'] . "<div class='get-now'>" . "<a href='" . esc_url($_aItem['strLink']) . "' target='_blank' rel='nofollow' class='button button-secondary'>" . __('Get it Now', 'fetch-tweets') . "</a>" . "</div>" . '</div>' . '</div>'; // If it's the first item in the row, add the class attribute. // Be aware that at this point, the tag will be unclosed. Therefore, it must be closed somewhere. if ($_aColumnInfo['iCurrColPos'] == 1) { $_sItem = '<div class="' . $_aColumnOption['sClassAttrRow'] . '">' . $_sItem; } // If the current column position reached the set max column, increment the current position of row if ($_aColumnInfo['iCurrColPos'] % $_iMaxCols == 0) { $_aColumnInfo['iCurrRowPos']++; // increment the row number $_aColumnInfo['iCurrColPos'] = 0; // reset the current column position $_sItem .= '</div>'; // close the section(row) div tag $_aColumnInfo['bIsRowTagClosed'] = True; } $_aOutput[] = $_sItem; } // if the section(row) tag is not closed, close it if (!$_aColumnInfo['bIsRowTagClosed']) { $_aOutput[] .= '</div>'; } $_aColumnInfo['bIsRowTagClosed'] = true; // enclose the output in the group tag return '<div class="' . $_aColumnOption['sClassAttr'] . ' ' . $_aColumnOption['sClassAttrGroup'] . ' ' . '"' . '>' . implode(PHP_EOL, $_aOutput) . '</div>'; }
public function do_fetch_tweets_extensions_get_extensions() { $oExtensionLoader = new FetchTweets_Extensions(); $arrFeedItems = $oExtensionLoader->fetchFeed('http://feeds.feedburner.com/MiunosoftFetchTweetsExtension'); if (empty($arrFeedItems)) { echo "<h3>" . __('No extension has been found.', 'fetch-tweets') . "</h3>"; return; } $arrOutput = array(); $intMaxCols = 4; $this->arrColumnInfo = $this->arrColumnInfoDefault; foreach ($arrFeedItems as $strTitle => $arrItem) { // Increment the position $this->arrColumnInfo['numCurrColPos']++; // Enclose the item buffer into the item container $strItem = '<div class="' . $this->arrColumnOption['strClassAttrCol'] . ' ftws_col_element_of_' . $intMaxCols . ' ' . ' ftws_extension ' . ($this->arrColumnInfo['numCurrColPos'] == 1 ? $this->arrColumnOption['strClassAttrFirstCol'] : '') . '"' . '>' . '<div class="ftws_extension_item">' . "<h4>{$arrItem['strTitle']}</h4>" . $arrItem['strDescription'] . "<div class='get-now'><a href='{$arrItem['strLink']}' target='_blank' rel='nofollow'>" . "<input class='button button-secondary' type='submit' value='" . __('Get it Now', 'fetch-tweets') . "' />" . "</a></div>" . '</div>' . '</div>'; // If it's the first item in the row, add the class attribute. // Be aware that at this point, the tag will be unclosed. Therefore, it must be closed somewhere. if ($this->arrColumnInfo['numCurrColPos'] == 1) { $strItem = '<div class="' . $this->arrColumnOption['strClassAttrRow'] . '">' . $strItem; } // If the current column position reached the set max column, increment the current position of row if ($this->arrColumnInfo['numCurrColPos'] % $intMaxCols == 0) { $this->arrColumnInfo['numCurrRowPos']++; // increment the row number $this->arrColumnInfo['numCurrColPos'] = 0; // reset the current column position $strItem .= '</div>'; // close the section(row) div tag $this->arrColumnInfo['fIsRowTagClosed'] = True; } $arrOutput[] = $strItem; } // if the section(row) tag is not closed, close it if (!$this->arrColumnInfo['fIsRowTagClosed']) { $arrOutput[] .= '</div>'; } $this->arrColumnInfo['fIsRowTagClosed'] = true; // enclose the output in the group tag $strOut = '<div class="' . $this->arrColumnOption['strClassAttr'] . ' ' . $this->arrColumnOption['strClassAttrGroup'] . ' ' . '"' . '>' . implode('', $arrOutput) . '</div>'; echo '<div class="ftws_extension_container">' . $strOut . '</div>'; }