-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ishanjayamanne
authored and
ishanjayamanne
committed
Aug 16, 2016
0 parents
commit 11d9068
Showing
5 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
/** | ||
* @package EvernoteSettings | ||
*/ | ||
class EvernoteAdminController extends LeftAndMain | ||
{ | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private static $url_segment = 'evernote-settings'; | ||
/** | ||
* @var string | ||
*/ | ||
private static $url_rule = '/$Action/$ID/$OtherID'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private static $menu_title = 'Evernote'; | ||
/** | ||
* @var string | ||
*/ | ||
private static $menu_icon = '/silverstripe-evernote/images/evernote.png'; | ||
|
||
|
||
/** | ||
* @param null $id Not used. | ||
* @param null $fields Not used. | ||
* | ||
* @return Form | ||
*/ | ||
public function getEditForm($id = null, $fields = null) | ||
{ | ||
|
||
$evernoteSettings = EvernoteSettings::current_Evernote_settings(); | ||
$fields = $evernoteSettings->getCMSFields(); | ||
|
||
// Retrieve validator, if one has been setup | ||
if ($evernoteSettings->hasMethod("getCMSValidator")) { | ||
$validator = $evernoteSettings->getCMSValidator(); | ||
} else { | ||
$validator = null; | ||
} | ||
|
||
$actions = $evernoteSettings->getCMSActions(); | ||
|
||
$form = CMSForm::create( | ||
$this, 'EditForm', $fields, $actions, $validator | ||
)->setHTMLID('Form_EditForm'); | ||
|
||
$form->setResponseNegotiator($this->getResponseNegotiator()); | ||
$form->addExtraClass('cms-content center cms-edit-form'); | ||
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); | ||
|
||
if ($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); | ||
|
||
$form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses()); | ||
$form->setAttribute('data-pjax-fragment', 'CurrentForm'); | ||
|
||
$this->extend('updateEditForm', $form); | ||
|
||
return $form; | ||
|
||
} | ||
|
||
/** | ||
* Save the current sites {@link SiteConfig} into the database. | ||
* | ||
* @param array $data | ||
* @param Form $form | ||
* @return String | ||
*/ | ||
public function save_evernotesettings($data, $form) | ||
{ | ||
$evernoteSettings = EvernoteSettings::current_Evernote_settings(); | ||
$form->saveInto($evernoteSettings); | ||
|
||
try { | ||
$evernoteSettings->write(); | ||
} catch (ValidationException $ex) { | ||
$form->sessionMessage($ex->getResult()->message(), 'bad'); | ||
return $this->getResponseNegotiator()->respond($this->request); | ||
} | ||
|
||
$this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.SAVEDUP', 'Saved.'))); | ||
|
||
return $form->forTemplate(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
/** | ||
* EvernoteSettings | ||
* | ||
* @property string APIKey Api key from Evernote. | ||
* @property string APISecret Api Secret from Evernote. | ||
* @property string CallbackURL Callback URL. | ||
* @property Boolean Sandbox Enable of disable Sandbox. | ||
* @property Boolean China Type Enable country china. | ||
* | ||
* @package EvernoteSettings | ||
*/ | ||
class EvernoteSettings extends DataObject { | ||
|
||
private static $db = array( | ||
"APIKey" => "Varchar", | ||
"APISecret" => "Varchar", | ||
"CallbackURL" => "Varchar(512)", | ||
"Sandbox" => "Boolean", | ||
"China" => "Boolean" | ||
); | ||
|
||
/** | ||
* Default permission to check for 'LoggedInUsers' to create or edit pages | ||
* | ||
* @var array | ||
* @config | ||
*/ | ||
private static $required_permission = array('CMS_ACCESS_CMSMain', 'CMS_ACCESS_LeftAndMain'); | ||
|
||
|
||
/** | ||
* @return FieldList | ||
*/ | ||
public function getCMSFields() { | ||
|
||
$fields = new FieldList( | ||
new TabSet("Root", | ||
$tabMain = new Tab('Evernote', | ||
$apiKey = new TextField('APIKey', 'API key', $this->APIKey), | ||
$apiSecret = new TextField('APISecret', 'API secret', $this->APISecret), | ||
$callbackURL = new TextField('CallbackURL', | ||
'CallbackURL - where user will be returned after authenticated from evernote', | ||
$this->CallbackURL | ||
), | ||
$sanbox = new CheckBoxField('Sandbox', 'Enable Sandbox', $this->Sandbox), | ||
$china = new CheckBoxField('China', 'Are you in China?', $this->China) | ||
) | ||
), | ||
new HiddenField('ID') | ||
); | ||
|
||
$this->extend('updateCMSFields', $fields); | ||
|
||
return $fields; | ||
} | ||
|
||
/** | ||
* Get the current Evernote Settings, and creates a new one through | ||
* {@link make_evernote_settings()} if none is found. | ||
* | ||
* @return EvernoteSettings | ||
*/ | ||
public static function current_Evernote_settings() { | ||
if ($evernoteSettings = DataObject::get_one('EvernoteSettings')) return $evernoteSettings; | ||
|
||
return self::make_evernote_settings(); | ||
} | ||
|
||
/** | ||
* Create EvernoteSettings with defaults from language file. | ||
* | ||
* @return EvernoteSettings | ||
*/ | ||
public static function make_evernote_settings() { | ||
$config = EvernoteSettings::create(); | ||
$config->write(); | ||
|
||
return $config; | ||
} | ||
|
||
/** | ||
* Get the actions that are sent to the CMS. | ||
* | ||
* In your extensions: updateEditFormActions($actions) | ||
* | ||
* @return FieldList | ||
*/ | ||
public function getCMSActions() { | ||
if (Permission::check('ADMIN')) { | ||
$actions = new FieldList( | ||
FormAction::create('save_evernotesettings', _t('CMSMain.SAVE','Save')) | ||
->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept') | ||
); | ||
} else { | ||
$actions = new FieldList(); | ||
} | ||
|
||
$this->extend('updateCMSActions', $actions); | ||
|
||
return $actions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "ishannz/silverstripe-evernote", | ||
"description": "Evernote wrapper for SilverStripe", | ||
"type": "silverstripe-module", | ||
"keywords": ["silverstripe", "evernote"], | ||
"license": "GNU GPL", | ||
"authors": [ | ||
{ | ||
"name": "Ishan Jayamanne", | ||
"email": "[email protected]" | ||
}], | ||
|
||
"support": { | ||
"issues": "https://github.com/ishannz/silverstripe-evernote/issues" | ||
}, | ||
|
||
"require": { | ||
"php": ">=5.5", | ||
"composer/installers": "*", | ||
"silverstripe/framework": "~3.1", | ||
"silverstripe/cms": ">=3.1.0", | ||
"evernote/evernote": "dev-master" | ||
}, | ||
|
||
|
||
"minimum-stability": "dev" | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.