adding zend project folders into old campcaster.

This commit is contained in:
naomiaro 2010-12-07 14:19:27 -05:00
parent 56abfaf28e
commit 7ef0c18b26
4045 changed files with 1054952 additions and 0 deletions

View file

@ -0,0 +1,58 @@
<?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_ROUTE:
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';
break;
default:
// application error
$this->getResponse()->setHttpResponseCode(500);
$this->view->message = 'Application error';
break;
}
// Log exception, if logger available
if ($log = $this->getLog()) {
$log->crit($this->view->message, $errors->exception);
}
// conditionally display exceptions
if ($this->getInvokeArg('displayExceptions') == true) {
$this->view->exception = $errors->exception;
}
$this->view->request = $errors->request;
}
public function getLog()
{
$bootstrap = $this->getInvokeArg('bootstrap');
if (!$bootstrap->hasPluginResource('Log')) {
return false;
}
$log = $bootstrap->getResource('Log');
return $log;
}
public function deniedAction()
{
// action body
}
}

View file

@ -0,0 +1,39 @@
<?php
class IndexController extends Zend_Controller_Action
{
public function init()
{
}
public function indexAction()
{
$this->_forward('index', 'login');
}
public function mainAction()
{
$this->_helper->layout->setLayout('layout');
}
public function newfieldAction()
{
// action body
}
public function displayAction()
{
// action body
}
}

View file

@ -0,0 +1,104 @@
<?php
class LibraryController extends Zend_Controller_Action
{
protected $pl_sess = null;
public function init()
{
if(!Zend_Auth::getInstance()->hasIdentity())
{
$this->_redirect('login/index');
}
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('contents', 'html')
->addActionContext('plupload', 'html')
->addActionContext('upload', 'json')
->addActionContext('delete', 'json')
->initContext();
$this->pl_sess = new Zend_Session_Namespace(UI_PLAYLIST_SESSNAME);
}
public function indexAction()
{
$this->view->headScript()->appendFile('/js/contextmenu/jquery.contextMenu.js','text/javascript');
$this->view->headScript()->appendFile('/js/campcaster/library/library.js','text/javascript');
$this->view->headLink()->appendStylesheet('/css/jquery.contextMenu.css');
$this->_helper->actionStack('context-menu', 'library');
}
public function contextMenuAction()
{
$pl_sess = $this->pl_sess;
$contextMenu;
$contextMenu[] = array('action' => '/Library/delete', 'text' => 'Delete');
if(isset($pl_sess->id))
$contextMenu[] = array('action' => '/Playlist/add-item', 'text' => 'Add To Playlist');
$this->view->menu = $contextMenu;
$this->_helper->actionStack('contents', 'library');
}
public function deleteAction()
{
$id = $this->_getParam('id');
if (!is_null($id)) {
$file = StoredFile::Recall($id);
if (PEAR::isError($file)) {
die('{"jsonrpc" : "2.0", "error" : {"message": ' + $file->getMessage() + '}}');
}
else if(is_null($file)) {
die('{"jsonrpc" : "2.0", "error" : {"message": "file doesn\'t exist"}}');
}
$res = $file->delete();
if (PEAR::isError($res)) {
die('{"jsonrpc" : "2.0", "error" : {"message": ' + $res->getMessage() + '}}');
}
}
else {
die('{"jsonrpc" : "2.0", "error" : {"message": "file doesn\'t exist"}}');
}
die('{"jsonrpc" : "2.0"}');
}
public function contentsAction()
{
$query["category"] = $this->_getParam('ob', "dc:creator");
$query["order"] = $this->_getParam('order', "asc");
$this->view->files = StoredFile::getFiles($query);
}
public function searchAction()
{
// action body
}
}

View file

