コード例 #1
0
ファイル: stray_new.php プロジェクト: rodrigoprimo/yogamitra
function stray_new()
{
    global $wpdb, $current_user;
    //load options
    $quotesoptions = array();
    $quotesoptions = get_option('stray_quotes_options');
    //security check
    if ($quotesoptions['stray_multiuser'] == false && !current_user_can('manage_options')) {
        die('Access Denied');
    }
    //decode and intercept
    foreach ($_POST as $key => $val) {
        $_POST[$key] = stripslashes($val);
    }
    // control the requests
    $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
    $quoteID = !empty($_REQUEST['quoteID']) ? $_REQUEST['quoteID'] : '';
    //this is for the bookmarklet
    if ($action == 'bookmarklet') {
        $quotesoptions = array();
        $quotesoptions = get_option('stray_quotes_options');
        $quote = !empty($_REQUEST['quote_quote']) ? stripslashes(trim($_REQUEST['quote_quote'])) : '';
        if ($quotesoptions['bookmarlet_source'] == 'Y') {
            $source = !empty($_REQUEST['quote_source']) ? stripslashes(trim($_REQUEST['quote_source'])) : '';
        }
        if ($quotesoptions['bookmarklet_cat']) {
            $category = $quotesoptions['bookmarklet_cat'];
        }
    }
    //after adding a new quote
    if ($action == 'add') {
        //assign variables and trim them
        $quote = !empty($_REQUEST['quote_quote']) ? trim($_REQUEST['quote_quote']) : '';
        $author = !empty($_REQUEST['quote_author']) ? trim($_REQUEST['quote_author']) : '';
        $source = !empty($_REQUEST['quote_source']) ? trim($_REQUEST['quote_source']) : '';
        $visible = !empty($_REQUEST['quote_visible']) ? trim($_REQUEST['quote_visible']) : '';
        if ($_REQUEST['quote_category']) {
            $category = trim($_REQUEST['quote_category']);
        } else {
            $category = $_REQUEST['categories'];
        }
        //remove spaces from categories
        if (preg_match('/\\s+/', $category) > 0) {
            $category = preg_replace('/\\s+/', '-', $category);
            $plusmessage = "<br/>Note: <strong>The name of the category you created contained spaces</strong>, which are not allowed. <strong>I replaced them with dashes</strong>. I hope it's okay.";
        }
        if ($category == false || $category == '') {
            $category = 'default';
        }
        //take care of stupid magic quotes
        if (ini_get('magic_quotes_gpc')) {
            $quote = stripslashes($quote);
            $author = stripslashes($author);
            $source = stripslashes($source);
            $category = stripslashes($category);
            $visible = stripslashes($visible);
        }
        //insert the quote into the database!!
        $sql = "insert into " . WP_STRAY_QUOTES_TABLE . " set `quote`='" . mysql_real_escape_string($quote) . "', `author`='" . mysql_real_escape_string($author) . "', `source`='" . mysql_real_escape_string($source) . "', `category`='" . mysql_real_escape_string($category) . "', `visible`='" . mysql_real_escape_string($visible) . "', `user`='" . mysql_real_escape_string($current_user->user_nicename) . "'";
        $wpdb->get_results($sql);
        //check: go and get the quote just inserted
        $sql2 = "select `quoteID` from " . WP_STRAY_QUOTES_TABLE . " where `quote`='" . mysql_real_escape_string($quote) . "' and `author`='" . mysql_real_escape_string($author) . "' and `source`='" . mysql_real_escape_string($source) . "' and `category`='" . mysql_real_escape_string($category) . "' and `visible`='" . mysql_real_escape_string($visible) . "' and `user`='" . mysql_real_escape_string($current_user->user_nicename) . "' limit 1";
        $result = $wpdb->get_results($sql2);
        //failure message
        if (empty($result) || empty($result[0]->quoteID)) {
            ?>
<div class="error fade"><p><?php 
            _e('<strong>Failure:</strong> Something went wrong when trying to insert the quote. Try again?', 'stray-quotes');
            ?>
</p></div><?php 
        } else {
            ?>
<div class="updated fade"><p><?php 
            $search = array("%s1", "%s2");
            $replace = array($result[0]->quoteID, get_option("siteurl") . '/wp-admin/admin.php?page=stray_manage');
            echo str_replace($search, $replace, __('Quote no. <strong>%s1</strong> was added to the database. To insert it in a post use: <code>[stray-id id=%s1]</code>. To review use the <a href="%s2">Manage page</a>.' . $plusmessage, 'stray-quotes'));
            ?>
</p></div><?php 
        }
    }
    //making the "add new quote" page
    ?>
<div class="wrap"><h2><?php 
    _e('Add new quote', 'stray-quotes');
    ?>
</h2><?php 
    //housecleaning
    $quoteID = false;
    $data = false;
    //get the last inserted quote
    if ($quoteID !== false) {
        if (intval($quoteID) != $quoteID) {
            ?>
<div class="error fade"><p><?php 
            _e('The Quote ID seems to be invalid.', 'stray-quotes');
            ?>
</p></div><?php 
            return;
        } else {
            $data = $wpdb->get_results("select * from " . WP_STRAY_QUOTES_TABLE . " where quoteID='" . mysql_real_escape_string($quoteID) . "' limit 1");
            if (empty($data)) {
                ?>
<div class="error fade"><p><?php 
                _e('Something is wrong. Sorry.', 'stray-quotes');
                ?>
</p></div><?php 
                return;
            }
            $data = $data[0];
        }
    }
    //optionally assign the just inserted quote to vaiables
    if ($quotesoptions['stray_clear_form'] !== 'Y') {
        if (!empty($data)) {
            $quote = $data->quote;
            $author = $data->author;
            $source = $data->source;
            $category = $data->category;
        }
    } else {
        if ($action != 'bookmarklet') {
            $quote = $author = $source = $category = false;
        }
    }
    //visibility
    $defaultVisible = $quotesoptions['stray_quotes_default_visible'];
    if (empty($data)) {
        if ($defaultVisible == 'Y') {
            $visible_yes = "checked";
            $visible_no = "";
        } else {
            $visible_yes = "";
            $visible_no = "checked";
        }
    } else {
        if ($data->visible == 'yes') {
            $visible_yes = "checked";
            $visible_no = "";
        } else {
            $visible_yes = "";
            $visible_no = "checked";
        }
    }
    //default category
    $defaultcategory = $quotesoptions['stray_default_category'];
    //make the "add new quote" form
    $styleborder = 'style="border:1px solid #ccc"';
    $styletextarea = 'style="border:1px solid #ccc; font-family: Times New Roman, Times, serif; font-size: 1.4em;"';
    ?>
		
		<div style="width:42em">
		<script src="<?php 
    echo WP_STRAY_QUOTES_PATH;
    ?>
inc/stray_quicktags.js" type="text/javascript"></script>
		<form name="quoteform" id="quoteform" method="post" action="<?php 
    echo $_SERVER['REQUEST_URI'];
    ?>
">
			<input type="hidden" name="action" value="add">
			<input type="hidden" name="quoteID" value="<?php 
    echo $quoteID;
    ?>
">
		
			<p><!--<label><?php 
    _e('Quote:', 'stray-quotes');
    ?>
</label>-->
			<script type="text/javascript">edToolbar();</script>
			<textarea id="qeditor" name="quote_quote" <?php 
    echo $styletextarea;
    ?>
 cols=68 rows=7><?php 
    echo $quote;
    ?>
</textarea>
			<script type="text/javascript">var edCanvas = document.getElementById('qeditor');</script>
			<p class="setting-description"><small><?php 
    _e('* Other than the few offered in the toolbar above, many HTML and non-HTML formatting elements can be used for the quote. Lines can be broken traditionally or using <code>&lt;br/&gt;</code>, etcetera.', 'stray-quotes');
    ?>
</small></p></p>
			
			<p><label><?php 
    _e('Author:', 'stray-quotes');
    ?>
</label>
			<input type="text" id="aeditor" name="quote_author" size=58 value="<?php 
    echo htmlspecialchars($author);
    ?>
" <?php 
    echo $styleborder;
    ?>
 />
			<script type="text/javascript">edToolbar1();</script>
			<script type="text/javascript">var edCanvas1 = document.getElementById('aeditor');</script><br />
		
			<label><?php 
    _e('Source:', 'stray-quotes');
    ?>
</label>
			<input type="text" id="seditor" name="quote_source" size=58 value="<?php 
    echo htmlspecialchars($source);
    ?>
" <?php 
    echo $styleborder;
    ?>
 />
			<script type="text/javascript">edToolbar2();</script>
			<script type="text/javascript">var edCanvas2 = document.getElementById('seditor');</script>
			<p class="setting-description"><small><?php 
    _e('* By adding a link to the author or the source, the default links specified on the settings page are ignored. Make sure the link is closed by a <code>&lt;/a&gt;</code> tag.', 'stray-quotes');
    ?>
</small></p></p>
			
			<p><label><?php 
    _e('Category:&nbsp;', 'stray-quotes');
    ?>
</label>				
			<select name="categories" style="vertical-align:middle; width:14em;" > 
			<?php 
    $categorylist = make_categories($current_user->user_nicename);
    foreach ($categorylist as $categoryo) {
        ?>
			<option value="<?php 
        echo $categoryo;
        ?>
" style=" padding-right:5px" 
			<?php 
        if ($categoryo == $category || $categoryo == $defaultcategory) {
            echo ' selected';
        }
        ?>
 >
			<?php 
        echo $categoryo;
        ?>
</option>
			<?php 
    }
    ?>
   
			</select>
			  
			<label><?php 
    _e('&nbsp;new category:&nbsp;', 'stray-quotes');
    ?>
</label>
			<input type="text" name="quote_category" size=24 value="" <?php 
    echo $styleborder;
    ?>
 /></p>
			
			<p><label><?php 
    _e('Visible:', 'stray-quotes');
    ?>
</label>
				<input type="radio" name="quote_visible" class="input" value="yes"<?php 
    echo $visible_yes;
    ?>
 /> <?php 
    _e('Yes', 'stray-quotes');
    ?>
					
				<input type="radio" name="quote_visible" class="input" value="no"<?php 
    echo $visible_no;
    ?>
 /> <?php 
    _e('No', 'stray-quotes');
    ?>
			</p><p>&nbsp;</p>
		
			<p><input type="submit" name="save"  class="button-primary" value="<?php 
    _e('Add quote', 'stray-quotes');
    ?>
 &raquo;" /></p>
		</form></div>
        
	</div><?php 
}
コード例 #2
0
function stray_manage()
{
    global $wpdb, $current_user;
    //load options
    $quotesoptions = get_option('stray_quotes_options');
    //security check
    if ($quotesoptions['stray_multiuser'] == false && !current_user_can('manage_options')) {
        die('Access Denied');
    }
    //decode and intercept
    foreach ($_POST as $key => $val) {
        $_POST[$key] = stripslashes($val);
    }
    //defaults and gets
    $action = !empty($_REQUEST['qa']) ? $_REQUEST['qa'] : '';
    $quoteID = !empty($_REQUEST['qi']) ? $_REQUEST['qi'] : '';
    $orderby = $quotesoptions['stray_quotes_order'];
    $pages = 1;
    $rows = $quotesoptions['stray_quotes_rows'];
    $categories = $quotesoptions['stray_quotes_categories'];
    $sort = $quotesoptions['stray_quotes_sort'];
    if (isset($_GET['qo'])) {
        $orderby = $_GET['qo'];
        $quotesoptions['stray_quotes_order'] = $_GET['qo'];
    }
    if (isset($_GET['qp'])) {
        $pages = $_GET['qp'];
    }
    if (isset($_GET['qr'])) {
        $rows = $_GET['qr'];
        $quotesoptions['stray_quotes_rows'] = $_GET['qr'];
    }
    if (isset($_GET['qc'])) {
        $categories = $_GET['qc'];
        $quotesoptions['stray_quotes_categories'] = $_GET['qc'];
    }
    if (isset($_GET['qs'])) {
        $sort = $_GET['qs'];
        $quotesoptions['stray_quotes_sort'] = $_GET['qs'];
    }
    $offset = ($pages - 1) * $rows;
    //check if the category I want exists
    $ok = false;
    $categorylist = make_categories();
    foreach ($categorylist as $category) {
        if ($category == $categories) {
            $ok = true;
        }
    }
    if ($ok == false) {
        $categories = 'all';
        $quotesoptions['stray_quotes_categories'] = 'all';
    }
    //update options now
    update_option('stray_quotes_options', $quotesoptions);
    //add variables to the url -- for different uses -- thanks to frettsy who suggested this use
    $baseurl = get_option("siteurl") . '/wp-admin/admin.php?page=stray_manage';
    $baseurl = querystrings($baseurl, 'qo', $orderby);
    $baseurl = querystrings($baseurl, 'qp', $pages);
    $baseurl = querystrings($baseurl, 'qr', $rows);
    $baseurl = querystrings($baseurl, 'qc', $categories);
    $urlaction = querystrings($baseurl, 'qs', $sort);
    //action: edit the quote
    if ($action == 'edit') {
        ?>
<div class="wrap"><h2><?php 
        _e('Edit quote ' . $quoteID, 'stray-quotes');
        ?>
</h2><?php 
        //check if something went wrong with quote id
        if (empty($quoteID)) {
            ?>
<div id="message" class="error"><p><?php 
            _e('Something is wrong. No quote ID from the query string.', 'stray-quotes');
            ?>
</p></div><?php 
        } else {
            //query
            $data = $wpdb->get_results("select * from " . WP_STRAY_QUOTES_TABLE . " where quoteID='" . mysql_real_escape_string($quoteID) . "' limit 1");
            //bad feedback
            if (empty($data)) {
                ?>
<div id="message" class="error"><p><?php 
                _e('Something is wrong. I can\'t find a quote linked up with that ID.', 'stray-quotes');
                ?>
</p></div><?php 
                return;
            }
            $data = $data[0];
            //encode strings
            if (!empty($data)) {
                $quote = htmlspecialchars($data->quote);
            }
            if (!empty($data)) {
                $author = htmlspecialchars($data->author);
            }
            if (!empty($data)) {
                $source = htmlspecialchars($data->source);
            }
            if (!empty($data)) {
                $category = htmlspecialchars($data->category);
            }
            //set visibility
            $defaultVisible = get_option('stray_quotes_default_visible');
            if (empty($data)) {
                if ($defaultVisible == 'Y') {
                    $visible_yes = "checked";
                    $visible_no = "";
                } else {
                    $visible_yes = "";
                    $visible_no = "checked";
                }
            } else {
                if ($data->visible == 'yes') {
                    $visible_yes = "checked";
                    $visible_no = "";
                } else {
                    $visible_yes = "";
                    $visible_no = "checked";
                }
            }
            //make the edit form
            $styleborder = 'style="border:1px solid #ccc"';
            $styletextarea = 'style="border:1px solid #ccc; font-family: Times New Roman, Times, serif; font-size: 1.4em;"';
            ?>
            <div style="width:42em">
			<script src="<?php 
            echo WP_STRAY_QUOTES_PATH;
            ?>
inc/stray_quicktags.js" type="text/javascript"></script>
            <form name="quoteform" id="quoteform" method="post" action="<?php 
            echo $_SERVER['REQUEST_URI'];
            ?>
">
				<input type="hidden" name="qa" value="edit_save">
				<input type="hidden" name="qi" value="<?php 
            echo $quoteID;
            ?>
">
			
				<p><!--<label><?php 
            _e('Quote:', 'stray-quotes');
            ?>
</label><br />-->
                <div style="float:left"><script type="text/javascript">edToolbar();</script></div>
                <div style="float:right; display:compact;margin-top:12px"><small><?php 
            _e('To insert this quote in a post use:', 'stray-quotes');
            ?>
 <code>[quote id=<?php 
            echo $quoteID;
            ?>
]</code></small></div>
                <textarea id="qeditor" name="quote_quote" <?php 
            echo $styletextarea;
            ?>
 cols=68 rows=7><?php 
            echo $quote;
            ?>
</textarea></p>
				<script type="text/javascript">var edCanvas = document.getElementById('qeditor');</script>
                <p class="setting-description"><small><?php 
            _e('* Other than the few offered in the toolbar above, many HTML and non-HTML formatting elements can be used for the quote. Lines can be broken traditionally or using <code>&lt;br/&gt;</code>, etcetera.', 'stray-quotes');
            ?>
</small></p></p>
                
				<p><label><?php 
            _e('Author:', 'stray-quotes');
            ?>
</label>
                <input type="text" id="aeditor" name="quote_author" size=58 value="<?php 
            echo $author;
            ?>
" <?php 
            echo $styleborder;
            ?>
 />
				<script type="text/javascript">edToolbar1();</script>
                <script type="text/javascript">var edCanvas1 = document.getElementById('aeditor');</script><br />
				
				<label><?php 
            _e('Source:', 'stray-quotes');
            ?>
</label>
                <input type="text" id="seditor" name="quote_source" size=58 value="<?php 
            echo $source;
            ?>
" <?php 
            echo $styleborder;
            ?>
 />
				<script type="text/javascript">edToolbar2();</script>
                <script type="text/javascript">var edCanvas2 = document.getElementById('seditor');</script>
                <p class="setting-description"><small><?php 
            _e('* By adding a link to the author or the source, the default links specified on the settings page are ignored. Make sure the link is closed by a <code>&lt;/a&gt;</code> tag.', 'stray-quotes');
            ?>
</small></p></p>
                
                <p><label><?php 
            _e('Category:&nbsp;', 'stray-quotes');
            ?>
</label>                
                <select name="categories" style="vertical-align:middle; width:14em;"> 
                <?php 
            $categorylist = make_categories($current_user->user_nicename);
            foreach ($categorylist as $categoryo) {
                ?>
                <option value="<?php 
                echo $categoryo;
                ?>
" style=" padding-right:5px"
                <?php 
                if ($categoryo == $category) {
                    echo ' selected';
                }
                ?>
 >
                <?php 
                echo $categoryo;
                ?>
</option>
                <?php 
            }
            ?>
   
                </select>
                  
                <label><?php 
            _e('new category:&nbsp;', 'stray-quotes');
            ?>
</label>
                <input type="text" name="quote_category" size=24 value="" <?php 
            echo $styleborder;
            ?>
 /></p>
                
				<p><label><?php 
            _e('Visible:', 'stray-quotes');
            ?>
</label>
					<input type="radio" name="quote_visible" class="input" value="yes"<?php 
            echo $visible_yes;
            ?>
 /> <?php 
            _e('Yes', 'stray-quotes');
            ?>
					
					<input type="radio" name="quote_visible" class="input" value="no"<?php 
            echo $visible_no;
            ?>
 /> <?php 
            _e('No', 'stray-quotes');
            ?>
				</p><p>&nbsp;</p>
				<p> <a href=" <?php 
            echo $urlaction;
            ?>
"><?php 
            _e('Cancel', 'stray-quotes');
            ?>
</a>&nbsp;
         	   <input type="submit" name="save"  class="button-primary" value="<?php 
            _e('Update quote', 'stray-quotes');
            ?>
 &raquo;" /></p>
			</form><p>&nbsp;</p></div><?php 
        }
    } else {
        //this "else" separates the edit form from the list of quotes. make it a "else if" below to revert to the old ways
        ?>
<div class="wrap">
        <h2><?php 
        _e('Manage quotes', 'stray-quotes');
        ?>
</h2><?php 
        $nothingmessage = __('Please select something first.', 'stray-quotes');
        $wrongmessage = __('Something went wrong.', 'stray-quotes');
        //action: save the quote
        if ($action == 'edit_save') {
            //assign variables, trim, replace spaces
            $quote = !empty($_REQUEST['quote_quote']) ? trim($_REQUEST['quote_quote']) : '';
            $author = !empty($_REQUEST['quote_author']) ? trim($_REQUEST['quote_author']) : '';
            $source = !empty($_REQUEST['quote_source']) ? trim($_REQUEST['quote_source']) : '';
            $visible = !empty($_REQUEST['quote_visible']) ? trim($_REQUEST['quote_visible']) : '';
            if ($_REQUEST['quote_category']) {
                $category = trim($_REQUEST['quote_category']);
            } else {
                $category = $_REQUEST['categories'];
            }
            if (preg_match('/\\s+/', $category) > 0) {
                $category = preg_replace('/\\s+/', '-', $category);
                $plusmessage = "<br/>Note: <strong>The name of the category you created contained spaces</strong>, which are not allowed. <strong>I replaced them with dashes</strong>. I hope it's okay.";
            }
            //magic quotes
            if (ini_get('magic_quotes_gpc')) {
                $quote = stripslashes($quote);
                $author = stripslashes($author);
                $source = stripslashes($source);
                $category = stripslashes($category);
                $visible = stripslashes($visible);
            }
            //negative feedback or UPDATE
            if (empty($quoteID)) {
                ?>
<div id="message" class="error fade"><p><?php 
                _e('<strong>Failure:</strong> No quote ID given.', 'stray-quotes');
                ?>
</p></div><?php 
            } else {
                //update the quote
                $sql = "UPDATE " . WP_STRAY_QUOTES_TABLE . " SET `quote`='" . mysql_real_escape_string($quote) . "', `author`='" . mysql_real_escape_string($author) . "', `source`='" . mysql_real_escape_string($source) . "', `category`='" . mysql_real_escape_string($category) . "', `visible`='" . mysql_real_escape_string($visible) . "', `user`='" . mysql_real_escape_string($current_user->user_nicename) . "' WHERE `quoteID`='" . mysql_real_escape_string($quoteID) . "'";
                $wpdb->get_results($sql);
                //verify what has been udpated
                $sql = "SELECT `quoteID` FROM " . WP_STRAY_QUOTES_TABLE . " WHERE `quote`='" . mysql_real_escape_string($quote) . "' AND `author`='" . mysql_real_escape_string($author) . "' AND `source`='" . mysql_real_escape_string($source) . "' AND `category`='" . mysql_real_escape_string($category) . "' AND `visible`='" . mysql_real_escape_string($visible) . "' AND `user`='" . mysql_real_escape_string($current_user->user_nicename) . "' LIMIT 1";
                $result = $wpdb->get_results($sql);
                //feedback
                if (empty($result) || empty($result[0]->quoteID)) {
                    ?>
<div id="message" class="error fade"><?php 
                    echo $wrongmessage;
                    ?>
</div><?php 
                } else {
                    ?>
<div id="message" class="updated fade"><p>
					<?php 
                    echo str_replace("%s", $quoteID, __('Quote <strong>%s</strong> updated.' . $plusmessage, 'stray-quotes'));
                    ?>
</p></div><?php 
                }
            }
        } else {
            if ($action == 'delete') {
                $sql = "delete from `" . WP_STRAY_QUOTES_TABLE . "` where quoteID='" . mysql_real_escape_string($quoteID) . "'";
                $wpdb->get_results($sql);
                $sql = "select quoteID from `" . WP_STRAY_QUOTES_TABLE . "` where quoteID='" . mysql_real_escape_string($quoteID) . "'";
                $result = $wpdb->get_results($sql);
                if (empty($result) || empty($result[0]->quoteID)) {
                    ?>
<div class="updated"><p><?php 
                    echo str_replace("%s", $quoteID, __('Quote <strong>%s</strong> deleted.', 'stray-quotes'));
                    ?>
</p></div><?php 
                } else {
                    ?>
<div class="error fade"><?php 
                    echo $wrongmessage;
                    ?>
</div><?php 
                }
            } else {
                if ($_POST['bulk'] == 'multidelete') {
                    $deleteIds = '';
                    $count = 0;
                    foreach ($_POST as $key => $val) {
                        if (substr($key, 0, 12) == 'check_select') {
                            $deleteIds .= "'" . $val . "',";
                            $count++;
                        }
                    }
                    $deleteIds = rtrim($deleteIds, ',');
                    $sql = "DELETE FROM `" . WP_STRAY_QUOTES_TABLE . "` WHERE `quoteID` IN(" . $deleteIds . ")";
                    $wpdb->query($sql);
                    $sql2 = "SELECT `quoteID` FROM `" . WP_STRAY_QUOTES_TABLE . "` WHERE `quoteID` IN(" . $deleteIds . ")";
                    $result = $wpdb->get_results($sql2);
                    if ($count == 0) {
                        ?>
<div class="error fade"><?php 
                        echo $nothingmessage;
                        ?>
</div><?php 
                    } else {
                        if (empty($result) || empty($result[0]->quoteID)) {
                            ?>
<div class="updated"><p><?php 
                            echo str_replace("%s", $count, __('<strong>%s</strong> quotes deleted.', 'stray-quotes'));
                            ?>
</p></div><?php 
                        } else {
                            ?>
<div class="error fade"><?php 
                            echo $wrongmessage;
                            ?>
</div><?php 
                        }
                    }
                } else {
                    if ($_POST['bulk'] == 'togglevisible') {
                        $toggleyes = '';
                        $toggleno = '';
                        $count = 0;
                        foreach ($_POST as $key => $val) {
                            if (substr($key, 0, 12) == 'check_select') {
                                $sql = "SELECT `visible` FROM `" . WP_STRAY_QUOTES_TABLE . "` WHERE `quoteID`='" . $val . "'";
                                $visibility = $wpdb->get_var($sql);
                                if ($visibility == 'yes') {
                                    $toggleyes .= "'" . $val . "',";
                                } else {
                                    $toggleno .= "'" . $val . "',";
                                }
                                $count++;
                            }
                        }
                        $toggleyes = rtrim($toggleyes, ',');
                        $toggleno = rtrim($toggleno, ',');
                        $sql = "UPDATE `" . WP_STRAY_QUOTES_TABLE . "` SET `visible`= 'no' WHERE `quoteID` IN(" . $toggleyes . ")";
                        $wpdb->query($sql);
                        $sql1 = "UPDATE `" . WP_STRAY_QUOTES_TABLE . "` SET `visible`= 'yes' WHERE `quoteID` IN(" . $toggleno . ")";
                        $wpdb->query($sql1);
                        $sql2 = "SELECT `quoteID` FROM `" . WP_STRAY_QUOTES_TABLE . "` WHERE `visible` IN(" . $toggleyes . ") = 'no'";
                        $result1 = $wpdb->get_results($sql2);
                        $sql3 = "SELECT `quoteID` FROM `" . WP_STRAY_QUOTES_TABLE . "` WHERE `visible` IN(" . $toggleno . ") = 'yes'";
                        $result2 = $wpdb->get_results($sql3);
                        if ($count == 0) {
                            ?>
<div class="error fade"><?php 
                            echo $nothingmessage;
                            ?>
</div><?php 
                        } else {
                            if ($result1 || $result2) {
                                ?>
<div class="updated"><p><?php 
                                echo str_replace("%s", $count, __('Visibility toggled for <strong>%s</strong> quotes.', 'stray-quotes'));
                                ?>
</p></div><?php 
                            } else {
                                ?>
<div class="error fade"><?php 
                                echo $wrongmessage;
                                ?>
</div><?php 
                            }
                        }
                    } else {
                        if ($_POST['bulk'] == 'changecategory') {
                            $newcat = $_POST['catselect'];
                            $catlist = '';
                            $count = 0;
                            foreach ($_POST as $key => $val) {
                                if (substr($key, 0, 12) == 'check_select') {
                                    $catlist .= "'" . $val . "',";
                                    $count++;
                                }
                            }
                            $catlist = rtrim($catlist, ',');
                            $sql = "UPDATE `" . WP_STRAY_QUOTES_TABLE . "` SET `category`='" . $newcat . "' WHERE `quoteID` IN(" . $catlist . ")";
                            $wpdb->query($sql);
                            $sql2 = "SELECT DISTINCT `category` FROM `" . WP_STRAY_QUOTES_TABLE . "` WHERE `quoteID` IN(" . $catlist . ")";
                            $result = $wpdb->get_var($sql2);
                            if ($count == 0) {
                                ?>
<div class="error fade"><?php 
                                echo $nothingmessage;
                                ?>
</div><?php 
                            } else {
                                if ($result == $newcat) {
                                    ?>
<div class="updated"><p><?php 
                                    echo str_replace("%s", $count, __('Category changed for <strong>%s</strong> quotes.', 'stray-quotes'));
                                    ?>
</p></div><?php 
                                } else {
                                    ?>
<div class="error fade"><?php 
                                    echo $wrongmessage;
                                    ?>
</div><?php 
                                }
                            }
                        } else {
                            if ($_POST['bulk'] == 'noaction') {
                                ?>
<div class="error fade"><?php 
                                _e('Please select something in the \'Bulk Actions\' menu first.', 'stray-quotes');
                                ?>
</div><?php 
                            }
                        }
                    }
                }
            }
        }
        // prepares WHERE condition (categories/users)
        $where = '';
        if (!$categories || $categories == 'all') {
            if (!current_user_can('manage_options')) {
                $where = " WHERE `user`='" . $current_user->user_nicename . "'";
            } else {
                $where = '';
            }
        } else {
            if (!current_user_can('manage_options')) {
                $where = " WHERE `category`='" . $categories . "' AND `user`='" . $current_user->user_nicename . "'";
            } else {
                $where = " WHERE `category`='" . $categories . "'";
            }
        }
        // how many rows we have in database
        $numrows = $wpdb->get_var("SELECT COUNT(`quoteID`) as rows FROM " . WP_STRAY_QUOTES_TABLE . $where);
        //temporary workaround for the "division by zero" problem
        if (is_string($rows)) {
            $rows = intval($rows);
        }
        settype($rows, "integer");
        // how many pages we have when using paging?
        if ($rows == NULL || $rows < 10) {
            $rows = 10;
        }
        $maxPage = ceil($numrows / $rows);
        // print the link to access each page (thanks to http://www.php-mysql-tutorial.com/wikis/php-tutorial/paging-using-php.aspx)
        $nav = '';
        for ($quotepage = 1; $quotepage <= $maxPage; $quotepage++) {
            //with few pages, print all the links
            if ($maxPage < 4) {
                if ($quotepage == $pages) {
                    $nav .= $quotepage;
                } else {
                    $nav .= ' <a href="' . querystrings($urlaction, 'qp', $quotepage) . '">' . $quotepage . '</a> ';
                }
                //with many pages
            } else {
                if ($quotepage == $pages) {
                    $nav .= $quotepage;
                } else {
                    if ($quotepage == 1 || $quotepage == $maxPage) {
                        $nav .= '';
                    } else {
                        //print links that are close to the current page (< 2 steps away)
                        if ($quotepage < $pages + 2 && $quotepage > $pages - 2) {
                            $nav .= ' <a href="' . querystrings($urlaction, 'qp', $quotepage) . '">' . $quotepage . '</a> ';
                        } else {
                            if ($pages > 3) {
                                $fdot = '.';
                            }
                            if ($pages != $maxPage - 1) {
                                $ldot = '.';
                            }
                        }
                    }
                }
            }
        }
        //print first and last, next and previous links
        if ($pages > 1) {
            $quotepage = $pages - 1;
            $prev = ' <a href="' . querystrings($urlaction, 'qp', $quotepage) . '" title="Previous ' . $rows . '">&laquo;</a> ';
            if ($maxPage > 4) {
                $first = ' <a href="' . querystrings($urlaction, 'qp', '1') . '">1</a> ' . $fdot . ' ';
            }
        } else {
            $prev = '&nbsp;';
            // we're on page one, don't print previous link
            if ($maxPage > 4) {
                $first = '&nbsp;';
            }
            //nor the first page link
        }
        if ($pages < $maxPage) {
            $missing = $numrows - $rows * $pages;
            if ($missing > $rows) {
                $missing = $rows;
            }
            $quotepage = $pages + 1;
            $next = ' <a href="' . querystrings($urlaction, 'qp', $quotepage) . '" title=" Next ' . $missing . '">&raquo;</a> ';
            if ($maxPage > 4) {
                $last = ' ' . $ldot . ' <a href="' . querystrings($urlaction, 'qp', $maxPage) . '"> ' . $maxPage . '</a> ';
            }
        } else {
            $next = '&nbsp;';
            // we're on the last page, don't print next link
            if ($maxPage > 4) {
                $last = '&nbsp;';
            }
            //nor the last page link
        }
        //get all the quotes
        $sql = "SELECT `quoteID`,`quote`,`author`,`source`,`category`,`visible`, `user` FROM " . WP_STRAY_QUOTES_TABLE . $where . " ORDER BY `" . $orderby . "`" . $sort . " LIMIT " . $offset . ", " . $rows;
        $quotes = $wpdb->get_results($sql);
        //page number has to be reset to 1 otherwise it would look like you have no quotes left when you are on a page too high for so many quotes.
        $urlrows = querystrings($urlaction, 'qp', '1');
        //HTML
        $bulkurl = remove_querystring_var($_SERVER['REQUEST_URI'], 'qa');
        $bulkurl = remove_querystring_var($bulkurl, 'qi');
        ?>
<form name="bulkform" id="bulkform" method="post" action="<?php 
        echo $bulkurl;
        ?>
">
        <div class="tablenav">
        <div class="alignleft actions" style="margin-right:10px">      
		<select name="bulk" id="bulkselect" style="vertical-align:middle;max-width:110px" onchange="javascript:disable_enable()" />
		<option value="noaction" ><?php 
        _e('Bulk Actions', 'stray-quotes');
        ?>
</option>
		<option value="multidelete"><?php 
        _e('delete', 'stray-quotes');
        ?>
</option>
		<option value="togglevisible"><?php 
        _e('toggle visibility', 'stray-quotes');
        ?>
</option>
		<option value="changecategory"><?php 
        _e('change category', 'stray-quotes');
        ?>
</option>
		</select>
		<select name="catselect" id="catselect" style="vertical-align:middle;max-width:120px"> 
		<?php 
        if (current_user_can('manage_options')) {
            $categorylist = make_categories();
        } else {
            $categorylist = make_categories($current_user->user_nicename);
        }
        foreach ($categorylist as $categoryo) {
            ?>
<option value="<?php 
            echo $categoryo;
            ?>
" >
			<?php 
            echo $categoryo;
            ?>
</option>
		<?php 
        }
        ?>
   
		</select>
		<input type="submit" value="<?php 
        _e('Apply', 'stray-quotes');
        ?>
" class="button-secondary action" />
		</div>
        
        <div class="alignleft actions"> 
		<span style="color:#666; font-size:11px;white-space:nowrap;"><?php 
        _e('display ', 'stray-quotes');
        ?>
 </span>
		<select name="lines" onchange="switchpage(this)"  style="vertical-align:middle">
		<option value=<?php 
        echo querystrings($urlrows, 'qr', '10');
        if ($rows == 10) {
            echo ' selected';
        }
        ?>
 ><?php 
        _e('10 quotes', 'stray-quotes');
        ?>
</option>
		<option value=<?php 
        echo querystrings($urlrows, 'qr', '15');
        if ($rows == 15) {
            echo ' selected';
        }
        ?>
 ><?php 
        _e('15 quotes', 'stray-quotes');
        ?>
</option>
		<option value=<?php 
        echo querystrings($urlrows, 'qr', '20');
        if ($rows == 20) {
            echo ' selected';
        }
        ?>
 ><?php 
        _e('20 quotes', 'stray-quotes');
        ?>
</option>
		<option value=<?php 
        echo querystrings($urlrows, 'qr', '30');
        if ($rows == 30) {
            echo ' selected';
        }
        ?>
 ><?php 
        _e('30 quotes', 'stray-quotes');
        ?>
</option>
		<option value=<?php 
        echo querystrings($urlrows, 'qr', '50');
        if ($rows == 50) {
            echo ' selected';
        }
        ?>
 ><?php 
        _e('50 quotes', 'stray-quotes');
        ?>
</option>
		<option value=<?php 
        echo querystrings($urlrows, 'qr', '100');
        if ($rows == 100) {
            echo ' selected';
        }
        ?>
 ><?php 
        _e('100 quotes', 'stray-quotes');
        ?>
</option>
		</select> <!--<span style="color:#666; font-size:11px;white-space:nowrap;"><?php 
        _e(' from ', 'stray-quotes');
        ?>
 </span>-->
		<select name="categories" onchange="switchpage(this)"  style="vertical-align:middle;max-width:120px"> 
		<option value="<?php 
        echo querystrings($urlaction, 'qc', 'all');
        ?>
" 
		<?php 
        if ($categories == '' || $categories == 'all') {
            echo ' selected';
        }
        ?>
><?php 
        _e('all categories', 'stray-quotes');
        ?>
</option>
		<?php 
        if (current_user_can('manage_options')) {
            $categorylist = make_categories();
        } else {
            $categorylist = make_categories($current_user->user_nicename);
        }
        foreach ($categorylist as $categoryo) {
            if (preg_match('/\\s+/', $categoryo) > 0) {
                $categoryo = preg_replace('/\\s+/', '-', $categoryo);
            }
            ?>
<option value="<?php 
            echo querystrings($urlaction, 'qc', $categoryo);
            ?>
" <?php 
            if ($categories) {
                if ($categories == $categoryo) {
                    echo ' selected';
                }
            }
            ?>
 ><?php 
            echo $categoryo;
            ?>
</option>
		<?php 
        }
        ?>
   
		</select></div>	
        
		<div class="tablenav-pages">
		<?php 
        $search = array("%s1", "%s2");
        $replace = array($pages, $maxPage);
        echo str_replace($search, $replace, __('<span class="displaying-num">Page %s1 of %s2</span>', 'stray-quotes'));
        echo '<strong>' . $prev . $first . $nav . $last . $next . '</strong>';
        ?>
</div>
		</div>
		<?php 
        //build table
        if (!empty($quotes)) {
            $imgasc = WP_STRAY_QUOTES_PATH . 'img/s_asc.png';
            $imgdsc = WP_STRAY_QUOTES_PATH . 'img/s_desc.png';
            ?>
<table class="widefat" id="straymanage">
            
            <?php 
            //column headers
            ?>
			<thead><tr>
				<th scope="col" style="padding-left: 0; margin-left:0">
				<input type="checkbox" style="padding-left:0" /></th>   
				
				<th scope="col" style="white-space: nowrap;"> <?php 
            if ($numrows != 1) {
                if ($orderby != 'quoteID') {
                    ?>
				<a href="<?php 
                    echo querystrings($urlaction, 'qo', 'quoteID');
                    ?>
" title="Sort"><?php 
                    _e('ID', 'stray-quotes');
                    ?>
</a>
				<?php 
                } else {
                    _e('ID', 'stray-quotes');
                    if ($sort == 'ASC') {
                        ?>
<a href="<?php 
                        echo querystrings($urlaction, 'qs', 'DESC');
                        ?>
">
					<img src= <?php 
                        echo $imgasc;
                        ?>
 alt="Descending" title="Descending" /></a> <?php 
                    } else {
                        if ($sort == 'DESC') {
                            ?>
<a href="<?php 
                            echo querystrings($urlaction, 'qs', 'ASC');
                            ?>
">
					<img src= <?php 
                            echo $imgdsc;
                            ?>
 alt="Ascending" title="Ascending" /></a> <?php 
                        }
                    }
                    ?>
							
				<?php 
                }
            } else {
                _e('ID', 'stray-quotes');
            }
            ?>
            
				</th>
				
				<th scope="col"> <?php 
            _e('Quote', 'stray-quotes');
            ?>
 </th>
				
				<th scope="col" style="white-space: nowrap;"> <?php 
            if ($numrows != 1) {
                if ($orderby != 'author') {
                    ?>
				<a href="<?php 
                    echo querystrings($urlaction, 'qo', 'author');
                    ?>
"><?php 
                    _e('Author', 'stray-quotes');
                    ?>
</a>
				<?php 
                } else {
                    _e('Author', 'stray-quotes');
                    if ($sort == 'ASC') {
                        ?>
<a href="<?php 
                        echo querystrings($urlaction, 'qs', 'DESC');
                        ?>
">
					<img src= <?php 
                        echo $imgasc;
                        ?>
 alt="Descending" title="Descending" /></a> <?php 
                    } else {
                        if ($sort == 'DESC') {
                            ?>
<a href="<?php 
                            echo querystrings($urlaction, 'qs', 'ASC');
                            ?>
">
					<img src= <?php 
                            echo $imgdsc;
                            ?>
 alt="Ascending" title="Ascending" /></a> <?php 
                        }
                    }
                    ?>
				<?php 
                }
            } else {
                _e('Author', 'stray-quotes');
            }
            ?>
            
				</th>
				
				<th scope="col" style="white-space: nowrap;"> <?php 
            if ($numrows != 1) {
                if ($orderby != 'source') {
                    ?>
				<a href="<?php 
                    echo querystrings($urlaction, 'qo', 'source');
                    ?>
"><?php 
                    _e('Source', 'stray-quotes');
                    ?>
</a>
				<?php 
                } else {
                    _e('Source', 'stray-quotes');
                    if ($sort == 'ASC') {
                        ?>
<a href="<?php 
                        echo querystrings($urlaction, 'qs', 'DESC');
                        ?>
">
					<img src= <?php 
                        echo $imgasc;
                        ?>
 alt="Descending" title="Descending" /></a> <?php 
                    } else {
                        if ($sort == 'DESC') {
                            ?>
<a href="<?php 
                            echo querystrings($urlaction, 'qs', 'ASC');
                            ?>
">
					<img src= <?php 
                            echo $imgdsc;
                            ?>
 alt="Ascending" title="Ascending" /></a> <?php 
                        }
                    }
                    ?>
				<?php 
                }
            } else {
                _e('Source', 'stray-quotes');
            }
            ?>
            
				</th>
				
				<th scope="col" style="white-space: nowrap;"> <?php 
            if ($numrows != 1) {
                if ($orderby != 'category') {
                    ?>
				<a href="<?php 
                    echo querystrings($urlaction, 'qo', 'category');
                    ?>
"><?php 
                    _e('Category', 'stray-quotes');
                    ?>
</a>
				<?php 
                } else {
                    _e('Category', 'stray-quotes');
                    if ($sort == 'ASC') {
                        ?>
<a href="<?php 
                        echo querystrings($urlaction, 'qs', 'DESC');
                        ?>
">
					<img src= <?php 
                        echo $imgasc;
                        ?>
 alt="Descending" title="Descending" /></a> <?php 
                    } else {
                        if ($sort == 'DESC') {
                            ?>
<a href="<?php 
                            echo querystrings($urlaction, 'qs', 'ASC');
                            ?>
">
					<img src= <?php 
                            echo $imgdsc;
                            ?>
 alt="Ascending" title="Ascending" /></a> <?php 
                        }
                    }
                    ?>
				<?php 
                }
            } else {
                _e('Category', 'stray-quotes');
            }
            ?>
            
				</th>
				
				<th scope="col" style="white-space: nowrap;"> <?php 
            if ($numrows != 1) {
                if ($orderby != 'visible') {
                    ?>
				<a href="<?php 
                    echo querystrings($urlaction, 'qo', 'visible');
                    ?>
"><?php 
                    _e('Visible', 'stray-quotes');
                    ?>
</a>
				<?php 
                } else {
                    _e('Visible', 'stray-quotes');
                    if ($sort == 'ASC') {
                        ?>
<a href="<?php 
                        echo querystrings($urlaction, 'qs', 'DESC');
                        ?>
">
					<img src= <?php 
                        echo $imgasc;
                        ?>
 alt="Descending" title="Descending" /></a> <?php 
                    } else {
                        if ($sort == 'DESC') {
                            ?>
<a href="<?php 
                            echo querystrings($urlaction, 'qs', 'ASC');
                            ?>
">
					<img src= <?php 
                            echo $imgdsc;
                            ?>
 alt="Ascending" title="Ascending" /></a> <?php 
                        }
                    }
                    ?>
				<?php 
                }
            } else {
                _e('Visible', 'stray-quotes');
            }
            ?>
            
				</th>
                
				<th scope="col">&nbsp;</th>
				<th scope="col">&nbsp;</th>

				<?php 
            if (current_user_can('manage_options') && $quotesoptions['stray_multiuser'] == true) {
                ?>
                <th scope="col" style="white-space: nowrap;"> <?php 
                if ($numrows != 1) {
                    if ($orderby != 'user') {
                        ?>
				<a href="<?php 
                        echo querystrings($urlaction, 'qo', 'user');
                        ?>
"><?php 
                        _e('User', 'stray-quotes');
                        ?>
</a>
				<?php 
                    } else {
                        _e('User', 'stray-quotes');
                        if ($sort == 'ASC') {
                            ?>
<a href="<?php 
                            echo querystrings($urlaction, 'qs', 'DESC');
                            ?>
">
					<img src= <?php 
                            echo $imgasc;
                            ?>
 alt="Descending" title="Descending" /></a> <?php 
                        } else {
                            if ($sort == 'DESC') {
                                ?>
<a href="<?php 
                                echo querystrings($urlaction, 'qs', 'ASC');
                                ?>
">
					<img src= <?php 
                                echo $imgdsc;
                                ?>
 alt="Ascending" title="Ascending" /></a> <?php 
                            }
                        }
                        ?>
				<?php 
                    }
                } else {
                    _e('User', 'stray-quotes');
                }
                ?>
            
				</th><?php 
            }
            ?>
				
                
			</tr></thead>
                
            <?php 
            //table rows
            ?>
            <tbody><?php 
            $i = 0;
            foreach ($quotes as $quote) {
                $alt = $i % 2 == 0 ? ' class="alternate"' : '';
                ?>
		
				<tr <?php 
                echo $alt;
                ?>
 <?php 
                if ($quote->user != $current_user->user_nicename) {
                    echo ' style="color:#aaa"';
                }
                ?>
 >
                				
					<td scope="col" style="white-space: nowrap;"><input type="checkbox" name="<?php 
                echo 'check_select' . $i;
                ?>
" value="<?php 
                echo $quote->quoteID;
                ?>
" /> </td> 
					
					<th scope="row"><?php 
                echo $quote->quoteID;
                ?>
</th>
					<td><?php 
                echo nl2br($quote->quote);
                ?>
</td>
					<td><?php 
                echo $quote->author;
                ?>
</td>
					<td><?php 
                echo $quote->source;
                ?>
</td>
					<td><?php 
                if ($quote->category == 'default') {
                    echo '<em>' . $quote->category . '</em>';
                } else {
                    echo $quote->category;
                }
                ?>
</td>
					<td><?php 
                if ($quote->visible == 'yes') {
                    _e('yes', 'stray-quotes');
                } else {
                    _e('no', 'stray-quotes');
                }
                ?>
</td>
										
					<td align="center">
					<a href="<?php 
                echo querystrings(querystrings($urlaction, 'qa', 'edit'), 'qi', $quote->quoteID);
                ?>
">
					<?php 
                _e('Edit', 'stray-quotes');
                ?>
</a></td>
	
					<td align="center">
					<a href="
					<?php 
                echo querystrings(querystrings($urlaction, 'qa', 'delete'), 'qi', $quote->quoteID);
                ?>
"
					onclick="if ( confirm('<?php 
                echo __('You are about to delete quote ', 'stray-quotes') . $quote->quoteID . '.\\n\\\'' . __('Cancel', 'stray-quotes') . '\\\' ' . __('to stop', 'stray-quotes') . ', \\\'OK\\\' ' . __('to delete', 'stray-quotes') . '.\'';
                ?>
) ) { return true;}return false;"><?php 
                echo __('Delete', 'stray-quotes');
                ?>
</a></td>			
                    
                    <?php 
                if (current_user_can('manage_options') && $quotesoptions['stray_multiuser'] == true) {
                    ?>
					<td><?php 
                    if ($quote->user == $current_user->user_nicename) {
                        echo '';
                    } else {
                        echo $quote->user;
                    }
                    ?>
</td>
                    <?php 
                }
                ?>
                    
				</tr>
				<?php 
                $i++;
            }
            ?>
			</tbody>
            
            <?php 
            //end table and navigation
            ?>
            </table><div class="tablenav"><div class="tablenav-pages">
			<?php 
            $search = array("%s1", "%s2");
            $replace = array($pages, $maxPage);
            echo str_replace($search, $replace, __('<span class="displaying-num">Page %s1 of %s2</span>', 'stray-quotes'));
            echo '<strong>' . $prev . $first . $nav . $last . $next . '</strong>';
            ?>
            </div></div></form><?php 
        } else {
            ?>
<p><div style="clear:both"> <?php 
            echo str_replace("%s1", get_option('siteurl') . "/wp-admin/admin.php?page=stray_manage", __('<br/>No quotes here. Maybe you want to <a href="%s1">reopen</a> this page.', 'stray-quotes'));
            ?>
 </div></p>
		</div><?php 
        }
    }
    ?>
