Example #1
0
File: query.php Project: rair/yacs
            if (isset($item['id'])) {
                $headers = Mailer::set_thread('article:' . $item['id']);
            } else {
                $headers = '';
            }
            // actual post - don't stop on error
            Mailer::notify(NULL, $to, $subject, $message, $headers);
        }
        // get the article back
        $article = Anchors::get('article:' . $_REQUEST['id']);
        // log the query submission
        if (is_object($article)) {
            $label = sprintf(i18n::c('New query: %s'), strip_tags($article->get_title()));
            $link = $context['url_to_home'] . $context['url_to_root'] . $article->get_url();
            $description = '<a href="' . $link . '">' . $link . '</a>' . "\n\n" . $article->get_teaser('basic');
            Logger::notify('query.php: ' . $label, $description);
        }
    }
    // display the form on GET
} else {
    $with_form = TRUE;
}
// display the form
if ($with_form) {
    // splash message
    $context['text'] .= '<p>' . i18n::s('Please fill out the form and it will be sent automatically to the site managers. Be as precise as possible, and mention your e-mail address to let us a chance to contact you back.') . "</p>\n";
    // the form to send a query
    $context['text'] .= '<form method="post" action="' . $context['script_url'] . '" onsubmit="return validateDocumentPost(this)" id="main_form"><div>';
    // surfer name
    if (!isset($item['edit_name'])) {
        $item['edit_name'] = Surfer::get_name();
Example #2
0
        $context['text'] .= Skin::build_block($follow_up, 'bottom');
        // log the creation of a new article
        $label = sprintf(i18n::c('Article copy: %s'), strip_tags($article->get_title()));
        // poster and target section
        if (is_object($anchor)) {
            $description = sprintf(i18n::c('Sent by %s in %s'), Surfer::get_name(), $anchor->get_title());
        } else {
            $description = sprintf(i18n::c('Sent by %s'), Surfer::get_name());
        }
        // title and link
        if ($title = $article->get_title()) {
            $description .= $title . "\n";
        }
        $description = '<a href="' . $context['url_to_home'] . $context['url_to_root'] . $article->get_url() . '">' . $article->get_title() . '</a>';
        // notify sysops
        Logger::notify('articles/duplicate.php: ' . $label, $description);
    }
    // action has to be confirmed
} elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
    Logger::error(i18n::s('The action has not been confirmed.'));
    // please confirm
} else {
    // the article or the anchor icon, if any
    $context['page_image'] = $item['icon_url'];
    if (!$context['page_image'] && is_object($anchor)) {
        $context['page_image'] = $anchor->get_icon_url();
    }
    // commands
    $menu = array();
    $menu[] = Skin::build_submit_button(i18n::s('Yes, I want to duplicate this page'), NULL, NULL, 'confirmed');
    if (isset($item['id'])) {
 /**
  * This send function sends a special command to the REST server with additional parameter.
  *
  * @author David Pauli <contact@david-pauli.de>
  * @param String command The path which is requested in the REST client.
  * @param String[] $postParameter Add specific parameters to the REST server.
  * @since 0.0.0
  * @since 0.0.1 Use HTTPRequestMethod enum.
  * @since 0.1.0 Allow empty message body if the status code is 204.
  * @since 0.1.2 Restructure the logging message and fix the PATCH call.
  * @since 0.1.2 Add error reporting.
  * @since 0.1.3 Remove isRESTCommand function.
  * @since 0.2.1 Refactor the complete send method.
  */
 public static function send($command = "", $postParameter = array())
 {
     self::errorReset();
     if (!InputValidator::isArray($postParameter)) {
         Logger::warning("ep6\\RESTClient\\Post parameter (" . $postParameter . ") are not valid.");
         self::errorSet("RESTC-5");
         return null;
     }
     if (!self::$ISCONNECTED) {
         Logger::warning("ep6\\RESTClient\nClient is not connected.");
         self::errorSet("RESTC-6");
         return null;
     }
     $protocol = self::$ISSSL ? "https" : "http";
     $url = $protocol . "://" . self::$HOST . "/" . self::PATHTOREST . "/" . self::$SHOP . "/" . $command;
     $headers = array("Accept: " . self::HTTP_ACCEPT, "Content-Type: " . self::HTTP_CONTENT_TYPE_JSON, "User-Agent: " . self::USER_AGENT);
     // add authentification if there is a token
     if (InputValidator::isAuthToken(self::$AUTHTOKEN)) {
         array_push($headers, "Authorization: Bearer " . self::$AUTHTOKEN);
     }
     # parse cookies
     if (!InputValidator::isEmptyArray(self::$COOKIES)) {
         $cookiesValues = array();
         foreach (self::$COOKIES as $key => $value) {
             array_push($cookiesValues, $key . "=" . $value);
         }
         array_push($headers, "Cookie: " . implode("; ", $cookiesValues));
     }
     $curl = curl_init($url);
     curl_setopt($curl, CURLOPT_FAILONERROR, 1);
     // show full errors
     curl_setopt($curl, CURLOPT_FORBID_REUSE, 0);
     // connection can be opened
     curl_setopt($curl, CURLOPT_FRESH_CONNECT, 0);
     // no new connection required
     curl_setopt($curl, CURLOPT_NOBODY, 0);
     // show body
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     // get response as string
     curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
     // no connection timeout
     curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, 0);
     // no connection timeout
     curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_NONE);
     // cURL will choose the http version
     curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_WHATEVER);
     // understand ipv4 and ipv6
     curl_setopt($curl, CURLINFO_HEADER_OUT, 1);
     // save the header in the log
     curl_setopt($curl, CURLOPT_HEADER, 1);
     // get the header
     if (self::$ISSSL) {
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
         // don't check the peer ssl cerrificate
         curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
         curl_setopt($curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS);
         curl_setopt($curl, CURLOPT_SSLVERSION, 0);
         // default ssl version
     } else {
         curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP);
         curl_setopt($curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP);
     }
     switch (self::$HTTP_REQUEST_METHOD) {
         case HTTPRequestMethod::GET:
             curl_setopt($curl, CURLOPT_HTTPGET, 1);
             break;
         case HTTPRequestMethod::POST:
             $JSONpostfield = JSONHandler::createJSON($postParameter);
             curl_setopt($curl, CURLOPT_POST, 1);
             curl_setopt($curl, CURLOPT_POSTREDIR, 0);
             // don't post on redirects
             curl_setopt($curl, CURLOPT_POSTFIELDS, $JSONpostfield);
             break;
         case HTTPRequestMethod::PUT:
             $JSONpostfield = JSONHandler::createJSON($postParameter);
             array_push($headers, "Content-Length: " . strlen($JSONpostfield));
             curl_setopt($curl, CURLOPT_POSTFIELDS, $JSONpostfield);
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
             break;
         case HTTPRequestMethod::DELETE:
             $JSONpostfield = JSONHandler::createJSON($postParameter);
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
             curl_setopt($curl, CURLOPT_POSTFIELDS, $JSONpostfield);
             break;
         case HTTPRequestMethod::PATCH:
             $JSONpostfield = "[" . JSONHandler::createJSON($postParameter) . "]";
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
             curl_setopt($curl, CURLOPT_POSTFIELDS, $JSONpostfield);
             break;
     }
     curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
     $response = curl_exec($curl);
     $info = curl_getinfo($curl);
     $error = curl_error($curl);
     curl_close($curl);
     # get header and body
     list($header, $body) = self::explodeResponse($response);
     $header = trim($header);
     $content = trim($body);
     $logMessage = "Request:\n" . "Parameters: " . http_build_query($postParameter) . "\n" . $info["request_header"] . "Response:\n" . "Size (Header/Request): " . $info["header_size"] . "/" . $info["request_size"] . " Bytes\n" . "Time (Total/Namelookup/Connect/Pretransfer/Starttransfer/Redirect): " . $info["total_time"] . " / " . $info["namelookup_time"] . " / " . $info["connect_time"] . " / " . $info["pretransfer_time"] . " / " . $info["starttransfer_time"] . " / " . $info["redirect_time"] . " seconds\n" . $response . "\n";
     Logger::notify("ep6\\RESTClient:\n" . $logMessage);
     # parse header, response code and body
     self::explodeHeader($header);
     self::$HTTP_RESPONSE_CODE = (int) $info["http_code"];
     if (!InputValidator::isEmpty($content)) {
         self::$CONTENT = $content;
     }
 }
 /**
  * This send function sends a special command to the REST server with additional parameter.
  *
  * @author David Pauli <contact@david-pauli.de>
  * @since 0.0.0
  * @since 0.0.1 Use HTTPRequestMethod enum.
  * @since 0.1.0 Allow empty message body if the status code is 204.
  * @api
  * @param String command The path which is requested in the REST client.
  * @param String[] postfields Add specific parameters to the REST server.
  * @return mixed[] The returned elements as array.
  */
 public static function send($command, $postfields = array())
 {
     if (!InputValidator::isRESTCommand($command) || !self::$ISCONNECTED || !InputValidator::isArray($postfields)) {
         return null;
     }
     $protocol = self::$ISSSL ? "https" : "http";
     $url = $protocol . "://" . self::$HOST . "/" . self::PATHTOREST . "/" . self::$SHOP . "/" . $command;
     $headers = array("Accept: " . self::HTTP_ACCEPT, "Content-Type: " . self::HTTP_CONTENT_TYPE);
     if (InputValidator::isAuthToken(self::$AUTHTOKEN)) {
         array_push($headers, "Authorization: Bearer " . self::$AUTHTOKEN);
     }
     $curl = curl_init($url);
     curl_setopt($curl, CURLOPT_FAILONERROR, 1);
     // show full errors
     curl_setopt($curl, CURLOPT_FORBID_REUSE, 0);
     // connection can be opened
     curl_setopt($curl, CURLOPT_FRESH_CONNECT, 0);
     // no new connection required
     curl_setopt($curl, CURLOPT_NOBODY, 0);
     // show body
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     // get response as string
     curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
     // no connection timeout
     curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, 0);
     // no connection timeout
     curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_NONE);
     // cURL will choose the http version
     curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_WHATEVER);
     // understand ipv4 and ipv6
     if (self::$ISSSL) {
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
         // don't check the peer ssl cerrificate
         curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
         curl_setopt($curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS);
         curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_DEFAULT);
         // default ssl version
     } else {
         curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP);
         curl_setopt($curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP);
     }
     switch (self::$HTTP_REQUEST_METHOD) {
         case HTTPRequestMethod::GET:
             curl_setopt($curl, CURLOPT_HTTPGET, 1);
             break;
         case HTTPRequestMethod::POST:
             $JSONpostfield = JSONHandler::createJSON($postfields);
             curl_setopt($curl, CURLOPT_POST, 1);
             curl_setopt($curl, CURLOPT_POSTREDIR, 0);
             // don't post on redirects
             curl_setopt($curl, CURLOPT_POSTFIELDS, $JSONpostfield);
             break;
         case HTTPRequestMethod::PUT:
             $JSONpostfield = JSONHandler::createJSON($postfields);
             array_push($headers, "Content-Length: " . strlen($JSONpostfield));
             curl_setopt($curl, CURLOPT_POSTFIELDS, $JSONpostfield);
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
             break;
         case HTTPRequestMethod::DELETE:
             $JSONpostfield = JSONHandler::createJSON($postfields);
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
             curl_setopt($curl, CURLOPT_POSTFIELDS, $JSONpostfield);
             break;
         case HTTPRequestMethod::PATCH:
             $JSONpostfield = JSONHandler::createJSON($postfields);
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
             curl_setopt($curl, CURLOPT_POSTFIELDS, $JSONpostfield);
             break;
     }
     curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
     $response = curl_exec($curl);
     $info = curl_getinfo($curl);
     $error = curl_error($curl);
     curl_close($curl);
     $logMessage = self::$HTTP_REQUEST_METHOD . " " . $info["url"] . "<br/>" . "<strong>Response</strong>: " . $info["http_code"] . ": <pre>" . htmlspecialchars($response) . "</pre><br/>" . "<strong>Content-Type</strong>: " . $info["content_type"] . "<br/>" . "<strong>Size</strong> (Header/Request): " . $info["header_size"] . "/" . $info["request_size"] . " Bytes<br/>" . "<strong>Time</strong> (Total/Namelookup/Connect/Pretransfer/Starttransfer/Redirect): " . $info["total_time"] . " / " . $info["namelookup_time"] . " / " . $info["connect_time"] . " / " . $info["pretransfer_time"] . " / " . $info["starttransfer_time"] . " / " . $info["redirect_time"] . " seconds<br/>";
     Logger::notify("<strong>HTTP-SEND</strong>:<br/>" . $logMessage);
     // if message body is empty this is allowed with 204
     if (!$response && $info["http_code"] != "204") {
         Logger::error("Error with send REST client: " . $error);
         return null;
     } elseif (!in_array($info["http_code"], array("200", "201", "204"))) {
         Logger::warning("Get wrong response: " . $info["http_code"]);
         return null;
     }
     return JSONHandler::parseJSON($response);
 }
