Plugin Directory

Changeset 1004461


Ignore:
Timestamp:
10/09/2014 12:41:02 PM (11 years ago)
Author:
robmcvey
Message:

Squashed commit of the following:

commit 60564f76003e24271604ced5ee16669752499433
Author: Rob McVey <robmcvey@…>
Date: Thu Oct 9 13:36:27 2014 +0100

Version 1.0.8

commit 99e53af0f8e87a3573bc9295b49527c144fe0971
Author: Rob McVey <robmcvey@…>
Date: Thu Oct 9 13:32:28 2014 +0100

Use select instead of buttons:

commit cc3feeacafaa64f9588bd71706a78dd18dcc1332
Author: Rob McVey <robmcvey@…>
Date: Thu Oct 9 13:23:32 2014 +0100

Cherry pick CSS from chrisgreen1993:issue-5

commit 786898cfcc48bad3a6018580a9f9adbaab911eed
Author: Rob McVey <robmcvey@…>
Date: Thu Oct 9 13:22:04 2014 +0100

Cherry pick CopifyViewJob from chrisgreen1993:issue-5

commit 175df54b5715c15d67dcd369223bb114a2493361
Author: Rob McVey <robmcvey@…>
Date: Thu Oct 9 13:16:13 2014 +0100

Cherry pick tests from chrisgreen1993:issue-5

commit fb5fe4d4d3da6f5298c1235ce414735f0d041eea
Author: Rob McVey <robmcvey@…>
Date: Thu Oct 9 13:10:18 2014 +0100

Cherry pick CopifyWordpress.php

from chrisgreen1993:issue-5

Location:
copify/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • copify/trunk/Lib/CopifyWordpress.php

    r1004398 r1004461  
    1212 * Plugin version
    1313 */
    14     protected $version = '1.0.7';
     14    protected $version = '1.0.8';
    1515
    1616/**
     
    252252        try {
    253253            if (empty($_POST)) {
    254                 throw new Exceptioon('POST request required');
     254                throw new Exception('POST request required');
    255255            }
    256256            // Initialise Copify API class
     
    406406        try {
    407407            if (empty($_POST)) {
    408                 throw new Exceptioon('POST request required');
     408                throw new Exception('POST request required');
    409409            }
    410410            // Initialise Copify API class
     
    412412            // Get the job id from the post data
    413413            $job_id = $_POST['job_id'];
     414            $post_type = $_POST['post_type'];
     415            if (!in_array($post_type, array('post', 'page'))) {
     416                throw new Exception('Post type must be either post or page');
     417            }
    414418            // Get the job record from API
    415419            $job = $this->Api->jobsView($job_id);
     
    420424                    'post_content' => $job['copy'],
    421425                    'post_status' => 'draft',
    422                     //'post_type' => [ 'post' | 'page' | 'link' | 'nav_menu_item' | 'custom_post_type' ]
     426                    'post_type' => $post_type,
    423427                );
    424428                $this->CopifyAddToPosts($job_id, $newPost);
     
    426430            // Build the success response
    427431            $response['status'] = 'success';
    428             $response['response'] = $result;
    429             $response['message'] = 'Job Moved to drafts';
     432            $response['response'] = true;
     433            $response['message'] = 'Order moved to drafts';
    430434            return $this->outputJson($response);
    431435        }   
     
    451455        try {
    452456            if (empty($_POST)) {
    453                 throw new Exceptioon('POST request required');
     457                throw new Exception('POST request required');
    454458            }
    455459            // Get the thingy
  • copify/trunk/Test/Lib/CopifyWordpressTest.php

    r1004398 r1004461  
    236236        $this->CopifyWordpress = $this->getMock('CopifyWordpress', array('wordpress', 'outputJson', 'setheader'));
    237237        $version = $this->CopifyWordpress->getVersion();
    238         $this->assertEquals('1.0.7', $version);
     238        $this->assertEquals('1.0.8', $version);
    239239        $mockVal = array(
    240240            'CopifyEmail' => 'foo@bar.com',
     
    14661466        $this->assertEquals($expected, $result);
    14671467    }
     1468   
     1469/**
     1470 * Tests that CopifyMoveToDrafts does the correct stuff when the job isn't already in the database
     1471 *
     1472 * @author Chris Green
     1473 **/
     1474    public function testCopifyMoveToDraftNotExist() {
     1475        // Mock a load of stuff
     1476        $_POST['job_id'] = '186';
     1477        $_POST['post_type'] = 'post';
     1478        $this->CopifyWordpress = $this->getMock('CopifyWordpress', array('wordpress', 'outputJson', 'CopifySetApiClass', 'CopifyJobIdExists', 'CopifyAddToPosts'));
     1479        $this->CopifyWordpress->Api = $this->getMock('Api', array('jobsView'), array('foo@bar.com', '324532452345324'));
     1480        // Job we want to post
     1481        $job = array(
     1482            'id' => 186,
     1483            'name' => 'order name',
     1484            'copy' => 'some copy'
     1485        );
     1486        // The post
     1487        $new_post = array(
     1488            'post_title' => 'order name',
     1489            'post_content' => 'some copy',
     1490            'post_status' => 'draft',
     1491            'post_type' => 'post'
     1492        );
     1493        // Correct response
     1494        $response = array(
     1495            'status' => 'success',
     1496            'message' => 'Order moved to drafts',
     1497            'response' => true,
     1498        );
     1499
     1500        $this->CopifyWordpress->expects($this->once())
     1501            ->method('CopifySetApiClass');
     1502
     1503        $this->CopifyWordpress->Api->expects($this->once())
     1504            ->method('jobsView')
     1505            ->with($this->equalTo('186'))
     1506            ->will($this->returnValue($job));
     1507
     1508        $this->CopifyWordpress->expects($this->once())
     1509            ->method('CopifyJobIdExists')
     1510            ->with($this->equalTo('186'))
     1511            ->will($this->returnValue(false)); // Job doesn't exist in db
     1512
     1513        $this->CopifyWordpress->expects($this->once())
     1514            ->method('CopifyAddToPosts')
     1515            ->with($this->equalTo(186), $this->equalTo($new_post));
     1516
     1517        $this->CopifyWordpress->expects($this->once())
     1518            ->method('outputJson')
     1519            ->with($this->equalTo($response));
     1520
     1521        $this->CopifyWordpress->CopifyMoveToDrafts();
     1522    }
     1523
     1524/**
     1525 * Tests that CopifyMoveToDrafts returns correct JSON when there is no POST data
     1526 *
     1527 * @author Chris Green
     1528 **/
     1529    public function testCopifyMoveToDraftNoPost() {
     1530        // Mock a load of stuff
     1531        $_POST = array();
     1532        $this->CopifyWordpress = $this->getMock('CopifyWordpress', array('wordpress', 'outputJson', 'CopifySetApiClass', 'CopifyJobIdExists', 'CopifyAddToPosts'));
     1533        $this->CopifyWordpress->Api = $this->getMock('Api', array('jobsView'), array('foo@bar.com', '324532452345324'));
     1534        // Correct response
     1535        $response = array(
     1536            'status' => 'error',
     1537            'message' => 'POST request required',
     1538            'response' => '',
     1539        );
     1540
     1541        $this->CopifyWordpress->expects($this->once())
     1542            ->method('outputJson')
     1543            ->with($this->equalTo($response));
     1544
     1545        $this->CopifyWordpress->CopifyMoveToDrafts();
     1546    }
     1547
     1548/**
     1549 * Tests that CopifyMoveToDrafts returns correct JSON when the post type is incorrect
     1550 *
     1551 * @author Chris Green
     1552 **/
     1553    public function testCopifyMoveToDraftWrongPostType() {
     1554        // Mock a load of stuff
     1555        $_POST['job_id'] = 186;
     1556        $_POST['post_type'] = 'hello';
     1557        $this->CopifyWordpress = $this->getMock('CopifyWordpress', array('wordpress', 'outputJson', 'CopifySetApiClass', 'CopifyJobIdExists', 'CopifyAddToPosts'));
     1558        $this->CopifyWordpress->Api = $this->getMock('Api', array('jobsView'), array('foo@bar.com', '324532452345324'));
     1559        // Correct response
     1560        $response = array(
     1561            'status' => 'error',
     1562            'message' => 'Post type must be either post or page',
     1563            'response' => '',
     1564        );
     1565
     1566        $this->CopifyWordpress->expects($this->once())
     1567            ->method('outputJson')
     1568            ->with($this->equalTo($response));
     1569
     1570        $this->CopifyWordpress->CopifyMoveToDrafts();
     1571    }
    14681572
    14691573}
  • copify/trunk/Views/CopifyViewJob.php

    r1004398 r1004461  
    150150            <?php if (!empty($job['copy']) && $job['job_status_id'] == 4 && !$CopifyJobIsPostAlready) : ?>
    151151                <span class="CopifyButton CopifyGreen CopifyMoveToDrafts">Move to Wordpress</span>
    152                 <form style="display:none;">
    153                     <input type="hidden" id="CopifyApproveJobIdHidden" value="<?php echo $job['id']; ?>" name="job_id">
     152                <form id="CopifyDraftsForm" style="display:none;">
     153                    <input type="hidden" id="CopifyDraftsJobIdHidden" value="<?php echo $job['id']; ?>" name="job_id">
     154                    <input type="hidden" id="CopifyDraftsPostTypeHidden" value="post" name="post_type">
    154155                </form>
    155                 <span class="CopifyConfirmSaving" id="CopifyConfirmSaving" style="display:none;">&nbsp;</span>
     156                <!--<span class="CopifyConfirmSaving" id="CopifyConfirmSaving" style="display:none;">&nbsp;</span>-->
     157               
     158                <!-- Modal -->
     159                <div id="CopifyDraftsModal" class="modal" style="display:none;">   
     160                    <div class="modal-header">
     161                        <button data-dismiss="modal" class="close" type="button">×</button>
     162                        <h3>Move to...</h3>
     163                    </div>
     164                    <div class="modal-body">
     165                        <select id="CopifyDraftsPostTypeSelect" class="CopifyDraftsPostTypeSelect">
     166                            <option value="post">Posts</option>
     167                            <option value="page">Pages</option>
     168                        </select>
     169                    </div>
     170                    <div class="modal-footer">
     171                        <span data-dismiss="modal" class="CopifyButton" >Cancel</span>
     172                        <span class="CopifyButton CopifyGreen" id="CopifyConfirmToDrafts">Move to Drafts</span>
     173                        <span class="CopifyConfirmSaving" id="CopifyConfirmSaving" style="display:none;">&nbsp;</span>
     174                    </div>
     175                </div>
    156176            <?php endif; ?>
    157177           
     
    431451    });
    432452   
     453    // Show move to drafts modal
     454    jQuery('.CopifyMoveToDrafts').click(function() {
     455        jQuery('#CopifyDraftsModal').modal({
     456            show: true
     457        });
     458    });
     459   
     460    // Set the post type and css
     461    jQuery('#CopifyDraftsPostTypeSelect').change(function() {
     462        var post_type = jQuery(this).val();
     463        jQuery('#CopifyDraftsPostTypeHidden').attr('value', post_type);
     464    });
     465   
    433466    // Move an already approved job to drafts
    434     jQuery('.CopifyMoveToDrafts').click(function() {
     467    jQuery('#CopifyConfirmToDrafts').click(function() {
    435468       
    436469        jQuery(this).hide();
    437470        jQuery('#CopifyConfirmSaving').show();
    438        
    439         var job_id = jQuery('#CopifyApproveJobIdHidden').val();
     471
     472        var job_id = jQuery('#CopifyDraftsJobIdHidden').val();
     473        var post_type = jQuery('#CopifyDraftsPostTypeHidden').val();
    440474       
    441475        var job = {
    442476            job_id: job_id,
     477            post_type: post_type,
    443478            action: 'CopifyMoveToDrafts'
    444479        };
     
    451486                if(data.status == 'success') {
    452487                    // OK
     488                    jQuery('#CopifyConfirmToDrafts').hide();
     489                    jQuery('#CopifyConfirmSaving').hide();
    453490                    window.location.href = window.location.href + '&flashMessage=Order+moved+to+Drafts';
    454491                } else {
  • copify/trunk/copify.php

    r1004398 r1004461  
    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.0.7
     6Version: 1.0.8
    77Author: Rob McVey
    88Author URI: http://uk.copify.com/
  • copify/trunk/css/Copify.css

    r1004398 r1004461  
    344344}
    345345
     346/* Move to drafts modal and buttons inside */
     347.CopifyPage #CopifyDraftsModal .modal-body {
     348    padding-top: 15px;
     349    text-align: center;
     350}
     351
     352.CopifyPage .CopifyDraftsPostTypeSelect {
     353    width:100%;
     354}
     355
    346356.CopifyPage  ::-webkit-input-placeholder {
    347     color:    #999;
     357    color: #999;
    348358    font-style:italic;
    349359}
    350360.CopifyPage  :-moz-placeholder {
    351     color:    #999;
     361    color: #999;
    352362    font-style:italic;
    353363}
  • copify/trunk/readme.txt

    r1004398 r1004461  
    11=== Copify ===
    2 Version: 1.0.7
     2Version: 1.0.8
    33Contributors: robmcvey
    44Tags: blog writers, automatic blogging, post writers, auto blogging, content, copywriting, copywriters, blogging, writers, writing, seo
     
    3939== Changelog ==
    4040
     41= 1.0.8 =
     42* When moving an already approved order to drafts, offer selection of "Post" or "Page"
     43
     44= 1.0.7 =
     45* Allows user to choose to publish blog with the supplied royalty free image (Blog package customers only)
     46
    4147= 1.0.6 =
    4248* Fixes issue with other plugins calling methods in wp-admin/includes/plugin.php such as is_plugin_active()
Note: See TracChangeset for help on using the changeset viewer.