oRequest = new WP_Http; $this->cookies = isset($_COOKIE[$this->cookieName]) ? unserialize(stripslashes($_COOKIE[$this->cookieName])) : array(); } public function __destruct() { } public function out() { print $this->html; } public function doAction() { $action = $_GET['action']; $params = $_GET + $_POST; $html = ''; switch($action) { case 'test': $html = $this->test();break; case 'dashboard': $html = $this->dashboard();break; case 'box': $html = $this->box();break; case 'advsearch': $html = $this->advsearch();break; case 'settings': $html = $this->settings();break; case 'category': $html = $this->category($params);break; case 'photo': $html = $this->photo($params);break; case 'signin': $html = $this->signin($params);break; case 'search': $html = $this->search($params);break; case 'insert-media': $html = $this->insertMedia($params);break; } return $this->html = $html; } public function test() { return $this->request($this->urlPrefix.'/testpage.php'); } public function insertMedia($params=array()) { $args = array( 'method'=>'POST', 'body'=>$params ); $json = $this->request($this->urlPrefix.'/wp/insert-media/'.$params['photo'].'/'.$params['sec'].'/',$args); $vars = json_decode($json,true); $html=$vars['html']; if ($vars['hosting'] == 'wordpress') { $photourl = $vars['image-src']; $photofilename = $vars['image-filename']; $time = current_time('mysql'); if ( ! ( ( $uploads = wp_upload_dir($time) ) && false === $uploads['error'] ) ) { print 'error'; } $filename = wp_unique_filename( $uploads['path'], $photofilename, null ); $new_file = $uploads['path'] . "/$filename"; $defaults = array('cookies' => $this->cookies); $args = wp_parse_args( array(), $defaults ); $r = $this->oRequest->request($photourl,$args); $content = $r['body']; file_put_contents($new_file, $content); $stat = stat( dirname( $new_file )); $perms = $stat['mode'] & 0000666; @ chmod( $new_file, $perms ); $new_url = $uploads['url'] . "/$filename"; //print $photourl . ' - > '.$new_url; $html = str_replace($photourl,$new_url,$html); //print $html; //exit; } return $this->sendToEditor(html_entity_decode(preg_replace('/[\r\n]+/',' ',$html))); //insert photo to post //close iframe return ''; } public function photo($params=array()) { return $this->request($this->urlPrefix.'/wp/photo/'.$params['photo'].'/'.$params['sec'].'/'); } public function category($params=array()) { return $this->request($this->urlPrefix.'/wp/category/'.$params['category'].'/'.($params['npage'] ? ($params['npage'].'/') : '') ); } public function search($params=array()) { $q = htmlspecialchars($params['q'], ENT_QUOTES, 'utf-8'); return $this->request($this->urlPrefix.'/wp/search/?q='.$q.'&page='.($params['npage'] ? $params['npage'] : 1) ); } public function dashboard() { return $this->request($this->urlPrefix.'/wp/dashboard/'); } public function signin($params=array()) { $defaults = array('method' => 'POST'); $r = wp_parse_args( $params, $defaults ); return $this->request($this->urlPrefix.'/wp/signin/?signin[email]='.$params['signin']['email'].'&signin[password]='.$params['signin']['password'],$r); } public function box() { return $this->request($this->urlPrefix.'/wp/box/'); } public function settings() { return $this->request($this->urlPrefix.'/wp/settings/'); } public function advsearch() { return $this->request($this->urlPrefix.'/wp/advsearch/'); } public function sendToEditor($content) { return ' '; } public function request($url,$args=array()) { $k = 3; do { $url = $url. (preg_match('/\?/',$url) ? '&' : '?') .'&wpurl='.urlencode(getenv('HTTP_REFERER') ? getenv('HTTP_REFERER') :plugin_dir_url( __FILE__ )) .'&wp_foter_path='.urlencode(FOTER_PLUGIN_URL); $defaults = array('cookies' => $this->cookies); $args = wp_parse_args( $args, $defaults ); $r = $this->oRequest->request($url,$args); } while ($k-- && ($r instanceof Wp_Error)); if ($r instanceof Wp_Error) { return 'foter connection error'; } if (is_array($r['cookies']) && count($r['cookies'])) { $this->cookies = $r['cookies']; } setcookie($this->cookieName, serialize($this->cookies)); return $r['body']; } } ob_start(); require_once('../../../wp-admin/admin.php'); if( !class_exists( 'WP_Http' ) ) include_once( ABSPATH . WPINC. '/class-http.php' ); $view = new FoterView(); $html = $view->doAction(); wp_enqueue_style( 'media' ); wp_enqueue_style('foter.css'); wp_enqueue_script('foter.js'); ob_end_flush(); $body_id = 'media-upload'; print wp_iframe(array($view,'out'),'image');