Changeset 1724186
- Timestamp:
- 09/04/2017 10:28:25 AM (8 years ago)
- Location:
- little-social/trunk
- Files:
-
- 12 edited
-
admin/class-social-admin.php (modified) (18 diffs)
-
little-social-media.php (modified) (4 diffs)
-
social/FacebookConnector.php (modified) (2 diffs)
-
social/InstagramConnector.php (modified) (1 diff)
-
social/SocialConnector.php (modified) (1 diff)
-
social/SocialMediaFactory.php (modified) (7 diffs)
-
social/SocialMediaGetter.php (modified) (4 diffs)
-
social/SocialRepository.php (modified) (6 diffs)
-
social/TwitterConnector.php (modified) (1 diff)
-
social/models/Instagram.php (modified) (2 diffs)
-
social/models/SocialPost.php (modified) (5 diffs)
-
social/models/Tweet.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
little-social/trunk/admin/class-social-admin.php
r1618483 r1724186 1 1 <?php 2 3 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/little-social-media-scheduler.php'; 2 4 3 5 /** … … 122 124 // add settings saved message with the class of "updated" 123 125 add_settings_error('wporg_messages', 'wporg_message', __('Settings Saved', $this->page), 'updated'); 126 127 128 //if settings have been changed - reset the cron with new value 129 $scheduler = new SocialMediaScheduler(); 130 $scheduler->addSocialScheduleEvent(); 131 124 132 } 125 133 … … 255 263 256 264 register_setting("general_social_settings_section", "social_cron_frequency"); 265 register_setting("general_social_settings_section", "days_to_keep_social_posts"); 257 266 258 267 //twitter … … 261 270 register_setting("twitter_settings_section", "social_twitter_username"); 262 271 register_setting("twitter_settings_section", "social_twitter_show_flag"); 272 register_setting("twitter_settings_section", "social_twitter_show_retweet_flag"); 273 register_setting("twitter_settings_section", "social_twitter_show_media_flag"); 274 register_setting("twitter_settings_section", "social_twitter_profile_image"); 263 275 264 276 //facebook … … 267 279 register_setting("facebook_settings_section", "social_facebook_username"); 268 280 register_setting("facebook_settings_section", "social_facebook_show_flag"); 281 register_setting("facebook_settings_section", "social_facebook_show_media_flag"); 282 register_setting("facebook_settings_section", "social_facebook_profile_image"); 269 283 270 284 //instagram … … 274 288 register_setting("instagram_settings_section", "social_instagram_access_token_link"); 275 289 register_setting("instagram_settings_section", "social_instagram_show_flag"); 290 register_setting("instagram_settings_section", "social_instagram_show_media_flag"); 291 register_setting("instagram_settings_section", "social_instagram_profile_image"); 276 292 277 293 //linkedin … … 280 296 register_setting("linkedin_settings_section", "social_linkedin_access_token"); 281 297 register_setting("linkedin_settings_section", "social_linkedin_page_url"); 298 register_setting("linkedin_settings_section", "social_linkedin_show_media_flag"); 299 register_setting("linkedin_settings_section", "social_linkedin_profile_image"); 282 300 283 301 } … … 350 368 'general_social_settings_section_id' 351 369 ); 370 371 add_settings_field( 372 'days_to_keep_social_posts', 373 'Number of days to keep posts in Database', 374 array( $this, 'days_to_keep_social_posts_callback' ), 375 'general_social_settings_section', 376 'general_social_settings_section_id' 377 ); 352 378 353 379 … … 362 388 ); 363 389 390 add_settings_field( 391 'social_facebook_show_media_flag', 392 'Show Media', 393 array( $this, 'social_facebook_show_media_flag_callback' ), 394 'facebook_settings_section', 395 'facebook_settings_section_id' 396 ); 397 364 398 add_settings_field( 365 399 'social_facebook_api_key', … … 386 420 ); 387 421 422 add_settings_field( 423 'social_facebook_profile_image', 424 'Profile Image', 425 array( $this, 'social_facebook_profile_image_callback' ), 426 'facebook_settings_section', 427 'facebook_settings_section_id' 428 ); 429 430 388 431 /* TWITTER Fields */ 389 432 … … 397 440 398 441 add_settings_field( 442 'social_twitter_show_retweet_flag', 443 'Show retweets', 444 array( $this, 'social_twitter_show_retweet_flag_callback' ), 445 'twitter_settings_section', 446 'twitter_settings_section_id' 447 ); 448 449 add_settings_field( 450 'social_twitter_show_media_flag', 451 'Show Media', 452 array( $this, 'social_twitter_show_media_flag_callback' ), 453 'twitter_settings_section', 454 'twitter_settings_section_id' 455 ); 456 457 add_settings_field( 399 458 'social_twitter_api_key', 400 459 'Twitter API', … … 420 479 ); 421 480 422 481 add_settings_field( 482 'social_twitter_profile_image', 483 'Profile Image', 484 array( $this, 'social_twitter_profile_image_callback' ), 485 'twitter_settings_section', 486 'twitter_settings_section_id' 487 ); 423 488 424 489 /* INSTAGRAM fields */ … … 433 498 434 499 add_settings_field( 500 'social_instagram_show_media_flag', 501 'Show Media', 502 array( $this, 'social_instagram_show_media_flag_callback' ), 503 'instagram_settings_section', 504 'instagram_settings_section_id' 505 ); 506 507 add_settings_field( 435 508 'social_instagram_client_id', 436 509 'Client ID', … … 460 533 'Instagram Access Token', 461 534 array( $this, 'social_instagram_access_token_callback' ), 535 'instagram_settings_section', 536 'instagram_settings_section_id' 537 ); 538 539 add_settings_field( 540 'social_instagram_profile_image', 541 'Profile Image', 542 array( $this, 'social_instagram_profile_image_callback' ), 462 543 'instagram_settings_section', 463 544 'instagram_settings_section_id' … … 477 558 478 559 add_settings_field( 560 'social_linkedin_show_media_flag', 561 'Show Media', 562 array( $this, 'social_linkedin_show_media_flag_callback' ), 563 'linkedin_settings_section', 564 'linkedin_settings_section_id' 565 ); 566 567 add_settings_field( 479 568 'social_linkedin_username', 480 569 'LinkedIn Username', … … 499 588 'linkedin_settings_section_id' 500 589 ); 501 590 591 add_settings_field( 592 'social_linkedin_profile_image', 593 'Profile Image', 594 array( $this, 'social_linkedin_profile_image_callback' ), 595 'linkedin_settings_section', 596 'linkedin_settings_section_id' 597 ); 502 598 503 599 } … … 536 632 } 537 633 634 function days_to_keep_social_posts_callback(){ 635 $this->outputInputSetting('days_to_keep_social_posts'); 636 } 637 538 638 public function social_linkedin_show_flag_callback(){ 539 639 $this->outputCheckboxSetting('social_linkedin_show_flag'); … … 615 715 $this->outputCheckboxSetting('social_twitter_show_flag'); 616 716 } 717 718 function social_twitter_show_retweet_flag_callback(){ 719 $this->outputCheckboxSetting('social_twitter_show_retweet_flag'); 720 } 721 722 723 /* 724 Show media callbacks 725 */ 726 727 function social_facebook_show_media_flag_callback(){ 728 $this->outputCheckboxSetting('social_facebook_show_media_flag'); 729 } 730 731 function social_twitter_show_media_flag_callback(){ 732 $this->outputCheckboxSetting('social_twitter_show_media_flag'); 733 } 734 735 function social_instagram_show_media_flag_callback(){ 736 $this->outputCheckboxSetting('social_instagram_show_media_flag'); 737 } 738 739 function social_linkedin_show_media_flag_callback(){ 740 $this->outputCheckboxSetting('social_linkedin_show_media_flag'); 741 } 742 743 744 /* 745 Profile image callbacks 746 */ 747 748 function social_facebook_profile_image_callback(){ 749 $this->outputInputSetting('social_facebook_profile_image'); 750 } 751 752 function social_twitter_profile_image_callback(){ 753 $this->outputInputSetting('social_twitter_profile_image'); 754 } 755 756 function social_instagram_profile_image_callback(){ 757 $this->outputInputSetting('social_instagram_profile_image'); 758 } 759 760 function social_linkedin_profile_image_callback(){ 761 $this->outputInputSetting('social_linkedin_profile_image'); 762 } 763 617 764 618 765 function outputInputSetting($settingName, $classes = ''){ -
little-social/trunk/little-social-media.php
r1659447 r1724186 6 6 * Author: Little Agency 7 7 * Author URI: wearelittle.agency 8 * Version: 1. 0.18 * Version: 1.3.0 9 9 */ 10 10 … … 72 72 require plugin_dir_path( __FILE__ ) . 'social/SocialConnector.php'; 73 73 74 75 74 /** 76 75 * Begins execution of the plugin. … … 91 90 social(); 92 91 93 /*94 function test(){95 $smg = new SocialMediaGetter();96 //$smg->getPostsFromTwitter();97 //$smg->getPostsFromFacebook();98 $smg->getPostsFromLinkedin();99 100 }101 add_action('init','test');*/102 92 103 93 104 / *105 $socialRepo = new SocialRepository();106 $fb = $socialRepo->getSocialModelsFromDb('linkedin','Linkedin');107 echo '<pre>' . var_export($fb[0]->getLinkedinUrl(),true) . '</pre>';die();108 */ 94 // $smg = new SocialMediaGetter(); 95 // $smg->getPostsFromTwitter(); 96 // $smg->getPostsFromFacebook(); 97 // $smg->getPostsFromInstagram(); 98 109 99 110 100 function getSocialPostsByPlatform(){ … … 138 128 139 129 } 140 //var_dump(getSocialPosts());die(); 141 //echo '<pre>' . var_export(getAllSocialPosts(),true) . '</pre>';die(); 130 131 function showTwitterMedia(){ 132 return get_option('social_twitter_show_media_flag'); 133 } 134 135 function showFacebookMedia(){ 136 return get_option('social_facebook_show_media_flag'); 137 } 138 139 function showInstagramMedia(){ 140 return get_option('social_instagram_show_media_flag'); 141 } 142 143 function showLinkedinMedia(){ 144 return get_option('social_linkedin_show_media_flag'); 145 } 146 147 function showRetweets(){ 148 return get_option('social_twitter_show_retweet_flag'); 149 } 150 151 function getProfileImage($platform){ 152 $setting = 'social_'. $platform .'_profile_image'; 153 154 if(!empty($setting) && !is_null($setting)){ 155 return get_option($setting); 156 } 157 158 return ''; 159 } 160 -
little-social/trunk/social/FacebookConnector.php
r1618483 r1724186 7 7 8 8 9 private $limit = 200; 10 private $facebookUrl = 'https://graph.facebook.com/USERNAME/posts?limit='; 9 private $limit = 100; 10 private $facebookUrl = 'https://graph.facebook.com/USERNAME/posts?fields=id,message,created_time,picture,likes,type,permalink_url, 11 source,link,description,from&limit='; 11 12 12 13 public function __construct(){ … … 31 32 32 33 $fbPosts = $this->getLatestPosts($apiUrl,[]); 33 return $this->createFacebookObjectsFromApi($fbPosts->data,"FBPost","facebook"); 34 35 //make sure no errors 36 if(!property_exists($fbPosts, 'error')){ 37 38 foreach($fbPosts->data as $post){ 39 if(property_exists($post, 'message')){ 40 $post->message = $this->removeEmoji($post->message); 41 } 42 } 43 44 return $this->createFacebookObjectsFromApi($fbPosts->data,"FBPost","facebook"); 45 } 46 34 47 } 35 48 -
little-social/trunk/social/InstagramConnector.php
r1618483 r1724186 21 21 $apiUrl = 'https://api.instagram.com/v1/users/self/media/recent/?access_token=' . $accessToken; 22 22 $instaPosts = $this->getLatestPosts($apiUrl,[]); 23 return $this->createInstagramObjectsFromApi($instaPosts->data,"Instagram","instagram"); 24 23 24 //make sure success 25 if($instaPosts->meta->code == 200){ 26 foreach($instaPosts->data as $post){ 27 if(!is_null($post->caption->text)){ 28 $post->caption->text = $this->removeEmoji($post->caption->text); 29 } 30 } 31 return $this->createInstagramObjectsFromApi($instaPosts->data,"Instagram","instagram"); 32 } 25 33 } 26 34 -
little-social/trunk/social/SocialConnector.php
r1618483 r1724186 38 38 return $this->socialMediaFactory->createLinkedinObjectsFromApi($response,$model,$type); 39 39 } 40 40 41 /* 42 Helper function 43 */ 44 //https://stackoverflow.com/questions/43097087/how-to-remove-non-text-chars-from-string-php 45 function removeEmoji($text){ 46 $text=preg_replace('/[^ -\x{2122}]/u','',$text); // no icons 47 $text=trim(preg_replace('/(?<=\s)\s+/','',$text)); // no leading/trailing/multi spaces 48 return $text; 49 } 41 50 42 51 } -
little-social/trunk/social/SocialMediaFactory.php
r1618483 r1724186 29 29 if(strcasecmp('twitter', $type) == 0){ 30 30 $post->setHashtags($responseObj->entities->hashtags); 31 } 32 33 31 32 //image 33 if(property_exists($responseObj->entities, 'media') && isset($responseObj->entities->media[0])){ 34 $post->setContentImage($responseObj->entities->media[0]->media_url_https); 35 } 36 37 if(property_exists($responseObj, 'retweeted_status')){ 38 //was retweeted 39 $post->setRetweeted(true); 40 } 41 42 } 43 44 34 45 //need to convert to unix timestamp so can order properly 35 46 $postDate = $this->convertDateToUnixTimestamp($responseObj->created_at); … … 68 79 $post = new $model; 69 80 $post->setId($responseObj->id); 70 $post->setType($type); 71 72 $post->setLikes($responseObj->likes); 73 $post->setContent($responseObj->message); 74 $post->setLink($responseObj->link); 75 $post->setPostType($responseObj->type); 76 $post->setVideo($responseObj->source); 77 //$post->setDate($responseObj->created_time); 81 82 if(property_exists($responseObj, 'type')){ 83 $post->setType($type); 84 $post->setPostType($responseObj->type); 85 } 86 87 if(property_exists($responseObj, 'likes')){ 88 $post->setLikes($responseObj->likes); 89 } 90 91 if(property_exists($responseObj, 'message')){ 92 $post->setContent($responseObj->message); 93 } 94 95 if(property_exists($responseObj, 'link')){ 96 $post->setLink($responseObj->link); 97 } 98 99 if(property_exists($responseObj, 'source')){ 100 $post->setVideo($responseObj->source); 101 } 102 78 103 79 104 //need to convert to unix timestamp so can order properly … … 81 106 $post->setDate($postDate); 82 107 83 if( !is_null($responseObj->description)){108 if(property_exists($responseObj, 'description')){ 84 109 $post->setDescription($responseObj->description); 85 110 } … … 88 113 $post->setUserScreenName($responseObj->from->name); 89 114 $post->setUserId($responseObj->from->id); 90 $post->setProfilePic($responseObj->picture); 91 115 116 if(property_exists($responseObj, 'picture')){ 117 $post->setProfilePic($responseObj->picture); 118 } 119 92 120 93 121 … … 153 181 $post->setUserId($responseObj->user->id); 154 182 $post->setUserName($responseObj->user->username); 155 $post->setUserUrl($responseObj->user->url); 183 if(!is_null($responseObj->user)){ 184 if(property_exists($responseObj->user, 'url')){ 185 $post->setUserUrl($responseObj->user->url); 186 } 187 } 156 188 $post->setLikes($responseObj->likes); 157 189 $post->setProfilePic($responseObj->user->profile_picture); … … 218 250 } 219 251 252 if(array_key_exists ( 'contentImage' , $postMeta ) && isset($postMeta['contentImage'][0])){ 253 $model->setContentImage($postMeta['contentImage'][0]); 254 } 255 220 256 if(array_key_exists ( 'date' , $postMeta ) && isset($postMeta['date'][0])){ 221 257 $model->setDate($postMeta['date'][0]); … … 256 292 if(array_key_exists ( 'profile_pic' , $postMeta ) && isset($postMeta['profile_pic'][0])){ 257 293 $model->setProfilePic($postMeta['profile_pic'][0]); 294 } 295 296 /* 297 Twitter 298 */ 299 300 if(array_key_exists ( 'retweeted' , $postMeta ) && isset($postMeta['retweeted'][0])){ 301 $model->setRetweeted($postMeta['retweeted'][0]); 258 302 } 259 303 -
little-social/trunk/social/SocialMediaGetter.php
r1618483 r1724186 26 26 $twitterConnector = new TwitterConnector(); 27 27 $posts = $twitterConnector->getLatestTweets(); 28 $this->insertPostsToDb($posts); 28 if(!is_null($posts)){ 29 $this->insertPostsToDb($posts); 30 } 29 31 } 30 32 } … … 35 37 $fbConnector = new FacebookConnector(); 36 38 $posts = $fbConnector->getLatestFbPosts(); 37 $this->insertPostsToDb($posts); 39 if(!is_null($posts)){ 40 $this->insertPostsToDb($posts); 41 } 38 42 } 39 43 } … … 43 47 $instaConnector = new InstagramConnector(); 44 48 $posts = $instaConnector->getLatestInstaPosts(); 45 $this->insertPostsToDb($posts,'instagram'); 49 if(!is_null($posts)){ 50 $this->insertPostsToDb($posts,'instagram'); 51 } 46 52 } 47 53 } … … 52 58 $linkedInConnector = new LinkedinConnector(); 53 59 $posts = $linkedInConnector->getLatestLinkedInPosts(); 54 $this->insertPostsToDb($posts,'linkedin'); 60 if(!is_null($posts)){ 61 $this->insertPostsToDb($posts,'linkedin'); 62 } 55 63 } 56 64 } -
little-social/trunk/social/SocialRepository.php
r1618483 r1724186 1 1 <?php 2 2 3 require_once( ABSPATH . "wp-includes/pluggable.php" ); 3 4 require_once( ABSPATH . 'wp-admin/includes/post.php' ); 5 require plugin_dir_path( __FILE__ ) . 'Helpers.php'; 4 6 5 7 class SocialRepository { … … 7 9 private $postType; 8 10 private $socialMediaFactory; 11 private $helpers; 9 12 10 13 public function __construct(){ 11 14 $this->postType = 'little_social'; 12 15 $this->socialMediaFactory = new SocialMediaFactory(); 16 $this->helpers = new Helpers(); 13 17 } 14 18 … … 120 124 $posts = $this->getAllSocialPosts(); 121 125 } 126 127 foreach($posts as $post){ 128 $id = $post->ID; 129 $date = get_post_meta( $id, 'date'); 130 131 if(isset($date[0])){ 132 $this->deleteIfOlderThanThreshold($id,$date[0]); 133 } 134 135 } 122 136 123 137 return $this->socialMediaFactory->createSocialObjectsFromDB($posts,$model); … … 222 236 update_post_meta($id, 'comments', $socialPost->getComments()); 223 237 238 $this->deleteIfOlderThanThreshold($id,$socialPost->getDate()); 224 239 225 240 }catch(Exception $e){ … … 248 263 return $id; 249 264 } 265 266 public function deleteIfOlderThanThreshold($id, $date){ 267 $deletePropertyRes = $this->helpers->checkIfSocialPostOlderThanKeepThreshold($date); 268 269 if($deletePropertyRes){ 270 wp_delete_post( $id , true ); 271 } 272 } 273 274 // public function checkIfSocialPostOlderThanKeepThreshold($socialPostDate){ 275 // $isOlderThanThreshold = false; 276 277 // $numberOfDays = get_option('days_to_keep_social_posts'); 278 279 // if(empty($numberOfDays) || is_null($numberOfDays)){ 280 // return false; 281 // } 282 283 // $now = new DateTime(); 284 285 // $lastUpdatedFormatted = date('Y-m-d H:i:s',$socialPostDate); 286 // $last = new DateTime($lastUpdatedFormatted); 287 288 // if($last->diff($now)->days > $numberOfDays) { 289 // $isOlderThanThreshold = true; 290 // } 291 292 // return $isOlderThanThreshold; 293 // } 250 294 251 295 public function addSocialPost($socialPost){ … … 302 346 if(strcasecmp($platform, 'twitter') == 0){ 303 347 update_post_meta($id, 'hashtags', $socialPost->getHashtags()); 304 } 348 update_post_meta($id, 'contentImage', $socialPost->getContentImage()); 349 update_post_meta($id, 'retweeted', $socialPost->getRetweeted()); 350 } 351 352 $this->deleteIfOlderThanThreshold($id,$socialPost->getDate()); 305 353 306 354 }catch(Exception $e){ -
little-social/trunk/social/TwitterConnector.php
r1618483 r1724186 54 54 $tweets = $this->getLatestPosts($apiUrl,$args); 55 55 foreach($tweets as $tweet){ 56 //echo '<pre>' . var_export($tweet->created_at) . '</pre>';56 $tweet->text = $this->removeEmoji($tweet->text); 57 57 } 58 //die();59 58 return $this->createSocialObjects($tweets,"Tweet","twitter"); 60 59 -
little-social/trunk/social/models/Instagram.php
r1659441 r1724186 111 111 $hours = $diff->h; 112 112 113 if($hours < =2){113 if($hours < 2){ 114 114 $age = $hours . ' hour ago'; 115 115 }else{ … … 123 123 $days = $diff->days; 124 124 125 if($days < =2){125 if($days < 2){ 126 126 $age = $days . ' day ago'; 127 127 }else{ -
little-social/trunk/social/models/SocialPost.php
r1659441 r1724186 15 15 protected $profilePic; 16 16 protected $description; 17 protected $contentImage; 17 18 18 19 public function setId($id){ … … 58 59 public function setProfilePic($profilePic){ 59 60 $this->profilePic = $profilePic; 61 } 62 63 public function setContentImage($contentImage){ 64 $this->contentImage = $contentImage; 60 65 } 61 66 … … 108 113 } 109 114 115 public function getContentImage(){ 116 return $this->contentImage; 117 } 118 110 119 public function getDescription(){ 111 120 return $this->description; … … 145 154 $hours = $diff->h; 146 155 147 if($hours < =2){156 if($hours < 2){ 148 157 $age = $hours . ' hour ago'; 149 158 }else{ … … 157 166 $days = $diff->days; 158 167 159 if($days < =2){168 if($days < 2){ 160 169 $age = $days . ' day ago'; 161 170 }else{ -
little-social/trunk/social/models/Tweet.php
r1618483 r1724186 6 6 7 7 protected $hashtags; 8 protected $retweeted = false; 8 9 9 10 public function setHashtags($hashtags){ … … 13 14 public function getHashtags(){ 14 15 return $this->hashtags; 16 } 17 18 public function setRetweeted($retweeted){ 19 $this->retweeted = $retweeted; 20 } 21 22 public function getRetweeted(){ 23 return $this->retweeted; 15 24 } 16 25 … … 24 33 return 'https://twitter.com/' . $screenname; 25 34 } 26 27 /*28 public function daysOld(){29 30 $age;31 32 $diff = 0;33 if(!is_null($this->getDate())){34 $postDate = new DateTime($this->getDate());35 $now = new DateTime();36 37 $diff = date_diff($now, $postDate);38 39 $days = $diff->days;40 41 if($diff->days == 0){42 43 if($diff->h == 0){44 //minutes45 $age = $diff->i . ' minutes ago';46 }else{47 //hours48 $age = $diff->h . ' hours ago';49 }50 51 }else{52 //days53 $age = $diff->days . ' days ago';54 }55 56 }57 58 return $age;59 }*/60 35 }
Note: See TracChangeset
for help on using the changeset viewer.