get_row("SELECT * FROM $wpdb->posts ORDER BY post_date desc LIMIT 1" , 'ARRAY_A'); // echo "
";
// print_r($recent_post_date);
// echo "
"; // echo "

"; // echo "Hora strtotime:".strtotime($recent_post_date['post_date']); // echo "

"; // echo "Hora strtotime 15 min:".strtotime("-15 minutes"); // echo "

"; // echo "Hora Resultado:".(strtotime($recent_post_date['post_date']) > strtotime("-15 minutes")); // echo "

"; date_default_timezone_set('America/Sao_Paulo'); $cache_life = 60*1; $filemtime = @filemtime('controlePublicacao.txt'); if (!$filemtime or (time() - $filemtime >= $cache_life)){ $textPublicacao = "\r\nPublicação iniciada às:".date('d-m-Y H:i:s')."\r\n"; //echo $textPublicacao."
"; file_put_contents('controlePublicacao.txt',$textPublicacao,FILE_APPEND); // if (strtotime($recent_post_date['post_date']) < strtotime("-28 minutes")) { //echo "mais de 15 minutos

"; echo "Iniciando....
"; // if (strtotime($recent_post_date['post_date']) < strtotime("-22 minutes")) { // //echo "mais de 15 minutos

"; // echo "Iniciando....
"; // echo "
";
	//print_r($recent_post_date);
	// echo "
"; // echo "

"; $tmhOAuth = new tmhOAuth($twitter_auth); $statuses_url = '1.1/lists/list.json'; $code = $tmhOAuth->request('GET', $tmhOAuth->url($statuses_url), array( 'owner_screen_name'=>$owner_screen_name, 'count'=>40, )); $return = json_decode($tmhOAuth->response['response']); foreach ($return as $lineCanal){ $tmhOAuthSecao = new tmhOAuth($twitter_auth); $statuses_url = '1.1/lists/statuses.json'; $canal = $lineCanal->slug; $canalName = $lineCanal->name; $code = $tmhOAuthSecao->request('GET', $tmhOAuthSecao->url($statuses_url), array( 'slug'=>$canal, 'owner_screen_name'=>$owner_screen_name, 'count'=>2, 'include_rts'=> false )); // $secao = $lineCanal->user->screen_name; echo "
sessão: ".$canal; file_put_contents('controlePublicacao.txt',$canal,FILE_APPEND); $returnSecao = json_decode($tmhOAuthSecao->response['response']); //} file_put_contents('controlePublicacao.txt',$returnSecao,FILE_APPEND); foreach ($returnSecao as $line){ $jsonMontado = array(); echo "

Post:
";
	      print_r ($line);
				echo "
