/** * Allow method overloading for this class. * This method allows any method name to be called on this object. The method * called is the method called via RPC, within the scope defined in $this->scope. * * @param string $fname The function name to call * @param array $args An array of arguments that were called with the function * @return array The result array */ public function __call($fname, $args) { if ($this->scope != '') { $rpc_method = "{$this->scope}.{$fname}"; } else { $rpc_method = $fname; } $rpx = new SimpleXMLElement('<methodCall/>'); $rpx->addChild('methodName', $rpc_method); if (count($args) > 0) { $params = $rpx->addchild('params'); foreach ($args as $arg) { $param = $params->addchild('param'); XMLRPCUtils::encode_arg($param, $arg); } } $request = new RemoteRequest($this->entrypoint, 'POST'); $request->add_header('Content-Type: text/xml;charset=utf-8'); $request->set_body($rpx->asXML()); $request->execute(); if ($request->executed()) { $response = $request->get_response_body(); // @todo this should use the MultiByte class, not directly call mb_string functions $enc = mb_detect_encoding($response); $responseutf8 = mb_convert_encoding($response, 'UTF-8', $enc); try { // @todo this should use libxml_use_internal_errors() instead of trying to hide the PHP warning see the plugin info parsing code for an example $bit = ini_get('error_reporting'); error_reporting($bit && !E_WARNING); $responsexml = new SimpleXMLElement($responseutf8); error_reporting($bit); $tmp = $responsexml->xpath('//params/param/value'); if (!($responsestruct = reset($tmp))) { $tmp = $responsexml->xpath('//fault/value'); if (!($responsestruct = reset($tmp))) { throw new Exception(_t('Invalid XML response.')); } } return XMLRPCUtils::decode_args($responsestruct); } catch (Exception $e) { //Utils::debug( $response, $e ); error_reporting($bit); return false; } } }
/** * Allow method overloading for this class. * This method allows any method name to be called on this object. The method * called is the method called via RPC, within the scope defined in $this->scope. * * @param string $fname The function name to call * @param array $args An array of arguments that were called with the function * @return array The result array */ public function __call($fname, $args) { if ($this->scope != '') { $rpc_method = "{$this->scope}.{$fname}"; } else { $rpc_method = $fname; } $rpx = new SimpleXMLElement('<methodCall/>'); $rpx->addChild('methodName', $rpc_method); if (count($args) > 0) { $params = $rpx->addchild('params'); foreach ($args as $arg) { $param = $params->addchild('param'); XMLRPCUtils::encode_arg($param, $arg); } } $request = new RemoteRequest($this->entrypoint, 'POST'); $request->add_header('Content-Type: text/xml'); $request->set_body($rpx->asXML()); $request->execute(); if ($request->executed()) { $response = $request->get_response_body(); $enc = mb_detect_encoding($response); $responseutf8 = mb_convert_encoding($response, 'UTF-8', $enc); try { $bit = ini_get('error_reporting'); error_reporting($bit && !E_WARNING); $responsexml = new SimpleXMLElement($responseutf8); error_reporting($bit); $tmp = $responsexml->xpath('//params/param/value'); if (!($responsestruct = reset($tmp))) { $tmp = $responsexml->xpath('//fault/value'); if (!($responsestruct = reset($tmp))) { throw new Exception(_t('Invalid XML response.')); } } return XMLRPCUtils::decode_args($responsestruct); } catch (Exception $e) { //Utils::debug($response, $e); error_reporting($bit); return false; } } }
/** * Execute a call to the Picasa Service * * @param $url string The destination url * @param $args array Optional Extra arguments * @param $post_data Optional Post data * @return mixed false on error or xml string */ public function call($url, $args = array(), $post_data = '') { $token = Options::get('picasa_token_' . User::identify()->id); $default_args = array('method' => 'GET'); $args = array_merge($default_args, $args); $request = new RemoteRequest($url, $args['method']); // set authorisation header $request->add_header(array("Authorization" => "AuthSub token=" . $token)); // add extra headers if (isset($args['http_headers'])) { foreach ($args['http_headers'] as $key => $value) { $request->add_header(array($key => $value)); } } if ($post_data != '') { $request->set_body($post_data); } $request->set_timeout(30); // execute request $result = $request->execute(); if (Error::is_error($result)) { return $result; } // get the response if executed if ($request->executed()) { $response = $request->get_response_body(); } if (!$response) { return Error::raise('API call failure', E_USER_WARNING); } // parse the result try { $xml = new SimpleXMLElement($response); return $xml; } catch (Exception $e) { Session::error('Currently unable to connect to the Picasa API.', 'Picasa API'); return false; } }
/** * Send a single Pingback * @param string $source_uri The URI source of the ping (here) * @param string $target_uri The URI destination of the ping (there, the site linked to in the content) * @param Post $post The post object that is initiating the ping, used to track the pings that were sent * @todo If receive error code of already pinged, add to the successful. */ public function send_pingback( $source_uri, $target_uri, $post = NULL ) { // RemoteRequest makes it easier to retrieve the headers. try { $rr = new RemoteRequest( $target_uri ); $rr->execute(); if ( ! $rr->executed() ) { return false; } } catch ( Exception $e ) { // log the pingback error EventLog::log( _t( 'Unable to retrieve target, can\'t detect pingback endpoint. (Source: %1$s | Target: %2$s)', array( $source_uri, $target_uri ) ), 'err', 'Pingback' ); return false; } $headers = $rr->get_response_headers(); $body = $rr->get_response_body(); // Find a Pingback endpoint. if ( isset( $headers['X-Pingback'] ) ) { $pingback_endpoint = $headers['X-Pingback']; } elseif ( preg_match( '/<link rel="pingback" href="([^"]+)" ?\/?'.'>/is', $body, $matches ) ) { $pingback_endpoint = $matches[1]; } else { // No Pingback endpoint found. return false; } try { $response = XMLRPCClient::open( $pingback_endpoint )->pingback->ping( $source_uri, $target_uri ); } catch ( Exception $e ) { EventLog::log( _t( 'Invalid Pingback endpoint - %1$s (Source: %2$s | Target: %3$s)', array( $pingback_endpoint, $source_uri, $target_uri ) ), 'err', 'Pingback' ); return false; } if ( isset( $response->faultString ) ) { EventLog::log( _t( 'Pingback error: %1$s - %2$s (Source: %3$s | Target: %4$s)', array( $response->faultCode, $response->faultString, $source_uri, $target_uri ) ), 'err', 'Pingback' ); return false; } else { // The pingback has been registered and is stored as a successful pingback. if ( is_object( $post ) ) { if ( isset( $post->info->pingbacks_successful ) ) { $pingbacks_successful = $post->info->pingbacks_successful; $pingbacks_successful[]= $target_uri; $post->info->pingbacks_successful = $pingbacks_successful; } else { $post->info->pingbacks_successful = array( $target_uri ); } $post->info->commit(); } return true; } }
/** * Send a single Pingback * @param string $source_uri The URI source of the ping (here) * @param string $target_uri The URI destination of the ping (there, the site linked to in the content) * @param Post $post The post object that is initiating the ping, used to track the pings that were sent * @todo If receive error code of already pinged, add to the successful. */ public function send_pingback($source_uri, $target_uri, $post = NULL) { // RemoteRequest makes it easier to retrieve the headers. $rr = new RemoteRequest($target_uri); $rr->execute(); if (!$rr->executed()) { return false; } $headers = $rr->get_response_headers(); $body = $rr->get_response_body(); // Find a Pingback endpoint. if (preg_match('/^X-Pingback: (\\S*)/im', $headers, $matches)) { $pingback_endpoint = $matches[1]; } elseif (preg_match('/<link rel="pingback" href="([^"]+)" ?\\/?' . '>/is', $body, $matches)) { $pingback_endpoint = $matches[1]; } else { // No Pingback endpoint found. return false; } try { $response = XMLRPCClient::open($pingback_endpoint)->pingback->ping($source_uri, $target_uri); } catch (Exception $e) { EventLog::log('Invalid Pingback endpoint - ' . $pingback_endpoint . ' (Source: ' . $source_uri . ' | Target: ' . $target_uri . ')', 'info', 'Pingback'); return false; } if (isset($response->faultString)) { EventLog::log($response->faultCode . ' - ' . $response->faultString . ' (Source: ' . $source_uri . ' | Target: ' . $target_uri . ')', 'info', 'Pingback'); return false; } else { // The pingback has been registered and is stored as a successful pingback. if (is_object($post)) { if (isset($post->info->pingbacks_successful)) { $pingbacks_successful = $post->info->pingbacks_successful; $pingbacks_successful[] = $target_uri; $post->info->pingbacks_successful = $pingbacks_successful; } else { $post->info->pingbacks_successful = array($target_uri); } $post->info->commit(); } return true; } }
/** * checks for the presence of an .htaccess file * invokes write_htaccess() as needed */ public function check_htaccess() { // default is assume we have mod_rewrite $this->handler_vars['no_mod_rewrite'] = false; // If this is the mod_rewrite check request, then bounce it as a success. if (strpos($_SERVER['REQUEST_URI'], 'check_mod_rewrite') !== false) { echo 'ok'; exit; } if (FALSE === strpos($_SERVER['SERVER_SOFTWARE'], 'Apache')) { // .htaccess is only needed on Apache // @TODO: add support for IIS and lighttpd rewrites return true; } $result = false; if (file_exists(HABARI_PATH . '/.htaccess')) { $htaccess = file_get_contents(HABARI_PATH . '/.htaccess'); if (false === strpos($htaccess, 'HABARI')) { // the Habari block does not exist in this file // so try to create it $result = $this->write_htaccess(true); } else { // the Habari block exists $result = true; } } else { // no .htaccess exists. Try to create one $result = $this->write_htaccess(); } if ($result) { // the Habari block exists, but we need to make sure // it is correct. // Check that the rewrite rules actually do the job. $test_ajax_url = Site::get_url('habari') . '/check_mod_rewrite'; $rr = new RemoteRequest($test_ajax_url, 'POST', 20); $rr_result = $rr->execute(); if (!$rr->executed()) { $result = $this->write_htaccess(true, true, true); } } return $result; }
public function action_publish_post($post, $form) { if ($post->content_type == Post::type('photo')) { // We need this to retrieve our form values $this->add_controls($form); $photo_src = $form->pb_photo_src->value; $thumbnail_json = urldecode($form->pb_thumbnail->value); $post->info->pb_savephoto = $form->pb_savephoto->value; $request = new RemoteRequest($form->pb_photo_src->value, 'GET'); /* We do thumbnails first because we require them */ if ($post->info->pb_savephoto || $form->pb_refresh->value || $post->info->thumbnail_json != urldecode($form->pb_thumbnail->value)) { // Saves processing time if thumbnails aren't to be updated (also means photo won't be) if ($request->execute()) { $path_thumbnail = Options::get('pb__dirs_thumbnails') . '/' . basename($photo_src); // PATH_SEPARATOR? $path_thumbnail = $this->get_save_path($path_thumbnail, $post); $this->gd_make_thumbnail($request->get_response_body(), $path_thumbnail['path'], json_decode($thumbnail_json)); $post->info->thumbnail_path = $path_thumbnail['path']; $post->info->thumbnail_filename = $path_thumbnail['filename']; } else { // This won't stop the saving process, wouldn't it would be a bitch? Session::error(_t('Photoblog was unable to retrieve the photo, check source URL.')); } } /* Let's make sure the request completed successfully */ if ($request->executed() && ($post->info->pb_savephoto || Options::get('pb__savephotos'))) { $path_photo = Options::get('pb__dirs_photos') . '/' . basename($photo_src); // PATH_SEPARATOR? $path_photo = $this->get_save_path($path_photo, $post); if (!file_exists($path_photo['path']) || $form->pb_refresh->value) { file_put_contents($path_photo['path'], $request->get_response_body()); $post->info->photo_path = $path_photo['path']; $post->info->photo_filename = $path_photo['filename']; } } // Overwrite values at the end so we can previously compare values properly $post->info->photo_src = $photo_src; $post->info->thumbnail_json = $thumbnail_json; } }