Skip to content

Commit

Permalink
Merge pull request #6 from jeroendesloovere/refactored-so-settings-cr…
Browse files Browse the repository at this point in the history
…eates-the-first-widget

Refactored so settings creates the first widget
  • Loading branch information
jessedobbelaere committed Mar 18, 2016
2 parents ac48afc + 4051f6d commit 49dd324
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 107 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.0.1 (xxxx-xx-xx)
--

Bugfixes:
* Backend helper needs authentication to find user.

1.0.0 (2015-08-28)
--

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ The Fork CMS Instagram module let's you display the X most recent Instagram imag
5. Go to `Settings > Modules > Instagram`.
6. Register a new client on the [Instagram developer page](https://instagram.com/developer/clients/manage/). Fill in your website/appname, the correct website URL and a redirect URL. The redirect URL should be similar to: `http://yourweburl.com/private/en/instagram/oauth` (fill in your website url).
7. Copy the client id and client secret to the Fork settings page and press the authenticate button. You get redirected to an Instagram page where you need to authorize the request. After that, you get redirected back to the Fork CMS settings and you’re logged in.
8. Go to `Modules > Instagram` and press the `add user` button. Fill in an Instagram username and save. A widget is now generated, which you can insert into any page.
5. Have fun!
8. Have fun!

## TODO
- [ ] Create Instagram feeds based on hashtags
Expand Down
1 change: 0 additions & 1 deletion src/Backend/Modules/Instagram/Actions/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ protected function loadForm()
$this->frm = new Form('add');

$this->frm->addText('username', null, null, 'inputText title', 'inputTextError title');
$this->frm->addText('function');

// meta
$this->meta = new Meta($this->frm, null, 'username', true);
Expand Down
16 changes: 11 additions & 5 deletions src/Backend/Modules/Instagram/Actions/Delete.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Backend\Modules\Team\Actions;
namespace Backend\Modules\Instagram\Actions;

use Backend\Core\Engine\Base\ActionDelete;
use Backend\Core\Engine\Model;
use Backend\Modules\Team\Engine\Model as BackendTeamModel;
use Backend\Modules\Instagram\Engine\Model as BackendInstagramModel;

/**
* This is the delete-action, it deletes an item
Expand All @@ -21,11 +21,17 @@ public function execute()
$this->id = $this->getParameter('id', 'int');

// does the item exist
if ($this->id !== null && BackendTeamModel::exists($this->id)) {
if ($this->id !== null && BackendInstagramModel::exists($this->id)) {
parent::execute();
$this->record = (array) BackendTeamModel::get($this->id);
$this->record = (array) BackendInstagramModel::get($this->id);

BackendTeamModel::delete($this->id);
if ($this->record['locked'] == 'Y') {
$this->redirect(
Model::createURLForAction('Index') . '&error=is-locked'
);
}

BackendInstagramModel::delete($this->id);

Model::triggerEvent(
$this->getModule(), 'after_delete',
Expand Down
6 changes: 6 additions & 0 deletions src/Backend/Modules/Instagram/Actions/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ protected function loadData()
}

$this->record = BackendInstagramModel::get($this->id);

if ($this->record['locked'] == 'Y') {
$this->redirect(
Model::createURLForAction('Index') . '&error=is-locked'
);
}
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/Backend/Modules/Instagram/Actions/Logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,22 @@ class Logout extends BackendBaseAction
*/
public function execute()
{
// save access_token to settings
$instagramUserId = $this->get('fork.settings')->get(
$this->URL->getModule(),
'default_instagram_user_id',
false
);

if ($instagramUserId) {
BackendInstagramModel::delete($instagramUserId);
}

$this->get('fork.settings')->set('Instagram', 'client_id', null);
$this->get('fork.settings')->set('Instagram', 'client_secret', null);
$this->get('fork.settings')->set('Instagram', 'username', null);
$this->get('fork.settings')->set('Instagram', 'access_token', null);
$this->get('fork.settings')->set('Instagram', 'default_instagram_user_id', null);

$this->redirect(BackendModel::createURLForAction('Settings'));
}
Expand Down
31 changes: 26 additions & 5 deletions src/Backend/Modules/Instagram/Actions/Oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Backend\Core\Engine\Base\Action as BackendBaseAction;
use Backend\Core\Engine\Model as BackendModel;
use Backend\Modules\Instagram\Engine\Helper;
use Backend\Modules\Instagram\Engine\Model as BackendInstagramModel;

/**
* This is the settings-action, it will display a form to set general instagram settings
Expand All @@ -31,8 +32,8 @@ public function execute()
$oAuthCode = $this->getParameter('code', 'string', '');

// get settings
$client_id = $this->get('fork.settings')->get($this->URL->getModule(), 'client_id');
$client_secret = $this->get('fork.settings')->get($this->URL->getModule(), 'client_secret');
$client_id = BackendModel::getModuleSetting($this->URL->getModule(), 'client_id');
$client_secret = BackendModel::getModuleSetting($this->URL->getModule(), 'client_secret');

// if no settings configured, redirect
if (!isset($client_id) || !isset($client_secret)) {
Expand All @@ -49,14 +50,34 @@ public function execute()
// oauth code is set (meaning we got redirected from instagram)
else {
// exchanging the instagram login code for an access token
$access_token = Helper::getOAuthToken($client_id, $client_secret, $oAuthCode, SITE_URL . BackendModel::createURLForAction('Oauth'), true);
$authenticationData = Helper::getOAuthToken($client_id, $client_secret, $oAuthCode, SITE_URL . BackendModel::createURLForAction('Oauth'), false);

// define variables
$userId = $authenticationData->user->id;
$userName = $authenticationData->user->username;
$accessToken = $authenticationData->access_token;

if (isset($accessToken)) {
$instagramUser = array(
'user_id' => $userId,
'username' => $userName,
'locked' => 'Y',
);

$instagramUser['id'] = BackendInstagramModel::insert($instagramUser);

if (isset($access_token)) {
// save access_token to settings
$this->get('fork.settings')->set(
$this->URL->getModule(),
'access_token',
$access_token
$accessToken
);

// save access_token to settings
$this->get('fork.settings')->set(
$this->URL->getModule(),
'default_instagram_user_id',
$instagramUser['id']
);

// trigger event
Expand Down
2 changes: 1 addition & 1 deletion src/Backend/Modules/Instagram/Engine/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function searchUser($name, $limit = 0)
if ($limit > 0) {
$params['count'] = $limit;
}
return self::makeApiCall('users/search', false, $params);
return self::makeApiCall('users/search', true, $params);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/Backend/Modules/Instagram/Engine/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class Model
*/
public static function delete($id)
{
$record = self::get($id);

// delete extra
BackendModel::deleteExtraById($record['extra_id'], true);

// delete user id
BackendModel::get('database')->delete('instagram_users', 'id = ?', (int) $id);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Backend/Modules/Instagram/Installer/Data/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ CREATE TABLE `instagram_users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(30) DEFAULT '',
`user_id` int(11) DEFAULT NULL,
`meta_id` int(11) DEFAULT NULL,
`extra_id` int(11) DEFAULT NULL,
`locked` enum('N','Y') NOT NULL DEFAULT 'N',
`hidden` enum('N','Y') NOT NULL DEFAULT 'N',
`created_on` datetime DEFAULT NULL,
`edited_on` datetime DEFAULT NULL,
Expand Down
4 changes: 4 additions & 0 deletions src/Backend/Modules/Instagram/Installer/Data/locale.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
<translation language="nl"><![CDATA[Account werd succesvol geauthenticeerd.]]></translation>
<translation language="en"><![CDATA[Account succesfully authenticated.]]></translation>
</item>
<item type="error" name="IsLocked">
<translation language="nl"><![CDATA[Deze widget is automatisch aangemaakt bij het toevoegen van uw APP credentials. U kan deze widget niet wijzigen.]]></translation>
<translation language="en"><![CDATA[This widget has been automatically created when you added your APP credentials. You can't edit this widget.]]></translation>
</item>
</Instagram>
<Core>
<item type="label" name="Instagram">
Expand Down
36 changes: 0 additions & 36 deletions src/Backend/Modules/Instagram/Layout/Templates/Add.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,6 @@
</div>
</div>


{*<div class="tabs">*}
{*<ul>*}
{*<li><a href="#tabContent">{$lblContent|ucfirst}</a></li>*}
{*<li><a href="#tabSEO">{$lblSEO|ucfirst}</a></li>*}
{*</ul>*}

{*<div id="tabContent">*}
{*<table border="0" cellspacing="0" cellpadding="0" width="100%">*}
{*<tr>*}
{*<td id="leftColumn">*}

{*<div class="box">*}
{*<div class="heading">*}
{*<h3>*}
{*<label for="function">{$lblFunction|ucfirst}</label>*}
{*</h3>*}
{*</div>*}
{*<div class="options">*}
{*{$txtFunction} {$txtFunctionError}*}
{*</div>*}
{*</div>*}


{*</td>*}

{*</tr>*}
{*</table>*}
{*</div>*}

{*<div id="tabSEO">*}
{*{include:{$BACKEND_CORE_PATH}/Layout/Templates/Seo.tpl}*}
{*</div>*}

{*</div>*}

<div class="fullwidthOptions">
<div class="buttonHolderRight">
<input id="addButton" class="inputButton button mainButton" type="submit" name="add" value="{$lblPublish|ucfirst}" />
Expand Down
56 changes: 0 additions & 56 deletions src/Backend/Modules/Instagram/Layout/Templates/Edit.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,62 +16,6 @@
</div>
</div>


{*<div class="tabs">*}
{*<ul>*}
{*<li><a href="#tabContent">{$lblContent|ucfirst}</a></li>*}
{*<li><a href="#tabSEO">{$lblSEO|ucfirst}</a></li>*}
{*</ul>*}

{*<div id="tabContent">*}
{*<table border="0" cellspacing="0" cellpadding="0" width="100%">*}
{*<tr>*}
{*<td id="leftColumn">*}

{*<div class="box">*}
{*<div class="heading">*}
{*<h3>*}
{*<label for="function">{$lblFunction|ucfirst}</label>*}
{*</h3>*}
{*</div>*}
{*<div class="options">*}
{*{$txtFunction} {$txtFunctionError}*}
{*</div>*}
{*</div>*}

{*<div class="box">*}
{*<div class="heading">*}
{*<h3>*}
{*<label for="photo">{$lblPhoto|ucfirst}</label>*}
{*</h3>*}
{*</div>*}
{*<div class="options">*}
{*{option:item.photo}*}
{*<p><img src="{$FRONTEND_FILES_URL}/team/photo/150x150/{$item.photo}"/></p>*}
{*{/option:item.photo}*}
{*<p>*}
{*{$filePhoto} {$filePhotoError}*}
{*</p>*}
{*</div>*}
{*</div>*}


{*</td>*}

{*<td id="sidebar">*}


{*</td>*}
{*</tr>*}
{*</table>*}
{*</div>*}

{*<div id="tabSEO">*}
{*{include:{$BACKEND_CORE_PATH}/Layout/Templates/Seo.tpl}*}
{*</div>*}

{*</div>*}

<div class="fullwidthOptions">
<a href="{$var|geturl:'delete'}&amp;id={$item.id}" data-message-id="confirmDelete" class="askConfirmation button linkButton icon iconDelete">
<span>{$lblDelete|ucfirst}</span>
Expand Down

0 comments on commit 49dd324

Please sign in to comment.