Skip to content
Browse files

Merge branch 'master' of https://github.com/foxrain/private-messages-…

…for-wordpress into foxrain-master

Conflicts:
	pm4wp.php
  • Loading branch information...
1 parent 6ca4714 commit 55bfa0ef5e84e958c881f8b746785147a6987549 @rilwis committed Nov 6, 2012
Showing with 593 additions and 157 deletions.
  1. +1 −0 css/style.css
  2. +16 −12 inc/send-page.php
  3. BIN lang/pm4wp-pl_PL.mo
  4. +423 −0 lang/pm4wp-pl_PL.po
  5. +153 −145 pm4wp.php
View
1 css/style.css
@@ -3,4 +3,5 @@
}
.form-table select {
height: auto;
+ width: 99%;
}
View
28 inc/send-page.php
@@ -162,35 +162,39 @@ function rwpm_send()
{
$id = $_GET['id'];
$msg = $wpdb->get_row( 'SELECT * FROM ' . $wpdb->prefix . 'pm WHERE `id` = "' . $id . '" LIMIT 1' );
-
+
$content = '<p>&nbsp;</p>';
$content .= '<p>---</p>';
$content .= '<p><em>' . __( 'In: ', 'pm4wp' ) . $msg->date . "\t" . $msg->sender . __( ' Wrote:', 'pm4wp' ) . '</em></p>';
$content .= wpautop( $msg->content );
$content = stripslashes( $content );
}
- // Get all users of blog
- $users = $wpdb->get_results( "SELECT display_name FROM $wpdb->users ORDER BY display_name ASC" );
-
+ // if auto suggest feature is turned on
if ( $option['type'] == 'autosuggest' )
- { // if auto suggest feature is turned on
+ {
?>
<input id="recipient" type="text" name="recipient" class="large-text" />
<?php
}
- else
- { // classic way: select recipient from dropdown list
+ else // classic way: select recipient from dropdown list
+ {
+ // Get all users of blog
+ $args = array(
+ 'order' => 'ASC',
+ 'orderby' => 'display_name' );
+ $values = get_users( $args );
+ $values = apply_filters( 'rwpm_recipients', $values );
?>
- <select name="recipient[]" multiple="multiple" size="5">
+ <select name="recipient[]" multiple="multiple" size="5">
<?php
- foreach ( $users as $user )
+ foreach ( $values as $value )
{
- $selected = ( $user->display_name == $recipient ) ? ' selected="selected"' : '';
- echo "<option value='$user->display_name'$selected>$user->display_name</option>";
+ $selected = ( $value->display_name == $recipient ) ? ' selected="selected"' : '';
+ echo "<option value='$value->display_name'$selected>$value->display_name</option>";
}
?>
- </select>
+ </select>
<?php
}
?>
View
BIN lang/pm4wp-pl_PL.mo
Binary file not shown.
View
423 lang/pm4wp-pl_PL.po
@@ -0,0 +1,423 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: Private Messages For WordPress\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2011-08-26 23:46+0700\n"
+"PO-Revision-Date: \n"
+"Last-Translator: \n"
+"Language-Team: Rilwis <rilwis@gmail.com>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Poedit-Language: English\n"
+"X-Poedit-Country: UNITED STATES\n"
+"X-Poedit-SourceCharset: utf-8\n"
+"X-Poedit-KeywordsList: __;_e;_n:1,2\n"
+"X-Poedit-Basepath: ./\n"
+"Plural-Forms: nplurals=2; plural=n != 1;\n"
+"X-Poedit-SearchPath-0: ..\n"
+
+#: ../pm4wp.php:79
+msgid "New PM at %BLOG_NAME%"
+msgstr "Nowe Wiadomości w %BLOG_NAME%"
+
+#: ../pm4wp.php:80
+msgid ""
+"You have new private message from <b>%SENDER%</b> at <b>%BLOG_NAME%</b>.\n"
+"\n"
+"<a href=\"%INBOX_URL%\">Click here</a> to go to your inbox.\n"
+"\n"
+"This email is sent automatically. Please don't reply."
+msgstr ""
+"Masz nową prywatną wiadomość od <b>%SENDER%</b> w <b>%BLOG_NAME%</b>.\n"
+"\n"
+"<a href=\"%INBOX_URL%\">Kliknij tutaj</a>, aby przejść do skrzynki odbiorczej.\n"
+"\n"
+"Ten e-mail jest wysyłany automatycznie. Prosimy nie odpowiadać."
+
+#: ../pm4wp.php:113
+#: ../pm4wp.php:142
+msgid "Private Messages Options"
+msgstr "Prywatne Wiadomości Opcje"
+
+#: ../pm4wp.php:113
+#: ../pm4wp.php:117
+#: ../widget.php:95
+msgid "Private Messages"
+msgstr "Prywatne Wiadomości"
+
+#: ../pm4wp.php:117
+msgid "Messages"
+msgstr "Wiadomości"
+
+#: ../pm4wp.php:120
+#: ../pm4wp.php:622
+msgid "Inbox"
+msgstr "Skrzynka odbiorcza"
+
+#: ../pm4wp.php:122
+#: ../pm4wp.php:813
+msgid "Outbox"
+msgstr "Skrzynka nadawcza"
+
+#: ../pm4wp.php:125
+#: ../pm4wp.php:297
+msgid "Send Private Message"
+msgstr "Wyślij wiadomość"
+
+#: ../pm4wp.php:125
+#: ../pm4wp.php:497
+msgid "Send"
+msgstr "Wyślij"
+
+#: ../pm4wp.php:153
+msgid "1. The plugin goes with a page template for front-end usage."
+msgstr "1.Wtyczka idzie z szablonu strony dla front-end użytkowania."
+
+#: ../pm4wp.php:154
+msgid "Copy file <code>pm4wp-template.php</code> to your theme folder and create a page with template <code>Private Messages</code>"
+msgstr "Skopiować plik <code>pm4wp-template.php</code> do katalogu tematycznego i stworzyć stronę z szablonu <code>prywatne wiadomości</code>"
+
+#: ../pm4wp.php:155
+msgid "The template is just the backbone. You should modify it to fit your theme."
+msgstr "Szablon jest tylko szkieletem. Należy go zmodyfikować, aby pasowały do tematu."
+
+#: ../pm4wp.php:156
+msgid "2. You can send to multiple recipients now."
+msgstr "2. Możesz wysłać wiadomość do wielu odbiorców, teraz."
+
+#: ../pm4wp.php:158
+msgid "Don't show this message next time"
+msgstr "Nie pokazuj tego komunikatu następnym razem"
+
+#: ../pm4wp.php:161
+msgid "Please set numbers of private messages for each user role:"
+msgstr "Proszę ustawić numery prywatne wiadomości dla każdej roli użytkownika:"
+
+#: ../pm4wp.php:162
+msgid "<b><i>0</i></b> means <b><i>unlimited</i></b>"
+msgstr "<b><i>0</i></b> środki <b><i>nieograniczona</i></b>"
+
+#: ../pm4wp.php:163
+msgid "<b><i>-1</i></b> means <b><i>not allowed</i></b> to send PM"
+msgstr "<b><i>-1</i></b> środki <b><i>nie jest dozwolone</i></b> Wysłać PW"
+
+#: ../pm4wp.php:169
+msgid "Administrator"
+msgstr "Administrator"
+
+#: ../pm4wp.php:175
+msgid "Editor"
+msgstr "Redaktor"
+
+#: ../pm4wp.php:179
+msgid "Author"
+msgstr "Autor"
+
+#: ../pm4wp.php:183
+msgid "Contributor"
+msgstr "Współpracownik"
+
+#: ../pm4wp.php:189
+msgid "Subscriber"
+msgstr "Subskrybent"
+
+#: ../pm4wp.php:194
+msgid "How do you want to choose recipient?"
+msgstr "Jak chcesz, aby wybrać odbiorcę?"
+
+#: ../pm4wp.php:197
+msgid "Dropdown list"
+msgstr "Lista rozwijana"
+
+#: ../pm4wp.php:199
+msgid "Auto suggest from user input"
+msgstr "Automatyczne sugerują od danego użytkownia"
+
+#: ../pm4wp.php:204
+msgid "Email template:"
+msgstr "Szablon Email:"
+
+#: ../pm4wp.php:208
+msgid "Enable sending email when user receive new PM?"
+msgstr "Włącz wysyłanie wiadomości e-mail, gdy użytkownik otrzyma nową Wiadomość ?"
+
+#: ../pm4wp.php:211
+msgid "Yes"
+msgstr "Tak"
+
+#: ../pm4wp.php:213
+msgid "No"
+msgstr "Nie"
+
+#: ../pm4wp.php:217
+msgid "From name (optional)"
+msgstr "Od nazwiska (opcjonalne)"
+
+#: ../pm4wp.php:222
+msgid "From email (optional)"
+msgstr "Z e-mail (w razie zapytań)"
+
+#: ../pm4wp.php:228
+#: ../pm4wp.php:487
+#: ../pm4wp.php:656
+#: ../pm4wp.php:709
+#: ../pm4wp.php:837
+#: ../pm4wp.php:873
+msgid "Subject"
+msgstr "Obiekt"
+
+#: ../pm4wp.php:234
+msgid "Body"
+msgstr "Całość"
+
+#: ../pm4wp.php:237
+msgid "Allowed HTML tags: "
+msgstr "Dozwolone znaczniki HTML:"
+
+#: ../pm4wp.php:241
+msgid "Available tags"
+msgstr "Dostępne tagi"
+
+#: ../pm4wp.php:246
+msgid "Blog name"
+msgstr "Temat wiadomości"
+
+#: ../pm4wp.php:250
+msgid "Email address of blog"
+msgstr "Wyślij adres bloga"
+
+#: ../pm4wp.php:254
+msgid "Sender name"
+msgstr "Nazwa nadawcy"
+
+#: ../pm4wp.php:258
+msgid "URL of inbox"
+msgstr "URL skrzynki odbiorczej"
+
+#: ../pm4wp.php:263
+msgid "Save Changes"
+msgstr "Zapisz zmiany"
+
+#: ../pm4wp.php:270
+msgid "Donation"
+msgstr "Dotacja"
+
+#: ../pm4wp.php:272
+msgid "This plugin has cost me countless hours of work, if you use it, please donate a token of your appreciation!"
+msgstr "Wtyczka ta kosztowała mnie wiele godzin pracy, jeśli używasz go, proszę darować znak swojego uznania!"
+
+#: ../pm4wp.php:310
+msgid "You have exceeded the limit of mailbox. Please delete some messages before sending another."
+msgstr "Został przekroczony limit w skrzynce odbiorczej. Proszę usunąć niektóre wiadomości przed wysłaniem następnej."
+
+#: ../pm4wp.php:334
+msgid "Please enter username of recipient."
+msgstr "Proszę podać nazwę użytkownika odbiorcy."
+
+#: ../pm4wp.php:338
+msgid "Please enter subject of message."
+msgstr "Wpisz temat wiadomości."
+
+#: ../pm4wp.php:342
+msgid "Please enter content of message."
+msgstr "Proszę wpisać treść wiadomości."
+
+#: ../pm4wp.php:426
+#, php-format
+msgid "%d message sent."
+msgid_plural "%d messages sent."
+msgstr[0] "%d Wiadomość została wysłana."
+msgstr[1] "%d Wiadomości zostały wysłane."
+
+#: ../pm4wp.php:426
+#, php-format
+msgid "%d error."
+msgid_plural "%d errors."
+msgstr[0] "%d Błąd"
+msgstr[1] "%d Błędy"
+
+#: ../pm4wp.php:435
+#: ../pm4wp.php:836
+#: ../pm4wp.php:872
+msgid "Recipient"
+msgstr "Odbiorca"
+
+#: ../pm4wp.php:491
+msgid "Content"
+msgstr "Treść"
+
+#: ../pm4wp.php:526
+msgid "Inbox \\ View Message"
+msgstr "Przychodzące // Widok wiadomości"
+
+#: ../pm4wp.php:528
+msgid "Back to inbox"
+msgstr "Powrót do skrzynki odbiorczej"
+
+#: ../pm4wp.php:532
+#: ../pm4wp.php:553
+#: ../pm4wp.php:747
+#: ../pm4wp.php:765
+msgid "Info"
+msgstr "Informacje o"
+
+#: ../pm4wp.php:533
+#: ../pm4wp.php:554
+#: ../pm4wp.php:748
+#: ../pm4wp.php:766
+msgid "Message"
+msgstr "wiadomość"
+
+#: ../pm4wp.php:534
+#: ../pm4wp.php:555
+#: ../pm4wp.php:749
+#: ../pm4wp.php:767
+msgid "Action"
+msgstr "Czynność"
+
+#: ../pm4wp.php:539
+#, php-format
+msgid "<b>Sender</b>: %s<br /><b>Date</b>: %s"
+msgstr "<b>Sender</b>: %s<br /><b>Date</b>: %s"
+
+#: ../pm4wp.php:540
+#: ../pm4wp.php:755
+#, php-format
+msgid "<p><b>Subject</b>: %s</p><p>%s</p>"
+msgstr "<p><b>Subject</b>: %s</p><p>%s</p>"
+
+#: ../pm4wp.php:543
+#: ../pm4wp.php:646
+#: ../pm4wp.php:691
+#: ../pm4wp.php:758
+#: ../pm4wp.php:858
+msgid "Delete"
+msgstr "Usuń"
+
+#: ../pm4wp.php:546
+#: ../pm4wp.php:694
+msgid "Reply"
+msgstr "Odpowiedz"
+
+#: ../pm4wp.php:578
+msgid "Message marked as read."
+msgid_plural "Messages marked as read"
+msgstr[0] "Wiadomość oznaczona jako przeczytana."
+msgstr[1] "Wiadomości oznaczone jako przeczytane."
+
+#: ../pm4wp.php:580
+#: ../pm4wp.php:612
+#: ../pm4wp.php:803
+msgid "Error. Please try again."
+msgstr "Błąd. Proszę spróbować ponownie"
+
+#: ../pm4wp.php:614
+#: ../pm4wp.php:805
+msgid "Message deleted."
+msgid_plural "Messages deleted."
+msgstr[0] "Wiadomość usunięta."
+msgstr[1] "Wiadomości usunięte."
+
+#: ../pm4wp.php:628
+msgid "You have no items in inbox."
+msgstr "Nie masz żadnych elementów w skrzynce odbiorczej."
+
+#: ../pm4wp.php:637
+#, php-format
+msgid "You have %d private message (%d unread)."
+msgid_plural "You have %d private messages (%d unread)."
+msgstr[0] "Masz %d prywatną wiadomość (nieprzeczytanych: %d)."
+msgstr[1] "Masz %d wiadomości (nieprzeczytanych: %d)."
+
+#: ../pm4wp.php:645
+msgid "Bulk Action"
+msgstr "Działanie masowe"
+
+#: ../pm4wp.php:647
+#: ../pm4wp.php:684
+msgid "Mark As Read"
+msgstr "Oznacz jako przeczytane"
+
+#: ../pm4wp.php:648
+msgid "Apply"
+msgstr "Zastosuj"
+
+#: ../pm4wp.php:655
+#: ../pm4wp.php:708
+msgid "Sender"
+msgstr "Nadawca"
+
+#: ../pm4wp.php:657
+#: ../pm4wp.php:710
+#: ../pm4wp.php:838
+#: ../pm4wp.php:874
+msgid "Date"
+msgstr "Data"
+
+#: ../pm4wp.php:678
+#: ../pm4wp.php:855
+msgid "View"
+msgstr "Wyświetl"
+
+#: ../pm4wp.php:741
+msgid "Outbox \\ View Message"
+msgstr "Wysłane // Widok Wiadomości"
+
+#: ../pm4wp.php:743
+msgid "Back to outbox"
+msgstr "Powrót do skrzynki nadawczej"
+
+#: ../pm4wp.php:754
+#, php-format
+msgid "<b>Recipient</b>: %s<br /><b>Date</b>: %s"
+msgstr "<b>Recipient</b>: %s<br /><b>Date</b>: %s"
+
+#: ../pm4wp.php:819
+msgid "You have no items in outbox."
+msgstr "Nie masz żadnych elementów w skrzynce nadawczej."
+
+#: ../pm4wp.php:822
+#, php-format
+msgid "You wrote %d private message."
+msgid_plural "You wrote %d private messages."
+msgstr[0] "Napisałeś %d wiadomość."
+msgstr[1] "Napisałeś %d wiadomości."
+
+#: ../pm4wp.php:829
+msgid "Delete Selected"
+msgstr "Usuń zaznaczone"
+
+#: ../pm4wp.php:904
+#, php-format
+msgid "You have %d new message!"
+msgid_plural "You have %d new messages!"
+msgstr[0] "Masz %d nową wiadomość!"
+msgstr[1] "Masz %d nowe wiadomości!"
+
+#: ../pm4wp.php:904
+#: ../widget.php:75
+msgid "Click here to go to inbox"
+msgstr "Kliknij tutaj aby przejść do skrzynki odbiorczej"
+
+#: ../widget.php:16
+msgid "Show notifications and new private messages on sidebar"
+msgstr "Pokaż powiadomienia i nowe wiadomości na pasku bocznym"
+
+#: ../widget.php:18
+msgid "Private Messages Widget"
+msgstr "Prywatne Wiadomości Widget"
+
+#: ../widget.php:68
+#, php-format
+msgid "<br />by <b>%s</b><br />at %s"
+msgstr "<br />by <b>%s</b><br />at %s"
+
+#: ../widget.php:99
+msgid "Title:"
+msgstr "Tytuł:"
+
+#: ../widget.php:104
+msgid "Number of PM:"
+msgstr "Liczba Wiadomości:"
+
View
298 pm4wp.php
@@ -1,145 +1,153 @@
-<?php
-/*
-Plugin Name: Private Messages For WordPress
-Plugin URI: http://www.deluxeblogtips.com/private-messages-for-wordpress
-Description: Allow members of WordPress blog send and receive private messages (PM)
-Version: 2.1.9
-Author: Rilwis
-Author URI: http://www.deluxeblogtips.com
-License: GNU GPL 2+
-*/
-
-// Prevent loading this file directly
-defined( 'ABSPATH' ) || exit;
-
-define( 'PM4WP_DIR', plugin_dir_path( __FILE__ ) );
-define( 'PM4WP_INC_DIR', trailingslashit( PM4WP_DIR . 'inc' ) );
-
-define( 'PM4WP_URL', plugin_dir_url( __FILE__ ) );
-define( 'PM4WP_CSS_URL', trailingslashit( PM4WP_URL . 'css' ) );
-define( 'PM4WP_JS_URL', trailingslashit( PM4WP_URL . 'js' ) );
-
-include_once PM4WP_INC_DIR . 'widget.php';
-include_once PM4WP_INC_DIR . 'inbox-page.php';
-include_once PM4WP_INC_DIR . 'send-page.php';
-include_once PM4WP_INC_DIR . 'outbox-page.php';
-
-if ( is_admin() )
-{
- include_once PM4WP_INC_DIR . 'options.php';
-}
-
-register_activation_hook( __FILE__, 'rwpm_activate' );
-add_action( 'plugins_loaded', 'rwpm_load_text_domain' );
-add_action( 'admin_notices', 'rwpm_notify' );
-add_action( 'admin_bar_menu', 'rwpm_adminbar', 300 );
-add_action( 'wp_ajax_rwpm_get_users', 'rwpm_get_users' );
-
-/**
- * Load plugin text domain
- *
- * @return void
- */
-function rwpm_load_text_domain()
-{
- load_plugin_textdomain( 'pm4wp', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
-}
-
-/**
- * Create table and register an option when activate
- *
- * @return void
- */
-function rwpm_activate()
-{
- global $wpdb;
-
- // Create table
- $query = 'CREATE TABLE IF NOT EXISTS ' . $wpdb->prefix . 'pm (
- `id` bigint(20) NOT NULL auto_increment,
- `subject` text NOT NULL,
- `content` text NOT NULL,
- `sender` varchar(60) NOT NULL,
- `recipient` varchar(60) NOT NULL,
- `date` datetime NOT NULL,
- `read` tinyint(1) NOT NULL,
- `deleted` tinyint(1) NOT NULL,
- PRIMARY KEY (`id`)
- ) COLLATE utf8_general_ci;';
-
- // Note: deleted = 1 if message is deleted by sender, = 2 if it is deleted by recipient
-
- $wpdb->query( $query );
-
- // Default numbers of PM for each group
- $default_option = array(
- 'administrator' => 0,
- 'editor' => 50,
- 'author' => 20,
- 'contributor' => 10,
- 'subscriber' => 5,
- 'type' => 'dropdown', // How to choose recipient: dropdown list or autocomplete based on user input
- 'email_enable' => 1,
- 'email_name' => '%BLOG_NAME%',
- 'email_address' => '%BLOG_ADDRESS%',
- 'email_subject' => __( 'New PM at %BLOG_NAME%', 'pm4wp' ),
- 'email_body' => __( "You have new private message from <b>%SENDER%</b> at <b>%BLOG_NAME%</b>.\n\n<a href=\"%INBOX_URL%\">Click here</a> to go to your inbox.\n\nThis email is sent automatically. Please don't reply.", 'pm4wp' )
- );
- add_option( 'rwpm_option', $default_option, '', 'no' );
-}
-
-/**
- * Show notification of new PM
- */
-function rwpm_notify()
-{
- global $wpdb, $current_user;
-
- // get number of unread messages
- $num_unread = (int) $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'pm WHERE `recipient` = "' . $current_user->user_login . '" AND `read` = 0 AND `deleted` != "2"' );
-
- if ( !$num_unread )
- return;
-
- printf(
- '<div id="message" class="error"><p><b>%s</b> <a href="%s">%s</a></p></div>',
- sprintf( _n( 'You have %d new message!', 'You have %d new messages!', $num_unread, 'pm4wp' ), $num_unread ),
- admin_url( 'admin.php?page=rwpm_inbox' ),
- __( 'Click here to go to inbox', 'pm4wp' )
- );
-}
-
-/**
- * Show number of unread messages in admin bar
- */
-function rwpm_adminbar()
-{
- global $wp_admin_bar;
- global $wpdb, $current_user;
-
- // get number of unread messages
- $num_unread = (int) $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'pm WHERE `recipient` = "' . $current_user->user_login . '" AND `read` = 0 AND `deleted` != "2"' );
-
- if ( $num_unread && is_admin_bar_showing() )
- {
- $wp_admin_bar->add_menu( array(
- 'id' => 'rwpm',
- 'title' => sprintf( _n( 'You have %d new message!', 'You have %d new messages!', $num_unread, 'pm4wp' ), $num_unread ),
- 'href' => admin_url( 'admin.php?page=rwpm_inbox' ),
- 'meta' => array( 'class' => "rwpm_newmessages" ),
- ) );
- }
-}
-
-/**
- * Ajax callback function to get list of users
- */
-function rwpm_get_users()
-{
- global $wpdb;
-
- $keyword = trim( strip_tags( $_POST['term'] ) );
- $values = $wpdb->get_col( "SELECT DISTINCT display_name FROM {$wpdb->users} WHERE display_name LIKE '{$keyword}%'" );
-
- die( json_encode( $values ) );
-}
+<?php
+/*
+Plugin Name: Private Messages For WordPress
+Plugin URI: http://www.deluxeblogtips.com/private-messages-for-wordpress
+Description: Allow members of WordPress blog send and receive private messages (PM)
+Version: 2.1.9
+Author: Rilwis
+Author URI: http://www.deluxeblogtips.com
+License: GNU GPL 2+
+*/
+
+// Prevent loading this file directly
+defined( 'ABSPATH' ) || exit;
+
+define( 'PM4WP_DIR', plugin_dir_path( __FILE__ ) );
+define( 'PM4WP_INC_DIR', trailingslashit( PM4WP_DIR . 'inc' ) );
+
+define( 'PM4WP_URL', plugin_dir_url( __FILE__ ) );
+define( 'PM4WP_CSS_URL', trailingslashit( PM4WP_URL . 'css' ) );
+define( 'PM4WP_JS_URL', trailingslashit( PM4WP_URL . 'js' ) );
+
+include_once PM4WP_INC_DIR . 'widget.php';
+include_once PM4WP_INC_DIR . 'inbox-page.php';
+include_once PM4WP_INC_DIR . 'send-page.php';
+include_once PM4WP_INC_DIR . 'outbox-page.php';
+
+if ( is_admin() )
+{
+ include_once PM4WP_INC_DIR . 'options.php';
+}
+
+register_activation_hook( __FILE__, 'rwpm_activate' );
+add_action( 'plugins_loaded', 'rwpm_load_text_domain' );
+add_action( 'admin_notices', 'rwpm_notify' );
+add_action( 'admin_bar_menu', 'rwpm_adminbar', 300 );
+add_action( 'wp_ajax_rwpm_get_users', 'rwpm_get_users' );
+
+/**
+ * Load plugin text domain
+ *
+ * @return void
+ */
+function rwpm_load_text_domain()
+{
+ load_plugin_textdomain( 'pm4wp', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
+}
+
+/**
+ * Create table and register an option when activate
+ *
+ * @return void
+ */
+function rwpm_activate()
+{
+ global $wpdb;
+
+ // Create table
+ $query = 'CREATE TABLE IF NOT EXISTS ' . $wpdb->prefix . 'pm (
+ `id` bigint(20) NOT NULL auto_increment,
+ `subject` text NOT NULL,
+ `content` text NOT NULL,
+ `sender` varchar(60) NOT NULL,
+ `recipient` varchar(60) NOT NULL,
+ `date` datetime NOT NULL,
+ `read` tinyint(1) NOT NULL,
+ `deleted` tinyint(1) NOT NULL,
+ PRIMARY KEY (`id`)
+ ) COLLATE utf8_general_ci;';
+
+ // Note: deleted = 1 if message is deleted by sender, = 2 if it is deleted by recipient
+
+ $wpdb->query( $query );
+
+ // Default numbers of PM for each group
+ $default_option = array(
+ 'administrator' => 0,
+ 'editor' => 50,
+ 'author' => 20,
+ 'contributor' => 10,
+ 'subscriber' => 5,
+ 'type' => 'dropdown', // How to choose recipient: dropdown list or autocomplete based on user input
+ 'email_enable' => 1,
+ 'email_name' => '%BLOG_NAME%',
+ 'email_address' => '%BLOG_ADDRESS%',
+ 'email_subject' => __( 'New PM at %BLOG_NAME%', 'pm4wp' ),
+ 'email_body' => __( "You have new private message from <b>%SENDER%</b> at <b>%BLOG_NAME%</b>.\n\n<a href=\"%INBOX_URL%\">Click here</a> to go to your inbox.\n\nThis email is sent automatically. Please don't reply.", 'pm4wp' )
+ );
+ add_option( 'rwpm_option', $default_option, '', 'no' );
+}
+
+/**
+ * Show notification of new PM
+ */
+function rwpm_notify()
+{
+ global $wpdb, $current_user;
+
+ // get number of unread messages
+ $num_unread = (int) $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'pm WHERE `recipient` = "' . $current_user->user_login . '" AND `read` = 0 AND `deleted` != "2"' );
+
+ if ( !$num_unread )
+ return;
+
+ printf(
+ '<div id="message" class="error"><p><b>%s</b> <a href="%s">%s</a></p></div>',
+ sprintf( _n( 'You have %d new message!', 'You have %d new messages!', $num_unread, 'pm4wp' ), $num_unread ),
+ admin_url( 'admin.php?page=rwpm_inbox' ),
+ __( 'Click here to go to inbox', 'pm4wp' )
+ );
+}
+
+/**
+ * Show number of unread messages in admin bar
+ */
+function rwpm_adminbar()
+{
+ global $wp_admin_bar;
+ global $wpdb, $current_user;
+
+ // get number of unread messages
+ $num_unread = (int) $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'pm WHERE `recipient` = "' . $current_user->user_login . '" AND `read` = 0 AND `deleted` != "2"' );
+
+ if ( $num_unread && is_admin_bar_showing() )
+ {
+ $wp_admin_bar->add_menu( array(
+ 'id' => 'rwpm',
+ 'title' => sprintf( _n( 'You have %d new message!', 'You have %d new messages!', $num_unread, 'pm4wp' ), $num_unread ),
+ 'href' => admin_url( 'admin.php?page=rwpm_inbox' ),
+ 'meta' => array( 'class' => "rwpm_newmessages" ),
+ ) );
+ }
+}
+
+/**
+ * Ajax callback function to get list of users
+ */
+function rwpm_get_users()
+{
+ $keyword = trim( strip_tags( $_POST['term'] ) );
+ $values = array();
+ $args = array( 'search' => '*' . $keyword . '*',
+ 'fields' => 'all_with_meta' );
+ $results_search_users = get_users( $args );
+ $results_search_users = apply_filters( 'rwpm_recipients', $results_search_users );
+ if ( !empty( $results_search_users ) )
+ {
+ foreach ( $results_search_users as $result )
+ {
+ $values[] = $result->display_name;
+ }
+ }
+ die( json_encode( $values ) );
+}

0 comments on commit 55bfa0e

Please sign in to comment.
Something went wrong with that request. Please try again.