Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: link_Ex
- Plugin URI: https://www.freelancer.com/u/al6ayib.html
- Description:Use [LE_link_Ex_Table] for showing the table, and [LE_link_Ex] for adding websites.
- lklkl
- Version: 1.0
- Author: Aaltayib Abdalla
- Author URI: https://www.freelancer.com/u/al6ayib.html
- */
- function link_EX_function() {
- install();
- if (isset($_POST['submit'])) {
- registration_validation(
- $_POST['sitename'],
- $_POST['website'],
- $_POST['niche'],
- $_POST['keywords']
- );
- // sanitize user form input
- global $sitename, $website, $niche, $keywords;
- //$id = sanitize_user($_POST['id']);
- //$user_id = esc_attr($_POST['user_id']);
- $sitename = sanitize_text_field($_POST['sitename']);
- $website = esc_url($_POST['website']);
- $niche = sanitize_text_field($_POST['niche']);
- $keywords = esc_textarea($_POST['keywords']);
- // call @function complete_registration to create the user
- // only when no WP_error is found
- complete_registration(
- $sitename,
- $user_id,
- $website,
- $niche,
- $keywords
- );
- }
- registration_form(
- $sitename,
- $website,
- $niche,
- $keywords
- );
- }
- function registration_form($sitename, $website, $niche, $keywords) {
- $niches = [
- 'Adulto',
- 'Afiliado/mini-site',
- 'Automotivo',
- 'Blog',
- 'Música',
- 'Notícias',
- 'Negócios',
- 'Tecnologia',
- 'Relacionamento',
- 'Receitas/Comida',
- 'Games',
- 'Cassino',
- 'Saúde/Emagrecimento',
- 'Pets/Animais',
- 'SEO',
- 'E-commerce',
- 'Esportes',
- 'Viagens',
- 'Outros'
- ];
- echo '<form action="' . $_SERVER['REQUEST_URI'] . '" method="post"><div class="cadastro">
- <label for="sitename">Nome do Site </label>
- <input type="text" name="sitename" value="' . (isset($_POST['sitename']) ? $sitename : null) . '">
- </div><div class="cadastro"><label for="website">URL (com http:// ou https://)</label>
- <input type="text" name="website" value="' . (isset($_POST['website']) ? $website : null) . '">
- </div>
- <div class="cadastro">
- <label for="niche">Nicho</label>
- <select name="niche">';
- echo '<option value="">Selecione</option>';
- foreach($niches as $n){
- echo '<option ';///////
- if(isset($_POST['niche'])){
- if($niche == $n) echo ' selected ';
- }
- //////
- echo ' value="'.$n.'">'.$n.'</option>';
- }
- echo '
- </select>
- </div>
- <div class="cadastro"><label for="keywords">Keywords ou Nichos</label>
- <input type="text" name="keywords" value="' . (isset($_POST['keywords']) ? $keywords : null) . '">
- </div>
- <div class="cadastro"><input type="submit" class="cadastro-enviar" name="submit" value="Adicionar website"/>
- </form></div>
- ';
- }
- function registration_validation($sitename, $website, $niche, $keywords) {
- global $reg_errors, $user_id;
- $reg_errors = new WP_Error;
- if(is_user_logged_in()) {
- $current_user = wp_get_current_user();
- $user_id = $current_user->ID;
- //print_r($current_user);
- //printf( 'Personal Message For %s!', esc_html( $current_user->user_pass ) );
- } else{
- $reg_errors->add('field', 'Você não fez login. <a href="' . get_site_url() . '/wp-login.php"><span style="text-decoration:underline; color:#2991d6;">Ir para a página de login</span></a>.');
- }
- if ( empty($website) || empty($sitename) || empty($keywords)) {
- $reg_errors->add('field', 'Preencha todos os campos requeridos.');
- }
- if($niche == null){
- $reg_errors->add('field', 'Selecione o nicho.');
- }
- if ( email_exists( $email ) ) {
- //$reg_errors->add('email', 'E-mail já em uso.');
- }
- if ( !empty( $website ) ) {
- if ( !filter_var($website, FILTER_VALIDATE_URL) ) {
- $reg_errors->add('website', 'URL inválida (não se esqueça de incluir o http ou https');
- } else {
- global $wpdb;
- $table_name = $wpdb->prefix.'link_ex';
- if($wpdb->get_results( "SELECT * FROM $table_name WHERE website LIKE '$website'" )){
- $reg_errors->add('website', 'URL já existe!');
- }
- }
- }
- if ( is_wp_error( $reg_errors ) ) {
- foreach ( $reg_errors->get_error_messages() as $error ) {
- echo '<div>';
- echo '<h4><strong style="color:red">ERRO: </strong>';
- echo $error . '</h4><br/>';
- echo '</div>';
- }
- }
- }
- function complete_registration() {
- global $reg_errors, $user_id, $sitename, $email, $website, $niche, $keywords, $wpdb;
- if ( count($reg_errors->get_error_messages()) < 1 ) {
- $data = array(
- 'name' => $sitename,
- 'user_id' => $user_id,
- 'website' => $website,
- 'niche' => $niche,
- 'keywords' => $keywords
- );
- global $wpdb;
- $table_name = $wpdb->prefix.'link_ex';
- $wpdb->insert($table_name, $data);
- $user = wp_insert_user( $userdata );
- $_POST = null;
- echo 'Adicionado com sucesso!';
- }
- }
- ///////////////////////////////////////////////////
- function html(){
- install();
- delete();
- if(isset($_POST['sender_name'])){
- email();
- }
- global $wpdb;
- $table_name = $wpdb->prefix.'link_ex';
- $data = $wpdb->get_results( "SELECT * FROM $table_name" );
- $linDir = plugin_dir_path( __FILE__ );
- wp_enqueue_style( 'dataTables.material', get_site_url().'/wp-content/plugins/link_Ex/css/dataTables.material.css',false,'1.1','all');
- wp_enqueue_style( 'shCore', get_site_url().'/wp-content/plugins/link_Ex/css/shCore.css',false,'1.1','all');
- wp_enqueue_style( 'demo', get_site_url().'/wp-content/plugins/link_Ex/css/demo.css',false,'1.1','all');
- wp_enqueue_style( 'jquery-ui', get_site_url().'/wp-content/plugins/link_Ex/css/jquery-ui.css',false,'1.1','all');
- // wp_enqueue_script( 'jquery.dataTables', get_site_url().'/wp-content/plugins/link_Ex/js/jquery.dataTables.js', array ( 'jquery' ), 1.1, false);
- wp_enqueue_script( 'jquery.dataTables', get_site_url().'/wp-content/plugins/link_Ex/js/jquery.dataTables.js');
- wp_enqueue_script( 'dataTables.material', get_site_url().'/wp-content/plugins/link_Ex/js/dataTables.material.js', array ( 'jquery' ), 1.1, false);
- wp_enqueue_script( 'demo', get_site_url().'/wp-content/plugins/link_Ex/js/demo.js', array ( 'jquery' ), 1.1, false);
- wp_enqueue_script( 'shCore', get_site_url().'/wp-content/plugins/link_Ex/js/shCore.js', array ( 'jquery' ), 1.1, false);
- wp_enqueue_script( 'jquery-ui', get_site_url().'/wp-content/plugins/link_Ex/js/jquery-ui.js', array ( 'jquery' ), 1.1, false);
- if (condition): ?>
- <script src="external/jquery/jquery.js"></script>
- <script src="jquery-ui.js"></script>
- <link href="jquery-ui.css" rel="stylesheet">
- <meta charset="utf-8">
- <meta name="viewport" content="initial-scale=1.0, maximum-scale=2.0">
- <!--<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/material-design-lite/1.1.0/material.min.css">-->
- <script type="text/javascript" language="javascript" src="//code.jquery.com/jquery-1.12.4.js">
- </script>
- <script type="text/javascript" language="javascript" class="init">
- $(document).ready(function() {
- var n='';
- var user_id = '';
- $( "#dialog" ).dialog({
- autoOpen: false,
- width: 400,
- buttons: [
- /* {
- text: "Ok",
- click: function() {
- var pa = $('.pa'+n).text();
- var da = $('.da'+n).text();
- var sitename = $('.sitename'+n).text();
- var url = $('.url'+n).text();
- var niche = $('.niche'+n).text();
- var sender_email = $('.sender_email').val();
- var sender_name = $('.sender_name').val();
- var sender_domain = $('.sender_domain').val();
- //$( this ).dialog( "close" );
- data = {
- 'sender_email':sender_email,
- 'sender_name':sender_name,
- 'sender_domain':sender_domain,
- 'receiver_id':user_id
- }
- $.post(
- 'wp-content/plugins/link_Ex/link_Ex.php',
- {
- 'action': 'add_foo',
- 'data': data
- },
- function(response){
- alert('The server responded: ' + response);
- }
- );
- //$( this ).dialog( "close" );
- //alert(user_id);
- }
- },*/
- {
- text: "Cancel",
- click: function() {
- $( this ).dialog( "close" );
- }
- }
- ]
- });
- // Link to open the dialog
- $( ".dialog-link" ).click(function( event ) {
- n = $(this).attr('n');
- var receiver_domain = $(this).attr("receiver-domain");
- $('.receiver-domain').val(receiver_domain);
- user_id = $(this).attr('user_id');
- $('.user_id_id').val(user_id);
- $('.comprar_id').val(user_id);
- $( "#dialog" ).dialog( "open" );
- event.preventDefault();
- });
- $('#example').DataTable( {
- columnDefs: [
- {
- targets: [ 0, 1, 2 ],
- className: 'mdl-data-table__cell--non-numeric'
- }
- ]
- } );
- $('.ex_show').click(function(){
- $('.exchange').toggle();
- })
- } );
- </script>
- <div class="dt-example dt-example-material" id='link_Ex'>
- <div class="container" style="">
- <section>
- <div data-role="main" class="ui-content">
- <table id="example" class="mdl-data-table" cellspacing="0" width="100%">
- <thead>
- <tr>
- <th>Nome do Site</th>
- <th>URL do Site</th>
- <th>PA</th>
- <th>DA</th>
- <th>Nicho</th>
- <th>Keyword ou Subnicho</th>
- <th>Trocar Link</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $i = 0;
- foreach($data as $site){
- $sites[] = $site->website;
- $i++;
- }
- $x = 1;
- $arr = [];
- for($c = 0;$c<=count($sites)-1;$c++){
- $new10 [] = $sites[$c];
- if($x==10 || $c==count($sites)-1){
- //print_r($new10);
- $new10 =api($new10);
- foreach($new10 as $new1){
- $arr[] = $new1;
- }
- $new10 = [];
- $x = 1;
- }
- $x++;
- }
- //echo '<pre>';
- //print_r($arr);
- //echo '</pre>';
- $j = 0;
- foreach($data as $tr){
- $pa = round($arr[$j]->upa,1);
- $da = round($arr[$j]->pda,1);
- //print_r($sites);
- $i = $tr->id;
- $user_id = $tr->user_id;
- $url = $tr->website;
- $user_info = get_userdata($user_id);
- $key = $tr->keywords;
- echo '<tr>';
- echo '<td class="td sitename'.$i.'">'.$tr->name.'</td>';
- echo '<td class="td url'.$i.'">'.$url.'</td>';
- //////////////
- echo '<td class="td pa'.$i.'">'.$pa.'</td>';
- echo '<td class="td da'.$i.'">'.$da.'</td>';
- ///////////////
- echo '<td class="td niche'.$i.'">'.$tr->niche.'</td>';
- echo '<td class="td keywords'.$i.'">'.$key.'</td>';
- /////////////
- echo '<td class="ex td" n="'.$i.'" >';
- $current_user = wp_get_current_user();
- $current_user_id = $current_user->ID;
- if(is_user_logged_in() && ($current_user_id==$user_id)) {
- echo '<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
- <input type="hidden" name="delete_id" value="'.$tr->id.'" />
- <button type="submit" style="background-color:red">Delete</button>
- </form>';
- }
- else
- {
- echo '
- <button receiver-domain="'.$tr->website.'" user_id="'.$user_id.'" class="dialog-link" id="dialog-link" n="'.$i.'" class="ui-button ui-corner-all ui- widget">
- <span class="ui-icon ui-icon-newwin"></span>Negociar</button>';
- }
- echo '</td></tr>';
- $j++;
- }
- ?>
- </tbody>
- </table>
- <div id="dialog" title="Por favor, entre com os detalhes de seu site!" n="15">
- <button class="ex_show">Trocar link</button>
- <div class="exchange" style="display:none">
- <form id="dialog-form" action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="post" style="border: 1px solid;padding: 10px;margin-bottom: 5px;padding-top: 60px;margin-top: -51px;">
- <label>Nome</label><input name='sender_name' class="sender_name" type="text"><br>
- <!--<label>E-mail</label><input name='sender_email' class="sender_email" type="text"><br>-->
- <label>Domínio para troca:</label><input name='sender_domain' class="sender_domain" type="text"><br>
- <input name="user_id" type="hidden" class='user_id_id'>
- <input name="receiver-domain" type="hidden" class="receiver-domain" />
- <input class="exchange" type="submit" name="exchange" value="Enviar" style="display:none"/>
- </form>
- </div>
- <form action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="post">
- <input name='sender_name' class="sender_name" type="hidden"><br>
- <!--<label>E-mail</label><input name='sender_email' class="sender_email" type="text"><br>-->
- <input name='sender_domain' class="sender_domain" type="hidden">
- <input name="user_id" type="hidden" class='user_id_id'>
- <input name='comprar_id' class="comprar_id" type="hidden">
- <input class="comprar" type="hidden" name="comprar" />
- <input name="receiver-domain" type="hidden" class="receiver-domain" />
- <input type="submit" name="buy" class="buy" value="Comprar" />
- </form>
- </div>
- </section>
- </div>
- </div>
- <?php else: ?>
- <?php endif ?>
- <?php
- }
- function api($site){
- $accessID = "mozscape-c0c36ab22e";
- $secretKey = "74bd7cfb5d4dbf3f61a8050712c3d5d3";
- // Set your expires times for several minutes into the future.
- // An expires time excessively far in the future will not be honored by the Mozscape API.
- $expires = time() + 300;
- // Put each parameter on a new line.
- $stringToSign = $accessID."\n".$expires;
- // Get the "raw" or binary output of the hmac hash.
- $binarySignature = hash_hmac('sha1', $stringToSign, $secretKey, true);
- // Base64-encode it and then url-encode that.
- $urlSafeSignature = urlencode(base64_encode($binarySignature));
- // Add up all the bit flags you want returned.
- // Learn more here: https://moz.com/help/guides/moz-api/mozscape/api-reference/url-metrics
- $cols = "103079215108";
- // Put it all together and you get your request URL.
- $requestUrl = "http://lsapi.seomoz.com/linkscape/url-metrics/?Cols=".$cols."&AccessID=".$accessID."&Expires=".$expires."&Signature=".$urlSafeSignature;
- // Put your URLS into an array and json_encode them.
- $batchedDomains = $site;
- $encodedDomains = json_encode($batchedDomains);
- // Use Curl to send off your request.
- // Send your encoded list of domains through Curl's POSTFIELDS.
- $options = array(
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_POSTFIELDS => $encodedDomains
- );
- $ch = curl_init($requestUrl);
- curl_setopt_array($ch, $options);
- $content = curl_exec($ch);
- curl_close( $ch );
- $contents = json_decode($content);
- $content = json_encode($content);
- //print_r($contents);
- //$contents = json_encode($contents);
- return $contents;
- }
- function email() {
- global $website;
- if(isset($_POST['exchange'])){
- if(!empty($_POST['sender_name']) && !empty($_POST['sender_domain'])){
- $sender_name = sanitize_text_field($_POST['sender_name']);
- //$sender_email = sanitize_text_field($_POST['sender_email']);
- $sender_domain = esc_url($_POST['sender_domain']);
- $receiver_domain = sanitize_text_field($_POST['receiver-domain']);
- $user_id = $_POST['user_id'] ;
- if ( !filter_var($sender_domain, FILTER_VALIDATE_URL) ) {
- echo '<h3>Seu domínio não é válido.</h3>';
- //$reg_errors->add('website', 'Website is not a valid URL');
- } else{
- if(is_user_logged_in()) {
- $current_user = wp_get_current_user();
- $sender_email = $current_user->user_email;
- $receiver_info = get_userdata($user_id);
- $email = $receiver_info->user_email;
- $api = api([$sender_domain]);
- $to = $email;
- //change $subject to match yours.
- $subject = 'Você recebeu um pedido de troca de links';
- $headers = "From: " . strip_tags('seo@ferramentasseo.club') . "\r\n";
- $headers .= "Reply-To: ". strip_tags($sender_email) . "\r\n";
- $headers .= "MIME-Version: 1.0\r\n";
- $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
- $message ='Você recebeu um pedido de troca de links. Abaixo as informações para contato: <br><br>
- <b>Nome</b> : '.$sender_name.'<br>
- <b>E-mail</b> : '.$sender_email.'<br>
- <b>Domínio para troca</b> : <a href="'.$sender_domain.'">'.$sender_domain.'</a><br>
- <b>DA</b> : '.round($api[0]->pda,1).'<br>
- <b>PA</b> : '.round($api[0]->upa,1).'<br>
- <b>Seu domínio</b> : '.$receiver_domain.'<br><br>
- Entre em contato para negociar a troca.';
- //echo $message;
- wp_mail($to, $subject, $message, $headers);
- echo '<h3>Uma mensagem de troca de link foi enviada com sucesso ao dono do domínio!</h3>';
- } else{
- echo '<h3><span style="color:red">Você não fez login. </span> <a href="' . get_site_url() . '/wp-login.php"><span style="text-decoration:underline; color:#2991d6;">Ir para a página de login</span></a>.</h3>';
- }
- }
- }
- else{
- echo '<h3>Por favor preencha todos os campos.</h3>';
- }
- }
- if(isset($_POST['buy'])){
- if(!empty($_POST['user_id'])){
- $receiver_domain = sanitize_text_field($_POST['receiver-domain']);
- $sender_name = sanitize_text_field($_POST['sender_name']);
- //$sender_email = sanitize_text_field($_POST['sender_email']);
- $sender_domain = esc_url($_POST['sender_domain']);
- $user_id = intval($_POST['user_id']) ;
- if(is_user_logged_in()) {
- $current_user = wp_get_current_user();
- $sender_email = $current_user->user_email;
- $receiver_info = get_userdata($user_id);
- $email = $receiver_info->user_email;
- $api = api([$sender_domain]);
- $sender_name = $current_user->display_name;
- $to = $email;
- $subject = 'Você recebeu um pedido de compra de links';
- $headers = "From: " . strip_tags('seo@ferramentasseo.club') . "\r\n";
- $headers .= "Reply-To: ". strip_tags($sender_email) . "\r\n";
- $headers .= "MIME-Version: 1.0\r\n";
- $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
- $message = 'Você recebeu um pedido de compra de links. Abaixo as informações para contato:<br><br>
- <b>Nome</b>: '.$sender_name.'<br>
- <b>E-mail</b>: '.$sender_email.'<br>
- <b>Seu domínio</b>: '.$receiver_domain.'<br><br>
- Entre em contato para negociar a venda do site.';
- //echo '<br>COMPRAR-'.$message.'<br>'.$email;
- //echo $message;
- wp_mail($to, $subject, $message, $headers);
- echo '<h3>Uma mensagem de compra de link foi enviada com sucesso ao dono do domínio!</h3>';
- } else{
- echo '<h3><span style="color:red">Você não fez login. </span> <a class="linklogin" href="' . get_site_url() . '/wp-login.php"> <span style="text-decoration:underline; color:#2991d6;">Ir para a página de login</span></a>.</h3>';
- }
- }
- }
- // Don't forget to stop execution afterward.
- }
- function delete(){
- if(isset($_POST['delete_id'])){
- $delete_id = intval($_POST['delete_id']);
- echo $delete_id;
- global $wpdb;
- $table_name = $wpdb->prefix.'link_ex';
- $delete_item = $wpdb->get_results( "SELECT * FROM $table_name WHERE id = $delete_id" );
- if($delete_item){
- echo '<h3 style="color:red">Tem certeza que deseja deletar este domínio?</h3>
- <p> <b>Name</b> : '.$delete_item[0]->name.'</p>
- <p> <a style="text-decoration:none" href="'.$delete_item[0]->website.'">'.$delete_item[0]->website.'</a></p>
- <form action="'.$_SERVER['REQUEST_URI'].'" method="post">
- <input type="hidden" name="confirm_delete_id" value="'.$delete_item[0]->id.'" />
- <button type="submit" style="background-color:red">Deletar</button>
- </form>
- ';
- }else{
- echo '<h3 style="color:orange">Erro: Item Inválido!</h3>';
- }
- }
- confirm_delete();
- }
- function confirm_delete(){
- if(isset($_POST['confirm_delete_id'])){
- $confirm_delete_id = intval($_POST['confirm_delete_id']);
- global $wpdb;
- $table_name = $wpdb->prefix.'link_ex';
- $confirm_delete_id = $wpdb->delete($table_name, array('id' => $confirm_delete_id ));
- if($confirm_delete_id){
- echo '<h2 style="color:green">Domínio deletado com sucesso!</h2>';
- }else{
- echo '<h3 style="color:red">Error: Inválido domínio a ser deletado!</h3>';
- }
- }
- }
- ///////////////////////////////////////////////////
- function install(){
- global $wpdb;
- $table_name = $wpdb->prefix.'link_ex';
- if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
- //table not in database. Create new table
- $charset_collate = $wpdb->get_charset_collate();
- $sql = "CREATE TABLE $table_name (
- id int(5) NOT NULL AUTO_INCREMENT,
- user_id int(5) NOT NULL,
- name varchar(40) NOT NULL,
- website varchar(50) NOT NULL,
- niche varchar(40) NOT NULL,
- keywords text NOT NULL,
- PRIMARY KEY (id)
- ) $charset_collate;";
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
- dbDelta( $sql );
- print_r(dbDelta( $sql ));
- }
- else{
- }
- }
- /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
- /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
- /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
- //////////////////////////////////////////////////
- // Register a new shortcode: [cr_link_EX]
- add_shortcode('LE_link_Ex', 'link_EX_shortcode');
- // The callback function that will replace [book]
- function link_EX_shortcode() {
- ob_start();
- link_EX_function();
- return ob_get_clean();
- }
- ////////////////////////////////////////////////
- //////////////////////////////////////////////////
- // Register a new shortcode: [cr_link_EX]
- add_shortcode('LE_link_Ex_Table', 'link_EX_Table_shortcode');
- // The callback function that will replace [book]
- function link_EX_Table_shortcode() {
- html();
- }
Add Comment
Please, Sign In to add comment