Skip to content

Commit

Permalink
Initial master of pastebin app
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Aug 13, 2008
0 parents commit 56674da
Show file tree
Hide file tree
Showing 3,989 changed files with 342,414 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
46 changes: 46 additions & 0 deletions .zfproject.xml
@@ -0,0 +1,46 @@
<?xml version="1.0"?>
<projectProfile>
<projectDirectory>
<projectProfileFile/>
<applicationDirectory>
<apisDirectory enabled="false"/>
<configsDirectory/>
<controllersDirectory>
<controllerFile controllerName="index"/>
<controllerFile controllerName="error"/>
</controllersDirectory>
<layoutsDirectory enabled="false"/>
<modelsDirectory/>
<modulesDirectory enabled="false"/>
<viewsDirectory>
<viewScriptsDirectory>
<viewControllerScriptsDirectory forControllerName="index">
<viewScriptFile scriptName="index"/>
</viewControllerScriptsDirectory>
</viewScriptsDirectory>
<viewHelpersDirectory/>
<viewFiltersDirectory enabled="false"/>
</viewsDirectory>
<bootstrapFile/>
</applicationDirectory>
<dataDirectory enabled="false">
<cacheDirectory enabled="false"/>
<searchIndexesDirectory enabled="false"/>
<localesDirectory enabled="false"/>
<logsDirectory enabled="false"/>
<sessionsDirectory enabled="false"/>
<uploadsDirectory enabled="false"/>
</dataDirectory>
<libraryDirectory>
<zfStandardLibraryDirectory/>
</libraryDirectory>
<publicDirectory>
<publicStylesheetsDirectory enabled="false"/>
<publicScriptsDirectory enabled="false"/>
<publicImagesDirectory enabled="false"/>
<publicIndexFile/>
<htaccessFile/>
</publicDirectory>
<providersDirectory enabled="false"/>
</projectDirectory>
</projectProfile>
35 changes: 35 additions & 0 deletions application/configs/paste.ini
@@ -0,0 +1,35 @@
[development]
paths.init = 0

db.cxn.adapter = "pdo_sqlite"
db.cxn.params.dbname = "paste-dev.db"
db.cache.backendName = "Sqlite"
db.cache.frontendName = "Core"
db.cache.frontendOptions.caching = false
db.cache.frontendOptions.lifetime = 900
db.cache.frontendOptions.automatic_serialization = true
db.cache.frontendOptions.automatic_cleaning_factor = 20
db.cache.backendOptions.cache_db_complete_path = "db-cache-dev.db"
db.cache.backendOptions.automatic_vacuum_factor = 20

cache.backendName = "Sqlite"
cache.frontendName = "Core"
cache.frontendOptions.caching = false
cache.frontendOptions.lifetime = 900
cache.frontendOptions.automatic_serialization = true
cache.frontendOptions.automatic_cleaning_factor = 20
cache.backendOptions.cache_db_complete_path = "cache-dev.db"
cache.backendOptions.automatic_vacuum_factor = 20

[testing : development]
db.cxn.params.dbname = "paste-test.db"
db.cache.backendOptions.cache_db_complete_path = "db-cache-test.db"

cache.backendOptions.cache_db_complete_path = "cache-test.db"

[production : development]
db.cxn.params.dbname = "paste-prod.db"
db.cache.backendOptions.cache_db_complete_path = "db-cache-prod.db"

cache.frontendOptions.caching = true
cache.backendOptions.cache_db_complete_path = "cache-prod.db"
43 changes: 43 additions & 0 deletions application/controllers/ErrorController.php
@@ -0,0 +1,43 @@
<?php
require_once 'Zend/Controller/Action.php';

class ErrorController extends Zend_Controller_Action
{
public function errorAction()
{
$errors = $this->_getParam('error_handler');

switch ($errors->type) {
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
// 404 error -- controller or action not found
$this->getResponse()->setHttpResponseCode(404);
$this->view->message = 'Page not found';
$this->view->code = 404;
if ($errors->type == Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER) {
$this->view->info = sprintf(
'Unable to find controller "%s" in module "%s"',
$errors->request->getControllerName(),
$errors->request->getModuleName()
);
}
if ($errors->type == Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION) {
$this->view->info = sprintf(
'Unable to find action "%s" in controller "%s" in module "%s"',
$errors->request->getActionName(),
$errors->request->getControllerName(),
$errors->request->getModuleName()
);
}
break;
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
default:
// application error
$this->getResponse()->setHttpResponseCode(500);
$this->view->message = 'Application error';
$this->view->code = 500;
$this->view->info = $errors->exception;
break;
}
}
}
44 changes: 44 additions & 0 deletions application/controllers/IndexController.php
@@ -0,0 +1,44 @@
<?php

