-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkbase.php
269 lines (269 loc) · 10.2 KB
/
linkbase.php
1
<?php ob_start();/*Plugin Name: Link Base TablePlugin URI: http://www.wplinkbase.comDescription: Feature packed & User friendly plugin to create an online database of useful links.Author: WPLinkBaseVersion: 1.0.1Author URI:http://www.wplinkbase.com*/$siteurl = get_option('siteurl');define( 'EDD_SL_STORE_URL', 'http://wplinkbase.com/' );define( 'EDD_SL_ITEM_NAME', 'Link Base Table' );define('LINKBASE_FOLDER', dirname(plugin_basename(__FILE__)));define('LINKBASE_URL', $siteurl.'/wp-content/plugins/' . LINKBASE_FOLDER);define('LINKBASE_FILE_PATH', dirname(__FILE__));define('LINKBASE_DIR_NAME', basename(LINKBASE_FILE_PATH));//------ this is the table prefix---------//global $wpdb;$linkbase_table_prefix=$wpdb->prefix.'linkbase_';define('LINKBASE_TABLE_PREFIX', $linkbase_table_prefix);//---do some table installatin--------------//register_activation_hook(__FILE__,'linkbase_install');register_deactivation_hook(__FILE__ , 'linkbase_uninstall' );if( !class_exists( 'EDD_SL_Plugin_Updater' ) ) { // load our custom updater include( dirname( __FILE__ ) . '/EDD_SL_Plugin_Updater.php' );}// retrieve our license key from the DB$license_key = trim( get_option( 'edd_sample_license_key' ) );// setup the updater$edd_updater = new EDD_SL_Plugin_Updater( EDD_SL_STORE_URL, __FILE__, array( 'version' => '1.0.1', // current version number 'license' => $license_key, // license key (used get_option above to retrieve from DB) 'item_name' => EDD_SL_ITEM_NAME, // name of this plugin 'author' => 'Vcpandya' // author of this plugin ));function linkbase_install(){ global $wpdb; $table = LINKBASE_TABLE_PREFIX."table"; $table1 = $wpdb->prefix."licensekey"; $table2 = LINKBASE_TABLE_PREFIX."linkbase"; $table3 = LINKBASE_TABLE_PREFIX."approvelinks"; $table4 = $wpdb->prefix."vote"; $table5 = $wpdb->prefix."ip"; $table6 = $wpdb->prefix."block_user"; $structure11= "CREATE TABLE $table1 ( id INT(9) NOT NULL AUTO_INCREMENT, licensekey VARCHAR(250), UNIQUE KEY id (id));"; $wpdb->query($structure11); $structure = "CREATE TABLE $table ( id INT(9) NOT NULL AUTO_INCREMENT, table_heading VARCHAR(80) NOT NULL, liks_posted INT(9) NOT NULL DEFAULT '0', pending_approval INT(9) NOT NULL DEFAULT '0', created_by VARCHAR(80) NOT NULL, created_date VARCHAR(80) NOT NULL, color VARCHAR(80) NOT NULL, UNIQUE KEY id (id) );"; $wpdb->query($structure); $structure1 = "CREATE TABLE $table2 ( id INT(9) NOT NULL AUTO_INCREMENT, link VARCHAR(80) NOT NULL, description text, likeup INT(9) NOT NULL DEFAULT '0', unlike INT(9) NOT NULL DEFAULT '0', approved INT(9) NOT NULL DEFAULT '0', denied INT(9) NOT NULL DEFAULT '0', table_id INT(9) NOT NULL DEFAULT '0', userid INT(9) NOT NULL DEFAULT '0', UNIQUE KEY id (id) );"; $wpdb->query($structure1); $structure2 = "CREATE TABLE $table3 ( id INT(9) NOT NULL AUTO_INCREMENT, link VARCHAR(250), sltd INT(11) NOT NULL, UNIQUE KEY id (id));"; $wpdb->query($structure2); $structure3 = "insert into $table3(id,link,sltd) values ('1','Moderate all links',0)"; $wpdb->query($structure3); $structure4 = "insert into $table3(id,link,sltd) values ('2','Moderate only unregistered users',0)"; $wpdb->query($structure4); $structure5 = "insert into $table3(id,link,sltd) values ('3','Auto approve all links',1)"; $wpdb->query($structure5); $structure6 = "CREATE TABLE $table4 ( id INT(9) NOT NULL AUTO_INCREMENT, process VARCHAR(250), vote INT(11) NOT NULL, UNIQUE KEY id (id));"; $wpdb->query($structure6); $structure7 = "insert into $table4(id,process,vote) values ('1','Any One Can Vote','1')"; $wpdb->query($structure7); $structure8 = "insert into $table4(id,process,vote) values ('2','Only Unregistered Users Can Vote','0')"; $wpdb->query($structure8); $structure9 = "CREATE TABLE $table5 ( id INT(9) NOT NULL AUTO_INCREMENT, ip VARCHAR(250), UNIQUE KEY id (id));"; $wpdb->query($structure9); $structure10 = "CREATE TABLE $table6 ( id INT(9) NOT NULL AUTO_INCREMENT, user_id VARCHAR(250), ban INT(9) NOT NULL, UNIQUE KEY id (id));"; $wpdb->query($structure10);}function linkbase_uninstall(){ global $wpdb; $table = LINKBASE_TABLE_PREFIX."table"; $table1 = $wpdb->prefix."licensekey"; $table2 = LINKBASE_TABLE_PREFIX."linkbase"; $table3 = LINKBASE_TABLE_PREFIX."approvelinks"; $table4 = $wpdb->prefix."vote"; $table5 = $wpdb->prefix."ip"; $table6 = $wpdb->prefix."block_user"; $structure = "drop table if exists $table"; $wpdb->query($structure); $structure1 = "drop table if exists $table2"; $wpdb->query($structure1); $structure2 = "drop table if exists $table3"; $wpdb->query($structure2); $structure3 = "drop table if exists $table4"; $wpdb->query($structure3); $structure4 = "drop table if exists $table5"; $wpdb->query($structure4); $structure5 = "drop table if exists $table6"; $wpdb->query($structure5); $structure33 = "drop table if exists $table1"; $wpdb->query($structure33); }//-------------create menu for admin-----------------------//function getuser(){ global $current_user; $current_user = wp_get_current_user(); $userid=$current_user->id; return $userid;}//-------------create menu for admin-----------------------//add_action('admin_menu','linkbase_admin_menu');function linkbase_admin_menu() { $userid=getuser(); $meta = get_usermeta($userid, 'wp_capabilities'); add_menu_page( "LinkBase", "LinkBase", 1, __FILE__, "linkbase_admin_list_site" ); add_submenu_page(__FILE__,'Link list','Link list','1','list-site','linkbase_admin_submenu');}//---- function for the site listing----//function linkbase_admin_list_site(){ include 'admin-list-site.php';}function linkbase_admin_submenu(){ include 'admin-list-submenu.php';}//-------------------------------- Function to add Stylesheet -------------------------////-------- Add plugin admin and frontend UI css file ---------//add_action('wp_print_styles', 'add_linkbase_stylesheet');function add_linkbase_stylesheet() { $myStyleUrl = LINKBASE_URL . '/style.css'; $myStyleFile = LINKBASE_FILE_PATH . '/style.css'; if ( file_exists($myStyleFile) ) { wp_register_style('myStyleSheets', $myStyleUrl); wp_enqueue_style( 'myStyleSheets'); } }function my_enqueue($hook) { wp_enqueue_script('jquerylib', 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js'); wp_enqueue_script('jqlib', 'http://cwo.ucsd.edu/_resources/shadowbox/shadowbox-3.0.3/shadowbox.js'); return;}add_action( 'wp_enqueue_scripts', 'my_enqueue' );function my_enqueue_style($hooks) { wp_enqueue_style( 'core', 'http://cwo.ucsd.edu/_resources/shadowbox/shadowbox-3.0.3/shadowbox.css', false ); return;}add_action( 'wp_enqueue_scripts', 'my_enqueue_style' );function my_enque($hook2) { wp_enqueue_script( 'my_jq_script', plugins_url('/lib/jquery-1.9.0.min.js', __FILE__) ); wp_enqueue_script( 'my_custom_script', plugins_url('/source/jquery.fancybox.js?v=2.1.4', __FILE__) ); /* <script type="text/javascript" src="../wp-content/plugins/linkbase/lib/jquery-1.9.0.min.js"></script> <!-- Add fancyBox main JS and CSS files --> <script type="text/javascript" src="../wp-content/plugins/linkbase/source/jquery.fancybox.js?v=2.1.4"></script> <link rel="stylesheet" type="text/css" href="../wp-content/plugins/linkbase/source/jquery.fancybox.css?v=2.1.4" media="screen" />*/ return;}add_action( 'admin_enqueue_scripts', 'my_enque' );function my_enque_style($hookss) { wp_enqueue_style( 'my_css', plugins_url('/source/jquery.fancybox.css?v=2.1.4', __FILE__) ); return;}add_action( 'admin_enqueue_scripts', 'my_enque_style' );//-------------------------------------- Ending function -----------------------------////----add_action('wp_print_styles', 'add_linkbase_stylesheet') this function run the add_linkbase_stylesheet() function.--------------////--------wp_register_style('myStyleSheets', $myStyleUrl) this function register the file $myStyleUrl with the name myStyleSheets.------////--------wp_enqueue_style( 'myStyleSheets') enqueue the style sheet named 'myStyleSheets'.------------////--------Now create the css file inside the linkbase-questions folder.--------////--------- Function for adding footer ------------------///*add_action('admin_footer', 'footer_text1');function footer_text1() { echo "<p id='footer1' style=\"text-align:center;\">Created by skysoft.net.in</p>";} *///--------------------- Function for Calling Shortcode On frontend-----------------------------////------------- ShortCode function calling -------------//function linkbase_tutorial_site_listing_shortcode($atts) { extract( shortcode_atts( array( 'id' => '0' ), $atts ) );$table_id=$id;include 'front-list-site.php';return; /*print '<p>PRINT</p>'; return '<p>THIS IS THE RETURN VALUE</p>';*/ //------ include admin-list-site.php from Linkbase Plugin; ----//}//-------- Add ShortCode for "front end listing" -----------//add_shortcode("linkbase","linkbase_tutorial_site_listing_shortcode");//------------------------ Ending function ----------------------------------------//function bm_sc_mshot ($attributes, $content = '', $code = '') { extract(shortcode_atts(array( 'url' => '', 'width' => 100, ), $attributes)); $imageUrl = bm_mshot ($url, $width); if ($imageUrl == '') { return ''; } else { $image = '<img src="' . $imageUrl . '" alt="' . $url . '" width="' . $width . '"/>'; return '<div class="browsershot mshot"><a href="' . $url . '" target="blank">' . $image . '</a></div>'; }}function bm_mshot ($url = '', $width = 100) { $pieces = explode("//", $url); $piec = explode(".", $url); $scrn = $piec[0]; $screen = $pieces[0]; $pieces[1]; if($screen == 'https:' || $screen == 'http:' || $scrn == 'www') { if ($url != '') { return 'http://s.wordpress.com/mshots/v1/' . urlencode(clean_url($url)) . '?w=' . $width; } else { return ''; } } else { return ''; }}add_shortcode('browsershot', 'bm_sc_mshot'); ?>