</div><?php 
}
コード例 #3
0
function stray_quotes_options()
{
    global $wpdb;
    //check whether user can manage options
    if (!current_user_can('manage_options')) {
        die('Access Denied');
    }
    //decode and intercept
    foreach ($_POST as $key => $val) {
        $_POST[$key] = stripslashes(utf8_encode($val));
    }
    //handle the post event
    if (!empty($_POST['do'])) {
        // check URLs
        if ($_POST['link_to'] == 'http://') {
            unset($_POST['link_to']);
        } else {
            if (!preg_match("#((http|https|ftp)://(\\S*?\\.\\S*?))(\\s|\\;|\\)|\\]|\\[|\\{|\\}|,|\"|'|:|\\<|\$|\\.\\s)#ie", $_POST['link_to'])) {
                unset($_POST['link_to']);
                $msgvar3 = 1;
            }
        }
        if ($_POST['source_link_to'] == 'http://') {
            unset($_POST['source_link_to']);
        } else {
            if (!preg_match("#((http|https|ftp)://(\\S*?\\.\\S*?))(\\s|\\;|\\)|\\]|\\[|\\{|\\}|,|\"|'|:|\\<|\$|\\.\\s)#ie", $_POST['source_link_to'])) {
                unset($_POST['source_link_to']);
                $msgvar3 = 1;
            }
        }
        //check loader
        if ($_POST['loader']) {
            $_POST['loader'] = strip_tags($_POST['loader']);
        }
        //get existing options
        $existingoptions = get_option('stray_quotes_options');
        //create array of values *ALL VALUES MUST BE INCLUDED HERE
        $quotesoptions = array('stray_quotes_before_all' => $_POST['before_all'], 'stray_quotes_after_all' => $_POST['after_all'], 'stray_quotes_before_quote' => $_POST['before_quote'], 'stray_quotes_after_quote' => $_POST['after_quote'], 'stray_quotes_before_author' => $_POST['before_author'], 'stray_quotes_after_author' => $_POST['after_author'], 'stray_quotes_before_source' => $_POST['before_source'], 'stray_quotes_after_source' => $_POST['after_source'], 'stray_quotes_put_quotes_first' => $_POST['put_quotes_first'], 'stray_quotes_default_visible' => $_POST['default_visible'], 'stray_quotes_linkto' => $_POST['link_to'], 'stray_quotes_sourcelinkto' => $_POST['source_link_to'], 'stray_quotes_authorspaces' => $_POST['author_spaces'], 'stray_quotes_sourcespaces' => $_POST['source_spaces'], 'stray_quotes_order' => $_POST['order'], 'stray_quotes_rows' => $_POST['rows'], 'stray_quotes_categories' => $_POST['categories'], 'stray_quotes_sort' => $_POST['sort'], 'stray_default_category' => $_POST['default_category'], 'stray_if_no_author' => $_POST['no_author'], 'stray_clear_form' => $_POST['clear_form'], 'stray_ajax' => $_POST['stray_ajax'], 'stray_before_loader' => $_POST['before_loader'], 'stray_loader' => $_POST['loader'], 'stray_after_loader' => $_POST['after_loader'], 'stray_loading' => $_POST['stray_loading'], 'stray_multiuser' => $_POST['stray_multiuser'], 'comment_scode' => $existingoptions['comment_scode'], 'title_scode' => $existingoptions['title_scode'], 'excerpt_scode' => $existingoptions['excerpt_scode'], 'widget_scode' => $existingoptions['widget_scode'], 'categories_scode' => $existingoptions['categories_scode'], 'tags_scode' => $existingoptions['tags_scode'], 'bloginfo_scode' => $existingoptions['bloginfo_scode'], 'bookmarlet_source' => $existingoptions['bookmarlet_source'], 'bookmarklet_cat' => $existingoptions['bookmarklet_cat']);
        //update options
        $update_quotes_options = update_option('stray_quotes_options', $quotesoptions);
        if ($update_quotes_options) {
            //positive feedback
            ?>
<div id="message" class="updated fade below-h2"><p>
            <?php 
            _e('<strong>Options saved...</strong> ', 'stray-quotes');
            if ($msgvar3 == 1) {
                _e('No problems. Well, except for one or more invalid urls that I discarded.', 'stray-quotes');
            } else {
                _e('No problems.', 'stray-quotes');
            }
            ?>
</p></div><?php 
        } else {
            //negative feedback
            ?>
<div id="message" class="error fade below-h2"><p>
            <?php 
            if ($msgvar3 == 1) {
                _e('The operation failed because of one or more invalid urls that I discarded.', 'stray-quotes');
            } else {
                _e('<strong>The options could not be saved</strong>. Either the operation went wrong, or you didn\'t make any changes.</strong> ', 'stray-quotes');
            }
            ?>
</p></div><?php 
        }
    }
    //get the options
    $quotesoptions = array();
    $quotesoptions = get_option('stray_quotes_options');
    $regularTitle = $quotesoptions['stray_quotes_regular_title'];
    $widgetTitle = $quotesoptions['stray_quotes_widget_title'];
    $beforeAll = $quotesoptions['stray_quotes_before_all'];
    $afterAll = $quotesoptions['stray_quotes_after_all'];
    $beforeQuote = $quotesoptions['stray_quotes_before_quote'];
    $afterQuote = $quotesoptions['stray_quotes_after_quote'];
    $beforeAuthor = $quotesoptions['stray_quotes_before_author'];
    $afterAuthor = $quotesoptions['stray_quotes_after_author'];
    $beforeSource = $quotesoptions['stray_quotes_before_source'];
    $afterSource = $quotesoptions['stray_quotes_after_source'];
    $putQuotesFirst = $quotesoptions['stray_quotes_put_quotes_first'];
    $defaultVisible = $quotesoptions['stray_quotes_default_visible'];
    $linkto = $quotesoptions['stray_quotes_linkto'];
    $sourcelinkto = $quotesoptions['stray_quotes_sourcelinkto'];
    $sourcespaces = $quotesoptions['stray_quotes_sourcespaces'];
    $authorspaces = $quotesoptions['stray_quotes_authorspaces'];
    $order = $quotesoptions['stray_quotes_order'];
    $rows = $quotesoptions['stray_quotes_rows'];
    $categories = $quotesoptions['stray_quotes_categories'];
    $sort = $quotesoptions['stray_quotes_sort'];
    $defaultcategory = $quotesoptions['stray_default_category'];
    $ifnoauthor = $quotesoptions['stray_if_no_author'];
    $clearform = $quotesoptions['stray_clear_form'];
    $strayajax = $quotesoptions['stray_ajax'];
    $beforeloader = $quotesoptions['stray_before_loader'];
    $quoteloader = $quotesoptions['stray_loader'];
    $afterloader = $quotesoptions['stray_after_loader'];
    $loading = $quotesoptions['stray_loading'];
    $multiuser = $quotesoptions['stray_multiuser'];
    if ($putQuotesFirst == 'Y') {
        $putQuotesFirst_selected = 'checked';
    }
    if ($defaultVisible == 'Y') {
        $defaultVisible_selected = 'checked';
    }
    if ($clearform == 'Y') {
        $clearform_selected = 'checked';
    }
    if ($strayajax == 'Y') {
        $strayajax_selected = 'checked';
    }
    if ($multiuser == 'Y') {
        $multiuser_selected = 'checked';
    }
    //javascript to disable ajax forms
    ?>
<script type="text/javascript">
		
		function disablefields() {
			// Get a fieldset
			var a = document.getElementById('ajaxinput1');
			var b = document.getElementById('ajaxinput2');
			var c = document.getElementById('ajaxinput3');
			var d = document.getElementById('ajaxinput4');
			<?php 
    if ($strayajax == "Y") {
        ?>
			a.disabled = true;
			b.disabled = true;
			c.disabled = true;
			d.disabled = true;
			<?php 
    } else {
        ?>
			a.disabled = false;
			b.disabled = false;
			c.disabled = false;
			d.disabled = false;
			<?php 
    }
    ?>
		} </script>	
	
	<?php 
    //the options form
    ?>
	<form name="frm_options" method="post" action="<?php 
    echo $_SERVER['REQUEST_URI'];
    ?>
">

    <?php 
    //quote aspect
    ?>
    <div class="wrap"><h2><?php 
    _e('Settings', 'stray-quotes');
    ?>
</h2>

    <p><h3 style="line-height:.1em"><?php 
    _e('How the quotes look', 'stray-quotes');
    ?>
</h3>
    <span class="setting-description"><?php 
    _e('Default settings to change how the quotes appear in your blog. These settings apply to ALL widgets, shortcodes or template tags, but they can be disabled from those if needed.', 'stray-quotes');
    ?>
</span>
    </p>
	<table class="form-table"> 
	
	<tr valign="top"><th scope="row"><?php 
    _e('The Quote Area', 'stray-quotes');
    ?>
</th>    
        <td><input type="text" size="50" name="before_all" value="<?php 
    echo utf8_decode(htmlspecialchars($beforeAll));
    ?>
"class="regular-text" /><span class="setting-description">
		<?php 
    _e('<br/>HTML or other elements <strong>before the quote area</strong>, which comes after the widget title and includes Quote, Author and Source. If more than one quote is listed, Quote Area is considered the entire list.<br/><strong>Sample value:</strong>', 'stray-quotes');
    ?>
 <code>&lt;div align=&quot;right&quot;&gt;</code></span></td>
        <td><input type="text" size="50" name="after_all" value="<?php 
    echo utf8_decode(htmlspecialchars($afterAll));
    ?>
"class="regular-text" /><span class="setting-description">
		<?php 
    _e('<br/>HTML or other elements <strong>after the quote area</strong>.<br/><strong>Sample value:</strong>', 'stray-quotes');
    ?>
 <code>&lt;/div&gt;</code></span>   
	</td></tr>
    
	<tr valign="top" style="background:#F0F0F0"><th scope="row"><?php 
    _e('Quote', 'stray-quotes');
    ?>
</th>    
        <td><input type="text" size="50" name="before_quote" value="<?php 
    echo utf8_decode(htmlspecialchars($beforeQuote));
    ?>
"class="regular-text" /><span class="setting-description">
        <?php 
    _e('<br/>HTML or other elements before the quote.<br/><strong>Sample value:</strong>', 'stray-quotes');
    ?>
 <code>&amp;#8220;</code></span>
        <td><input type="text" size="50" name="after_quote" value="<?php 
    echo utf8_decode(htmlspecialchars($afterQuote));
    ?>
"class="regular-text" /><span class="setting-description">
		<?php 
    _e('<br/>HTML or other elements after the quote.<br/><strong>Sample value:</strong>', 'stray-quotes');
    ?>
 <code>&amp;#8221;</code></span>    
    </td></tr>
    
	<tr valign="top"><th scope="row"><?php 
    _e('Author', 'stray-quotes');
    ?>
</th><td>    
        <input type="text" size="50" name="before_author" value="<?php 
    echo utf8_decode(htmlspecialchars($beforeAuthor));
    ?>
" class="regular-text" /><span class="setting-description">
		<?php 
    _e('<br/>HTML or other elements before the author.<br/><strong>Sample value:</strong>', 'stray-quotes');
    ?>
 <code>&lt;br/&gt;<?php 
    _e('by', 'stray-quotes');
    ?>
&amp;nbsp;</code></span>
        <br/>
        <input type="text" size="50" name="after_author" value="<?php 
    echo utf8_decode(htmlspecialchars($afterAuthor));
    ?>
" class="regular-text" /><span class="setting-description">
		<?php 
    _e('<br/>HTML or other elements after the author.', 'stray-quotes');
    ?>
</span></td>
        <td><input type="text" size="50" name="link_to" value="<?php 
    if ($linkto) {
        echo utf8_decode(htmlspecialchars($linkto));
    } else {
        echo 'http://';
    }
    ?>
" class="regular-text code" /><span class="setting-description">
		<?php 
    _e('<br/>You can link the Author to a website of your choice.
		<br/>Use this variable in your link: <code>%AUTHOR%</code><br/>
		<strong>Sample values:</strong>', 'stray-quotes');
    ?>
 <code>http://www.google.com/search?q=&quot;%AUTHOR%&quot;</code><br/> 
		<code>http://en.wikipedia.org/wiki/%AUTHOR%</code><br />
        <?php 
    _e('Replace spaces within %AUTHOR% with ', 'stray-quotes');
    ?>
        <input type="text" size="1" maxlength="1" name="author_spaces" value="<?php 
    echo utf8_decode(htmlspecialchars($authorspaces));
    ?>
" /></span>
   	</td></tr>
    
	<tr valign="top" style="background:#F0F0F0"><th scope="row"><?php 
    _e('Source', 'stray-quotes');
    ?>
</th><td>    
        <input type="text" size="50" name="before_source" value="<?php 
    echo utf8_decode(htmlspecialchars($beforeSource));
    ?>
" class="regular-text" /><span class="setting-description">
		<?php 
    _e('<br/>HTML or other elements before the source.<br/><strong>Sample value:</strong>', 'stray-quotes');
    ?>
 <code>,&lt;em&gt;&amp;nbsp;</code></span><br/>
        <input type="text" size="50" name="no_author" value="<?php 
    echo utf8_decode(htmlspecialchars($ifnoauthor));
    ?>
" class="regular-text" /><span class="setting-description">
		<?php 
    _e('<br/>HTML or other elements before the source <strong>if there is no author</strong>.<br/>Overrides the field above when no author is present.<br/><strong>Sample value:</strong>', 'stray-quotes');
    ?>
 <code>&lt;br/&gt;source:&amp;nbsp;</code></span>
        <br/>        
        <input type="text" size="50" name="after_source" value="<?php 
    echo utf8_decode(htmlspecialchars($afterSource));
    ?>
" class="regular-text" /><span class="setting-description">
		<?php 
    _e('<br/>HTML or other elements after the source.<br/><strong>Sample value:</strong>', 'stray-quotes');
    ?>
 <code>&lt;/em&gt;</code></span></td>
        <td><input type="text" size="50" name="source_link_to" value="<?php 
    if ($sourcelinkto) {
        echo utf8_decode(htmlspecialchars($sourcelinkto));
    } else {
        echo 'http://';
    }
    ?>
" class="regular-text code" /><span class="setting-description">
		<?php 
    _e('<br/>You can link the Source to a website of your choice.
		<br/>Use this variable in your link: <code>%SOURCE%</code><br/>
		<strong>Sample values:</strong>', 'stray-quotes');
    ?>
 <code>http://www.google.com/search?q=&quot;%SOURCE%&quot;</code><br/> 
		<code>http://en.wikipedia.org/wiki/%SOURCE%</code><br />
        <?php 
    _e('Replace spaces within %SOURCE% with ', 'stray-quotes');
    ?>
        <input type="text" size="1" maxlength="1" name="source_spaces" value="<?php 
    echo utf8_decode(htmlspecialchars($sourcespaces));
    ?>
" />
        </span>
   	</td></tr>
    
	<tr valign="top"><th scope="row"><?php 
    _e('Quote before Author and Source', 'stray-quotes');
    ?>
</th><td colspan="2">    
    	<input type="checkbox" name="put_quotes_first" value="Y" <?php 
    echo $putQuotesFirst_selected;
    ?>
 /><span class="setting-description">
        <?php 
    _e('If checked, returns the quote before author and source (The opposite is NOT considered by the <code>[all-quotes]</code> shortcode).', 'stray-quotes');
    ?>
</span>
    </td></tr>
    
    </table>
    <br/>
   	<div class="submit">
    <input type="hidden" name="do" value="Update" />
    <input type="submit" value="<?php 
    _e('Update all Settings', 'stray-quotes');
    ?>
 &raquo;" />
    </div>
    
   <p>&nbsp;</p>
   
	<?php 
    //AJAX loader
    ?>
    <p><h3 style="line-height:.1em"><?php 
    _e('AJAX settings', 'stray-quotes');
    ?>
</h3>
    <span class="setting-description"><?php 
    _e('Default settings for the dynamic loader.', 'stray-quotes');
    ?>
</span>
    </p>
    <table class="form-table"> 
      
    <tr valign="top"><th scope="row"><?php 
    _e('Enable/Disable AJAX', 'stray-quotes');
    ?>
</th>    
        <td colspan="2"><input type="checkbox" name="stray_ajax" value="Y" <?php 
    echo $strayajax_selected;
    ?>
 onchange="javascript:disable_enable()" /><span class="setting-description"><?php 
    echo str_replace("%s", get_option("siteurl") . '/wp-admin/admin.php?page=stray_help', __('&nbsp;If checked, <strong>disables the AJAX loader</strong> entirely. If unchecked, AJAX can still be disabled from the widgets, the template tags or the shortcodes (see <a href="%s">help page</a>).', 'stray-quotes'));
    ?>
</span></td></tr>
        
    <tr valign="top" style="background:#F0F0F0"><th scope="row"><?php 
    _e('The AJAX loader', 'stray-quotes');
    ?>
</th>
    <td><input type="text" size="50" name="loader" value="<?php 
    echo utf8_decode(htmlspecialchars($quoteloader));
    ?>
" class="regular-text" id="ajaxinput1" /><span class="setting-description"><?php 
    echo str_replace("%s", get_option("siteurl") . '/wp-admin/admin.php?page=stray_help', __('<br/>Enter here the <strong>link phrase</strong> used to dynamically load another quote. HTML not allowed. If you leave this empty, the quote will be reloaded by clicking on it. You can <strong>override</strong> this setting in widgets, shortcodes or in the template (see <a href="%s">help page</a>), <strong>only</strong> if you leave this field empty.<br/><strong>Sample value:</strong>', 'stray-quotes'));
    ?>
 <code>New quote &amp;raquo;</code></span></td>        
    <td><input type="text" size="50" name="before_loader" value="<?php 
    echo utf8_decode(htmlspecialchars($beforeloader));
    ?>
" class="regular-text"  id="ajaxinput3" /><span class="setting-description"><?php 
    _e('<br/>HTML or other elements before the quote loader.<br/><strong>Sample value:</strong>', 'stray-quotes');
    ?>
 <code>&lt;p align="left"&gt;</code></span><br/> 
    <input type="text" size="50" name="after_loader" value="<?php 
    echo utf8_decode(htmlspecialchars($afterloader));
    ?>
" class="regular-text"  id="ajaxinput4"  /><span class="setting-description"><?php 
    _e('<br/>HTML or other elements after the quote loader.<br/><strong>Sample value:</strong>', 'stray-quotes');
    ?>
 <code>&lt;/p&gt;</code></span> </td></tr>
    
    <tr valign="top"><th scope="row"><?php 
    _e('The loading message', 'stray-quotes');
    ?>
</th>
    <td colspan="2"><input type="text" size="50" name="stray_loading" value="<?php 
    echo utf8_decode(htmlspecialchars($loading));
    ?>
" class="regular-text"  id="ajaxinput2" /><span class="setting-description"><?php 
    _e('<br/>The loading message in between quotes.<br/><strong>Sample value:</strong>', 'stray-quotes');
    ?>
 <code>loading...</code></span></td></tr>
        
	</table>
    <br/>
	<div class="submit">
    <input type="hidden" name="do" value="Update" />
    <input type="submit" value="<?php 
    _e('Update all Settings', 'stray-quotes');
    ?>
 &raquo;" />
    </div>
    
    <p>&nbsp;</p>
    
	<?php 
    //new quotes
    ?>
    <p><h3 style="line-height:.1em"><?php 
    _e('New quotes', 'stray-quotes');
    ?>
</h3>
    <span class="setting-description"><?php 
    _e('Default settings when you create a new quote.', 'stray-quotes');
    ?>
</span>
    </p>
    <table class="form-table">
    
    <tr valign="top"><th scope="row"><?php 
    _e('Visibility', 'stray-quotes');
    ?>
</th>       
        <td colspan="2"><input type="checkbox" name="default_visible" value="Y" <?php 
    echo $defaultVisible_selected;
    ?>
 /><span class="setting-description">
        <?php 
    _e('If checked, will set "Visible" to "Yes" for all new quotes.', 'stray-quotes');
    ?>
</span>
    </td></tr>
    
    <tr valign="top" style="background:#F0F0F0"><th scope="row"><?php 
    _e('Default category', 'stray-quotes');
    ?>
</th>       
    <td colspan="2"><select name="default_category" style="vertical-align:middle"> 
    <?php 
    $categorylist = make_categories();
    foreach ($categorylist as $categoryo) {
        ?>
    	<option value="<?php 
        echo $categoryo;
        ?>
" 
		<?php 
        if ($categoryo == $defaultcategory) {
            echo ' selected ';
        }
        ?>
 >
		<?php 
        echo $categoryo;
        ?>
</option>
	<?php 
    }
    ?>
   
    </select><span class="setting-description"> 
	<?php 
    _e('This category will be the default for all new quotes.', 'stray-quotes');
    ?>
</span>
	</td></tr>
    
    <tr valign="top"><th scope="row"><?php 
    _e('Clear the form', 'stray-quotes');
    ?>
</th>       
        <td colspan="2"><input type="checkbox" name="clear_form" value="Y" <?php 
    echo $clearform_selected;
    ?>
 /><span class="setting-description">
        <?php 
    _e('If checked, will clear the values from the form after adding a new quote.', 'stray-quotes');
    ?>
</span>
    </td></tr> 
    
	</table>
    <br/>
	<div class="submit">
    <input type="hidden" name="do" value="Update" />
    <input type="submit" value="<?php 
    _e('Update all Settings', 'stray-quotes');
    ?>
 &raquo;" />
    </div>
    
    <p>&nbsp;</p>
     
	<?php 
    //management of quotes
    ?>
    
    <p><h3 style="line-height:.1em"><?php 
    _e('Management of the quotes', 'stray-quotes');
    ?>
</h3>
    <span class="setting-description"><?php 
    _e('Default settings for the management page.  They can be changed on the management page as well.', 'stray-quotes');
    ?>
</span>
    </p>
    <table class="form-table">
     <tr valign="top"><th scope="row"><?php 
    _e('Order by', 'stray-quotes');
    ?>
</th>       
        <td><select name="order" style="vertical-align:middle" >
        <option value="quoteID" <?php 
    if ($order == "quoteID") {
        echo 'selected="selected"';
    }
    ?>
 >ID</option>
        <option value="author" <?php 
    if ($order == "author") {
        echo 'selected="selected"';
    }
    ?>
 >Author</option>
        <option value="source" <?php 
    if ($order == "source") {
        echo 'selected="selected"';
    }
    ?>
 >Source</option>
        <option value="category" <?php 
    if ($order == "category") {
        echo 'selected="selected"';
    }
    ?>
 >Category</option>
        <option value="visible" <?php 
    if ($order == "visible") {
        echo 'selected="selected"';
    }
    ?>
 >Visibility</option>
        </select><span class="setting-description">
        <?php 
    _e('<br/>The list of quotes in the management page will be ordered by this value.', 'stray-quotes');
    ?>
</span>
      </td>
      <td><select name="sort" style="vertical-align:middle" >
        <option value="ASC" <?php 
    if ($sort == "ASC") {
        echo 'selected="selected"';
    }
    ?>
 >Ascending</option>
        <option value="DESC" <?php 
    if ($sort == "DESC") {
        echo 'selected="selected"';
    }
    ?>
 >Descending</option>
        </select><span class="setting-description">
        <?php 
    _e('<br/>The sorting of quotes will take this direction.', 'stray-quotes');
    ?>
</span>
      </td></tr>
     <tr valign="top" style="background:#F0F0F0"><th scope="row"><?php 
    _e('Quotes per page', 'stray-quotes');
    ?>
</th>       
        <td colspan="2"><select name="rows" style="vertical-align:middle">
        <option value="10" <?php 
    if ($rows == 10) {
        echo ' selected';
    }
    ?>
 >10</option>
        <option value="15" <?php 
    if ($rows == 15) {
        echo ' selected';
    }
    ?>
 >15</option>
        <option value="20" <?php 
    if ($rows == 20) {
        echo ' selected';
    }
    ?>
 >20</option>
        <option value="30" <?php 
    if ($rows == 30) {
        echo ' selected';
    }
    ?>
 >30</option>
        <option value="50" <?php 
    if ($rows == 50) {
        echo ' selected';
    }
    ?>
 >50</option>
        <option value="100" <?php 
    if ($rows == 100) {
        echo ' selected';
    }
    ?>
 >100</option>
        </select><span class="setting-description">
        <?php 
    _e('The list of quotes in the management page will display this much quotes per page.', 'stray-quotes');
    ?>
</span>
      </td></tr>
    <tr valign="top"><th scope="row"><?php 
    _e('Show categories', 'stray-quotes');
    ?>
</th>       
    <td colspan="2"><select name="categories" style="vertical-align:middle"> 
    <option value="<?php 
    echo $urlcategory . 'all';
    ?>
" 
	<?php 
    if ($categories == '' || $categories == 'all') {
        echo ' selected';
    }
    ?>
><?php 
    _e('All categories', 'stray-quotes');
    ?>
</option>
    <?php 
    $categorylist = make_categories();
    foreach ($categorylist as $categoryo) {
        ?>
    	<option value="<?php 
        echo $urlcategory . $categoryo;
        ?>
" 
		<?php 
        if ($categories) {
            if ($categories == $categoryo) {
                echo ' selected';
            }
        }
        ?>
 >
		<?php 
        echo $categoryo;
        ?>
</option>
	<?php 
    }
    ?>
   
    </select><span class="setting-description"> 
	<?php 
    _e('The list of quotes in the management page will present quotes from this category only.', 'stray-quotes');
    ?>
</span>
	</td></tr>
	</table>
    <br/>
	<div class="submit">
    <input type="hidden" name="do" value="Update" />
    <input type="submit" value="<?php 
    _e('Update all Settings', 'stray-quotes');
    ?>
 &raquo;" />
    </div>
    <p>&nbsp;</p>
    
    
   <p>&nbsp;</p>
   
	<?php 
    //Multiuser
    ?>
    <p><h3 style="line-height:.1em"><?php 
    _e('Multiuser settings', 'stray-quotes');
    ?>
</h3>
    <span class="setting-description"><?php 
    _e('Allow contributors to access a restricted version of Stray Random Quotes.', 'stray-quotes');
    ?>
</span>
    </p>
    <table class="form-table"> 
    
    <tr valign="top"><th scope="row"><?php 
    _e('Enable multiuser capability', 'stray-quotes');
    ?>
</th>    
        <td colspan="2"><input type="checkbox" name="stray_multiuser" value="Y" <?php 
    echo $multiuser_selected;
    ?>
 /><span class="setting-description"><?php 
    _e(' If checked a contributor (non-administrator) to the blog will be enabled to: create new quotes, edit and manage his own, and access a limited version of the help page.', 'stray-quotes');
    ?>
</span></td></tr>
      
	</table>
    <br/>
	<div class="submit">
    <input type="hidden" name="do" value="Update" />
    <input type="submit" value="<?php 
    _e('Update all Settings', 'stray-quotes');
    ?>
 &raquo;" />
    </div>
    </div>
    </form><?php 
}
コード例 #4
0
function stray_tools()
{
    global $current_user;
    //get the options
    $quotesoptions = array();
    $quotesoptions = get_option('stray_quotes_options');
    //security check
    if ($quotesoptions['stray_multiuser'] == false && !current_user_can('manage_options')) {
        die('Access Denied');
    }
    if (!empty($_POST['do'])) {
        //function to change bookmarklet options
        if (isset($_POST['boptions'])) {
            $quotesoptions = array();
            $quotesoptions = get_option('stray_quotes_options');
            $quotesoptions['bookmarklet_cat'] = $_POST['categories'];
            $quotesoptions['bookmarlet_source'] = $_POST['websource'];
            $update_shortcodes = update_option('stray_quotes_options', $quotesoptions);
            //feedback
            if ($update_shortcodes) {
                ?>
                <div id="message" class="updated fade below-h2"><p>
                <?php 
                _e('<strong>Bookmarklet options saved.</strong>', 'stray-quotes');
                ?>
</p></div><?php 
            } else {
                ?>
<div id="message" class="error fade below-h2"><p>
				<?php 
                _e('<strong>Bookmarklet options not saved. Something went wrong!</strong>', 'stray-quotes');
                ?>
</p></div><?php 
            }
        } else {
            if (isset($_POST['enable']) && current_user_can('manage_options')) {
                $quotesoptions = array();
                $quotesoptions = get_option('stray_quotes_options');
                $quotesoptions['comment_scode'] = $_POST['comment_scode'];
                $quotesoptions['title_scode'] = $_POST['title_scode'];
                $quotesoptions['excerpt_scode'] = $_POST['excerpt_scode'];
                $quotesoptions['widget_scode'] = $_POST['widget_scode'];
                $quotesoptions['categories_scode'] = $_POST['categories_scode'];
                $quotesoptions['tags_scode'] = $_POST['tags_scode'];
                $quotesoptions['bloginfo_scode'] = $_POST['bloginfo_scode'];
                $update_shortcodes = update_option('stray_quotes_options', $quotesoptions);
                //feedback
                if ($update_shortcodes) {
                    ?>
                <div id="message" class="updated fade below-h2"><p>
                <?php 
                    _e('<strong>Shortcodes enabled.</strong>', 'stray-quotes');
                    ?>
</p></div><?php 
                } else {
                    ?>
<div id="message" class="error fade below-h2"><p>
				<?php 
                    _e('<strong>Shortcodes not enabled. Something went wrong!</strong>', 'stray-quotes');
                    ?>
</p></div><?php 
                }
            } else {
                if (isset($_POST['submit']) && current_user_can('manage_options')) {
                    global $wpdb;
                    $query1 = $wpdb->query("ALTER TABLE `" . WP_STRAY_QUOTES_TABLE . "` DROP `quoteID`");
                    $query2 = $wpdb->query("ALTER TABLE `" . WP_STRAY_QUOTES_TABLE . "` ADD COLUMN `quoteID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
                    if ($query1 && $query2) {
                        ?>
                <div id="message" class="updated fade below-h2"><p>
                <?php 
                        echo str_replace("%s", get_option("siteurl") . '/wp-admin/admin.php?page=stray_manage', __('<strong>Quote IDs have been reset.</strong> To review use the <a href="%s">Manage page</a>.', 'stray-quotes'));
                        ?>
</p></div><?php 
                    } else {
                        ?>
                <div id="message" class="error fade below-h2"><p>
                <?php 
                        _e('<strong>Failure.</strong> It was not possible to reset the ID numbers.', 'stray-quotes');
                        ?>
</p></div><?php 
                    }
                } else {
                    if (isset($_POST['resetsettings']) && current_user_can('manage_options')) {
                        $quotesoptions = array('stray_quotes_before_all' => '', 'stray_quotes_before_quote' => '&#8220;', 'stray_quotes_after_quote' => '&#8221;', 'stray_quotes_before_author' => '<br/>by&nbsp;', 'stray_quotes_after_author' => '', 'stray_quotes_before_source' => '<em>&nbsp;', 'stray_quotes_after_source' => '</em>', 'stray_quotes_after_all' => '', 'stray_quotes_put_quotes_first' => 'Y', 'stray_quotes_default_visible' => 'Y', 'stray_quotes_linkto' => '', 'stray_quotes_sourcelinkto' => '', 'stray_quotes_sourcespaces' => '-', 'stray_quotes_authorspaces' => '-', 'stray_if_no_author' => '<br/>source:&nbsp;', 'stray_quotes_uninstall' => '', 'stray_clear_form' => 'Y', 'stray_quotes_order' => 'quoteID', 'stray_quotes_rows' => 10, 'stray_quotes_categories' => 'all', 'stray_quotes_sort' => 'DESC', 'stray_default_category' => 'default', 'stray_quotes_version' => WP_STRAY_VERSION, 'stray_before_loader' => '<p align=>"left">', 'stray_loader' => '', 'stray_after_loader' => '</p>', 'stray_ajax' => '', 'comment_scode' => '', 'title_scode' => '', 'excerpt_scode' => '', 'widget_scode' => '', 'categories_scode' => '', 'tags_scode' => '', 'bloginfo_scode' => '', 'bookmarlet_source' => '', 'bookmarklet_cat' => '', 'stray_loading' => __('loading...', 'stray-quotes'), 'stray_quotes_first_time' => '');
                        $updateoptions = update_option('stray_quotes_options', $quotesoptions);
                        //feedback
                        if ($updateoptions) {
                            ?>
                <div id="message" class="updated fade below-h2"><p>
                <?php 
                            _e('<strong>The settings have been reset to factory defaults.</strong>', 'stray-quotes');
                            ?>
</p></div><?php 
                        } else {
                            ?>
<div id="message" class="error fade below-h2"><p>
				<?php 
                            _e('<strong>Settings not reset. Something went wrong!</strong>', 'stray-quotes');
                            ?>
</p></div><?php 
                        }
                    }
                }
            }
        }
    }
    if ($quotesoptions['comment_scode'] == 'Y') {
        $comment_scode_selected = 'checked';
    }
    if ($quotesoptions['title_scode'] == 'Y') {
        $title_scode_selected = 'checked';
    }
    if ($quotesoptions['excerpt_scode'] == 'Y') {
        $excerpt_scode_selected = 'checked';
    }
    if ($quotesoptions['widget_scode'] == 'Y') {
        $widget_scode_selected = 'checked';
    }
    if ($quotesoptions['tags_scode'] == 'Y') {
        $tags_scode_selected = 'checked';
    }
    if ($quotesoptions['categories_scode'] == 'Y') {
        $categories_scode_selected = 'checked';
    }
    if ($quotesoptions['bloginfo_scode'] == 'Y') {
        $bloginfo_scode_selected = 'checked';
    }
    if ($quotesoptions['bookmarlet_source'] == 'Y') {
        $websource_selected = 'checked';
    }
    $category = $quotesoptions['bookmarklet_cat'];
    ?>
<div class="wrap">
	<h2><?php 
    _e('Tools for Stray Random Quotes', 'stray-quotes');
    ?>
</h2>
    
    <?php 
    //the bookmarklet
    ?>
	<p><h3>Bookmarklet</h3></p>
	<blockquote>
	<p><?php 
    _e('To create quotes on the fly, drag the link below to your bowser toolbar.', 'stray-quotes');
    ?>
	<br/><span class="setting-description"><?php 
    _e('How to use: When you find some text in a web page that you want to turn into a quote, select the text and click on the link.', 'stray-quotes');
    ?>
</span></p><p><strong><a href="<?php 
    echo "javascript:if(navigator.userAgent.indexOf('Safari')%20>=%200){Q=getSelection();}else{Q=document.selection?document.selection.createRange().text:document.getSelection();}void(window.open('" . get_option('siteurl') . "/wp-admin/admin.php?page=stray_new&action=bookmarklet&quote_quote='+encodeURIComponent(Q)+'&quote_source=<a%20href='+encodeURIComponent(location.href)+'>'+encodeURIComponent(document.title)+'</a>'));";
    ?>
"><?php 
    _e('Quote this', 'stray-quotes');
    ?>
</a></strong></p>
    
    <?php 
    if (current_user_can('manage_options')) {
        ?>
<form name="frm_bookmarklet" action="<?php 
        echo $_SERVER['REQUEST_URI'];
        ?>
" method="post">
    <p><?php 
        _e('Default category for bookmarklet quotes: ', 'stray-quotes');
        ?>
<select name="categories" style="vertical-align:middle; width:14em;"> 
	<?php 
        $categorylist = make_categories();
        foreach ($categorylist as $categoryo) {
            ?>
    <option value="<?php 
            echo $categoryo;
            ?>
" style=" padding-right:5px"
    <?php 
            if ($categoryo == $category) {
                echo ' selected';
            }
            ?>
 >
    <?php 
            echo $categoryo;
            ?>
</option>
    <?php 
        }
        ?>
   
    </select><br/>
    <input type="checkbox" name="websource" value="Y" <?php 
        echo $websource_selected;
        ?>
 />&nbsp;<?php 
        _e('If checked, will add a link to the web page as source for the quote.', 'stray-quotes');
        ?>
<br/><span class="setting-description"><?php 
        _e('Note: no matter how you change these options, the bookmarklet will stay the same', 'stray-quotes');
        ?>
.</span></p>	
    <p class="submit"><input type="hidden" name="do" value="Update" />
    <input type="submit" name="boptions" value="<?php 
        _e('Apply bookmarklet options', 'stray-quotes');
        ?>
">	
	</p></form><?php 
    }
    ?>
	
	<?php 
    if (!current_user_can('manage_options')) {
        die('');
    }
    ?>
	</blockquote>
    	
	 <?php 
    //the shortcodes
    ?>
	<p><h3><?php 
    _e('Add shortcodes everywhere', 'stray-quotes');
    ?>
</h3></p>
	<blockquote><form name="frm_scode" action="<?php 
    echo $_SERVER['REQUEST_URI'];
    ?>
" method="post">
    <p><?php 
    _e('For some reason, you might want to add random things <em>via shortcodes</em> to other parts of your blog other than posts and pages. Wordpress does not support this, but a patch is pretty easy to apply. All you have to do is select here below the areas where you want to be able to use shortcodes. This method will allow you to have things such as random taglines or random category names the easiest way.', 'stray-quotes');
    ?>
    <br/>	<span class="setting-description">
    <?php 
    _e('Note that this will apply to all sorts of shortcodes and not only to those of Stray Random Quotes. Consider this carefully when you enable it for an area accessible to everyone, such as comments. If you don\'t understand any of this, don\'t use it.', 'stray-quotes');
    ?>
</span></p>
    <ul><li><input type="checkbox" name="comment_scode" value="Y" <?php 
    echo $comment_scode_selected;
    ?>
 />
	<?php 
    _e('Enable shortcodes in <strong>comments</strong>', 'stray-quotes');
    ?>
</li>
    <li><input type="checkbox" name="title_scode" value="Y" <?php 
    echo $title_scode_selected;
    ?>
 />
	<?php 
    _e('Enable shortcodes in <strong>post titles</strong>', 'stray-quotes');
    ?>
</li>
    <li><input type="checkbox" name="excerpt_scode" value="Y" <?php 
    echo $excerpt_scode_selected;
    ?>
 />
	<?php 
    _e('Enable shortcodes in <strong>post excerpts</strong>', 'stray-quotes');
    ?>
</li>
    <li><input type="checkbox" name="categories_scode" value="Y" <?php 
    echo $categories_scode_selected;
    ?>
 />
	<?php 
    _e('Enable shortcodes in <strong>categories</strong>', 'stray-quotes');
    ?>
</li>
    <li><input type="checkbox" name="tags_scode" value="Y" <?php 
    echo $tags_scode_selected;
    ?>
 />
	<?php 
    _e('Enable shortcodes in <strong>tags</strong>', 'stray-quotes');
    ?>
</li>
    <li><input type="checkbox" name="bloginfo_scode" value="Y" <?php 
    echo $bloginfo_scode_selected;
    ?>
 />
	<?php 
    _e('Enable shortcodes in <strong>bloginfo (such as blog title or the tagline)</strong>', 'stray-quotes');
    ?>
</li>
    <li><input type="checkbox" name="widget_scode" value="Y" <?php 
    echo $widget_scode_selected;
    ?>
 />
	<?php 
    _e('Enable shortcodes in <strong>text widgets</strong>', 'stray-quotes');
    ?>
</li></ul>
    <p class="submit">&nbsp;<input type="hidden" name="do" value="Update" /><input type="submit" name="enable" value="<?php 
    _e('Toggle shortcodes', 'stray-quotes');
    ?>
">	
    </p>
	</form></blockquote>
    
	<?php 
    //the index reset
    ?>
    <p><h3><?php 
    _e('Reset the index', 'stray-quotes');
    ?>
</h3></p>
    <blockquote><form name="frm_index" action="<?php 
    echo $_SERVER['REQUEST_URI'];
    ?>
" method="post">
    <p><?php 
    _e('If you want to reset the numbering of your quotes, click on the button below. If you are the cautious type, maybe you want to backup first.', 'stray-quotes');
    ?>
    <br/><span class="setting-description"><?php 
    _e('Note that after this some (or all) IDs might not correspond to the same quotes.', 'stray-quotes');
    ?>
</span></p>
    <p class="submit">&nbsp;<input type="hidden" name="do" value="Update" /><input type="submit" name="submit" value="<?php 
    _e('Reset index', 'stray-quotes');
    ?>
">	
    </p>
    </form></blockquote>

	 <?php 
    //reset options
    ?>
	<p><h3><?php 
    _e('Reset the Settings', 'stray-quotes');
    ?>
</h3></p>
	<blockquote><form name="frm_reset" action="<?php 
    echo $_SERVER['REQUEST_URI'];
    ?>
" method="post">
    <p><?php 
    _e('If you want the defaults settings back, click on the button below.', 'stray-quotes');
    ?>
    <br/>	<span class="setting-description">
    <?php 
    _e('This will revert all the settings to factory defaults according to recent issues of the plugin. They might differ from what they were many versions ago.', 'stray-quotes');
    ?>
</span></p>
    
    <p class="submit">&nbsp;<input type="hidden" name="do" value="Update" /><input type="submit" name="resetsettings" value="<?php 
    _e('Reset Settings', 'stray-quotes');
    ?>
">	
    </p>
	</form></blockquote>
        
	</div><?php 
}
コード例 #5
0
function stray_intro()
{
    global $wpdb, $current_user;
    //load options
    $quotesoptions = array();
    $quotesoptions = get_option('stray_quotes_options');
    //security check
    if ($quotesoptions['stray_multiuser'] == false && !current_user_can('manage_options')) {
        die('Access Denied');
    }
    $widgetpage = get_option('siteurl') . "/wp-admin/widgets.php";
    $management = get_option('siteurl') . "/wp-admin/admin.php?page=stray_manage";
    $options = get_option('siteurl') . "/wp-admin/admin.php?page=stray_quotes_options";
    $new = get_option('siteurl') . "/wp-admin/admin.php?page=stray_new";
    $help = get_option('siteurl') . "/wp-admin/admin.php?page=stray_help";
    $toolspage = get_option('siteurl') . "/wp-admin/admin.php?page=stray_tools";
    $straymessage = $quotesoptions['stray_quotes_first_time'];
    //get total quotes
    $totalsql = "SELECT COUNT(`quoteID`) AS `Rows` FROM `" . WP_STRAY_QUOTES_TABLE . "` WHERE `user`='" . $current_user->user_nicename . "'";
    $totalquotes = $wpdb->get_var($totalsql);
    //feedback following activation (see main file)
    if ($straymessage != "") {
        ?>
<div id="message" class="updated fade"><ul><?php 
        echo $straymessage;
        ?>
</ul></div><?php 
        //empty message after feedback
        $quotesoptions['stray_quotes_first_time'] = "";
        update_option('stray_quotes_options', $quotesoptions);
    }
    ?>
<div class="wrap"><h2>Stray Random Quotes: <?php 
    _e('Overview', 'stray-quotes');
    ?>
</h2><?php 
    echo STRAY_DIR . '=stray_dir<br/>' . WP_STRAY_QUOTES_PATH . '=WP_STRAY_QUOTES_PATH<br/>';
    echo WP_CONTENT_URL . '=WP_CONTENT_URL<br/>' . WP_SITEURL . '=WP_SITEURL<br/>' . WP_PLUGIN_URL . '=WP_PLUGIN_URL<br/>' . WP_PLUGIN_DIR . '=WP_PLUGIN_DIR<br/><br/>';
    echo ABSPATH . 'wp-content/plugins/' . STRAY_DIR . 'lang<br/>';
    echo WP_PLUGIN_DIR . '/' . STRAY_DIR . 'lang<br/>';
    if ($totalquotes > 0) {
        //quotes and categories
        $howmanycategories = count(make_categories($current_user->user_nicename));
        if ($howmanycategories == 1) {
            $howmanycategories = __('one category', 'stray-quotes');
        } else {
            if ($howmanycategories) {
                $howmanycategories = $howmanycategories . ' ' . __('categories', 'stray-quotes');
            }
            $categorymost = mostused("category");
        }
        $sql = "SELECT COUNT( `category` ) AS `Rows` , `category` FROM `" . WP_STRAY_QUOTES_TABLE . "` WHERE `user`='" . $current_user->user_nicename . "' GROUP BY `category` ORDER BY `Rows` DESC";
        $howmany = $wpdb->get_results($sql);
        if (count($howmany) > 1) {
            $as = __(', distributed as follows:', 'stray-quotes');
        } else {
            $as = '.';
        }
        $search = array('%s1', '%s2', '%s3');
        $replace = array($totalquotes, $howmanycategories, $as);
        echo str_replace($search, $replace, __('<p>Right now you have <strong>%s1 quotes</strong> in <strong>%s2</strong>%s3</p>', 'stray-quotes'));
        if ($howmany && count($howmany) > 1) {
            ?>
		
			<table class="widefat" style="width:200px"><?php 
            $i = 0;
            foreach ($howmany as $many) {
                $alt = $i % 2 == 0 ? ' class="alternate"' : '';
                ?>
<tr <?php 
                echo $alt;
                ?>
>
				<th scope="row"><?php 
                echo $many->Rows;
                ?>
</th>
				<td><?php 
                echo $many->category;
                ?>
</td>
				</tr><?php 
            }
            ?>
			</table><?php 
        }
        //visible quotes
        $visiblequotes = $wpdb->get_var("SELECT COUNT(`quoteID`) as rows FROM " . WP_STRAY_QUOTES_TABLE . " WHERE visible='yes' AND `user`='" . $current_user->user_nicename . "'");
        if ($visiblequotes == $totalquotes) {
            $visiblequotes = __('All your quotes ', 'stray-quotes');
        }
        echo str_replace('%s3', $visiblequotes, __('<p><strong>%s3</strong> are visible.</p>', 'stray-quotes'));
        //author
        $authormost = mostused("author");
        if ($authormost) {
            echo str_replace('%s5', $authormost, __('<p>Your most quoted author is <strong>%s5</strong>.</p>', 'stray-quotes'));
        }
        //source
        $sourcemost = mostused("source");
        if ($sourcemost) {
            str_replace('%s5', $sourcemost, __('<p>Your most used source is <strong>%s5</strong>.</p>', 'stray-quotes'));
        }
    } else {
        _e('There is nothing to report.', 'stray-quotes');
    }
    ?>
<p><?php 
    //link pages
    $search = array("%s1", "%s2");
    $replace = array($new, $management);
    echo str_replace($search, $replace, __('To start doing stuff, you can <a href="%s1"><strong>add new quotes</strong></a>;<br />use the <a href="%s2"><strong>manage</strong></a> page to edit or delete existing quotes;', 'stray-quotes'));
    if (current_user_can('manage_options')) {
        echo str_replace("%s3", $options, __('<br />change the <a href="%s3"><strong>settings</strong></a> to control how the quotes are displayed on your blog;', 'stray-quotes'));
    }
    $search2 = array("%s4", "%s5");
    $replace2 = array($help, $toolspage);
    echo str_replace($search2, $replace2, __('<br/>a <a href="%s5"><strong>tools page</strong></a> can help you do more;<br/>if you\'re new to all this, visit the <a href="%s4"><strong>help page</strong></a>.', 'stray-quotes'));
    ?>
    
	</p>
    
    <p><?php 
    _e('Brought to you by <a href="http://code.italyisfalling.com">lines of code</a>', 'stray-quotes');
    ?>
, <?php 
    echo date('Y');
    ?>
.<br/><?php 
    _e('Happy quoting.', 'stray-quotes');
    ?>
</p><br/>
    
    <?php 
    //donate
    ?>
	<p><form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIHTwYJKoZIhvcNAQcEoIIHQDCCBzwCAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJKoZIhvcNAQEBBQAEgYA2O4E/j8fFampI20hAUYhfyrYbcbf6zOimrurK2YJe4cqTS8sb9/6LHDuOzB8k6p9PwrlCHch30ugTvxn2YSBG6UO2yW7MnJ8SUhqFjDdPnOOjwz1BeHbhTnRq2AAqOUIoBmHeN7rkaZmIAMTPGzaTDlctrvBjXE6KtyIYOLZGOTELMAkGBSsOAwIaBQAwgcwGCSqGSIb3DQEHATAUBggqhkiG9w0DBwQI50y9eCyGwC+AgagvUvGaa2/4FDe+MbGaA/UtbPk8eaKJ+/drzfxr7wAU8PZyfQZZOLs9OU+g03BMaNLf6D1hosdcwh04KCPKKVgso0YEn5QUJ5l+kMVvHDwPfR4w45qxjE4Kty7S6pAoH3pwRCPmyhiYNQBPMp+WaK4zc3sY1tf3BhVs0mIlgJniCSoKhd7sla4AkFas+F/f5eTq1skZWzFUG8lZx6QEuJVrY9TpiOmAT+agggOHMIIDgzCCAuygAwIBAgIBADANBgkqhkiG9w0BAQUFADCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20wHhcNMDQwMjEzMTAxMzE1WhcNMzUwMjEzMTAxMzE1WjCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMFHTt38RMxLXJyO2SmS+Ndl72T7oKJ4u4uw+6awntALWh03PewmIJuzbALScsTS4sZoS1fKciBGoh11gIfHzylvkdNe/hJl66/RGqrj5rFb08sAABNTzDTiqqNpJeBsYs/c2aiGozptX2RlnBktH+SUNpAajW724Nv2Wvhif6sFAgMBAAGjge4wgeswHQYDVR0OBBYEFJaffLvGbxe9WT9S1wob7BDWZJRrMIG7BgNVHSMEgbMwgbCAFJaffLvGbxe9WT9S1wob7BDWZJRroYGUpIGRMIGOMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExFjAUBgNVBAcTDU1vdW50YWluIFZpZXcxFDASBgNVBAoTC1BheVBhbCBJbmMuMRMwEQYDVQQLFApsaXZlX2NlcnRzMREwDwYDVQQDFAhsaXZlX2FwaTEcMBoGCSqGSIb3DQEJARYNcmVAcGF5cGFsLmNvbYIBADAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GBAIFfOlaagFrl71+jq6OKidbWFSE+Q4FqROvdgIONth+8kSK//Y/4ihuE4Ymvzn5ceE3S/iBSQQMjyvb+s2TWbQYDwcp129OPIbD9epdr4tJOUNiSojw7BHwYRiPh58S1xGlFgHFXwrEBb3dgNbMUa+u4qectsMAXpVHnD9wIyfmHMYIBmjCCAZYCAQEwgZQwgY4xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLUGF5UGFsIEluYy4xEzARBgNVBAsUCmxpdmVfY2VydHMxETAPBgNVBAMUCGxpdmVfYXBpMRwwGgYJKoZIhvcNAQkBFg1yZUBwYXlwYWwuY29tAgEAMAkGBSsOAwIaBQCgXTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0wOTAzMTUxOTU0MzlaMCMGCSqGSIb3DQEJBDEWBBRW8vE+0WlOclLy+2xT45QYBoG2XTANBgkqhkiG9w0BAQEFAASBgBaizvQNlNCTsdBS3+6v+BROeHwOznMLFmlFYI3KW1FU9o0Fvk7suoOWExeqCMMLEjSiVprn2+e9+oKVEERSa5tYJoohmZoTFmOg349OdXvJ5Y0PaEiIslltATysrUsN66JHxisLLamvvhVVQDnjon/LooFHfKL0DNiqABTKC5xO-----END PKCS7-----
">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"style="padding:0;border:none">
</form></p></div><?php 
}
コード例 #6
0
    function control($widget_args = 1)
    {
        global $wp_registered_widgets;
        static $updated = false;
        $quotesoptions = get_option('stray_quotes_options');
        //extract widget arguments
        if (is_numeric($widget_args)) {
            $widget_args = array('number' => $widget_args);
        }
        $widget_args = wp_parse_args($widget_args, array('number' => -1));
        extract($widget_args, EXTR_SKIP);
        $options_all = get_option('widget_stray_quotes');
        if (!is_array($options_all)) {
            $options_all = array();
        }
        if (!$updated && !empty($_POST['sidebar'])) {
            $sidebar = (string) $_POST['sidebar'];
            $sidebars_widgets = wp_get_sidebars_widgets();
            if (isset($sidebars_widgets[$sidebar])) {
                $this_sidebar =& $sidebars_widgets[$sidebar];
            } else {
                $this_sidebar = array();
            }
            foreach ($this_sidebar as $_widget_id) {
                if ('widget_stray_quotes' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number'])) {
                    $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
                    if (!in_array("stray_widgets-{$widget_number}", $_POST['widget-id'])) {
                        unset($options_all[$widget_number]);
                    }
                }
            }
            foreach ((array) $_POST['widget_stray_quotes'] as $widget_number => $posted) {
                if (!isset($posted['title']) && isset($options_all[$widget_number])) {
                    continue;
                }
                $options = array();
                $options['title'] = $posted['title'];
                $options['groups'] = isset($posted['groups']) ? implode(',', $posted['groups']) : '';
                $options['sequence'] = $posted['sequence'];
                $options['linkphrase'] = $posted['linkphrase'];
                $options['timer'] = $posted['timer'];
                $options['noajax'] = $posted['noajax'];
                $options['multi'] = $posted['multi'];
                $options['disableaspect'] = $posted['disableaspect'];
                $options['contributor'] = $posted['contributor'];
                $options_all[$widget_number] = $options;
            }
            update_option('widget_stray_quotes', $options_all);
            $updated = true;
        }
        $default_options = array('title' => __('Random Quote', 'stray-quotes'), 'groups' => implode(",", make_categories()), 'sequence' => true, 'multi' => '1', 'linkphrase' => $quotesoptions['stray_loader'], 'timer' => '0', 'noajax' => false, 'disableaspect' => false, 'contributor' => '');
        if (-1 == $number) {
            $number = '%i%';
            $values = $default_options;
        } else {
            $values = $options_all[$number];
        }
        if ($values['sequence'] == "Y") {
            $random_selected = ' checked="checked"';
        }
        if ($values['noajax'] == "Y") {
            $noajax_selected = ' checked="checked"';
        }
        if ($values['disableaspect'] == "Y") {
            $disableaspect_selected = ' checked="checked"';
        }
        if ($values['timer'] == '') {
            $values['timer'] = '0';
        }
        if ($values['multi'] == '') {
            $values['multi'] = '1';
        }
        // widget options form
        ?>
        <p align="right"><span class="setting-description"><small><?php 
        _e('all settings are for this widget only.', 'stray-quotes');
        ?>
</small></span></p>
        <p><label><strong><?php 
        _e('Title', 'stray-quotes');
        ?>
</strong></label>
		<input class="widefat" id="widget_stray_quotes-<?php 
        echo $number;
        ?>
-title" 
        name="widget_stray_quotes[<?php 
        echo $number;
        ?>
][title]" type="text" 
        value="<?php 
        echo htmlspecialchars($values['title'], ENT_QUOTES);
        ?>
" />
        </p>
        
        <div style="float:left; width:210px; padding-right:10px;">
        
        <?php 
        if ($quotesoptions['stray_multiuser'] == 'Y') {
            $height = '70px';
        } else {
            $height = '130px';
        }
        ?>
        
        
		<p><label><strong><?php 
        _e('Categories', 'stray-quotes');
        ?>
</strong><br/><span class="setting-description"><small><?php 
        _e('Quotes are taken from these categories. Drag the mouse or ctrl-click to multi-select', 'stray-quotes');
        ?>
</small></span></label>
		<select class="widefat" style="width: 100%; height: <?php 
        echo $height;
        ?>
;" name="widget_stray_quotes[<?php 
        echo $number;
        ?>
][groups][]" 
        id="widget_stray_quotes-<?php 
        echo $number;
        ?>
-groups" multiple="multiple">
		<?php 
        $items = make_categories();
        $groups = explode(',', $values['groups']);
        if ($items) {
            foreach ($items as $item) {
                if (in_array($item, $groups)) {
                    $current = ' selected="selected"';
                } else {
                    $current = '';
                }
                echo "\n\t<option value='{$item}'{$current}>{$item}</option>";
            }
        }
        ?>
</select></p>
        
        <?php 
        if ($quotesoptions['stray_multiuser'] == 'Y') {
            ?>
        <p><label><strong><?php 
            _e('Only from this contributor', 'stray-quotes');
            ?>
</strong><br/><span class="setting-description"> <small> <?php 
            _e('if left empty, quotes are taken from all contributors.', 'stray-quotes');
            ?>
</small></span></label>
		<input class="widefat" id="widget_stray_quotes-<?php 
            echo $number;
            ?>
-user" 
        name="widget_stray_quotes[<?php 
            echo $number;
            ?>
][contributor]" type="text" 
        value="<?php 
            echo htmlspecialchars($values['contributor'], ENT_QUOTES);
            ?>
" /></p>
        <?php 
        }
        ?>
 
 		</div>
        <div style="float:left; width:200px; border-left:1px #ccc solid; padding-left:10px;">
        
		<p><input type="checkbox" name="widget_stray_quotes[<?php 
        echo $number;
        ?>
][sequence]" value="Y" <?php 
        echo $random_selected;
        ?>
 /><label><strong><?php 
        _e('Random', 'stray-quotes');
        ?>
</strong><br/><span class="setting-description"><small><?php 
        _e('Leave unckecked to load the quotes in order beginning from a random one.', 'stray-quotes');
        ?>
</small></span></label><br />&nbsp;</p>
        
 		
		<p><strong><?php 
        _e('Show', 'stray-quotes');
        ?>
</strong>&nbsp;<input type="text" style="border: 1px solid #ccc;width:40px" name="widget_stray_quotes[<?php 
        echo $number;
        ?>
][multi]" value="<?php 
        echo $values['multi'];
        ?>