Example #5
0
File: edit.php Project: rair/yacs
         $attributes['message'] = '<p>' . i18n::s('Following files have been added:') . '</p>' . $compact_list;
         $attributes['anchor'] = $anchor->get_reference();
         // notification to send by e-mail
         $mail = array();
         $mail['subject'] = sprintf(i18n::c('%s: %s'), i18n::c('Contribution'), strip_tags($anchor->get_title()));
         $mail['notification'] = Files::build_notification('multiple', $attributes);
         // one file has been added
     } elseif ($item =& Files::get_by_anchor_and_name($anchor->get_reference(), $uploaded)) {
         $context['text'] .= '<p>' . i18n::s('Following file has been added:') . '</p>' . Codes::render_object('file', $item['id']);
         // use this file record
         $_REQUEST['id'] = $item['id'];
         // log single upload
         $label = sprintf(i18n::c('New file in %s'), strip_tags($anchor->get_title()));
         $link = Files::get_permalink($item);
         $description = sprintf(i18n::c('%s at %s'), $item['file_name'], '<a href="' . $link . '">' . $link . '</a>');
         Logger::notify('files/edit.php: ' . $label, $description);
         // notification to send by e-mail
         $mail = array();
         $mail['subject'] = sprintf(i18n::c('%s: %s'), i18n::c('Contribution'), strip_tags($anchor->get_title()));
         $mail['notification'] = Files::build_notification('upload', $item);
     }
     // send to anchor watchers
     if (isset($_REQUEST['notify_watchers']) && $_REQUEST['notify_watchers'] == 'Y') {
         $anchor->alert_watchers($mail, $action, isset($_REQUEST['active']) && $_REQUEST['active'] == 'N');
     }
     // send to followers of this user
     if (isset($_REQUEST['notify_followers']) && $_REQUEST['notify_followers'] == 'Y' && Surfer::get_id() && $_REQUEST['active'] != 'N') {
         $mail['message'] = Mailer::build_notification($mail['notification'], 2);
         Users::alert_watchers('user:' . Surfer::get_id(), $mail);
     }
 }
