Esempio n. 1
0
 /**
  * This function creates a HTML-block for a menu item.
  *
  * @access public
  * @author k
  * @param MenuElement $parameters['menuElement']
  *        	the menu element
  * @param string $parameters['type']
  *        	the type
  * @see MenuElement::$type
  * @uses Error for error handling
  * @uses ErrorView for error handling
  * @uses MENU_COMMON for the common menu
  * @uses MENU_SIDE for the menu in sidebar
  */
 public static function buildMenuElement($parameters)
 {
     require_once 'HTML/Template/IT.php';
     $tpl = new \HTML_Template_IT(ROOT_FOLDER . 'html');
     $tpl->loadTemplatefile('particle-template.html');
     switch ($parameters['type']) {
         case MENU_COMMON:
             $tpl->setCurrentBlock('item-in-common-menu');
             $tpl->setVariable(array('HREF-OF-ITEM-IN-COMMON-MENU' => null === $parameters['menuElement']->getHref() ? $parameters['menuElement']->translate(array('property' => 'href', 'isSlug' => true)) : $parameters['menuElement']->getHref(), 'LABEL-OF-ITEM-IN-COMMON-MENU' => $parameters['menuElement']->translate(array('property' => 'label'))));
             $tpl->parse('item-in-common-menu');
             // echo ' 38: ', $tpl->get('menu-item');
             return $tpl->get('item-in-common-menu');
             break;
         case MENU_SIDE:
             $tpl->setCurrentBlock('item-in-menu-in-sidebar');
             $tpl->setVariable(array('HREF-OF-ITEM-IN-MENU-IN-SIDEBAR' => null === $parameters['menuElement']->getHref() ? $parameters['menuElement']->translate(array('property' => 'href', 'isSlug' => true)) : $parameters['menuElement']->getHref(), 'LABEL-OF-ITEM-IN-MENU-IN-SIDEBAR' => $parameters['menuElement']->translate(array('property' => 'label'))));
             $tpl->parse('item-in-menu-in-sidebar');
             return $tpl->get('item-in-menu-in-sidebar');
             break;
         default:
             require_once dirname(__FILE__) . '/Error.php';
             $error = new Error();
             $error->setMessage(\pstk\String::translate('errorWhichMenu'));
             require_once dirname(__FILE__) . '/ErrorView.php';
             ErrorView::raiseError($error);
     }
 }
 public function create($article)
 {
     $postArgs = array('post_title' => $article->entityName, 'post_type' => DPSFA_Article_Slug, 'post_content' => '', 'post_excerpt' => '', 'post_status' => 'publish');
     $post = wp_insert_post($postArgs);
     if ($post) {
         $date = new \DateTime();
         $article->id = $post;
         $article->date_created = $date->getTimestamp();
         $article->save();
     } else {
         $error = new Error("Error", 400);
         $error->setTitle('Could not create Article');
         $error->setMessage('Wordpress could not create the article');
         $error->setRaw($post);
     }
 }
 public function has_api_credentials()
 {
     // Make sure all credentials have been entered
     // If nothign has been entered, return false
     if (empty($this->key) && empty($this->secret) && empty($this->device_token) && empty($this->device_id)) {
         return false;
     } else {
         $missing = array();
         if (empty($this->key)) {
             array_push($missing, "API Key");
         }
         if (empty($this->secret)) {
             array_push($missing, "API Secret");
         }
         if (empty($this->device_token)) {
             array_push($missing, "Device Token");
         }
         if (empty($this->device_id)) {
             array_push($missing, "Device ID");
         }
         if (empty($missing)) {
             return true;
         } else {
             // Throw new error
             $error = new Error("Error", $code);
             $error->setTitle('Missing Credentials');
             $error->setMessage('One of the required API credentials is missing, please fill out: ' . implode(", ", $missing));
             throw $error;
         }
     }
 }
 /**
  * This method will get the access token.
  *
  * @param {String} $refresh_token - The base-64 encoded refresh token
  * @param {String} $grant_type - The grant type, optional parameters
  * @example $grant_type = 'refresh_token';
  * @param {String} $scope - The scope value, optional parameters
  * @example $scope = 'AdobeID,openid';
  */
 public function refresh_access_token($grant_type = 'refresh_token', $scope = 'AdobeID,openid')
 {
     // set request header:
     // [+] Accept: application/json
     // [+] Content-Type: application/x-www-form-urlencoded
     $headers = array('Accept: application/json', 'Content-Type: Content-Type: application/x-www-form-urlencoded');
     // set request URL
     $url = $this->authentication_endpoint . "/ims/token/v1?grant_type=device&client_id=" . $this->client_id . "&client_secret=" . $this->client_secret . "&scope=openid&device_token=" . $this->device_token . "&device_id=" . $this->device_id;
     // call helper to initiate the cURL request
     $curl = new Curl('POST', $url, $headers);
     // Parse out token
     $data = $curl->getResponseBody();
     if (!empty($data['error'])) {
         // Throw new error
         $error = new Error("Error", 401);
         $error->setRaw(array("headers" => $curl->getResponseHeader(), "body" => $curl->getResponseBody(), "url" => $curl->getRequestUrl(), "entity" => ''));
         $error->setTitle('API Credentials Not Valid');
         $error->setMessage('The API credentials supplied are not valid. The plugin will not allow you to access any of the cloud functions without proper credentials: ' . $data['error']);
         // Return token
         $this->access_token = "";
         $this->refresh_token = "";
         // Save access token
         $settings = new Settings();
         $settings->access_token = "";
         $settings->refresh_token = "";
         $settings->publications = array();
         $settings->permissions = array();
         $settings->save();
         throw $error;
     } else {
         $access_token = isset($data['access_token']) ? $data['access_token'] : null;
         $refresh_token = isset($data['refresh_token']) ? $data['refresh_token'] : null;
         // Save access token
         $settings = new Settings();
         $settings->access_token = $access_token;
         $settings->refresh_token = $refresh_token;
         $settings->save();
         // Return token
         $this->access_token = $access_token;
         $this->refresh_token = $refresh_token;
     }
 }