" maxlength="4" />&nbsp;<strong><?php 
        _e('quotes at a time', 'stray-quotes');
        ?>
</strong><br />&nbsp;</p>
        
        <p><input type="checkbox" name="widget_stray_quotes[<?php 
        echo $number;
        ?>
][disableaspect]" value="Y" <?php 
        echo $disableaspect_selected;
        ?>
 /><label><strong><?php 
        _e('Disable aspect settings', 'stray-quotes');
        ?>
</strong><br/><span class="setting-description"><small><?php 
        echo str_replace("%s1", get_option('siteurl') . "/wp-admin/admin.php?page=stray_quotes_options", __('As set in the "How the quotes look" section of the <a href="%s1">settings page</a>.', 'stray-quotes'));
        ?>
</small></span></label></p>
        
        
        </div>
        
        <div style="float:right; width:200px; height:100%; border-left:1px #ccc solid; padding-left:10px;"><!--<p><?php 
        _e('AJAX functionality:', 'stray-quotes');
        ?>
</p>-->
		<p><label><strong><?php 
        _e('Reload phrase', 'stray-quotes');
        ?>
</strong><br/><span class="setting-description"> <small> <?php 
        _e('if left empty, reloading is done by clicking on the quote area.', 'stray-quotes');
        ?>
</small></span></label>
		<input class="widefat" id="widget_stray_quotes-<?php 
        echo $number;
        ?>
