PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/mts_onepage/index.php

https://bitbucket.org/tulsagraphics/themes
PHP | 82 lines | 70 code | 6 blank | 6 comment | 23 complexity | 50272f967876a6cd237496b5a749695b MD5 | raw file
Possible License(s): AGPL-1.0, BSD-3-Clause, GPL-2.0
  1. <?php
  2. $mts_options = get_option(MTS_THEME_NAME);
  3. if(!empty($mts_options['mts_homepage_layout']['enabled'])){
  4. $homepage_layout = $mts_options['mts_homepage_layout']['enabled'];
  5. } else {
  6. $homepage_layout = array();
  7. }
  8. ?>
  9. <?php get_header(); ?>
  10. <div id="page">
  11. <?php
  12. foreach($homepage_layout as $key => $section){
  13. if($key == 'twitter'){
  14. ?>
  15. <?php
  16. /**
  17. * Twitter tweets
  18. */
  19. if(array_key_exists('twitter',$homepage_layout)) :?>
  20. <section id="homepage-twitter" class="homepage-section homepage-twitter" style="background-color:<?php echo $mts_options['homepage_twitter_background_color']; ?>;background-image: url(<?php print $mts_options['homepage_twitter_background_image']; ?>); ">
  21. <div class="inside">
  22. <?php
  23. if(empty($mts_options['homepage_twitter_api_key']) || empty($mts_options['homepage_twitter_api_secret']) || empty($mts_options['homepage_twitter_access_token']) || empty($mts_options['homepage_twitter_access_token_secret']) || empty($mts_options['homepage_twitter_username'])){
  24. echo '<strong>'.__('The section is not configured correctly', 'mythemeshop').'</strong>'; }
  25. //check if cache needs update
  26. $mts_twitter_plugin_last_cache_time = get_option('mts_twitter_plugin_last_cache_time');
  27. $diff = time() - $mts_twitter_plugin_last_cache_time;
  28. $crt =0 * 3600;
  29. if($diff >= $crt || empty($mts_twitter_plugin_last_cache_time)){
  30. if(!require_once('functions/twitteroauth.php')){ echo '<strong>Couldn\'t find twitteroauth.php!</strong>'; }
  31. $connection = mts_getConnectionWithhomepage_twitter_access_token($mts_options['homepage_twitter_api_key'], $mts_options['homepage_twitter_api_secret'], $mts_options['homepage_twitter_access_token'], $mts_options['homepage_twitter_access_token_secret']);
  32. $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$mts_options['homepage_twitter_username']."&count=".$mts_options['homepage_twitter_tweet_count']) or die('Couldn\'t retrieve tweets! Wrong username?');
  33. if(!empty($tweets->errors)){
  34. if($tweets->errors[0]->message == 'Invalid or expired token'){
  35. echo '<strong>'.$tweets->errors[0]->message.'!</strong><br />You\'ll need to regenerate it <a href="https://dev.twitter.com/apps" target="_blank">here</a>!';
  36. }else{ echo '<strong>'.$tweets->errors[0]->message.'</strong>'; }
  37. }
  38. if(is_array($tweets)){
  39. for($i = 0;$i <= count($tweets); $i++){
  40. if(!empty($tweets[$i])){
  41. $tweets_array[$i]['created_at'] = $tweets[$i]->created_at;
  42. $tweets_array[$i]['text'] = $tweets[$i]->text;
  43. $tweets_array[$i]['status_id'] = $tweets[$i]->id_str;
  44. }
  45. }
  46. //save tweets to wp option
  47. update_option('mts_twitter_plugin_tweets',serialize($tweets_array));
  48. update_option('mts_twitter_plugin_last_cache_time',time());
  49. echo '<!-- twitter cache has been updated! -->';
  50. }
  51. //convert links to clickable format
  52. }
  53. $mts_twitter_plugin_tweets = maybe_unserialize(get_option('mts_twitter_plugin_tweets'));
  54. if(!empty($mts_twitter_plugin_tweets)){
  55. print '<div class="mts_recent_tweets tweets">';
  56. $fctr = '1';
  57. foreach($mts_twitter_plugin_tweets as $tweet){
  58. if ($mts_options['homepage_twitter_slider'] == '0' && $fctr > 1) continue;
  59. print '<div><span>'.mts_convert_links($tweet['text']).'</span></div>';
  60. $fctr++;
  61. }
  62. print '</div>
  63. <a class="twitter_username" href="http://twitter.com/'.$mts_options['homepage_twitter_username'].'"><span class="fa fa-twitter"></span>'.__('Follow us on Twitter', 'mythemeshop').'</a>';
  64. }
  65. ?>
  66. </div>
  67. </section>
  68. <?php endif; ?>
  69. <?php
  70. } else{
  71. get_template_part( 'home/front-page', $key );
  72. }
  73. }
  74. ?>
  75. <?php get_footer(); ?>