Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieter Wyns committed May 10, 2013
0 parents commit 529f5e4
Show file tree
Hide file tree
Showing 29 changed files with 2,522 additions and 0 deletions.
19 changes: 19 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) Fork CMS

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Module: Whitepapers



## Installation

Visit the [Fork CMS knowledge base](http://fork-cms.com/knowledge-base) to learn how to install a module. To download the zip-package go to the [extension page](http://www.fork-cms.com/extensions/detail/whitepapers) of the module on fork-cms.com.

## Contributing

It would be great if you could help us improve the module. GitHub does a great job in managing collaboration by providing different tools, the only thing you need is a [GitHub](https://github.com/) login.

* Use **Pull requests** to add or update code
* **Issues** for bug reporting or code discussions
* Or regarding documentation and how-to's, check out **Wiki**

More info on how to work with GitHub on [help.github.com](https://help.github.com).

## License

The module is licensed under MIT. In short, this license allows you to do everything as long as the copyright statement stays present.
124 changes: 124 additions & 0 deletions backend/modules/whitepapers/actions/add.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

/*
* 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.
*/

/**
* This is the add-action, it will display a form to create a new item
*
* @author Jelmer Snoeck <[email protected]>
*/
class BackendWhitepapersAdd extends BackendBaseActionAdd
{
/**
* Execute the actions
*/
public function execute()
{
parent::execute();

$this->loadForm();
$this->validateForm();

$this->parse();
$this->display();
}

/**
* Load the form
*/
protected function loadForm()
{
$rbtVisibleValues[] = array('label' => BL::lbl('Hidden'), 'value' => 'N');
$rbtVisibleValues[] = array('label' => BL::lbl('Published'), 'value' => 'Y');

$this->frm = new BackendForm('add');
$this->frm->addText('title', null, null, 'inputText title', 'inputTextError title');
$this->frm->addEditor('text');
$this->frm->addFile('file')->setAttribute('extension', 'pdf');
$this->frm->addImage('image');
$this->frm->addRadiobutton('visible', $rbtVisibleValues, 'Y');
$this->frm->addText('tags', null, null, 'inputText tagBox', 'inputTextError tagBox');

$this->meta = new BackendMeta($this->frm, null, 'title', true);
}

/**
* Parse the page
*/
protected function parse()
{
parent::parse();

// assign the url for the detail page
$url = BackendModel::getURLForBlock($this->URL->getModule(), 'detail');
$url404 = BackendModel::getURL(404);
if($url404 != $url) $this->tpl->assign('detailURL', SITE_URL . $url);
}

/**
* Validate the form
*/
protected function validateForm()
{
if($this->frm->isSubmitted())
{
$this->frm->cleanupFields();

// validation
$fields = $this->frm->getFields();
$fields['title']->isFilled(BL::err('FieldIsRequired'));
$fields['text']->isFilled(BL::err('FieldIsRequired'));

if($fields['image']->isFilled(BL::err('FieldIsRequired')))
{
// do minimum size checks
}

if($fields['file']->isFilled(BL::err('FieldIsRequired')))
{
$fields['file']->isAllowedExtension(array('pdf'), sprintf(BL::err('ExtensionNotAllowed'), 'pdf'));
}

$this->meta->validate();

if($this->frm->isCorrect())
{
// the basic file directory
$filepath = FRONTEND_FILES_PATH . '/whitepapers';

$item['meta_id'] = $this->meta->save();
$item['language'] = BL::getWorkingLanguage();
$item['title'] = $fields['title']->getValue();
$item['text'] = $fields['text']->getValue();
$item['filename'] = BackendWhitepapersModel::getFilename($this->meta->getURL() . '.' . $fields['file']->getExtension());
$item['image'] = BackendWhitepapersModel::getFilename($this->meta->getURL() . '.' . $fields['image']->getExtension(), 'images/source');
$item['visible'] = $fields['visible']->getValue();
$item['id'] = BackendWhitepapersModel::insert($item);

// upload the file
$fields['file']->moveFile($filepath . '/files/' . $item['filename']);

// upload the image
// @todo create thumbnails
$fields['image']->moveFile($filepath . '/images/source/' . $item['image']);

// save the tags
BackendTagsModel::saveTags($item['id'], $fields['tags']->getValue(), $this->URL->getModule());

BackendSearchModel::saveIndex(
$this->getModule(),
$item['id'],
array('title' => $item['title'], 'text' => $item['title'])
);

BackendModel::triggerEvent($this->getModule(), 'after_add', $item);
$this->redirect(BackendModel::createURLForAction('index') . '&report=added&highlight=row-' . $item['id']);
}
}
}
}
40 changes: 40 additions & 0 deletions backend/modules/whitepapers/actions/delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* 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.
*/

/**
* This is the elete-action, it delete an item
*
* @author Jelmer Snoeck <[email protected]>
*/
class BackendWhitepapersDelete extends BackendBaseActionDelete
{
/**
* Execute the action
*/
public function execute()
{
$this->id = $this->getParameter('id', 'int');

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

// delete the whitepaper data
BackendWhitepapersModel::delete($this->id);
BackendSearchModel::removeIndex($this->getModule(), $this->id);

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

$this->redirect(BackendModel::createURLForAction('index') . '&report=deleted&var=' . urlencode($this->record['title']));
}
else $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing');
}
}
58 changes: 58 additions & 0 deletions backend/modules/whitepapers/actions/download.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/*
* 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.
*/

/**
* This is the Download action, it will force you to download a certain whitepaper
*
* @author Jelmer Snoeck <[email protected]>
*/
class BackendWhitepapersDownload extends BackendBaseAction
{
/**
* Execute the action
*/
public function execute()
{
parent::execute();

$whitepaperId = $this->getParameter('id', 'int', null);

// download the whitepaper if it exists
if(BackendWhitepapersModel::exists($whitepaperId))
{
$whitepaper = BackendWhitepapersModel::get($whitepaperId);
$filename = $whitepaper['filename'];
$filepath = FRONTEND_FILES_PATH . '/whitepapers/files/' . $filename;
$fileExtension = strrchr($filename, '.');

// add extra extensions and content type if needed.
switch($fileExtension)
{
case '.pdf':
default:
$contentType = 'application/pdf';
break;
}

// the file does not exist, redirect
if(!SpoonFile::exists($filepath)) $this->redirect(BackendModel::createURLForAction('edit') . '&amp;id=' . $whitepaperId . '&amp;error=non-existing');

// set the headers and download the file
SpoonHTTP::setHeaders(array(
'Content-Disposition: attachment; filename="' . $whitepaper['filename'] . '"',
'Content-Type: ' . $contentType,
'Content-Length: ' . filesize($filepath)
));
echo SpoonFile::getContent($filepath);
exit;
}
// the item does not exist
else $this->redirect(BackendModel::createURLForAction() . '&amp;error=non-existing');
}
}
Loading

0 comments on commit 529f5e4

Please sign in to comment.