/** * Dispatches the trigger specified * * @param int $key */ public function dispatch($key) { $vr = new Ot_Config_Register(); $triggerSystem = $vr->getVar('triggerSystem'); if (is_null($triggerSystem)) { $triggerSystem = false; } else { $triggerSystem = $triggerSystem->getValue(); } // if the trigger system is globally disabled just return if ($triggerSystem == false) { return; } $action = new Ot_Model_DbTable_TriggerAction(); $actions = $action->getActionsForTrigger($key); foreach ($actions as $a) { $helper = new $a->actionKey(); $data = $helper->getDbTable()->find($a->triggerActionId); if (is_null($data)) { continue; } $data = $data->toArray(); foreach ($data as &$d) { foreach ($this->_vars as $key => $value) { if (is_array($value)) { $value = implode(', ', $value); } $d = str_replace("[[{$key}]]", $value, $d); } } $helper->dispatch($data); } }
public function configVar($var) { $vr = new Ot_Config_Register(); $thisVar = $vr->getVar($var); if (is_null($thisVar)) { return ''; } return $thisVar->getValue(); }
public function apiDocsAction() { $apiRegistry = new Ot_Api_Register(); $endpoints = $apiRegistry->getApiEndpoints(); $apiMethods = array('get', 'put', 'post', 'delete'); $data = array(); $acl = new Ot_Acl('remote'); $vr = new Ot_Config_Register(); $role = $vr->getVar('defaultRole')->getValue(); if (Zend_Auth::getInstance()->hasIdentity()) { $thisAccount = Zend_Auth::getInstance()->getIdentity(); if (count($thisAccount->role) > 1) { $roles = array(); // Get role names from the list of role Ids foreach ($thisAccount->role as $r) { $roles[] = $acl->getRole($r); } // Create a new role that inherits from all the returned roles $roleName = implode(',', $roles); $role = $roleName; $acl->addRole(new Zend_Acl_Role($roleName), $roles); } elseif (count($thisAccount->role) == 1) { $role = $thisAccount->role[0]; } if ($role == '' || !$acl->hasRole($role)) { $role = $vr->getVar('defaultRole')->getValue(); } } foreach ($endpoints as &$e) { $data[$e->getName()] = array('name' => $e->getName(), 'methods' => array(), 'description' => $e->getDescription()); $reflection = new ReflectionClass($e->getMethodClassname()); $methods = $reflection->getMethods(); foreach ($methods as $m) { // the api "module" here is really a kind of placeholder $aclResource = 'api_' . strtolower($e->getName()); if (in_array($m->name, $apiMethods) && $m->class == $e->getMethodClassname() && $acl->isAllowed($role, $aclResource, $m->name)) { $instructions = 'No instructions provided'; if ($m->getDocComment() != '') { $instructions = $this->_cleanComment($m->getDocComment()); } $data[$e->getName()]['methods'][$m->getName()] = $instructions; } } } $endpoints = array(); foreach ($data as $key => $val) { if (count($val['methods']) != 0) { $endpoints[$key] = $val; } } $this->view->endpoints = $endpoints; $this->_helper->pageTitle('API Documentation'); }
public function __construct($options = array()) { parent::__construct($options); $register = new Ot_Config_Register(); $vars = $register->getVars(); $varsByModule = array(); foreach ($vars as $v) { if (!isset($varsByModule[$v['namespace']])) { $varsByModule[$v['namespace']] = array(); } $varsByModule[$v['namespace']][] = $v['object']; } $section = new Zend_Form_Element_Select('section', array('label' => 'Select Configuration Section:')); $section->setDecorators(array('ViewHelper', array(array('wrapperField' => 'HtmlTag'), array('tag' => 'div', 'class' => 'select-control')), array('Label', array('placement' => 'prepend', 'class' => 'select-label')), array(array('wrapperAll' => 'HtmlTag'), array('tag' => 'div', 'class' => 'select-header')))); $this->addElement($section); $sectionOptions = array(); foreach ($varsByModule as $key => $value) { $group = array(); foreach ($value as $v) { //$elm = $v->getFormElement(); $elm = $v->renderFormElement(); $elm->setDecorators(array('ViewHelper', array('Errors', array('class' => 'help-inline')), array(array('wrapperField' => 'HtmlTag'), array('tag' => 'div', 'class' => 'fields')), array('Label', array('placement' => 'append', 'class' => 'field-label')), array('Description', array('placement' => 'append', 'tag' => 'div', 'class' => 'field-description')), array(array('empty' => 'HtmlTag'), array('placement' => 'append', 'tag' => 'div', 'class' => 'clearfix')), array(array('wrapperAll' => 'HtmlTag'), array('tag' => 'div', 'class' => 'field-group')))); $group[] = $elm->getName(); $this->addElement($elm); } $sectionOptions[preg_replace('/[^a-z]/i', '', $key)] = $key; $this->addDisplayGroup($group, $key); } asort($sectionOptions); $section->setMultiOptions($sectionOptions); $this->setDisplayGroupDecorators(array('FormElements', 'Fieldset')); $this->addElement('submit', 'submit', array('buttonType' => Twitter_Bootstrap_Form_Element_Submit::BUTTON_PRIMARY, 'label' => 'Save Configuration')); $this->addElement('button', 'cancel', array('label' => 'form-button-cancel', 'type' => 'button')); $this->addDisplayGroup(array('submit', 'cancel'), 'actions', array('disableLoadDefaultDecorators' => true, 'decorators' => array('Actions'))); return $this; }
public function exportAction() { $this->_helper->viewRenderer->setNeverRender(); $this->_helper->layout->disableLayout(); header('Content-type: text/csv'); header('Content-disposition: attachment;filename=configExport-' . date('c') . '.csv'); $vr = new Ot_Config_Register(); $options = $vr->getVars(); $data = array(); foreach ($options as $key => $o) { $value = $o['object']->getRawValue(); $data[] = array($key, $value); } $tmpfname = tempnam("/tmp", "FOO"); $handle = fopen($tmpfname, "w"); foreach ($data as $d) { fputcsv($handle, $d); } echo file_get_contents($tmpfname); fclose($handle); unlink($tmpfname); }
public function indexAction() { $returnType = 'json'; try { $apiRegister = new Ot_Api_Register(); $vr = new Ot_Config_Register(); $params = $this->_getAllParams(); if (isset($params['type']) && in_array(strtolower($returnType), array('json', 'php'))) { $returnType = strtolower($params['type']); } if (!isset($params['endpoint']) || empty($params['endpoint'])) { return $this->_validOutput(array('message' => 'Welcome to the ' . $vr->getVar('appTitle')->getValue() . ' API. You will need an API key to get any further. Visit ' . Zend_Registry::get('siteUrl') . '/account to get one.'), $returnType); } $endpoint = $params['endpoint']; $thisEndpoint = $apiRegister->getApiEndpoint($endpoint); if (is_null($thisEndpoint)) { return $this->_errorOutput('Invalid Endpoint', $returnType, 404); } if (!isset($params['key']) || empty($params['key'])) { return $this->_errorOutput('You must provide an API key', $returnType, 403); } $apiApp = new Ot_Model_DbTable_ApiApp(); $thisApp = $apiApp->getAppByKey($params['key']); if (is_null($thisApp)) { return $this->_errorOutput('Invalid API key', $returnType, 403); } $otAccount = new Ot_Model_DbTable_Account(); $thisAccount = $otAccount->getByAccountId($thisApp->accountId); if (is_null($thisAccount)) { return $this->_errorOutput('No user found for this API key', $returnType, 403); } $acl = new Ot_Acl('remote'); if (count($thisAccount->role) > 1) { $roles = array(); // Get role names from the list of role Ids foreach ($thisAccount->role as $r) { $roles[] = $acl->getRole($r); } // Create a new role that inherits from all the returned roles $roleName = implode(',', $roles); $thisAccount->role = $roleName; $acl->addRole(new Zend_Acl_Role($roleName), $roles); } elseif (count($thisAccount->role) == 1) { $thisAccount->role = array_pop($thisAccount->role); } if (!$acl->hasRole($thisAccount->role)) { $thisAccount->role = $vr->getVar('defaultRole')->getValue(); } $role = $thisAccount->role; if ($role == '' || !$acl->hasRole($role)) { $role = $vr->getVar('defaultRole')->getValue(); } // the api "module" here is really a kind of placeholder $aclResource = 'api_' . strtolower($thisEndpoint->getName()); Zend_Auth::getInstance()->getStorage()->write($thisAccount); } catch (Exception $e) { return $this->_errorOutput($e->getMessage(), $returnType); } $data = array(); $apiObject = $thisEndpoint->getEndpointObj(); if ($this->_request->isPost()) { if (!$acl->isAllowed($role, $aclResource, 'post')) { return $this->_errorOutput('You do not have permission to access this endpoint with POST', $returnType, 403); } try { $data = $apiObject->post($params); } catch (Exception $e) { return $this->_errorOutput($e->getMessage(), $returnType); } } else { if ($this->_request->isPut()) { if (!$acl->isAllowed($role, $aclResource, 'put')) { return $this->_errorOutput('You do not have permission to access this endpoint with PUT', $returnType, 403); } try { $data = $apiObject->put($params); } catch (Exception $e) { return $this->_errorOutput($e->getMessage(), $returnType); } } else { if ($this->_request->isDelete()) { if (!$acl->isAllowed($role, $aclResource, 'delete')) { return $this->_errorOutput('You do not have permission to access this endpoint with DELETE', $returnType, 403); } try { $data = $apiObject->delete($params); } catch (Exception $e) { return $this->_errorOutput($e->getMessage(), $returnType); } } else { if (!$acl->isAllowed($role, $aclResource, 'get')) { return $this->_errorOutput('You do not have permission to access this endpoint with GET', $returnType, 403); } try { $data = $apiObject->get($params); } catch (Exception $e) { return $this->_errorOutput($e->getMessage(), $returnType); } } } } return $this->_validOutput($data, $returnType); }
public function _initVars() { $site = array(); $site[] = new Ot_Var_Type_Text('appTitle', 'Application Title', 'The title of the application.', 'OT Framework Application'); $site[] = new Ot_Var_Type_Textarea('appDescription', 'Application Description', 'The application description.', 'App description!'); $site[] = new Ot_Var_Type_Text('metaKeywords', 'Keywords', 'The meta keywords you would like to use for the application.', ''); $site[] = new Ot_Var_Type_Theme('theme', 'Site Theme', 'The display theme for the application', 'default'); $site[] = new Ot_Var_Type_Select('triggerSystem', 'Trigger System', 'Whether to globally enable or disable the trigger system. Enable in production.', '1', array(0 => 'Disabled', 1 => 'Enabled')); $site[] = new Ot_Var_Type_Select('showTrackbackOnError', 'Show Error Trackbacks', 'Switch to show error trackbacks when the application has errors. Should likely be turned off in production.', '0', array(0 => 'No', 1 => 'Yes')); $auth = array(); $auth[] = new Ot_Var_Type_Multiselect('requiredAccountFields', 'Required User Account Fields', 'When a user logs in, if these fields are not populated, they will be forced to populate the fields before continuing', array('firstName', 'lastName', 'emailAddress'), array('firstName' => 'First Name', 'lastName' => 'Last Name', 'emailAddress' => 'Email Address')); $auth[] = new Ot_Var_Type_Role('defaultRole', 'Default Role', 'Default role that a user gets if they are not logged in.', '1'); $auth[] = new Ot_Var_Type_Role('newAccountRole', 'New Account Role', 'Role which is assigned to users when a new account is created for them', '1'); $format = array(); $format[] = new Ot_Var_Type_Text('dateTimeFormat', 'Date/Time Format', 'Date / Time formatted using PHP\'s strftime() function.', '%m/%d/%Y %I:%M %p'); $format[] = new Ot_Var_Type_Text('medDateFormat', 'Medium Date Format', 'Date formatted using PHP\'s strftime() function.', '%b %e, %Y'); $format[] = new Ot_Var_Type_Text('longDateCompactFormat', 'Long Date Compact Format', 'Date formatted using PHP\'s strftime() function.', '%a, %b %e, %Y'); $format[] = new Ot_Var_Type_Text('longDateFormat', 'Long Date Format', 'Date formatted using PHP\'s strftime() function.', '%m/%d/%Y'); $format[] = new Ot_Var_Type_Text('dayFormat', 'Day Format', 'Date formatted using PHP\'s strftime() function.', '%d'); $format[] = new Ot_Var_Type_Text('timeFormat', 'Time Format', 'Time formatted using PHP\'s strftime() function.', '%I:%M %p'); $vr = new Ot_Config_Register(); $vr->registerVars($site, 'App Settings'); $vr->registerVars($auth, 'Authentication'); $vr->registerVars($format, 'Date/Time Formats'); }