-title" 
        name="widget_stray_quotes[<?php 
        echo $number;
        ?>
][linkphrase]" type="text" 
        value="<?php 
        echo htmlspecialchars($values['linkphrase'], ENT_QUOTES);
        ?>
" /></p>
        

        
        <p><strong><?php 
        _e('Rotate every', 'stray-quotes');
        ?>
</strong>&nbsp;<input type="text" style="border: 1px solid #ccc;width:30px" name="widget_stray_quotes[<?php 
        echo $number;
        ?>
][timer]" value="<?php 
        echo $values['timer'];
        ?>
" />&nbsp;<strong><?php 
        _e('seconds', 'stray-quotes');
        ?>
</strong><br/><span class="setting-description"><small> <?php 
        _e('Reload the quote after the set interval. This hides the link phrase. Leave this empty or set it to 0 to disable.', 'stray-quotes');
        ?>
</small></span></p>
        


		<p><input type="checkbox" name="widget_stray_quotes[<?php 
        echo $number;
        ?>
][noajax]" value="Y" <?php 
        echo $noajax_selected;
        ?>
 /><label><strong><?php 
        _e('Disable AJAX', 'stray-quotes');
        ?>
</strong><br/><span class="setting-description"><small> <?php 
        _e('Check to disable any dynamic reloading of the quote.', 'stray-quotes');
        ?>
</small></span></label></p>
        
        </div>     
        <div style="clear:both;">&nbsp;</div><?php 
    }