Example #6
0
File: edit.php Project: rair/yacs
        }
        if (is_object($anchor)) {
            $menu = array_merge($menu, array('sections/edit.php?anchor=' . urlencode($anchor->get_reference()) => i18n::s('Add another section')));
        }
        $follow_up .= Skin::build_list($menu, 'menu_bar');
        $context['text'] .= Skin::build_block($follow_up, 'bottom');
        // log the creation of a new section
        $label = sprintf(i18n::c('New section: %s'), strip_tags($section->get_title()));
        if (is_object($anchor)) {
            $description = sprintf(i18n::s('Sent by %s in %s'), Surfer::get_name(), $anchor->get_title());
        } else {
            $description = sprintf(i18n::s('Sent by %s'), Surfer::get_name());
        }
        $link = $context['url_to_home'] . $context['url_to_root'] . $section->get_url();
        $description .= "\n\n" . $section->get_teaser('basic') . "\n\n" . '<a href="' . $link . '">' . $link . '</a>';
        Logger::notify('sections/edit.php: ' . $label, $description);
    }
    // display the form on GET
} else {
    $with_form = TRUE;
}
// display the form
if ($with_form) {
    // give context
    $context['current_action'] = 'edit';
    // branch to another script to save data
    if (isset($_REQUEST['options']) && preg_match('/\\bedit_as_[a-zA-Z0-9_\\.]+?\\b/i', $_REQUEST['options'], $matches) && is_readable($matches[0] . '.php')) {
        include $matches[0] . '.php';
        return;
    } elseif (is_object($overlay) && ($deputy = $overlay->get_value('edit_as')) && is_readable('edit_as_' . $deputy . '.php')) {
        include 'edit_as_' . $deputy . '.php';
Example #7
0
 /**
  * do whatever is necessary when a page has been updated
  *
  * This function:
  * - logs the update
  * - sends notification to watchers and to followers
  * - "touches" the container of the page,
  * - ping referred pages remotely (via the pingback protocol)
  * - ping selected servers, if any
  * - and triggers the hook 'update'.
  *
  * The first parameter provides the watching context to consider. If call is related
  * to the creation of a published page, the context is the section that hosts the new
  * page. If call is related to a draft page that has been published, then the context
  * is the page itself.
  *
  * This function is also able to notify followers of the surfer who has initiated the
  * action.
  *
  * @param object the watching context
  * @param array attributes of the published page
  * @param object page overlay, if any
  * @param boolean TRUE if dates should be left unchanged, FALSE otherwise
  * @param boolean TRUE if watchers should be notified, FALSE otherwise
  * @param boolean TRUE if followers should be notified, FALSE otherwise
  */
 public static function finalize_update($anchor, $item, $overlay = NULL, $silently = FALSE, $with_watchers = TRUE, $with_followers = FALSE)
 {
     global $context;
     // proceed only if the page has been published
     if (isset($item['publish_date']) && $item['publish_date'] > NULL_DATE) {
         // notification to send by e-mail
         $mail = array();
         $mail['subject'] = sprintf(i18n::c('%s: %s'), i18n::c('Update'), strip_tags($item['title']));
         $mail['notification'] = Articles::build_notification('update', $item);
         $mail['headers'] = Mailer::set_thread('article:' . $item['id']);
         // allow the overlay to prevent notifications of watcherss
         if (is_object($overlay) && !$overlay->should_notify_watchers($mail)) {
             $with_watchers = FALSE;
         }
         // send to watchers of this page, and to watchers upwards
         if ($with_watchers && ($handle = new Article())) {
             $handle->load_by_content($item, $anchor);
             $handle->alert_watchers($mail, 'article:update', $item['active'] == 'N');
         }
         // never notify followers on private pages
         if (isset($item['active']) && $item['active'] == 'N') {
             $with_followers = FALSE;
         }
         // allow the overlay to prevent notifications of followers
         if (is_object($overlay) && !$overlay->should_notify_followers()) {
             $with_followers = FALSE;
         }
         // send to followers of this user
         if ($with_followers && Surfer::get_id()) {
             $mail['message'] = Mailer::build_notification($mail['notification'], 2);
             Users::alert_watchers('user:' . Surfer::get_id(), $mail);
         }
         // update anchors
         $anchor->touch('article:update', $item['id'], $silently);
         // advertise public pages
         if (isset($item['active']) && $item['active'] == 'Y') {
             // expose links within the page
             $raw = '';
             if (isset($item['introduction'])) {
                 $raw .= $item['introduction'];
             }
             if (isset($item['source'])) {
                 $raw .= ' ' . $item['source'];
             }
             if (isset($item['description'])) {
                 $raw .= ' ' . $item['description'];
             }
             // pingback to referred links, if any
             include_once $context['path_to_root'] . 'links/links.php';
             Links::ping($raw, 'article:' . $item['id']);
             // ping servers, if any
             Servers::notify($anchor->get_url());
         }
     }
     // 'update' hook
     if (is_callable(array('Hooks', 'include_scripts'))) {
         Hooks::include_scripts('update', $item['id']);
     }
     // log page update
     $label = sprintf(i18n::c('Update: %s'), strip_tags($item['title']));
     $poster = Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']);
     $description = sprintf(i18n::c('Updated by %s in %s'), $poster, $anchor->get_title());
     $description .= "\n\n" . '<a href="' . Articles::get_permalink($item) . '">' . $item['title'] . '</a>';
     Logger::notify('articles/articles.php: ' . $label, $description);
 }
Example #8
0
File: edit.php Project: rair/yacs
         $context['text'] .= Mailer::build_recipients($anchor->get_reference());
         // follow-up commands
         $follow_up = i18n::s('What do you want to do now?');
         $menu = array();
         if (is_object($anchor)) {
             $menu = array_merge($menu, array($anchor->get_url('links') => i18n::s('View the page')));
             $menu = array_merge($menu, array('links/edit.php?anchor=' . $anchor->get_reference() => i18n::s('Submit another link')));
         }
         $follow_up .= Skin::build_list($menu, 'menu_bar');
         $context['text'] .= Skin::build_block($follow_up, 'bottom');
         // log the submission of a new link by a non-associate
         if (!Surfer::is_associate() && is_object($anchor)) {
             $label = sprintf(i18n::c('New link at %s'), strip_tags($anchor->get_title()));
             $link = $context['url_to_home'] . $context['url_to_root'] . $anchor->get_url() . '#_attachments';
             $description = $_REQUEST['link_url'] . "\n" . sprintf(i18n::c('at %s'), '<a href="' . $link . '">' . $link . '</a>');
             Logger::notify('links/edit.php: ' . $label, $description);
         }
     }
     // update an existing link
 } else {
     // display the form on error
     if (!Links::put($_REQUEST)) {
         $item = $_REQUEST;
         $with_form = TRUE;
         // follow-up
     } else {
         // touch the related anchor
         $anchor->touch('link:update', $_REQUEST['id'], isset($_REQUEST['silent']) && $_REQUEST['silent'] == 'Y');
         // clear cache
         Links::clear($_REQUEST);
         // forward to the updated anchor page
 /**
  * This send function sends a special command to the REST server with additional parameter.
  *
  * @param String	command		The path which is requested in the REST client.
  * @param Array		parameter	Add specific parameters to the REST server.
  * @return String	The returned JSON object or null if something is wrong.
  */
 public static function sendWithParameter($command, $parameter = array())
 {
     if (!InputValidator::isRESTCommand($command)) {
         return null;
     }
     if (!self::$ISCONNECTED) {
         return null;
     }
     $protocol = self::$ISSSL ? "https" : "http";
     $url = $protocol . "://" . self::$HOST . "/" . self::PATHTOREST . "/" . self::$SHOP . "/" . $command;
     $curl = curl_init($url);
     curl_setopt($curl, CURLOPT_FAILONERROR, 1);
     // show full errors
     curl_setopt($curl, CURLOPT_FORBID_REUSE, 0);
     // connection can be opened
     curl_setopt($curl, CURLOPT_FRESH_CONNECT, 0);
     // no new connection required
     curl_setopt($curl, CURLOPT_NOBODY, 0);
     // show body
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     // get response as string
     curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
     // no connection timeout
     curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, 0);
     // no connection timeout
     curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_NONE);
     // cURL will choose the http version
     curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_WHATEVER);
     // understand ipv4 and ipv6
     curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: " . self::HTTP_ACCEPT, "Authorization: Bearer " . self::$AUTHTOKEN, "Content-Type: " . self::HTTP_CONTENT_TYPE));
     if (self::$ISSSL) {
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
         // don't check the peer ssl cerrificate
         curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
         curl_setopt($curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS);
         curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_DEFAULT);
         // default ssl version
     } else {
         curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP);
         curl_setopt($curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP);
     }
     switch (self::$HTTP_REQUEST_METHOD) {
         case "GET":
             curl_setopt($curl, CURLOPT_HTTPGET, 1);
             break;
         case "POST":
             curl_setopt($curl, CURLOPT_POST, 1);
             curl_setopt($curl, CURLOPT_POSTREDIR, 0);
             // don't post on redirects
             break;
         case "PUT":
             curl_setopt($curl, CURLOPT_PUT, 1);
             break;
     }
     $response = curl_exec($curl);
     $info = curl_getinfo($curl);
     $error = curl_error($curl);
     curl_close($curl);
     $logMessage = self::$HTTP_REQUEST_METHOD . " " . $info["url"] . "<br/>" . "<strong>Response</strong>: " . $info["http_code"] . ": <pre>" . htmlspecialchars($response) . "</pre><br/>" . "<strong>Content-Type</strong>: " . $info["content_type"] . "<br/>" . "<strong>Size</strong> (Header/Request): " . $info["header_size"] . "/" . $info["request_size"] . " Bytes<br/>" . "<strong>Time</strong> (Total/Namelookup/Connect/Pretransfer/Starttransfer/Redirect): " . $info["total_time"] . " / " . $info["namelookup_time"] . " / " . $info["connect_time"] . " / " . $info["pretransfer_time"] . " / " . $info["starttransfer_time"] . " / " . $info["redirect_time"] . " seconds<br/>";
     Logger::notify("<strong>HTTP-SEND</strong>:<br/>" . $logMessage);
     if (!$response) {
         Logger::error("Error with send REST client: " . $error);
         return null;
     } elseif (!in_array($info["http_code"], array("200", "201", "204"))) {
         Logger::warning("Get wrong response: " . $info["http_code"]);
         return null;
     }
     return $response;
 }
