plug_login.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. <?php
  2. if (!class_exists("plug_login")) {
  3. class plug_login {
  4. function __construct($ns) {
  5. $this->title = __("Login", "dagsopt");
  6. $this->pluginname = $ns->pluginname;
  7. $this->file = $ns->file;
  8. $this->ns = $ns;
  9. }
  10. function start() {
  11. add_action('init', array(&$this, 'override_reset_password_form_redirect'));
  12. add_filter("login_redirect", array(&$this, "my_login_redirect"), 10, 3);
  13. add_filter("admin_bar_menu", array(&$this, "replace_howdy"), 25);
  14. add_filter('login_headerurl', array(&$this, 'login_headerurl'));
  15. add_filter('login_headertext', array(&$this, 'login_headertext'));
  16. add_filter('login_message', array(&$this, 'login_message'));
  17. add_action('register_form', array(&$this, 'plugin_form'));
  18. if (defined("WP_SITEURL") && defined('WP_SITEURL_CDN')) {
  19. add_filter('stylesheet_directory_uri', array(&$this, 'l_stylesheet_directory_uri'));
  20. }
  21. add_action('login_head', array(&$this, 'login_head'));
  22. add_action('user_register', array(&$this, 'plugin_user_register'), 10, 3);
  23. add_action('personal_options_update', array(&$this, 'plugin_user_register'), 10, 3);
  24. add_action('admin_enqueue_scripts', function () {
  25. /*
  26. if possible try not to queue this all over the admin by adding your settings GET page val into next
  27. if( empty( $_GET['page'] ) || "my-settings-page" !== $_GET['page'] ) { return; }
  28. */
  29. wp_enqueue_media();
  30. });
  31. add_filter('upload_mimes', function ($mime_types) {
  32. $mime_types['m4a'] = 'audio/m4a'; //
  33. $mime_types['m4v'] = 'video/mp4'; //
  34. $mime_types['svg'] = 'image/svg+xml'; // Adding .svg extension
  35. $mime_types['json'] = 'application/json'; // Adding .json extension
  36. // unset( $mime_types['xls'] ); // Remove .xls extension
  37. // unset( $mime_types['xlsx'] ); // Remove .xlsx extension
  38. return $mime_types;
  39. }, 1, 1);
  40. add_action('register_post', array(&$this, 'register_post'), 10, 3);
  41. add_action('edit_user_profile', array(&$this, 'plugin_show_user_profile'), 10, 3);
  42. add_action('admin_footer', array(&$this, 'admin_footer'), 10, 3);
  43. }
  44. //add_action('show_user_profile', 'plugin_show_user_profile');
  45. function admin_footer() {
  46. /*
  47. if possible try not to queue this all over the admin by adding your settings GET page val into next
  48. if( empty( $_GET['page'] ) || "my-settings-page" !== $_GET['page'] ) { return; }
  49. */
  50. ?>
  51. <script>
  52. jQuery(document).ready(function($){
  53. $(".uploadbutton").click(function(e){
  54. e.preventDefault();
  55. var self = $(this);
  56. var target = jQuery('.valuereciever', self.parent())
  57. var preview = jQuery('img', self.parent())
  58. var custom_uploader;
  59. if (custom_uploader) {
  60. custom_uploader.open();
  61. return;
  62. }
  63. custom_uploader = wp.media.frames.file_frame = wp.media({
  64. title: 'Choose Image',
  65. button: {
  66. text: 'Choose Image'
  67. },
  68. multiple: false
  69. });
  70. custom_uploader.on('select', function() {
  71. attachment = custom_uploader.state().get('selection').first().toJSON();
  72. console.log(attachment);
  73. target.val("<?php echo WP_SITEURL_CDN ?>/"+attachment.url.split("/").slice(3).join("/"));
  74. preview.attr("src", target.val() );
  75. });
  76. custom_uploader.open();
  77. })
  78. /* var custom_uploader
  79. , click_elem = jQuery('.uploadbutton')
  80. , target = jQuery('.valuereciever', click_elem.parent())
  81. click_elem.click(function(e) {
  82. e.preventDefault();
  83. //If the uploader object has already been created, reopen the dialog
  84. if (custom_uploader) {
  85. custom_uploader.open();
  86. return;
  87. }
  88. //Extend the wp.media object
  89. custom_uploader = wp.media.frames.file_frame = wp.media({
  90. title: 'Choose Image',
  91. button: {
  92. text: 'Choose Image'
  93. },
  94. multiple: false
  95. });
  96. //When a file is selected, grab the URL and set it as the text field's value
  97. custom_uploader.on('select', function() {
  98. attachment = custom_uploader.state().get('selection').first().toJSON();
  99. console.log(attachment);
  100. target.val("/"+attachment.url.split("/").slice(3).join("/"));
  101. });
  102. //Open the uploader dialog
  103. custom_uploader.open();
  104. });
  105. */
  106. });
  107. </script>
  108. <?php
  109. }
  110. function plugin_show_user_profile($user) {
  111. ?>
  112. <h3><?php _e('Pro/Select information')?></h3>
  113. <table class="form-table">
  114. <tr>
  115. <td><input type="hidden" name="r_proselect" id="r_proselect" value="<?php echo $user->Proselect; ?>" /><?php echo $user->Proselect; ?></td>
  116. </tr>
  117. <tr>
  118. <th><label for="Navn"><?php _e('Navn');?></label></th>
  119. <td><input type="text" name="r_navn" id="r_navn" value="<?php echo $user->Navn; ?>" /></td>
  120. </tr>
  121. <tr>
  122. <th><label for="Medlem af"><?php _e('Medlem af');?></label></th>
  123. <td><input type="text" name="r_membership" id="r_membership" value="<?php echo $user->Gruppe; ?>" /></td>
  124. </tr>
  125. </table>
  126. <?php
  127. }
  128. function replace_howdy($wp_admin_bar) {
  129. $my_account = $wp_admin_bar->get_node('my-account');
  130. $newtitle = str_replace('Hejsa,', 'Velkommen,', $my_account->title);
  131. $wp_admin_bar->add_node(array(
  132. 'id' => 'my-account',
  133. 'title' => $newtitle,
  134. ));
  135. }
  136. function my_login_redirect($redirect_to, $request) {
  137. $redirect_url = WP_SITEURL;
  138. return $redirect_url;
  139. }
  140. function override_reset_password_form_redirect() {
  141. $action = isset($_GET['action']) ? $_GET['action'] : '';
  142. $key = isset($_GET['key']) ? $_GET['key'] : '';
  143. $login = isset($_GET['login']) ? $_GET['login'] : '';
  144. if ('wp-login.php' === $GLOBALS['pagenow'] && ('resetpass' == $action)) {
  145. if (isset($_POST['wp-submit']) && $_POST['wp-submit'] == "Reset Password") {
  146. foreach ($_COOKIE as $key => $value) {
  147. if (stristr($key, "wp-resetpass")) {
  148. $v = explode(":", $value);
  149. $login = array_shift($v);
  150. }
  151. # code...
  152. }
  153. //print_r($GLOBALS);
  154. //wp_redirect(site_url('/wp-login.php') . '?action=welcome&user_login=' . $login);
  155. //exit;
  156. }
  157. }
  158. }
  159. function get_page_by_name($post_name, $output = OBJECT) {
  160. global $wpdb;
  161. $post = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type='page'", $post_name));
  162. if ($post) {
  163. return get_post($post, $output);
  164. }
  165. return null;
  166. }
  167. function l_stylesheet_directory_uri($t) {
  168. return str_replace(WP_SITEURL, WP_SITEURL_CDN, $t);
  169. }
  170. function login_headerurl($t) {
  171. return "/";
  172. }
  173. function login_headertext($t) {
  174. return "Til forsiden";
  175. }
  176. function login_message($t) {
  177. $login = "";
  178. foreach ($_COOKIE as $key => $value) {
  179. if (stristr($key, "wp-resetpass")) {
  180. $v = explode(":", $value);
  181. $login = array_shift($v);
  182. }
  183. }
  184. $str = '<style type="text/css">
  185. body {
  186. background-size: cover;
  187. background-position: center center;
  188. background-image: url(' . stripslashes(get_option($this->pluginname . "_login_background_image")) . ');
  189. }
  190. .login h1 a {
  191. margin-top:-50px;
  192. padding-bottom: 5px;
  193. width: auto;
  194. height: 110px;
  195. background-size: auto;
  196. background-image: url(' . stripslashes(get_option($this->pluginname . "_login_image")) . ');}
  197. .login_holder {
  198. margin-top: 20px;
  199. margin-left: 0;
  200. padding: 26px 24px 46px;
  201. font-weight: 400;
  202. overflow: hidden;
  203. background: #fff;
  204. border: 1px solid #ccd0d4;
  205. box-shadow: 0 1px 3px rgb(0 0 0 / 4%);
  206. }
  207. ' . stripslashes(get_option($this->pluginname . "_login_styles")) . '
  208. </style>
  209. <script type="text/javascript">
  210. jQuery(document).ready(function($){
  211. var qq = {};
  212. $.each(document.location.search.substr(1).split("&"),function(c,q){
  213. var i = q.split("=");
  214. qq[i[0].toString()] = i[1].toString();
  215. });
  216. if(qq.action=="resetpass"){
  217. setTimeout(function(){
  218. window.location.href="/wp-login.php?action=welcome&user_login=' . $login . '"
  219. },500)
  220. }else{
  221. $("#user_login").val(qq["user_login"]);
  222. }
  223. })
  224. </script>
  225. <div class="login_holder">
  226. <p>';
  227. if (isset($_GET['action'])) {
  228. $type = isset($_GET['type']) ? $_GET['type'] : 'default';
  229. if ($type !== "default") {
  230. //print_r($args);
  231. $page = $this->get_page_by_name($type);
  232. if ($page) {
  233. $str .= apply_filters('the_content', $page->post_content);
  234. } else {
  235. $str .= stripslashes(get_option($this->pluginname . "_login_support_splash_" . $_GET['action'], false));
  236. }
  237. } else {
  238. $str .= stripslashes(get_option($this->pluginname . "_login_support_splash_" . $_GET['action'], false));
  239. }
  240. } else {
  241. $str .= stripslashes(get_option($this->pluginname . "_login_support_splash", false));
  242. }
  243. $str .= '</p></div>';
  244. return $str;
  245. }
  246. function plugin_user_register($id) {
  247. $user_info = get_userdata($id);
  248. update_user_meta($id, 'Proselect', $_POST['r_proselect']);
  249. update_user_meta($id, 'Navn', $_POST['r_navn']);
  250. update_user_meta($id, 'Gruppe', $_POST['r_membership']);
  251. // update_usermeta($id, 'Institution' , $_POST['r_institution'] );
  252. // update_usermeta($id, 'Fag' , $_POST['r_fag'] );
  253. // update_usermeta($id, 'Fødselsår' , $_POST['r_alder'] );
  254. }
  255. function register_post($login, $email, $errors) {
  256. if (empty($_POST['r_proselect'])) {
  257. $_POST['r_proselect'] = "Perspektiv";
  258. }
  259. if (empty($_POST['r_navn'])) {
  260. $errors->add('demo_error', __('Du skal udfylde Navn'));
  261. }
  262. ;
  263. if (empty($_POST['r_membership']) || $_POST['r_membership'] === "Vælg gruppe") {
  264. $errors->add('demo_error', __('Du skal udfylde Gruppe'));
  265. }
  266. ;
  267. /* if(empty($_POST['r_fag'])){
  268. $errors->add('demo_error',__('Du skal udfylde Fag'));
  269. };
  270. if(empty($_POST['r_alder'])){
  271. $errors->add('demo_error',__('Du skal udfylde Alder'));
  272. }else{
  273. $alder = intval($_POST['r_alder']);
  274. if($alder < 1900 || $alder > 2005){
  275. $errors->add('demo_error',__('hmmm.. din alder virker mystisk'));
  276. };
  277. };
  278. */
  279. }
  280. function help() {
  281. ?>
  282. <?php echo (__("Adds logo to login page", "dagsopt")) ?>
  283. <a href="/wp-login.php"><?php echo (__("Login page", "dagsopt")) ?></a>
  284. <?php
  285. }
  286. function login_head() {
  287. $type = isset($_GET['type']) ? $_GET['type'] : 'default';
  288. if ($type !== "!!default") {
  289. ?>
  290. <script type='text/javascript' src='/wp-includes/js/jquery/jquery.js?ver=1.4.2'></script>
  291. <script type="text/javascript">
  292. jQuery(document).ready(function(){
  293. if(jQuery("form").length>0 && jQuery("form").attr('action').indexOf('register')>-1){
  294. console.log("SPECIAL REGV");
  295. //jQuery("form").prepend('<h3><?php echo ($type) ?></h3><br>');
  296. jQuery("p:contains('Brugernavn')").hide();
  297. jQuery("#user_email").attr("tabindex","24")
  298. jQuery("#r_navn").attr("tabindex","25")
  299. jQuery("#r_membership").attr("tabindex","26")
  300. jQuery("#wp-submit").attr("tabindex","27")
  301. var t = (jQuery('#login_error').html())+"";
  302. var a = t.split("\n");
  303. if(a.length && a[0].indexOf('brugernavn')>-1){
  304. a.shift();
  305. jQuery('#login_error').html(a.join("\n"));
  306. }
  307. jQuery("#user_login").hide();
  308. jQuery('label[for="user_login"]').hide();
  309. jQuery('#wp-submit').click(function(){
  310. console.log("SEND");
  311. jQuery('#user_login').val(jQuery('#user_email').val());
  312. });
  313. }
  314. });
  315. </script>
  316. <?php
  317. }
  318. ?>
  319. <?php
  320. }
  321. function plugin_form() {
  322. $type = isset($_GET['type']) ? $_GET['type'] : 'default';
  323. $html = '
  324. <div width="100%">
  325. <input type="hidden" name="r_proselect" id="r_proselect" value="' . $type . '">
  326. <p>
  327. <label style="display: block; margin-bottom: 5px;">' . __('Navn', 'Navn') . '
  328. <input type="text" name="r_navn" id="r_navn" class="input nnl" value="' . (isset($_POST['r_navn']) ? $_POST['r_navn'] : "") . '" size="20" tabindex="25" />
  329. </label>
  330. </p>
  331. <input type="hidden" name="r_membership" id="r_membership" value="' . $type . '">
  332. </div>
  333. ';
  334. echo $html;
  335. }
  336. function Option($pre) {
  337. update_option($pre . '_support_splash', $_POST[$pre . '_support_splash']);
  338. update_option($pre . '_support_splash_rp', $_POST[$pre . '_support_splash_rp']);
  339. update_option($pre . '_support_splash_welcome', $_POST[$pre . '_support_splash_welcome']);
  340. update_option($pre . '_support_splash_resetpass', $_POST[$pre . '_support_splash_resetpass']);
  341. update_option($pre . '_support_splash_register', $_POST[$pre . '_support_splash_register']);
  342. update_option($pre . '_background_image', $_POST[$pre . '_background_image']);
  343. update_option($pre . '_image', $_POST[$pre . '_image']);
  344. update_option($pre . '_styles', $_POST[$pre . '_styles']);
  345. }
  346. function admin_line($pre) {
  347. ?>
  348. <hr>
  349. <div >
  350. <div style="width: 300px; height: 100px; overflow: hidden">
  351. <img height="100" src="<?php echo (stripslashes(get_option($pre . "_image"))); ?>">
  352. </div>
  353. <?php echo (__("Login image:", "dagsopt")) ?><br>
  354. <input type="text" name="<?php echo ($pre . '_image'); ?>" class="valuereciever" value="<?php echo (stripslashes(get_option($pre . "_image"))); ?>" />
  355. <button class="button uploadbutton">Upload</button>
  356. </div>
  357. <div >
  358. <div style="width: 300px; height: 100px; overflow: hidden">
  359. <img height="100" src="<?php echo (stripslashes(get_option($pre . "_background_image"))); ?>">
  360. </div>
  361. <?php echo (__("Login background image:", "dagsopt")) ?><br>
  362. <input type="text" name="<?php echo ($pre . '_background_image'); ?>" class="valuereciever" value="<?php echo (stripslashes(get_option($pre . "_background_image"))); ?>" />
  363. <button class="button uploadbutton">Upload</button>
  364. </div>
  365. <hr>
  366. <?php echo (__("Login styles:", "dagsopt")) ?><br><textarea style="width: 100%; height: 150px;" name="<?php echo ($pre . '_styles'); ?>"><?php echo (stripslashes(get_option($pre . "_styles"))); ?></textarea>
  367. <hr>
  368. <?php echo (__("Login splash html:", "dagsopt")) ?><br><textarea style="width: 100%; height: 150px;" name="<?php echo ($pre . '_support_splash'); ?>"><?php echo (stripslashes(get_option($pre . "_support_splash"))); ?></textarea>
  369. <hr>
  370. <?php echo (__("Login splash html rp:", "dagsopt")) ?><br><textarea style="width: 100%; height: 150px;" name="<?php echo ($pre . '_support_splash_rp'); ?>"><?php echo (stripslashes(get_option($pre . "_support_splash_rp"))); ?></textarea>
  371. <hr>
  372. <?php echo (__("Login splash html welcome:", "dagsopt")) ?><br><textarea style="width: 100%; height: 150px;" name="<?php echo ($pre . '_support_splash_welcome'); ?>"><?php echo (stripslashes(get_option($pre . "_support_splash_welcome"))); ?></textarea>
  373. <hr>
  374. <?php echo (__("Login splash html resetpass:", "dagsopt")) ?><br><textarea style="width: 100%; height: 150px;" name="<?php echo ($pre . '_support_splash_resetpass'); ?>"><?php echo (stripslashes(get_option($pre . "_support_splash_resetpass"))); ?></textarea>
  375. <hr>
  376. <?php echo (__("Login splash html register:", "dagsopt")) ?><br><textarea style="width: 100%; height: 150px;" name="<?php echo ($pre . '_support_splash_register'); ?>"><?php echo (stripslashes(get_option($pre . "_support_splash_register"))); ?></textarea>
  377. <?php
  378. }
  379. }
  380. global $plug_login;
  381. $plug_login = new plug_login($this);
  382. $this->dagsopt['plug_login'] = $plug_login;
  383. }