Options/Ask Me after activation of the plugin. To see the plugin in action you can visit Sara's or Jelena's blog Inspired by Dean Edwards' about me script http://dean.edwards.name/about */ /********************** CONSTANTS **********************/ define("TABLE_AM_QUESTIONS", $table_prefix."askme_questions"); define("TABLE_AM_QUESTIONS_PHRASE", $table_prefix."askme_questions_phrases"); define("TABLE_AM_COWARDS", $table_prefix."askme_cowards"); define("TABLE_AM_SETTINGS", $table_prefix."askme_settings"); /* // WordPress 1.5 includes this file again on the options page. Avoid duplicate declaration: if ( function_exists("is_plugin_page") && is_plugin_page() ) { askme_options_page(); return; } */ add_action('options_page_askme', 'askme_options_page'); /******************** INSTALLATION FUNC ********************/ function askme_install () { global $table_prefix, $wpdb; global $user_ID; require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); $table_name_questions = $table_prefix . "askme_questions"; $table_name_questions_phrase = $table_prefix . "askme_questions_phrases"; $table_name_cowards = $table_prefix . "askme_cowards"; $table_name_settings = $table_prefix . "askme_settings"; if($wpdb->get_var("show tables like '$table_name_questions'") != $table_name_questions) { $sql = "CREATE TABLE ".$table_name_questions." ( question_ID bigint(20) NOT NULL auto_increment, question text NOT NULL, answer text, user varchar(50) default NULL, email varchar(100) default '', url varchar(100) default '', approved tinyint(1) default '0', date_entered datetime default '0000-00-00 00:00:00', wants_return_email tinyint(1) default '0', PRIMARY KEY (`question_ID`) );"; dbDelta($sql); } if($wpdb->get_var("show tables like '$table_name_questions_phrase'") != $table_name_questions_phrase) { $sql = "CREATE TABLE ".$table_name_questions_phrase." ( phrase_ID bigint(20) NOT NULL auto_increment, phrase varchar(255) NOT NULL default '', PRIMARY KEY (`phrase_ID`) )"; dbDelta($sql); $sql = "INSERT INTO ".$table_name_questions_phrase." (phrase_ID, phrase) VALUES (1, 'asks');"; $wpdb->query($sql); } if($wpdb->get_var("show tables like '$table_name_cowards'") != $table_name_questions) { $sql = "CREATE TABLE ".$table_name_cowards." ( coward_ID bigint(20) NOT NULL auto_increment, coward varchar(255) NOT NULL default '', PRIMARY KEY (`coward_ID`) );"; dbDelta($sql); $sql = "INSERT INTO ".$table_name_cowards." (coward_ID, coward) VALUES (1, 'Guest'), (2, 'Anonymous');"; $wpdb->query($sql); } //create a page called Ask me //prepare date: $date_now = current_time('mysql'); $date_now_gm = get_gmt_from_date($date_now); $page_url = get_option('siteurl')."/ask-me/"; $content = "Regular about pages are boring, aren't they? In addition to having a typical \"About Me\" page, I decided to have a page where visitors could ask what they want to know instead of me telling them what I think they should know. So go ahead, ask me a question. Of course these questions are moderated, but pretty much anything goes (within reason). "; $content = $wpdb->escape($content); $sql = "INSERT INTO ".$table_prefix."posts SET"; $sql .= " post_author = '".$user_ID."'"; $sql .= ", post_date = '".$date_now."'"; $sql .= ", post_date_gmt = '".$date_now_gm."'"; $sql .= ", post_title = 'Ask me'"; $sql .= ", post_name = 'ask-me'"; $sql .= ", post_status = 'static'"; $sql .= ", post_category = 0"; $sql .= ", post_parent = 0"; $sql .= ", post_content = '".$content."'"; $wpdb->query($sql); if($wpdb->get_var("show tables like '$table_name_settings'") != $table_name_questions) { $sql = "CREATE TABLE ".$table_name_settings." ( SettingsID int(11) NOT NULL auto_increment, Email varchar(255) NOT NULL default '', PerPage smallint(6) NOT NULL default '0', PerPagePublic tinyint(4) NOT NULL default '0', FormAction varchar(100) NOT NULL, PRIMARY KEY (`SettingsID`) );"; dbDelta($sql); $email = get_option('admin_email'); $sql = "INSERT INTO ".$table_name_settings." (SettingsID, Email, PerPage, PerPagePublic, FormAction) VALUES (1, '" . $email . "', 20, 20, '".$page_url."');"; $results = $wpdb->query($sql); } return true; } function askme_get_questions() { global $wpdb; if(!isset($_GET['start'])) { $start = 0; } else { $start = $_GET['start']; } //get No of records from settings tbl $sql = "SELECT PerPagePublic FROM ".TABLE_AM_SETTINGS." LIMIT 1"; $settings = $wpdb->get_row($sql); $limit = $settings->PerPagePublic; // No of records to be shown per page. askme_print_list($start, $limit); $numrows = askme_get_questions_count("SELECT question, answer, user, email, url, date_entered FROM ".TABLE_AM_QUESTIONS." WHERE approved='1' "); echo "
Be the first to ask a Question!
"; } } //get a random anonymous user title function askme_get_coward() { global $wpdb; $cowards = $wpdb->get_row("SELECT coward FROM ".TABLE_AM_COWARDS." ORDER BY RAND() LIMIT 1"); return $cowards->coward; }//askme_get_coward() function output_form() { global $start; global $limit; global $wpdb; //get action from the settings $result = $wpdb->get_row("select FormAction from " . TABLE_AM_SETTINGS); $action = $result->FormAction; $form = ''; echo '
'; echo ''; echo '
'; echo ''; echo '
'; echo '; echo '
'; echo ''; echo '
'; echo ''; echo '';*/ }//output_form() function check_submit() { if (isset($_POST['question'])) { $errors = verify_input(); if (!empty($errors)) { echo "" . $errors . ""; } else { echo "Yay! Your question is on the way to be answered. :)"; insert_question(); send_email(); } } }//check_submit() function send_email() { global $wpdb; $settings = $wpdb->get_row("SELECT Email, PerPage FROM ".TABLE_AM_SETTINGS." LIMIT 1"); $subject = "Someone asked you a question!"; $from = "From: " . $settings->Email; $body = "A question is waiting for your moderation:\n\n"; $body .= "User: " . $_POST['username'] . "\n"; $body .= "Email: " . $_POST['email'] . "\n"; $body .= "URL: " . $_POST['url'] . "\n"; $body .= "Question: " . $_POST['question'] . "\n"; mail($settings->Email, $subject, $body, $from); }//send_email() function insert_question() { global $wpdb; if($_POST['wants_return_email']) { $checked = 1; } else { $checked = 0; } $name = $wpdb->escape($_POST['username']); $email = $wpdb->escape($_POST['email']); $url = $wpdb->escape($_POST['url']); if ($url == "http://") { $url = ""; } $question = $wpdb->escape($_POST['question']); $query = "INSERT INTO ".TABLE_AM_QUESTIONS." SET"; $query .= " question = '".$question."'"; $query .= ", user = '".$name."'"; $query .= ", url = '".$url."'"; $query .= ", email = '".$email."'"; $query .= ", approved = 0"; $query .= ", date_entered = NOW()"; $query .= ", wants_return_email = " . $checked; $wpdb->query($query); }//insert_question() function verify_input() { $errString = ''; if ($_POST['email'] == '') { $errString .= "You must enter your email.| PREV"; } echo " | "; $i=0; $j=1; for($i=0;$i < $numrows;$i=$i+$limit) { if($i <> $start) { echo " " . $j . " "; } else { echo "" . $j . ""; } /// Current page is not displayed as link and given font color blue $j=$j+1; } echo " | "; if($start <= $numrows - $limit) { print "NEXT"; } echo " |
You have successfully deleted your question.
You have successfully deleted selected questions.
You have successfully updated your question.
You have successfully updated your 'Ask me' settings.