├── .gitignore ├── wp-forrst-posts ├── forrstdata.php ├── screenshot-1.png ├── readme.txt ├── caching.php └── index.php └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.log -------------------------------------------------------------------------------- /wp-forrst-posts/forrstdata.php: -------------------------------------------------------------------------------- 1 | //this file is intentially blank, cached data will be stored here when first ran. -------------------------------------------------------------------------------- /wp-forrst-posts/screenshot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dcblogdev/WP-Forrst-Posts/master/wp-forrst-posts/screenshot-1.png -------------------------------------------------------------------------------- /wp-forrst-posts/readme.txt: -------------------------------------------------------------------------------- 1 | === WP Forrst Posts === 2 | Contributors: daveismyname 3 | Tags: Forrst Plugin 4 | Requires at least: 3.0 5 | Tested up to: 3.4.1 6 | License: GPLv2 or later 7 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 8 | 9 | Display your 25 latest Forrst (public) posts. 10 | 11 | == Description == 12 | 13 | WP Forrst Posts allows you to display your 25 latest Forrst (public) posts using the Forrst API. 14 | 15 | The posts from Forrst are cached to avoid any API limits. The cached posts are stored in a file called forrstdata.php this file is only used to read data that has been cached. 16 | 17 | == Installation == 18 | 19 | 1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory 20 | 2. Activate the plugin through the 'Plugins' menu in WordPress 21 | 3. Enter your Forrst username on the options page in settings/WP Forrst Posts 22 | 4. Place [wp_forrst_posts] in the page you want the posts to be displayed 23 | 24 | == Frequently Asked Questions == 25 | 26 | = I don't see any posts = 27 | 28 | Make sure you have saved your username in the plugin options page and it is correct. 29 | 30 | = Some of my posts are missing = 31 | 32 | Only posts marked as public will be displayed. 33 | 34 | == Screenshots == 35 | 36 | 1. screenshot-1.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | WP Forrst Posts 2 | ====== 3 | 4 | Description 5 | ------ 6 | WP Forrst Posts allows you to display your 25 latest Forrst (public) posts using the Forrst API. 7 | 8 | The posts from Forrst are cached to avoid any API limits. The cached posts are stored in a file called forrstdata.php this file is only used to read data that has been cached. 9 | 10 | Installation 11 | ------ 12 | 1. Upload `wp-forrst-posts` folder to the `/wp-content/plugins/` directory. 13 | 2. Activate the plugin through the `Plugins` menu in WordPress. 14 | 3. Enter your Forrst username on the options page in `settings/WP Forrst Posts`. 15 | 4. Place `[wp_forrst_posts]` in the page you want the posts to be displayed. 16 | 17 | Frequently Asked Questions 18 | ------ 19 | ### I don't see any posts 20 | 21 | Make sure you have saved your username in the plugin options page and it is correct. 22 | 23 | ### Some of my posts are missing 24 | 25 | Only posts marked as public will be displayed. 26 | 27 | Manifest 28 | ------ 29 | Contributors: [David Carr](https://github.com/daveismyname), [Stefan Cosma](https://github.com/stefanbc) 30 | 31 | Requires Wordpress at least: 3.0 32 | 33 | Tested up to: 3.4.1 34 | 35 | License: GPLv2 or later 36 | 37 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 38 | -------------------------------------------------------------------------------- /wp-forrst-posts/caching.php: -------------------------------------------------------------------------------- 1 | 0 && strlen($apiURI) > 0) { 15 | 16 | //set the local file path and api path 17 | $this->filePath = $filePath; 18 | $this->apiURI = $apiURI; 19 | 20 | //does the file need to be updated? 21 | if ($this->checkForRenewal()) { 22 | 23 | //get the data you need 24 | $data = $this->getExternalInfo(); 25 | 26 | //save the data to your file 27 | $this->saveFile($data); 28 | 29 | return true; 30 | } else { 31 | //no need to update the file 32 | return true; 33 | } 34 | 35 | } else { 36 | echo "No file path and / or api URI specified."; 37 | return false; 38 | } 39 | } 40 | 41 | function checkForRenewal() { 42 | 43 | 44 | //set the caching time (in seconds) 45 | $cachetime = (3600);//1 hour 46 | 47 | //get the file time 48 | $filetimemod = getlastmod($this->filePath) + $cachetime; 49 | 50 | //if the renewal date is smaller than now, return true; else false (no need for update) 51 | if ($filetimemod < time()) { 52 | //return true; 53 | } else { 54 | //return false; 55 | } 56 | return true; 57 | } 58 | 59 | function getExternalInfo() { 60 | 61 | //get remote data 62 | $resp = wp_remote_get( $this->apiURI ); 63 | 64 | //if http status code is equal to 200 carry on otherwise return false 65 | if ( 200 == $resp['response']['code'] ) { 66 | //get the returned data 67 | $body = $resp['body']; 68 | //detcode the json object 69 | $data = json_decode($body, true); 70 | return $data; 71 | } else { 72 | return false; 73 | } 74 | 75 | } 76 | 77 | function saveFile($data) { 78 | 79 | //save the data to the filePath if file cannot be opened kill the script and show an error 80 | $fp = fopen($this->filePath, 'w+')or die('cannot open file'); 81 | fwrite($fp, base64_encode(serialize($data))); 82 | fclose($fp); 83 | 84 | 85 | 86 | } 87 | 88 | } 89 | ?> 90 | -------------------------------------------------------------------------------- /wp-forrst-posts/index.php: -------------------------------------------------------------------------------- 1 | register_settings_and_fields(); 40 | $this->options = get_option('wp_forrst_posts'); 41 | } 42 | 43 | public function add_menu_page(){ 44 | add_options_page(self::plugin_name, self::plugin_name, 'administrator', __FILE__, array('wp_forrst_posts', 'display_options_page')); 45 | } 46 | 47 | public function display_options_page(){ 48 | ?> 49 | 50 |
51 | 52 | 53 |