Example #10
0
        // log the creation of a new section
        $label = sprintf(i18n::c('Section copy: %s'), strip_tags($section->get_title()));
        // poster and target section
        if (is_object($anchor)) {
            $description = sprintf(i18n::c('Sent by %s in %s'), Surfer::get_name(), $anchor->get_title());
        } else {
            $description = sprintf(i18n::c('Sent by %s'), Surfer::get_name());
        }
        // title and link
        if ($title = $section->get_title()) {
            $description .= $title . "\n";
        }
        $link = $context['url_to_home'] . $context['url_to_root'] . $section->get_url();
        $description = '<a href="' . $link . '">' . $link . '</a>' . "\n\n";
        // notify sysops
        Logger::notify('sections/duplicate.php: ' . $label, $description);
    }
    // action has to be confirmed
} elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
    Logger::error(i18n::s('The action has not been confirmed.'));
    // please confirm
} else {
    // the section or the anchor icon, if any
    $context['page_image'] = $item['icon_url'];
    if (!$context['page_image'] && is_object($anchor)) {
        $context['page_image'] = $anchor->get_icon_url();
    }
    // commands
    $menu = array();
    $menu[] = Skin::build_submit_button(i18n::s('Yes, I want to duplicate this section'), NULL, NULL, 'confirmed');
    if (isset($item['id'])) {
Example #11
0
File: edit.php Project: rair/yacs
         $menu = array_merge($menu, array(Comments::get_url($_REQUEST['id'], 'edit') => $label));
     }
     $follow_up .= Skin::build_list($menu, 'menu_bar');
     $context['text'] .= Skin::build_block($follow_up, 'bottom');
     // comment author
     if ($author = Surfer::get_name()) {
         $author = sprintf(i18n::c('Comment by %s'), $author);
     } else {
         $author = i18n::c('Anonymous comment');
     }
     // log the submission of a new comment
     $label = sprintf(i18n::c('%s: %s'), $author, strip_tags($anchor->get_title()));
     $link = $context['url_to_home'] . $context['url_to_root'] . Comments::get_url($_REQUEST['id']);
     $description = '<a href="' . $link . '">' . $link . '</a>';
     // notify sysops
     Logger::notify('comments/edit.php: ' . $label, $description);
     // forward to the updated thread
     if (!isset($_REQUEST['follow_up'])) {
         // redirect
         Safe::redirect($anchor->get_url('comments'));
     } elseif ($_REQUEST['follow_up'] === 'json') {
         // provide a json version of the new comment.
         Comments::render_json($_REQUEST['id'], $anchor);
     }
     // update of an existing comment
 } else {
     // remember the previous version
     if ($item['id']) {
         include_once '../versions/versions.php';
         Versions::save($item, 'comment:' . $item['id']);
     }
Example #12
0
File: edit.php Project: rair/yacs
                    $context['text'] .= Skin::build_block($follow_up, 'bottom');
                    // send silently a message to the event logger, if any
                    switch ($item['capability']) {
                        case 'A':
                            $label = sprintf(i18n::c('New associate: %s'), $item['nick_name']);
                            break;
                        case 'M':
                            $label = sprintf(i18n::c('New member: %s'), $item['nick_name']);
                            break;
                        default:
                            $label = sprintf(i18n::c('New subscriber: %s'), $item['nick_name']);
                            break;
                    }
                    $link = Users::get_permalink($item);
                    $description = '<a href="' . $link . '">' . $link . '</a>';
                    Logger::notify('users/edit.php: ' . $label, $description);
                }
            }
        }
    }
    // on GET always display the form
} else {
    $with_form = TRUE;
}
// display the form if required to do so
if ($with_form) {
    // the form to edit a user
    $context['text'] .= '<form method="post" action="' . $context['script_url'] . '" onsubmit="return validateDocumentPost(this)" id="main_form"><div>';
    $fields = array();
    // this form has several panels
    $panels = array();
 /**
  * This function returns the products by using the product filter.
  *
  * @author David Pauli <contact@david-pauli.de>
  * @return Product[] Returns an array of products.
  * @since 0.0.0
  * @since 0.1.0 Use a default Locale.
  * @since 0.1.1 Unstatic every attributes.
  * @since 0.1.2 Add error reporting.
  * @since 0.1.3 Get all results.
  * @since 0.2.0 Set error message for empty responses to notify.
  * @since 0.2.1 Implement REST client fixes.
  */
 public function getProducts()
 {
     $this->errorReset();
     $parameter = $this->getParameter();
     // if request method is blocked
     if (!RESTClient::setRequestMethod(HTTPRequestMethod::GET)) {
         $this->errorSet("RESTC-9");
         return;
     }
     RESTClient::send(self::RESTPATH . "?" . $parameter);
     $content = RESTClient::getJSONContent();
     // if respond is empty
     if (InputValidator::isEmpty($content)) {
         $this->errorSet("PF-8");
         Logger::notify("ep6\\ProductFilter\nREST respomd for getting products is empty.");
         return;
     }
     // if there is no results, page AND resultsPerPage element
     if (InputValidator::isEmptyArrayKey($content, "results") || InputValidator::isEmptyArrayKey($content, "page") || InputValidator::isEmptyArrayKey($content, "resultsPerPage")) {
         $this->errorSet("PF-9");
         Logger::error("ep6\\ProductFilter\nRespond for " . self::RESTPATH . " can not be interpreted.");
         return;
     }
     $this->results = $content['results'];
     $products = array();
     // is there any product found: load the products.
     if (!InputValidator::isEmptyArrayKey($content, "items") && sizeof($content['items']) != 0) {
         foreach ($content['items'] as $item) {
             $product = new Product($item);
             // go to every filter
             foreach ($this->filters as $filter) {
                 switch ($filter->getAttribute()) {
                     case 'stocklevel':
                         $value = array();
                         $value["stocklevel"] = $product->getStocklevel();
                         break;
                     case 'price':
                         $value = array();
                         $value["price"] = $product->getPrice()->getAmount();
                         break;
                     case 'category':
                         $value = array();
                         $value["category"] = $product->getCategories();
                         break;
                     default:
                         $value = $item;
                         break;
                 }
                 if (!InputValidator::isEmptyArrayKey($value, $filter->getAttribute()) || $filter->getOperator() == FilterOperation::UNDEF) {
                     if (!InputValidator::isArray($value[$filter->getAttribute()])) {
                         if (!$filter->isElementInFilter($value)) {
                             continue 2;
                         }
                     }
                 } else {
                     continue 2;
                 }
             }
             array_push($products, $product);
         }
     }
     return $products;
 }
 /**
  * This function returns the orders by using the order filter.
  *
  * @author David Pauli <contact@david-pauli.de>
  * @return Order[] Returns an array of orders.
  * @since 0.1.3
  * @since 0.2.0 Set error message for empty responses to notify.
  * @since 0.2.1 Implement REST client fixes.
  */
 public function getOrders()
 {
     $this->errorReset();
     $parameter = $this->getParameter();
     // if request method is blocked
     if (!RESTClient::setRequestMethod(HTTPRequestMethod::GET)) {
         $this->errorSet("RESTC-9");
         return;
     }
     RESTClient::send(self::RESTPATH . "?" . $parameter);
     $content = RESTClient::getJSONContent();
     // if respond is empty
     if (InputValidator::isEmpty($content)) {
         $this->errorSet("OF-1");
         Logger::notify("ep6\\OrderFilter\nREST respond for getting orders is empty.");
         return;
     }
     // if there is no results, page AND resultsPerPage element
     if (InputValidator::isEmptyArrayKey($content, "results") || InputValidator::isEmptyArrayKey($content, "page") || InputValidator::isEmptyArrayKey($content, "resultsPerPage")) {
         $this->errorSet("OF-2");
         Logger::error("ep6\\OrderFilter\nRespond for " . self::RESTPATH . " can not be interpreted.");
         return;
     }
     $this->results = $content['results'];
     $orders = array();
     // is there any order found: load the products.
     if (!InputValidator::isEmptyArrayKey($content, "items") && sizeof($content['items']) != 0) {
         foreach ($content['items'] as $item) {
             $order = new Order($item);
             // go to every filter
             foreach ($this->filters as $filter) {
                 if (!InputValidator::isEmptyArrayKey($item, $filter->getAttribute()) || $filter->getOperator() == FilterOperation::UNDEF) {
                     if (!InputValidator::isArray($item[$filter->getAttribute()])) {
                         if (!$filter->isElementInFilter($item)) {
                             continue 2;
                         }
                     }
                 } else {
                     continue 2;
                 }
             }
             array_push($orders, $order);
         }
     }
     return $orders;
 }