Stories plugin 2

// To generate a wssharestory from a post id add_action( 'admin_init', 'create_wssharestory_from_url_from_admin_init' ); function create_wssharestory_from_url_from_admin_init() { if ( isset( $_GET['post_type'] ) && $_GET['post_type'] == 'ws-share-plugin' && isset( $_GET['id'] ) ) { if (isset( $_GET['action'] )) { if ($_GET['action'] == 'wsshareaval') { // o cliente clicou em avaliar artigo $idavaliacao = $_GET['idavaliacao']; $meuid = $_GET['id']; $link = get_permalink($meuid); ?> <body style="background:#f0f0f1"> <h2>Avaliação do WebStories</h2> <h3>Link: <a href="<?php echo $link; ?>"><?php echo $link; ?> </a><br></h3> <h3>Observação: Avaliações serão apresentadas ao criador para que ele evolua na construção da comunidade. Mas fique tranquilo que não informamos qual usuário fez a avaliação.</h3><br> <form action="<?php echo admin_url( 'admin-post.php' ); ?>"> <input type="hidden" name="action" value="wpseaval_23456"> <input type="hidden" name="idorigem" value="<?php echo $meuid; ?>"> <input type="hidden" name="iddestino" value="<?php echo $idavaliacao; ?>"> <fieldset> <legend>Como você avalia o WebStorie:</legend> <div> <input type="radio" id="avaliacao" name="avaliacao" value="positivo" checked> <label for="huey">Positivo</label> </div> <div> <input type="radio" id="avaliacao" name="avaliacao" value="negativo"> <label for="dewey">Negativo</label> </div> </fieldset> <h2>Informe o que pode ser melhorado nele: </h2><br> <textarea id="w3review" name="melhoria" rows="4" cols="90"></textarea> <?php submit_button( 'Enviar Avaliação' ); ?> </form> </body> <?php exit; } } else { $post_id = $_GET['id']; $wssharestory = create_wssharestory($post_id);// If create wssharestory was successful, redirect to post edit page if ($wssharestory[1] == 200) { wp_redirect( admin_url( 'edit.php?post_type=ws-share-plugin&error=0' ) ); exit; } else { // If not redirect to post edit page with error message $error = $wssharestory[0]; ?> <body style="background:#f0f0f1"> <h2 style="color: white;">Erro ao Enviar Web Stories!</h2><br> <h2 style="color:red"><?php echo $error; ?></h2><br> <h2 style="color: white;">Corrija o WebStorie para que possa compartilhar!</h2><br> <a href="edit.php?post_type=web-story" style="background-color: #0d1239; border: none; color: white; padding: 12px 24px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; border-radius: 20px; width: 150px;">Voltar</a> </body> <?php exit; //$redirect = add_query_arg( 'edit.php?post_type=web-story', 'error', $error ); //wp_redirect( admin_url( 'edit.php?post_type=web-story') ); //exit; } } } } // Return only post_content when accessing page with post_content=true in url add_action( 'template_redirect', 'return_share_post_content' ); function return_share_post_content() { // Check if is singular and if post type is ws-share-plugin, if not return if ( ! is_singular( 'ws-share-plugin' ) ) { return; } else { global $post; $post_content = $post->post_content; echo $post_content; exit; } } // Function to create the configuration page // Configuration page will have a form to create webstories from a url // an input for token // an input for Adsense code // an input for Google Analytics code function wssharestory_config_page() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); } $plugin1 = is_plugin_active( 'amp/amp.php' ); if ($plugin1 == false) { $plugin1 = is_plugin_active( 'accelerated-mobile-pages/accelerated-mobile-pages.php' ); } $plugin2 = is_plugin_active( 'web-stories/web-stories.php' ); $plugin1 = true; if (($plugin1 == false ) or ($plugin2 == false)) { ?> <div style="background-color: black; text-align: center; padding: 22px; position: fixed; top: 22%; left: 22%; bottom: 10%; right: 22%; margin: auto; border-radius: 10px;"> <h2 >ENVIANDO WEB STORIES...</h2> <h1>Configurações - Versão 6.2</h1><br><h1 style="color:red">Problema para utilizar o Plugin</h1><br> <?php if ($plugin1 == false ) { ?> <h2>Você precisa instalar o <a href="<?php admin_url( 'plugin-install.php?s=amp&tab=search&type=term'); ?> ">plugin AMP</a> ou o <a href="https://blog.winfacil.com.br/wp-admin/plugin-install.php?s=accelerated-mobile-page&tab=search&type=term">plugin accelerated mobile page</a> para compartilhar os Web Stories</h2><br> <?php } if ($plugin2 == false ) { ?> <h2>Você precisa instalar o <a href="<?php admin_url( 'plugin-install.php?s=web-stories&tab=search&type=term'); ?>">plugin Web Stories</a> para compartilhar os Web Stories</h2><br> </div><?php } } else { ?> <div class="wrap" style="background-color: #1C1C1C; border: 1px solid #ccc; border-radius: 10px; width: 90%; margin: 2% auto 0; padding: 2%;"> <h1 style="color: #fff;"><b>WEB STORIES PLUS</b> - Configurações - Versão <font color="yellow">6.2</font></h1><p> <div class="notice notice-success is-dismissible"><h4 style="color: #000;">Caso você ainda não tenha sua conta (Storie Plus Token) acesse <a href="https://rede.servidortrader.com/register.php">CLICANDO AQUI!</a></h4></div> <h2 style="color: #fff;">Como Funciona:</h2> <ol style="color: #fff;"> <li>Gere seu Storie Plus Token e Informe nessa tela</li> <li>Vá no menu <b>Stories</b> -> <b> Todas as Histórias</b>. </li> <li>Escolha um Stories para compartilhar e clique em "Compartilhar Postagem" - Ao compartilhar um Stories, você recebe um novo Stories compartilhado por outro usuário</li> <li><b>Observação:</b> WebStories recebidos NÃO podem ser compartilhados E os web stories baixados não podem ser editados..</li> <li><b>Observação2:</b> Caso você esteja com problemas no webstories recebidos, baixe o plugin AMP ou plugin accelerated mobile page para resolver o problema.</li> </ol> <form method="post" action="options.php"> <?php settings_fields( 'wssharestory-config' ); ?> <?php do_settings_sections( 'wssharestory-config' ); ?> <div class="form-table" style="color: #fff;"> <label><b>Storie Plus Token</b></label><br> <input type="text" name="wssharestory_token" value="<?php echo esc_attr( get_option( 'wssharestory_token' ) ); ?>" /> <label><b>Publicar Automaticamente WebStories Recebidos?</b></label> <?php $escolha = 'S'; if (esc_attr( get_option( 'wssharestory_publicado' ) ) == 'S') { $escolha = 'S'; }else if (esc_attr( get_option( 'wssharestory_publicado' ) ) == 'N') { $escolha = 'N'; } ?> <select name="wssharestory_publicado" > <option value="S" <?php if ($escolha == 'S') { echo 'selected'; } ?> >SIM</option> <option value="N" <?php if ($escolha == 'N') { echo 'selected'; } ?> >NÃO</option> </select> <?php submit_button(); ?> <?php echo display_developers(); ?> </div> </form> </div> <?php } }// Register the settings add_action( 'admin_init', 'register_wssharestory_config' ); function register_wssharestory_config() { register_setting( 'wssharestory-config', 'wssharestory_token' ); register_setting( 'wssharestory-config', 'wssharestory_publicado' ); } function wssource_download_page() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); } else { // busca 1 a 1 no servidor// baixa os stories//guarda no banco $link = site_url(); $token = get_option( 'wssharestory_token' ); $publicado = get_option( 'wssharestory_publicado' ); if ($token == '') { ?> <h1>SEM TOKEN ASSOCIADO. FAVOR CONFIGURAR!</h1> <?php } else { $valido = false; } $url1 = "https://dados.servidortrader.com/fase1baixarwebstories.php"; $response1 = wp_remote_post( $url1 , array( 'timeout' => 15, 'method' => 'POST', 'body' => array ( 'token' => $token, 'link' => $link ) ) ); $resposta1 = wp_remote_retrieve_body($response1); $resposta1 = explode('#',$resposta1); if ($resposta1[0] == 'N') { show_message('VOCÊ NÃO TEM WEB-STORIES PARA BAIXAR ! <br> MOTIVO:'.$resposta1[1]); } else { $cont = 0; $saldo = $resposta1[1]; $max = intval($resposta1[2]); ?> <h2>SALDO TOTAL: <?php echo $saldo;?></h2><br> <h2>DISPONÍVEL PARA BAIXAR: <?php echo $max;?></h2> <?php $resposta = ""; while ($cont < $max) { $prox = trim($resposta1[$cont+3]); $url2 = "https://dados.servidortrader.com/buscahtml.php"; $response2 = wp_remote_post( $url2 , array( 'timeout' => 15, 'method' => 'POST', 'body' => array ( 'token' => $token, 'id' => $prox, 'link' =>$link ) ) ); $resphtml2 = wp_remote_retrieve_body($response2); $url3 = "https://dados.servidortrader.com/buscacontent.php"; $response3 = wp_remote_post( $url3 , array( 'timeout' => 15, 'method' => 'POST', 'body' => array ( 'token' => $token, 'id' => $prox, 'link' => $link ) ) ); $resphtml3 = wp_remote_retrieve_body($response3); $url4 = "https://dados.servidortrader.com/buscameta.php"; $response4 = wp_remote_post( $url4 , array( 'timeout' => 15, 'method' => 'POST', 'body' => array ( 'token' => $token, 'id' => $prox, 'link' => $link ) ) ); $resphtml4 = wp_remote_retrieve_body($response4); $resphtml4 = explode('<=>',$resphtml4); $respok = $resphtml4[0]; $title = $resphtml4[1]; $idrecebido = $resphtml4[2]; if ($respok == 'S') { //$metadado = $resphtml4[3]; $status = 'draft'; if ($publicado == 'S') { $status = 'publish'; } // trocar as imagens $listaimg = ProcurarImagensNoHTML($resphtml2); $arrayteste = ''; foreach($listaimg as $imagens) { $novaimagem2 = uploadRemoteImageAndAttach($imagens,$arrayteste); if ($novaimagem2[0] <> false) { if ($novaimagem2[1] <> '') { if ($arrayteste == '') { $arrayteste = $novaimagem2[1]; } else { $arrayteste = $arrayteste.'||'.$novaimagem2[1]; } } $novaimagem = $novaimagem2[0]; // echo '<br>-----------------<br>'; $resphtml2 = str_replace($imagens, $novaimagem, $resphtml2); } } $resphtml3 = procuraImagemNoJson($resphtml3); $post_id = wp_insert_post(array( 'post_title' => $title, 'post_content' => $resphtml2, 'post_content_filtered' => $resphtml3, 'post_status' => $status, 'post_type' => 'web-story' )); //adiciona a metatag add_post_meta($post_id,'web_stories_copiado','S'); add_post_meta($post_id,'web_stories_idcopiado',$idrecebido); //idrecebido server para avaliar o post original se bom ou não. //add_post_meta($post_id,'web_stories_poster',$metadado); global $wpdb; $results = $wpdb->get_results( "SELECT post_id,meta_id,meta_value FROM {$wpdb->prefix}postmeta WHERE meta_key = 'web_stories_publisher_logo' order by post_id asc", OBJECT ); $metaid = 0; foreach($results as $row) { if ($metaid == 0) { $metaid = $row->meta_value; } } add_post_meta($post_id,'web_stories_publisher_logo',$metaid); $permalink = get_permalink($post_id); $dom = new DOMDocument(); $dom->loadHTML($resphtml2); $tagsimg = $dom->getElementsByTagName('link'); $srtlink = ''; foreach ($tagsimg as $key=>$value) { $linkref = $value->getAttribute('href'); if (mb_strpos($linkref, 'post_type=web-story') !== false) { // echo 'aqui'.$link.'<br>'.$permalink; $srtlink = $linkref; } } if ($srtlink <> '') { $post_content = get_post_field('post_content', $post_id); $partes = explode('?',$srtlink); $removepadrao = '<link rel="canonical" href="'.$partes[0]; $novaparte = explode('web-stories',$permalink); $canonical = '<link rel="canonical" href="'.$novaparte[0]; $post_content = str_replace($removepadrao,$canonical , $post_content); $partes = explode('p=',$srtlink); $removepadrao = 'p='.$partes[1]; $canonical = 'p='.$post_id; $post_content = str_replace($removepadrao,$canonical , $post_content); $post_content = str_replace($removepadrao,$canonical , $post_content); wp_update_post(array( 'ID' => $post_id, 'post_content' => $post_content )); } $resposta =$resposta.'<a href ="'.$permalink.'"> '.$title.'</a><br>'; } else { $resposta = $resposta.$title.'<br>'; } $cont = $cont + 1; } ?> <div style="background-color:#1C1C1C; text-align: center; padding: 22px; position: fixed; top: 22%; left: 22%; bottom: 10%; right: 22%; margin: auto; border-radius: 10px;"><h1>LINKS DOS STORIES BAIXADOS:</h1><br> <h2><?php echo $resposta; ?></h2> <?php } $msg = '<br> <a href="'. admin_url('edit.php?post_type=web-story').'" target="_blank" style="background-color: #0d1239; border: none; color: white; padding: 12px 24px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; border-radius: 20px; width: 150px;"> TODOS WEB STORIES</a>'; show_message($msg); return [$resposta1[0], $resposta1[1]]; } } add_action( 'admin_post_wpse_79898', 'wpse_79898_test' ); function wpse_79898_test() { ?><body style="background:#1C1C1C> <?php wssource_download_page(); ?> </body> <?php }

Deixe um comentário