Advertisement
Guest User

general_function

a guest
Nov 2nd, 2011
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.20 KB | None | 0 0
  1. <?php
  2. if (!class_exists('General'))
  3. {
  4.     class General
  5.     {
  6.         // Class initialization
  7.         function General()
  8.         {
  9.         }
  10.  
  11.         function get_general_settings()
  12.         {
  13.             global $wpdb;
  14.             $settingoptions = $wpdb->get_var("select option_value from $wpdb->options where option_name like 'mysite_general_settings'");
  15.             $option_value = unserialize($settingoptions);
  16.             $option_value['feature_catid'] = $this->get_category_by_cat_name(get_option('ptthemes_feature_catid'));
  17.             return $option_value;
  18.         }
  19.  
  20.         function get_site_emailId()
  21.         {
  22.             $generalinfo = get_option('mysite_general_settings');
  23.             if($generalinfo['site_email'] == '')
  24.             {
  25.                 return get_option('admin_email');
  26.             }else
  27.             {
  28.                 return $generalinfo['site_email'];
  29.             }
  30.         }
  31.  
  32.         function get_site_emailName()
  33.         {
  34.             $generalinfo = get_option('mysite_general_settings');
  35.             if($generalinfo['site_email_name'] == '')
  36.             {
  37.                 return get_option('blogname');
  38.             }else
  39.             {
  40.                 return $generalinfo['site_email_name'];
  41.             }
  42.         }
  43.  
  44.         function get_currency_symbol()
  45.         {
  46.             $generalinfo = get_option('mysite_general_settings');
  47.             if($generalinfo['currencysym'] == '')
  48.             {
  49.                 return '$';
  50.             }else
  51.             {
  52.                 return $generalinfo['currencysym'];
  53.             }
  54.         }
  55.  
  56.         function get_currency_code()
  57.         {
  58.             $generalinfo = get_option('mysite_general_settings');
  59.             if($generalinfo['currency'] == '')
  60.             {
  61.                 return 'USD';
  62.             }else
  63.             {
  64.                 return $generalinfo['currency'];
  65.             }
  66.         }
  67.  
  68.         function get_paypal_merchantID()
  69.         {
  70.             $generalinfo = get_option('mysite_general_settings');
  71.             if($generalinfo['paypal_merchantid'] == '')
  72.             {
  73.                 return get_option('admin_email');
  74.             }else
  75.             {
  76.                 return $generalinfo['paypal_merchantid'];
  77.             }
  78.         }
  79.  
  80.         function get_ads_default_status()
  81.         {
  82.             $generalinfo = get_option('mysite_general_settings');
  83.             if($generalinfo['approve_ads'] == '')
  84.             {
  85.                 return 'publish';
  86.             }else
  87.             {
  88.                 return $generalinfo['approve_ads'];
  89.             }
  90.         }
  91.  
  92.         function get_index_settings()
  93.         {
  94.             if(get_option('ptthemes_index_page_settings') == '')
  95.             {
  96.                 return 'index1.php';
  97.             }else
  98.             {
  99.                 return get_option('ptthemes_index_page_settings');
  100.             }
  101.         }
  102.  
  103.         function get_ads_alive_days()
  104.  
  105.         {
  106.  
  107.             $generalinfo = get_option('mysite_general_settings');
  108.  
  109.             if($generalinfo['ads_days'] == '')
  110.  
  111.             {
  112.  
  113.                 return '30';
  114.  
  115.             }else
  116.  
  117.             {
  118.  
  119.                 return $generalinfo['ads_days'];
  120.  
  121.             }
  122.  
  123.         }
  124.  
  125.         function get_blog_catid()
  126.         {
  127.  
  128.             $blog_catid = get_inc_categories("cat_exclude_");
  129.  
  130.             $blog_catid_array = explode(',',$blog_catid);
  131.  
  132.             $catid_array = array();
  133.  
  134.             for($i=0;$i<count($blog_catid_array);$i++)
  135.  
  136.             {
  137.  
  138.                 if($blog_catid_array[$i])
  139.  
  140.                 {
  141.  
  142.                     $catid_array[] = $blog_catid_array[$i];
  143.  
  144.                 }
  145.  
  146.             }
  147.  
  148.             return implode(',',$catid_array);
  149.  
  150.         }  
  151.  
  152.         function getCategoryList( $parent = 0, $level = 0, $categories = 0, $page = 1, $per_page = 1000 )
  153.  
  154.         {
  155.  
  156.             $count = 0;
  157.  
  158.        
  159.  
  160.             if ( empty($categories) )
  161.  
  162.             {
  163.  
  164.                 $args = array('hide_empty' => 0);
  165.  
  166.                 if ( !empty($_GET['s']) )
  167.  
  168.                     $args['search'] = $_GET['s'];
  169.  
  170.        
  171.  
  172.                 $categories = get_categories( $args );
  173.  
  174.                 if ( empty($categories) )
  175.  
  176.                     return false;
  177.  
  178.             }      
  179.  
  180.             $children = _get_term_hierarchy('category');
  181.  
  182.             return $this->_cat_rows1( $parent, $level, $categories, $children, $page, $per_page, $count );
  183.  
  184.         }
  185.  
  186.  
  187.  
  188.         function _cat_rows1( $parent = 0, $level = 0, $categories, &$children, $page = 1, $per_page = 20, &$count ) {
  189.  
  190.        
  191.  
  192.             global $category_array;
  193.  
  194.             $start = ($page - 1) * $per_page;
  195.  
  196.             $end = $start + $per_page;
  197.  
  198.             ob_start();
  199.  
  200.        
  201.  
  202.             foreach ( $categories as $key => $category ) {
  203.  
  204.                 if ( $count >= $end )
  205.  
  206.                     break;
  207.  
  208.        
  209.  
  210.                 if ( $category->parent != $parent && empty($_GET['s']) )
  211.  
  212.                     continue;
  213.  
  214.        
  215.  
  216.                 // If the page starts in a subtree, print the parents.
  217.  
  218.                 if ( $count == $start && $category->parent > 0 ) {
  219.  
  220.        
  221.  
  222.                     $my_parents = array();
  223.  
  224.                     $p = $category->parent;
  225.  
  226.                     while ( $p ) {
  227.  
  228.                         $my_parent = get_category( $p );
  229.  
  230.                         $my_parents[] = $my_parent;
  231.  
  232.                         if ( $my_parent->parent == 0 )
  233.  
  234.                             break;
  235.  
  236.                         $p = $my_parent->parent;
  237.  
  238.                     }
  239.  
  240.        
  241.  
  242.                     $num_parents = count($my_parents);
  243.  
  244.                     while( $my_parent = array_pop($my_parents) ) {
  245.  
  246.                         $category_array[] =$this-> _cat_row1( $my_parent, $level - $num_parents );
  247.  
  248.                         $num_parents--;
  249.  
  250.                     }
  251.  
  252.                 }
  253.  
  254.        
  255.  
  256.                 if ($count >= $start)
  257.  
  258.                 {
  259.  
  260.                     //$category_array[] = _cat_row( $category, $level );
  261.  
  262.                     $categoryinfo = array();
  263.  
  264.                     $category = get_category( $category, '', '' );
  265.  
  266.                     $default_cat_id = (int) get_option( 'default_category' );
  267.  
  268.                     $pad = str_repeat( '&#8212; ', max(0, $level) );
  269.  
  270.                     $name = ( $name_override ? $name_override : $pad . ' ' . $category->name );
  271.  
  272.                     $categoryinfo['ID'] = $category->term_id;
  273.  
  274.                     $categoryinfo['name'] = $name;
  275.  
  276.                     $category_array[] = $categoryinfo;
  277.  
  278.                 }
  279.  
  280.        
  281.  
  282.                 unset( $categories[ $key ] );
  283.  
  284.        
  285.  
  286.                 $count++;
  287.  
  288.        
  289.  
  290.                 if ( isset($children[$category->term_id]) )
  291.  
  292.                     $this->_cat_rows1( $category->term_id, $level + 1, $categories, $children, $page, $per_page, $count );
  293.  
  294.             }
  295.  
  296.        
  297.  
  298.             $output = ob_get_contents();
  299.  
  300.             ob_end_clean();
  301.  
  302.             return $category_array;
  303.  
  304.            
  305.  
  306.         }
  307.  
  308.        
  309.  
  310.         function get_category_dropdown_options($selectedId='',$exclude_cat='')
  311.  
  312.         {
  313.  
  314.             global $wpdb;
  315.  
  316.             $general_settings = $this->get_general_settings();
  317.  
  318.             $category_price_info = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'category_price_info'");
  319.  
  320.             $category_price_info_arr = unserialize($category_price_info);
  321.  
  322.             $category_array = array();
  323.  
  324.             $category_array = $this->getCategoryList();
  325.  
  326.             $option_str = '';
  327.  
  328.             $exclude_catarr = explode(',',$exclude_cat);
  329.  
  330.             for($i=0;$i<count($category_array);$i++)
  331.  
  332.             {
  333.  
  334.                 if(!in_array($category_array[$i]['ID'],$exclude_catarr))
  335.  
  336.                 {
  337.  
  338.                     $selected = '';
  339.  
  340.                     if($selectedId == $category_array[$i]['ID']){$selected="selected";};
  341.  
  342.                     $option_str .= '<option value="'.$category_array[$i]['ID'].'" '.$selected.'>'.$category_array[$i]['name'];
  343.  
  344.                     if($category_price_info_arr[$category_array[$i]['ID']])
  345.  
  346.                     {
  347.  
  348.                         $price = '';
  349.  
  350.                         $price = $category_price_info_arr[$category_array[$i]['ID']]-$general_settings['ads_price'];
  351.  
  352.                         if($price<0)
  353.  
  354.                         {
  355.  
  356.                             $price = '-'.$general_settings['currencysym'].abs($price);
  357.  
  358.                         }elseif($price>0)
  359.  
  360.                         {
  361.  
  362.                             $price = '+'.$general_settings['currencysym'].abs($price);
  363.  
  364.                         }
  365.  
  366.                         if($price)
  367.  
  368.                         {
  369.  
  370.                             $option_str .= ' ('.$price.')';
  371.  
  372.                         }
  373.  
  374.                     }
  375.  
  376.                     $option_str .= '</option>';            
  377.  
  378.                 }
  379.  
  380.             }
  381.  
  382.             return $option_str;
  383.  
  384.         }
  385.  
  386.        
  387.  
  388.         function get_category_price($termid)
  389.  
  390.         {
  391.  
  392.             global $wpdb;
  393.  
  394.             $category_price_info = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'category_price_info'");
  395.  
  396.             $category_price_info_arr = unserialize($category_price_info);
  397.  
  398.             return $category_price_info_arr[$termid];
  399.  
  400.         }
  401.  
  402.         function get_currency_sym()
  403.  
  404.         {
  405.  
  406.             global $wpdb;
  407.  
  408.             $settingoptions = $wpdb->get_var("select option_value from $wpdb->options where option_name like 'mysite_general_settings'");
  409.  
  410.             $option_value = unserialize($settingoptions);
  411.  
  412.             return $option_value['currencysym'];
  413.  
  414.         }
  415.  
  416.         function get_featured_price()
  417.  
  418.         {
  419.  
  420.             global $wpdb;
  421.  
  422.             $settingoptions = $wpdb->get_var("select option_value from $wpdb->options where option_name like 'mysite_general_settings'");
  423.  
  424.             $option_value = unserialize($settingoptions);
  425.  
  426.             return number_format($option_value['feature_ads_price'],2);
  427.  
  428.         }
  429.  
  430.        
  431.  
  432.         function sendEmail($fromEmail,$fromEmailName,$toEmail,$toEmailName,$subject,$message,$extra='')
  433.  
  434.         {
  435.  
  436.             $headers  = 'MIME-Version: 1.0' . "\r\n";
  437.  
  438.             $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
  439.  
  440.            
  441.  
  442.             // Additional headers
  443.  
  444.             $headers .= 'To: '.$toEmailName.' <'.$toEmail.'>' . "\r\n";
  445.  
  446.             $headers .= 'From: '.$fromEmailName.' <'.$fromEmail.'>' . "\r\n";
  447.            
  448.             //$headers .= 'Cc: [email protected]' . "\r\n";
  449.  
  450.             //$headers .= 'Bcc: [email protected]' . "\r\n";
  451.  
  452.             /*echo "Message : ".$message;
  453.             echo "<br>";
  454.             echo "Headers : ".$headers;
  455.             echo "<br>";
  456.             echo "Email To : ".$toEmail;
  457.             echo "<br>";
  458.             echo "Subject : ".$subject;
  459.             echo "<br>";
  460.             exit;*/
  461.  
  462.             // Mail it
  463.  
  464.             //mail($toEmail, $subject, $message, $headers);
  465.             wp_mail( $toEmail, $subject, $message, $headers );
  466.  
  467.         }
  468.  
  469.        
  470.  
  471.         function get_post_info($pid)
  472.  
  473.         {
  474.  
  475.             global $wpdb;
  476.  
  477.             $productinfosql = "select ID,post_title,post_content from $wpdb->posts where ID=$pid";
  478.  
  479.             $productinfo = $wpdb->get_results($productinfosql);
  480.  
  481.             foreach($productinfo[0] as $key=>$val)
  482.  
  483.             {
  484.  
  485.                 $productArray[$key] = $val;
  486.  
  487.             }
  488.  
  489.             return $productArray;
  490.  
  491.         }
  492.  
  493.        
  494.  
  495.         function get_feature_catid()
  496.  
  497.         {
  498.  
  499.             global $wpdb;
  500.  
  501.             $feature_catid = get_option('ptthemes_feature_catid');
  502.  
  503.             return $catid = $wpdb->get_var("SELECT term_ID FROM $wpdb->terms WHERE name = '$feature_catid'");
  504.  
  505.         }
  506.        
  507.         function get_category_by_cat_name($catname)
  508.         {
  509.             if($catname)
  510.             {
  511.                 global $wpdb;
  512.                 return $wpdb->get_var("SELECT $wpdb->terms.term_id FROM $wpdb->terms WHERE $wpdb->terms.name = \"$catname\"");
  513.             }
  514.         }
  515.        
  516.         function delete_post($pid)
  517.         {
  518.             global $wpdb;
  519.             if($pid)
  520.             {
  521.                 $commentsql = "delete from $wpdb->comments where comment_post_ID=\"$pid\"";
  522.                 $wpdb->query($commentsql);
  523.                 $postmetasql = "delete from $wpdb->postmeta where post_id=\"$pid\"";
  524.                 $wpdb->query($postmetasql);
  525.                 $postmetasql = "delete from $wpdb->term_relationships where object_id=\"$pid\"";
  526.                 $wpdb->query($postmetasql);
  527.                 $postmetasql = "delete from $wpdb->posts where ID=\"$pid\"";
  528.                 $wpdb->query($postmetasql);
  529.             }
  530.         }
  531.        
  532.         function is_show_contact_email()
  533.         {
  534.             if(get_option('ptthemes_detail_show_email')=='yes')
  535.             {
  536.                 return true;
  537.             }else
  538.             {
  539.                 return false;
  540.             }
  541.         }
  542.         function is_show_cat_only_home()
  543.         {
  544.             //echo get_option('ptthemes_index_page_show_cat');exit;
  545.             if(get_option('ptthemes_index_page_show_cat')=='no')
  546.             {
  547.                 return true;
  548.             }else
  549.             {
  550.                 return false;
  551.             }
  552.            
  553.         }
  554.        
  555.         function is_latest_listing_home()
  556.         {
  557.             if(get_option('ptthemes_index_page_latest')=='yes')
  558.             {
  559.                 return true;
  560.             }else
  561.             {
  562.                 return false;
  563.             }
  564.            
  565.         }
  566.        
  567.         function get_discount_amount($coupon,$amount)
  568.         {
  569.             global $wpdb;
  570.             if($coupon!='' && $amount>0)
  571.             {
  572.                 $couponsql = "select option_value from $wpdb->options where option_name='discount_coupons'";
  573.                 $couponinfo = $wpdb->get_results($couponsql);
  574.                 if($couponinfo)
  575.                 {
  576.                     foreach($couponinfo as $couponinfoObj)
  577.                     {
  578.                         $option_value = unserialize($couponinfoObj->option_value);
  579.                         foreach($option_value as $key=>$value)
  580.                         {
  581.                             if($value['couponcode'] == $coupon)
  582.                             {
  583.                                 if($value['dis_per']=='per')
  584.                                 {
  585.                                     $discount_amt = ($amount*$value['dis_amt'])/100;
  586.                                 }else
  587.                                 if($value['dis_per']=='amt')
  588.                                 {
  589.                                     $discount_amt = $value['dis_amt'];
  590.                                 }
  591.                             }
  592.                         }
  593.                     }
  594.                     return $discount_amt;
  595.                 }
  596.             }
  597.             return false;          
  598.         }
  599.  
  600.     }
  601.  
  602. }
  603.  
  604. if(!$General)
  605.  
  606. {
  607.  
  608.     $General = new General();
  609.  
  610. }
  611.  
  612. ?>
  613.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement