WordPress.org

Plugin Directory

Changeset 529259


Ignore:
Timestamp:
04/09/12 20:43:02 (2 years ago)
Author:
ldebrouwer
Message:

Version 0.3.1. See changelog for a list of improvements.

Location:
affiliate-press/trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • affiliate-press/trunk/affiliate-press.php

    r528774 r529259  
    22/** 
    33 * @package Affiliate_Press 
    4  * @version 0.3 
     4 * @version 0.3.1 
    55 */ 
    66/* 
     
    99Description: Affiliate Press allows you to set up an affiliate website based on product feeds as easy as 1-2-3. 
    1010Author: ldebrouwer 
    11 Version: 0.3 
     11Version: 0.3.1 
    1212Author URI: http://lucdebrouwer.nl/ 
    1313*/ 
     
    3131function AP_activation() { 
    3232    include( LDB_AP_PATH . 'affiliate-press-upgrade.php' ); 
    33     update_option( 'LDB_Affiliate_Press_Version', '0.3' ); 
     33    update_option( 'LDB_Affiliate_Press_Version', '0.3.1' ); 
     34    wp_schedule_event( time(), 'hourly', 'AP_cronjob' ); 
    3435} 
    3536 
    36 /* Check if an update is required */ 
     37function AP_deactivation() { 
     38    wp_clear_scheduled_hook( 'AP_cronjob' ); 
     39} 
     40 
     41/* Check if an update is required and set the cronjob */ 
    3742register_activation_hook( __FILE__, 'AP_activation' ); 
     43 
     44/* Unset the cronjob */ 
     45register_deactivation_hook(__FILE__, 'AP_deactivation'); 
    3846 
    3947/* Start the plugin */ 
  • affiliate-press/trunk/includes/class-affiliate-press.php

    r528774 r529259  
    88        public $messages = array(); 
    99        public $action = false; 
    10  
    11         /* Load the custom post type, menu, meta box, stylesheet. Perform actions if needed. */ 
     10        public $titles = array(); 
     11 
     12        /* Load the custom post type, menu, meta box, stylesheet. Perform actions if needed. And assign something to the cronjob. */ 
    1213        function __construct() { 
    1314            add_action( 'init', array( &$this, 'AP_loadCpt' ) ); 
     
    1718            add_action( 'admin_print_scripts-post.php', array( &$this, 'AP_loadStyle' ) ); 
    1819            add_action( 'admin_init', array( &$this, 'AP_performAction' ) ); 
     20            add_action( 'AP_cronjob', array( &$this, 'AP_processAllPrices' ) ); 
    1921        } 
    2022 
     
    3133 
    3234            $hiddenpages = array( 
    33                 'affiliate_press_edit' => array( &$this, 'AP_editFeed' ), 
    34                 'affiliate_press_view' => array( &$this, 'AP_viewFeed' ), 
    35                 'affiliate_press_linktoproduct' => array( &$this, 'AP_linkToProduct' ) 
     35                'affiliate_press_edit' => array( array( &$this, 'AP_editFeed' ), __( 'Edit feed', 'LDB_AP' ) ), 
     36                'affiliate_press_view' => array( array( &$this, 'AP_viewFeed' ), __( 'View feed', 'LDB_AP' ) ), 
     37                'affiliate_press_linktoproduct' => array( array( &$this, 'AP_linkToProduct' ), __( 'Link item to an existing product', 'LDB_AP' ) ) 
    3638            ); 
    3739            $this->AP_registerHiddenPages( $hiddenpages, $parent ); 
     
    4345            foreach( $pages as $slug => $function ) { 
    4446                $hookname = get_plugin_page_hookname( $slug, $parent ); 
     47                $this->titles[ $slug ] = $function[1]; 
    4548                if ( !empty( $hookname ) ) { 
    46                     add_action( $hookname, $function ); 
     49                    add_action( $hookname, $function[0] ); 
    4750                } 
    4851                $_registered_pages[ $hookname ] = true; 
    4952                add_action( 'admin_print_styles-' . $hookname, array( &$this, 'AP_loadStyle' ) ); 
    5053            } 
     54            if( isset( $_GET['page'] ) && isset( $pages[ $_GET['page'] ] ) && isset( $pages[ $_GET['page'] ][1] ) ) 
     55                add_filter( 'admin_title', array( &$this, 'AP_changeTitle' ), 10, 2 ); 
     56        } 
     57 
     58        function AP_changeTitle( $admin_title, $title ) { 
     59            if( isset( $_GET['page'] ) && isset( $this->titles[ $_GET['page'] ] ) ) 
     60            return $this->titles[ $_GET['page'] ] . $admin_title; 
    5161        } 
    5262 
     
    148158            switch( $action ) { 
    149159                case 'process': 
    150                     if( isset( $_REQUEST['feed'] ) && is_array( $_REQUEST['feed'] ) && isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'bulk-feeds' ) ) { 
    151                         foreach( $_REQUEST['feed'] as $feed ) { 
     160                    if( isset( $_GET['feed'] ) && is_array( $_GET['feed'] ) && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'bulk-feeds' ) ) { 
     161                        foreach( $_GET['feed'] as $feed ) { 
    152162                            $this->AP_processPrices( $feed ); 
    153163                        } 
     
    161171                break; 
    162172                case 'delete': 
    163                     if( isset( $_REQUEST['feed'] ) && isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'bulk-feeds' ) ) { 
    164                         $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'apfeeds WHERE ID IN (' . implode( ', ', $_REQUEST['feed'] ) . ')' ); 
     173                    if( isset( $_GET['feed'] ) && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'bulk-feeds' ) ) { 
     174                        $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'apfeeds WHERE ID IN (' . implode( ', ', $_GET['feed'] ) . ')' ); 
    165175                        $this->AP_setMessage( __( 'The feeds were succesfully deleted.', 'LDB_AP' ), 'success' ); 
    166176                    } 
     
    171181                break; 
    172182                case 'draft': 
    173                     if( isset( $_POST['identifier'] ) && isset( $_GET['feed'] ) && isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'bulk-feeds' ) ) { 
     183                    if( isset( $_GET['identifier'] ) && isset( $_GET['feed'] ) && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'bulk-feeds' ) ) { 
    174184                        $items = @$this->AP_processFeed( $_GET['feed'] ); 
    175                         foreach( $_POST['identifier'] as $identifier ) { 
     185                        foreach( $_GET['identifier'] as $identifier ) { 
    176186                            foreach( $items as $item ) { 
    177187                                if( $item['identifier'] === $identifier ) 
     
    206216                        if( isset( $_GET['order'] ) ) 
    207217                            $order = '&order=' . $_GET['order']; 
    208                         header( 'Location:?page=' . $_GET['page'] . '&action=view&feed=' . $_GET['feed'] . '&_wpnonce=' . $_GET['_wpnonce'] . $paged . $orderby . $order . $post ); 
     218                        header( 'Location:?page=' . $_GET['page'] . '&action=view&feed=' . $_GET['feed'] . '&_viewnonce=' . $_GET['_viewnonce'] . $paged . $orderby . $order . $post ); 
    209219                    } 
    210220                break; 
     
    297307                $this->AP_setMessage( sprintf( __( 'The item was succesfully linked to the product with title "%s".', 'LDB_AP' ), $postinfo->post_title ), 'success' ); 
    298308            } 
    299             if( isset( $_GET['feed'] ) && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'view' . $_GET['feed'] ) ) { 
     309            if( isset( $_GET['feed'] ) && isset( $_GET['_viewnonce'] ) && wp_verify_nonce( $_GET['_viewnonce'], 'view' . $_GET['feed'] ) ) { 
    300310                $feed = @$this->AP_getFeed( $_GET['feed'] ); 
    301311                $items = @$this->AP_processFeed( $_GET['feed'] ); 
     
    550560        } 
    551561 
     562        /* Function that processes all the prices. For cron purposes. */ 
     563        function AP_processAllPrices() { 
     564            global $wpdb; 
     565            $feeds = $wpdb->get_results( 'SELECT ID FROM ' . $wpdb->prefix . 'apfeeds ORDER BY ID ASC', ARRAY_A ); 
     566            foreach( $feeds as $feed ) { 
     567                $this->AP_processPrices( $feed['ID'] ); 
     568            } 
     569        } 
     570 
    552571        /* Function that builds a table to display the prices in the front-end. */ 
    553572        function AP_buildTable( $data ) { 
  • affiliate-press/trunk/includes/class-feeds-table.php

    r528774 r529259  
    2727 
    2828        function column_title( $item ) { 
     29            $paged = ''; 
     30            $orderby = ''; 
     31            $order = ''; 
     32            if( isset( $_GET['paged'] ) ) 
     33                $paged = '&paged=' . $_GET['paged']; 
     34            if( isset( $_GET['orderby'] ) ) 
     35                $orderby = '&orderby=' . $_GET['orderby']; 
     36            if( isset( $_GET['order'] ) ) 
     37                $order = '&order=' . $_GET['order']; 
     38         
    2939            $actions = array( 
    30                 'view' => sprintf( '<a href="%s">%s</a>', wp_nonce_url( '?page=affiliate_press_view&feed=' . $item['ID'], 'view' . $item['ID'] ) , __( 'View', 'LDB_AP' ) ), 
    31                 'edit' => sprintf( '<a href="%s">%s</a>', wp_nonce_url( '?page=affiliate_press_edit&feed=' . $item['ID'], 'edit' . $item['ID'] ) , __( 'Edit', 'LDB_AP' ) ), 
    32                 'process' => sprintf( '<a href="%s">%s</a>', wp_nonce_url( '?page=' . $_REQUEST['page'] . '&action=process&feed=' . $item['ID'], 'process' . $item['ID'] ) , __( 'Process', 'LDB_AP' ) ), 
    33                 'delete' => sprintf( '<a href="%s">%s</a>', wp_nonce_url( '?page=' . $_REQUEST['page'] . '&action=delete&feed=' . $item['ID'], 'delete' . $item['ID'] ) , __( 'Delete', 'LDB_AP' ) ), 
     40                'view' => sprintf( '<a href="%s">%s</a>', '?page=affiliate_press_view&feed=' . $item['ID'] . '&_viewnonce=' . wp_create_nonce( 'view' . $item['ID'] ) . $paged . $orderby . $order , __( 'View', 'LDB_AP' ) ), 
     41                'edit' => sprintf( '<a href="%s">%s</a>', wp_nonce_url( '?page=affiliate_press_edit&feed=' . $item['ID'] . $paged . $orderby . $order, 'edit' . $item['ID'] ) , __( 'Edit', 'LDB_AP' ) ), 
     42                'process' => sprintf( '<a href="%s">%s</a>', wp_nonce_url( '?page=' . $_REQUEST['page'] . '&action=process&feed=' . $item['ID'] . $paged . $orderby . $order, 'process' . $item['ID'] ) , __( 'Process', 'LDB_AP' ) ), 
     43                'delete' => sprintf( '<a href="%s">%s</a>', wp_nonce_url( '?page=' . $_REQUEST['page'] . '&action=delete&feed=' . $item['ID'] . $paged . $orderby . $order, 'delete' . $item['ID'] ) , __( 'Delete', 'LDB_AP' ) ), 
    3444            ); 
    3545            return sprintf( '%1$s <span style="color:silver">(id:%2$s)</span>%3$s', $item['title'], $item['ID'], $this->row_actions( $actions ) ); 
  • affiliate-press/trunk/includes/class-items-table.php

    r528774 r529259  
    109109        function column_name( $item ) { 
    110110            global $wpdb; 
    111             $query = 'SELECT wposts.ID FROM ' . $wpdb->posts . ' wposts, ' . $wpdb->postmeta . ' wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = "' . $item['matches'] . '" AND wpostmeta.meta_value = "' . $item['identifier'] . '" AND wposts.post_type = "product"'; 
    112             $results = $wpdb->get_results( $query ); 
     111            $results = $wpdb->get_results( 'SELECT wposts.ID FROM ' . $wpdb->posts . ' wposts, ' . $wpdb->postmeta . ' wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = "' . $item['matches'] . '" AND wpostmeta.meta_value = "' . $item['identifier'] . '" AND wposts.post_type = "product"' ); 
    113112            $actions = array(); 
     113            $paged = ''; 
     114            $orderby = ''; 
     115            $order = ''; 
     116            if( isset( $_GET['paged'] ) ) 
     117                $paged = '&paged=' . $_GET['paged']; 
     118            if( isset( $_GET['orderby'] ) ) 
     119                $orderby = '&orderby=' . $_GET['orderby']; 
     120            if( isset( $_GET['order'] ) ) 
     121                $order = '&order=' . $_GET['order']; 
     122 
    114123            if( count( $results ) > 0 ) { 
    115124                return $item['name']; 
    116125            } else { 
    117                 $paged = ''; 
    118                 $orderby = ''; 
    119                 $order = ''; 
    120                 if( isset( $_GET['paged'] ) ) 
    121                     $paged = '&paged=' . $_GET['paged']; 
    122                 if( isset( $_GET['orderby'] ) ) 
    123                     $orderby = '&orderby=' . $_GET['orderby']; 
    124                 if( isset( $_GET['order'] ) ) 
    125                     $order = '&order=' . $_GET['order']; 
    126                  
    127                 $actions['draft'] = sprintf( '<a href="%s">%s</a>', wp_nonce_url( '?page=' . $_REQUEST['page'] . '&action=draft&feed=' . $item['feed_id'] . '&identifier=' . $item['identifier'] . $paged . $orderby . $order . '&_draftnonce=' . wp_create_nonce( 'draft' . $item['identifier'] ), 'view' . $item['feed_id'] ) , __( 'Create as draft', 'LDB_AP' ) ); 
    128             } 
    129             $products = get_posts( 
    130                 array( 
    131                     'post_type' => 'product', 
    132                     'post_status' => array( 'publish', 'draft' ) 
    133                 ) 
    134             ); 
    135             $actions['additem'] = sprintf( '<a href="%s" class="thickbox">%s</a>', wp_nonce_url( '?page=affiliate_press_linktoproduct&identifier=' .$item['identifier'] . '&matches=' . $item['matches'] . '&name=' . $item['name'], 'linkto' . $item['identifier'] ), __( 'Link to an existing product', 'LDB_AP' ) ); 
    136             return sprintf( '%1$s %2$s', $item['name'], $this->row_actions( $actions ) ); 
     126                $actions['draft'] = sprintf( '<a href="%s">%s</a>', '?page=' . $_REQUEST['page'] . '&action=draft&feed=' . $item['feed_id'] . '&identifier=' . $item['identifier'] . $paged . $orderby . $order . '&_draftnonce=' . wp_create_nonce( 'draft' . $item['identifier'] ) . '&_viewnonce=' . wp_create_nonce( 'view' . $item['feed_id'] ) , __( 'Create as draft', 'LDB_AP' ) ); 
     127                $products = get_posts( 
     128                    array( 
     129                        'post_type' => 'product', 
     130                        'post_status' => array( 'publish', 'draft' ) 
     131                    ) 
     132                ); 
     133                $actions['additem'] = sprintf( '<a href="%s">%s</a>', wp_nonce_url( '?page=affiliate_press_linktoproduct&identifier=' .$item['identifier'] . '&matches=' . $item['matches'] . '&name=' . $item['name'], 'linkto' . $item['identifier'] ), __( 'Link to an existing product', 'LDB_AP' ) ); 
     134                return sprintf( '%1$s %2$s', $item['name'], $this->row_actions( $actions ) ); 
     135            } 
    137136        } 
    138137 
  • affiliate-press/trunk/readme.txt

    r528774 r529259  
    5353== Changelog == 
    5454 
     55= 0.3.1 = 
     56* Added support for cron jobs. They will process all prices every hour for now. Later I'll make this manageable through a settings page. 
     57* Fixed a small bug where performing a bulk actions redirected you to the wrong page. 
     58* Tweaked the styling on the messages/warnings a little. 
     59* Made the icons stand out more. 
     60* The title tags for the 'hidden pages' are now also rendered correctly. 
     61* Switched from POST to GET methods on the feed and item index pages to allow keyboard entry of page numbers for the pagination. 
     62* Added support to return you to the right index page if you've been using sortable columns. 
     63 
    5564= 0.3 = 
    5665* Rewrite of a substantial part of the code. 
  • affiliate-press/trunk/styles.css

    r528107 r529259  
    11.message { 
    22    padding: 8px 35px 8px 14px; 
    3     margin-bottom: 18px; 
     3    margin: 18px 0; 
    44    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5); 
    55    background-color: #fcf8e3; 
  • affiliate-press/trunk/views/feed-add.php

    r528107 r529259  
    11<div class="wrap"> 
    2     <div class="icon32" id="icon-feeds"><br /></div><h2><?php echo __( 'Add Feed', 'LDB_AP' ); ?></h2> 
     2    <div class="icon32" id="icon-feeds"><br /></div><h2><?php echo __( 'Add feed', 'LDB_AP' ); ?></h2> 
    33    <div id="ap_body"> 
    44        <div id="ap_main"> 
  • affiliate-press/trunk/views/feed-edit.php

    r528107 r529259  
    11<div class="wrap"> 
    2     <div class="icon32" id="icon-feeds"><br /></div><h2><?php echo __( 'Edit Feed', 'LDB_AP' ); ?></h2> 
     2    <div class="icon32" id="icon-feeds"><br /></div><h2><?php echo __( 'Edit feed', 'LDB_AP' ); ?></h2> 
    33    <div id="ap_body"> 
    44        <div id="ap_main"> 
  • affiliate-press/trunk/views/feed-index.php

    r528107 r529259  
    44    <div id="ap_body"> 
    55        <div id="ap_main"> 
    6             <form id="feeds" method="post"> 
     6            <form id="feeds" method="get"> 
    77                <input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" /> 
    88<?php 
  • affiliate-press/trunk/views/feed-view.php

    r528107 r529259  
    11<div class="wrap"> 
    2     <div class="icon32" id="icon-feeds"><br /></div><h2><?php echo sprintf( __( 'View Feed %s', 'LDB_AP' ), $feed['title'] ); ?></h2> 
     2    <div class="icon32" id="icon-feeds"><br /></div><h2><?php echo sprintf( __( 'View feed %s', 'LDB_AP' ), $feed['title'] ); ?></h2> 
    33    <?php $this->AP_getMessage(); ?> 
    44    <div id="ap_body"> 
    55        <div id="ap_main"> 
    6             <form action="?page=affiliate_press_feeds&amp;feed=<?php echo $feed['ID']; ?>&amp;action=view&amp;_wpnonce=<?php echo $_GET['_wpnonce']; ?>" method="post"> 
    7                 <input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" /> 
     6            <form action="?page=affiliate_press_view&amp;feed=<?php echo $feed['ID']; ?>&amp;action=view&amp;_viewnonce=<?php echo $_GET['_viewnonce']; ?>" method="get"> 
     7                <input type="hidden" name="page" value="<?php echo $_GET['page']; ?>" /> 
     8                <input type="hidden" name="_viewnonce" value="<?php echo $_GET['_viewnonce']; ?>" /> 
     9                <input type="hidden" name="feed" value="<?php echo $feed['ID']; ?>" /> 
    810<?php 
    911    $itemsTable = new itemsTable(); 
Note: See TracChangeset for help on using the changeset viewer.