function url_exists($url) { $log = wpro()->debug->logblock('WPRO_Http::url_exists($url = "' . $url . '")'); $ch = curl_init(); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_URL, $url); $result = trim(curl_exec_follow($ch)); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($httpCode != 200) { return $log->logreturn(false); } return $log->logreturn(true); }
/** * gets the html content from a URL * @param string $url * @return string */ function curl_get_contents($url) { $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_URL, $url); curl_setopt($c, CURLOPT_TIMEOUT, 30); curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0); // curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE); // $contents = curl_exec($c); $contents = curl_exec_follow($c); curl_close($c); return $contents ? $contents : FALSE; }
function get_web_page($url) { $user_agent = 'Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0'; $options = array(CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_POST => false, CURLOPT_USERAGENT => $user_agent, CURLOPT_COOKIEFILE => "cookie.txt", CURLOPT_COOKIEJAR => "cookie.txt", CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_ENCODING => "", CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => 120, CURLOPT_TIMEOUT => 120, CURLOPT_MAXREDIRS => 10); $ch = curl_init($url); curl_setopt_array($ch, $options); // $content = curl_exec( $ch ); $content = curl_exec_follow($ch); $err = curl_errno($ch); $errmsg = curl_error($ch); $header = curl_getinfo($ch); curl_close($ch); $header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; return $header; }
function getURLMetadata($url) { //allow only http(s) and (s)ftp $protocols = '/^[hs]{0,1}[tf]{0,1}tp[s]{0,1}\\:\\/\\//i'; //if not (allowed) protocol is given, assume http if (preg_match($protocols, $url) == 0) { $url = 'http://' . $url; } $metadata['url'] = $url; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $page = curl_exec_follow($ch); curl_close($ch); @preg_match("/<title>(.*)<\\/title>/si", $page, $match); $metadata['title'] = htmlspecialchars_decode(@$match[1]); return $metadata; }
function gtw_attend($info, $wkey) { $hyConNameFirst = $info['first_name']; $hyConNameLast = $info['last_name']; $hyConEmail = $info['email']; $url = "https://www.gotowebinar.com/en_US/island/webinar/registration.flow"; $postvar = "Template=island/webinar/registration.tmpl&Form=webinarRegistrationForm&WebinarKey=" . $wkey . "&Name_First=" . $hyConNameFirst . "&Name_Last=" . $hyConNameLast . "&Email=" . $hyConEmail; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FAILONERROR, 1); // old code - curlopt followlocation won't work with open base_dir or if PHP is in safe mode. // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postvar); $result = curl_exec_follow($ch); curl_close($ch); }
function pmxi_curl_download($url, $fullpath, $to_variable) { if (!function_exists('curl_version')) { return false; } $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $rawdata = curl_exec_follow($ch); $result = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if (empty($rawdata)) { return false; } if (!@file_put_contents($fullpath, $rawdata)) { $fp = fopen($fullpath, 'w'); fwrite($fp, $rawdata); fclose($fp); } return $result == 200 ? $to_variable ? $rawdata : true : false; }
function curl_file_get_contents($url) { // set address $curl = curl_init(trim($url, ' ?')); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); curl_setopt($curl, CURLOPT_FAILONERROR, TRUE); curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE); curl_setopt($curl, CURLOPT_TIMEOUT, 15); curl_setopt($curl, CURLOPT_VERBOSE, TRUE); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // request content $content = curl_exec_follow($curl); $a = array('type' => curl_getinfo($curl, CURLINFO_CONTENT_TYPE), 'content' => $content, 'status' => curl_getinfo($curl, CURLINFO_HTTP_CODE)); // close curl_close($curl); // return return preg_match('/^200|304|301|300$/m', $a['status']) && preg_match('/jpg|png|jpeg|gif$/i', $a['type']) ? $a : null; }
function load_image_to_edit_path($filepath, $attachment_id, $size) { $log = wpro()->debug->logblock('WPRO_Uploads::load_image_to_edit_path($filepath = "' . $filepath . '", $attachment_id = ' . $attachment_id . ', $size = ' . $size . ')'); if ($filepath === '') { // Why is this shit being called with an empty $filepath!? $log->log('File path is empty!'); } else { if (file_exists($filepath)) { // When no backend is active: // Without this file_exists, during an upload to WordPress, // it will try to download the image to it's own path, // which results in the upload being 0 bytes in length. $log->log("Don't download. File already exists."); } else { $attachment_url = wp_get_attachment_url($attachment_id); $fileurl = wpro()->url->attachmentUrl($filepath); $filepath = wpro()->url->tmpFilePath($filepath); $log->log('$attachment_url = "' . $attachment_url . '"'); $log->log('$fileurl = "' . $fileurl . '"'); $log->log('$filepath = "' . $filepath . '"'); if (substr($fileurl, 0, 7) == 'http://' || substr($fileurl, 0, 8) == 'https://') { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $fileurl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); $fh = fopen($filepath, 'w'); fwrite($fh, curl_exec_follow($ch)); fclose($fh); //$this->removeTemporaryLocalData($filepath); return $log->logreturn($filepath); } } } return $log->logreturn($filepath); }
function load_image_to_edit_path($filepath) { $this->debug('WordpressReadOnly::load_image_to_edit_path("' . $filepath . '");'); if (substr($filepath, 0, 7) == 'http://') { $ending = ''; if (preg_match('/\\.([^\\.\\/]+)$/', $filepath, $regs)) { $ending = '.' . $regs[1]; } $tmpfile = $this->tempdir . 'wpro' . time() . rand(0, 999999) . $ending; while (file_exists($tmpfile)) { $tmpfile = $this->tempdir . 'wpro' . time() . rand(0, 999999) . $ending; } $filepath = $this->url_normalizer($filepath); $this->debug('-> Loading file from: ' . $filepath); $this->debug('-> Storing file at: ' . $tmpfile); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $filepath); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); $fh = fopen($tmpfile, 'w'); fwrite($fh, curl_exec_follow($ch)); fclose($fh); $this->removeTemporaryLocalData($tmpfile); return $tmpfile; } return $filepath; }
public static function save_google_docs($note_id) { $edit_url = DB::GetOne('SELECT doc_id FROM utils_attachment_googledocs WHERE note_id = %d', array($note_id)); if (!$edit_url) { Base_StatusBarCommon::message(__('Document not found'), 'warning'); return false; } if(!preg_match('/(spreadsheet|document)%3A(.+)$/i',$edit_url,$matches)) { Base_StatusBarCommon::message(__('Document not found'), 'warning'); return false; } $edit_url = $matches[2]; $doc = $matches[1]=='document'; if ($doc) $export_url = 'https://docs.google.com/feeds/download/documents/Export?id='.$edit_url.'&exportFormat=doc'; else $export_url = 'https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key='.$edit_url.'&exportFormat=xls'; DB::Execute('DELETE FROM utils_attachment_googledocs WHERE note_id = %d', array($note_id)); $g_auth = Utils_AttachmentCommon::get_google_auth(null, null, $doc?'writely':'wise'); $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $headers = array( "Authorization: GoogleLogin auth=" . $g_auth, "If-Match: *", "GData-Version: 3.0", ); curl_setopt($curl, CURLOPT_URL, $export_url); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_POST, false); $response = curl_exec_follow($curl); $row = DB::GetRow('SELECT f.*,l.f_crypted as crypted FROM utils_attachment_file f INNER JOIN utils_attachment_data_1 l ON l.id=f.attach_id WHERE f.id=%d',array($note_id)); $local = DATA_DIR.'/Utils_Attachment/temp/'.Acl::get_user().'/gdocs'; @mkdir($local,0777,true); $dest_file = $local.'/'.$row['id']; if($row['crypted']) { $password = $_SESSION['client']['cp'.$row['attach_id']]; $response = Utils_AttachmentCommon::encrypt($response,$password); } file_put_contents($dest_file, $response); if($doc) { $ext = 'docx'; } else $ext = 'xlsx'; $row['original'] = substr($row['original'],0,strrpos($row['original'],'.')).'.'.$ext; Utils_AttachmentCommon::add_file($row['attach_id'], Acl::get_user(), $row['original'], $dest_file); DB::Execute('UPDATE utils_attachment_file SET deleted=1 WHERE id=%d',array($row['id'])); $headers = array( "Authorization: GoogleLogin auth=" . $g_auth, "If-Match: *", "GData-Version: 3.0", ); curl_setopt($curl, CURLOPT_URL, $edit_url); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE'); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_POST, false); $response = curl_exec($curl); Base_StatusBarCommon::message(__('Changes saved')); }