Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: codeablehq/expertstatsplugin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.1.0
Choose a base ref
...
head repository: codeablehq/expertstatsplugin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Jul 12, 2017

  1. Make client rows more compact

    jin0x committed Jul 12, 2017
    Copy the full SHA
    95aed48 View commit details

Commits on Jul 23, 2019

  1. Update README.md

    add truncate instructions
    wpbullet authored Jul 23, 2019
    Copy the full SHA
    b534687 View commit details
  2. Merge pull request #49 from wpbullet/patch-1

    Update README.md
    11digitlabs authored Jul 23, 2019
    Copy the full SHA
    18d01f3 View commit details

Commits on Jul 25, 2019

  1. 👌 IMPROVE: If we find a transaction that already exists, bail out and…

    … don't continue updating all the transactions
    PanosSynetos committed Jul 25, 2019
    Copy the full SHA
    2773fb3 View commit details

Commits on Aug 2, 2019

  1. Copy the full SHA
    39306dc View commit details
  2. 👌 IMPROVE: Tasks - Fix some cases where the tasks don't have valid da…

    …tes (due to API inconsistencies)
    PanosSynetos committed Aug 2, 2019
    Copy the full SHA
    6b4dad8 View commit details
  3. Copy the full SHA
    d9ceee3 View commit details

Commits on Oct 1, 2019

  1. Fix settings page label (hours/days)

    Francesco Carlucci authored and Francesco Carlucci committed Oct 1, 2019
    Copy the full SHA
    1af4f8c View commit details
  2. Merge pull request #52 from frenxi/fix-admin-settings-canceled-field-…

    …label
    
    Fix settings page label (hours/days)
    11digitlabs authored Oct 1, 2019
    Copy the full SHA
    10f8de8 View commit details
  3. Copy the full SHA
    afca542 View commit details

Commits on Jun 1, 2020

  1. Copy the full SHA
    8938c42 View commit details

Commits on Sep 2, 2020

  1. Merge pull request #55 from dimadin/patch-1

    Use WordPress HTTP API instead of cURL
    11digitlabs authored Sep 2, 2020
    Copy the full SHA
    7a88d86 View commit details
  2. Update README.md

    11digitlabs authored Sep 2, 2020
    Copy the full SHA
    c9266ee View commit details
  3. Copy the full SHA
    c12e3fa View commit details

Commits on Jul 16, 2021

  1. Copy the full SHA
    48117cd View commit details
  2. Copy the full SHA
    be2b076 View commit details
  3. Copy the full SHA
    108e77b View commit details
  4. Copy the full SHA
    9da84b0 View commit details

Commits on Jul 20, 2021

  1. Revert "Make client rows more compact"

    This reverts commit 95aed48.
    PanosSynetos committed Jul 20, 2021
    Copy the full SHA
    c1ff385 View commit details
  2. Copy the full SHA
    5340f85 View commit details
  3. Merge pull request #58 from kakoma/feat/add-actions-and-filters

    Add initial actions and filters
    11digitlabs authored Jul 20, 2021
    Copy the full SHA
    a1f5e76 View commit details
  4. Bumb version

    PanosSynetos committed Jul 20, 2021
    Copy the full SHA
    c62d757 View commit details

Commits on Mar 6, 2022

  1. Fixing issue #60

    Adding back to the body request the auth token for the plugin class
    spyrosvl committed Mar 6, 2022
    Copy the full SHA
    4dce7a2 View commit details
Showing with 801 additions and 749 deletions.
  1. +13 −1 README.md
  2. +53 −58 classes/api_calls.php
  3. +28 −3 classes/api_data.php
  4. +1 −1 classes/tasks.php
  5. +4 −251 functions/admin-estimate.php
  6. +10 −182 functions/admin-settings.php
  7. +4 −251 functions/admin-tasks.php
  8. +249 −0 templates/admin-estimate.php
  9. +189 −0 templates/admin-settings.php
  10. +248 −0 templates/admin-task-table.php
  11. +2 −2 wp-codeable.php
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Codeable](https://img.shields.io/badge/Codeable-Experts-blue.svg?style=flat-square)]()
# Codeable Expert Stats Plugin Readme
*Contributors:* Spyros Vlachopoulos, Panagiotis Synetos, John Leskas, Justin Frydman, Jonathan Bossenger, Rob Scott, Philipp Stracker
*Contributors:* Spyros Vlachopoulos, Panagiotis Synetos, John Leskas, Justin Frydman, Jonathan Bossenger, Rob Scott, Philipp Stracker, Milan Dinić

*Tested up to:* WordPress 5.2.2

@@ -60,6 +60,18 @@ If you don't have it installed, you can:

This will give you the normal WP update notification when a new version ships, and its a 1 click update.

### Migrating from Old Version

You may want to truncate these tables, replace wp_ with your database prefix

```
TRUNCATE TABLE wp_codeable_amounts;
TRUNCATE TABLE wp_codeable_clients;
TRUNCATE TABLE wp_codeable_tasks;
TRUNCATE TABLE wp_codeable_transactions;
TRUNCATE TABLE wp_codeable_transcactions;
```

### Frequently Asked Questions

*There was a problem fetching remote data from Codeable*
111 changes: 53 additions & 58 deletions classes/api_calls.php
Original file line number Diff line number Diff line change
@@ -25,6 +25,13 @@ class wpcable_api_calls {
*/
public $auth_token = '';

/**
* Get the option to know when to stop pulling tasks
*
* @var int
*/
private $tasks_stop_at_page = 0;

/**
* Returns the singleton instance to the API object.
*
@@ -45,6 +52,7 @@ public static function inst() {
*/
private function __construct() {
$this->get_auth_token();
$this->tasks_stop_at_page = (int) get_option( 'wpcable_tasks_stop_at_page', 0 );
}

/**
@@ -62,7 +70,7 @@ public function login( $email, $password ) {

$this->auth_token = '';
$url = 'users/login';
$login_call = $this->get_curl( $url, $args );
$login_call = $this->request( $url, $args );

// Credential error checking.
if (
@@ -133,7 +141,7 @@ private function get_auth_token() {
*/
public function self() {
$url = 'users/me';
$login_call = $this->get_curl( $url, [], 'get' );
$login_call = $this->request( $url, [], 'get' );

unset( $login_call['auth_token'] );

@@ -150,7 +158,7 @@ public function transactions_page( $page = 1 ) {
$url = 'users/me/transactions';
$args = [ 'page' => $page ];

$transactions = $this->get_curl( $url, $args, 'get' );
$transactions = $this->request( $url, $args, 'get' );

return $transactions;
}
@@ -176,7 +184,13 @@ public function tasks_page( $filter = 'preferred', $page = 1 ) {
'per_page' => $num,
];

$tasks = $this->get_curl( $url, $args, 'get' );
// Stop at the next page before it does the call
if ( $this->tasks_stop_at_page
&& ( $this->tasks_stop_at_page + 1 ) === $page ) {
return [];
}

$tasks = $this->request( $url, $args, 'get' );

return $tasks;
}
@@ -187,84 +201,65 @@ public function tasks_page( $filter = 'preferred', $page = 1 ) {
* @param string $url API endpoint.
* @param array $args Additional URL params or post data.
* @param string $method Request method [GET|POST].
* @param string $headers Optional Curl headers.
* @param array $headers Optional HTTP headers.
* @return array
*/
private function get_curl( $url, $args = [], $method = 'post', $headers = '' ) {
$res = false;
private function request( $url, $args = [], $method = 'POST', $headers = [] ) {
$response_body = false;

try {
set_time_limit( 300 );
set_time_limit( 300 );

$ch = curl_init();
$method = strtolower( $method );
$method = strtoupper( $method );
$request_args = [ 'method' => $method ];
$url = 'https://api.codeable.io/' . ltrim( $url, '/' );

if ( false === $ch ) {
throw new Exception( 'Failed to initialize cURL' );
}

$url = 'https://api.codeable.io/' . ltrim( $url, '/' );

if ( 'get' === $method ) {
if ( ! empty( $args ) ) {
$url = $url . '?' . http_build_query( $args );
}
if ( ! empty( $args ) ) {
if ( 'GET' === $method ) {
$url = add_query_arg( $args, $url );
} else {
curl_setopt( $ch, CURLOPT_POSTFIELDS, $args );
}

// Setup request to send json via POST.
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );

if ( ! $headers || ! is_array( $headers ) ) {
$headers = [];
$request_args['body'] = $args;
}
if ( $this->auth_token_known() ) {
$headers[] = 'Authorization: Bearer ' . $this->auth_token;
}

curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );

// Send request.
$content = curl_exec( $ch );
}

if ( false === $content ) {
echo '<pre>' . print_r( $url, true ) . '</pre>';
$request_args['headers'] = $headers;

echo '<pre>';
print_r( curl_error( $ch ) );
echo '</pre>';
if ( $this->auth_token_known() ) {
$request_args['headers']['Authorization'] = 'Bearer ' . $this->auth_token;
}

echo '<pre>';
print_r( curl_errno( $ch ) );
echo '</pre>';
$response = wp_remote_request( $url, $request_args );

die;
}
curl_close( $ch );

$res = json_decode( $content, true );
} catch ( Exception $e ) {
if ( is_wp_error( $response ) ) {
trigger_error(
sprintf(
'cURL failed with error #%d: %s',
$e->getCode(), $e->getMessage()
'Request failed with error %1$s: %2$s',
$response->get_error_code(), $response->get_error_message()
),
E_USER_ERROR
);
return false;
}

if ( is_array( $res ) && ! empty( $res['errors'] ) ) {
if ( false !== array_search( 'Invalid login credentials', $res['errors'], true ) ) {
$response_body = json_decode( $response['body'], true );

if( isset( $response['headers'] ) ) {

$full_header = $response['headers']->getAll();
if ( isset( $full_header['auth-token'] ) && !empty( $full_header['auth-token'] ) ) {

$response_body['auth_token'] = $full_header['auth-token'];
}
}

if ( is_array( $response_body ) && ! empty( $response_body['errors'] ) ) {
if ( false !== array_search( 'Invalid login credentials', $response_body['errors'], true ) ) {
// The auth_token expired or login failed: Clear the token!
// Next time the user visits the settings page, they need to login again.
codeable_api_logout();
return false;
}
}

return $res;
return $response_body;
}

}
31 changes: 28 additions & 3 deletions classes/api_data.php
Original file line number Diff line number Diff line change
@@ -294,6 +294,15 @@ private function store_transactions( $page ) {
$tr['credit_amounts'],
$tr['debit_amounts']
);

// If we find a transaction that already exists, bail out and don't continue updating all the transactions
if ( $exists ) {
update_option( 'wpcable_average', $single_page['average_task_size'] );
update_option( 'wpcable_balance', $single_page['balance'] );
update_option( 'wpcable_revenue', $single_page['revenue'] );
return false;
}

}

return $page + 1;
@@ -400,16 +409,30 @@ private function store_tasks( $filter, $page ) {
} elseif ( ! empty( $task['last_event']['object']['published_at'] ) ) {
$new_task['last_activity'] = (int) $task['last_event']['object']['published_at'];
$new_task['last_activity_by'] = '';
}elseif ( ! empty( $task['last_event']['object']['created_at'] ) ) {
$new_task['last_activity'] = (int) strtotime($task['last_event']['object']['created_at']);
$new_task['last_activity_by'] = '';
}
elseif ( ! empty( $task['last_event']['object']['updated_at'] ) ) {
$new_task['last_activity'] = (int) strtotime($task['last_event']['object']['updated_at']);
$new_task['last_activity_by'] = '';
}


if ( ! empty( $task['last_event']['user']['full_name'] ) ) {
$new_task['last_activity_by'] = $task['last_event']['user']['full_name'];
}

if ( ! empty( $task['last_event']['type']) && 'create_vault' === $task['last_event']['type']) {
$new_task['last_activity'] = (int) strtotime($task['last_event']['user']['last_sign_in_at']);
$new_task['last_activity_by'] = $task['last_event']['user']['full_name'];
}

// Some simple rules to automatically detect the correct flag for tasks.
if ( 'canceled' === $task['state'] ) {
// Tasks that were canceled by the client obviously are lost.
$new_task['flag'] = 'lost';
$new_task['flag'] = 'lost';
$new_task['last_activity'] = (int) strtotime( $task['published_at'] );
} elseif ( $new_task['hidden'] ) {
// Tasks that I hide from my Codeable list are "lost for us".
$new_task['flag'] = 'lost';
@@ -426,8 +449,10 @@ private function store_tasks( $filter, $page ) {
}
} elseif ( empty( $new_task['last_activity'] ) ) {
// This workroom is private for another expert = possibly lost.
if ( in_array( $task['state'], [ 'hired', 'completed', 'refunded' ], true ) ) {
$new_task['flag'] = 'lost';
if ( in_array( $task['state'], [ 'hired', 'completed', 'refunded', 'paid' ], true ) ) {
$new_task['flag'] = 'lost';
// Disabled last activity for these ones, as it was causing more problems than solving
// $new_task['last_activity'] = (int) strtotime( $task['published_at'] );
}
}

2 changes: 1 addition & 1 deletion classes/tasks.php
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ public function sanitize_task( $task ) {
false
);

return $task;
return apply_filters( 'wpcable_sanitize_task',$task );
}

/**
Loading