Skip to content

Commit

Permalink
Update to Fork CMS v4
Browse files Browse the repository at this point in the history
  • Loading branch information
jessedobbelaere committed Jun 19, 2016
1 parent 49dd324 commit 32e9ead
Show file tree
Hide file tree
Showing 29 changed files with 387 additions and 469 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
1.0.1 (xxxx-xx-xx)
2.0.0
--
* Switch to Fork CMS v4 with Twig template support

1.0.1 (2016-03-17)
--
Bugfixes:
* Backend helper needs authentication to find user.

1.0.0 (2015-08-28)
--

First public release
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
The Fork CMS Instagram module let's you display the X most recent Instagram images for one (or multiple) users.

## Preview
[ ![Image](https://i.imgur.com/8ciwbRim.png "Backend") ](https://i.imgur.com/8ciwbRi.png)
[![Image](http://i.imgur.com/Iu5T1SDm.png "Backend") ](http://i.imgur.com/Iu5T1SD.png)
[![Image](http://i.imgur.com/UNwoA0Wm.png "Backend") ](http://i.imgur.com/UNwoA0W.png)
[ ![Image](http://i.imgur.com/6pT2cYdm.png "Backend") ](http://i.imgur.com/6pT2cYd.png)
[ ![Image](http://i.imgur.com/YdBq9YZm.png "Backend") ](http://i.imgur.com/YdBq9YZ.png)
[ ![Image](http://i.imgur.com/zLyr5Ftm.png "Backend") ](http://i.imgur.com/zLyr5Ft.png)

## Installation

1. Upload the `/src/Backend/Modules/Instagram` folder to your `/src/Backend/Modules` folder and your `/src/Frontend/Modules/Instagram` folder to `/src/Frontend/Modules` folder.
3. Browse to your Fork CMS backend site.
4. Go to `Settings > Modules`. Click on the install button next to the menu module.
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. Have fun!
2. Browse to your Fork CMS backend site.
3. Go to `Settings > Modules`. Click on the install button next to the menu module.
4. Go to `Settings > Modules > Instagram`.
5. 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).
6. 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.
7. Have fun!

## TODO
- [ ] Create Instagram feeds based on hashtags

## Bugs

If you encounter any bugs, please create an issue and I'll try to fix it (or feel free to fix it yourself with a pull-request).

## Discussion
- Twitter: [@jessedobbelaere](https://www.twitter.com/jessedobbelaere)
- E-mail: <jesse@dobbelaere-ae.be> for any questions or remarks.
- Slack: [Fork CMS Slack channel](https://fork-cms.herokuapp.com)

Credits to @waldocosman for his original Instagram module, the inspiration for this module.
2 changes: 1 addition & 1 deletion VERSION.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
2.0.0
34 changes: 10 additions & 24 deletions src/Backend/Modules/Instagram/Actions/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
use Backend\Core\Engine\Model;
use Backend\Modules\Instagram\Engine\Helper;
use Backend\Modules\Instagram\Engine\Model as BackendInstagramModel;
use Backend\Modules\Search\Engine\Model as BackendSearchModel;
use Backend\Modules\Tags\Engine\Model as BackendTagsModel;
use Backend\Modules\Users\Engine\Model as BackendUsersModel;

/**
* This is the add-action, it will display a form to create a new item
Expand Down Expand Up @@ -43,7 +40,7 @@ protected function loadForm()

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

// meta
// Meta
$this->meta = new Meta($this->frm, null, 'username', true);
}

Expand All @@ -54,15 +51,14 @@ protected function parse()
{
parent::parse();

// get url
// Get url
$url = Model::getURLForBlock($this->URL->getModule(), 'Detail');
$url404 = Model::getURL(404);

// parse additional variables
// Parse additional variables
if ($url404 != $url) {
$this->tpl->assign('detailURL', SITE_URL . $url);
}
$this->record['url'] = $this->meta->getURL();
}

/**
Expand All @@ -73,39 +69,29 @@ protected function validateForm()
if ($this->frm->isSubmitted()) {
$this->frm->cleanupFields();

// validation
// Validation
$fields = $this->frm->getFields();

$fields['username']->isFilled(Language::err('FieldIsRequired'));

// validate meta
//$this->meta->validate();

if ($this->frm->isCorrect()) {
// build the item
// Build the item
$item['username'] = $fields['username']->getValue();
// $item['meta_id'] = $this->meta->save();

// lookup user id
// Lookup user id
$userObj = Helper::searchUser($item['username']);
if (isset($userObj->data)) {
$userId = $userObj->data[0]->id;
$item['user_id'] = $userId;
} else {
$this->redirect(
Model::createURLForAction('Index') . '&error=api_error'
);
$this->redirect(Model::createURLForAction('Index') . '&error=api_error');
}

// insert it
// Insert it
$item['id'] = BackendInstagramModel::insert($item);
Model::triggerEvent($this->getModule(), 'after_add', $item);

Model::triggerEvent(
$this->getModule(), 'after_add', $item
);
$this->redirect(
Model::createURLForAction('Index') . '&report=added&highlight=row-' . $item['id']
);
$this->redirect(Model::createURLForAction('Index') . '&report=added&highlight=row-' . $item['id']);
}
}
}
Expand Down
13 changes: 4 additions & 9 deletions src/Backend/Modules/Instagram/Actions/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,18 @@ public function execute()
{
$this->id = $this->getParameter('id', 'int');

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

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

// Delete the file
BackendInstagramModel::delete($this->id);

Model::triggerEvent(
$this->getModule(), 'after_delete',
array('id' => $this->id)
);
Model::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id));

$this->redirect(
Model::createURLForAction('Index') . '&report=deleted&var=' .
Expand Down
40 changes: 8 additions & 32 deletions src/Backend/Modules/Instagram/Actions/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
use Backend\Core\Engine\Base\ActionEdit;
use Backend\Core\Engine\Form;
use Backend\Core\Engine\Language;
use Backend\Core\Engine\Meta;
use Backend\Core\Engine\Model;
use Backend\Modules\Instagram\Engine\Helper;
use Backend\Modules\Instagram\Engine\Model as BackendInstagramModel;
use Backend\Modules\Search\Engine\Model as BackendSearchModel;
use Backend\Modules\Tags\Engine\Model as BackendTagsModel;
use Backend\Modules\Users\Engine\Model as BackendUsersModel;

/**
* This is the edit-action, it will display a form with the item data to edit
Expand Down Expand Up @@ -42,17 +38,13 @@ protected function loadData()
{
$this->id = $this->getParameter('id', 'int', null);
if ($this->id == null || !BackendInstagramModel::exists($this->id)) {
$this->redirect(
Model::createURLForAction('Index') . '&error=non-existing'
);
$this->redirect(Model::createURLForAction('Index') . '&error=non-existing');
}

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

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

Expand All @@ -61,14 +53,9 @@ protected function loadData()
*/
protected function loadForm()
{
// create form
// Create form
$this->frm = new Form('edit');

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

// meta
// $this->meta = new Meta($this->frm, $this->record['meta_id'], 'username', true);
// $this->meta->setUrlCallBack('Backend\Modules\Instagram\Engine\Model', 'getUrl', array($this->record['id']));
}

/**
Expand All @@ -78,16 +65,14 @@ protected function parse()
{
parent::parse();

// get url
// Get url
$url = Model::getURLForBlock($this->URL->getModule(), 'Detail');
$url404 = Model::getURL(404);

// parse additional variables
// Parse additional variables
if ($url404 != $url) {
$this->tpl->assign('detailURL', SITE_URL . $url);
}
//$this->record['url'] = $this->meta->getURL();


$this->tpl->assign('item', $this->record);
}
Expand All @@ -105,9 +90,6 @@ protected function validateForm()

$fields['username']->isFilled(Language::err('FieldIsRequired'));

// validate meta
//$this->meta->validate();

if ($this->frm->isCorrect()) {
$item['id'] = $this->id;

Expand All @@ -119,20 +101,14 @@ protected function validateForm()
$userId = $userObj->data[0]->id;
$item['user_id'] = $userId;
} else {
$this->redirect(
Model::createURLForAction('Index') . '&error=api_error'
);
$this->redirect(Model::createURLForAction('Index') . '&error=api_error');
}

BackendInstagramModel::update($item);
$item['id'] = $this->id;

Model::triggerEvent(
$this->getModule(), 'after_edit', $item
);
$this->redirect(
Model::createURLForAction('Index') . '&report=edited&highlight=row-' . $item['id']
);
Model::triggerEvent($this->getModule(), 'after_edit', $item);
$this->redirect(Model::createURLForAction('Index') . '&report=edited&highlight=row-' . $item['id']);
}
}
}
Expand Down
12 changes: 2 additions & 10 deletions src/Backend/Modules/Instagram/Actions/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@

namespace Backend\Modules\Instagram\Actions;

/*
* This file is part of Fork CMS.
*
* For the full copyright and license information, please view the license
* file that was distributed with this source code.
*/

use Backend\Core\Engine\Base\ActionIndex as BackendBaseActionIndex;
use Backend\Core\Engine\Authentication;
use Backend\Core\Engine\DataGridArray;
use Backend\Core\Engine\DataGridDB;
use Backend\Core\Engine\Language;
use Backend\Core\Engine\Model;
Expand Down Expand Up @@ -46,13 +38,13 @@ protected function loadDataGrid()
Language::getWorkingLanguage()
);

// reform date
// Reform date
$this->dataGrid->setColumnFunction(
array('Backend\Core\Engine\DataGridFunctions', 'getLongDate'),
array('[created_on]'), 'created_on', true
);

// check if this action is allowed
// Check if this action is allowed
if (Authentication::isAllowedAction('Edit')) {
$this->dataGrid->addColumn(
'edit', null, Language::lbl('Edit'),
Expand Down
28 changes: 10 additions & 18 deletions src/Backend/Modules/Instagram/Actions/Logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@

namespace Backend\Modules\Instagram\Actions;

/*
* This file is part of Fork CMS.
*
* For the full copyright and license information, please view the license
* file that was distributed with this source code.
*/

use Backend\Core\Engine\Base\Action as BackendBaseAction;
use Backend\Core\Engine\Model as BackendModel;
use Backend\Modules\Instagram\Engine\Model as BackendInstagramModel;

/**
* This is the logout-action, it will remove the settings
Expand All @@ -24,22 +18,20 @@ 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
);
$settingsService = $this->get('fork.settings');

// Save access_token to settings
$instagramUserId = $settingsService->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);
$settingsService->set('Instagram', 'client_id', null);
$settingsService->set('Instagram', 'client_secret', null);
$settingsService->set('Instagram', 'username', null);
$settingsService->set('Instagram', 'access_token', null);
$settingsService->set('Instagram', 'default_instagram_user_id', null);

$this->redirect(BackendModel::createURLForAction('Settings'));
}
Expand Down

0 comments on commit 32e9ead

Please sign in to comment.