Example #1
0
 /**
  * Method for object initialization by the string
  * @param string $string response string
  * @return Error error object
  */
 public static function initializeByString($string)
 {
     $object = json_decode($string);
     $Response = new self();
     $Response->setError($object->error);
     return $Response;
 }
Example #2
0
 /**
  * Method for object initialization by the string
  * @param string $string response string with error data
  * @return Error response object
  */
 public static function initializeByString($string)
 {
     $data = array();
     parse_str($string, $data);
     $Error = new self();
     $Error->setError($data['error'])->setDescription($data['error_description']);
     return $Error;
 }
Example #3
0
 public static function get($bin = null)
 {
     $_bl = new self();
     if (!is_numeric($bin)) {
         $_bl->setError('no bin provided or not numeric');
         return $_bl;
     }
     return $_bl->fetch($bin);
 }
Example #4
0
 public static function failure($msg = null, $extra = array())
 {
     $result = new self();
     $result->setError();
     $result->setMessage($msg);
     foreach ($extra as $k => $v) {
         $result->{$k} = $v;
     }
     return $result;
 }
Example #5
0
 /**
  * Show list for central view
  *
  * @param $personal boolean   display rssfeeds created by me ? (true by default)
  *
  * @return Nothing (display function)
  **/
 static function showListForCentral($personal = true)
 {
     global $DB, $CFG_GLPI;
     $users_id = Session::getLoginUserID();
     $today = date('Y-m-d');
     $now = date('Y-m-d H:i:s');
     if ($personal) {
         /// Personal notes only for central view
         if ($_SESSION['glpiactiveprofile']['interface'] == 'helpdesk') {
             return false;
         }
         $query = "SELECT `glpi_rssfeeds`.*\n                   FROM `glpi_rssfeeds`\n                   WHERE `glpi_rssfeeds`.`users_id` = '{$users_id}'\n                         AND `glpi_rssfeeds`.`is_active` = '1'\n                   ORDER BY `glpi_rssfeeds`.`name`";
         $titre = "<a href='" . $CFG_GLPI["root_doc"] . "/front/rssfeed.php'>" . _n('Personal RSS feed', 'Personal RSS feeds', Session::getPluralNumber()) . "</a>";
     } else {
         // Show public rssfeeds / not mines : need to have access to public rssfeeds
         if (!self::canView()) {
             return false;
         }
         $restrict_user = '******';
         // Only personal on central so do not keep it
         if ($_SESSION['glpiactiveprofile']['interface'] == 'central') {
             $restrict_user = "******";
         }
         $query = "SELECT `glpi_rssfeeds`.*\n                   FROM `glpi_rssfeeds` " . self::addVisibilityJoins() . "\n                   WHERE {$restrict_user}\n                         AND " . self::addVisibilityRestrict() . "\n                   ORDER BY `glpi_rssfeeds`.`name`";
         if ($_SESSION['glpiactiveprofile']['interface'] != 'helpdesk') {
             $titre = "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/rssfeed.php\">" . _n('Public RSS feed', 'Public RSS feeds', Session::getPluralNumber()) . "</a>";
         } else {
             $titre = _n('Public RSS feed', 'Public RSS feeds', Session::getPluralNumber());
         }
     }
     $result = $DB->query($query);
     $items = array();
     $rssfeed = new self();
     if ($nb = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             if ($rssfeed->getFromDB($data['id'])) {
                 // Force fetching feeds
                 if ($feed = self::getRSSFeed($data['url'], $data['refresh_rate'])) {
                     // Store feeds in array of feeds
                     $items = array_merge($items, $feed->get_items(0, $data['max_items']));
                     $rssfeed->setError(false);
                 } else {
                     $rssfeed->setError(true);
                 }
             }
         }
     }
     echo "<br><table class='tab_cadrehov'>";
     echo "<tr class='noHover'><th colspan='2'><div class='relative'><span>{$titre}</span>";
     if ($personal && self::canCreate() || !$personal && Session::haveRight('rssfeed_public', CREATE)) {
         echo "<span class='floatright'>";
         echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/rssfeed.form.php'>";
         echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/plus.png' alt='" . __s('Add') . "' title=\"" . __s('Add') . "\"></a></span>";
     }
     echo "</div></th></tr>\n";
     if ($nb) {
         usort($items, array('SimplePie', 'sort_items'));
         foreach ($items as $item) {
             echo "<tr class='tab_bg_1'><td>";
             echo HTML::convDateTime($item->get_date('Y-m-d H:i:s'));
             echo "</td><td>";
             $link = $item->feed->get_permalink();
             if (empty($link)) {
                 echo $item->feed->get_title();
             } else {
                 echo "<a target='_blank' href='{$link}'>" . $item->feed->get_title() . '</a>';
             }
             $link = $item->get_permalink();
             //                echo "<br>";
             //                echo $item->get_title();
             //                echo "</td><td>";
             $rand = mt_rand();
             echo "<div id='rssitem{$rand}' class='pointer rss'>";
             if (!is_null($link)) {
                 echo "<a target='_blank' href='{$link}'>";
             }
             echo $item->get_title();
             //                echo Html::resume_text(Html::clean(Toolbox::unclean_cross_side_scripting_deep($item->get_content())), 300);
             if (!is_null($link)) {
                 echo "</a>";
             }
             echo "</div>";
             Html::showToolTip(Toolbox::unclean_html_cross_side_scripting_deep($item->get_content()), array('applyto' => "rssitem{$rand}", 'display' => true));
             echo "</td></tr>";
         }
     }
     echo "</table>\n";
 }