@ -0,0 +1,96 @@
<?php
class LoginController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
if(Zend_Auth::getInstance()->hasIdentity())
{
$this->_redirect('library/index');
}
//uses separate layout without a navigation.
$this->_helper->layout->setLayout('login');
$request = $this->getRequest();
$form = new Application_Form_Login();
$errorMessage = "";
if($request->isPost())
{
if($form->isValid($request->getPost()))
{
$authAdapter = $this->getAuthAdapter();
# get the username and password from the form
$username = $form->getValue('username');
$password = $form->getValue('password');
# pass to the adapter the submitted username and password
$authAdapter->setIdentity($username)
->setCredential($password);
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
# is the user a valid one?
if($result->isValid())
{
# all info about this user from the login table
# omit only the password, we don't need that
$userInfo = $authAdapter->getResultRowObject(null, 'password');
# the default storage is a session with namespace Zend_Auth
$authStorage = $auth->getStorage();
$authStorage->write($userInfo);
$this->_redirect('library/index');
}
else
{
$errorMessage = "Wrong username or password provided. Please try again.";
}
}
}
$this->view->errorMessage = $errorMessage;
$this->view->form = $form;
}
public function logoutAction()
{
Zend_Auth::getInstance()->clearIdentity();
$this->_redirect('login/index');
}
/**
* Gets the adapter for authentication against a database table
*
* @return object
*/
protected function getAuthAdapter()
{
$dbAdapter = Zend_Db_Table::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
$authAdapter->setTableName('cc_subjs')
->setIdentityColumn('login')
->setCredentialColumn('pass')
->setCredentialTreatment('MD5(?)');
return $authAdapter;
}
}

View file

@ -0,0 +1,255 @@
<?php
class PlaylistController extends Zend_Controller_Action
{
protected $pl_sess = null;
public function init()
{
if(!Zend_Auth::getInstance()->hasIdentity())
{
$this->_redirect('login/index');
}
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('add-item', 'json')
->addActionContext('delete-item', 'html')
->addActionContext('set-fade', 'json')
->addActionContext('set-cue', 'json')
->addActionContext('move-item', 'html')
->initContext();
$this->pl_sess = new Zend_Session_Namespace(UI_PLAYLIST_SESSNAME);
}
public function indexAction()
{
}
public function newAction()
{
$pl_sess = $this->pl_sess;
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$pl = new Playlist();
$pl_id = $pl->create("Test Zend Auth");
$pl->setPLMetaData('dc:creator', $userInfo->login);
$pl->lock($userInfo->id);
//set this playlist as active id.
$pl_sess->id = $pl_id;
$this->_helper->redirector('metadata');
}
public function metadataAction()
{
$pl_sess = $this->pl_sess;
$request = $this->getRequest();
$form = new Application_Form_PlaylistMetadata();
if ($this->getRequest()->isPost()) {
if ($form->isValid($request->getPost())) {
$formdata = $form->getValues();
$pl = Playlist::Recall($pl_sess->id);
$pl->setPLMetaData(UI_MDATA_KEY_TITLE, $formdata["title"]);
if(isset($formdata["description"]))
$pl->setPLMetaData(UI_MDATA_KEY_DESCRIPTION, $formdata["description"]);
$this->_helper->redirector('edit');
}
}
$this->view->form = $form;
}
public function editAction()
{
$this->view->headScript()->appendFile('/js/campcaster/playlist/playlist.js','text/javascript');
$pl_sess = $this->pl_sess;
if(isset($pl_sess->id)) {
$pl = Playlist::Recall($pl_sess->id);
$this->view->playlistcontents = $pl->getContents();
return;
}
$this->_helper->redirector('index');
}
public function addItemAction()
{
$pl_sess = $this->pl_sess;
$id = $this->_getParam('id');
if (!is_null($id)) {
if(isset($pl_sess->id)) {
$pl = Playlist::Recall($pl_sess->id);
$res = $pl->addAudioClip($id);
if (PEAR::isError($res)) {
die('{"jsonrpc" : "2.0", "error" : {"message": ' + $res->getMessage() + '}}');
}
die('{"jsonrpc" : "2.0"}');
}
die('{"jsonrpc" : "2.0", "error" : {"message": "no open playlist"}}');
}
die('{"jsonrpc" : "2.0", "error" : {"message": "a file is not chosen"}}');
}
public function moveItemAction()
{
$pl_sess = $this->pl_sess;
if(isset($pl_sess->id)) {
$oldPos = $this->_getParam('oldPos');
$newPos = $this->_getParam('newPos');
$pl = Playlist::Recall($pl_sess->id);
$pl->moveAudioClip($oldPos, $newPos);
$this->view->playlistcontents = $pl->getContents();
return;
}
$this->_helper->redirector('index');
}
public function deleteItemAction()
{
$pl_sess = $this->pl_sess;
if(isset($pl_sess->id)) {
$positions = $this->_getParam('pos', array());
$pl = Playlist::Recall($pl_sess->id);
if (!is_array($positions))
$positions = array($positions);
//so the automatic updating of playlist positioning doesn't affect removal.
sort($positions);
$positions = array_reverse($positions);
foreach ($positions as $pos) {
$pl->delAudioClip($pos);
}
$this->view->playlistcontents = $pl->getContents();
return;
}
$this->_helper->redirector('index');
}
public function setCueAction()
{
$pl_sess = $this->pl_sess;
if(isset($pl_sess->id)) {
$pos = $this->_getParam('pos');
$cueIn = $this->_getParam('cueIn', null);
$cueOut = $this->_getParam('cueOut', null);
$pl = Playlist::Recall($pl_sess->id);
$response = $pl->changeClipLength($pos, $cueIn, $cueOut);
die(json_encode($response));
}
$this->_helper->redirector('index');
}
public function setFadeAction()
{
$pl_sess = $this->pl_sess;
if(isset($pl_sess->id)) {
$pos = $this->_getParam('pos');
$fadeIn = $this->_getParam('fadeIn', null);
$fadeOut = $this->_getParam('fadeOut', null);
$pl = Playlist::Recall($pl_sess->id);
$response = $pl->changeFadeInfo($pos, $fadeIn, $fadeOut);
die(json_encode($response));
}
$this->_helper->redirector('index');
}
public function deleteAction()
{
$id = $this->_getParam('id', null);
if (!is_null($id)) {
$this->closePlaylist();
Playlist::Delete($id);
}
}
public function deleteActiveAction()
{
$pl_sess = $this->pl_sess;
if(isset($pl_sess->id)) {
$pl = Playlist::Recall($pl_sess->id);
$this->closePlaylist($pl);
Playlist::Delete($pl_sess->id);
unset($pl_sess->id);
}
$this->_helper->redirector('index');
}
public function closePlaylist($pl)
{
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$res = $pl->unlock($userInfo->id);
return $res;
}
}