class IndexController extends Zend_Controller_Action
{
public function indexAction()
{
$this->_helper->redirector('index', 'paste');
}

public function testEditorAction()
{
Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
$this->view->dojo()->registerModulePath('paste', '../paste')
->requireModule('paste.main')
->addOnLoad('paste.main.init')
->enable();

$request = $this->getRequest();

if ($request->isPost()) {
$this->view->data = $request->getPost();
return $this->render('test-complete');
}

$form = new Zend_Dojo_Form(array(
'action' => '/index/test-editor',
'method' => 'post',
'elementsBelongTo' => 'fooForm',
));
$form->addPrefixPath('My_Form_Element', 'My/Form/Element', 'element');

$form->addElement('Editor', 'content', array(
'width' => '200px',
'value' => "It was a dark and stormy night. Your story belongs here!",
));

$form->addElement('SubmitButton', 'save', array(
'label' => 'Save',
));

$this->view->form = $form;
return $this->render();
}
}
225 changes: 225 additions & 0 deletions application/controllers/PasteController.php
@@ -0,0 +1,225 @@
<?php
/**
* Pastebin application
*
* @uses Zend_Controller_Action
* @package Paste
* @author Matthew Weier O'Phinney <matthew@weierophinney.net>
* @copyright Copyright (C) 2008 - Present, Matthew Weier O'Phinney
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
* @version $Id: $
*/
class PasteController extends Zend_Controller_Action
{
protected $_model;

/**
* Pre-Dispatch: set up dojo and context switching
*
* @return void
*/
public function preDispatch()
{
Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
$contextSwitch = $this->_helper->contextSwitch;
$contextSwitch->addContext('ajax', array('suffix' => 'ajax'))
->addActionContext('new', 'ajax')
->addActionContext('followup', 'ajax')
->addActionContext('display', 'ajax')
->addActionContext('active', 'ajax')
->addActionContext('active-data', 'ajax')
->initContext();

$this->view->dojo()->registerModulePath('paste', '../paste')
->requireModule('paste.main')
->addOnLoad('paste.main.init');
}

/**
* Landing page
*
* @return void
*/
public function indexAction()
{
}

/**
* New Paste page
*
* @return void
*/
public function newAction()
{
$form = $this->getForm();
$this->view->form = $form;
}

/**
* Save paste
*
* @return void
*/
public function saveAction()
{
$request = $this->getRequest();
if (!$request->isPost()) {
return $this->_helper->redirector('new');
}

$form = $this->getForm();
if (!$form->isValid($request->getPost($form->getElementsBelongTo()))) {
$this->view->form = $form;
return $this->render('new');
}

$data = $form->getValues();
$data = $data['pasteform'];
$model = $this->getModel();
$id = $model->add($data);
$this->_helper->redirector('display', null, null, array('id' => $id));
}

/**
* Display paste
*
* @return void
*/
public function displayAction()
{
if (!$id = $this->_getParam('id', false)) {
return $this->_helper->redirector('index');
}

$model = $this->getModel();
if (!$paste = $model->get($id)) {$view = Zend_Layout::getMvcInstance()->getView();
$this->view->title = 'Not Found';
$this->view->message = "Paste not found";
return;
}

$this->view->id = $id;
$this->view->title = $id;
$this->view->paste = $paste;
}

/**
* Follow-up paste form
*
* @return void
*/
public function followupAction()
{
if (!$id = $this->_getParam('id', false)) {
return $this->_helper->redirector('index');
}

$model = $this->getModel();
if (!$paste = $model->get($id)) {$view = Zend_Layout::getMvcInstance()->getView();
$this->view->title = 'Not Found';
$this->view->message = "Paste not found";
return;
}
$this->view->id = $id;

$followupKeys = array(
'code' => null,
'type' => null,
'summary' => null,
);
$followup = array_intersect_key($paste, $followupKeys);
$followup['parent'] = $id;

$form = $this->getFollowupForm($id);
$form->setDefaults($followup);

$this->view->title = 'Followup: ' . $id;
$this->view->form = $form;
}

/**
* Process followup
*
* @return void
*/
public function saveFollowupAction()
{
$request = $this->getRequest();
if (!$request->isPost()) {
return $this->_helper->redirector('new');
}

if (!$parentId = $this->_getParam('id', false)) {
return $this->_helper->redirector('index');
}

$form = $this->getFollowupForm($parentId);
if (!$form->isValid($request->getPost($form->getElementsBelongTo()))) {
$this->view->form = $form;
return $this->render('followup');
}

$data = $form->getValues();
$data = $data[$form->getElementsBelongTo()];
$model = $this->getModel();
$id = $model->add($data);
$this->_helper->redirector('display', null, null, array('id' => $id));
}

public function activeAction()
{
}

public function activeDataAction()
{
$model = $this->getModel();
$dojoData = new Zend_Dojo_Data('id', $model->fetchActive(), 'id');
$this->view->data = $dojoData;
}

/**
* Helper method: get paste model
*
* @return Paste
*/
public function getModel()
{
if (null === $this->_model) {
$this->_model = new Paste();
}
return $this->_model;
}

/**
* Helper method: get new paste form
*
* @return PasteForm
*/
public function getForm()
{
require_once dirname(__FILE__) . '/../forms/PasteForm.php';
return new PasteForm(array('action' => '/paste/save', 'method' => 'post'));
}

/**
* Helper method: get followup paste form
*
* @param string $id
* @return PasteForm
*/
public function getFollowupForm($id)
{
$form = $this->getForm();
$form->addElement('hidden', 'parent', array(
'required' => true,
'validators' => array(
new Zend_Validate_Identical($id),
),
))
->setName('followupform')
->setElementsBelongTo('followupform')
->setAction('/paste/save-followup/id/' . $id);
$form->save->setDijitParam('onClick', 'paste.main.followupPasteButton');
return $form;
}
}
Empty file added application/data/cache-dev.db
Empty file.
Empty file added application/data/cache-test.db
Empty file.
Empty file.
Empty file.
Binary file added application/data/paste-dev.db
Binary file not shown.
Binary file added application/data/paste-test.db
Binary file not shown.
Binary file added application/data/paste.db
Binary file not shown.

0 comments on commit 56674da

Please sign in to comment.