54 |

To display your Forrst posts enter [wp_forrst_posts] on your desired page.

55 | 56 |
57 | 58 | 59 | 60 |

61 | 62 |

63 |
64 | 65 | 66 |
67 | options[username].'" />'; 83 | } 84 | 85 | } 86 | 87 | add_action('admin_menu', 'WP_Forrst_Options'); 88 | add_action('admin_init', 'WP_Forrst_Init'); 89 | 90 | function WP_Forrst_Options(){ 91 | WP_Forrst_Posts::add_menu_page(); 92 | } 93 | 94 | function WP_Forrst_Init(){ 95 | new WP_Forrst_Posts(); 96 | } 97 | 98 | //add shortcode to its hook. 99 | add_shortcode('wp_forrst_posts','WP_Forrst_Load_Posts'); 100 | 101 | //function to get the file contents from the forrstdata.php file using curl 102 | function curl_file_get_contents($url){ 103 | $ch = curl_init(); 104 | curl_setopt($ch, CURLOPT_URL, $url); 105 | curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 106 | $data = curl_exec($ch); 107 | curl_close($ch); 108 | return $data; 109 | } 110 | 111 | //function to load all posts call by a shortcode of [forrst_posts] 112 | function WP_Forrst_Load_Posts(){ 113 | 114 | require('caching.php'); 115 | 116 | $options = get_option('wp_forrst_posts'); 117 | $username = $options['username']; 118 | 119 | //initalise object pass location of file to store the data and the resource to call, forrst with the username specified in the plugin options 120 | //make sure username is not empty. 121 | if($username !=''){ 122 | //cache data if not already stored 123 | $caching = new Caching(WP_PLUGIN_DIR.'/wp-forrst-posts/forrstdata.php','https://forrst.com/api/v2/users/posts?username='.$username); 124 | 125 | //read data 126 | $fromfile = curl_file_get_contents(WP_PLUGIN_URL.'/wp-forrst-posts/forrstdata.php'); 127 | 128 | //unserialise data 129 | $data = unserialize(base64_decode($fromfile)); 130 | 131 | //if there is data to work with 132 | if(!empty($data)) 133 | { 134 | 135 | //count number of items in array 136 | $data_count = count($data['resp']) -1; 137 | 138 | //loop through array items 139 | for($i = 0; $i <= $data_count; $i++){ 140 | ?> 141 | 142 | 143 |
144 |

145 | 146 | '; 149 | } 150 | ?> 151 | 152 | 153 | 154 |
155 |
156 |

157 | Date: 158 | | Comments: Comments 159 | | Categories: 160 | 161 | ' . $tag . ', '; 166 | } 167 | ?> 168 | 169 |

170 |
171 |
172 |
173 | 174 | 175 | 176 | Continue Reading and comment on Forrst → 177 |
178 | 179 | 180 | Could not load data!

'; 185 | } 186 | } 187 | 188 | } 189 | 190 | 191 | ?> 192 | --------------------------------------------------------------------------------