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

This commit is contained in:
Peter Molnar 2015-03-20 10:32:58 +00:00
parent 2c16178e2c
commit b207c17a97

View file

@ -12,6 +12,7 @@ class Keyring_500px_Reactions extends Keyring_Reactions_Base {
const NUM_PER_REQUEST = 100; // Number of images per request to ask for const NUM_PER_REQUEST = 100; // Number of images per request to ask for
const SILONAME = '500px.com'; const SILONAME = '500px.com';
const PHOTOPATTERN = '/https:\/\/500px\.com\/photo\/([0-9]+)[\/]?(.*)/';
function __construct() { function __construct() {
$this->methods = array ( $this->methods = array (
@ -46,12 +47,16 @@ class Keyring_500px_Reactions extends Keyring_Reactions_Base {
__( 'Missing syndication URL.', 'keyring') __( 'Missing syndication URL.', 'keyring')
); );
$silo_id = trim(end((explode('/', rtrim($syndication_url, '/'))))); $matches = array();
if (empty($silo_id)) $match = preg_match ( static::PHOTOPATTERN, $syndication_url, $matches );
if ( !$match || empty($matches) || !isset($matches[1]) || empty($matches[1])) {
return new Keyring_Error( return new Keyring_Error(
'keyring-500px-reactions-photo-id-not-found', 'keyring-500px-reactions-photo-id-not-found',
__( 'Cannot get photo ID out of syndication URL.', 'keyring' ) __( 'Cannot get photo ID out of syndication URL.', 'keyring' )
); );
}
$silo_id = $matches[1];
$func = 'get_' . $method; $func = 'get_' . $method;
if ( !method_exists( $this, $func ) ) if ( !method_exists( $this, $func ) )