Skip to content

Commit

Permalink
fixed sending email for admin's posts, password requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahY committed Feb 23, 2012
1 parent b3bb8c4 commit b309319
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
20 changes: 19 additions & 1 deletion qa-admin-check.php
Expand Up @@ -5,8 +5,9 @@ function process_event($event, $userid, $handle, $cookieid, $params) {
if (qa_opt('expert_question_enable')) {
switch ($event) {
case 'a_post':
if(qa_opt('notify_admin_a_post'))
if(qa_opt('notify_admin_a_post')) {
$this->sendEmail($event,$userid,$handle,$params);
}
break;
case 'c_post':
if(qa_opt('notify_admin_c_post'))
Expand All @@ -18,6 +19,10 @@ function process_event($event, $userid, $handle, $cookieid, $params) {
}
}
function sendEmail($event,$userid,$handle,$params){
$email = $this->getEmail($userid);
if($email == qa_opt('feedback_email'))
return;

$parent = qa_db_read_one_assoc(
qa_db_query_sub(
'SELECT * FROM ^posts WHERE postid=#',
Expand Down Expand Up @@ -51,4 +56,17 @@ function sendEmail($event,$userid,$handle,$params){
'^url'=> $url,
));
}
function getEmail($userid) {
require_once QA_INCLUDE_DIR.'qa-db-selects.php';
if (QA_FINAL_EXTERNAL_USERS) {
$email=qa_get_user_email($userid);

} else {
$useraccount=qa_db_select_with_pending(
qa_db_user_account_selectspec($userid, true)
);
$email=@$useraccount['email'];
}
return $email;
}
}
26 changes: 17 additions & 9 deletions qa-php-widget.php
Expand Up @@ -32,7 +32,9 @@ function admin_form(&$qa_content)
$ok = null;

if(qa_clicked('db_process')) {
if(file_exists(dirname(__FILE__).'/password') && file_get_contents(dirname(__FILE__).'/password') && qa_post_text('admin_plus_password') != trim(file_get_contents(dirname(__FILE__).'/password')))
if(!file_exists(dirname(__FILE__).'/password') || !file_get_contents(dirname(__FILE__).'/password'))
$error = 'No password file found.';
if(qa_post_text('admin_plus_password') != trim(file_get_contents(dirname(__FILE__).'/password')))
$error = 'Password incorrect.';
else {
$command = qa_post_text('db_command');
Expand All @@ -51,22 +53,28 @@ function admin_form(&$qa_content)
// Create the form for display

$fields = array();

if(file_exists(dirname(__FILE__).'/password') && file_get_contents(dirname(__FILE__).'/password')) {
$fields[] = array(
'error' => @$error,
'label' => 'PHP Password',
'value' => '',
'tags' => 'NAME="admin_plus_password"',
);
}

$fields[] = array(
'label' => 'Command:',
'tags' => 'NAME="db_command"',
'value' => @$command,
'rows' => 20,
'type' => 'textarea',
);
$fields[] = array(
'label' => 'Command:',
'tags' => 'NAME="db_command"',
'value' => @$command,
'rows' => 20,
'type' => 'textarea',
);
}
else
$fields[] = array(
'error' => 'In order to run php code, ou must place a password in a file called \'password\' in the admin plugin directory.',
'type' => 'static',
);

$fields[] = array(
'type' => 'blank',
Expand Down

0 comments on commit b309319

Please sign in to comment.