Skip to content
This repository has been archived by the owner on Aug 21, 2019. It is now read-only.

Commit

Permalink
removed need for account and userid when used without user
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Meilick <b@bnomei.com>
  • Loading branch information
bnomei committed Apr 8, 2017
1 parent f515811 commit ff3acd0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 30 deletions.
41 changes: 25 additions & 16 deletions kirby-instagram-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,38 @@ function instagramapi($user, $endpoint, $snippet = '', $params = []) {
$endpoint = trim($endpoint);
$endpoint = rtrim($endpoint,'/');
if(substr($endpoint, 0, 1) != '/') $endpoint = '/'.$endpoint;

// PARAMS
if(!$params || gettype($params) != 'array') {
$params = array();
}

// USER
// TOKEN
$userInstagram = null;
if(is_string($user)) {
if(str::contains($user, ' ')) {
$iad = explode(' ', $user); // see $account_ID_Token
if(count($iad) == 3) {
$userInstagram = [
'account' => $iad[0],
'userid' => $iad[1],
'token' => $iad[2],
];
}
$token = c::get('plugin.instagram-api.token', '');
if($token && strlen(trim($token)) > 0) {
$userInstagram = [
'account' => '',
'userid' => '',
'token' => $token,
];
$user = null;
}

// USER
if($user && is_string($user)) {
if($tryUser = site()->user($user)) {
$user = $tryUser;
} else {
$user = site()->user($user);
$userInstagram = [
'account' => '',
'userid' => '',
'token' => $token,
];
$user = null;
}
}
if(is_a($user, 'User')) {
if($user && is_a($user, 'User')) {
if($iad = $user->instagramapi()) {
$iad = explode(' ', $iad); // see $account_ID_Token
if(count($iad) == 3) {
Expand All @@ -99,10 +108,10 @@ function instagramapi($user, $endpoint, $snippet = '', $params = []) {
}
}
}
if(is_array($user)) {
if($user && is_array($user)) {
$userInstagram = $user;
}

if(!$userInstagram || !is_array($userInstagram)) {
return 'Invalid User.';
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kirby-instagram-api",
"description": "Kirby CMS User-Field, Tag and Page Method to access Instagram API Endpoints. This is a boilerplate to create your own Instagram embeds.",
"version": "0.7.0",
"version": "0.7.1",
"type": "kirby-plugin",
"license": "Commercial",
"author": "Bruno Meilick"
Expand Down
38 changes: 25 additions & 13 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,26 +152,34 @@ Of course you can use the Page or Site Methods directly. Take a look at the [exa

### Use without extending a Kirby User (v0.7+)

If you already have `account`, `userid` and `token` you can use this plugin without its Kirby User Field. Like it was suggested by @olach in [Issue #1](https://github.com/bnomei/kirby-instagram-api/issues/1).

Use the Tag with `space` seperated values.
If you already have a `token` you can use this plugin without its Kirby User Field. Like it was suggested by @olach in [Issue #1](https://github.com/bnomei/kirby-instagram-api/issues/1). Just use your `token` instead of the username.

```
(instagramapi: ACCOUNT USERID TOKEN endpoint: users/self/media/recent snippet: ia-example-media)
(instagramapi: TOKEN endpoint: users/self/media/recent snippet: ia-example-media)
```

```php
// as array
$logindata = [
'account' => 'ACCOUNT',
'userid' => 'USERID',
'token' => 'TOKEN',
];
// or as string
$logindata = 'ACCOUNT USERID TOKEN';
$result = $page->instagramapi($logindata, 'users/self/media/recent');
$result = $page->instagramapi(TOKEN, 'users/self/media/recent');
foreach($result['data'] as $data) { /*...*/ }
```

If you set the token in you `site/config/config.php` it will override all other means.

```php
c::set('plugin.instagram-api.token', 'TOKEN');
```

```
(instagramapi: DoesNotMatter endpoint: users/self/media/recent snippet: ia-example-media)
```

```php
// suggested
$result = $page->instagramapi(c::get('plugin.instagram-api.token'), 'users/self/media/recent');
// or even
$result = $page->instagramapi('DoesNotMatter', 'users/self/media/recent');
$result = $page->instagramapi(null, 'users/self/media/recent');
foreach($result['data'] as $data) { /*...*/ }
```

## Other Setting
Expand All @@ -188,6 +196,10 @@ You can set these in your `site/config/config.php`.
### plugin.instagram-api.client-secret
- get it from [Instagram Deverloper](https://www.instagram.com/developer/clients/manage/)

### plugin.instagram-api.token
- default: ''
- set this if you want to ommit specifying the token.

### plugin.instagram-api.tag.endpoint
- default: ''
- set this if you want to ommit specifying the endpoint in the tag.
Expand Down

0 comments on commit ff3acd0

Please sign in to comment.