Example #1
0
 /**
  * Returns an array of objects (as returned by $wpdb->get_results()) of this user's recent posts.
  *
  * @param int $count Amount of rows to return.
  * @return ObjectArray
  */
 public function getRecentPosts($count = 15, $order = 'DESC')
 {
     $wpdb = ThinkUpWordPressPlugin::getDatabaseConnection();
     $options_array = ThinkUpWordPressPlugin::getOptionsArray();
     // database may be on same server but not same db as wordpress
     $db = $wpdb->escape($options_array['thinkup_db']['value']);
     $prefix = $options_array['thinkup_table_prefix']['value'];
     if ($count >= 0) {
         $sql = $wpdb->prepare("\n                SELECT *\n                FROM {$db}." . $prefix . "posts\n                WHERE author_username='******'\n                    AND in_reply_to_user_id is null\n                    AND network='%s'\n                ORDER BY pub_date {$wpdb->escape($order)}\n                LIMIT %d", $this->username, $this->network, $count);
     } else {
         $sql = $wpdb->prepare("\n                SELECT *\n                FROM {$db}." . $prefix . "posts\n                WHERE author_username='******'\n                    AND in_reply_to_user_id is null\n                    AND network='%s'\n                ORDER BY pub_date {$wpdb->escape($order)}", $this->username, $this->network);
     }
     return $wpdb->get_results($sql);
 }
    /**
     * The default landing page for the plugin's admin pages.
     *
     * PHP + HTML = Messy :(
     */
    public static function settings() {
        //fetch the options array
        $options_array = ThinkUpWordPressPlugin::getOptionsArray();

        //check to see if the form was submitted
        if (isset($_POST['Submit'])) {
            //make sure the user submitting the form is an admin
            check_admin_referer('thinkup_settings_submit',
            ThinkUpWordPressPlugin::nonceName());

            foreach ($options_array as $opt) {
                // read posted values
                $opt['value'] = $_POST[$opt['key']];

                // save the posted value in the database
                if ($opt['key'] == 'thinkup_dbpw') {
                    // scramble the password
                    update_option($opt['key'],
                    ThinkUpWordPressPlugin::scramblePassword($opt['value']));
                } else {
                    // store non-passwords normally
                    update_option($opt['key'], $opt['value']);
                }
            }

            // print "updated!" message to screen
            ?>
<div class="updated">
<p><strong> <?php _e('Options saved.',
ThinkUpWordPressPlugin::uniqueIdentifier()); ?> </strong></p>
</div>
<?php

//force an update to the options array for display purposes
$options_array = ThinkUpWordPressPlugin::getOptionsArray('force-update');
        }

        ?>

<div id="poststuff" class="ui-sortable meta-box-sortable">
<div class="postbox" id="thinkup_settings">
<h3><?php _e('ThinkUp Plugin Settings',
ThinkUpWordPressPlugin::uniqueIdentifier()); ?></h3>
<div class="inside" style="line-height: 2;">
<form name="thinkup_settings_form" method="post" action=""><?php
//Add the nonce field for added security.
wp_nonce_field('thinkup_settings_submit',
ThinkUpWordPressPlugin::nonceName());
?>

<table>
<?php
foreach ($options_array as $opt) {
    if ($opt['key'] == 'thinkup_dbpw') {
        $field_value =
        ThinkUpWordPressPlugin::unscramblePassword(
        get_option($opt['key']));
    }
    else {
        $field_value = get_option($opt['key']);
    }

    ?>
	<tr>
		<td align="right" valign="top"><?php _e($opt['label'], 
		ThinkUpWordPressPlugin::uniqueIdentifier()); ?></td>
		<td><input type="<?php echo $opt['type']; ?>"
			name="<?php echo $opt['key'] ?>" value="<?php echo $field_value ?>"
			size="20"> <br />
		<small> <?php echo $opt['description']; ?> </small></td>
	</tr>
	<?php } ?>
</table>

<p class="submit"><input type="submit" name="Submit"
	value="<?php _e('Update Options',
                               ThinkUpWordPressPlugin::uniqueIdentifier()); ?>" />
</p>
</form>
</div>
</div>
</div>
                               <?php
    }
Example #3
0
    /**
     * Return an object (as returned by $wpdb->get_row()) of this post's database record.
     *
     * @return Object Post's database record.
     */
    public function getPostInfo() {
        if (!isset($this->post_info)) {
            $wpdb = ThinkUpWordPressPlugin::getDatabaseConnection();

            if (!isset($this->get_post_info_sql)) {
                $options_array = ThinkUpWordPressPlugin::getOptionsArray();

                // database may be on same server but not same db as wordpress
                $db = $wpdb->escape($options_array['thinkup_db']['value']);
                $prefix = $options_array['thinkup_table_prefix']['value'];

                $this->get_post_info_sql = $wpdb->prepare("
                     SELECT *
                     FROM
                     `$db`.`".$prefix."posts`
                     WHERE
                         post_id = {$wpdb->escape($this->post_id)}
                         AND network = %s;", $this->network);
            }
            $this->post_info = $wpdb->get_row($this->get_post_info_sql);
        }

        return $this->post_info;
    }