all repos — keyring-reactions-importer @ b207c17a972ca97601ae62df26af7e6d31a59810

regex match 500px instead of standard url explode since the full url of the photo can have the photo name in it after the id
Peter Molnar hello@petermolnar.eu
Fri, 20 Mar 2015 10:32:58 +0000
commit

b207c17a972ca97601ae62df26af7e6d31a59810

parent

2c16178e2c57fb3ed8d4f0e8c9852ec7fb5d5635

1 files changed, 7 insertions(+), 2 deletions(-)

jump to
M importers/keyring-reactions-500px.phpimporters/keyring-reactions-500px.php

@@ -12,6 +12,7 @@ const REQUESTS_PER_LOAD = 3; // How many remote requests should be made before reloading the page?

const NUM_PER_REQUEST = 100; // Number of images per request to ask for const SILONAME = '500px.com'; + const PHOTOPATTERN = '/https:\/\/500px\.com\/photo\/([0-9]+)[\/]?(.*)/'; function __construct() { $this->methods = array (

@@ -46,12 +47,16 @@ 'keyring-500px-reactions-missing-syndication-url',

__( 'Missing syndication URL.', 'keyring') ); - $silo_id = trim(end((explode('/', rtrim($syndication_url, '/'))))); - if (empty($silo_id)) + $matches = array(); + $match = preg_match ( static::PHOTOPATTERN, $syndication_url, $matches ); + if ( !$match || empty($matches) || !isset($matches[1]) || empty($matches[1])) { return new Keyring_Error( 'keyring-500px-reactions-photo-id-not-found', __( 'Cannot get photo ID out of syndication URL.', 'keyring' ) ); + } + + $silo_id = $matches[1]; $func = 'get_' . $method; if ( !method_exists( $this, $func ) )