Advertisement
baliniz

FirstLoadAction.php

Feb 28th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.66 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @author : Jegtheme
  4.  */
  5. namespace JNews\Ajax;
  6.  
  7. /**
  8.  * Class JNews Website Fragment
  9.  */
  10. Class FirstLoadAction
  11. {
  12.     public function build_response($action)
  13.     {
  14.         $response = array();
  15.  
  16.         if(in_array('desktop_login', $action)) {
  17.             $response['desktop_login'] = $this->top_bar_account();
  18.         }
  19.  
  20.         if(in_array('mobile_login', $action)) {
  21.             $response['mobile_login'] = $this->mobile_account();
  22.         }
  23.  
  24.         if(in_array('login_form', $action)) {
  25.             $response['social_login_form'] = $this->social_login();
  26.             $response['social_register_form'] = $this->social_register();
  27.             $response['account_nonce'] = $this->account_nonce();
  28.         }
  29.  
  30.         $response = apply_filters('jnews_do_first_load_action', $response, $action);
  31.  
  32.         wp_send_json($response);
  33.     }
  34.  
  35.     public function account_nonce()
  36.     {
  37.         return wp_create_nonce('jnews_nonce');
  38.     }
  39.  
  40.     public function top_bar_account()
  41.     {
  42.         if(!is_user_logged_in()) {
  43.  
  44.             $output = "<li><a href=\"#jeg_loginform\" class=\"jeg_popuplink\"><i class=\"fa fa-lock\"></i> " .  jnews_return_translation('Login', 'jnews', 'login') . "</a></li>";
  45.  
  46.             if(get_option( 'users_can_register' )) {
  47.                 $output .= "<li><a href=\"#jeg_registerform\" class=\"jeg_popuplink\"><i class=\"fa fa-user\"></i> " . jnews_return_translation('Register', 'jnews', 'register') . "</a></li>";
  48.             }
  49.  
  50.         } else {
  51.             $current_user = wp_get_current_user();
  52.  
  53.             $output =
  54.                 "<li>
  55.                    <a href=\"" . get_author_posts_url($current_user->ID) . "\" class=\"logged\">" . get_avatar( $current_user->user_email, 22 ) . esc_html($current_user->display_name) . " TES</a>                    
  56.                    " . $this->dropdown() . "
  57.                </li>";
  58.         }
  59.  
  60.         return $output;
  61.     }
  62.  
  63.     public function mobile_account()
  64.     {
  65.         $cartoutput = "";
  66.  
  67.         if(function_exists('is_woocommerce')) {
  68.             $cartoutput = "<li class=\"cart\"><a href=\"" . wc_get_cart_url() . "\"><i class=\"fa fa-shopping-cart\"></i> " . jnews_return_translation('Cart', 'jnews', 'cart') . "</a></li>";
  69.         }
  70.  
  71.         if(!is_user_logged_in()) {
  72.  
  73.             $registeroutput = "";
  74.  
  75.             if(get_option( 'users_can_register' )) {
  76.                 $registeroutput = "<li><a href=\"#jeg_registerform\" class=\"jeg_popuplink\"><i class=\"fa fa-user\"></i> " . jnews_return_translation('Sign Up', 'jnews', 'sign_up') . "</a></li>";
  77.             }
  78.  
  79.             $output =
  80.                 "<ul class=\"jeg_accountlink\">
  81.                    <li><a href=\"#jeg_loginform\" class=\"jeg_popuplink\"><i class=\"fa fa-lock\"></i> " .  jnews_return_translation('Login', 'jnews', 'login') . "</a></li>
  82.                    {$registeroutput}
  83.                    {$cartoutput}
  84.                </ul>";
  85.  
  86.         } else {
  87.  
  88.             $current_user = wp_get_current_user();
  89.             $account_url = get_author_posts_url($current_user->ID);
  90.  
  91.             $output =
  92.                 "<div class=\"profile_box\">
  93.                    <a href=\"{$account_url}\" class=\"profile_img\">" . get_avatar( $current_user->user_email, 55 ) . "</a>
  94.                    <h3><a href=\"{$account_url}\" class=\"profile_name\">" . esc_html(get_the_author_meta('display_name', get_current_user_id())) . "</a></h3>
  95.                    <ul class=\"profile_links\">
  96.                        <li><a href=\"{$account_url}\"><i class=\"fa fa-user\"></i> " . jnews_return_translation('Account', 'jnews', 'account') . "</a></li>
  97.                        {$cartoutput}
  98.                        <li><a href=\"" . esc_url(wp_logout_url()) . "\" class=\"logout\"><i class=\"fa fa-sign-out\"></i> " . jnews_return_translation('Logout', 'jnews', 'logout') . "</a></li>
  99.                    </ul>
  100.                </div>";
  101.  
  102.         }
  103.  
  104.         return $output;
  105.     }
  106.  
  107.     public function dropdown()
  108.     {
  109.         $dropdown_html = '';
  110.         $dropdown = array();
  111.  
  112.         if(function_exists('is_woocommerce'))
  113.         {
  114.             $dropdown['order'] = array(
  115.                 'text' => jnews_return_translation('Order List', 'jnews', 'order_list'),
  116.                 'url' => wc_get_account_endpoint_url('orders')
  117.             );
  118.  
  119.             $dropdown['edit-account'] = array(
  120.                 'text' => jnews_return_translation('Edit Account', 'jnews', 'edit_profile'),
  121.                 'url' => wc_get_account_endpoint_url('edit-account')
  122.             );
  123.         }
  124.  
  125.         $dropdown['logout'] = array(
  126.             'text' => jnews_return_translation('Logout', 'jnews', 'logout'),
  127.             'url' => wp_logout_url()
  128.         );
  129.  
  130.         $dropdown = apply_filters('jnews_dropdown_link', $dropdown);
  131.  
  132.         foreach($dropdown as $key => $value)
  133.         {
  134.             $dropdown_html .= "<li><a href=\"{$value['url']}\" class=\"{$key}\">{$value['text']}</a></li>";
  135.         }
  136.  
  137.         return "<ul>" . $dropdown_html . "</ul>";
  138.     }
  139.  
  140.     public function social_login()
  141.     {
  142.         $output = "<h3>" . jnews_return_translation('Welcome Back!', 'jnews', 'welcome_back') . "</h3>";
  143.  
  144.         if ( defined('JNEWS_SOCIAL_LOGIN') )
  145.         {
  146.             $output .= apply_filters( 'jnews_social_login', '', 'login' );
  147.         }
  148.  
  149.         return $output;
  150.     }
  151.  
  152.     public function social_register()
  153.     {
  154.         $output = "<h3>" . jnews_return_translation('Create New Account!', 'jnews', 'create_new_account') . "</h3>";
  155.  
  156.         if ( defined('JNEWS_SOCIAL_LOGIN') )
  157.         {
  158.             $output .= apply_filters( 'jnews_social_login', '', 'register' );
  159.         }
  160.  
  161.         return $output;
  162.     }
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement