. */ //authority_linker register_activation_hook( __FILE__,'wp_authority_linker_register' ); add_action('admin_menu','wp_authority_linker_menu'); add_filter('the_content','wp_authority_linker_inject_links'); add_action('add_meta_boxes','wp_authority_linker_register_meta_box'); add_action('save_post','wp_authority_linker_meta_data',10,2); function wp_authority_linker_register_meta_box() { add_meta_box('wp_authority_linker_tick_meta_box','Authority Linker Options','wp_authority_linker_tick_meta_box','post','side'); add_meta_box('wp_authority_linker_tick_meta_box','Authority Linker Options','wp_authority_linker_tick_meta_box','page','side'); } function wp_authority_linker_tick_meta_box($post) { // Retrieve is allow to add link status $post_authority_linker_status = esc_html(get_post_meta($post->ID,'post_authority_linker_status',true)); ?>
| Allow to add Links | /> |
';
print_r($_POST);
echo '';*/
// Save the settings //
if(isset($_POST['Save']))
{
$err_flg = 0;
// Get settings and do some validation
$table_name = "wp_authority_linker";
if(trim($type) == 'add')
{
if($post['linkinfo']['al_link_url'] == '')
{
queue_message( __('Please enter Link', 'wp_authority_linker' ), 'error' );
$err_flg = 1;
}
if($post['linkinfo']['al_keywords'] == '')
{
queue_message( __('Please enter Keywords', 'wp_authority_linker' ), 'error' );
$err_flg = 1;
}
## URL check
if($post['linkinfo']['al_link_url'] != '')
{
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $post['linkinfo']['al_link_url'])) {
queue_message( __( 'Invalid URL', 'wp_authority_linker' ), 'error' );
$err_flg = 1;
}
}
##
## Check keyword is exists or not
/*if($post['linkinfo']['al_keywords'] != '')
{
$keywords_exists = '';
$arr_keywords = explode(",",$post['linkinfo']['al_keywords']);
//echo '';
//print_r($arr_keywords);
//echo ''; die;
foreach ($arr_keywords as $key => $value)
{
$sql = "SELECT * FROM wp_authority_linker WHERE keywords LIKE '%".$value."%'";
$results = $wpdb->get_results($sql);
if($results)
{
$keywords_exists .= $value.'';
//print_r($arr_keywords);
//echo ''; die;
foreach ($arr_keywords as $key => $value)
{
$sql = "SELECT * FROM wp_authority_linker WHERE link_id != ".$_POST['link_id']." AND keywords LIKE '%".$value."%'";
$results = $wpdb->get_results($sql);
if($results)
{
$keywords_exists .= $value.''; print_r($patterns_scram); print_r($replacements_scram); echo ''; */ $content = str_replace($patterns_scram, $replacements_scram, $content); }//if scrambled replacement is poresent then bring to origianl format }//if link addition applicable for post/page return $content; } function do_getLink_info( $id ) { global $wpdb; $table_name = "wp_authority_linker"; $sql = "SELECT * FROM $table_name WHERE `link_id`='".$id."'"; return $results = $wpdb->get_row($sql); } function do_dumpLink_actions() { /*echo '
'; print_r($_FILES); echo '';*/ global $wpdb; if ($_FILES[bulk_links_file][size] > 0) { //get the csv file $file = $_FILES[bulk_links_file][tmp_name]; $handle = fopen($file,"r"); $table_name = "wp_authority_linker"; //loop through the csv file and insert into database $import_count = 0; $total_count = 0; do { if ($data[0]) { $err_flg = 0; $post['linkinfo']['al_link_url'] = $data[0]; $post['linkinfo']['al_keywords'] = $data[1]; // Get settings and do some validation if($post['linkinfo']['al_link_url'] == '') { //queue_message( __('Please enter Link', 'wp_authority_linker' ), 'error' ); $err_flg = 1; } if($post['linkinfo']['al_keywords'] == '') { //queue_message( __('Please enter Keywords', 'wp_authority_linker' ), 'error' ); $err_flg = 1; } ## URL check if($post['linkinfo']['al_link_url'] != '') { if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $post['linkinfo']['al_link_url'])) { //queue_message( __( 'Invalid URL', 'wp_authority_linker' ), 'error' ); $err_flg = 1; } } ## if($err_flg == 0) { //die; // Update database option and get response $wpdb->insert($table_name, array( 'link'=>$post['linkinfo']['al_link_url'], 'keywords'=>$post['linkinfo']['al_keywords'] )); $getLinkID = $wpdb->insert_id; if($getLinkID > 0) { $import_count++; } else { queue_message( __( 'Error!Please Try Again', 'wp_authority_linker' ), 'error' ); } } $total_count++; } } while ($data = fgetcsv($handle,1000,",",'"')); if($total_count > 0) { return queue_message( __( "$import_count out of $total_count links has been added successfully. ", 'wp_authority_linker' ), 'updated' ); } } } function do_updMaxLink_actions() { if($_POST['wp_authority_linker_max_links'] != '') { if(preg_match('/^\d+$/',$_POST['wp_authority_linker_max_links'])) { $wp_authority_linker_max_links = sanitize_text_field($_POST[wp_authority_linker_max_links]); update_option('wp_authority_linker_max_links', $wp_authority_linker_max_links); return queue_message( __( "Max link count has been updated successfully. ", 'wp_authority_linker' ), 'updated' ); } else { return queue_message( __( "Max link count must be positive integer ", 'wp_authority_linker' ), 'error' ); } } else { return queue_message( __( "Max link count can not be empty. ", 'wp_authority_linker' ), 'error' ); } } function wp_authority_linker_config_page() { //links_tab ?>
"; print_r($_REQUEST); echo "";die;
$table_name = $wpdb->prefix . "authority_linker";
if(isset($_REQUEST['action'])) {
if($_REQUEST['action'] != '')
{
if(trim($_REQUEST['action']) == 'delete')
{
if(!is_array($_REQUEST['link_id'])) {
if(intval(trim($_REQUEST['link_id'])) > 0)
{
//die("is first");
$delsql = "DELETE FROM $table_name WHERE $table_name.`link_id` = '".intval(trim($_REQUEST['link_id']))."'";
$wpdb->query($delsql);
}
}
else {
if(count($_REQUEST['link_id']) > 0)
{
//die("is 2ND");
$delsql = "DELETE FROM $table_name WHERE $table_name.`link_id` IN (".implode(',',$_REQUEST['link_id']).")";
$wpdb->query($delsql);
}
}
// Show update message
queue_message( __( 'Link has been deleted successfully.', 'wp_authority_linker' ), 'updated' );
}
}
}
$sql = "SELECT * FROM $table_name ";
if(isset($_REQUEST['s'])) {
if(trim($_REQUEST['s']) != '') {
$sql .= "WHERE `link` LIKE '%".trim($_REQUEST['s'])."%' OR `keywords` LIKE '%".trim($_REQUEST['s'])."%' ";
}
}
$sql .= "ORDER BY `link_id` DESC";
$results = $wpdb->get_results($sql);
$recordsArr = array();
if($wpdb->num_rows)
{
foreach ($results as $result)
{
$recordsArr[] = array('link_id' => $result->link_id,'link' => $result->link, 'keywords' => $result->keywords);
}
}
$filename = dirname( __FILE__ ) . '/link_list_table.php';
require_once( $filename );
global $linkListTable;
$option = 'per_page';
$args = array(
'label' => 'Links',
'default' => 10,
'option' => 'links_per_page'
);
add_screen_option( $option, $args );
$linkListTable = new Link_List_Table();
$linkListTable->link_data = $recordsArr;
$linkListTable->prepare_items();
$linkListTable->search_box( 'search', 'search_id' );
$linkListTable->display();
}
/**
* Script to produce the CSV
*
*/
function generate_csv( $page,$post )
{
$sitename = sanitize_key( get_bloginfo( 'name' ) );
if ( ! empty( $sitename ) )
$sitename .= '.';
$filename = $sitename . 'links.' . date( 'Y-m-d-H-i-s' ) . '.csv';
ob_end_clean();
header( 'Content-Description: File Transfer' );
header( 'Content-Disposition: attachment; filename=' . $filename );
header( 'Content-Type: text/csv; charset=' . get_option( 'blog_charset' ), true );
$exclude_data = apply_filters( 'pp_eu_exclude_data', array() );
global $wpdb;
$fields = array('ID', 'Links', 'keywords');
$dbfields = array('link_id', 'link', 'keywords');
$headers = array();
foreach ( $fields as $key => $field ) {
if ( in_array( $field, $exclude_data ) )
unset( $fields[$key] );
else
$headers[] = '"' . $field . '"';
}
echo implode( ',', $headers ) . "\n";
$table_name = $wpdb->prefix . "authority_linker";
$sql = "SELECT * FROM $table_name ";
if(is_array($_REQUEST['link_id'])) {
if(count($_REQUEST['link_id']) > 0) {
$sql .= "WHERE $table_name.`link_id` IN (".implode(',',$_REQUEST['link_id']).") ";
//$sql .= "WHERE $table_name.`link_id` IN (3,9) ";
}
}
$sql .= "ORDER BY `link_id` ASC";
$results = $wpdb->get_results($sql);
//echo ""; print_r($results); echo ""; die;
if($wpdb->num_rows)
{
foreach ($results as $result)
{
$data = array();
foreach ( $dbfields as $field ) {
$value = isset( $result->{$field} ) ? $result->{$field} : '';
$value = is_array( $value ) ? serialize( $value ) : $value;
$data[] = '"' . str_replace( '"', '""', $value ) . '"';
}
echo implode( ',', $data ) . "\n";
}
}
exit;
}
function queue_message( $text, $type )
{
$message = "";
//return $message;
add_action( 'wp_authority_linker_admin_messages', create_function( '', 'echo "'. $message .'";' ) );
}
class wp_authority_linker_callback
{
private $replacement;
private $srch_cnt;
private $match_cnt;
private $rand_val;
function __construct($replacement,$srch_cnt)
{
$this->replacement = $replacement;
$this->srch_cnt = $srch_cnt;
$this->match_cnt = 0;
if($this->srch_cnt > 1)
{
$this->rand_val = rand(1, $this->srch_cnt);
}
else
{
$this->rand_val = 1;
}
}
public function callback($matches)
{
$this->match_cnt++;
if($this->match_cnt == $this->rand_val)
{
return $this->replacement;
}
else
{
return $matches[0];
}
}
}
?>