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 ""; } function askme_get_questions_count($sql) { global $wpdb; $questions = $wpdb->get_results($sql); return count($questions); } function askme_print_list($start, $limit) { //global $limit; //global $begin; global $wpdb; $questions = $wpdb->get_results("SELECT question, answer, user, email, url, date_entered FROM ".TABLE_AM_QUESTIONS." WHERE approved='1' ORDER BY date_entered DESC limit " . $start . ", " . $limit); $phrases = $wpdb->get_results("SELECT phrase FROM ".TABLE_AM_QUESTIONS_PHRASE." ORDER BY rand()"); if(is_array($questions) && !empty($questions)) { foreach ($questions as $question) { $randNumber = rand(1, count($phrases)-1); $post_question = stripslashes($question->question); $post_answer = stripslashes($question->answer); $url = $question->url; $name = $question->user; if (trim($name) == "") { $name = askme_get_coward(); } //start the question/answer div here echo "
"; //the phrase.. i.e. Sara wants to know: echo "
"; echo "
"; echo "
" . $post_question . "
"; if($url) { echo "" . $name . " "; } else { echo $name . " "; } echo "
" . $post_answer . "
"; echo "
"; } } else { 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 = '

Ask a Question


 
'; echo $form; /*echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; echo '

; echo '

Answer
Name
Email
URL
Date Entered
Approved:
approved){echo "checked";} ?>" id="askme_approved" />
get_row("SELECT Email, PerPage, PerPagePublic, FormAction FROM ".TABLE_AM_SETTINGS." LIMIT 1"); ?>
Back to Question list

Update Settings

Email Address
Admin Per Page
Public Per Page
Form action
query($sql); echo ("

You have successfully deleted your question.

"); }//askme_admin_delete_question($id) function askme_admin_delete_question_all($id) { global $wpdb; $sql = "DELETE FROM ".TABLE_AM_QUESTIONS; $sql .= " WHERE 1>2"; for($i=0; $i query($sql); echo ("

You have successfully deleted selected questions.

"); }//askme_admin_delete_question_all($id) function askme_admin_edit_question($id) { global $wpdb; $sql = "UPDATE ".TABLE_AM_QUESTIONS." SET " . "question = '" . addslashes($_POST['askme_question']) . "', " . "answer = '" . addslashes($_POST['askme_answer']) . "', " . "user = '" . addslashes($_POST['askme_name']) . "', " . "email = '" . $_POST['askme_email'] . "', " . "url = '" . $_POST['askme_url'] . "', " . "date_entered = '" . $_POST['askme_date'] . "', "; $approved = 0; if ($_POST['askme_approved']) { $approved = 1; } $sql .= "approved = " . $approved . " WHERE question_id = " . $id; // echo $sql; $wpdb->query($sql); echo ("

You have successfully updated your question.

"); //if the person wants to be notified of a response, send email if($_POST['wants_return_email']==1 && $approved) { $sql = "SELECT Email, FormAction FROM ".TABLE_AM_SETTINGS." LIMIT 1"; $settings = $wpdb->get_row($sql); $email = $settings->Email; // Your email address $action = $settings->FormAction; // form action $sql = "select option_value from wp_options where option_name = 'blogname'"; $result = $wpdb->get_row($sql); $blogname = $result->option_value; //this will be the blog name $sql = "select option_value from wp_options where option_name = 'siteurl'"; $result = $wpdb->get_row($sql); $siteurl = $result->option_value; //this will be the site url $headers = "From: " . $email . "\r\n"; $subject = "Your question has been answered at: " . $blogname; $to = $_POST['askme_email']; $message = "Thank you for asking a question, I have answered it now. Please visit my site to see the answer:\n\n "; $message .= $siteurl . $action; mail($to,$subject,$message,$headers); }//end email }//askme_admin_edit_question($id) function askme_admin_edit_settings($data) { global $wpdb; $sql = "UPDATE ".TABLE_AM_SETTINGS." SET"; $sql .= " Email = '".$data["Email"]."'"; if(empty($data["PerPage"])) $sql .= ", PerPage = 10"; else $sql .= ", PerPage = '".$data["PerPage"]."'"; if(empty($data["PerPagePublic"])) $sql .= ", PerPagePublic = 10"; else $sql .= ", PerPagePublic = '".$data["PerPagePublic"]."'"; $wpdb->query($sql); echo ("

You have successfully updated your 'Ask me' settings.

"); }//askme_admin_edit_settings($data) function askme_options_page () { if($_POST['submit']) { if($_POST["f_settings"]["action"] == "yes") { //call function to update settings askme_admin_edit_settings($_POST["f_settings"]); askme_admin_settings(); } else { askme_admin_edit_question($_POST['askme_id']); askme_admin_get_questions(); } } else if ($_POST['action'] == "deleteall") { //we need to delete bunch of G&A askme_admin_delete_question_all($_POST["questionid"]); askme_admin_get_questions(); } else if ($_GET['action'] == 'edit') { askme_admin_display_form($_GET['id']); } else if ($_GET['action'] == 'delete') { askme_admin_delete_question($_GET['id']); askme_admin_get_questions(); } else if ($_GET['settings'] == 'yes') { askme_admin_settings(); } else { askme_admin_get_questions(); } }//askme_options_page () add_action('admin_menu', 'askme_add_options_page'); add_action('activate_askme.php','askme_install'); ?>