Example #6
0
 /**
  * @param array $array
  * @param bool $strict
  * @return Document
  * @throws FromArrayCompilationException
  */
 public static function fromArray(array $array, $strict = true)
 {
     $document = new self();
     if (array_key_exists('collection', $array)) {
         if (!is_array($array['collection'])) {
             throw new ExpectedArrayException('collection', gettype($array['collection']));
         }
         try {
             $document->setCollection(Collection::fromArray($array['collection'], $strict));
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('collection', $e->getMessage());
         }
     }
     if (array_key_exists('error', $array)) {
         if (!is_array($array['error'])) {
             throw new ExpectedArrayException('error', gettype($array['error']));
         }
         try {
             $document->setError(Error::fromArray($array['error']));
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('error', $e->getMessage());
         }
     }
     if (array_key_exists('template', $array)) {
         if (!is_array($array['template'])) {
             throw new ExpectedArrayException('template', gettype($array['template']));
         }
         try {
             $document->setTemplate(Template::fromArray($array['template'], $strict));
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('template', $e->getMessage());
         }
     }
     if (array_key_exists('queries', $array)) {
         if (!is_array($array['queries'])) {
             throw new ExpectedArrayException('queries', gettype($array['queries']));
         }
         try {
             foreach ($array['queries'] as $key => $queryArray) {
                 if (!is_array($queryArray)) {
                     throw new ExpectedArrayException($key, gettype($queryArray));
                 }
                 try {
                     $document->getQueries()->add(Query::fromArray($queryArray, $strict));
                 } catch (FromArrayCompilationException $e) {
                     throw new FromArrayCompilationException($key, $e->getMessage());
                 }
             }
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('queries', $e->getMessage());
         }
     }
     return $document;
 }
 /**
  * {@inheritdoc}
  */
 public static function fromArray(array $values)
 {
     $message = new self();
     $values = array_merge(['error' => null, 'hash' => null, 'settings' => null], $values);
     $message->setError($values['error']);
     $message->setHash($values['hash']);
     $message->setSettings($values['settings']);
     return $message;
 }
Example #8
0
 /**
  * Create and throw Exception
  * @param $key
  * @param $error
  * @return self
  */
 public static function exception($key, $error)
 {
     $exception = new self();
     $exception->setError($key, $error);
     return $exception;
 }
Example #9
0
 /**
  * @param \Guzzle\Http\Message\Response $guzzleResponse
  * @param ActionsInterface              $action
  * @return Response
  */
 public static function parseGuzzleResponse(\Guzzle\Http\Message\Response $guzzleResponse, ActionsInterface $action)
 {
     $response = new self();
     if ($guzzleResponse->getStatusCode() != 200) {
         $response->setStatus(false);
         $response->setError($response::ERROR_REQUEST_ERROR);
         return $response;
     }
     $responseArray = json_decode($guzzleResponse->getBody(true), true);
     $response->setStatus($responseArray['ok']);
     if ($response->getStatus() === false) {
         $response->setError($responseArray['error']);
         return $response;
     }
     $response->setData($action->parseResponse($responseArray));
     return $response;
 }
Example #10
0
 /**
  * Initialization method
  * @param stdClass $Object object for initialization
  * @return Error initialized object
  */
 public static function initializeByObject(stdClass $Object)
 {
     $Error = new self();
     if (isset($Object->error)) {
         $Error->setError($Object->error);
     }
     if (isset($Object->error_description)) {
         $Error->setDescription($Object->error_description);
     }
     return $Error;
 }
 /**
  * @param Response $response
  *
  * @return RepositoryResponse
  */
 public static function fromResponse(Response $response)
 {
     $self = new self();
     $error = new Error();
     $self->setSuccessful(false);
     $responseContent = self::getResponseContent($response);
     $self->setResponse($responseContent);
     $responseArray = json_decode($responseContent, true);
     if (isset($responseArray['response']['status'])) {
         $self->setSuccessful($responseArray['response']['status'] == self::STATUS_SUCCESS);
     }
     if (!$self->isSuccessful()) {
         $error = Error::fromArray($responseArray['response']);
     }
     $self->setError($error);
     return $self;
 }
