DB_Twitter_Feed_Base

The DevBuddy Twitter Feed Plugin DB Twitter Feed Base class.

Defined (1)

The class is defined in the following location(s).

/lib/class.twitter-feed-base.php  
  1. class DB_Twitter_Feed_Base extends DevBuddy_Feed_Plugin { 
  2.  
  3. /** 
  4. * @var string The name of the plugin to be used within the code 
  5. */ 
  6. public $plugin_name = 'db_twitter_feed'; 
  7.  
  8. /** 
  9. * @var string The short name of the plugin to be used within the code 
  10. */ 
  11. public $plugin_short_name = 'dbtf'; 
  12.  
  13. /** 
  14. * @var object Twitter API object 
  15. */ 
  16. public $twitter; 
  17.  
  18. /** 
  19. * @var string Used for storing the main group of options in the WP database 
  20. */ 
  21. protected $options_group_main; 
  22.  
  23. /** 
  24. * @var string Used for identifying the main options in the WP database 
  25. */ 
  26. protected $options_name_main; 
  27.  
  28. /** 
  29. * @var string Page URI within the WordPress admin 
  30. */ 
  31. protected $page_uri_main; 
  32.  
  33. /** 
  34. * @var array Holds the configuration options and their default and/or user defined values 
  35. */ 
  36. protected $defaults = array( 
  37. 'feed_type' => 'user_timeline', // String: ("user_timeline" or "search") The type of feed to render 
  38. 'user' => 'EjiOsigwe', // String: Any valid Twitter username 
  39. 'search_term' => '#twitter', // String: Any term to be search on Twitter 
  40. 'count' => '10', // String: Number of tweets to retrieve 
  41. 'exclude_replies' => 'no', // String: ("yes" or "no") Only display tweets that aren't replies 
  42. 'show_images' => 'no', // String: ("yes" or "no") Whether to load embedded images or not 
  43. 'https' => 'no', // String: ("yes" or "no") Load media from Twitter over secure HTTPS 
  44. 'default_styling' => 'no', // String: ("yes" or "no") Load the bundled stylesheet 
  45. 'cache_hours' => 0, // Int: Number of hours to cache the output 
  46. 'clear_cache' => 'no', // String: ("yes" or "no") Clear the cache for the set feed term,  
  47. 'oauth_access_token' => NULL, // String: The OAuth Access Token 
  48. 'oauth_access_token_secret' => NULL, // String: The OAuth Access Token Secret 
  49. 'consumer_key' => NULL, // String: The Consumer Key 
  50. 'consumer_secret' => NULL // String: The Consumer Secret 
  51. ); 
  52.  
  53.  
  54. /** 
  55. * Initialise important aspects of the plugin 
  56. * Set properties used for administritive processes 
  57. * and register the bundled stylesheet and shortcode 
  58. * with WordPress. 
  59. * @access public 
  60. * @return void 
  61. * @since 1.0.0 
  62. */ 
  63. public function __construct() { 
  64. $this->set_main_admin_vars(); 
  65.  
  66. add_action( 'wp_enqueue_scripts', array( $this, 'register_default_styling' ) ); 
  67. add_shortcode( 'db_twitter_feed', array( $this, 'register_twitter_feed_sc' ) ); 
  68.  
  69. if ( $this->get_db_plugin_option( $this->options_name_main, 'default_styling' ) === 'yes' ) 
  70. add_action( 'wp_enqueue_scripts', array( $this, 'load_default_styling' ) ); 
  71.  
  72.  
  73. /** 
  74. * Set properties used for administritive processes 
  75. * @access protected 
  76. * @return void 
  77. * @since 1.0.0 
  78. */ 
  79. protected function set_main_admin_vars() { 
  80. $this->options_group_main = $this->plugin_name; 
  81. $this->options_name_main = $this->plugin_name.'_options'; 
  82. $this->page_uri_main = 'db-twitter-feed-settings'; 
  83.  
  84.  
  85. /** 
  86. * Register the bundled stylesheet within WordPress ready for loading 
  87. * @access public 
  88. * @return void 
  89. * @since 1.0.0 
  90. */ 
  91. public function register_default_styling() { 
  92. wp_register_style( $this->plugin_name.'-default', DBTF_URL . '/assets/feed.css', NULL, '2.2', 'all' ); 
  93.  
  94.  
  95. /** 
  96. * Set the bundled stylesheet to be loaded to the page by WordPress 
  97. * @access public 
  98. * @return void 
  99. * @since 1.0.0 
  100. */ 
  101. public function load_default_styling() { 
  102. wp_enqueue_style( $this->plugin_name.'-default' ); 
  103.  
  104.  
  105. /** 
  106. * Register the shortcode that is used to render the feed 
  107. * This method is merely a port that moves the configuration data given 
  108. * to the db_twitter_feed() template tag, which does all of the actual 
  109. * work. 
  110. * @access public 
  111. * @return The db_twitter_feed() template tag with the $given_atts array as the parameter 
  112. * @since 1.0.0 
  113. * @param array $given_atts An associative array of feed configuration options 
  114. */ 
  115. public function register_twitter_feed_sc( $given_atts ) { 
  116. $default_atts = 
  117. array( 
  118. 'feed_type' => NULL,  
  119. 'user' => NULL,  
  120. 'search_term' => NULL,  
  121. 'count' => NULL,  
  122. 'exclude_replies' => NULL,  
  123. 'show_images' => NULL,  
  124. 'https' => NULL,  
  125. 'default_styling' => NULL,  
  126. 'cache_hours' => NULL,  
  127. 'clear_cache' => NULL,  
  128. 'oauth_access_token' => NULL,  
  129. 'oauth_access_token_secret' => NULL,  
  130. 'consumer_key' => NULL,  
  131. 'consumer_secret' => NULL 
  132. ); 
  133.  
  134. extract( 
  135. shortcode_atts( $default_atts, $given_atts ) 
  136. ); 
  137.  
  138. $feed_config = 
  139. array( 
  140. 'feed_type' => $feed_type,  
  141. 'user' => $user,  
  142. 'search_term' => $search_term,  
  143. 'count' => $count,  
  144. 'exclude_replies' => $exclude_replies,  
  145. 'show_images' => $show_images,  
  146. 'https' => $https,  
  147. 'default_styling' => $default_styling,  
  148. 'cache_hours' => $cache_hours,  
  149. 'clear_cache' => $clear_cache,  
  150. 'oauth_access_token' => $oauth_access_token,  
  151. 'oauth_access_token_secret' => $oauth_access_token_secret,  
  152. 'consumer_key' => $consumer_key,  
  153. 'consumer_secret' => $consumer_secret,  
  154. 'is_shortcode_called' => TRUE 
  155. ); 
  156.  
  157. return db_twitter_feed( $feed_config ); 
  158.  
  159.  
  160. /** 
  161. * Retrieve original version of masked data  
  162. * Takes a name, searches the database for,  
  163. * and returns the original, untampered data. 
  164. * @access protected 
  165. * @return array 
  166. * @since 1.0.0 
  167. * @param array $input An associative array of the submitted data 
  168. */ 
  169. protected function unmask_data( $input ) { 
  170. if ( preg_match( '|^([a-zA-Z0-9]{3})([x]+)([a-zA-Z0-9]{3})$|', $input['consumer_key'] ) === 1 ) { 
  171. $input['consumer_key'] = $this->get_option( $this->options_name_main, 'consumer_key' ); 
  172. if ( preg_match( '|^([a-zA-Z0-9]{3})([x]+)([a-zA-Z0-9]{3})$|', $input['consumer_secret'] ) === 1 ) { 
  173. $input['consumer_secret'] = $this->get_option( $this->options_name_main, 'consumer_secret' ); 
  174. if ( preg_match( '|^([0-9]+)([x]+)?-([x]+)([a-zA-Z0-9]{3})$|', $input['oauth_access_token'] ) === 1 ) { 
  175. $input['oauth_access_token'] = $this->get_option( $this->options_name_main, 'oauth_access_token' ); 
  176. if ( preg_match( '|^([a-zA-Z0-9]{3})([x]+)([a-zA-Z0-9]{3})$|', $input['oauth_access_token_secret'] ) === 1 ) { 
  177. $input['oauth_access_token_secret'] = $this->get_option( $this->options_name_main, 'oauth_access_token_secret' ); 
  178.  
  179. return $input; 
  180.  
  181.  
  182. /** 
  183. * Method used to parse through data submitted on the feed's settings page within WordPress 
  184. * This method will unmask authentication 
  185. * data if necessary by searching for and 
  186. * returning the value stored in the 
  187. * database. 
  188. * This method will also check for values 
  189. * marked as hidden, and move their data 
  190. * over to their visible counterparts 
  191. * @access public 
  192. * @return array 
  193. * @since 1.1.0 
  194. * @param array $input An associative array of the submitted data 
  195. */ 
  196. public function sanitize_settings_submission( $input ) { 
  197. // Deals with a cache clear request 
  198. if ( isset($input['cache_clear_flag']) && (int) $input['cache_clear_flag'] === 1 ) { 
  199. $bcc_feedback = $this->batch_clear_cache( $input['cache_segment'] ); 
  200.  
  201. // Establish tone of error by reading what is returned by batch_clear_cache() 
  202. switch ( $bcc_feedback ) { 
  203. case 'no_' . $input['cache_segment'] . '_cache_data_to_clear': 
  204. case 'no_cache_data_to_clear': 
  205. case 'no_segment_chosen': 
  206. case 'cache_not_cleared': 
  207. case 'unknown_error': 
  208. $tone = 'error'; 
  209. break; 
  210.  
  211. case ucfirst($input['cache_segment']) . '_cache_cleared': 
  212. case 'cache_cleared': 
  213. $tone = 'updated'; 
  214. break; 
  215.  
  216. // Set notification for next page 
  217. add_settings_error( 'cache_hours', 'cache_hours', ucfirst(str_replace('_', ' ', $bcc_feedback)), $tone ); 
  218.  
  219. // Return the original options as they're not be changed 
  220. $input = get_option( $this->options_name_main ); 
  221. return $input; 
  222.  
  223.  
  224. // Makes sure that no quotes have been used in any of the fields 
  225. foreach ( $input as $field_name => $field ) { 
  226. if ( strpos($field, '"') || strpos($field, "'") ) { 
  227. // Variable used for consistency when referencing the field name 
  228. $option_name = $field_name; 
  229.  
  230. // Get the field name without the "_hid" if it has it 
  231. $field_is_hidden = FALSE; 
  232. if ( strpos($field_name, '_hid') ) { 
  233. $field_is_hidden = TRUE; 
  234. $field_name_wh = str_replace('_hid', '', $field_name); 
  235. $option_name = $field_name_wh; 
  236.  
  237. // Replace value with quote in with old value from database 
  238. $input[$field_name] = $this->get_option( $this->options_name_main, $option_name ); 
  239.  
  240. // Check if we already set the error for this field (i.e. has duplicate hidden field) 
  241. $set_error = TRUE; 
  242. $error_msgs = get_settings_errors(); 
  243.  
  244. foreach ( $error_msgs as $error_msg ) { 
  245. if ( in_array('quotes_in_field_' . $option_name, $error_msg) ) { 
  246. $set_error = FALSE; 
  247.  
  248. if ( $set_error ) { 
  249. // Let the user know what's up 
  250. add_settings_error( '', 'quotes_in_field_' . $option_name, 'Quotes are not allowed in the <u>' . ucwords(str_replace('_', ' ', $option_name)) . '</u> field. Your change for that field was not applied' ); 
  251.  
  252. // Cleared as used else where in this section of code 
  253. unset($option_name); 
  254.  
  255.  
  256. // We don't want the cache_segment option to be saved 
  257. if ( isset( $input['cache_segment'] ) ) { 
  258. unset( $input['cache_segment'] ); 
  259. unset( $input['cache_clear_flag'] ); 
  260.  
  261. /** Saving via the WP settings page overwrites all 
  262. options that are currently saved. Here, we grab 
  263. items that aren't available in the settings page 
  264. and ensure that they aren't overwritten. */ 
  265. $options = get_option( $this->options_name_main ); 
  266. $option_saver = array(); 
  267. $option_saver_list = array( 
  268. //'feed_term_cache' 
  269. ); 
  270.  
  271. foreach ( $option_saver_list as $option_name ) { 
  272. /** However, we don't want to create an option 
  273. that doesn't already exist */ 
  274. if ( isset( $options[ $option_name ] ) ) { 
  275. $input[ $option_name ] = $options[ $option_name ]; 
  276.  
  277.  
  278. /** Some settings have matching hidden and visible fields 
  279. The hidden ones are the ones we want and this little 
  280. bit of script ensures that that's what we get */ 
  281. foreach ( $input as $item => $value ) { 
  282. if ( preg_match( '|_hid$|', $item ) === 1 ) { 
  283. $feed_value_name = str_replace('_hid', '', $item); 
  284.  
  285. unset( $input[ $feed_value_name ] ); 
  286. $input[ $feed_value_name ] = $value; 
  287.  
  288. unset( $input[ $item ] ); 
  289.  
  290.  
  291. // Check to see if any of the authentication data has been edited, grab the stored value if not 
  292. $input = $this->unmask_data( $input ); 
  293.  
  294.  
  295. // Finally, clear the cache of the current feed term 
  296. switch ( $input['feed_type'] ) { 
  297. case 'user_timeline': 
  298. $cache_id = $input['twitter_username']; 
  299. break; 
  300.  
  301. case 'search': 
  302. $cache_id = $input['search_term']; 
  303. break; 
  304.  
  305. default: 
  306. $cache_id = FALSE; 
  307. break; 
  308.  
  309. if ( $cache_id !== FALSE ) { 
  310. $this->clear_cache_output( $cache_id, $input['feed_type'] ); 
  311.  
  312. return $input; 
  313.  
  314.  
  315.  
  316. /** 
  317. * Cache whatever is in the DevBuddy_Feed_Plugin::$output property 
  318. * This method also sets the DevBuddy_Feed_Plugin::$is_cached property 
  319. * to TRUE once the cache is set. 
  320. * @access public 
  321. * @return void 
  322. * @since 1.2.0 
  323. * @param int $hours The number of hours the output should be cached for 
  324. */ 
  325. public function cache_output( $hours = 0 ) { 
  326. if ( ! isset( $this->options ) ) { 
  327. $this->error( 1, __CLASS__ . '->options must be set before an output can be cached' ); 
  328. return FALSE; 
  329.  
  330. /** The cache for the feed instance is set using the 
  331. feed term as its ID. Here we grab the ID */ 
  332. $id = ( isset($this->feed_term) ) ? $this->feed_term : FALSE; 
  333.  
  334. if ( (int) $hours > 0 ) { 
  335. if ( $id ) { 
  336. // Encode the cache 
  337. $the_output = json_encode($this->output); 
  338.  
  339. // Create the cache 
  340. set_transient( $this->plugin_name . '_output_' . $id, $the_output, 3600 * $hours ); 
  341.  
  342. // Check that the cache creation was successful 
  343. $cache_successful = get_transient( $this->plugin_name . '_output_' . $id ); 
  344.  
  345. if ( $cache_successful ) { 
  346. $this->is_cached = TRUE; 
  347.  
  348. $this->update_feed_term_cache( 
  349. array( 
  350. 'user' => $this->options['user'],  
  351. 'feed_type' => $this->options['feed_type'],  
  352. 'search_term' => $this->options['search_term'],  
  353. 'cache_hours' => $this->options['cache_hours'] 
  354. ); 
  355.  
  356. return TRUE; 
  357.  
  358. } else { 
  359. $this->error( 2, 'Cache operation unsuccessful near line <b>' . __LINE__ . '</b> in <b>' . __FILE__ . '</b>' ); 
  360. return FALSE; 
  361.  
  362. } else { 
  363. $this->error( 2, 'Given ID should not be FALSE near line <b>' . __LINE__ . '</b> in <b>' . __FILE__ . '</b>' ); 
  364. return FALSE; 
  365.  
  366.  
  367.  
  368. /** 
  369. * Clear the cached output of a specific user or search 
  370. * This method also sets the DevBuddy_Feed_Plugin::$is_cached 
  371. * property to FALSE once the cache is deleted and is called 
  372. * when changes have been saved on the settings page in 
  373. * WordPress. 
  374. * @access public 
  375. * @return bool 
  376. * @since 1.0.0 
  377. * @param string $id The cached ID of the feed 
  378. * @param string $segment The segment of the feed term cache that the $id belongs to 
  379. */ 
  380. public function clear_cache_output( $id, $segment = NULL ) { 
  381. delete_transient( $this->plugin_name . '_output_' . $id ); 
  382.  
  383. $clear_cache_successful = ( get_transient( $this->plugin_name . '_output_' . $id ) ) ? FALSE : TRUE; 
  384.  
  385. if ( $clear_cache_successful ) { 
  386. $this->is_cached = FALSE; 
  387.  
  388. /** If a segment is available, we specify it to add accuracy to 
  389. feed term cache update */ 
  390. if ( $segment === NULL ) { 
  391. $this->clear_feed_term_cache_item( $id ); 
  392. } else { 
  393. $this->clear_feed_term_cache_item( $id, $segment ); 
  394.  
  395. return TRUE; 
  396.  
  397. } else { 
  398. $this->error( 2, __METHOD__ . ' was unsuccessful' ); 
  399. return FALSE; 
  400.  
  401.  
  402. /** 
  403. * Update the feed term cache with about a cache. 
  404. * Necessary data to pass to the array: user, feed_type, search_term, cache_hours 
  405. * @access protected 
  406. * @return bool A boolean indication of whether or not the feed term cache update was successful 
  407. * @since 1.2.0 
  408. *  
  409. * @param array $input An associative array of data necessary to populate the feed term cache 
  410. */ 
  411. protected function update_feed_term_cache( $input ) { 
  412. // No array? No go. 
  413. if ( ! is_array($input) ) { 
  414. return FALSE; 
  415.  
  416. $options = get_option( $this->options_name_main ); 
  417. $valid_feed_type = TRUE; 
  418.  
  419. // Grab the feed term cache or create it if it doesn't exist 
  420. $ftc = get_transient( $this->plugin_name . '_ftc' ); 
  421. if ( ! $ftc ) { 
  422. $ftc = array( 
  423. 'user_timeline' => array(),  
  424. 'search' => array() 
  425. ); 
  426.  
  427. /** Check that the user has requested to cache the feed and 
  428. create the cache data array item */ 
  429. if ( (int) $input['cache_hours'] !== 0 && ! $this->is_empty() && ! $this->has_errors() ) { 
  430. $cache_hours = (int) $input['cache_hours'] * 3600; 
  431. $cache_expires = time() + $cache_hours; 
  432.  
  433. switch ( $input['feed_type'] ) { 
  434. case 'user_timeline': 
  435. $user = htmlspecialchars($input['user'], ENT_QUOTES); 
  436. if ( $user !== FALSE ) { 
  437. $ftc['user_timeline'][ $user ] = array( 
  438. 'cache_began' => time(),  
  439. 'cache_lasts' => $cache_hours,  
  440. 'cache_expires' => $cache_expires 
  441. ); 
  442. break; 
  443.  
  444. case 'search': 
  445. $search_term = htmlspecialchars($input['search_term'], ENT_QUOTES); 
  446. if ( $search_term !== FALSE ) { 
  447. $ftc['search'][ $search_term ] = array( 
  448. 'cache_began' => time(),  
  449. 'cache_lasts' => $cache_hours,  
  450. 'cache_expires' => $cache_expires 
  451. ); 
  452. break; 
  453.  
  454. default: 
  455. $valid_feed_type = FALSE; 
  456. break; 
  457.  
  458. if ( $valid_feed_type === TRUE ) { 
  459. if ( set_transient( $this->plugin_name . '_ftc', $ftc, 3600 * 24 ) === FALSE ) { 
  460. $this->error( 2, 'set_transient() for ' . $this->plugin_name . '_ftc was unsuccessful' ); 
  461. return FALSE; 
  462.  
  463. } else { 
  464. return TRUE; 
  465.  
  466. } else { 
  467. $this->error( 2, 'Invalid feed type on line ' . __LINE__ ); 
  468. return FALSE; 
  469.  
  470.  
  471. /** 
  472. * Clear a specific option term the feed term cache 
  473. * @access protected 
  474. * @return bool A boolean indication of whether or not the operation was successful 
  475. * @since 1.2.0 
  476. *  
  477. * @param string $term The identifier for the term you wish to clear 
  478. * @param mixed $segment The identifier for the segment you wish to clear 
  479. */ 
  480. protected function clear_feed_term_cache_item( $term, $segment = NULL ) { 
  481. $ftc = get_transient( $this->plugin_name . '_ftc' ); 
  482.  
  483. // Assuming empty 
  484. $ftc_is_empty = TRUE; 
  485.  
  486. // Check that a feed term cache is even available... 
  487. if ( $ftc !== FALSE ) { 
  488.  
  489. // ...and has entries 
  490. foreach ( $ftc as $cache ) { 
  491. if ( ! empty( $cache ) ) { 
  492. $ftc_is_empty = FALSE; 
  493.  
  494.  
  495. if ( $ftc === FALSE || $ftc_is_empty === TRUE ) { 
  496. //$this->error( 3, 'A feed term cache has not recently been created, nothing to clear' ); 
  497. return FALSE; 
  498.  
  499. // Return false if given segment doesn't exist 
  500. if ( $segment !== NULL && ! array_key_exists($segment, $ftc) ) { 
  501. $this->error( 2, 'Given segment [' . $segment . '] does not exist in feed term cache:' . __LINE__ ); 
  502. return FALSE; 
  503.  
  504. // Return false if data for given identifier doesn't exist 
  505. if ( $segment !== NULL && array_key_exists($segment, $ftc) && ! isset($ftc[$segment][$term]) ) { 
  506. $this->error( 3, 'Given term [' . $term . '] does not exist in feed term cache:' . __LINE__); 
  507. return FALSE; 
  508.  
  509. // Clear the term from the feed term cache 
  510. // If $segment is NULL, clear all instances of $term 
  511. if ( $segment === NULL ) { 
  512. foreach ( $ftc as $s => $t_data ) { 
  513. foreach ( $t_data as $t => $data ) { 
  514. if ( $t === $term ) { 
  515. unset($ftc[$s][$term]); 
  516.  
  517. } else { 
  518. unset($ftc[$segment][$term]); 
  519.  
  520.  
  521. // Push the updated feed term cache 
  522. $ftc_updated = set_transient( $this->plugin_name . '_ftc', $ftc, 3600 * 24 ); 
  523. if ( $ftc_updated === TRUE ) { 
  524. return TRUE; 
  525. } else { 
  526. $this->error( 2, __METHOD__ . ', ftc transient update was unsuccessful' ); 
  527. return FALSE; 
  528.  
  529.  
  530.  
  531. /** 
  532. * Batch clear feed cache 
  533. * @access public 
  534. * @return string A line of text describing the outcome of the operation 
  535. * @since 1.2.0 
  536. * @param string $segment The segment of the cache you wish to clear 
  537. */ 
  538. public function batch_clear_cache( $segment = 'all' ) { 
  539. if ( is_array($segment) && isset($segment['segment']) ) { 
  540. $segment = $segment['segment']; 
  541.  
  542. // Check that a cache segment has been passed 
  543. if ( $segment === '0' ) { 
  544. return 'no_segment_chosen'; 
  545.  
  546. // Check for existing feed term cache 
  547. $ftc = get_transient( $this->plugin_name . '_ftc' ); 
  548. $no_cache_records = FALSE; 
  549.  
  550. // Check that the transient did exist 
  551. if ( $ftc === FALSE ) { 
  552. $no_cache_records = TRUE; 
  553.  
  554. /** Though the transient may exist, it may be empty so we 
  555. check through each segment to see if it contains data */ 
  556. if ( $ftc !== FALSE ) { 
  557. $active_segments = 0; 
  558.  
  559. foreach ( $ftc as $seg ) { 
  560. if ( is_array($seg) && count($seg) > 0 ) { 
  561. $active_segments++; 
  562.  
  563. if ( $active_segments === 0 ) { 
  564. $no_cache_records = TRUE; 
  565.  
  566. if ( $no_cache_records === TRUE ) { 
  567. return 'no_cache_data_to_clear'; 
  568.  
  569. // Holds info on each term cache clear. Useful for debugging 
  570. $feedback = array(); 
  571.  
  572. switch ( $segment ) { 
  573. case 'user_timeline': 
  574. $clearance_list = $ftc['user_timeline']; 
  575. break; 
  576.  
  577. case 'search': 
  578. $clearance_list = $ftc['search']; 
  579. break; 
  580.  
  581. case 'all': 
  582. $clearance_list = NULL; 
  583. break; 
  584.  
  585. default: 
  586. $clearance_list = FALSE; 
  587. break; 
  588.  
  589. $cache_cleared = FALSE; 
  590.  
  591. if ( $clearance_list !== FALSE && is_array($clearance_list) ) { 
  592.  
  593. // Check that there's data to clear and clear if so 
  594. if ( is_array($clearance_list) && count($clearance_list) > 0 ) { 
  595. foreach ( $clearance_list as $term => $term_data ) { 
  596. $feedback[ $term ] = $this->clear_cache_output( $term, $segment ); 
  597. $cache_cleared = TRUE; 
  598.  
  599. } else { 
  600. $cache_cleared = FALSE; 
  601.  
  602. if ( $cache_cleared ) { 
  603. return ucfirst($segment) . '_cache_cleared'; 
  604. } else { 
  605. return 'no_' . $segment . '_cache_data_to_clear'; 
  606.  
  607. } elseif ( $clearance_list === NULL ) { 
  608. foreach ( $ftc as $s => $t_data ) { 
  609. foreach ( $t_data as $t => $data ) { 
  610. $feedback[ $t ] = $this->clear_cache_output( $t, $s ); 
  611. $cache_cleared = TRUE; 
  612.  
  613. if ( $cache_cleared ) { 
  614. return 'cache_cleared'; 
  615. } else { 
  616. return 'cache_not_cleared'; 
  617.  
  618. } else { 
  619. return 'unknown_error'; 
  620.  
  621.  
  622. } // END class