Plugin Directory

Changeset 1440060


Ignore:
Timestamp:
06/20/2016 12:57:41 PM (10 years ago)
Author:
robmcvey
Message:

fix conflicts

Location:
copify/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • copify/trunk/.travis.yml

    r1400273 r1440060  
    22
    33php:
     4  - 5.3
    45  - 5.4
    56  - 5.5
     7  - 5.6
     8  - 7.0
    69
    710before_script:
  • copify/trunk/Lib/CopifyApi.php

    r1400273 r1440060  
    11<?php
    2 // 
     2//
    33//  Copify.php
    44//  php
    5 // 
     5//
    66//  Created by Rob Mcvey on 2012-05-11.
    77//  Copyright 2012 Rob Mcvey. All rights reserved.
    8 // 
     8//
    99class CopifyApi {
    10    
     10
    1111/**
    1212 * The API URL
    1313 */
    1414    public $basePath = 'https://sandbox.copify.com/api';
    15        
     15
    1616/**
    1717 * The API version
    1818 */
    1919    public $apiVersion = 'v1';
    20        
     20
    2121/**
    2222 * live / sandbox
    2323 */
    2424    public $mode = 'live';
    25    
     25
    2626/**
    2727 * Which country API to use. uk or us
    2828 */
    2929    public $country = 'uk';
    30    
     30
    3131/**
    3232 * Resource path e.g. jobs
    3333 */
    34     public $resource;   
     34    public $resource;
    3535
    3636/**
    3737 * Accept format
    3838 */
    39     public $format = 'json';   
     39    public $format = 'json';
    4040
    4141/**
    4242 * The full URL to the resource e.g. https://www.copify.com/jobs/123.json
    4343 */
    44     public $fullUrl;   
     44    public $fullUrl;
    4545
    4646/**
    4747 * URL parameters to append
    4848 */
    49     public $params = '';   
     49    public $params = '';
    5050
    5151/**
    5252 * The HTTP method to use
    5353 */
    54     public $httpMethod = 'GET'; 
     54    public $httpMethod = 'GET';
    5555
    5656/**
     
    5858 */
    5959    public $headers = array();
    60    
     60
    6161/**
    6262 * Start up
     
    6464 * @return void
    6565 * @author Rob Mcvey
    66  * @param string $apiEmail 
    67  * @param string $apiKey 
     66 * @param string $apiEmail
     67 * @param string $apiKey
    6868 **/
    6969    public function __construct($apiEmail = null , $apiKey = null) {
     
    7575        if(empty($apiKey) || empty($apiEmail)) {
    7676            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        }
    7878
    7979        // Set the default headers for Authorization and User-Agent
     
    8181        $this->headers['User-Agent'] = $apiEmail;
    8282    }
    83        
     83
    8484/**
    8585 * Sets the full URL
     
    9191        $this->fullUrl = $this->basePath .'/' . $this->apiVersion . '/'. $this->resource . '.' . $this->format . $this->params;
    9292    }
    93    
     93
    9494/**
    9595 * Get a list of job records (20 per page)
     
    115115 * @return array
    116116 * @author Rob Mcvey
    117  * @param int $id 
     117 * @param int $id
    118118 **/
    119119    public function jobsView($id = null) {
     
    238238 * @return array
    239239 * @author Rob Mcvey
    240  * @param int $id 
     240 * @param int $id
    241241 **/
    242242    public function usersView($id =null) {
     
    261261        // Build the URL
    262262        $this->setfullUrl();
    263        
     263
    264264        // create a curly wurly resource
    265265        $curlyWurly = curl_init($this->fullUrl);
    266        
     266
    267267        // Return the response don't just splurt it out on screen
    268268        curl_setopt($curlyWurly , CURLOPT_RETURNTRANSFER, true);
    269                
     269
    270270        // Return the headers from Copify
    271271        curl_setopt($curlyWurly , CURLOPT_HEADER, false);
    272        
     272
    273273        // Don't hang around forever
    274274        curl_setopt($curlyWurly , CURLOPT_TIMEOUT, 20);
    275        
     275
    276276        // Set the HTTP method (make uppercase just in case)
    277277        $method = strtoupper($this->httpMethod);
     
    292292        curl_setopt($curlyWurly, CURLOPT_SSL_VERIFYPEER, false);
    293293        curl_setopt($curlyWurly, CURLOPT_SSL_VERIFYHOST, false);
    294        
     294
    295295        if(!$response = curl_exec($curlyWurly)) {
    296296            throw new Exception(curl_error($curlyWurly));
    297         } 
     297        }
    298298
    299299        // Bye bye curly wurly
  • copify/trunk/Lib/CopifyWordpress.php

    r1400276 r1440060  
    1212 * Plugin version
    1313 */
    14     protected $version = '1.2.0';
     14    protected $version = '1.2.1';
    1515
    1616/**
     
    5252 **/
    5353    public function CopifySettings() {
     54
    5455        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());
    5568            // Get API credentials
    5669            $CopifyLoginDetails = $this->wordpress('get_option', 'CopifyLoginDetails' , false);
     
    6174                $CopifyApiKey = $_POST['CopifyApiKey'];
    6275                $CopifyLocale = $_POST['CopifyLocale'];
    63                 $CopifyWPUser = $_POST['CopifyWPUser'];
     76
     77                if (isset($_POST['CopifyWPUser'])) {
     78                    $CopifyWPUser = $_POST['CopifyWPUser'];
     79                } else {
     80                    $CopifyWPUser = '';
     81                }
     82
     83
    6484                // Array to save
    6585                $toSave = array(
     
    88108                $CopifyEmail = '';
    89109                $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            }
    97114            // Flash message of some kind?
    98115            if (isset($_GET['flashMessage']) && !empty($_GET['flashMessage'])) {
  • copify/trunk/README.md

    r1400273 r1440060  
    99### Requirements
    1010
     11* PHP >= 5.3
    1112* WordPress >= 3.2.0
    1213* PHP cURL extension
  • copify/trunk/Test/Lib/CopifyWordpressTest.php

    r1400276 r1440060  
    3535
    3636/**
     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/**
    3776 * testCopifySetApiClass
    3877 *
     
    110149        $_POST['CopifyLocale'] = 'au';
    111150        $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))
    113161            ->method('wordpress')
    114162            ->with('get_option', 'CopifyLoginDetails', false)
     
    118166            'CopifyApiKey' => '876453456786',
    119167            '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))
    122209            ->method('wordpress')
    123210            ->with('add_option', 'CopifyLoginDetails', $toSave)
     
    142229            'CopifyLocale' => 'uk',
    143230        );
    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))
    145241            ->method('wordpress')
    146242            ->with('get_option', 'CopifyLoginDetails', false)
     
    150246            'CopifyApiKey' => '876453456786',
    151247            'CopifyLocale' => 'au',
    152         );
    153         $this->CopifyWordpress->expects($this->at(1))
     248            'CopifyWPUser' => ''
     249        );
     250        $this->CopifyWordpress->expects($this->at(2))
    154251            ->method('wordpress')
    155252            ->with('update_option', 'CopifyLoginDetails', $toSave)
     
    200297
    201298/**
    202  * testCopifyRequestFilterTokenMisMatch
    203  *
    204  * @return void
    205  * @author Rob Mcvey
    206  **/
    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 /**
    230299 * testCopifyRequestFilterCheckToken
    231300 *
     
    236305        $this->CopifyWordpress = $this->getMock('CopifyWordpress', array('wordpress', 'outputJson', 'setheader'));
    237306        $version = $this->CopifyWordpress->getVersion();
    238         $this->assertEquals('1.2.0', $version);
     307        $this->assertEquals('1.2.1', $version);
    239308        $mockVal = array(
    240309            'CopifyEmail' => 'foo@bar.com',
  • copify/trunk/Views/CopifySettings.php

    r1400273 r1440060  
    6262            <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>
    6363            <div class="input">
    64                 <?php $wp_users = get_users([]); ?>
    6564                <select name="CopifyWPUser">
    6665                    <?php
  • copify/trunk/copify.php

    r1400276 r1440060  
    44Plugin URI: https://github.com/copify/copify-wordpress
    55Description: Automatically publish unique, relevant content every week from Copify's team of professional writers.
    6 Version: 1.2.0
     6Version: 1.2.1
    77Author: Rob McVey
    88Author URI: http://uk.copify.com/
  • copify/trunk/readme.txt

    r1400276 r1440060  
    11=== Copify ===
    2 Version: 1.2.0
     2
     3Version: 1.2.1
    34Contributors: robmcvey
    45Tags: blog writers, automatic blogging, post writers, auto blogging, content, copywriting, copywriters, blogging, writers, writing, seo
     
    3940== Changelog ==
    4041
     42<<<<<<< 4159b6e30c12e6fdfd282c4782e3c683e34b2578
     43=======
     44= 1.2.1 =
     45* Backwards support for PHP 5.3
     46
     47>>>>>>> Squashed commit of the following:
    4148= 1.2.0 =
    4249* Allows posts that are auto-published to be assigned to a custom user
Note: See TracChangeset for help on using the changeset viewer.