"; var_dump($line); file_put_contents('controlePublicacao.txt',$line,FILE_APPEND); $iddaPagina = $line->id; $urlPagina = $line->entities->urls[0]->url; $urlTwittePic = $line->entities->media[0]->url; $imagemPagina = $line->entities->media[0]->media_url; $hashTag = $line->entities->hashtags[0]->text; $imagemProfile = $line->user->profile_banner_url; $nameProfile = $line->user->name; $userProfile = $line->user->screen_name; $texto = $line->text; $texto = str_pad($texto, 3, ' ', STR_PAD_LEFT); //pad feed //$startat = stripos($texto, '@'); //$numat = substr_count($texto, '@'); $numhash = substr_count($texto, '#'); $numhttp = substr_count($texto, 'http'); $texto = preg_replace("/(http:\/\/)(.*?)\/([\w\.\/\&\=\?\-\,\:\;\#\_\~\%\+]*)/", "", $texto); //$texto = preg_replace("(@([a-zA-Z0-9\_]+))", "", $texto); //$texto = preg_replace('/(^|\s)#(\w+)/', '', $texto); $coisasATirar = array($urlTwittePic,$urlPagina,"#","@"); $texto = str_replace($coisasATirar, "", $texto); $fonte = $owner_screen_name = 'peranewsint'?'SOURCE':'FONTE'; // if($urlPagina != ''&& $imagemPagina != ''){ if($urlPagina != ''){ $arquivoPost = ""; $html = file_get_html($urlPagina); if($userProfile == 'autoesporte'){ $xPathWrap_P = $html->find('div[id=materia-parsed-corpo]',0); }else if($userProfile == 'g1carros' || $userProfile == 'siteEgo'){ if($html->find('div[id=materia-letra]',0) != ''){ $xPathWrap_P = $html->find('div[id=materia-letra]',0); }else{ $xPathWrap_P = $html->find('article',0); } }else if(strrpos($userProfile,'EXAME') === true ){ $xPathWrap_P = $html->find('article',0); }else if(strrpos($userProfile,'GizmodoBR') === true ){ $xPathWrap_P = $html->find('div[id=content]',0); }else if(strrpos($userProfile,'quatrorodas') === true ){ //header('Content-Type: text/html; charset=iso-8859-1'); //echo ''; }else{ if($html->find('article',0) != ''){ $xPathWrap_P = $html->find('article',0); }else{ $xPathWrap_P = $html->find('body',0); } //echo "Caiu no else
"; } $arquivoPost .= ''; foreach($xPathWrap_P->find('p') as $i=>$paragrafo) { // if($i = floor($i/2)){ // $arquivoPost .= '

'.$paragrafo.'

'; // }else{ $arquivoPost .= '

'.$paragrafo.'

'; // } }//foreach Paragrafo //$arquivoPost .= '

'; $arquivoPost .= '

'.$fonte.'

'; $jsonMontado = array( 'post_author' => 1, //'post_content' => iconv('ISO-8859-1','UTF-8', $arquivoPost), 'post_content' => mb_detect_encoding($str, 'UTF-8', true)!="UTF-8"? iconv('ISO-8859-1','UTF-8', $arquivoPost):$arquivoPost, 'post_title' => wp_strip_all_tags($texto), 'post_status' => 'publish', 'post_type' => 'post', 'import_id' => $iddaPagina, 'tax_input' => array( 'non_hierarchical_tax' => $userProfile,$hashTag, ) ); $post_exists = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE id = '" . $iddaPagina . "'", 'ARRAY_A'); if(!$post_exists){ $post_id = wp_insert_post( $jsonMontado, true ); // echo 'Inserido Post: '; // print_r($post_id); // echo ', Title: '.wp_strip_all_tags($texto).'
'; $nPosts++; if($imagemPagina != ''){ $imagemPaginaOriginal = $imagemPagina; $upload_dir = wp_upload_dir(); $image_data = file_get_contents($imagemPagina); $filename = basename($imagemPagina); if(wp_mkdir_p($upload_dir['path'])) $file = $upload_dir['path'] . '/' . $filename; else $file = $upload_dir['basedir'] . '/' . $filename; file_put_contents($file, $image_data); $wp_filetype = wp_check_filetype($filename, null ); $attachment = array( 'post_mime_type' => $wp_filetype['type'], 'post_title' => sanitize_title($texto), 'post_content' => '$texto', 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment( $attachment, $file, $post_id ); require_once(ABSPATH . 'wp-admin/includes/image.php'); $attach_data = wp_generate_attachment_metadata( $attach_id, $file ); wp_update_attachment_metadata( $attach_id, $attach_data ); set_post_thumbnail( $post_id, $attach_id ); }else{ // echo 'Post nao inserido: '.$iddaPagina.', Title: '.wp_strip_all_tags($texto).'
'; } wp_set_object_terms( 1, null, 'category' ); wp_set_object_terms($post_id, str_replace("1", "", $canalName), 'category', False); // $getImageFile = $imagemPagina; // $wp_filetype = wp_check_filetype( $getImageFile, null ); // $attachment_data = array( // 'post_mime_type' => $wp_filetype['type'], // 'post_title' => sanitize_title($texto), // 'post_content' => '', // 'post_status' => 'inherit' // ); // // $attach_id = wp_insert_attachment( $attachment_data, $getImageFile, $post_id ); } //echo '

Canal:'.$canal.' Secao:'.$userProfile.', Postid:'.$iddaPagina.', Titulo:'.$texto.', UTF:'.mb_detect_encoding($str, 'UTF-8', true).',
URL: '.$urlPagina.'
Imagem:



'; //echo "erro".$arquivoPost.'

'; }//if tem link }//foreach Post // }//foreach Secao }//foreach Canal $textPublicacao2 = ", com: ".$nPosts." salvos\r\n"; //echo $textPublicacao2."
"; file_put_contents('controlePublicacao.txt',$textPublicacao2,FILE_APPEND); }else{ return $cache_life; echo date('d-m-Y H:i:s')." menos de ".$cache_life." segundos

"; } ?>