Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!class_exists('MyDomainListPluginPro', false)) {
- class MyDomainListPluginPro {
- const POSTTYPE = 'mdlp_my_domain_list';
- const TAXONOMY = 'mdlp_categories';
- const OPTIONNAME = 'mdlp_settings';
- const ALLCOLUMNS = 'owner,extension,registrar,created,changed,expires,price,offer,category,buy';
- public $pluginDir;
- public $pluginPath;
- public $pluginUrl;
- public $pluginDomain = 'My-Domain-List-Pro';
- private $tabIndexStart = 5000;
- private $taxonomyLabels;
- public $latestOptions;
- public $postData;
- public $shortcodeOptions;
- public $postDataFilter;
- private $postTypeArgs = array(
- 'public' => true,
- 'rewrite'=> false,
- 'singular_label' => 'mydomainlist',
- 'publicly_queryable' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'query_var' => true,
- 'capability_type' => 'post',
- 'has_archive' => true,
- 'hierarchical' => false,
- 'menu_position' => 5,
- 'supports' => array('title','editor','author','thumbnail','excerpt','comments', 'custom-fields', 'revisions')
- );
- public $metaTags = array(
- '_MyDomainListName',
- '_MyDomainListRegistrar',
- '_MyDomainListOwner',
- '_MyDomainListCreated',
- '_MyDomainListExpires',
- '_MyDomainListChanged',
- '_MyDomainListPrice',
- '_MyDomainListRedirectURL',
- '_MyDomainListThumbnailURL',
- '_MyDomainListShowOfferButton',
- '_MyDomainListPaymentService',
- '_MyDomainListIsPremium',
- '_MyDomainListCurrency',
- '_MyDomainListHTMLCode',
- '_MyDomainListExtension',
- '_MyDomainListCategories'
- );
- public $currencies = array(
- "USD" => "$",
- "CAD" => "$",
- "BRL" => "R$",
- "GBP" => "£",
- "EUR" => "€",
- "INR" => "Rp",
- "JPY" => "¥"
- );
- /**
- * MyDomainListPlugin plugin constructor
- *
- * @return null
- */
- function __construct()
- {
- $this->pluginDir = trailingslashit( basename( dirname(__FILE__) ) );
- $this->pluginPath = trailingslashit( dirname(__FILE__) );
- $this->pluginUrl = WP_PLUGIN_URL.'/'.$this->pluginDir;
- register_activation_hook( __FILE__, array(&$this, 'activate' ));
- register_uninstall_hook(__FILE__, array( &$this, 'uninstall' ));
- register_deactivation_hook( __FILE__, array(&$this, 'deactivate' ));
- add_theme_support( 'post-thumbnails', array( 'self::POSTTYPE' ) );
- $this->add_actions();
- $this->add_admin_actions();
- }
- function __destruct()
- {
- unset($mdlp);
- }
- /**
- * This function writes to the header tag of the page
- *
- * @return null
- */
- function loadHeader() {
- ?>
- <link rel='stylesheet' href='http://ajax.googleapis.com/ajax/libs/jqueryui/1.7/themes/smoothness/jquery-ui.css' type='text/css' media='all' />
- <?php
- }
- /**
- * This function registers the MyDomainListProWidget widget
- *
- * @return Array post data
- */
- function load_my_domain_list_pro_widget() {
- register_widget( new MyDomainListProWidget );
- }
- /**
- * This function initializes MyDomainListPlugin Pro plugin action and filter hooks
- *
- * @return null
- */
- private function add_actions() {
- add_action( 'wp_head', array ($this, loadHeader));
- add_action( 'init', array( $this, 'initialize'), 1 );
- add_action('wp_enqueue_scripts', array( $this, 'load_assets'), 1 );
- add_action('admin_menu', array("MyDomainListPluginProAdmin", 'add_main_plugin_menu'));
- add_action("template_include", array( $this,'show_site_template'));
- include( $this->pluginPath . 'my-domain-list-pro-widget.php' );
- add_action('widgets_init', create_function('', 'return register_widget("MyDomainListProWidget");'));
- add_action("manage_posts_custom_column", array(&$this, "custom_my_domain_list_columns"));
- add_filter("manage_edit-" . self::POSTTYPE . "_columns", array( &$this, 'edit_my_domain_list_columns'));
- add_action( 'save_post', array( $this, 'save_my_domain_postdata' ) ); // Save the custom fields
- add_action('quick_edit_custom_box', array( $this,'show_quick_edit'), 10, 2);
- add_action('admin_head-edit.php', array( $this,'get_quick_edit_data'));
- add_action('edit_post',array ($this, 'save_quick_edit_data'), 10, 3);
- add_action('wp_ajax_my-domain-list-pro-user-table', array("MyDomainListPluginProUser", "display_user_table"));
- add_action('wp_ajax_nopriv_my-domain-list-pro-user-table', array("MyDomainListPluginProUser", "display_user_table"));
- add_action('wp_ajax_nopriv_my-domain-list-pro-make-offer', array($this, "process_offer"));
- add_action('wp_ajax_my-domain-list-pro-make-offer', array($this, "process_offer"));
- add_shortcode( 'my-domain-list-pro',array("MyDomainListPluginProUser", "handle_shortcode"));
- //add_filter('generate_rewrite_rules', array(&$this,'filterRewriteRules'));
- }
- /**
- * This function customizes the admin footer
- *
- * @return null
- */
- function add_admin_footer() {
- echo 'DN';
- }
- /**
- * This function calls the single template to display each custom post type
- * http://prefix.my-domain-list.com/mdlp_my_domain_list/mdlp_categories
- * http://prefix.my-domain-list.com/mdlp_my_domain_list/creditdemo-com/
- * http://prefix.my-domain-list.com/mdlp_my_domain_list/
- * @return template
- */
- function show_site_template($template){
- if ( get_query_var( 'post_type' ) != self::POSTTYPE ) {
- return $template;
- }
- if ( get_query_var('post_type') == self::POSTTYPE ) {
- if ( is_single() ) {
- return $this->pluginPath . '/single-mdlp_my_domain_list.php';
- //http://prefix.my-domain-list.com/mdlp_my_domain_list/creditdemo-com/
- }else if(is_post_type_archive(self::POSTTYPE )){
- return $this->pluginPath . '/archive-mdlp_my_domain_list.php';
- //http://prefix.my-domain-list.com/mdlp_my_domain_list/
- }else {
- return $this->pluginPath . '/my-domain-list-pro-category.php';
- //http://prefix.my-domain-list.com/mdlp_my_domain_list/mdlp_categories
- }
- } //http://prefix.my-domain-list.com/mdlp_my_domain_list/mdlp_categories/service/
- //reference: http://mondaybynoon.com/2011/05/20/revisiting-custom-post-types-taxonomies-permalinks-slugs/
- }
- /**
- * This function gets the Post data based on a key value
- * @param $key filter value such as category, extension, owner, etc
- * @return Array post data
- */
- function get_post_data_key_values($key){
- $val = array();
- foreach($this->postData as $arr){
- foreach ($arr as $k => $value) {
- if($key=="category"){
- if($k=="category") {
- foreach($value as $cat){
- if(!in_array($cat, $val)){
- array_push($val, $cat);
- }
- }
- }
- }else{
- if(($k==$key)&& (!in_array($value, $val))) {
- array_push($val, $value);
- }
- }}
- }
- return $val;
- }
- /**
- * This function gets the filtered data on the Post Filtered data
- *
- * @return Array post data filtered
- */
- function get_post_data_filtered($key, $value, $page=null){
- $val = array();
- //echo "key" . $key;
- //echo "value" . $value;
- //key=category value=Brasil
- foreach($this->postData as $arr){
- foreach ($arr as $k => $v) {
- //echo $k;
- //id,category,extension,name,owner,registrar,created,expires,changed,price,redirectURL,thumbnailURL,showOfferButton
- //echo $v;
- //234,Array,.com,souocara.com,Luciana Bruscino,GODADDY.COM,...
- if(($k==$key)&& (!in_array($arr, $val)))
- {
- if(isset($page)){
- if(is_array($v)){ //category is an array
- if(in_array($value, $v)){
- array_push($val,$arr);
- }
- }else{
- if(strtoupper($v[0])==strtoupper($value)) {array_push($val, $arr);}}
- }else{
- if(is_array($v)){ //category is an array
- if(in_array($value, $v)){
- array_push($val,$arr);
- }
- }else{
- if(strtoupper($v)==strtoupper($value)) {
- array_push($val, $arr);
- }}
- }
- }
- }
- }
- return $val;
- }
- /**
- * This function returns the icon - featured image
- *
- * @param $posId integer Post ID
- * @param $defaultSize string Size of the image thumbnail image - exceptable values: medium, large or full
- * @param $showEmpty bool Displays default image - thumb-empty.jpg
- *
- * @return null
- */
- function show_domain_icon($postId, $defaultSize = 'small', $showEmpty=false){
- $class = "";
- $thumb ="";
- $img = get_the_post_thumbnail($postId, $defaultSize);
- if(empty($img) && $showEmpty){
- $imgPath = WP_PLUGIN_URL.'/my-domain-list-pro/img/thumb-empty.jpg';
- switch($defaultSize){
- case "full":
- $imageSize = "";
- break;
- case "thumbnail":
- $imageSize = "width=150 height=150";
- break;
- default:
- $imageSize = "width=50 height=50";
- }
- $img = '<img src="'.$imgPath.'" '. $imageSize .'>';
- }
- $link = get_post_meta($postId , '_MyDomainListRedirectURL' , true );
- if(empty($link)) $link =get_permalink( $postId );
- if(!empty($link)){
- $thumb ='<a href="';
- $thumb .= $link;
- $thumb .= '" >';
- }
- $thumb .= $img;
- if(!empty($link)){$thumb .= '</a>';}
- return $thumb;
- }
- /**
- * This function returns the domain name and associated link
- *
- * @param $posId integer Post ID
- * @param $withThumbnail bool Displays domain name with featured image
- *
- * @return null
- */
- function show_domain_name($postId, $withThumbnail = true){
- $link =get_post_meta($postId , '_MyDomainListRedirectURL' , true );
- if(empty($link)) $link =get_permalink( $postId );
- $class = "";
- $thumb ="";
- if($withThumbnail){
- if(has_post_thumbnail( $postId )){
- $thumb ='<a href="';
- $thumb .= $link;
- $thumb .= '" >';
- $thumb .= get_the_post_thumbnail($postId, array(50,50));
- $thumb .= '</a>';
- }
- }
- if(get_post_meta( $postId, "_MyDomainListIsPremium", true )=="Y")
- $class = "mdlp_css_premium";
- $name = $thumb . '<a href="'.trim($link).'" target="_blank" class="'.$class.'">'. get_the_title($postId).'</a>';
- $asLink = $this->getOption("NameAsLink");
- if($asLink=="false"){
- $name = $thumb . ' '. get_the_title($postId);
- }
- return $name;
- }
- /**
- * This function returns the domain category and link
- *
- * @param $posId integer Post ID
- *
- * @return null
- */
- function show_domain_category($postId){
- return the_terms( $postId, self::TAXONOMY, '', ', ', '' );
- }
- /**
- * This function retrieve the domain category as an array
- *
- * @param $posId integer Post ID
- *
- * @return array of categories
- */
- function retrieve_domain_category($postId){
- $terms = get_the_terms( $postId, self::TAXONOMY );
- if ( $terms && ! is_wp_error( $terms ) ){
- $draught_links = array();
- foreach ( $terms as $term ) {
- $draught_links[] = $term->name;
- }
- return $draught_links;
- }
- }
- /**
- * This function returns the domain description
- *
- * @param $posId integer Post ID
- *
- * @return null
- */
- function show_domain_desc($postId) {
- $content_post = get_post($postId);
- return $content_post->post_content;
- }
- /**
- * This function returns the buy button from the selected payment service
- *
- * @param $posId integer Post ID
- *
- * @return null
- */
- function show_buy_button($postId){
- $html = get_post_meta( $postId, "_MyDomainListHTMLCode", true );
- if(!$html)
- $html="";
- return html_entity_decode($html);
- }
- /**
- * This function returns the offer button
- *
- * @param $posId integer Post ID
- *
- * @return null
- */
- function show_offer_button($postId){
- $price = get_post_meta( $postId, "_MyDomainListPrice", true );
- $name = get_post_meta( $postId, "_MyDomainListName", true );
- $key = $this->getOption("TableCurrency");
- $price = $this->currency_format($price, $key);
- if (empty($price)){
- $price = 0.00;
- }
- return '<input type="button" id="mdlp_btn_offer_'.$postId.'" value="Make Offer" name="'. $price .'|'. $name .'" class="myDomainListProMakeOfferButton" />';
- }
- /**
- * This function returns the domain price
- *
- * @param $posId integer Post ID
- *
- * @return null
- */
- function show_domain_price($postId, $showOffer = false){
- $price = get_post_meta( $postId, "_MyDomainListPrice", true );
- if (empty($price)){
- $price = 0.00;
- }
- $key = $this->getOption("TableCurrency");
- $symbol = $this->currencies[$key];
- $price = $this->currency_format($price, $key);
- if($showOffer) {
- return $symbol. $price.$this->show_domain_offers(get_post_meta( $postId, "_MyDomainListName", true ));
- }
- return $symbol. $price;
- }
- /**
- * This function returns the domain price
- *
- * @param $name string Domain Name
- *
- * @return null
- */
- function show_domain_offers($name){
- global $wpdb;
- $mdlp_offer_table_name = $wpdb->prefix . "mydomainlistpro_offer";
- $offers = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(name) FROM %s WHERE name %s", $mdlp_offer_table_name, $name ) );
- if($offers)
- return '<div class="mdlp_css_OfferCountBackground" title="# offers - see in WPDashboard">'.$offers.'</div> ';
- return;
- }
- /**
- * This function returns the domain price currency only
- *
- *
- * @return null
- */
- function show_domain_currency(){
- $key = $this->getOption("TableCurrency");
- $symbol = $this->currencies[$key];
- return $symbol;
- }
- /**
- * This function returns created date
- *
- * @param $posId integer Post ID
- *
- * @return expiration date div
- */
- public function show_domain_date($postId, $type='Expires') {
- $tag = "_MyDomainListDate".$type;
- $tag1 = "_MyDomainList".$type;
- $cDate = get_post_meta( $postId, $tag, true );
- if(empty($cDate)){
- $cDate = get_post_meta( $postId, $tag1, true );
- }
- return $cDate;
- }
- /**
- * This function returns text if Domain is marked as Premium in Domain Post
- *
- * @param $posId integer Post ID
- *
- * @return Premium text
- */
- public function show_premium_text($postId, $displayText='* this is a premium domain'){
- $text = "";
- if(get_post_meta( $postId , '_MyDomainListIsPremium' , true )=="Y"){
- $text = $displayText;
- }
- return $text;
- }
- /**
- * This function return expiration date and tag
- *
- * @param $posId integer Post ID
- *
- * @return expiration date div
- */
- public function show_domain_expire_date($postId) {
- //$exp_date = get_post_meta( $postId, "_MyDomainListExpires", true );
- $exp_date = $this->show_domain_date($postId, 'Expires');
- $expirationNotification ="";
- if (empty($exp_date))
- return "";
- if(($exp_date !="0000-00-00")){
- $todays_date = date("Y-m-d");
- $today = strtotime($todays_date);
- $expiration_date = strtotime($exp_date);
- $difference = $expiration_date - $today;
- if ($difference < 0) { $difference = 0; }
- $daysToExpire = floor($difference/60/60/24);
- if ($expiration_date < $today) {
- $expirationNotification = '<div class="mdlp_css_ExpiredBackground" title="domain expired">e</div>';
- }else if ($daysToExpire == 0){
- $expirationNotification='<div class="mdlp_css_ExpiredBackground" title="domain expires today">!</div>';
- }else if ($daysToExpire < 10){
- $expirationNotification='<div class="mdlp_css_Expired10Background" title="expires within 10 days">!</div>';
- }else if ($daysToExpire < 30 ){
- $expirationNotification='<div class="mdlp_css_Expired30Background" title="expires within 30 days">!</div>';
- }
- }
- return $exp_date." ".$expirationNotification;
- }
- /**
- * This function initializes MyDomainListPlugin plugin action and filter hooks for the Admin panel
- *
- * @return null
- */
- private function add_admin_actions() {
- if ( is_admin() ){
- add_action( 'admin_init', array($this, "initializeAdmin") );
- add_action('admin_enqueue_scripts', array( $this, 'load_assets_admin'), 1 );
- add_filter('admin_footer_text', array($this, "add_admin_footer"));
- add_action('admin_menu', array($this, 'add_new_admin_redirect'));
- add_action('wp_ajax_my-domain-list-pro-dismiss-offer', array("MyDomainListPluginProDashboard", "dismissOffer"));
- add_action('wp_ajax_nopriv_my-domain-list-pro-dismiss-offer', array("MyDomainListPluginProDashboard", "dismissOffer"));
- add_action('wp_dashboard_setup', array("MyDomainListPluginPro","add_dashboard_widget") );
- wp_localize_script( 'my-domain-list-ajax-request', 'my_domain_ajax_script', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
- add_action('restrict_manage_posts',array($this, 'my_domain_restrict_manage_posts'));
- add_action( 'request', array($this, 'my_domain_request') );
- }
- }
- /**
- * Adds Domain specific rewrite rules.
- *
- * @return void
- */
- public function filterRewriteRules( $wp_rewrite ) {
- //if ( '' == get_option('permalink_structure') ) {
- //}
- $base = trailingslashit( $this->rewriteSlug );
- $baseSingle = trailingslashit( $this->rewriteSlugSingular );
- $baseTax = trailingslashit( $this->taxRewriteSlug );
- $baseTax = "(.*)" . $baseTax;
- $newRules[$base . 'page/(\d+)'] = 'index.php?post_type=' . self::POSTTYPE;
- $newRules[$baseTax . '([^/]+)/?$'] = 'index.php?post_type= ' . self::POSTTYPE;
- $wp_rewrite->rules = $newRules + $wp_rewrite->rules;
- }
- function create_submenu() {
- //create custom post type menu
- add_menu_page('Domain List Pro', 'Domain List Pro', 'administrator', 'mdlp_main_menu', 'mdlp_settings');
- //create submenu items
- add_submenu_page('mdlp_main_menu', 'Add New', 'Add New', 'administrator', 'mdlp_sub_add_new',array("MyDomainListPluginProAdmin", "addAdminPage"));
- add_submenu_page('mdlp_main_menu', 'Customize', 'Customize', 'administrator', 'mdlp_sub_customize', array('MyDomainListPluginProAdmin', 'addAdminPage'));
- }
- /**
- * This function checks if user is trying to access the Add New page and redirects it to Setting page
- *
- * @return redirect
- */
- function add_new_admin_redirect() {
- $result = stripos($_SERVER['REQUEST_URI'], 'post-new.php?post_type='.self::POSTTYPE);
- if ($result!==false) {
- wp_redirect(get_option('siteurl') . '/wp-admin/admin.php?page=mdlp_sub_add_new');
- }
- }
- /**
- * This function removes the Add New option from the Menu
- *
- * @return null;
- */
- function remove_add_new_option(){
- global $submenu;
- unset($submenu['edit.php?post_type='.self::POSTTYPE][10]);
- }
- /**
- * This function initializes MyDomainListPlugin plugin
- *
- * @return null
- */
- public function initialize() {
- $this->pluginName = __( 'My Domain List', $this->pluginDomain );
- $this->rewriteSlugSingular = 'my-domain-list-pro-single';
- $this->rewriteSlug = 'mdlp_my_domain_list';
- $this->taxRewriteSlug = $this->rewriteSlug . '/' . __( 'mdlp_categories', $this->pluginDomain );
- global $wpdb;
- $mdlp_offer_table_name = $wpdb->prefix . "mydomainlistpro_offer";
- if($wpdb->get_var("SHOW TABLES LIKE '$mdlp_offer_table_name'") != $mdlp_offer_table_name) {
- $sql = "CREATE TABLE $mdlp_offer_table_name (
- id int(11) NOT NULL AUTO_INCREMENT,
- postID int(11) NOT NULL,
- name VARCHAR(200) NOT NULL,
- email VARCHAR(80) NOT NULL,
- price int(2) NOT NULL,
- comments TEXT,
- currency VARCHAR(3),
- updated_at DATETIME NOT NULL,
- PRIMARY KEY (id)
- );";
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
- dbDelta($sql);
- }
- $this->create_post_type();
- }
- public function create_post_type() {
- $this->get_post_type_labels();
- register_post_type(self::POSTTYPE, $this->postTypeArgs);
- register_taxonomy( self::TAXONOMY, self::POSTTYPE, array(
- 'hierarchical' => true,
- 'update_count_callback' => '',
- 'query_var'=>true,
- 'rewrite' => false,
- //'rewrite' => array('slug'=> $this->taxRewriteSlug),
- 'public' => true,
- 'show_ui' => true,
- 'has_archive' => true,
- 'labels' => $this->taxonomyLabels
- ));
- }
- private function get_post_type_labels() {
- $this->postTypeArgs['labels'] = array(
- 'name' => __('My Domain', $this->pluginDomain),
- 'singular_name' => __('My Domain List', $this->pluginDomain),
- 'add_new' => __('Add New', $this->pluginDomain),
- 'add_new_item' => __('Add New Domain', $this->pluginDomain),
- 'edit_item' => __('Edit My Domain List', $this->pluginDomain),
- 'new_item' => __('New My Domain', $this->pluginDomain),
- 'view_item' => __('View My Domain List', $this->pluginDomain),
- 'search_items' => __('Search My Domains List', $this->pluginDomain),
- 'not_found' => __('No domains found', $this->pluginDomain),
- 'not_found_in_trash' => __('No domains found in Trash', $this->pluginDomain),
- 'menu_name' => __('All Domains', $this->pluginDomain),
- 'parent_item_colon' => ''
- );
- $this->taxonomyLabels = array(
- 'name' => __( 'Categories', $this->pluginDomain ),
- 'singular_name' => __( 'My Domain List Category', $this->pluginDomain ),
- 'search_items' => __( 'Search My Domain List Categories', $this->pluginDomain ),
- 'all_items' => __( 'All My Domain List Categories', $this->pluginDomain ),
- 'parent_item' => __( 'Parent My Domain List Category', $this->pluginDomain ),
- 'parent_item_colon' => __( 'Parent My Domain List Category:', $this->pluginDomain ),
- 'edit_item' => __( 'Edit My Domain List Category', $this->pluginDomain ),
- 'update_item' => __( 'Update My Domain List Category', $this->pluginDomain ),
- 'add_new_item' => __( 'Add New My Domain List Category', $this->pluginDomain ),
- 'new_item_name' => __( 'New My Domain List Category Name', $this->pluginDomain )
- );
- }
- function save_my_domain_postdata($postId ) {
- global $_POST;
- // verify this came from the our screen and with proper authorization,
- if ( $post->post_type != self::POSTTYPE ) {
- //return;
- }
- if ( wp_is_post_autosave( $postId ) || $post->post_status == 'auto-draft' || isset($_GET['bulk_edit']) || $_REQUEST['action'] == 'inline-save' ) {
- //return;
- }
- remove_action( 'save_post', array( $this, 'save_my_domain_postdata' ) );
- //update meta fields
- foreach ( $this->metaTags as $tag ) {
- $htmlElement = ltrim( $tag, '_' );
- if ( isset( $_POST[$htmlElement] ) ) {
- if ( is_string($_POST[$htmlElement]) )
- $_POST[$htmlElement] = filter_var($_POST[$htmlElement], FILTER_SANITIZE_STRING);
- $meta_value =$_POST[$htmlElement];
- if($htmlElement =='_MyDomainListShowOfferButton') {
- if(empty($meta_value)) $meta_value ='N';
- }
- update_post_meta( $postId, $tag, $_POST[$htmlElement] );
- }
- }
- }
- /**
- * This function display Custom Post Type fields in Quick Edit
- *
- * @return null
- */
- function show_quick_edit( $col, $type ) {
- if( $type == self::POSTTYPE && did_action('quick_edit_custom_box') === 1){ ?>
- <fieldset class="inline-edit-col-left">
- <div class="inline-edit-col">
- <div class="inline-edit-group">
- <label class="inline-edit-status alignleft"> <span
- style="width: 40%; font: italic 12px Georgia, serif;">Domain Price:
- <?php echo $this->show_domain_currency();?> </span> <input
- id="_MyDomainListPriceEdit" type="text"
- name="_MyDomainListPriceEdit" value="" size="5" /> </label> <input
- type="hidden" name="is_quickedit" value="true" />
- </div>
- </div>
- </fieldset>
- <?php } else {
- return;
- }
- }
- /**
- * This function gets current value of Custom Post Type field in Quick Edit
- * It uses ajax to pull data from the server via the my-domain-list-admin-edit.php file
- *
- * @return null
- */
- function get_quick_edit_data() {
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function() {
- jQuery("a.editinline").live("click", function() {
- var mdlp_action_url = "<?php echo $this->pluginUrl ?>my-domain-list-admin-edit.php";
- var mdlp_post_id = inlineEditPost.getId(this);
- if(mdlp_post_id){
- jQuery.post(mdlp_action_url,
- { mdlp_js_post_id: mdlp_post_id },
- function(data){jQuery("#_MyDomainListPriceEdit").val(data); }
- );
- }
- });
- });
- </script>
- <?php }
- /**
- * This function saves value of Custom Post Type field in Quick Edit to the appropriate WP MetaData
- *
- *
- * @return null
- */
- function save_quick_edit_data($post_id, $post) {
- if( $post->post_type != self::POSTTYPE ) return;
- if (isset($_POST['is_quickedit']))
- update_post_meta($post_id, '_MyDomainListPrice', $_POST['_MyDomainListPriceEdit']);
- }
- /**
- * This function displays custom data from my domain list post type
- *
- * @return null
- */
- function custom_my_domain_list_columns($column) {
- global $post;
- switch ($column) {
- case "_MyDomainListOwner":
- echo get_post_meta( $post->ID , '_MyDomainListOwner' , true );
- break;
- case "_MyDomainListCreated":
- //echo get_post_meta( $post->ID , '_MyDomainListCreated' , true );
- echo $this->show_domain_date( $post->ID , 'Created');
- break;
- case "_MyDomainListExpires":
- echo $this->show_domain_expire_date($post->ID);
- break;
- case "_MyDomainListRegistrar":
- echo get_post_meta( $post->ID , '_MyDomainListRegistrar' , true );
- break;
- case "_MyDomainListPrice":
- echo $this->show_domain_price($post->ID, true);
- break;
- case "_MyDomainListCategories":
- //$cats = get_the_term_list($post->ID, self::TAXONOMY, '', ', ', '' );
- //echo ( $cats ) ? strip_tags( $cats ) : '—';
- echo $this->show_domain_category($post->ID);
- break;
- }
- }
- function edit_my_domain_list_columns($column){
- $columns = array(
- "cb" => "<input type=\"checkbox\" />",
- "title" => "Name",
- "_MyDomainListRegistrar" => "Registrar",
- "_MyDomainListOwner" => "Owner",
- "_MyDomainListCreated" => "Created",
- "_MyDomainListExpires" => "Expires",
- "_MyDomainListPrice"=>"Price",
- "_MyDomainListCategories"=>"Categories"
- );
- return $columns;
- }
- function my_domain_restrict_manage_posts() {
- global $typenow;
- global $wp_query;
- if ($typenow==self::POSTTYPE){
- $args = array(
- 'show_option_all' => "Show All Categories",
- 'taxonomy' => self::TAXONOMY,
- 'name' => self::TAXONOMY,
- 'orderby' => 'name',
- 'selected' => get_term_by('name', $wp_query->query[self::TAXONOMY], self::TAXONOMY)->term_id,
- 'id' => '',
- 'hierarchical' => true,
- 'depth' => 1,
- 'show_count' => true, // Show # listings in parens
- 'hide_empty' => true,
- );
- wp_dropdown_categories($args);
- }
- }
- function my_domain_request($request) {
- if (is_admin() && $GLOBALS['PHP_SELF'] == '/wp-admin/edit.php' && isset($request['post_type']) && $request['post_type']==self::POSTTYPE) {
- $request[self::TAXONOMY] = get_term($request[self::TAXONOMY],self::TAXONOMY)->slug;
- }
- return $request;
- }
- /**
- * This function initializes js necessary to be used in the Admin page as well as metaboxes
- *
- * @return null
- */
- function initializeAdmin() {
- wp_register_script( 'my-domain-list-pro_1', plugins_url('/js/my-domain-list-pro-js-script.js', __FILE__), array('jquery'));
- wp_enqueue_script('my-domain-list-pro_1');
- wp_register_script( 'my-domain-list-pro_4', plugins_url('/js/jscolor.js', __FILE__), array('jquery'));
- wp_enqueue_script('my-domain-list-pro_4');
- add_meta_box( 'My Domain List Details', $this->pluginName, array( $this, 'create_meta_boxes' ), self::POSTTYPE, 'normal', 'high' );
- }
- /**
- * This function creates the metaboxes boxes. It calls the metabox file for the form data
- *
- * @return null
- */
- public function create_meta_boxes() {
- global $post;
- $postId = $post->ID;
- foreach ( $this->metaTags as $tag ) {
- $$tag = get_post_meta( $postId, $tag, true );
- if($tag =='_MyDomainListShowOfferButton') {
- if(empty($$tag)) $$tag ='N';
- }
- if ( $postId && isset($_GET['post']) && $_GET['post'] ) { //if there is a post AND the post has been saved at least once.
- if(!update_post_meta($postId, $tag, htmlentities($$tag, ENT_QUOTES), true)){
- /*echo "Issue updating data";*/
- }
- } else {
- update_post_meta($postId, $tag, htmlentities($$tag, ENT_QUOTES), true);
- }
- }
- $showOfferButton = '';
- if(get_post_meta( $postId, "_MyDomainListShowOfferButton", true )=="Y"){
- $showOfferButton = " selected";
- }
- $isPremium="";
- if(get_post_meta( $postId, "_MyDomainListIsPremium", true )=="Y"){
- $isPremium=" selected";
- }
- include( $this->pluginPath . 'my-domain-list-pro-metabox.php' );
- }
- /**
- * This function creates the select box for the currency
- *
- * @return null
- */
- function show_currency_options(){
- $optionHTML = '<select name="my_domain_list_pro_currency" id="my_domain_list_pro_currency">';
- foreach($this->currencies as $currencyKey => $currencyValue){
- $currencySelectOptionSelected =($currencyKey==$this->getOption("TableCurrency"))?' selected ':'';
- $optionHTML .= '<option value="'.$currencyKey.'" '. $currencySelectOptionSelected.'>';
- $optionHTML .= $currencyKey;
- $optionHTML .= '</option>';
- }
- return $optionHTML;
- }
- /**
- * add_dashboard_widget
- *
- * This function creates the function used in the action hook for the dashboard widget
- *
- * return null
- */
- function add_dashboard_widget() {
- wp_add_dashboard_widget('my_domain_list_pro_dashboard_widget', 'My Domain List Pro Offers', array("MyDomainListPluginProDashboard","dashboard_widget_output"));
- }
- /**
- * This function processes the domain offer information into the database.
- *
- * @return message to user with information (name and price) about the offer.
- */
- function process_offer(){
- global $mdlp;
- global $wpdb;
- //Verifies the AJAX request to prevent processing requests external of the blog.
- check_ajax_referer( "my_domain_list_pro_make_offer_content_key" );
- $myDomainListOfferData = $_REQUEST[ 'attr' ];
- $myDomainListNameValue = $myDomainListOfferData[name];
- $myDomainListPriceValue = $myDomainListOfferData[price];
- $myDomainListEmailValue = $myDomainListOfferData[email];
- $myDomainListCommentsValue = $myDomainListOfferData[comments];
- $myDomainListCurrencyValue = $myDomainListOfferData[currency];
- $my_domain_list_offer_table_name = $wpdb->prefix . "mydomainlistpro_offer";
- $query = $wpdb->prepare( "INSERT INTO $my_domain_list_offer_table_name ( name, email, comments, price, currency, updated_at) VALUES ( %s, %s, %s, %f, %s, %s )",
- $myDomainListNameValue,
- $myDomainListEmailValue,
- $myDomainListCommentsValue,
- $myDomainListPriceValue,
- $myDomainListCurrencyValue,
- date("Y/m/d")
- ); //end query
- if ($wpdb->query($query) === FALSE) {
- $return = new WP_Error('offer_insert_error', __('There has been a problem, please contact the website admin directly to make an offer.'));
- }
- if ( is_wp_error($return) ) {
- echo $return->get_error_message();
- }else{
- echo "Your offer of ".self::show_domain_currency() .$myDomainListPriceValue ." for ". $myDomainListNameValue . " has been submitted.";
- $p = $myDomainListPriceValue.' '.$myDomainListCurrencyValue;
- $args = array("domain" => $myDomainListNameValue, "price"=> $p);
- self::notify($args);
- }
- die();
- }
- /**
- * This function prepares data to call send email
- *
- * @return null
- */
- function notify($args= array()){
- $sender = "Admin";
- $rec = get_bloginfo('admin_email');
- $recipients = self::get_recipients($rec);
- $subject = "An offer has been made on your domain";
- $type = 'Default';
- $body = 'Good News! An offer has been make on '. $args["domain"].' for '.$args["price"].'. Login to your Wordpress Dashboard to find out more.';
- self::send_mail($recipients, $rec, $sender, $subject, $body, $type, $args);
- }
- /**
- * This function will return the recipient email(s)
- *
- * @return null
- */
- function get_recipients($recipients){
- if(empty($recipients)){
- return "";
- }
- if(is_array($recipients)){
- return implode(",", $recipients);
- }
- return (string) $recipients;
- }
- /**
- * This function sends email
- *
- * Returns number of recipients addressed in emails or false on internal error.
- */
- function send_mail($recipients, $sender_email, $sender_name, $subject = '', $message = '', $type = 'plaintext', $args) {
- $headers = "From: \"$sender_name\" <$sender_email>\n";
- $headers .= "Return-Path: <" . $sender_email . ">\n";
- $headers .= "Reply-To: \"" . $sender_name . "\" <" . $sender_email . ">\n";
- $headers .= "X-Mailer: PHP" . phpversion() . "\n";
- $subject = stripslashes($subject);
- $message = stripslashes($message);
- if ('html' == $type) {
- $headers .= "MIME-Version: 1.0\n";
- $headers .= "Content-Type: " . get_bloginfo('html_type') . "; charset=\"". get_bloginfo('charset') . "\"\n";
- $body = "<html><head><title>" . $subject . "</title></head><body>" . $message . "</body></html>";
- } else {
- $headers .= "MIME-Version: 1.0\n";
- $headers .= "Content-Type: text/plain; charset=\"". get_bloginfo('charset') . "\"\n";
- $message = preg_replace('|&[^a][^m][^p].{0,3};|', '', $message);
- $message = preg_replace('|&|', '&', $message);
- $body = wordwrap(strip_tags($message), 80, "\n");
- }
- if(!empty($args)){
- $b= '';
- foreach($args as $key => $value){
- if($key=="recipients"){
- $recipients = $value;
- }else{
- $b = str_replace("%".$key."%", $value , $body);
- $body = $b;
- }
- }
- }
- if ( (empty($recipients)) ) { return false; }
- //$headers .= "To: " . implode(',', $recipients) . "\n\n";
- $headers .= "To: " . $recipients . "\n\n";
- if(@wp_mail($recipients, $subject, $body, $headers)){
- return true;
- }
- echo "\n*Error notifying Admin of the offer, please contact site owner directly.";
- return false;
- }
- /**
- * activate
- *
- * This function creates settings options (settings) entries in wp_options and mydomainlist table in mysql
- * return null
- */
- public function activate() {
- $myDomainListSettingsData = array(
- 'mdlp_opt_Color'=>'ffffff',
- 'mdlp_opt_BackgroundColor'=>'000000',
- 'mdlp_opt_Pages'=>'',
- 'mdlp_opt_TableSize'=>'small',
- 'mdlp_opt_TableShow'=>'all',
- 'mdlp_opt_TableFilter'=>'None',
- 'mdlp_opt_PaginationType' => 'Numbers',
- 'mdlp_opt_TableCurrency' =>'USD',
- 'mdlp_opt_NameAsLink'=>'true'
- );
- add_option(self::OPTIONNAME, $myDomainListSettingsData);
- }
- /**
- * deactivate
- *
- * This function cleans up the entries (settings) created in the wp_options table in mysql.
- *
- */
- public function deactivate() {
- delete_option(self::OPTIONNAME);
- $this->flushRewriteRules();
- }
- /**
- * uninstall
- *
- * This function drops the mydomainlist table in mysql. Domains will no longer be available
- *
- */
- public function uninstall(){
- global $wpdb;
- $mydomainlistoffertable = $wpdb->prefix."mydomainlistpro_offer";
- $wpdb->query("DROP TABLE IF EXISTS $mydomainlistoffertable");
- }
- /**
- * Flush rewrite rules to support custom links
- *
- * @link http://codex.wordpress.org/Custom_Queries#Permalinks_for_Custom_Archives
- */
- public function flushRewriteRules() {
- global $wp_rewrite;
- $wp_rewrite->flush_rules();
- // in case this was called too early, let's get it in the end.
- add_action('shutdown', array($this, 'flushRewriteRules'));
- }
- /**
- * This function disables the browser from caching the data
- *
- * @return null
- */
- public function disableBrowserCache() {
- header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
- header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
- header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
- header("Cache-Control: post-check=0, pre-check=0", false);
- header("Pragma: no-cache");
- }
- /**
- * load_assets for admin pages only
- *
- * This function loads the necessary css and js files needed to support the plugin admin pages.
- *
- */
- public function load_assets_admin(){
- wp_enqueue_script('jquery');
- $css_url = WP_PLUGIN_URL.'/my-domain-list-pro/css/my-domain-list-pro_style.css';
- $css_file = WP_PLUGIN_DIR.'/my-domain-list-pro/css/my-domain-list-pro_style.css';
- if (file_exists($css_file)) {
- wp_register_style('my-domain-list-pro_stylesheet', $css_url);
- wp_enqueue_style('my-domain-list-pro_stylesheet');
- }
- }
- /**
- * load_assets
- *
- * This function loads the necessary javascript and css files needed to support the plugin - front end pages.
- *
- */
- public function load_assets() {
- wp_enqueue_script('jquery');
- wp_register_script( 'my-domain-list-pro_0', plugins_url('/js/my-domain-list-pro-js-tablesorter.js', __FILE__), array('jquery'));
- wp_enqueue_script('my-domain-list-pro_0');
- wp_register_script( 'my-domain-list-pro_2', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js');
- wp_enqueue_script( 'my-domain-list-pro_2' );
- $css_url = WP_PLUGIN_URL.'/my-domain-list-pro/css/my-domain-list-pro_style.css';
- $css_file = WP_PLUGIN_DIR.'/my-domain-list-pro/css/my-domain-list-pro_style.css';
- $css_dialog_url = WP_PLUGIN_URL.'/my-domain-list-pro/css/my-domain-list-pro_dialog.css';
- $css_dialog_file = WP_PLUGIN_DIR.'/my-domain-list-pro/css/my-domain-list_dialog.css';
- if (file_exists($css_file)) {
- wp_register_style('my-domain-list-pro_stylesheet', $css_url);
- wp_enqueue_style('my-domain-list-pro_stylesheet');
- }
- if (file_exists($css_dialog_file)) {
- wp_register_style('my-domain-list-pro_dialog_stylesheet', $css_dialog_url);
- wp_enqueue_style('my-domain-list-pro_dialog_stylesheet');
- }
- }
- /**
- * properCase
- *
- * This function converts a string into its proper case format.
- *
- * @param string $string Any string value
- * @return string String formatted in proper case
- */
- public function properCase($string){
- $string = strtolower($string);
- return substr_replace($string, strtoupper(substr($string, 0, 1)), 0, 1);
- }
- /**
- * saveOptions
- *
- * This function saves data into the options table
- *
- * @param array $opts
- * @return null
- */
- public function saveOptions($options) {
- if (!is_array($options)) {
- return;
- }
- if ( update_option(self::OPTIONNAME, $options) ) {
- $this->latestOptions = $options;
- } else {
- $this->latestOptions = $this->getOptions();
- }
- }
- /**
- * saveShortCodeOptions
- *
- * This function saves the shortcode data into shortcodeOptions property
- *
- * @param array $opts
- * @return null
- */
- public function saveShortCodeOptions ($options){
- if (!is_array($options)) {
- return;
- }
- $this->shortcodeOptions = $options;
- }
- /**
- * getShortcodeOptions
- *
- * This function saves data into the shortcodeOptions property
- * @return null
- */
- public function getShortcodeOptions(){
- return $this->shortcodeOptions;
- }
- /**
- * getOptions
- *
- * This function saves data into the options table
- * @return null
- */
- public function getOptions() {
- return get_option(self::OPTIONNAME, array());
- }
- /**
- * getOption
- *
- * @param string $optionName
- * @param string $default
- *
- * This function returns the option value requested. It also sets the default value if sent
- * @return string option saved
- */
- public function getOption($optionName, $default = '') {
- if( ! $optionName )
- return null;
- $options = $this->getOptions();
- $optionName = "mdlp_opt_".$optionName;
- return ( isset($options[$optionName]) ) ? $options[$optionName] : $default;
- }
- /**
- * getShortcodeOption
- *
- * @param string $optionName
- * @param string $default
- *
- * This function returns the shortcode value requested. It also sets the default value if sent
- * @return string option saved
- */
- public function getShortcodeOption($optionName, $default = '') {
- if( ! $optionName )
- return null;
- $options = $this->shortcodeOptions;
- if($optionName == 'size')
- return ( isset($options[$optionName]) ) ? 'myDomainListTable'.$options[$optionName] : $default;
- if($optionName == 'show'){
- $cols = ( isset($options[$optionName]) ) ? $options[$optionName] : $default;
- if($cols=='all'){
- return self::ALLCOLUMNS;
- }else{
- return preg_replace('/\s+/', '',$cols);
- }
- }
- return ( isset($options[$optionName]) ) ? $options[$optionName] : $default;
- }
- /**
- * This functions sets the next tab index
- * @return void
- */
- public function tabIndex() {
- echo $this->tabIndexStart;
- $this->tabIndexStart++;
- }
- /**
- * This function gets the taxonomy name
- * @return string Taxonomy
- */
- public function get_taxonomy() {
- return self::TAXONOMY;
- }
- function currency_format($amount, $key ='USD', $precision = 0, $use_commas = true, $show_currency_symbol = false, $parentheses_for_negative_amounts = false)
- {
- $amount = (float) $amount;
- // Get rid of negative zero
- $zero = round(0, $precision);
- if (round($amount, $precision) == $zero) {
- $amount = $zero;
- }
- if ($key=='BRL' || $key == 'EUR' || $key=='INR' || $key == 'JPY'){
- $use_commas = false;
- }
- if ($use_commas) {
- if ($parentheses_for_negative_amounts && ($amount < 0)) {
- $amount = '('.number_format(abs($amount), $precision).')';
- }
- else {
- $amount = number_format($amount, $precision);
- }
- }
- else {
- if ($parentheses_for_negative_amounts && ($amount < 0)) {
- $amount = '('.round(abs($amount), $precision).')';
- }
- else {
- $amount = number_format($amount, $precision, ',', '.');
- }
- }
- if ($show_currency_symbol) {
- $amount = '$'.$amount; // Change this to use the organization's country's symbol in the future
- }
- return $amount;
- }
- /**
- * This function displays page loading div on the page
- *
- * @return null
- */
- public function showPageLoadingIndicator(){
- ?>
- <div id="mdlp_id_page-loading" style="display: none">
- <img src="<?php echo WP_PLUGIN_URL.'/my-domain-list-pro/img/ajax-loader.gif' ?>" />
- </div>
- <?php
- }
- }//end class
- }
- global $mdlp;
- $mdlp = new MyDomainListPluginPro;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment