Changeset 1440060
- Timestamp:
- 06/20/2016 12:57:41 PM (10 years ago)
- Location:
- copify/trunk
- Files:
-
- 8 edited
-
.travis.yml (modified) (1 diff)
-
Lib/CopifyApi.php (modified) (10 diffs)
-
Lib/CopifyWordpress.php (modified) (4 diffs)
-
README.md (modified) (1 diff)
-
Test/Lib/CopifyWordpressTest.php (modified) (7 diffs)
-
Views/CopifySettings.php (modified) (1 diff)
-
copify.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
copify/trunk/.travis.yml
r1400273 r1440060 2 2 3 3 php: 4 - 5.3 4 5 - 5.4 5 6 - 5.5 7 - 5.6 8 - 7.0 6 9 7 10 before_script: -
copify/trunk/Lib/CopifyApi.php
r1400273 r1440060 1 1 <?php 2 // 2 // 3 3 // Copify.php 4 4 // php 5 // 5 // 6 6 // Created by Rob Mcvey on 2012-05-11. 7 7 // Copyright 2012 Rob Mcvey. All rights reserved. 8 // 8 // 9 9 class CopifyApi { 10 10 11 11 /** 12 12 * The API URL 13 13 */ 14 14 public $basePath = 'https://sandbox.copify.com/api'; 15 15 16 16 /** 17 17 * The API version 18 18 */ 19 19 public $apiVersion = 'v1'; 20 20 21 21 /** 22 22 * live / sandbox 23 23 */ 24 24 public $mode = 'live'; 25 25 26 26 /** 27 27 * Which country API to use. uk or us 28 28 */ 29 29 public $country = 'uk'; 30 30 31 31 /** 32 32 * Resource path e.g. jobs 33 33 */ 34 public $resource; 34 public $resource; 35 35 36 36 /** 37 37 * Accept format 38 38 */ 39 public $format = 'json'; 39 public $format = 'json'; 40 40 41 41 /** 42 42 * The full URL to the resource e.g. https://www.copify.com/jobs/123.json 43 43 */ 44 public $fullUrl; 44 public $fullUrl; 45 45 46 46 /** 47 47 * URL parameters to append 48 48 */ 49 public $params = ''; 49 public $params = ''; 50 50 51 51 /** 52 52 * The HTTP method to use 53 53 */ 54 public $httpMethod = 'GET'; 54 public $httpMethod = 'GET'; 55 55 56 56 /** … … 58 58 */ 59 59 public $headers = array(); 60 60 61 61 /** 62 62 * Start up … … 64 64 * @return void 65 65 * @author Rob Mcvey 66 * @param string $apiEmail 67 * @param string $apiKey 66 * @param string $apiEmail 67 * @param string $apiKey 68 68 **/ 69 69 public function __construct($apiEmail = null , $apiKey = null) { … … 75 75 if(empty($apiKey) || empty($apiEmail)) { 76 76 throw new InvalidArgumentException('Please set the values for your API key and your email e.g: <pre>$Copify = new Copify("API KEY" , "API EMAIL");</pre>'); 77 } 77 } 78 78 79 79 // Set the default headers for Authorization and User-Agent … … 81 81 $this->headers['User-Agent'] = $apiEmail; 82 82 } 83 83 84 84 /** 85 85 * Sets the full URL … … 91 91 $this->fullUrl = $this->basePath .'/' . $this->apiVersion . '/'. $this->resource . '.' . $this->format . $this->params; 92 92 } 93 93 94 94 /** 95 95 * Get a list of job records (20 per page) … … 115 115 * @return array 116 116 * @author Rob Mcvey 117 * @param int $id 117 * @param int $id 118 118 **/ 119 119 public function jobsView($id = null) { … … 238 238 * @return array 239 239 * @author Rob Mcvey 240 * @param int $id 240 * @param int $id 241 241 **/ 242 242 public function usersView($id =null) { … … 261 261 // Build the URL 262 262 $this->setfullUrl(); 263 263 264 264 // create a curly wurly resource 265 265 $curlyWurly = curl_init($this->fullUrl); 266 266 267 267 // Return the response don't just splurt it out on screen 268 268 curl_setopt($curlyWurly , CURLOPT_RETURNTRANSFER, true); 269 269 270 270 // Return the headers from Copify 271 271 curl_setopt($curlyWurly , CURLOPT_HEADER, false); 272 272 273 273 // Don't hang around forever 274 274 curl_setopt($curlyWurly , CURLOPT_TIMEOUT, 20); 275 275 276 276 // Set the HTTP method (make uppercase just in case) 277 277 $method = strtoupper($this->httpMethod); … … 292 292 curl_setopt($curlyWurly, CURLOPT_SSL_VERIFYPEER, false); 293 293 curl_setopt($curlyWurly, CURLOPT_SSL_VERIFYHOST, false); 294 294 295 295 if(!$response = curl_exec($curlyWurly)) { 296 296 throw new Exception(curl_error($curlyWurly)); 297 } 297 } 298 298 299 299 // Bye bye curly wurly -
copify/trunk/Lib/CopifyWordpress.php
r1400276 r1440060 12 12 * Plugin version 13 13 */ 14 protected $version = '1.2. 0';14 protected $version = '1.2.1'; 15 15 16 16 /** … … 52 52 **/ 53 53 public function CopifySettings() { 54 54 55 try { 56 // All available locales 57 $CopifyAvailableLocales = array( 58 'uk' => 'UK', 59 'us' => 'USA', 60 'au' => 'Australia' 61 ); 62 $CopifyEmail = ''; 63 $CopifyApiKey = ''; 64 $CopifyLocale = ''; 65 $CopifyWPUser = ''; 66 // Get our users for autopublish 67 $wp_users = $this->wordpress('get_users', array()); 55 68 // Get API credentials 56 69 $CopifyLoginDetails = $this->wordpress('get_option', 'CopifyLoginDetails' , false); … … 61 74 $CopifyApiKey = $_POST['CopifyApiKey']; 62 75 $CopifyLocale = $_POST['CopifyLocale']; 63 $CopifyWPUser = $_POST['CopifyWPUser']; 76 77 if (isset($_POST['CopifyWPUser'])) { 78 $CopifyWPUser = $_POST['CopifyWPUser']; 79 } else { 80 $CopifyWPUser = ''; 81 } 82 83 64 84 // Array to save 65 85 $toSave = array( … … 88 108 $CopifyEmail = ''; 89 109 $CopifyApiKey = ''; 90 } 91 // All available locales 92 $CopifyAvailableLocales = array( 93 'uk' => 'UK', 94 'us' => 'USA', 95 'au' => 'Australia', 96 ); 110 $CopifyLocale = ''; 111 $CopifyWPUser = ''; 112 113 } 97 114 // Flash message of some kind? 98 115 if (isset($_GET['flashMessage']) && !empty($_GET['flashMessage'])) { -
copify/trunk/README.md
r1400273 r1440060 9 9 ### Requirements 10 10 11 * PHP >= 5.3 11 12 * WordPress >= 3.2.0 12 13 * PHP cURL extension -
copify/trunk/Test/Lib/CopifyWordpressTest.php
r1400276 r1440060 35 35 36 36 /** 37 * Check dev mode 38 * 39 * @param string $foo Bar 40 * @return void 41 */ 42 public function testDevMode() 43 { 44 $this->assertFalse(COPIFY_DEVMODE); 45 } 46 47 /** 48 * testCopifyRequestFilterTokenMisMatch 49 * 50 * @return void 51 * @author Rob Mcvey 52 **/ 53 public function testCopifyRequestFilterTokenMisMatch() { 54 $this->CopifyWordpress = $this->getMock('CopifyWordpress', array('wordpress', 'outputJson', 'setheader')); 55 $mockVal = array( 56 'CopifyEmail' => 'foo@bar.com', 57 'CopifyApiKey' => '324532452345324', 58 'CopifyLocale' => 'uk', 59 ); 60 $this->CopifyWordpress->expects($this->once()) 61 ->method('wordpress') 62 ->with('get_option', 'CopifyLoginDetails', false) 63 ->will($this->returnValue($mockVal)); 64 $this->CopifyWordpress->expects($this->once()) 65 ->method('outputJson') 66 ->with(array('message' => 'Permission denied')); 67 $this->CopifyWordpress->expects($this->once()) 68 ->method('setheader') 69 ->with('HTTP/1.0 403 Forbidden'); 70 $_GET["copify-action"] = true; 71 $_GET["token"] = 'd0cf87af82e652220087e7613f0332abc1461a0'; 72 $this->CopifyWordpress->CopifyRequestFilter(); 73 } 74 75 /** 37 76 * testCopifySetApiClass 38 77 * … … 110 149 $_POST['CopifyLocale'] = 'au'; 111 150 $this->CopifyWordpress = $this->getMock('CopifyWordpress', array('wordpress')); 112 $this->CopifyWordpress->expects($this->at(0)) 151 $getUsers = array( 152 array('ID' => 1, 'display_name' => 'admin'), 153 array('ID' => 2, 'display_name' => 'dave'), 154 ); 155 $userObject = json_decode(json_encode($getUsers), FALSE); 156 $this->CopifyWordpress->expects($this->at(0)) 157 ->method('wordpress') 158 ->with('get_users', array()) 159 ->will($this->returnValue($userObject)); 160 $this->CopifyWordpress->expects($this->at(1)) 113 161 ->method('wordpress') 114 162 ->with('get_option', 'CopifyLoginDetails', false) … … 118 166 'CopifyApiKey' => '876453456786', 119 167 'CopifyLocale' => 'au', 120 ); 121 $this->CopifyWordpress->expects($this->at(1)) 168 'CopifyWPUser' => '', 169 ); 170 $this->CopifyWordpress->expects($this->at(2)) 171 ->method('wordpress') 172 ->with('add_option', 'CopifyLoginDetails', $toSave) 173 ->will($this->returnValue(true)); 174 $this->CopifyWordpress->CopifySettings(); 175 } 176 177 /** 178 * testCopifySettingsSaveWithUser 179 * 180 * @return void 181 * @author Rob Mcvey 182 **/ 183 public function testCopifySettingsSaveWithUser() { 184 $_POST['CopifyEmail'] = 'hello@newemail.com'; 185 $_POST['CopifyApiKey'] = '876453456786'; 186 $_POST['CopifyLocale'] = 'au'; 187 $_POST['CopifyWPUser'] = 6; 188 $this->CopifyWordpress = $this->getMock('CopifyWordpress', array('wordpress')); 189 $getUsers = array( 190 array('ID' => 1, 'display_name' => 'admin'), 191 array('ID' => 2, 'display_name' => 'dave'), 192 ); 193 $userObject = json_decode(json_encode($getUsers), FALSE); 194 $this->CopifyWordpress->expects($this->at(0)) 195 ->method('wordpress') 196 ->with('get_users', array()) 197 ->will($this->returnValue($userObject)); 198 $this->CopifyWordpress->expects($this->at(1)) 199 ->method('wordpress') 200 ->with('get_option', 'CopifyLoginDetails', false) 201 ->will($this->returnValue(false)); 202 $toSave = array( 203 'CopifyEmail' => 'hello@newemail.com', 204 'CopifyApiKey' => '876453456786', 205 'CopifyLocale' => 'au', 206 'CopifyWPUser' => 6, 207 ); 208 $this->CopifyWordpress->expects($this->at(2)) 122 209 ->method('wordpress') 123 210 ->with('add_option', 'CopifyLoginDetails', $toSave) … … 142 229 'CopifyLocale' => 'uk', 143 230 ); 144 $this->CopifyWordpress->expects($this->at(0)) 231 $getUsers = array( 232 array('ID' => 1, 'display_name' => 'admin'), 233 array('ID' => 2, 'display_name' => 'dave'), 234 ); 235 $userObject = json_decode(json_encode($getUsers), FALSE); 236 $this->CopifyWordpress->expects($this->at(0)) 237 ->method('wordpress') 238 ->with('get_users', array()) 239 ->will($this->returnValue($userObject)); 240 $this->CopifyWordpress->expects($this->at(1)) 145 241 ->method('wordpress') 146 242 ->with('get_option', 'CopifyLoginDetails', false) … … 150 246 'CopifyApiKey' => '876453456786', 151 247 'CopifyLocale' => 'au', 152 ); 153 $this->CopifyWordpress->expects($this->at(1)) 248 'CopifyWPUser' => '' 249 ); 250 $this->CopifyWordpress->expects($this->at(2)) 154 251 ->method('wordpress') 155 252 ->with('update_option', 'CopifyLoginDetails', $toSave) … … 200 297 201 298 /** 202 * testCopifyRequestFilterTokenMisMatch203 *204 * @return void205 * @author Rob Mcvey206 **/207 public function testCopifyRequestFilterTokenMisMatch() {208 $this->CopifyWordpress = $this->getMock('CopifyWordpress', array('wordpress', 'outputJson', 'setheader'));209 $mockVal = array(210 'CopifyEmail' => 'foo@bar.com',211 'CopifyApiKey' => '324532452345324',212 'CopifyLocale' => 'uk',213 );214 $this->CopifyWordpress->expects($this->once())215 ->method('wordpress')216 ->with('get_option', 'CopifyLoginDetails', false)217 ->will($this->returnValue($mockVal));218 $this->CopifyWordpress->expects($this->once())219 ->method('outputJson')220 ->with(array('message' => 'Permission denied'));221 $this->CopifyWordpress->expects($this->once())222 ->method('setheader')223 ->with('HTTP/1.0 403 Forbidden');224 $_GET["copify-action"] = true;225 $_GET["token"] = 'd0cf87af82e652220087e7613f0332abc1461a0';226 $this->CopifyWordpress->CopifyRequestFilter();227 }228 229 /**230 299 * testCopifyRequestFilterCheckToken 231 300 * … … 236 305 $this->CopifyWordpress = $this->getMock('CopifyWordpress', array('wordpress', 'outputJson', 'setheader')); 237 306 $version = $this->CopifyWordpress->getVersion(); 238 $this->assertEquals('1.2. 0', $version);307 $this->assertEquals('1.2.1', $version); 239 308 $mockVal = array( 240 309 'CopifyEmail' => 'foo@bar.com', -
copify/trunk/Views/CopifySettings.php
r1400273 r1440060 62 62 <label for="CopifyWPUser">Auto-publish author <i>(optional)</i><br><small style="color:#ccc;">Posts that go live automatically will be published under this author</small></label> 63 63 <div class="input"> 64 <?php $wp_users = get_users([]); ?>65 64 <select name="CopifyWPUser"> 66 65 <?php -
copify/trunk/copify.php
r1400276 r1440060 4 4 Plugin URI: https://github.com/copify/copify-wordpress 5 5 Description: Automatically publish unique, relevant content every week from Copify's team of professional writers. 6 Version: 1.2. 06 Version: 1.2.1 7 7 Author: Rob McVey 8 8 Author URI: http://uk.copify.com/ -
copify/trunk/readme.txt
r1400276 r1440060 1 1 === Copify === 2 Version: 1.2.0 2 3 Version: 1.2.1 3 4 Contributors: robmcvey 4 5 Tags: blog writers, automatic blogging, post writers, auto blogging, content, copywriting, copywriters, blogging, writers, writing, seo … … 39 40 == Changelog == 40 41 42 <<<<<<< 4159b6e30c12e6fdfd282c4782e3c683e34b2578 43 ======= 44 = 1.2.1 = 45 * Backwards support for PHP 5.3 46 47 >>>>>>> Squashed commit of the following: 41 48 = 1.2.0 = 42 49 * Allows posts that are auto-published to be assigned to a custom user
Note: See TracChangeset
for help on using the changeset viewer.