/** * The index * * This is the index action where we check if the localConfigPath * is writeable by the user. If it isn't then we set a warning message. * * @uses Default_Model_Action * @return void */ public function indexAction() { $model = new Default_Model_Action; $dir = Zend_Registry::get('localConfigPath'); $dir = $dir . 'actions.xml'; $dir = Zend_Registry::get('localConfigPath'); if (!is_writable($dir)) { $actionPathMessage = sprintf($this->tr->_('ACTION_DIR_PROBLEM'), $dir); $setupHelpMessage = $this->tr->_('SETUP_HELP_MESSAGE'); $this->addMessage( $actionPathMessage .' <br /><br />' . $setupHelpMessage ); $this->_redirect('/action/error'); } $data = $model->getAll(); if ($data == false) { $data = array(); } $this->view->data = $data; }
public function indexAction() { $model = new Default_Model_Action(); $data = $model->getAll(); if ($data == false) { $data = array(); } $this->view->data = $data; }
/** * Generate documentation, in available formats. * * @return void **/ public function generateAction() { $doc_data = array(); $emod = new Default_Model_Error(); $amod = new Default_Model_Action(); $omod = new Default_Model_Output(); $doc_data['actions'] = $amod->getAll(); $doc_data['output-types'] = $omod->getAll(); $doc_data['errors'] = $emod->getAll(); $this->view->doc_data = $doc_data; }
public function init() { $routesAndActions = array('Actions' => array(), 'Routes' => array()); $model = new Default_Model_Action(); $allActions = $model->getAll(); foreach ($allActions as $db_action) { $routesAndActions['Actions'][$db_action['hash']] = $db_action['name']; if (!empty($db_action['route'])) { $routesAndActions['Routes']['route-' . $db_action['hash']] = $db_action['route']; } } $action = new Zend_Form_Element_Select('action'); $action->setLabel('Action'); $action->addMultiOptions($routesAndActions); $this->addElement($action); $params = new Zend_Form_Element_Text('query_uri'); $params->setLabel('Query URI'); $params->setRequired(true); $params->setAttrib('size', '80'); $this->addElement($params); $t = new Default_Model_Tester(); $output = $t->buildForm(); $p = new Lupin_Form_Element_Static('params'); $p->setValue($output); $p->setLabel('Params'); $this->addElement($p); $formats = array(); $outputModel = new Default_Model_Output(); $format = new Zend_Form_Element_Select('format'); $format->setLabel('Format'); $format->setRequired(true); foreach ($outputModel->getAll() as $key => $db_format) { $formats[$db_format["name"]] = $db_format["name"] . (!$db_format["enabled"] ? " (disabled)" : ''); if ($db_format["default"] != '0') { $format->setValue(array($db_format["name"], $db_format["name"])); } } $format->addMultiOptions($formats); $this->addElement($format); $methods = array('get' => 'GET', 'post' => 'POST', 'put' => 'PUT', 'delete' => 'DELETE', 'head' => 'HEAD'); $method = new Zend_Form_Element_Select('method'); $method->setLabel('Method'); $method->setRequired(true); $method->addMultiOptions($methods); $this->addElement($method); $email = new Zend_Form_Element_Text('email'); $email->setLabel('Email'); $email->setAttrib('size', '40'); $this->addElement($email); $key = new Zend_Form_Element_Text('key'); $key->setLabel('Secret Key'); $key->setAttrib('size', '40'); $this->addElement($key); $email_key = new Zend_Form_Element_Select('email-key'); $email_key->setLabel('Load Email/Key Combo'); $params->setAttrib('size', '55'); $emails_keys = array(0 => 'Select a combination to fill the fields above.'); $partnerModel = new Default_Model_Partner(); $partners = $partnerModel->getAll(); if (!empty($partners)) { foreach ($partners as $key => $partner) { if (!empty($partner)) { $emails_keys[$partner['hash']] = $partner['email'] . ' / ' . $partner['api_key']; } } } $email_key->addMultiOptions($emails_keys); $this->addElement($email_key); $config_model = new Default_Model_Configuration(); $url = new Zend_Form_Element_Text('url'); $url->setLabel('API Domain'); $url->setRequired(true); $url->setValue($config_model->getKey("api_url")); $this->addElement($url); parent::init(); }
public function init() { $this->setAction(URL_BASE . '/tester'); $tr = Zend_Registry::get('tr'); $routesAndActions = array('Routes' => array(), 'History' => array()); $model = new Default_Model_Action(); $allActions = $model->getAll(); foreach ($allActions as $db_action) { if (!empty($db_action['route'])) { $routesAndActions['Routes']['route-' . $db_action['hash']] = $db_action['route']; } } $test_history = new Zend_Session_Namespace('test_history'); $history = $test_history->value; if ($history) { foreach ($history as $route => $data) { if (!empty($route)) { $routesAndActions['History'][$route] = $route; } } } $action = new Zend_Form_Element_Select('action'); $action->setLabel($tr->_('ACTION')); $action->addMultiOptions($routesAndActions); $this->addElement($action); $params = new Zend_Form_Element_Text('query_uri'); $params->setLabel($tr->_('QUERY_URI')); $params->setRequired(true); $params->addValidator('NotEmpty', true, array('messages' => $tr->_('GENERAL_MISSING_TEXT_VALUE'))); $params->setAttrib('size', '80'); $this->addElement($params); $t = new Default_Model_Tester(); $output = $t->buildForm(); $p = new Lupin_Form_Element_Static('params'); $p->setValue($output); $p->setLabel($tr->_('PARAMS')); $this->addElement($p); $formats = array(); $outputModel = new Default_Model_Output(); $format = new Zend_Form_Element_Select('format'); $format->setLabel($tr->_('FORMAT')); $format->setRequired(true); foreach ($outputModel->getAll() as $key => $db_format) { $formats[$db_format["name"]] = $db_format["name"] . (!$db_format["enabled"] ? " (" . $tr->_('DISABLED') . ")" : ''); if ($db_format["default"] != '0') { $format->setValue(array($db_format["name"], $db_format["name"])); } } $format->addMultiOptions($formats); $this->addElement($format); $methods = array('get' => 'GET', 'post' => 'POST', 'put' => 'PUT', 'delete' => 'DELETE', 'head' => 'HEAD'); // Explicitly turn off translations, our DELETE got translated $method = new Zend_Form_Element_Select('method', array('disableTranslator' => true)); $method->setLabel($tr->_('METHOD')); $method->setRequired(true); $method->addMultiOptions($methods); $this->addElement($method); $email = new Zend_Form_Element_Text('email'); $email->setLabel($tr->_('EMAIL')); $email->setAttrib('size', '40'); $this->addElement($email); $key = new Zend_Form_Element_Text('key'); $key->setLabel($tr->_('SECRET_KEY')); $key->setAttrib('size', '40'); $this->addElement($key); $email_key = new Zend_Form_Element_Select('email-key'); $email_key->setLabel($tr->_('LOAD_EMAIL_KEY')); $params->setAttrib('size', '55'); $emails_keys = array(0 => $tr->_('SELECT_COMBO_OF_FIELDS')); $partnerModel = new Default_Model_Partner(); $partners = $partnerModel->getAll(); if (!empty($partners)) { foreach ($partners as $key => $partner) { if (!empty($partner)) { $emails_keys[$partner['hash']] = $partner['email'] . ' / ' . $partner['api_key']; } } } $email_key->addMultiOptions($emails_keys); $this->addElement($email_key); $config_model = new Default_Model_Configuration(); $url = new Zend_Form_Element_Text('url'); $url->setLabel($tr->_('API_DOMAIN')); $url->setRequired(true); $url->addValidator('NotEmpty', true, array('messages' => $tr->_('GENERAL_MISSING_TEXT_VALUE'))); $url->setValue($config_model->getKey("api_url")); $this->addElement($url); $ssl = new Zend_Form_Element_Checkbox('ssl'); $ssl->setLabel($tr->_('USE_HTTPS')); $this->addElement($ssl); parent::init(); }
/** * Test an action * * This is the test action method. It test a specific action. * * @return void */ public function testAction() { $this->_helper->viewRenderer->setViewSuffix('txt'); // The options we are accepting for adding $options = new Zend_Console_Getopt(array('name|n=s' => 'Name of the action to call.', 'parameters|p=s' => 'Paramters to use. For example var1=val1&var2=val2', 'format|f=s' => 'Format to return. Defaults to XML.', 'method|m=s' => 'Method to use. Defaults to GET.', 'email|e=s' => 'Email or username to use.', 'secretkey|sk=s' => 'Secret key associated with email passed.', 'domain|d=s' => 'Domain to use, if not included will use default', 'query-uri|u=s' => 'Query uri to use. For example /testing/1', 'https|h' => 'Use https.')); try { $options->parse(); } catch (Zend_Console_Getopt_Exception $e) { $this->view->message = $e->getUsageMessage(); return; } if ($options->name == '') { $this->view->message = $options->getUsageMessage(); return; } $confModel = new Default_Model_Configuration(); if (!$confModel->getKey('api_url')) { $this->view->message = 'Remember you can set the default API domain name in your admin configuration.' . PHP_EOL; } if (!class_exists('HttpRequest')) { $this->view->message = 'HttpRequest class was not found the pecl_http (http://pecl.php.net/package/pecl_http) package is required to use the tester.' . PHP_EOL; return; } $action_name = $options->name; $params = $options->parameters; $format = $options->format; $method = $options->method; $email = $options->email; $password = $options->secretkey; $url = $options->domain; $ssl = $options->https; $query_uri = $options->getOption('query-uri'); if ($url == '') { $url = $confModel->getKey('api_url'); } if ($query_uri == '') { $actionModel = new Default_Model_Action(); $actions = $actionModel->getAll(); foreach ($actions as $action_details) { if ($action_details['name'] == $action_name) { $query_uri = $action_details['route']; } } } $newMethod = HTTP_METH_GET; switch (strtolower($method)) { case 'get': $newMethod = HTTP_METH_GET; break; case 'post': $newMethod = HTTP_METH_POST; break; case 'put': $newMethod = HTTP_METH_PUT; break; case 'delete': $newMethod = HTTP_METH_DELETE; break; case 'head': $newMethod = HTTP_METH_HEAD; break; } $request_url = 'http' . ($ssl !== null ? 's' : '') . '://' . $url . '/' . $query_uri . '.' . strtolower($format); $httpOptions = array(); if ($email && $password) { $httpOptions = array('headers' => array('Accept' => '*/*'), 'httpauth' => $email . ':' . $password, 'httpauthtype' => HTTP_AUTH_DIGEST); } $request = new HttpRequest($request_url, $newMethod, $httpOptions); if ("POST" == strtoupper($method)) { $request->setBody($params); } else { $request->setQueryData($params); } $res = $request->send(); $responseInfo = $request->getResponseInfo(); $this->view->request_url = $responseInfo['effective_url']; $this->view->response_header = $this->collapseHeaders($res->getHeaders()); $this->view->content = $res->getBody(); $this->view->status = $res->getResponseCode(); $this->view->method = isset($method) ? strtoupper($method) : 'GET'; $this->view->request_post_fields = $newMethod == HTTP_METH_POST ? $params : ''; }