Example #12
0
 /**
  * @param array $array
  * @param bool $strict
  * @return Collection
  * @throws FromArrayCompilationException
  */
 public static function fromArray(array $array, $strict = true)
 {
     $href = '';
     $version = '1.0';
     if (array_key_exists('href', $array)) {
         $href = $array['href'];
     } elseif ($strict) {
         throw new MissingArgumentException('href');
     }
     if (array_key_exists('version', $array)) {
         $version = $array['version'];
     }
     $collection = new self($href, $version);
     if (array_key_exists('links', $array)) {
         if (!is_array($array['links'])) {
             throw new ExpectedArrayException('links', gettype($array['links']));
         }
         try {
             foreach ($array['links'] as $key => $linkArray) {
                 if (!is_array($linkArray)) {
                     throw new ExpectedArrayException($key, gettype($linkArray));
                 }
                 try {
                     $collection->getLinks()->add(Link::fromArray($linkArray, $strict));
                 } catch (FromArrayCompilationException $e) {
                     throw new FromArrayCompilationException($key, $e->getMessage());
                 }
             }
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('links', $e->getMessage());
         }
     }
     if (array_key_exists('items', $array)) {
         if (!is_array($array['items'])) {
             throw new ExpectedArrayException('items', gettype($array['items']));
         }
         try {
             foreach ($array['items'] as $key => $itemArray) {
                 if (!is_array($itemArray)) {
                     throw new ExpectedArrayException($key, gettype($itemArray));
                 }
                 try {
                     $collection->getItems()->add(Item::fromArray($itemArray, $strict));
                 } catch (FromArrayCompilationException $e) {
                     throw new FromArrayCompilationException($key, $e->getMessage());
                 }
             }
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('items', $e->getMessage());
         }
     }
     if (array_key_exists('queries', $array)) {
         if (!is_array($array['queries'])) {
             throw new ExpectedArrayException('queries', gettype($array['queries']));
         }
         try {
             foreach ($array['queries'] as $key => $queryArray) {
                 if (!is_array($queryArray)) {
                     throw new ExpectedArrayException($key, gettype($queryArray));
                 }
                 try {
                     $collection->getQueries()->add(Query::fromArray($queryArray, $strict));
                 } catch (FromArrayCompilationException $e) {
                     throw new FromArrayCompilationException($key, $e->getMessage());
                 }
             }
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('queries', $e->getMessage());
         }
     }
     if (array_key_exists('template', $array)) {
         if (!is_array($array['template'])) {
             throw new ExpectedArrayException('template', gettype($array['template']));
         }
         try {
             $collection->setTemplate(Template::fromArray($array['template'], $strict));
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('template', $e->getMessage());
         }
     }
     if (array_key_exists('error', $array)) {
         if (!is_array($array['error'])) {
             throw new ExpectedArrayException('error', gettype($array['error']));
         }
         try {
             $collection->setError(Error::fromArray($array['error']));
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('error', $e->getMessage());
         }
     }
     if (array_key_exists('paging', $array)) {
         if (!is_array($array['paging'])) {
             throw new ExpectedArrayException('paging', gettype($array['paging']));
         }
         try {
             $collection->setPaging(Paging::fromArray($array['paging'], $strict));
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('paging', $e->getMessage());
         }
     }
     return $collection;
 }
 /**
  * {@inheritdoc}
  */
 public static function fromArray(array $values)
 {
     $message = new self();
     $values = array_merge(['error' => null, 'file' => []], $values);
     $message->setError($values['error']);
     foreach ($values['file'] as $item) {
         $message->addFile($item);
     }
     return $message;
 }
 public static function outputErrorMessage($message)
 {
     $response = new self();
     $response->setError(0, $message);
     $response->output();
 }
Example #15
0
 /**
  * @param array $data
  * @throws Exception
  * @return self
  */
 public static function fromArray($data)
 {
     if (empty($data['jsonrpc'])) {
         throw new Exception('Response is not valid JsonRPC response: missing protocol version');
     }
     if ($data['jsonrpc'] != Request::VERSION) {
         throw new Exception('Response is not valid JsonRPC response: invalid protocol version');
     }
     $response = new self();
     if (!empty($data['error'])) {
         $response->setError(static::getErrorObject($data['error']));
     } else {
         if (empty($data['result'])) {
             throw new Exception('Response is not valid JsonRPC response: missing result');
         }
         $response->setResult($data['result']);
     }
     if (empty($data['id'])) {
         throw new Exception('Response is not valid JsonRPC response: missing id');
     }
     $response->setId($data['id']);
     return $response;
 }
 /**
  * {@inheritdoc}
  */
 public static function fromArray(array $values)
 {
     $message = new self();
     $values = array_merge(['status_code' => null, 'request_id' => null, 'api_url' => null, 'platform_returns' => [], 'auth_ticket' => null, 'returns' => [], 'error' => null], $values);
     $message->setStatusCode($values['status_code']);
     $message->setRequestId($values['request_id']);
     $message->setApiUrl($values['api_url']);
     $message->setAuthTicket($values['auth_ticket']);
     $message->setError($values['error']);
     foreach ($values['platform_returns'] as $item) {
         $message->addPlatformReturns($item);
     }
     foreach ($values['returns'] as $item) {
         $message->addReturns($item);
     }
     return $message;
 }