Esempio n. 5
0
 private function RunTestMethod($test_method_name)
 {
     $error_catcher = $this->getErrorCatcherObject();
     $error_catcher->setUp();
     $this->resetErrorsExpectations();
     $test = $this->start_new_test($test_method_name);
     $this->setUp();
     $this->assertPreConditions();
     $exception_generated = false;
     try {
         $this->{$test_method_name}();
     } catch (\Exception $exception) {
         $exception_generated = true;
         if (!$this->exception_expected) {
             $test->setException($exception);
         }
     }
     if ($this->exception_expected && !$exception_generated) {
         $test->setSuccessful(false);
     }
     if ($error_catcher->hasErrors()) {
         if (!$this->error_expected) {
             $test->setErrors($error_catcher->getErrors());
         }
     } else {
         if ($this->error_expected) {
             $test->setSuccessful(false);
             $Error = new Error();
             $Error->setMessage("Error is expected but wasn't generated");
             $test->setErrors(array($Error));
         }
     }
     $this->assertPostConditions();
     $this->tearDown();
     if (!$test->isSuccessful()) {
         $this->onNotSuccessfulTest();
     }
 }
Esempio n. 6
0
 /** 
  * Constructor encargado de inicializar el c�digo de error
  * @param	$code	Es el c�digo del error
  * @return   void
  */
 function AplExternaError($code = 0)
 {
     Error::Error($code);
     Error::setMessage($this->tipoError($code));
 }
Esempio n. 7
0
 /** 
  * Constructor encargado de inicializar el código de error
  * @param	$code	Es el código del error
  * @return   void
  */
 function CombinaError($code = 0)
 {
     Error::Error($code);
     Error::setMessage($this->tipoError($code));
 }
 /**
  * This method will initialize and execute the HTTPS request.
  */
 public function exec()
 {
     // initialize the cURL
     $this->curl = curl_init();
     // initialize cURL parameters
     curl_setopt_array($this->curl, $this->curl_options);
     // execute cURL request
     $this->curl_response = curl_exec($this->curl);
     // get the response HTTP code
     $this->curl_http_code = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
     // get the response header size
     $this->curl_response_size = curl_getinfo($this->curl, CURLINFO_HEADER_SIZE);
     // call helper to parse & store the response header and body
     $this->formatResponse();
     if (curl_errno($this->curl)) {
         $error = new Error("Error", curl_errno($this->curl));
         $error = new Error("Error", 300);
         $error->setTitle('Unable to send a request to the Adobe API');
         $error->setMessage(curl_error($this->curl));
         throw $error;
     }
     // close cURL request
     curl_close($this->curl);
 }