G2A Many GEOs
SHARE
TWEET

Untitled

a guest Sep 15th, 2013 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4.  * Dashboard class
  5.  *
  6.  * @author Tareq Hasan
  7.  * @package WP User Frontend
  8.  */
  9. class WPUF_Frontend_Dashboard {
  10.  
  11.     function __construct() {
  12.         add_shortcode( 'wpuf_dashboard', array($this, 'shortcode') );
  13.     }
  14.  
  15.     /**
  16.      * Handle's user dashboard functionality
  17.      *
  18.      * Insert shortcode [wpuf_dashboard] in a page to
  19.      * show the user dashboard
  20.      *
  21.      * @since 0.1
  22.      */
  23.     function shortcode( $atts ) {
  24.  
  25.         extract( shortcode_atts( array('post_type' => 'post'), $atts ) );
  26.  
  27.         ob_start();
  28.  
  29.         if ( is_user_logged_in() ) {
  30.             $this->post_listing( $post_type );
  31.         } else {
  32.             $message = wpuf_get_option( 'un_auth_msg', 'wpuf_dashboard' );
  33.  
  34.             if ( empty( $message ) ) {
  35.                 $msg = sprintf( __( "This page is restricted. Please %s to view this page.", 'wpuf' ), wp_loginout( '', false ) );
  36.                 echo apply_filters( 'wpuf_dashboard_unauth', $msg, $post_type );
  37.             } else {
  38.                 echo $message;
  39.             }
  40.         }
  41.  
  42.         $content = ob_get_contents();
  43.         ob_end_clean();
  44.  
  45.         return $content;
  46.     }
  47.  
  48.     /**
  49.      * List's all the posts by the user
  50.      *
  51.      * @global object $wpdb
  52.      * @global object $userdata
  53.      */
  54.     function post_listing( $post_type ) {
  55.         global $wpdb, $userdata, $post;
  56.  
  57.         $userdata = get_userdata( $userdata->ID );
  58.         $pagenum = isset( $_GET['pagenum'] ) ? intval( $_GET['pagenum'] ) : 1;
  59.  
  60.         //delete post
  61.         if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == "del" ) {
  62.             $this->delete_post();
  63.         }
  64.  
  65.         //show delete success message
  66.         if ( isset( $_GET['msg'] ) && $_GET['msg'] == 'deleted' ) {
  67.             echo '<div class="success">' . __( 'Post Deleted', 'wpuf' ) . '</div>';
  68.         }
  69.  
  70.         $args = array(
  71.             'author' => get_current_user_id(),
  72.             'post_status' => array('draft', 'future', 'pending', 'publish', 'private' ),
  73.             'post_type' => $post_type,
  74.             'posts_per_page' => wpuf_get_option( 'per_page', 'wpuf_dashboard', 10 ),
  75.             'paged' => $pagenum
  76.         );
  77.  
  78.         $original_post = $post;
  79.         $dashboard_query = new WP_Query( apply_filters( 'wpuf_dashboard_query', $args ) );
  80.         $post_type_obj = get_post_type_object( $post_type );
  81.         ?>
  82.        
  83. <?php $user_id = get_current_user_id(); ?>
  84. <?php $user_info = get_userdata($user_id); ?>
  85. <div style="width: 700px; margin:0 0 10px 0;">
  86. <div style="float: left; width: 100px; border-right:1px solid #ddd; padding-right:5px;"><?php echo get_avatar( $user_id, $size = '100', $default = 'http://cdn.sakuhetu.com/imgs/global/No-Pic.jpg' ); ?></div>
  87.  
  88. <div style="float: left; width: 575px; padding-left:5px; margin-top:-5px;">
  89. <strong><?php echo $user_info-> user_firstname; ?></strong>, You have Created
  90. <strong style="color:#F00;"><?php function countUserPosts($user_id) {$userposts = get_posts('post_status=any&showposts=-1&author='.$user_id);        return count($userposts);} echo countUserPosts($user_id); ?></strong> Post(s), since <strong><?php echo date("F j, Y", strtotime(get_userdata(get_current_user_id( ))->user_registered)); ?></strong>.
  91. <br /> Address: <?php echo $user_info-> address; ?>
  92. <br /> Mobile: <?php echo $user_info-> mobile; ?>
  93. <br /> Phone: <?php echo $user_info-> phone; ?>
  94. <br /> <a title="Edit My Profile" href="<?php bloginfo('url'); ?>/edit-my-profile">Edit My Profile</a>
  95. </div>
  96. <br style="clear: left;" />
  97. </div>
  98.  
  99. <h1>My Posts</h1>
  100.  
  101. <div id="tabs" class="htabs">
  102. <a href="#published">Published Posts</a>
  103. <a href="#pending">Pending Reviews</a>
  104. <a href="#draft">Saved In Draft</a>
  105. </div>
  106.  
  107. <div id="published" class="tab-content">
  108. <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts($paged . '&showposts=10&author='.$user_id.'&paged=$paged&post_status=publish'); ?>
  109. <?php while (have_posts()) : the_post();?>
  110.  
  111. <div class="product-list">
  112.  
  113. <div>
  114. <div class="inner">
  115.    
  116. <div style="width: 825px;">
  117. <div style="float: left; width: 110px;">
  118. <div class="image">
  119. <?php
  120. if ( has_post_thumbnail()) {
  121. $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
  122. echo '<a href="'.get_permalink().'" title="'.get_the_title(). '" >';
  123. the_post_thumbnail('thumbnail');
  124. echo '</a>';
  125. } else { ?>
  126. <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><img src="http://www.ekarnal.com/wp-content/uploads/2013/09/no-img-100x100.jpg" width="100" height="100" alt="No Image Available" /></a>
  127. <?php }?>
  128. </div>
  129. </div>
  130.  
  131. <div style="float: left; width: 640px; padding-left:5px;">
  132. <div class="name" style="margin-bottom:-1px; text-transform:capitalize;"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php the_title(); ?></a></div>
  133. <div style="border-bottom:1px solid #ddd; padding-bottom:5px; width:615px; text-transform:capitalize;"><?php trimcont(95); ?> ... &raquo;</div>
  134. <div style="margin-top:20px;">
  135.  
  136. <?php if ( in_category( '330' )) { ?>
  137. <a class="hrefbutton" style="background:#f00;" onclick="return false">This Listing Is Expired</a>
  138. <?php } else { ?>
  139. <a href="<?php echo wp_nonce_url('edit-the-post?pid='.get_the_ID().''); ?>" class="hrefbutton" style="background:#4692F7;" title="Edit">Edit This Listing</a>
  140. <?php
  141. ?>
  142. <?php $del_url = add_query_arg( array('action' => 'del', 'pid' => $post->ID) ); ?>
  143. <a onclick="return confirm('Are you sure to delete this post?');" href="<?php echo wp_nonce_url( $del_url, 'wpuf_del' ) ?>" class="hrefbutton" style="background-color:#F00;" title="Delete">Delete</a>
  144. <?php } ?>
  145.  
  146. </div>
  147.  
  148. </div>
  149.  
  150. <br style="clear: left;" />
  151. </div>
  152.  
  153. </div>
  154. </div>
  155. </div>
  156. <?php endwhile; ?>
  157. <div style="float:right;"><?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?></div>
  158. <?php wp_reset_query(); ?></div>
  159.    
  160. <div id="pending" class="tab-content">
  161.  
  162. <?php query_posts('showposts=-1&author='.$user_id.'&post_status=pending'); ?>
  163. <?php while (have_posts()) : the_post();?>
  164.  
  165. <div class="product-list">
  166.  
  167. <div>
  168. <div class="inner">
  169.    
  170. <div style="width: 825px;">
  171. <div style="float: left; width: 110px;">
  172. <div class="image">
  173. <?php
  174. if ( has_post_thumbnail()) {
  175. $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
  176. echo '<a href="'.get_permalink().'" title="'.get_the_title(). '" >';
  177. the_post_thumbnail('thumbnail');
  178. echo '</a>';
  179. } else { ?>
  180. <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><img src="http://www.ekarnal.com/wp-content/uploads/2013/09/no-img-100x100.jpg" width="100" height="100" alt="No Image Available" /></a>
  181. <?php }?>
  182. </div>
  183. </div>
  184.  
  185. <div style="float: left; width: 640px; padding-left:5px;">
  186. <div class="name" style="margin-bottom:-1px; text-transform:capitalize;"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php the_title(); ?></a></div>
  187. <div style="border-bottom:1px solid #ddd; padding-bottom:5px; width:615px; text-transform:capitalize;"><?php trimcont(95); ?> ... &raquo;</div>
  188. <div style="margin-top:20px;">
  189.  
  190. <a href="<?php echo wp_nonce_url('edit-the-post?pid='.get_the_ID().''); ?>" class="hrefbutton" style="background:#4692F7;" title="Edit">Edit This Listing</a>
  191. <a onclick="return confirm('Are you sure to delete this post?');" href="<?php echo wp_nonce_url( $del_url, 'wpuf_del' ) ?>" class="hrefbutton" style="background-color:#F00;" title="Delete">Delete</a>
  192.  
  193. </div>
  194.  
  195. </div>
  196.  
  197. <br style="clear: left;" />
  198. </div>
  199.  
  200. </div>
  201. </div>
  202. </div>
  203. <?php endwhile; ?>
  204. <?php wp_reset_query(); ?>
  205. </div>
  206.  
  207. <div id="draft" class="tab-content">
  208.  
  209. <?php query_posts('showposts=-1&author='.$user_id.'&post_status=draft'); ?>
  210. <?php while (have_posts()) : the_post();?>
  211.  
  212. <div class="product-list">
  213.  
  214. <div>
  215. <div class="inner">
  216.    
  217. <div style="width: 825px;">
  218. <div style="float: left; width: 110px;">
  219. <div class="image">
  220. <?php
  221. if ( has_post_thumbnail()) {
  222. $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
  223. echo '<a href="'.get_permalink().'" title="'.get_the_title(). '" >';
  224. the_post_thumbnail('thumbnail');
  225. echo '</a>';
  226. } else { ?>
  227. <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><img src="http://www.ekarnal.com/wp-content/uploads/2013/09/no-img-100x100.jpg" width="100" height="100" alt="No Image Available" /></a>
  228. <?php }?>
  229. </div>
  230. </div>
  231.  
  232. <div style="float: left; width: 640px; padding-left:5px;">
  233. <div class="name" style="margin-bottom:-1px; text-transform:capitalize;"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php the_title(); ?></a></div>
  234. <div style="border-bottom:1px solid #ddd; padding-bottom:5px; width:615px; text-transform:capitalize;"><?php trimcont(95); ?> ... &raquo;</div>
  235. <div style="margin-top:20px;">
  236.  
  237. <a href="<?php echo wp_nonce_url('edit-the-post?pid='.get_the_ID().''); ?>" class="hrefbutton" style="background:#4692F7;" title="Edit">Edit This Listing</a>
  238. <a onclick="return confirm('Are you sure to delete this post?');" href="<?php echo wp_nonce_url('my-dashboard?action=del&pid='.get_the_ID().''); ?>" class="hrefbutton" style="background-color:#F00;" title="Delete">Delete</a>
  239.  
  240. </div>
  241.  
  242. </div>
  243.  
  244. <br style="clear: left;" />
  245. </div>
  246.  
  247. </div>
  248. </div>
  249. </div>
  250. <?php endwhile; ?>
  251. <?php wp_reset_query(); ?>
  252. </div>
  253.  
  254.         <?php
  255.     }
  256.  
  257.     function delete_post() {
  258.         global $userdata;
  259.  
  260.         $nonce = $_REQUEST['_wpnonce'];
  261.         if ( !wp_verify_nonce( $nonce, 'wpuf_del' ) ) {
  262.             die( "Security check" );
  263.         }
  264.  
  265.         //check, if the requested user is the post author
  266.         $maybe_delete = get_post( $_REQUEST['pid'] );
  267.  
  268.         if ( ($maybe_delete->post_author == $userdata->ID) || current_user_can( 'delete_others_pages' ) ) {
  269.             wp_delete_post( $_REQUEST['pid'] );
  270.  
  271.             //redirect
  272.             $redirect = add_query_arg( array('msg' => 'deleted'), get_permalink() );
  273.             wp_redirect( $redirect );
  274.         } else {
  275.             echo '<div class="error">' . __( 'You are not the post author. Cheeting huh!', 'wpuf' ) . '</div>';
  276.         }
  277.     }
  278.  
  279. }
  280. ?>
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top