-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 2194df9
Showing
33 changed files
with
3,624 additions
and
0 deletions.
There are no files selected for viewing
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 @@ | ||
Croogo plugin of Amazon S3 |
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,11 @@ | ||
name: Universal Storage | ||
description: Local and Amazon S3 media storages plugin | ||
|
||
author: Denys Kyselov | ||
authorEmail: [email protected] | ||
authorUrl: https://github.com/TamiasSibiricus | ||
|
||
dependencies: | ||
plugins: | ||
- acl | ||
- extensions |
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,75 @@ | ||
<?php | ||
/** | ||
* Example Activation | ||
* | ||
* Activation class for Example plugin. | ||
* This is optional, and is required only if you want to perform tasks when your plugin is activated/deactivated. | ||
* | ||
* @package Croogo | ||
* @author Fahad Ibnay Heylaal <[email protected]> | ||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License | ||
* @link http://www.croogo.org | ||
*/ | ||
class StorageActivation { | ||
/** | ||
* onActivate will be called if this returns true | ||
* | ||
* @param object $controller Controller | ||
* @return boolean | ||
*/ | ||
public function beforeActivation(&$controller) { | ||
return true; | ||
} | ||
/** | ||
* Called after activating the plugin in ExtensionsPluginsController::admin_toggle() | ||
* | ||
* @param object $controller Controller | ||
* @return void | ||
*/ | ||
public function onActivation(&$controller) { | ||
$controller->Croogo->addAco('Local'); | ||
$controller->Croogo->addAco('Local/admin_index'); | ||
$controller->Croogo->addAco('Local/admin_add'); | ||
$controller->Croogo->addAco('Local/admin_edit'); | ||
$controller->Croogo->addAco('Local/admin_delete'); | ||
$controller->Croogo->addAco('S3'); | ||
$controller->Croogo->addAco('S3/admin_index'); | ||
$controller->Croogo->addAco('S3/admin_add'); | ||
$controller->Croogo->addAco('S3/admin_edit'); | ||
$controller->Croogo->addAco('S3/admin_delete'); | ||
|
||
//init settings for S3 | ||
$controller->Setting->write('Service.mediaPath', 'uploads', array('editable' => 1, 'description' => 'Path to upload media')); | ||
$controller->Setting->write('Service.s3bucketName', 'Provide Your bucket name', array('editable' => 1, 'description' => 'Amazon S3 bucket name')); | ||
$controller->Setting->write('Service.s3accessKey', 'Provide Your Access Key ID', array('editable' => 1, 'description' => 'Amazon S3 Access Key ID')); | ||
$controller->Setting->write('Service.s3secretKey', 'Provide Your Secret Access Key', array('editable' => 1, 'description' => 'Amazon S3 Secret Access Key')); | ||
|
||
} | ||
/** | ||
* onDeactivate will be called if this returns true | ||
* | ||
* @param object $controller Controller | ||
* @return boolean | ||
*/ | ||
public function beforeDeactivation(&$controller) { | ||
return true; | ||
} | ||
/** | ||
* Called after deactivating the plugin in ExtensionsPluginsController::admin_toggle() | ||
* | ||
* @param object $controller Controller | ||
* @return void | ||
*/ | ||
public function onDeactivation(&$controller) { | ||
// ACL: remove ACOs with permissions | ||
$controller->Croogo->removeAco('Local'); | ||
$controller->Croogo->removeAco('S3'); | ||
|
||
//remove S3 settings | ||
$controller->Setting->deleteKey('Service.mediaPath'); | ||
$controller->Setting->deleteKey('Service.s3bucketName'); | ||
$controller->Setting->deleteKey('Service.s3accessKey'); | ||
$controller->Setting->deleteKey('Service.s3secretKey'); | ||
} | ||
} | ||
?> |
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,49 @@ | ||
<?php | ||
/** | ||
* Routes | ||
* | ||
* example_routes.php will be loaded in main app/config/routes.php file. | ||
*/ | ||
Croogo::hookRoutes('storage'); | ||
/** | ||
* Behavior | ||
* | ||
* This plugin's Example behavior will be attached whenever Node model is loaded. | ||
*/ | ||
//Croogo::hookBehavior('Node', 'Example.Example', array()); | ||
/** | ||
* Component | ||
* | ||
* This plugin's Example component will be loaded in ALL controllers. | ||
*/ | ||
//Croogo::hookComponent('*', 'Example.Example'); | ||
/** | ||
* Helper | ||
* | ||
* This plugin's Example helper will be loaded via NodesController. | ||
*/ | ||
//Croogo::hookHelper('Nodes', 'Example.Example'); | ||
/** | ||
* Admin menu (navigation) | ||
* | ||
* This plugin's admin_menu element will be rendered in admin panel under Extensions menu. | ||
*/ | ||
Croogo::hookAdminMenu('storage'); | ||
/** | ||
* Admin row action | ||
* | ||
* When browsing the content list in admin panel (Content > List), | ||
* an extra link called 'Example' will be placed under 'Actions' column. | ||
*/ | ||
//Croogo::hookAdminRowAction('Nodes/admin_index', 'Example', 'plugin:example/controller:example/action:index/:id'); | ||
/** | ||
* Admin tab | ||
* | ||
* When adding/editing Content (Nodes), | ||
* an extra tab with title 'Example' will be shown with markup generated from the plugin's admin_tab_node element. | ||
* | ||
* Useful for adding form extra form fields if necessary. | ||
*/ | ||
//Croogo::hookAdminTab('Nodes/admin_add', 'Example', 'example.admin_tab_node'); | ||
//Croogo::hookAdminTab('Nodes/admin_edit', 'Example', 'example.admin_tab_node'); | ||
?> |
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,7 @@ | ||
<?php | ||
|
||
CroogoRouter::connect('/admin/attachments', array('plugin' => 'storage', 'controller' => 'local', 'action' => 'index', 'admin' => true)); | ||
CroogoRouter::connect('/admin/attachments/browse', array('plugin' => 'storage', 'controller' => 'local', 'action' => 'browse', 'admin' => true)); | ||
//CroogoRouter::connect('/admin/attachments', array('plugin' => 'amazon_s3', 'controller' => 'local_media', 'action' => 'index', 'admin' => true)); | ||
|
||
?> |
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,219 @@ | ||
<?php | ||
/** | ||
* Local Media Controller | ||
* | ||
* This file will take care of file uploads (with rich text editor integration). | ||
* | ||
* Big part of code inspired from original Croogo attachments controller | ||
* | ||
* PHP version 5 | ||
* | ||
* @category Controller | ||
* @package Croogo | ||
* @version 1.0 | ||
* @author Denys Kyselov <[email protected]> | ||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License | ||
* @link http://www.cmgroup.org.ua | ||
*/ | ||
|
||
class LocalController extends AppController { | ||
/** | ||
* Controller name | ||
* | ||
* @var string | ||
* @access public | ||
*/ | ||
public $name = 'Local'; | ||
/** | ||
* Models used by the Controller | ||
* | ||
* @var array | ||
* @access public | ||
*/ | ||
public $uses = array('Node'); | ||
/** | ||
* Helpers used by the Controller | ||
* | ||
* @var array | ||
* @access public | ||
*/ | ||
public $helpers = array('Filemanager', 'Text', 'Image'); | ||
/** | ||
* Node type | ||
* | ||
* If the Controller uses Node model, | ||
* this is, most of the time, the singular of the Controller name in lowercase. | ||
* | ||
* @var string | ||
* @access public | ||
*/ | ||
public $type = 'attachment'; | ||
/** | ||
* Uploads directory | ||
* | ||
* relative to the webroot. | ||
* | ||
* @var string | ||
* @access public | ||
*/ | ||
public $uploadsDir = 'uploads'; | ||
|
||
/** | ||
* Before executing controller actions | ||
* | ||
* @return void | ||
* @access public | ||
*/ | ||
public function beforeFilter() { | ||
parent::beforeFilter(); | ||
|
||
// Comment, Category, Tag not needed | ||
$this->Node->unbindModel(array('hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Category', 'Tag'))); | ||
|
||
$this->Node->type = $this->type; | ||
$this->Node->Behaviors->attach('Tree', array('scope' => array('Node.type' => $this->type))); | ||
$this->set('type', $this->type); | ||
} | ||
|
||
/** | ||
* Admin index | ||
* | ||
* @return void | ||
* @access public | ||
*/ | ||
public function admin_index() { | ||
$this->set('title_for_layout', __('Local storage', true)); | ||
|
||
$this->Node->recursive = 0; | ||
$this->paginate['Node']['order'] = 'Node.created DESC'; | ||
$this->set('local', $this->paginate()); | ||
} | ||
|
||
/** | ||
* Admin add | ||
* | ||
* @return void | ||
* @access public | ||
*/ | ||
public function admin_add() { | ||
$this->set('title_for_layout', __('Add Local Media', true)); | ||
|
||
if (isset($this->params['named']['editor'])) { | ||
$this->layout = 'admin_full'; | ||
} | ||
|
||
if (!empty($this->data)) { | ||
$file = $this->data['Node']['file']; | ||
unset($this->data['Node']['file']); | ||
|
||
// check if file with same path exists | ||
$destination = WWW_ROOT . $this->uploadsDir . DS . $file['name']; | ||
if (file_exists($destination)) { | ||
$newFileName = String::uuid() . '-' . $file['name']; | ||
$destination = WWW_ROOT . $this->uploadsDir . DS . $newFileName; | ||
} else { | ||
$newFileName = $file['name']; | ||
} | ||
|
||
// remove the extension for title | ||
if (explode('.', $file['name']) > 0) { | ||
$fileTitleE = explode('.', $file['name']); | ||
array_pop($fileTitleE); | ||
$fileTitle = implode('.', $fileTitleE); | ||
} else { | ||
$fileTitle = $file['name']; | ||
} | ||
|
||
$this->data['Node']['title'] = $fileTitle; | ||
$this->data['Node']['slug'] = $newFileName; | ||
$this->data['Node']['mime_type'] = $file['type']; | ||
//$this->data['Node']['guid'] = Router::url('/' . $this->uploadsDir . '/' . $newFileName, true); | ||
$this->data['Node']['path'] = '/' . $this->uploadsDir . '/' . $newFileName; | ||
|
||
$this->Node->create(); | ||
if ($this->Node->save($this->data)) { | ||
// move the file | ||
move_uploaded_file($file['tmp_name'], $destination); | ||
|
||
$this->Session->setFlash(__('The Local Media has been saved', true), 'default', array('class' => 'success')); | ||
|
||
if (isset($this->params['named']['editor'])) { | ||
$this->redirect(array('action' => 'browse')); | ||
} else { | ||
$this->redirect(array('action'=>'index')); | ||
} | ||
} else { | ||
$this->Session->setFlash(__('The Local could not be saved. Please, try again.', true), 'default', array('class' => 'error')); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Admin edit | ||
* | ||
* @param int $id | ||
* @return void | ||
* @access public | ||
*/ | ||
public function admin_edit($id = null) { | ||
$this->set('title_for_layout', __('Edit Media Info', true)); | ||
|
||
if (!$id && empty($this->data)) { | ||
$this->Session->setFlash(__('Invalid Local Media', true), 'default', array('class' => 'error')); | ||
$this->redirect(array('action'=>'index')); | ||
} | ||
if (!empty($this->data)) { | ||
if ($this->Node->save($this->data)) { | ||
$this->Session->setFlash(__('The Local Media Info has been saved', true), 'default', array('class' => 'success')); | ||
$this->redirect(array('action'=>'index')); | ||
} else { | ||
$this->Session->setFlash(__('The Local Media Info could not be saved. Please, try again.', true), 'default', array('class' => 'error')); | ||
} | ||
} | ||
if (empty($this->data)) { | ||
$this->data = $this->Node->read(null, $id); | ||
} | ||
} | ||
|
||
/** | ||
* Admin delete | ||
* | ||
* @param int $id | ||
* @return void | ||
* @access public | ||
*/ | ||
public function admin_delete($id = null) { | ||
if (!$id) { | ||
$this->Session->setFlash(__('Invalid id for Local Media', true), 'default', array('class' => 'error')); | ||
$this->redirect(array('action'=>'index')); | ||
} | ||
if (!isset($this->params['named']['token']) || ($this->params['named']['token'] != $this->params['_Token']['key'])) { | ||
$blackHoleCallback = $this->Security->blackHoleCallback; | ||
$this->$blackHoleCallback(); | ||
} | ||
|
||
$attachment = $this->Node->find('first', array( | ||
'conditions' => array( | ||
'Node.id' => $id, | ||
'Node.type' => $this->type, | ||
), | ||
)); | ||
if (isset($attachment['Node'])) { | ||
if ($this->Node->delete($id)) { | ||
unlink(WWW_ROOT . $this->uploadsDir . DS . $attachment['Node']['slug']); | ||
$this->Session->setFlash(__('Local media deleted', true), 'default', array('class' => 'success')); | ||
$this->redirect(array('action'=>'index')); | ||
} | ||
} else { | ||
$this->Session->setFlash(__('Invalid id for Local media', true), 'default', array('class' => 'error')); | ||
$this->redirect(array('action'=>'index')); | ||
} | ||
} | ||
|
||
public function admin_browse() { | ||
$this->layout = 'admin_full'; | ||
$this->admin_index(); | ||
} | ||
|
||
} | ||
?> |
Oops, something went wrong.