You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

225 line
12 KiB

  1. <?php get_header(); ?>
  2. <?php the_post(); ?>
  3. <?php
  4. /**
  5. * user edit ajax system
  6. * =====================
  7. * passwords strenght meter taken from:
  8. * https://code.tutsplus.com/articles/using-the-included-password-strength-meter-script-in-wordpress--wp-34736
  9. * https://github.com/WordPress/WordPress/blob/master/wp-admin/js/user-profile.js#L223
  10. * ajax idea:
  11. * https://wordpress.stackexchange.com/questions/274778/updating-user-profile-with-ajax-not-working
  12. * form field validation:
  13. * https://itnext.io/https-medium-com-joshstudley-form-field-validation-with-html-and-a-little-javascript-1bda6a4a4c8c
  14. * page template idea:
  15. * https://wordpress.stackexchange.com/questions/9775/how-to-edit-a-user-profile-on-the-front-end
  16. */
  17. $customPostsMeta = get_post_custom();
  18. $subheadline = $customPostsMeta['_subheadline'][0];
  19. $show_profile = is_user_logged_in();
  20. $content_class = 'content clearfix';
  21. if ( $show_profile ) {
  22. $content_class .= ' content-profile';
  23. /**
  24. * @user collect user data to show
  25. */
  26. $current_user = wp_get_current_user();
  27. $current_user_favorites = get_user_meta($current_user->ID, '_favorite_posts', true);
  28. $favorites = false;
  29. if ( !empty($current_user_favorites) ) {
  30. $favorites = new WP_Query(array(
  31. 'post_type' => 'any',
  32. 'post__in' => $current_user_favorites,
  33. ));
  34. }
  35. $current_users_comments = get_comments(array(
  36. 'user_id' => $current_user->ID,
  37. ));
  38. $current_users_comments_number = count($current_users_comments);
  39. $has_comments = $current_users_comments_number > 0;
  40. $comment_item_args = array(
  41. 'avatar_size' => 150,
  42. );
  43. $comment_item_depth = 0;
  44. $edit_data_attributes = ' data-edit="' . __('Bearbeiten', 'sandbox') . '" data-save="' . __('Speichern', 'sandbox') . '" data-saving="' . __('Speichert', 'sandbox') . '" data-saved="' . __('Gespeichert', 'sandbox') . '" data-generate="' . __('Passwort generieren', 'sandbox') . '"';
  45. $edit_box = '<div class="user_edit"' . $edit_data_attributes . '><a href="#%s">' . __('Bearbeiten', 'sandbox') . '</a><div class="field">%s</div></div>';
  46. $input_pattern = ' pattern="[A-Za-z0-9 ]{3,32}"';
  47. $input_title = ' title="' . __('Nur Buchstaben oder Zahlen erlaubt') . '"';
  48. $input_pattern_nickname = ' pattern="[a-zA-Z0-9-_ ]{3,32}"';
  49. $input_title_nickname = ' title="' . __('Nur Buchstaben, Zahlen, Binde- und Unterstriche erlaubt') . '"';
  50. $input_pattern_password = ' pattern="^[^\\\\]*$"';
  51. $input_title_password = ' title="' . __('Alle Zeichen außer "\" sind erlaubt.') . '"';
  52. /**
  53. * Taken from WordPress
  54. * https://github.com/WordPress/WordPress/blob/master/wp-admin/user-edit.php#L462
  55. */
  56. $display_names = array();
  57. $display_names['display_nickname'] = $current_user->nickname;
  58. $display_names['display_username'] = $current_user->user_login;
  59. if ( !empty($current_user->first_name) ) {
  60. $display_names['display_firstname'] = $current_user->first_name;
  61. }
  62. if ( !empty($current_user->last_name) ) {
  63. $display_names['display_lastname'] = $current_user->last_name;
  64. }
  65. if ( !empty($current_user->first_name) && !empty($current_user->last_name) ) {
  66. $display_names['display_firstlast'] = $current_user->first_name . ' ' . $current_user->last_name;
  67. $display_names['display_lastfirst'] = $current_user->last_name . ' ' . $current_user->first_name;
  68. }
  69. if ( !in_array( $current_user->display_name, $display_names) ) { // Only add this if it isn't duplicated elsewhere.
  70. $display_names = array('display_displayname' => $current_user->display_name) + $display_names;
  71. }
  72. $display_names = array_map('trim', $display_names);
  73. $display_names = array_unique($display_names);
  74. }
  75. // echo var_dump($current_user->first_name);
  76. ?>
  77. <?php if ( $show_profile ) { ?>
  78. <article id="content" <?php post_class(array('wrapper', 'container')) ?>>
  79. <header class="content-header">
  80. <figure class="avatar"><?php echo get_avatar($current_user->ID); ?></figure>
  81. <div class="inner">
  82. <h1 class="title"><?php echo $current_user->data->display_name; ?></h1>
  83. <?php if ( !empty($subheadline) ) { ?>
  84. <div class="subheadline">
  85. <?php echo $subheadline; ?>
  86. </div>
  87. <?php } ?>
  88. </div>
  89. <?php
  90. /**
  91. * @Sidebar Content
  92. */
  93. get_sidebar('content-header'); ?>
  94. </header>
  95. <div class="content content-profile-name clearfix">
  96. <?php
  97. /**
  98. * @Sidebar Meta
  99. */
  100. get_sidebar('meta'); ?>
  101. <h3><?php echo __('Ihre Daten', 'sandbox'); ?></h3>
  102. <dl class="profile-data user_edit-disabled">
  103. <dt class="user_login"><?php echo __('Benutzername', 'sandbox'); ?></dt>
  104. <dd id="profile-user_login">
  105. <div class="current"><?php echo $current_user->user_login; ?></div>
  106. </dd>
  107. <dt class="first_name"><?php echo __('Vorname', 'sandbox'); ?></dt>
  108. <dd id="profile-first_name" class="user_edit"<?php echo $edit_data_attributes; ?>>
  109. <div class="field">
  110. <input type="text" name="first_name" id="first_name"<?php echo $input_pattern; ?><?php echo $input_title; ?> placeholder="<?php echo $current_user->first_name; ?>" disabled />
  111. <button class="abort" title="<?php echo __('Abbrechen', 'sandbox'); ?>"></button>
  112. </div>
  113. <div class="current"><?php echo $current_user->first_name; ?></div>
  114. <label class="edit_link" for="first_name" data-mode="edit"><?php echo __('Bearbeiten', 'sandbox'); ?></label>
  115. </dd>
  116. <dt class="last_name"><?php echo __('Nachname', 'sandbox'); ?></dt>
  117. <dd id="profile-last_name" class="user_edit"<?php echo $edit_data_attributes; ?>>
  118. <div class="field">
  119. <input type="text" name="last_name" id="last_name"<?php echo $input_pattern; ?><?php echo $input_title; ?> placeholder="<?php echo $current_user->last_name; ?>" disabled />
  120. <button class="abort" title="<?php echo __('Abbrechen', 'sandbox'); ?>"></button>
  121. </div>
  122. <div class="current"><?php echo $current_user->last_name; ?></div>
  123. <label class="edit_link" for="last_name" data-mode="edit"><?php echo __('Bearbeiten', 'sandbox'); ?></label>
  124. </dd>
  125. <dt class="nickname"><?php echo __('Spitzname', 'sandbox'); ?></dt>
  126. <dd id="profile-nickname" class="user_edit"<?php echo $edit_data_attributes; ?>>
  127. <div class="field">
  128. <input type="text" name="nickname" id="nickname"<?php echo $input_pattern_nickname; ?><?php echo $input_title_nickname; ?> placeholder="<?php echo $current_user->nickname; ?>" disabled />
  129. <button class="abort" title="<?php echo __('Abbrechen', 'sandbox'); ?>"></button>
  130. </div>
  131. <div class="current"><?php echo $current_user->nickname; ?></div>
  132. <label class="edit_link" for="nickname" data-mode="edit"><?php echo __('Bearbeiten', 'sandbox'); ?></label>
  133. </dd>
  134. <dt class="display_name"><?php echo __('Anzeigename', 'sandbox'); ?></dt>
  135. <dd id="profile-display_name" class="user_edit"<?php echo $edit_data_attributes; ?>>
  136. <div class="field">
  137. <select name="display_name" id="display_name" disabled>
  138. <?php foreach ( $display_names as $key => $value ) { ?>
  139. <option <?php selected($current_user->display_name, $value); ?>><?php echo $value; ?></option>
  140. <?php } ?>
  141. </select>
  142. <button class="abort" title="<?php echo __('Abbrechen', 'sandbox'); ?>"></button>
  143. </div>
  144. <div class="current"><?php echo $current_user->display_name; ?></div>
  145. <label class="edit_link" for="display_name" data-mode="edit"><?php echo __('Bearbeiten', 'sandbox'); ?></label>
  146. </dd>
  147. <dt class="pass1"><?php echo __('Passwort', 'sandbox'); ?></dt>
  148. <dd id="profile-pass1" class="user_edit"<?php echo $edit_data_attributes; ?>>
  149. <div class="field">
  150. <input type="password" name="pass1" id="pass1" placeholder="<?php echo __('Neues Passwort eingeben'); ?>" value="" autocomplete="off" data-pw="<?php echo esc_attr(wp_generate_password(24)); ?>"<?php echo $input_pattern_password; ?><?php echo $input_title_password; ?> />
  151. <button class="hide" title="<?php echo __('Verbergen', 'sandbox'); ?>"></button>
  152. <button class="abort" title="<?php echo __('Abbrechen', 'sandbox'); ?>"></button>
  153. </div>
  154. <div class="current">*****</div>
  155. <label class="edit_link" for="pass1" data-mode="generate"><?php echo __('Passwort generieren', 'sandbox'); ?></label>
  156. <div class="strength-meter"><?php echo __('Passwortstärke', 'sandbox'); ?>: <span></span></div>
  157. </dd>
  158. </dl>
  159. </div>
  160. <?php if ( $favorites && $favorites->have_posts() ) { ?>
  161. <div class="content content-profile-favorites">
  162. <h3><?php echo __('Sie haben', 'sandbox'); ?> <?php printf(_n('<span>ein</span> Lernmaterial', '<span>%s</span> Lernmaterialien', $favorites->post_count, 'sandbox'), number_format_i18n($favorites->post_count));?> <?php echo __('favorisiert', 'sandbox'); ?></h3>
  163. <ol class="favorites-list profile-list">
  164. <?php while ( $favorites->have_posts() ) {
  165. $favorites->the_post();
  166. $favoriteMeta = get_post_custom();
  167. $favorite_id = get_the_ID();
  168. $file_url = $favoriteMeta['_alpha_file_url'][0];
  169. $file_size = $favoriteMeta['_alpha_file_size'][0];
  170. $file_count = !empty($favoriteMeta['_alpha_file_count'][0]) ? intval($favoriteMeta['_alpha_file_count'][0]) : 0;
  171. $file_options = unserialize($favoriteMeta['_alpha_file_options'][0]);
  172. $description = $favoriteMeta['_download-description'][0];
  173. $exercise = $favoriteMeta['_download-challenge'][0];
  174. $author = $favoriteMeta['_download-author'][0];
  175. $license = $favoriteMeta['_download-license'][0];
  176. $favorite_post_type = get_post_type();
  177. ?>
  178. <li id="favorite-<?php echo $favorite_id; ?>" <?php post_class('comment'); ?>>
  179. <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
  180. </li>
  181. <?php } ?>
  182. <?php wp_reset_postdata(); ?>
  183. </ol>
  184. </div>
  185. <?php } else {?>
  186. <div class="content content-profile-favorites">
  187. <h3><?php echo __('Sie haben noch keine Lernmaterialien favorisiert', 'sandbox'); ?></h3>
  188. <a href="<?php echo get_post_type_archive_link('alpha_download') ?>" class="more"><?php echo __('Zu den Lernmaterialien', 'sandbox'); ?></a>
  189. </div>
  190. <?php } ?>
  191. <?php if ( $has_comments ) { ?>
  192. <div class="content content-profile-comments">
  193. <h3><?php echo __('Sie haben', 'sandbox'); ?> <?php printf(_n('<span>eine</span> Bewertung', '<span>%s</span> Bewertungen', $current_users_comments_number, 'sandbox'), number_format_i18n($current_users_comments_number));?> <?php echo __('verfasst', 'sandbox'); ?></h3>
  194. <ol class="comment-list profile-list">
  195. <?php foreach ( $current_users_comments as $comment ) {
  196. if ( !isset($GLOBALS['comment']) ) {
  197. $GLOBALS['comment'] = $comment;
  198. }
  199. $comment_post = get_post($comment->comment_post_ID);
  200. ?>
  201. <li id="comment-<?php comment_ID(); ?>" <?php comment_class( $comment->has_children ? 'parent' : '', $comment ); ?>>
  202. <h4><?php echo __('Verfasst zu'); ?> <a href="<?php the_permalink($comment->comment_post_ID); ?>"><?php echo get_the_title($comment->comment_post_ID); ?></a> <?php echo __('am'); ?> <?php printf( __('%1$s at %2$s'), get_comment_date('', $comment ), get_comment_time() ); ?></h4>
  203. <?php if ('0' == $comment->comment_approved ) : ?>
  204. <p class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.'); ?></p>
  205. <?php endif; ?>
  206. <?php echo apply_filters('comment_text', $comment->comment_content, $comment, $args); ?>
  207. </li>
  208. <?php } ?>
  209. </ol>
  210. </div>
  211. <?php } ?>
  212. </article><!-- .post -->
  213. <?php } else { ?>
  214. <?php the_content() ?>
  215. <?php wp_link_pages('before=<div class="page-link">' . __('Pages:', 'sandbox') . '&after=</div>') ?>
  216. <?php } ?>
  217. <?php get_footer() ?>