Guest User

php

a guest
Oct 28th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 47.15 KB | None | 0 0
  1. <?php
  2.  
  3. if (!class_exists('MyDomainListPluginPro', false)) {
  4.     class MyDomainListPluginPro {
  5.        
  6.         const POSTTYPE              = 'mdlp_my_domain_list';
  7.         const TAXONOMY              = 'mdlp_categories';   
  8.         const OPTIONNAME            = 'mdlp_settings';
  9.         const ALLCOLUMNS            = 'owner,extension,registrar,created,changed,expires,price,offer,category,buy';
  10.         public $pluginDir;
  11.         public $pluginPath;
  12.         public $pluginUrl;
  13.         public $pluginDomain        = 'My-Domain-List-Pro';
  14.         private $tabIndexStart      = 5000;    
  15.         private $taxonomyLabels;
  16.         public $latestOptions;
  17.         public $postData;      
  18.         public $shortcodeOptions;      
  19.         public $postDataFilter;    
  20.  
  21.        
  22.  
  23.         private $postTypeArgs = array(
  24.             'public' => true,  
  25.             'rewrite'=> false,             
  26.             'singular_label' => 'mydomainlist',
  27.             'publicly_queryable' => true,
  28.             'show_ui' => true,
  29.             'show_in_menu' => true,
  30.             'query_var' => true,           
  31.             'capability_type' => 'post',
  32.             'has_archive' => true,
  33.             'hierarchical' => false,
  34.             'menu_position' => 5,  
  35.             'supports' => array('title','editor','author','thumbnail','excerpt','comments', 'custom-fields', 'revisions')
  36.         ); 
  37.            
  38.         public $metaTags = array(
  39.             '_MyDomainListName',
  40.             '_MyDomainListRegistrar',
  41.             '_MyDomainListOwner',
  42.             '_MyDomainListCreated',
  43.             '_MyDomainListExpires',
  44.             '_MyDomainListChanged',
  45.             '_MyDomainListPrice',
  46.             '_MyDomainListRedirectURL',
  47.             '_MyDomainListThumbnailURL',
  48.             '_MyDomainListShowOfferButton',
  49.             '_MyDomainListPaymentService',
  50.             '_MyDomainListIsPremium',
  51.             '_MyDomainListCurrency',
  52.             '_MyDomainListHTMLCode',
  53.             '_MyDomainListExtension',
  54.             '_MyDomainListCategories'
  55.         );
  56.        
  57.         public $currencies = array(            
  58.                     "USD" => "$",
  59.                                         "CAD" => "$",
  60.                     "BRL" => "R$",
  61.                     "GBP" => "£",             
  62.                     "EUR" => "€",
  63.                     "INR" => "Rp",
  64.                     "JPY" => "¥"  
  65.                 );             
  66.        
  67.         /**
  68.          * MyDomainListPlugin plugin constructor
  69.          *
  70.          * @return null
  71.          */
  72.         function __construct()
  73.         {
  74.             $this->pluginDir        = trailingslashit( basename( dirname(__FILE__) ) );
  75.             $this->pluginPath       = trailingslashit( dirname(__FILE__) );
  76.             $this->pluginUrl        = WP_PLUGIN_URL.'/'.$this->pluginDir;
  77.            
  78.             register_activation_hook( __FILE__, array(&$this, 'activate' ));
  79.             register_uninstall_hook(__FILE__,  array( &$this, 'uninstall' ));
  80.             register_deactivation_hook( __FILE__, array(&$this, 'deactivate' ));
  81.             add_theme_support( 'post-thumbnails', array( 'self::POSTTYPE' ) ); 
  82.                    
  83.             $this->add_actions();
  84.             $this->add_admin_actions();
  85.         }
  86.  
  87.                function __destruct()
  88.                 {
  89.                     unset($mdlp);
  90.                 }
  91.                  
  92. /**
  93.          * This function writes to the header tag of the page
  94.          *
  95.          * @return null
  96.          */
  97.  
  98. function loadHeader() {
  99.   ?>
  100.       <link rel='stylesheet'  href='http://ajax.googleapis.com/ajax/libs/jqueryui/1.7/themes/smoothness/jquery-ui.css' type='text/css' media='all' />
  101.   <?php
  102. }
  103.  
  104.  
  105. /**
  106.              * This function registers the MyDomainListProWidget widget
  107.              *
  108.              * @return Array post data
  109.              */
  110.             function load_my_domain_list_pro_widget() {
  111.                 register_widget( new MyDomainListProWidget );
  112.             }
  113.    
  114.         /**
  115.          * This function initializes MyDomainListPlugin Pro plugin action and filter hooks
  116.          *
  117.          * @return null
  118.          */
  119.         private function add_actions() {
  120.  
  121.                         add_action( 'wp_head', array ($this, loadHeader));
  122.                         add_action( 'init', array( $this, 'initialize'), 1 );
  123.                         add_action('wp_enqueue_scripts', array( $this, 'load_assets'), 1 );
  124.             add_action('admin_menu',  array("MyDomainListPluginProAdmin", 'add_main_plugin_menu'));            
  125.             add_action("template_include",  array( $this,'show_site_template'));
  126.            
  127.  
  128.            
  129. include( $this->pluginPath . 'my-domain-list-pro-widget.php' );
  130.  
  131.             add_action('widgets_init', create_function('', 'return register_widget("MyDomainListProWidget");'));
  132.  
  133.             add_action("manage_posts_custom_column", array(&$this, "custom_my_domain_list_columns"));
  134.             add_filter("manage_edit-" . self::POSTTYPE . "_columns", array( &$this, 'edit_my_domain_list_columns'));
  135.             add_action( 'save_post', array( $this, 'save_my_domain_postdata' ) ); // Save the custom fields            
  136.             add_action('quick_edit_custom_box', array( $this,'show_quick_edit'), 10, 2);
  137.             add_action('admin_head-edit.php', array( $this,'get_quick_edit_data'));
  138.             add_action('edit_post',array ($this, 'save_quick_edit_data'), 10, 3);
  139.  
  140.             add_action('wp_ajax_my-domain-list-pro-user-table', array("MyDomainListPluginProUser", "display_user_table"));
  141.             add_action('wp_ajax_nopriv_my-domain-list-pro-user-table', array("MyDomainListPluginProUser", "display_user_table"));
  142.             add_action('wp_ajax_nopriv_my-domain-list-pro-make-offer', array($this, "process_offer"));
  143.             add_action('wp_ajax_my-domain-list-pro-make-offer', array($this, "process_offer"));
  144.             add_shortcode( 'my-domain-list-pro',array("MyDomainListPluginProUser", "handle_shortcode"));       
  145.  
  146.             //add_filter('generate_rewrite_rules', array(&$this,'filterRewriteRules'));
  147.         }  
  148.        
  149.         /**
  150.          * This function customizes the admin footer
  151.          *
  152.          * @return null
  153.          */
  154.         function add_admin_footer() {
  155.             echo 'DN';
  156.     }
  157.        
  158.         /**
  159.          * This function calls the single template to display each custom post type
  160.          *  http://prefix.my-domain-list.com/mdlp_my_domain_list/mdlp_categories
  161.          *  http://prefix.my-domain-list.com/mdlp_my_domain_list/creditdemo-com/
  162.          *  http://prefix.my-domain-list.com/mdlp_my_domain_list/
  163.          * @return template
  164.          */
  165.         function show_site_template($template){
  166.  
  167.             if ( get_query_var( 'post_type' ) != self::POSTTYPE ) {
  168.                 return $template;
  169.             }
  170.            
  171.             if ( get_query_var('post_type') == self::POSTTYPE ) {              
  172.                 if ( is_single() ) {               
  173.                      return $this->pluginPath . '/single-mdlp_my_domain_list.php';
  174.                      //http://prefix.my-domain-list.com/mdlp_my_domain_list/creditdemo-com/
  175.                 }else if(is_post_type_archive(self::POSTTYPE )){
  176.                     return $this->pluginPath . '/archive-mdlp_my_domain_list.php';
  177.                     //http://prefix.my-domain-list.com/mdlp_my_domain_list/
  178.                 }else {
  179.                     return $this->pluginPath . '/my-domain-list-pro-category.php';     
  180.                     //http://prefix.my-domain-list.com/mdlp_my_domain_list/mdlp_categories 
  181.                 }                                  
  182.             }   //http://prefix.my-domain-list.com/mdlp_my_domain_list/mdlp_categories/service/
  183.             //reference: http://mondaybynoon.com/2011/05/20/revisiting-custom-post-types-taxonomies-permalinks-slugs/                                              
  184.         }                  
  185.                
  186.         /**
  187.          * This function gets the Post data based on a key value
  188.          * @param $key filter value such as category, extension, owner, etc
  189.          * @return Array post data
  190.          */
  191.         function get_post_data_key_values($key){           
  192.             $val = array();
  193.            
  194.             foreach($this->postData as $arr){              
  195.                 foreach ($arr as $k => $value) {              
  196.                            if($key=="category"){                            
  197.                               if($k=="category") {
  198.                                  foreach($value as $cat){
  199.                                     if(!in_array($cat, $val)){
  200.                                      array_push($val, $cat);
  201.                                     }
  202.                                  }
  203.                               }
  204.                            }else{            
  205.                      if(($k==$key)&& (!in_array($value, $val))) {
  206.                                array_push($val, $value);
  207.                              }
  208.                 }}
  209.             }          
  210.             return $val;
  211.         }
  212.        
  213.         /**
  214.          * This function gets the filtered data on the Post Filtered data
  215.          *
  216.          * @return Array post data filtered
  217.          */
  218.         function get_post_data_filtered($key, $value, $page=null){
  219.            
  220.             $val = array();        
  221. //echo "key" . $key;           
  222. //echo "value" . $value;
  223. //key=category value=Brasil
  224.             foreach($this->postData as $arr){              
  225.                 foreach ($arr as $k => $v) {               
  226. //echo $k;
  227. //id,category,extension,name,owner,registrar,created,expires,changed,price,redirectURL,thumbnailURL,showOfferButton
  228. //echo $v;
  229. //234,Array,.com,souocara.com,Luciana Bruscino,GODADDY.COM,...
  230.                     if(($k==$key)&& (!in_array($arr, $val)))
  231.                     {
  232.                         if(isset($page)){
  233.                                                         if(is_array($v)){ //category is an array
  234.                                                           if(in_array($value, $v)){
  235.                                                             array_push($val,$arr);
  236.                                                           }
  237.                                                         }else{
  238.                             if(strtoupper($v[0])==strtoupper($value)) {array_push($val, $arr);}}
  239.                         }else{
  240.                             if(is_array($v)){ //category is an array
  241.                                                           if(in_array($value, $v)){
  242.                                                             array_push($val,$arr);
  243.                                                           }
  244.                                                         }else{
  245.                                                         if(strtoupper($v)==strtoupper($value)) {
  246.                                                            array_push($val, $arr);
  247.                                                         }}
  248.                         }
  249.                        
  250.                     }
  251.                 }
  252.             }          
  253.             return $val;
  254.         }                      
  255.  
  256.        
  257.        
  258.         /**
  259.          * This function returns the icon - featured image
  260.          *
  261.          * @param $posId integer Post ID
  262.          * @param $defaultSize string Size of the image thumbnail image - exceptable values: medium, large or full
  263.          * @param $showEmpty bool Displays default image - thumb-empty.jpg
  264.          *
  265.          * @return null
  266.          */
  267.         function show_domain_icon($postId, $defaultSize = 'small', $showEmpty=false){      
  268.                
  269.             $class = "";   
  270.             $thumb ="";
  271.                    
  272.                         $img = get_the_post_thumbnail($postId, $defaultSize);
  273.                         if(empty($img) && $showEmpty){
  274.                            $imgPath = WP_PLUGIN_URL.'/my-domain-list-pro/img/thumb-empty.jpg';
  275.                            
  276.                            switch($defaultSize){
  277.                              case "full":
  278.                                $imageSize = "";
  279.                                break;
  280.                              case "thumbnail":
  281.                                $imageSize = "width=150 height=150";
  282.                                break;                                                      
  283.                              default:
  284.                                $imageSize = "width=50 height=50";
  285.                            }
  286.                            $img = '<img src="'.$imgPath.'" '. $imageSize .'>';
  287.                         }
  288.                         $link = get_post_meta($postId , '_MyDomainListRedirectURL' , true );
  289.             if(empty($link)) $link =get_permalink( $postId );  
  290.                         if(!empty($link)){
  291.                $thumb ='<a href="';
  292.                $thumb .= $link;
  293.                $thumb .= '" >';
  294.                         }
  295.             $thumb .=  $img;
  296.             if(!empty($link)){$thumb .=  '</a>';}                                      
  297.                
  298.             return $thumb;                     
  299.         }
  300.        
  301.         /**
  302.          * This function returns the domain name and associated link
  303.          *
  304.          * @param $posId integer Post ID
  305.          * @param $withThumbnail bool Displays domain name with featured image
  306.          *
  307.          * @return null
  308.          */
  309.         function show_domain_name($postId, $withThumbnail = true){     
  310.            
  311.             $link =get_post_meta($postId , '_MyDomainListRedirectURL' , true );
  312.                         if(empty($link)) $link =get_permalink( $postId );  
  313.             $class = "";
  314.             $thumb ="";
  315.             if($withThumbnail){
  316.                            if(has_post_thumbnail( $postId )){          
  317.                 $thumb ='<a href="';
  318.                 $thumb .= $link;
  319.                 $thumb .= '" >';
  320.                 $thumb .=  get_the_post_thumbnail($postId, array(50,50));
  321.                 $thumb .=  '</a>'; 
  322.                             }                      
  323.             }
  324.            
  325.             if(get_post_meta( $postId, "_MyDomainListIsPremium", true )=="Y")
  326.                 $class = "mdlp_css_premium";
  327.  
  328.                         $name = $thumb . '<a href="'.trim($link).'" target="_blank" class="'.$class.'">'. get_the_title($postId).'</a>';
  329.             $asLink = $this->getOption("NameAsLink");
  330.                         if($asLink=="false"){
  331.                    $name = $thumb . ' '. get_the_title($postId);
  332.             }
  333.  
  334.             return $name;
  335.            
  336.                
  337.         }
  338.        
  339.         /**
  340.          * This function returns the domain category and link
  341.          *
  342.          * @param $posId integer Post ID
  343.          *
  344.          * @return null
  345.          */    
  346.         function show_domain_category($postId){        
  347.                    
  348.             return the_terms( $postId, self::TAXONOMY, '', ', ', '' );     
  349.         }
  350. /**
  351.          * This function retrieve the domain category as an array
  352.          *
  353.          * @param $posId integer Post ID
  354.          *
  355.          * @return array of categories
  356.          */
  357.    
  358.         function retrieve_domain_category($postId){
  359.                        $terms =  get_the_terms( $postId, self::TAXONOMY ); 
  360.  
  361. if ( $terms && ! is_wp_error( $terms ) ){
  362.  
  363.     $draught_links = array();
  364.  
  365.     foreach ( $terms as $term ) {
  366.         $draught_links[] = $term->name;
  367.     }
  368.                        
  369.     return $draught_links;
  370. }
  371.         }
  372.  
  373. /**
  374.          * This function returns the domain description
  375.          *
  376.          * @param $posId integer Post ID
  377.          *
  378.          * @return null
  379.          */
  380.         function show_domain_desc($postId) {
  381.             $content_post = get_post($postId);
  382.             return $content_post->post_content;
  383.                 }
  384.        
  385.         /**
  386.          * This function returns the buy button from the selected payment service
  387.          *
  388.          * @param $posId integer Post ID
  389.          *
  390.          * @return null
  391.          */
  392.         function show_buy_button($postId){                 
  393.             $html = get_post_meta( $postId, "_MyDomainListHTMLCode", true );
  394.             if(!$html)
  395.                 $html="";
  396.                         return html_entity_decode($html);          
  397.         }
  398.        
  399.         /**
  400.          * This function returns the offer button
  401.          *
  402.          * @param $posId integer Post ID
  403.          *
  404.          * @return null
  405.          */
  406.         function show_offer_button($postId){           
  407.             $price = get_post_meta( $postId, "_MyDomainListPrice", true );
  408.             $name = get_post_meta( $postId, "_MyDomainListName", true );
  409. $key = $this->getOption("TableCurrency");
  410.                         $price = $this->currency_format($price, $key);
  411.             if (empty($price)){
  412.                 $price = 0.00; 
  413.             }
  414.            
  415.             return  '<input type="button" id="mdlp_btn_offer_'.$postId.'" value="Make Offer" name="'. $price .'|'. $name .'" class="myDomainListProMakeOfferButton" />';
  416.         }
  417.        
  418.         /**
  419.                          * This function returns the domain price
  420.                          *
  421.                          * @param $posId integer Post ID
  422.                          *
  423.                          * @return null
  424.                          */
  425.         function show_domain_price($postId, $showOffer = false){
  426.                             $price =  get_post_meta( $postId, "_MyDomainListPrice", true );
  427.                             if (empty($price)){
  428.                                 $price = 0.00;
  429.                             }
  430.                             $key = $this->getOption("TableCurrency");
  431.                             $symbol = $this->currencies[$key];
  432.  
  433.                             $price = $this->currency_format($price, $key);
  434.                             if($showOffer) {
  435.                                 return $symbol. $price.$this->show_domain_offers(get_post_meta( $postId, "_MyDomainListName", true ));
  436. }
  437.     return $symbol. $price;
  438.                         }
  439.  
  440.  
  441. /**
  442.                          * This function returns the domain price
  443.                          *
  444.                          * @param $name string Domain Name
  445.                          *
  446.                          * @return null
  447.                          */
  448. function show_domain_offers($name){                                
  449.                             global $wpdb;
  450.                             $mdlp_offer_table_name = $wpdb->prefix . "mydomainlistpro_offer";
  451.                                                
  452.                             $offers = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(name) FROM %s WHERE name %s", $mdlp_offer_table_name, $name ) );                    
  453.                             if($offers)
  454.                                 return '<div class="mdlp_css_OfferCountBackground" title="# offers - see in WPDashboard">'.$offers.'</div> ';
  455.                            
  456.                             return;
  457.                         }
  458.                        
  459.     /**
  460.                          * This function returns the domain price currency only
  461.                          *
  462.                          *
  463.                          * @return null
  464.                          */
  465.                         function show_domain_currency(){
  466.                                
  467.                             $key = $this->getOption("TableCurrency");
  468.                             $symbol = $this->currencies[$key];
  469.    
  470.                             return $symbol;
  471.                         }
  472.        
  473.        
  474. /**
  475.          * This function returns created date
  476.          *
  477.          * @param $posId integer Post ID
  478.          *
  479.          * @return expiration date div
  480.          */
  481.         public function show_domain_date($postId, $type='Expires') {
  482.                     $tag = "_MyDomainListDate".$type;
  483.                     $tag1 = "_MyDomainList".$type;
  484.             $cDate = get_post_meta( $postId, $tag, true );
  485.             if(empty($cDate)){
  486.             $cDate = get_post_meta( $postId, $tag1, true );
  487.             }
  488.                     return $cDate;
  489.        
  490.         }
  491. /**
  492.          * This function returns text if Domain is marked as Premium in Domain Post
  493.          *
  494.          * @param $posId integer Post ID
  495.          *
  496.          * @return Premium text
  497.          */
  498.                 public function show_premium_text($postId, $displayText='* this is a premium domain'){
  499.                    $text = "";                  
  500.                    if(get_post_meta( $postId , '_MyDomainListIsPremium' , true )=="Y"){
  501.                            $text = $displayText;
  502.                    }
  503.                    return $text;
  504.                 }
  505.         /**
  506.          * This function return expiration date and tag
  507.          *
  508.          * @param $posId integer Post ID
  509.          *
  510.          * @return expiration date div
  511.          */
  512.         public function show_domain_expire_date($postId) {
  513.             //$exp_date = get_post_meta( $postId, "_MyDomainListExpires", true );
  514.                       $exp_date = $this->show_domain_date($postId, 'Expires');
  515.             $expirationNotification ="";
  516.            
  517.             if (empty($exp_date))
  518.              return "";
  519.              
  520.            if(($exp_date !="0000-00-00")){
  521.             $todays_date = date("Y-m-d");
  522.             $today = strtotime($todays_date);
  523.             $expiration_date = strtotime($exp_date);
  524.             $difference = $expiration_date - $today;
  525.             if ($difference < 0) { $difference = 0; }
  526.             $daysToExpire = floor($difference/60/60/24);
  527.            
  528.             if ($expiration_date < $today) {
  529.                 $expirationNotification = '<div class="mdlp_css_ExpiredBackground" title="domain expired">e</div>';
  530.             }else if ($daysToExpire == 0){
  531.                 $expirationNotification='<div class="mdlp_css_ExpiredBackground" title="domain expires today">!</div>';
  532.             }else if ($daysToExpire < 10){
  533.                 $expirationNotification='<div class="mdlp_css_Expired10Background" title="expires within 10 days">!</div>';
  534.             }else if ($daysToExpire < 30 ){
  535.                 $expirationNotification='<div class="mdlp_css_Expired30Background" title="expires within 30 days">!</div>';
  536.             }
  537.                  }
  538.             return $exp_date." ".$expirationNotification;
  539.         }
  540.    
  541.        
  542.        
  543.         /**
  544.          * This function initializes MyDomainListPlugin plugin action and filter hooks for the Admin panel
  545.          *
  546.          * @return null
  547.          */
  548.         private function add_admin_actions() {         
  549.             if ( is_admin() ){             
  550.                     add_action( 'admin_init', array($this, "initializeAdmin") );
  551.                                         add_action('admin_enqueue_scripts', array( $this, 'load_assets_admin'), 1 );
  552.  
  553.                     add_filter('admin_footer_text', array($this, "add_admin_footer"));         
  554.                     add_action('admin_menu', array($this, 'add_new_admin_redirect'));
  555.                     add_action('wp_ajax_my-domain-list-pro-dismiss-offer',  array("MyDomainListPluginProDashboard", "dismissOffer"));
  556.                     add_action('wp_ajax_nopriv_my-domain-list-pro-dismiss-offer',  array("MyDomainListPluginProDashboard", "dismissOffer"));
  557.  
  558.                     add_action('wp_dashboard_setup', array("MyDomainListPluginPro","add_dashboard_widget") );
  559.                     wp_localize_script( 'my-domain-list-ajax-request', 'my_domain_ajax_script', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); 
  560.  
  561. add_action('restrict_manage_posts',array($this, 'my_domain_restrict_manage_posts'));
  562. add_action( 'request', array($this, 'my_domain_request') );
  563.                
  564.                 }
  565.         }
  566.                
  567.        
  568.     /**
  569.          * Adds Domain specific rewrite rules.
  570.          *       
  571.          * @return void
  572.          */
  573.         public function filterRewriteRules( $wp_rewrite ) {
  574.             //if ( '' == get_option('permalink_structure') ) {
  575.                
  576.             //}
  577.  
  578.             $base = trailingslashit( $this->rewriteSlug );
  579.             $baseSingle = trailingslashit( $this->rewriteSlugSingular );
  580.             $baseTax = trailingslashit( $this->taxRewriteSlug );
  581.             $baseTax = "(.*)" . $baseTax;
  582.            
  583.             $newRules[$base . 'page/(\d+)'] = 'index.php?post_type=' . self::POSTTYPE;
  584.             $newRules[$baseTax . '([^/]+)/?$'] = 'index.php?post_type= ' . self::POSTTYPE;
  585.        
  586.             $wp_rewrite->rules = $newRules + $wp_rewrite->rules;   
  587.          
  588.        
  589.        
  590.         }
  591.        
  592.        
  593.         function create_submenu() {
  594.             //create custom post type menu
  595.             add_menu_page('Domain List Pro', 'Domain List Pro', 'administrator', 'mdlp_main_menu', 'mdlp_settings');
  596.        
  597.             //create submenu items
  598.             add_submenu_page('mdlp_main_menu', 'Add New', 'Add New', 'administrator', 'mdlp_sub_add_new',array("MyDomainListPluginProAdmin", "addAdminPage"));             
  599.             add_submenu_page('mdlp_main_menu', 'Customize', 'Customize', 'administrator', 'mdlp_sub_customize', array('MyDomainListPluginProAdmin', 'addAdminPage'));              
  600.         }
  601.        
  602.         /**
  603.          * This function checks if user is trying to access the Add New page and redirects it to Setting page
  604.          *
  605.          * @return redirect
  606.          */
  607.         function add_new_admin_redirect() {
  608.           $result = stripos($_SERVER['REQUEST_URI'], 'post-new.php?post_type='.self::POSTTYPE);      
  609.        
  610.           if ($result!==false) {
  611.             wp_redirect(get_option('siteurl') . '/wp-admin/admin.php?page=mdlp_sub_add_new');          
  612.              
  613.           }        
  614.         }
  615.        
  616.         /**
  617.          * This function removes the Add New option from the Menu
  618.          *
  619.          * @return null;
  620.          */
  621.         function remove_add_new_option(){
  622.             global $submenu;
  623.             unset($submenu['edit.php?post_type='.self::POSTTYPE][10]);         
  624.         }
  625.        
  626.         /**
  627.          * This function initializes MyDomainListPlugin plugin
  628.          *
  629.          * @return null
  630.          */
  631.         public function initialize() {
  632.                 $this->pluginName = __( 'My Domain List', $this->pluginDomain );   
  633.                 $this->rewriteSlugSingular = 'my-domain-list-pro-single';  
  634.                 $this->rewriteSlug =    'mdlp_my_domain_list';             
  635.                 $this->taxRewriteSlug = $this->rewriteSlug . '/' . __( 'mdlp_categories', $this->pluginDomain );                           
  636.  
  637.  
  638. global $wpdb;                      
  639.                           $mdlp_offer_table_name = $wpdb->prefix . "mydomainlistpro_offer";
  640.            
  641.             if($wpdb->get_var("SHOW TABLES LIKE '$mdlp_offer_table_name'") != $mdlp_offer_table_name) {
  642.                     $sql = "CREATE TABLE $mdlp_offer_table_name (
  643.                         id int(11) NOT NULL AUTO_INCREMENT,
  644.                         postID int(11) NOT NULL,
  645.                         name VARCHAR(200) NOT NULL,
  646.                         email VARCHAR(80) NOT NULL,
  647.                         price int(2) NOT NULL,
  648.                         comments TEXT,          
  649.                         currency VARCHAR(3),
  650.                         updated_at DATETIME NOT NULL,
  651.                                PRIMARY KEY (id)
  652.                        
  653.                     );";
  654.                     require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  655.                     dbDelta($sql);
  656.                 }  
  657.                
  658.  
  659.                 $this->create_post_type();                 
  660.         }
  661.  
  662.  
  663.         public function create_post_type() {
  664.             $this->get_post_type_labels();
  665.             register_post_type(self::POSTTYPE, $this->postTypeArgs);                   
  666.             register_taxonomy( self::TAXONOMY, self::POSTTYPE, array(
  667.                 'hierarchical' => true,
  668.                 'update_count_callback' => '',
  669.                 'query_var'=>true,
  670.                 'rewrite' => false,
  671.                 //'rewrite' => array('slug'=> $this->taxRewriteSlug),
  672.                 'public' => true,
  673.                 'show_ui' => true,
  674.                 'has_archive' => true,
  675.                 'labels' => $this->taxonomyLabels
  676.             ));
  677.                
  678.         }
  679.        
  680.        
  681.         private function get_post_type_labels() {
  682.             $this->postTypeArgs['labels'] = array(
  683.                 'name' => __('My Domain', $this->pluginDomain),
  684.                 'singular_name' => __('My Domain List', $this->pluginDomain),
  685.                 'add_new' => __('Add New', $this->pluginDomain),
  686.                 'add_new_item' => __('Add New Domain', $this->pluginDomain),
  687.                 'edit_item' => __('Edit My Domain List', $this->pluginDomain),
  688.                 'new_item' => __('New My Domain', $this->pluginDomain),
  689.                 'view_item' => __('View My Domain List', $this->pluginDomain),
  690.                 'search_items' => __('Search My Domains List', $this->pluginDomain),
  691.                 'not_found' => __('No domains found', $this->pluginDomain),
  692.                 'not_found_in_trash' => __('No domains found in Trash', $this->pluginDomain),
  693.                 'menu_name' => __('All Domains', $this->pluginDomain),
  694.                 'parent_item_colon' => ''
  695.             );             
  696.            
  697.             $this->taxonomyLabels = array(
  698.                 'name' =>  __( 'Categories', $this->pluginDomain ),
  699.                 'singular_name' =>  __( 'My Domain List Category', $this->pluginDomain ),
  700.                 'search_items' =>  __( 'Search My Domain List Categories', $this->pluginDomain ),
  701.                 'all_items' => __( 'All My Domain List Categories', $this->pluginDomain ),
  702.                 'parent_item' =>  __( 'Parent My Domain List Category', $this->pluginDomain ),
  703.                 'parent_item_colon' =>  __( 'Parent My Domain List Category:', $this->pluginDomain ),
  704.                 'edit_item' =>   __( 'Edit My Domain List Category', $this->pluginDomain ),
  705.                 'update_item' =>  __( 'Update My Domain List Category', $this->pluginDomain ),
  706.                 'add_new_item' =>  __( 'Add New My Domain List Category', $this->pluginDomain ),
  707.                 'new_item_name' =>  __( 'New My Domain List Category Name', $this->pluginDomain )              
  708.             );
  709.            
  710.            
  711.  
  712.         }
  713.    
  714.        
  715.         function save_my_domain_postdata($postId ) {
  716.             global $_POST;
  717.            
  718.            
  719.             // verify this came from the our screen and with proper authorization, 
  720.             if ( $post->post_type != self::POSTTYPE ) {
  721.                 //return;
  722.             }          
  723.             if ( wp_is_post_autosave( $postId ) || $post->post_status == 'auto-draft' || isset($_GET['bulk_edit']) || $_REQUEST['action'] == 'inline-save' ) {
  724.                 //return;
  725.             }
  726.            
  727.             remove_action( 'save_post', array( $this, 'save_my_domain_postdata' ) );
  728.        
  729.             //update meta fields
  730.             foreach ( $this->metaTags as $tag ) {
  731.                 $htmlElement = ltrim( $tag, '_' );
  732.                
  733.                 if ( isset( $_POST[$htmlElement] ) ) {             
  734.                     if ( is_string($_POST[$htmlElement]) )
  735.                         $_POST[$htmlElement] = filter_var($_POST[$htmlElement], FILTER_SANITIZE_STRING);
  736.                    
  737.                     $meta_value =$_POST[$htmlElement];
  738.                     if($htmlElement =='_MyDomainListShowOfferButton') {
  739.                         if(empty($meta_value)) $meta_value ='N';
  740.                     }
  741.                     update_post_meta( $postId, $tag, $_POST[$htmlElement] );
  742.                 }
  743.             }
  744.         }
  745.    
  746.  
  747. /**
  748.                          * This function display Custom Post Type fields in Quick Edit
  749.                          *
  750.                          * @return null
  751.                          */
  752. function show_quick_edit( $col, $type ) {
  753.             if( $type == self::POSTTYPE  && did_action('quick_edit_custom_box') === 1){ ?>
  754.     <fieldset class="inline-edit-col-left">
  755.         <div class="inline-edit-col">
  756.             <div class="inline-edit-group">
  757.                 <label class="inline-edit-status alignleft"> <span
  758.                     style="width: 40%; font: italic 12px Georgia, serif;">Domain Price:
  759.                     <?php echo $this->show_domain_currency();?> </span> <input
  760.                     id="_MyDomainListPriceEdit" type="text"
  761.                     name="_MyDomainListPriceEdit" value="" size="5" /> </label> <input
  762.                     type="hidden" name="is_quickedit" value="true" />
  763.             </div>
  764.         </div>
  765.     </fieldset>
  766.                     <?php } else {
  767.                         return;
  768.                     }
  769.                         }
  770.    
  771.    
  772.                         /**
  773.                          * This function gets current value of Custom Post Type field in Quick Edit
  774.                          * It uses ajax to pull data from the server via the my-domain-list-admin-edit.php file
  775.                          *
  776.                          * @return null
  777.                          */
  778.                         function get_quick_edit_data() {
  779.                             ?>
  780.     <script type="text/javascript">
  781.       jQuery(document).ready(function() {    
  782.         jQuery("a.editinline").live("click", function() {    
  783.           var mdlp_action_url = "<?php echo $this->pluginUrl  ?>my-domain-list-admin-edit.php";    
  784.              
  785.              var mdlp_post_id = inlineEditPost.getId(this);
  786.               if(mdlp_post_id){
  787.           jQuery.post(mdlp_action_url,
  788.                 { mdlp_js_post_id: mdlp_post_id },
  789.                     function(data){jQuery("#_MyDomainListPriceEdit").val(data); }
  790.                 );
  791.               }
  792.           });
  793.         });
  794.      
  795.     </script>
  796.                             <?php }
  797.    
  798.    
  799.                             /**
  800.                              * This function saves value of Custom Post Type field in Quick Edit to the appropriate WP MetaData
  801.                              *
  802.                              *
  803.                              * @return null
  804.                              */
  805.                             function save_quick_edit_data($post_id, $post) {
  806.                                 if( $post->post_type != self::POSTTYPE ) return;
  807.                                 if (isset($_POST['is_quickedit']))
  808.                                 update_post_meta($post_id, '_MyDomainListPrice', $_POST['_MyDomainListPriceEdit']);
  809.                             }
  810.    
  811.  
  812.         /**
  813.          * This function displays custom data from my domain list post type
  814.          *
  815.          * @return null
  816.          */
  817.         function custom_my_domain_list_columns($column) {
  818.             global $post;
  819.        
  820.             switch ($column) {
  821.                case "_MyDomainListOwner":
  822.                  echo get_post_meta( $post->ID , '_MyDomainListOwner' , true );
  823.                 break;
  824.                 case "_MyDomainListCreated":
  825.               //echo get_post_meta( $post->ID , '_MyDomainListCreated' , true );
  826.                                 echo $this->show_domain_date( $post->ID , 'Created');
  827.                 break;
  828.                 case "_MyDomainListExpires":                   
  829.                     echo $this->show_domain_expire_date($post->ID);              
  830.                 break;
  831.                case "_MyDomainListRegistrar":
  832.                  echo get_post_meta( $post->ID , '_MyDomainListRegistrar' , true );
  833.                 break;
  834.                case "_MyDomainListPrice":
  835.                  echo $this->show_domain_price($post->ID, true);
  836.                break;
  837.                case "_MyDomainListCategories":     
  838.                     //$cats = get_the_term_list($post->ID, self::TAXONOMY, '', ', ', '' );                 
  839.                     //echo ( $cats ) ? strip_tags( $cats ) : '—';                                    
  840.                     echo $this->show_domain_category($post->ID);   
  841.                    
  842.                 break;
  843.             }
  844.         }
  845.            
  846.        
  847.         function edit_my_domain_list_columns($column){     
  848.             $columns = array(
  849.             "cb" => "<input type=\"checkbox\" />",
  850.             "title" => "Name",         
  851.             "_MyDomainListRegistrar" => "Registrar",
  852.             "_MyDomainListOwner" => "Owner",
  853.             "_MyDomainListCreated" => "Created",
  854.             "_MyDomainListExpires" => "Expires",
  855.             "_MyDomainListPrice"=>"Price",
  856.             "_MyDomainListCategories"=>"Categories"
  857.             );
  858.         return $columns;       
  859.         }
  860.  
  861.  
  862.         function my_domain_restrict_manage_posts() {
  863.             global $typenow;
  864.             global $wp_query;
  865.             if ($typenow==self::POSTTYPE){
  866.                          $args = array(
  867.                              'show_option_all' => "Show All Categories",
  868.                              'taxonomy'        => self::TAXONOMY,
  869.                              'name'               => self::TAXONOMY,
  870.  'orderby'         =>  'name',
  871.             'selected'        =>  get_term_by('name', $wp_query->query[self::TAXONOMY], self::TAXONOMY)->term_id,
  872. 'id'                 => '',
  873.             'hierarchical'    =>  true,
  874.             'depth'           =>  1,
  875.             'show_count'      =>  true, // Show # listings in parens
  876.             'hide_empty'      =>  true,
  877.  
  878.  
  879.                          );
  880.                 wp_dropdown_categories($args);
  881.                         }
  882.         }
  883.  
  884.                function my_domain_request($request) {
  885.  
  886.                   if (is_admin() && $GLOBALS['PHP_SELF'] == '/wp-admin/edit.php' && isset($request['post_type']) && $request['post_type']==self::POSTTYPE) {                       
  887.             $request[self::TAXONOMY] = get_term($request[self::TAXONOMY],self::TAXONOMY)->slug;        
  888.              }
  889.               return $request;
  890.                }
  891.  
  892.  
  893.         /**
  894.          * This function initializes js necessary to be used in the Admin  page as well as metaboxes
  895.          *
  896.          * @return null
  897.          */
  898.         function initializeAdmin() {
  899.             wp_register_script( 'my-domain-list-pro_1', plugins_url('/js/my-domain-list-pro-js-script.js', __FILE__), array('jquery'));
  900.             wp_enqueue_script('my-domain-list-pro_1');         
  901.             wp_register_script( 'my-domain-list-pro_4', plugins_url('/js/jscolor.js', __FILE__),  array('jquery'));
  902.             wp_enqueue_script('my-domain-list-pro_4');  
  903.             add_meta_box( 'My Domain List Details', $this->pluginName, array( $this, 'create_meta_boxes' ), self::POSTTYPE, 'normal', 'high' );
  904.         }
  905.    
  906.         /**
  907.          * This function creates the metaboxes boxes. It calls the metabox file for the form data
  908.          *
  909.          * @return null
  910.          */
  911.         public function create_meta_boxes() {
  912.             global $post;
  913.             $postId = $post->ID;
  914.             foreach ( $this->metaTags as $tag ) {
  915.  
  916.                 $$tag = get_post_meta( $postId, $tag, true );
  917.                 if($tag =='_MyDomainListShowOfferButton') {
  918.                     if(empty($$tag)) $$tag ='N';
  919.                 }
  920.                
  921.                 if ( $postId && isset($_GET['post']) && $_GET['post'] ) { //if there is a post AND the post has been saved at least once.                                                                                                                          
  922.                                        
  923.                                          if(!update_post_meta($postId, $tag, htmlentities($$tag, ENT_QUOTES), true)){
  924.                                            /*echo "Issue updating data";*/
  925.                                            }                             
  926.  
  927.                 } else {                                                                   
  928.                     update_post_meta($postId, $tag, htmlentities($$tag, ENT_QUOTES), true);                    
  929.                 }
  930.             }
  931.             $showOfferButton = '';                 
  932.             if(get_post_meta( $postId, "_MyDomainListShowOfferButton", true )=="Y"){
  933.                 $showOfferButton = " selected";
  934.                         }
  935.             $isPremium="";
  936.             if(get_post_meta( $postId, "_MyDomainListIsPremium", true )=="Y"){
  937.                
  938. $isPremium=" selected";
  939.                
  940.             }
  941.                                                
  942.             include( $this->pluginPath . 'my-domain-list-pro-metabox.php' );
  943.            
  944.         }
  945.    
  946.         /**
  947.          * This function creates the select box for the currency
  948.          *
  949.          * @return null
  950.          */
  951.         function show_currency_options(){
  952.            
  953.             $optionHTML = '<select name="my_domain_list_pro_currency" id="my_domain_list_pro_currency">';
  954.             foreach($this->currencies as $currencyKey => $currencyValue){
  955.                     $currencySelectOptionSelected =($currencyKey==$this->getOption("TableCurrency"))?' selected ':'';
  956.                     $optionHTML .= '<option value="'.$currencyKey.'" '. $currencySelectOptionSelected.'>';
  957.                     $optionHTML .= $currencyKey;
  958.                     $optionHTML .= '</option>';
  959.                 }
  960.             return  $optionHTML;       
  961.         }      
  962.  
  963.    
  964.         /**
  965.          * add_dashboard_widget
  966.          *
  967.          * This function creates the function used in the action hook for the dashboard widget
  968.          *
  969.          * return null
  970.          */
  971.         function add_dashboard_widget() {
  972.            
  973.             wp_add_dashboard_widget('my_domain_list_pro_dashboard_widget', 'My Domain List Pro Offers', array("MyDomainListPluginProDashboard","dashboard_widget_output"));
  974.            
  975.         }
  976.  
  977. /**
  978.      * This function processes the domain offer information into the database.
  979.      *
  980.      * @return message to user with information (name and price) about the offer.
  981.      */
  982.     function process_offer(){
  983.         global $mdlp;
  984.         global $wpdb;      
  985.         //Verifies the AJAX request to prevent processing requests external of the blog.
  986.         check_ajax_referer( "my_domain_list_pro_make_offer_content_key" );     
  987.         $myDomainListOfferData = $_REQUEST[ 'attr' ];
  988.         $myDomainListNameValue = $myDomainListOfferData[name];
  989.         $myDomainListPriceValue = $myDomainListOfferData[price];
  990.         $myDomainListEmailValue = $myDomainListOfferData[email];
  991.         $myDomainListCommentsValue = $myDomainListOfferData[comments];
  992.         $myDomainListCurrencyValue = $myDomainListOfferData[currency];
  993.        
  994.         $my_domain_list_offer_table_name = $wpdb->prefix . "mydomainlistpro_offer";
  995.         $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 )",                
  996.         $myDomainListNameValue,
  997.         $myDomainListEmailValue,
  998.         $myDomainListCommentsValue,
  999.         $myDomainListPriceValue,
  1000.         $myDomainListCurrencyValue,
  1001.         date("Y/m/d")
  1002.         );  //end query
  1003.  
  1004.         if ($wpdb->query($query) === FALSE) {
  1005.             $return =  new WP_Error('offer_insert_error', __('There has been a problem, please contact the website admin directly to make an offer.'));
  1006.         }
  1007.        
  1008.         if ( is_wp_error($return) ) {
  1009.             echo $return->get_error_message();
  1010.         }else{                     
  1011.             echo "Your offer of ".self::show_domain_currency() .$myDomainListPriceValue ." for ". $myDomainListNameValue . " has been submitted.";
  1012.                         $p = $myDomainListPriceValue.' '.$myDomainListCurrencyValue;
  1013.                         $args = array("domain" => $myDomainListNameValue, "price"=> $p);
  1014.                         self::notify($args);
  1015.         }
  1016.         die();
  1017.     }
  1018.  
  1019. /**
  1020.          * This function prepares data to call send email
  1021.          *
  1022.          * @return null
  1023.          */
  1024.         function notify($args= array()){                                   
  1025.             $sender = "Admin";
  1026.                         $rec = get_bloginfo('admin_email');
  1027.             $recipients = self::get_recipients($rec);
  1028.             $subject = "An offer has been made on your domain";
  1029.             $type = 'Default';
  1030.             $body = 'Good News! An offer has been make on '. $args["domain"].' for '.$args["price"].'. Login to your Wordpress Dashboard to find out more.';
  1031.                    
  1032.             self::send_mail($recipients, $rec, $sender,  $subject,  $body,  $type, $args);
  1033.         }
  1034.  
  1035. /**
  1036.          * This function will return the recipient email(s)
  1037.          *
  1038.          * @return null
  1039.          */
  1040.         function get_recipients($recipients){      
  1041.             if(empty($recipients)){
  1042.                 return "";
  1043.             }  
  1044.            
  1045.             if(is_array($recipients)){
  1046.                 return implode(",", $recipients);
  1047.             }
  1048.  
  1049.             return (string) $recipients;
  1050.         }
  1051.  
  1052.  
  1053. /**
  1054.          * This function sends email
  1055.          *
  1056.          * Returns number of recipients addressed in emails or false on internal error.
  1057.          */
  1058.         function send_mail($recipients, $sender_email, $sender_name, $subject = '', $message = '', $type = 'plaintext', $args) {                       
  1059.                  
  1060.             $headers  = "From: \"$sender_name\" <$sender_email>\n";
  1061.             $headers .= "Return-Path: <" . $sender_email . ">\n";
  1062.             $headers .= "Reply-To: \"" . $sender_name . "\" <" . $sender_email . ">\n";
  1063.             $headers .= "X-Mailer: PHP" . phpversion() . "\n";
  1064.        
  1065.             $subject = stripslashes($subject);
  1066.             $message = stripslashes($message);                 
  1067.  
  1068.             if ('html' == $type) {
  1069.                 $headers .= "MIME-Version: 1.0\n";
  1070.                 $headers .= "Content-Type: " . get_bloginfo('html_type') . "; charset=\"". get_bloginfo('charset') . "\"\n";
  1071.                 $body = "<html><head><title>" . $subject . "</title></head><body>" . $message . "</body></html>";
  1072.             } else {
  1073.                 $headers .= "MIME-Version: 1.0\n";
  1074.                 $headers .= "Content-Type: text/plain; charset=\"". get_bloginfo('charset') . "\"\n";
  1075.                 $message = preg_replace('|&[^a][^m][^p].{0,3};|', '', $message);
  1076.                 $message = preg_replace('|&amp;|', '&', $message);
  1077.                 $body = wordwrap(strip_tags($message), 80, "\n");                  
  1078.             }
  1079.  
  1080.             if(!empty($args)){
  1081.                 $b= '';
  1082.                 foreach($args as $key => $value){
  1083.                     if($key=="recipients"){
  1084.                         $recipients = $value;
  1085.                     }else{
  1086.                         $b = str_replace("%".$key."%", $value , $body);
  1087.                         $body  = $b;
  1088.                     }
  1089.                 }                          
  1090.             }
  1091.            
  1092.             if ( (empty($recipients)) ) { return false; }
  1093.                
  1094.             //$headers .= "To: " . implode(',', $recipients) . "\n\n";
  1095.             $headers .= "To: " . $recipients . "\n\n";                 
  1096.             if(@wp_mail($recipients, $subject, $body, $headers)){
  1097.            
  1098.                 return true;
  1099.             }                      
  1100.             echo "\n*Error notifying Admin of the offer, please contact site owner directly.";
  1101.             return false;
  1102.         }
  1103.  
  1104.  
  1105.         /**
  1106.          * activate
  1107.          *
  1108.          * This function creates settings options (settings) entries in wp_options and mydomainlist table in mysql
  1109.          * return null
  1110.          */
  1111.         public function activate() {
  1112.                $myDomainListSettingsData = array(
  1113.                      'mdlp_opt_Color'=>'ffffff',
  1114.              'mdlp_opt_BackgroundColor'=>'000000',
  1115.                      'mdlp_opt_Pages'=>'',               
  1116.                          'mdlp_opt_TableSize'=>'small',
  1117.                      'mdlp_opt_TableShow'=>'all',
  1118.                          'mdlp_opt_TableFilter'=>'None',
  1119.                  'mdlp_opt_PaginationType' => 'Numbers',
  1120.              'mdlp_opt_TableCurrency' =>'USD',
  1121.                          'mdlp_opt_NameAsLink'=>'true'
  1122.                  );
  1123.                  add_option(self::OPTIONNAME, $myDomainListSettingsData);                          
  1124.         }
  1125.  
  1126.         /**
  1127.          * deactivate
  1128.          *
  1129.          * This function cleans up the entries (settings) created in the wp_options table in mysql.
  1130.          *
  1131.          */
  1132.         public function deactivate() {
  1133.             delete_option(self::OPTIONNAME);
  1134.             $this->flushRewriteRules();
  1135.         }
  1136.  
  1137.         /**
  1138.          * uninstall
  1139.          *
  1140.          * This function drops the mydomainlist table in mysql. Domains will no longer be available
  1141.          *
  1142.          */
  1143.         public function uninstall(){
  1144.             global $wpdb;          
  1145.             $mydomainlistoffertable = $wpdb->prefix."mydomainlistpro_offer";
  1146.             $wpdb->query("DROP TABLE IF EXISTS $mydomainlistoffertable");
  1147.         }
  1148.  
  1149.         /**
  1150.          * Flush rewrite rules to support custom links
  1151.          *
  1152.          * @link http://codex.wordpress.org/Custom_Queries#Permalinks_for_Custom_Archives
  1153.          */
  1154.         public function flushRewriteRules() {
  1155.             global $wp_rewrite;
  1156.             $wp_rewrite->flush_rules();
  1157.             // in case this was called too early, let's get it in the end.
  1158.             add_action('shutdown', array($this, 'flushRewriteRules'));
  1159.         }              
  1160.  
  1161.         /**
  1162.          * This function disables the browser from caching the data
  1163.          *
  1164.          * @return null
  1165.          */
  1166.         public function disableBrowserCache() {
  1167.             header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
  1168.             header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  1169.             header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
  1170.             header("Cache-Control: post-check=0, pre-check=0", false);
  1171.             header("Pragma: no-cache");
  1172.         }
  1173.  
  1174.  
  1175.         /**
  1176.          * load_assets for admin pages only
  1177.          *
  1178.          * This function loads the necessary css and js files needed to support the plugin admin pages.
  1179.          *
  1180.          */
  1181.                 public function load_assets_admin(){
  1182.                        wp_enqueue_script('jquery');
  1183.            
  1184.  
  1185.             $css_url = WP_PLUGIN_URL.'/my-domain-list-pro/css/my-domain-list-pro_style.css';
  1186.             $css_file = WP_PLUGIN_DIR.'/my-domain-list-pro/css/my-domain-list-pro_style.css';
  1187.            
  1188.             if (file_exists($css_file)) {
  1189.                 wp_register_style('my-domain-list-pro_stylesheet', $css_url);
  1190.                 wp_enqueue_style('my-domain-list-pro_stylesheet');
  1191.             }          
  1192.                  }
  1193.         /**
  1194.          * load_assets
  1195.          *
  1196.          * This function loads the necessary javascript and css files needed to support the plugin - front end pages.
  1197.          *
  1198.          */
  1199.         public function load_assets() {                
  1200.  
  1201.             wp_enqueue_script('jquery');
  1202.             wp_register_script( 'my-domain-list-pro_0', plugins_url('/js/my-domain-list-pro-js-tablesorter.js', __FILE__),  array('jquery'));
  1203.             wp_enqueue_script('my-domain-list-pro_0');
  1204.  
  1205.             wp_register_script( 'my-domain-list-pro_2', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js');
  1206.             wp_enqueue_script( 'my-domain-list-pro_2' );
  1207.            
  1208.  
  1209.             $css_url = WP_PLUGIN_URL.'/my-domain-list-pro/css/my-domain-list-pro_style.css';
  1210.             $css_file = WP_PLUGIN_DIR.'/my-domain-list-pro/css/my-domain-list-pro_style.css';
  1211.             $css_dialog_url = WP_PLUGIN_URL.'/my-domain-list-pro/css/my-domain-list-pro_dialog.css';
  1212.             $css_dialog_file = WP_PLUGIN_DIR.'/my-domain-list-pro/css/my-domain-list_dialog.css';
  1213.            
  1214.  
  1215.             if (file_exists($css_file)) {
  1216.                 wp_register_style('my-domain-list-pro_stylesheet', $css_url);
  1217.                 wp_enqueue_style('my-domain-list-pro_stylesheet');
  1218.             }
  1219.             if (file_exists($css_dialog_file)) {
  1220.                    
  1221.                 wp_register_style('my-domain-list-pro_dialog_stylesheet', $css_dialog_url);
  1222.                 wp_enqueue_style('my-domain-list-pro_dialog_stylesheet');
  1223.             }
  1224.  
  1225.         }
  1226.  
  1227.         /**
  1228.          * properCase
  1229.          *
  1230.          * This function converts a string into its proper case format.
  1231.          *
  1232.          * @param    string   $string    Any string value
  1233.          * @return   string   String formatted in proper case
  1234.          */
  1235.         public function properCase($string){
  1236.             $string = strtolower($string);
  1237.             return substr_replace($string, strtoupper(substr($string, 0, 1)), 0, 1);
  1238.         }
  1239.            
  1240.         /**
  1241.          * saveOptions
  1242.          *
  1243.          * This function saves data into the options table
  1244.          *
  1245.          * @param    array   $opts
  1246.          * @return   null
  1247.          */
  1248.           public function saveOptions($options) {
  1249.                 if (!is_array($options)) {
  1250.                     return;
  1251.                 }
  1252.                 if ( update_option(self::OPTIONNAME, $options) ) {
  1253.                     $this->latestOptions = $options;
  1254.                 } else {
  1255.                     $this->latestOptions = $this->getOptions();
  1256.                 }
  1257.             }
  1258.        
  1259.         /**
  1260.          * saveShortCodeOptions
  1261.          *
  1262.          * This function saves the shortcode data into shortcodeOptions property
  1263.          *
  1264.          * @param    array   $opts
  1265.          * @return   null
  1266.          */
  1267.         public function saveShortCodeOptions ($options){
  1268.             if (!is_array($options)) {
  1269.                 return;
  1270.             }
  1271.             $this->shortcodeOptions = $options;
  1272.         }
  1273.  
  1274.         /**
  1275.          * getShortcodeOptions
  1276.          *     
  1277.          * This function saves data into the shortcodeOptions property
  1278.          * @return   null
  1279.          */  
  1280.         public function getShortcodeOptions(){
  1281.             return $this->shortcodeOptions;
  1282.         }
  1283.        
  1284.         /**
  1285.          * getOptions
  1286.          *     
  1287.          * This function saves data into the options table
  1288.          * @return   null
  1289.          */  
  1290.         public function getOptions() {        
  1291.             return get_option(self::OPTIONNAME, array());
  1292.         }
  1293.        
  1294.         /**
  1295.          * getOption
  1296.          *
  1297.          * @param    string   $optionName
  1298.          * @param    string   $default
  1299.          *
  1300.          * This function returns the option value requested. It also sets the default value if sent
  1301.          * @return   string option saved
  1302.          */  
  1303.         public function getOption($optionName, $default = '') {
  1304.             if( ! $optionName )
  1305.                 return null;           
  1306.    
  1307.             $options = $this->getOptions();
  1308.             $optionName = "mdlp_opt_".$optionName;
  1309.             return ( isset($options[$optionName]) ) ? $options[$optionName] : $default;
  1310.        
  1311.         }
  1312.        
  1313.         /**
  1314.          * getShortcodeOption
  1315.          *
  1316.          * @param    string   $optionName
  1317.          * @param    string   $default
  1318.          *
  1319.          * This function returns the shortcode value requested. It also sets the default value if sent
  1320.          * @return   string option saved
  1321.          */  
  1322.         public function getShortcodeOption($optionName, $default = '') {
  1323.             if( ! $optionName )
  1324.                 return null;   
  1325.                
  1326.             $options = $this->shortcodeOptions;                    
  1327.             if($optionName == 'size')
  1328.                 return ( isset($options[$optionName]) ) ? 'myDomainListTable'.$options[$optionName] : $default;
  1329.                
  1330.             if($optionName == 'show'){                                 
  1331.                  $cols = ( isset($options[$optionName]) ) ? $options[$optionName] : $default;              
  1332.                  if($cols=='all'){
  1333.                     return self::ALLCOLUMNS;
  1334.                  }else{
  1335.                     return preg_replace('/\s+/', '',$cols);
  1336.                  }
  1337.             }  
  1338.                
  1339.             return ( isset($options[$optionName]) ) ? $options[$optionName] : $default;            
  1340.         }
  1341.  
  1342.         /**
  1343.          * This functions sets the next tab index
  1344.          * @return void
  1345.          */
  1346.         public function tabIndex() {
  1347.             echo $this->tabIndexStart;
  1348.             $this->tabIndexStart++;
  1349.         }
  1350.    
  1351.         /**
  1352.          * This function gets the taxonomy name
  1353.          * @return string Taxonomy
  1354.          */
  1355.         public function get_taxonomy() {
  1356.                 return self::TAXONOMY;
  1357.         }
  1358.        
  1359.  
  1360. function currency_format($amount, $key ='USD', $precision = 0, $use_commas = true, $show_currency_symbol = false, $parentheses_for_negative_amounts = false)
  1361. {
  1362.     $amount = (float) $amount;
  1363.     // Get rid of negative zero
  1364.     $zero = round(0, $precision);
  1365.     if (round($amount, $precision) == $zero) {
  1366.         $amount = $zero;
  1367.     }
  1368.  
  1369.     if ($key=='BRL' || $key == 'EUR' || $key=='INR' || $key == 'JPY'){
  1370.          $use_commas = false;
  1371.     }
  1372.     if ($use_commas) {
  1373.         if ($parentheses_for_negative_amounts && ($amount < 0)) {
  1374.             $amount = '('.number_format(abs($amount), $precision).')';
  1375.         }
  1376.         else {
  1377.             $amount = number_format($amount, $precision);
  1378.         }
  1379.     }
  1380.     else {
  1381.         if ($parentheses_for_negative_amounts && ($amount < 0)) {
  1382.             $amount = '('.round(abs($amount), $precision).')';
  1383.         }
  1384.         else {
  1385.             $amount = number_format($amount, $precision, ',', '.');
  1386.         }
  1387.     }
  1388.    
  1389.     if ($show_currency_symbol) {
  1390.         $amount = '$'.$amount;  // Change this to use the organization's country's symbol in the future
  1391.     }
  1392.     return $amount;
  1393. }
  1394.  
  1395.     /**
  1396.          * This function displays page loading div on the page
  1397.          *
  1398.          * @return null
  1399.          */
  1400.         public function showPageLoadingIndicator(){
  1401.             ?>
  1402.                 <div id="mdlp_id_page-loading" style="display: none">
  1403.                 <img src="<?php echo  WP_PLUGIN_URL.'/my-domain-list-pro/img/ajax-loader.gif' ?>" />
  1404.                 </div>
  1405.             <?php
  1406.         }
  1407.  
  1408.        
  1409.     }//end class
  1410. }
  1411. global $mdlp;
  1412. $mdlp = new MyDomainListPluginPro;
  1413.  
  1414.  
  1415.  
  1416. ?>
Advertisement
Add Comment
Please, Sign In to add comment