View file

@ -0,0 +1,179 @@
<?php
class PluploadController extends Zend_Controller_Action
{
public function init()
{
if(!Zend_Auth::getInstance()->hasIdentity())
{
$this->_redirect('login/index');
}
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('upload', 'json')
->initContext();
}
public function indexAction()
{
// action body
}
public function uploadAction()
{
// HTTP headers for no cache etc
header('Content-type: text/plain; charset=UTF-8');
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
// Settings
$targetDir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
$cleanupTargetDir = false; // Remove old files
$maxFileAge = 60 * 60; // Temp file age in seconds
// 5 minutes execution time
@set_time_limit(5 * 60);
// usleep(5000);
// Get parameters
$chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0;
$chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0;
$fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
// Clean the fileName for security reasons
//$fileName = preg_replace('/[^\w\._]+/', '', $fileName);
// Create target dir
if (!file_exists($targetDir))
@mkdir($targetDir);
// Remove old temp files
if (is_dir($targetDir) && ($dir = opendir($targetDir))) {
while (($file = readdir($dir)) !== false) {
$filePath = $targetDir . DIRECTORY_SEPARATOR . $file;
// Remove temp files if they are older than the max age
if (preg_match('/\.tmp$/', $file) && (filemtime($filePath) < time() - $maxFileAge))
@unlink($filePath);
}
closedir($dir);
} else
die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
// Look for the content type header
if (isset($_SERVER["HTTP_CONTENT_TYPE"]))
$contentType = $_SERVER["HTTP_CONTENT_TYPE"];
if (isset($_SERVER["CONTENT_TYPE"]))
$contentType = $_SERVER["CONTENT_TYPE"];
if (strpos($contentType, "multipart") !== false) {
if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
// Open temp file
$out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
if ($out) {
// Read binary input stream and append it to temp file
$in = fopen($_FILES['file']['tmp_name'], "rb");
if ($in) {
while ($buff = fread($in, 4096))
fwrite($out, $buff);
} else
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
fclose($out);
unlink($_FILES['file']['tmp_name']);
} else
die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
} else
die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
} else {
// Open temp file
$out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
if ($out) {
// Read binary input stream and append it to temp file
$in = fopen("php://input", "rb");
if ($in) {
while ($buff = fread($in, 4096))
fwrite($out, $buff);
} else
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
fclose($out);
} else
die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
}
$audio_file = $targetDir . DIRECTORY_SEPARATOR . $fileName;
$md5 = md5_file($audio_file);
$duplicate = StoredFile::RecallByMd5($md5);
if ($duplicate) {
if (PEAR::isError($duplicate)) {
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' . $duplicate->getMessage() .'}}');
}
else {
$duplicateName = $duplicate->getMetadataValue(UI_MDATA_KEY_TITLE);
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "An identical audioclip named ' . $duplicateName . ' already exists in the storage server."}}');
}
}
$metadata = camp_get_audio_metadata($audio_file);
if (PEAR::isError($metadata)) {
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' + $metadata->getMessage() + '}}');
}
// #2196 no id tag -> use the original filename
if (basename($audio_file) == $metadata[UI_MDATA_KEY_TITLE]) {
$metadata[UI_MDATA_KEY_TITLE] = basename($audio_file);
$metadata[UI_MDATA_KEY_FILENAME] = basename($audio_file);
}
// setMetadataBatch doesnt like these values
unset($metadata['audio']);
unset($metadata['playtime_seconds']);
$values = array(
"filename" => basename($audio_file),
"filepath" => $audio_file,
"filetype" => "audioclip",
"mime" => $metadata[UI_MDATA_KEY_FORMAT],
"md5" => $md5
);
$storedFile = StoredFile::Insert($values);
if (PEAR::isError($storedFile)) {
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' + $storedFile->getMessage() + '}}');
}
$storedFile->setMetadataBatch($metadata);
// Return JSON-RPC response
die('{"jsonrpc" : "2.0", "id" : '.$storedFile->getId().' }');
}
public function pluploadAction()
{
$view = $this->view;
$view->headScript()->appendFile('/js/plupload/plupload.full.min.js','text/javascript');
$view->headScript()->appendFile('/js/plupload/jquery.plupload.queue.min.js','text/javascript');
$view->headScript()->appendFile('/js/campcaster/library/plupload.js','text/javascript');
$view->headLink()->appendStylesheet('/css/plupload.queue.css');
}
}

View file

@ -0,0 +1,53 @@
<?php
class ScheduleController extends Zend_Controller_Action
{
public function init()
{
if(!Zend_Auth::getInstance()->hasIdentity())
{
$this->_redirect('login/index');
}
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('event-feed', 'json')
->addActionContext('add-show-dialog', 'json')
->initContext();
}
public function indexAction()
{
$this->view->headScript()->appendFile('/js/fullcalendar/fullcalendar.min.js','text/javascript');
$this->view->headScript()->appendFile('/js/campcaster/schedule/schedule.js','text/javascript');
$this->view->headLink()->appendStylesheet('/css/fullcalendar.css');
$this->view->headLink()->appendStylesheet('/css/schedule.css');
}
public function eventFeedAction()
{
$start = $this->_getParam('start', null);
$end = $this->_getParam('end', null);
$weekday = $this->_getParam('weekday', null);
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$show = new Show($userInfo->type);
$this->view->events = $show->getFullCalendarEvents($start, $end, $weekday);
}
public function addShowDialogAction()
{
$user = new User();
$this->view->hosts = $user->getHosts();
}
}

View file

@ -0,0 +1,77 @@
<?php
class SearchController extends Zend_Controller_Action
{
protected $form;
public function init()
{
if(!Zend_Auth::getInstance()->hasIdentity())
{
$this->_redirect('login/index');
}
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('newfield', 'html')
->initContext();
$this->form = new Application_Form_AdvancedSearch();
}
public function indexAction()
{
// action body
}
public function displayAction()
{
$this->view->headScript()->appendFile('/js/campcaster/library/advancedsearch.js','text/javascript');
$this->view->headLink()->appendStylesheet('/css/library_search.css');
$this->form = new Application_Form_AdvancedSearch();
$form = $this->form;
// Form has not been submitted - pass to view and return
if (!$this->getRequest()->isPost()) {
$sub = new Application_Form_AdvancedSearchRow(1);
$form->addSubForm($sub, 'row_1');
$form->getSubForm('row_1')->removeDecorator('DtDdWrapper');
$this->view->form = $form;
return;
}
// Form has been submitted - run data through preValidation()
$form->preValidation($_POST);
if (!$form->isValid($_POST)) {
$this->view->form = $form;
return;
}
// Form is valid
$this->view->form = $form;
$info = $form->getValues();
$this->view->files = StoredFile::searchFiles($info);
}
public function newfieldAction()
{
$id = $this->_getParam('id', 1);
$this->form->addSubForm(new Application_Form_AdvancedSearchRow($id), 'row_'.$id, $id);
$this->form->getSubForm('row_'.$id)->removeDecorator('DtDdWrapper');
$e = $this->form->getSubForm('row_'.$id);
$this->view->field = $e->__toString();
}
}

View file

@ -0,0 +1,147 @@
<?php
class Zend_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
{
/**
* @var Zend_Acl
**/
protected $_acl;
/**
* @var string
**/
protected $_roleName;
/**
* @var array
**/
protected $_errorPage;
/**
* Constructor
*
* @param mixed $aclData
* @param $roleName
* @return void
**/
public function __construct(Zend_Acl $aclData, $roleName = 'guest')
{
$this->_errorPage = array('module' => 'default',
'controller' => 'error',
'action' => 'denied');
$this->_roleName = $roleName;
if (null !== $aclData) {
$this->setAcl($aclData);
}
}
/**
* Sets the ACL object
*
* @param mixed $aclData
* @return void
**/
public function setAcl(Zend_Acl $aclData)
{
$this->_acl = $aclData;
}
/**
* Returns the ACL object
*
* @return Zend_Acl
**/
public function getAcl()
{
return $this->_acl;
}
/**
* Returns the ACL role used
*
* @return string
* @author
**/
public function getRoleName()
{
return $this->_roleName;
}
public function setRoleName($type)
{
$roles = array("A" => "admin", "H" => "host", "G" => "guest");
$this->_roleName = $roles[$type];
}
/**
* Sets the error page
*
* @param string $action
* @param string $controller
* @param string $module
* @return void
**/
public function setErrorPage($action, $controller = 'error', $module = null)
{
$this->_errorPage = array('module' => $module,
'controller' => $controller,
'action' => $action);
}
/**
* Returns the error page
*
* @return array
**/
public function getErrorPage()
{
return $this->_errorPage;
}
/**
* Predispatch
* Checks if the current user identified by roleName has rights to the requested url (module/controller/action)
* If not, it will call denyAccess to be redirected to errorPage
*
* @return void
**/
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
if (Zend_Auth::getInstance()->hasIdentity()){
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$this->setRoleName($userInfo->type);
}
else {
$this->_roleName = "guest";
}
$resourceName = '';
if ($request->getModuleName() != 'default') {
$resourceName .= strtolower($request->getModuleName()) . ':';
}
$resourceName .= strtolower($request->getControllerName());
/** Check if the controller/action can be accessed by the current user */
if (!$this->getAcl()->isAllowed($this->_roleName, $resourceName, $request->getActionName())) {
/** Redirect to access denied page */
$this->denyAccess();
}
}
/**
* Deny Access Function
* Redirects to errorPage, this can be called from an action using the action helper
*
* @return void
**/
public function denyAccess()
{
$this->_request->setModuleName($this->_errorPage['module']);
$this->_request->setControllerName($this->_errorPage['controller']);
$this->_request->setActionName($this->_errorPage['action']);
}
}