コード例 #1
0
ファイル: get_entries.php プロジェクト: RainGrid/site
function gwolle_gb_get_entries($args = array())
{
    global $wpdb;
    $where = " 1 = %d";
    $values = array(1);
    if (!is_array($args)) {
        return false;
    }
    if (isset($args['checked'])) {
        if ($args['checked'] == 'checked' || $args['checked'] == 'unchecked') {
            $where .= "\n\t\t\t\tAND\n\t\t\t\tischecked = %d";
            if ($args['checked'] == 'checked') {
                $values[] = 1;
            } else {
                if ($args['checked'] == 'unchecked') {
                    $values[] = 0;
                }
            }
        }
    }
    if (isset($args['spam'])) {
        if ($args['spam'] == 'spam' || $args['spam'] == 'nospam') {
            $where .= "\n\t\t\t\tAND\n\t\t\t\tisspam = %d";
            if ($args['spam'] == 'spam') {
                $values[] = 1;
            } else {
                if ($args['spam'] == 'nospam') {
                    $values[] = 0;
                }
            }
        }
    }
    if (isset($args['trash'])) {
        if ($args['trash'] == 'trash' || $args['trash'] == 'notrash') {
            $where .= "\n\t\t\t\tAND\n\t\t\t\tistrash = %d";
            if ($args['trash'] == 'trash') {
                $values[] = 1;
            } else {
                if ($args['trash'] == 'notrash') {
                    $values[] = 0;
                }
            }
        }
    }
    if (isset($args['author_id'])) {
        $where .= "\n\t\t\tAND\n\t\t\tauthor_id = %d";
        $values[] = (int) $args['author_id'];
    }
    if (isset($args['email'])) {
        $where .= "\n\t\t\tAND\n\t\t\tauthor_email = %s";
        $values[] = $args['email'];
    }
    if (isset($args['no_moderators'])) {
        $no_moderators = $args['no_moderators'];
        if ($no_moderators === 'true') {
            $users = gwolle_gb_get_moderators();
            if (is_array($users) && !empty($users)) {
                foreach ($users as $user_info) {
                    $where .= "\n\t\t\t\t\t\tAND\n\t\t\t\t\t\tauthor_id != %d";
                    $values[] = $user_info->ID;
                }
            }
        }
    }
    if (isset($args['book_id'])) {
        $where .= "\n\t\t\tAND\n\t\t\tbook_id = %d";
        $values[] = (int) $args['book_id'];
    }
    // Offset
    $offset = " OFFSET 0 ";
    // default
    if (isset($args['offset']) && (int) $args['offset'] > 0) {
        $offset = " OFFSET " . (int) $args['offset'];
    }
    // Limit
    if (is_admin()) {
        $perpage_option = (int) get_option('gwolle_gb-entries_per_page', 20);
    } else {
        $perpage_option = (int) get_option('gwolle_gb-entriesPerPage', 20);
    }
    $limit = " LIMIT " . $perpage_option;
    // default
    if (isset($args['num_entries']) && (int) $args['num_entries'] > 0) {
        $limit = " LIMIT " . (int) $args['num_entries'];
    } else {
        if (isset($args['num_entries']) && (int) $args['num_entries'] == -1) {
            $limit = ' LIMIT 999999999999999 ';
            $offset = ' OFFSET 0 ';
        }
    }
    $tablename = $wpdb->prefix . "gwolle_gb_entries";
    $sql = "\n\t\t\tSELECT\n\t\t\t\t`id`,\n\t\t\t\t`author_name`,\n\t\t\t\t`author_id`,\n\t\t\t\t`author_email`,\n\t\t\t\t`author_origin`,\n\t\t\t\t`author_website`,\n\t\t\t\t`author_ip`,\n\t\t\t\t`author_host`,\n\t\t\t\t`content`,\n\t\t\t\t`datetime`,\n\t\t\t\t`ischecked`,\n\t\t\t\t`checkedby`,\n\t\t\t\t`istrash`,\n\t\t\t\t`isspam`,\n\t\t\t\t`admin_reply`,\n\t\t\t\t`admin_reply_uid`,\n\t\t\t\t`book_id`\n\t\t\tFROM\n\t\t\t\t" . $tablename . "\n\t\t\tWHERE\n\t\t\t\t" . $where . "\n\t\t\tORDER BY\n\t\t\t\tdatetime DESC\n\t\t\t" . $limit . " " . $offset . "\n\t\t\t;";
    $sql = $wpdb->prepare($sql, $values);
    $datalist = $wpdb->get_results($sql, ARRAY_A);
    //$wpdb->print_error();
    //echo "number of rows: " . $wpdb->num_rows;
    if (is_array($datalist) && !empty($datalist)) {
        $entries = array();
        foreach ($datalist as $data) {
            // Use the fields that the setter method expects
            $item = array('id' => (int) $data['id'], 'author_name' => stripslashes($data['author_name']), 'author_id' => (int) $data['author_id'], 'author_email' => stripslashes($data['author_email']), 'author_origin' => stripslashes($data['author_origin']), 'author_website' => stripslashes($data['author_website']), 'author_ip' => $data['author_ip'], 'author_host' => $data['author_host'], 'content' => stripslashes($data['content']), 'datetime' => $data['datetime'], 'ischecked' => (int) $data['ischecked'], 'checkedby' => (int) $data['checkedby'], 'istrash' => (int) $data['istrash'], 'isspam' => (int) $data['isspam'], 'admin_reply' => stripslashes($data['admin_reply']), 'admin_reply_uid' => (int) $data['admin_reply_uid'], 'book_id' => (int) $data['book_id']);
            $entry = new gwolle_gb_entry();
            $entry->set_data($item);
            // Add entry to the array of all entries
            $entries[] = $entry;
        }
        return $entries;
    }
    return false;
}
コード例 #2
0
ファイル: emailtab.php プロジェクト: RainGrid/site
function gwolle_gb_page_settingstab_email()
{
    if (function_exists('current_user_can') && !current_user_can('manage_options')) {
        die(__('Cheatin’ uh?', 'gwolle-gb'));
    }
    ?>

	<input type="hidden" id="gwolle_gb_tab" name="gwolle_gb_tab" value="gwolle_gb_mail" />
	<?php 
    settings_fields('gwolle_gb_options');
    do_settings_sections('gwolle_gb_options');
    ?>
	<table class="form-table">
		<tbody>

		<tr valign="top">
			<th scope="row"><label for="admin_mail_from"><?php 
    _e('Admin mail from address', 'gwolle-gb');
    ?>
</label></th>
			<td>
				<input type="email" name="admin_mail_from" id="admin_mail_from" class="regular-text" value="<?php 
    echo gwolle_gb_sanitize_output(get_option('gwolle_gb-mail-from', false));
    ?>
" placeholder="*****@*****.**" />
				<br />
				<span class="setting-description">
					<?php 
    _e('You can set the email address that is used for the From header of the mail that a notification subscriber gets on new entries.', 'gwolle-gb');
    echo '<br />';
    _e('By default the main admin address is used from General >> Settings.', 'gwolle-gb');
    ?>
				</span>
			</td>
		</tr>

		<tr valign="top">
			<th scope="row"><label for="unsubscribe"><?php 
    _e('Unsubscribe moderators', 'gwolle-gb');
    ?>
</label></th>
			<td>
				<?php 
    // Check if function mail() exists. If not, display a hint to the user.
    if (!function_exists('mail')) {
        echo '<p class="setting-description">' . __('Sorry, but the function <code>mail()</code> required to notify you by mail is not enabled in your PHP configuration. You might want to install a WordPress plugin that uses SMTP instead of <code>mail()</code>. Or you can contact your hosting provider to change this.', 'gwolle-gb') . '</p>';
    }
    ?>
				<select name="unsubscribe" id="unsubscribe">
					<option value="0"><?php 
    _e('Unsubscribe User', 'gwolle-gb');
    ?>
</option>
					<?php 
    $user_ids = get_option('gwolle_gb-notifyByMail');
    if (strlen($user_ids) > 0) {
        $user_ids = explode(",", $user_ids);
        if (is_array($user_ids) && !empty($user_ids)) {
            foreach ($user_ids as $user_id) {
                $user_info = get_userdata($user_id);
                if ($user_info === FALSE) {
                    // Invalid $user_id
                    continue;
                }
                $username = $user_info->first_name . ' ' . $user_info->last_name . ' (' . $user_info->user_email . ')';
                if ($user_info->ID == get_current_user_id()) {
                    $username .= ' ' . __('You', 'gwolle-gb');
                }
                echo '<option value="' . $user_id . '">' . $username . '</option>';
            }
        }
    }
    ?>
				</select><br />
				<label for="unsubscribe"><?php 
    _e('These users have subscribed to the notification emails.', 'gwolle-gb');
    ?>
<br />
				<?php 
    _e('Select a user if you want that user to unsubscribe from the notification emails.', 'gwolle-gb');
    ?>
</label>
			</td>
		</tr>

		<tr valign="top">
			<th scope="row"><label for="subscribe"><?php 
    _e('Subscribe moderators', 'gwolle-gb');
    ?>
</label></th>
			<td>
				<select name="subscribe" id="subscribe">
					<option value="0"><?php 
    _e('Subscribe User', 'gwolle-gb');
    ?>
</option>
					<?php 
    $users = gwolle_gb_get_moderators();
    if (is_array($users) && !empty($users)) {
        foreach ($users as $user_info) {
            // Test if already subscribed
            if (is_array($user_ids) && !empty($user_ids)) {
                if (in_array($user_info->ID, $user_ids)) {
                    continue;
                }
            }
            $username = $user_info->first_name . ' ' . $user_info->last_name . ' (' . $user_info->user_email . ')';
            if ($user_info->ID == get_current_user_id()) {
                $username .= ' ' . __('You', 'gwolle-gb');
            }
            echo '<option value="' . $user_info->ID . '">' . $username . '</option>';
        }
    }
    ?>
				</select><br />
				<label for="subscribe"><?php 
    _e('You can subscribe a moderator to the notification emails.', 'gwolle-gb');
    ?>
<br />
				<?php 
    _e('Select a user that you want subscribed to the notification emails.', 'gwolle-gb');
    ?>
				<?php 
    _e("You will only see users with the roles of Administrator, Editor and Author, who have the capability 'moderate_comments' .", 'gwolle-gb');
    ?>
				</label>
			</td>
		</tr>

		<tr valign="top">
			<th scope="row"><label for="adminMailContent"><?php 
    _e('Admin mail content', 'gwolle-gb');
    ?>
</label></th>
			<td>
				<?php 
    $mailText = gwolle_gb_sanitize_output(get_option('gwolle_gb-adminMailContent', false));
    if (!$mailText) {
        // No text set by the user. Use the default text.
        $mailText = __("\nHello,\n\nThere is a new guestbook entry at '%blog_name%'.\nYou can check it at %entry_management_url%.\n\nHave a nice day.\nYour Gwolle-GB-Mailer\n\n\nWebsite address: %blog_url%\nUser name: %user_name%\nUser email: %user_email%\nEntry status: %status%\nEntry content:\n%entry_content%\n", 'gwolle-gb');
    }
    ?>
				<textarea name="adminMailContent" id="adminMailContent" style="width:400px;height:300px;" class="regular-text"><?php 
    echo $mailText;
    ?>
</textarea>
				<br />
				<span class="setting-description">
					<?php 
    _e('You can set the content of the mail that a notification subscriber gets on new entries. The following tags are supported:', 'gwolle-gb');
    echo '<br />';
    $mailTags = array('user_email', 'user_name', 'entry_management_url', 'blog_name', 'blog_url', 'wp_admin_url', 'entry_content', 'status', 'author_ip');
    for ($i = 0; $i < count($mailTags); $i++) {
        if ($i != 0) {
            echo ', ';
        }
        echo '%' . $mailTags[$i] . '%';
    }
    echo ".";
    ?>
				</span>
			</td>
		</tr>

		<tr valign="top">
			<th scope="row"><label for="mail_author"><?php 
    _e('Mail Author', 'gwolle-gb');
    ?>
</label></th>
			<td>
				<input <?php 
    if (get_option('gwolle_gb-mail_author', 'false') == 'true') {
        echo 'checked="checked"';
    }
    ?>
					type="checkbox" name="mail_author" id="mail_author">
				<label for="mail_author">
					<?php 
    _e('Mail the author with a confirmation email.', 'gwolle-gb');
    ?>
				</label>
				<br />
				<span class="setting-description">
					<?php 
    _e("The author of the guestbook entry will receive an email after posting. It will have a copy of the entry.", 'gwolle-gb');
    ?>
				</span>
			</td>
		</tr>

		<tr valign="top">
			<th scope="row"><label for="authorMailContent"><?php 
    _e('Author mail content', 'gwolle-gb');
    ?>
</label></th>
			<td>
				<?php 
    $mailText = gwolle_gb_sanitize_output(get_option('gwolle_gb-authorMailContent', false));
    if (!$mailText) {
        // No text set by the user. Use the default text.
        $mailText = __("\nHello,\n\nYou have just posted a new guestbook entry at '%blog_name%'.\n\nHave a nice day.\nThe editors at %blog_name%.\n\n\nWebsite address: %blog_url%\nUser name: %user_name%\nUser email: %user_email%\nEntry content:\n%entry_content%\n", 'gwolle-gb');
    }
    ?>
				<textarea name="authorMailContent" id="authorMailContent" style="width:400px;height:300px;" class="regular-text"><?php 
    echo $mailText;
    ?>
</textarea>
				<br />
				<span class="setting-description">
					<?php 
    _e('You can set the content of the mail that the author of the entry will receive. The following tags are supported:', 'gwolle-gb');
    echo '<br />';
    $mailTags = array('user_email', 'user_name', 'blog_name', 'blog_url', 'entry_content');
    for ($i = 0; $i < count($mailTags); $i++) {
        if ($i != 0) {
            echo ', ';
        }
        echo '%' . $mailTags[$i] . '%';
    }
    ?>
				</span>
			</td>
		</tr>

		<tr valign="top">
			<th scope="row"><label for="gwolle_gb-mail_admin_replyContent"><?php 
    _e('Admin Reply mail content', 'gwolle-gb');
    ?>
</label></th>
			<td>
				<?php 
    $mailText = gwolle_gb_sanitize_output(get_option('gwolle_gb-mail_admin_replyContent', false));
    if (!$mailText) {
        // No text set by the user. Use the default text.
        $mailText = __("\nHello,\n\nAn admin has just added or changed a reply message to your guestbook entry at '%blog_name%'.\n\nHave a nice day.\nThe editors at %blog_name%.\n\n\nWebsite address: %blog_url%\nAdmin Reply:\n%admin_reply%\n", 'gwolle-gb');
    }
    ?>
				<textarea name="gwolle_gb-mail_admin_replyContent" id="gwolle_gb-mail_admin_replyContent" style="width:400px;height:300px;" class="regular-text"><?php 
    echo $mailText;
    ?>
</textarea>
				<br />
				<span class="setting-description">
					<?php 
    _e('You can set the content of the mail that the author of the entry will receive when an Admin Reply is added. The following tags are supported:', 'gwolle-gb');
    echo '<br />';
    $mailTags = array('user_email', 'user_name', 'blog_name', 'blog_url', 'admin_reply');
    for ($i = 0; $i < count($mailTags); $i++) {
        if ($i != 0) {
            echo ', ';
        }
        echo '%' . $mailTags[$i] . '%';
    }
    ?>
				</span>
			</td>
		</tr>

		<tr>
			<td colspan="2">
				<p class="submit">
					<input type="submit" name="gwolle_gb_settings_email" id="gwolle_gb_settings_email" class="button-primary" value="<?php 
    esc_attr_e('Save settings', 'gwolle-gb');
    ?>
" />
				</p>
			</td>
		</tr>

		</tbody>
	</table>

	<?php 
}