Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
d057c557
Commit
d057c557
authored
Jul 15, 2016
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Coding style (question page)
parent
e6f8efb5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1002 additions
and
996 deletions
+1002
-996
question-post.php
qa-include/pages/question-post.php
+698
-695
question.php
qa-include/pages/question.php
+304
-301
No files found.
qa-include/pages/question-post.php
View file @
d057c557
...
@@ -20,992 +20,996 @@
...
@@ -20,992 +20,996 @@
More about this license: http://www.question2answer.org/license.php
More about this license: http://www.question2answer.org/license.php
*/
*/
if
(
!
defined
(
'QA_VERSION'
))
{
// don't allow this page to be requested directly from browser
if
(
!
defined
(
'QA_VERSION'
))
{
// don't allow this page to be requested directly from browser
header
(
'Location: ../'
);
header
(
'Location: ../'
);
exit
;
exit
;
}
}
require_once
QA_INCLUDE_DIR
.
'app/limits.php'
;
require_once
QA_INCLUDE_DIR
.
'app/limits.php'
;
require_once
QA_INCLUDE_DIR
.
'pages/question-submit.php'
;
require_once
QA_INCLUDE_DIR
.
'pages/question-submit.php'
;
$code
=
qa_post_text
(
'code'
);
$code
=
qa_post_text
(
'code'
);
// Process general cancel button
// Process general cancel button
if
(
qa_clicked
(
'docancel'
))
if
(
qa_clicked
(
'docancel'
))
qa_page_q_refresh
(
$pagestart
);
qa_page_q_refresh
(
$pagestart
);
// Process incoming answer (or button)
// Process incoming answer (or button)
if
(
$question
[
'answerbutton'
])
{
if
(
$question
[
'answerbutton'
])
{
if
(
qa_clicked
(
'q_doanswer'
))
if
(
qa_clicked
(
'q_doanswer'
))
qa_page_q_refresh
(
$pagestart
,
'answer'
);
qa_page_q_refresh
(
$pagestart
,
'answer'
);
// The 'approve', 'login', 'confirm', 'limit', 'userblock', 'ipblock' permission errors are reported to the user here
// The 'approve', 'login', 'confirm', 'limit', 'userblock', 'ipblock' permission errors are reported to the user here
// The other option ('level') prevents the answer button being shown, in qa_page_q_post_rules(...)
// The other option ('level') prevents the answer button being shown, in qa_page_q_post_rules(...)
if
(
qa_clicked
(
'a_doadd'
)
||
(
$pagestate
==
'answer'
))
if
(
qa_clicked
(
'a_doadd'
)
||
$pagestate
==
'answer'
)
{
switch
(
qa_user_post_permit_error
(
'permit_post_a'
,
$question
,
QA_LIMIT_ANSWERS
))
{
switch
(
qa_user_post_permit_error
(
'permit_post_a'
,
$question
,
QA_LIMIT_ANSWERS
))
{
case
'login'
:
case
'login'
:
$pageerror
=
qa_insert_login_links
(
qa_lang_html
(
'question/answer_must_login'
),
qa_request
());
$pageerror
=
qa_insert_login_links
(
qa_lang_html
(
'question/answer_must_login'
),
qa_request
());
break
;
break
;
case
'confirm'
:
case
'confirm'
:
$pageerror
=
qa_insert_login_links
(
qa_lang_html
(
'question/answer_must_confirm'
),
qa_request
());
$pageerror
=
qa_insert_login_links
(
qa_lang_html
(
'question/answer_must_confirm'
),
qa_request
());
break
;
break
;
case
'approve'
:
case
'approve'
:
$pageerror
=
qa_lang_html
(
'question/answer_must_be_approved'
);
$pageerror
=
qa_lang_html
(
'question/answer_must_be_approved'
);
break
;
break
;
case
'limit'
:
case
'limit'
:
$pageerror
=
qa_lang_html
(
'question/answer_limit'
);
$pageerror
=
qa_lang_html
(
'question/answer_limit'
);
break
;
break
;
default
:
default
:
$pageerror
=
qa_lang_html
(
'users/no_permission'
);
$pageerror
=
qa_lang_html
(
'users/no_permission'
);
break
;
break
;
case
false
:
case
false
:
if
(
qa_clicked
(
'a_doadd'
))
{
if
(
qa_clicked
(
'a_doadd'
))
{
$answerid
=
qa_page_q_add_a_submit
(
$question
,
$answers
,
$usecaptcha
,
$anewin
,
$anewerrors
);
$answerid
=
qa_page_q_add_a_submit
(
$question
,
$answers
,
$usecaptcha
,
$anewin
,
$anewerrors
);
if
(
isset
(
$answerid
))
if
(
isset
(
$answerid
))
qa_page_q_refresh
(
0
,
null
,
'A'
,
$answerid
);
qa_page_q_refresh
(
0
,
null
,
'A'
,
$answerid
);
else
else
$formtype
=
'a_add'
;
// show form again
$formtype
=
'a_add'
;
// show form again
}
else
}
else
$formtype
=
'a_add'
;
// show form as if first time
$formtype
=
'a_add'
;
// show form as if first time
break
;
break
;
}
}
}
}
}
// Process close buttons for question
// Process close buttons for question
if
(
$question
[
'closeable'
])
{
if
(
$question
[
'closeable'
])
{
if
(
qa_clicked
(
'q_doclose'
))
if
(
qa_clicked
(
'q_doclose'
))
qa_page_q_refresh
(
$pagestart
,
'close'
);
qa_page_q_refresh
(
$pagestart
,
'close'
);
elseif
(
qa_clicked
(
'doclose'
)
&&
qa_page_q_permit_edit
(
$question
,
'permit_close_q'
,
$pageerror
))
{
elseif
(
qa_clicked
(
'doclose'
)
&&
qa_page_q_permit_edit
(
$question
,
'permit_close_q'
,
$pageerror
))
{
if
(
qa_page_q_close_q_submit
(
$question
,
$closepost
,
$closein
,
$closeerrors
))
if
(
qa_page_q_close_q_submit
(
$question
,
$closepost
,
$closein
,
$closeerrors
))
qa_page_q_refresh
(
$pagestart
);
qa_page_q_refresh
(
$pagestart
);
else
else
$formtype
=
'q_close'
;
// keep editing if an error
$formtype
=
'q_close'
;
// keep editing if an error
}
elseif
((
$pagestate
==
'close'
)
&&
qa_page_q_permit_edit
(
$question
,
'permit_close_q'
,
$pageerror
))
}
elseif
((
$pagestate
==
'close'
)
&&
qa_page_q_permit_edit
(
$question
,
'permit_close_q'
,
$pageerror
))
$formtype
=
'q_close'
;
$formtype
=
'q_close'
;
}
}
// Process any single click operations or delete button for question
// Process any single click operations or delete button for question
if
(
qa_page_q_single_click_q
(
$question
,
$answers
,
$commentsfollows
,
$closepost
,
$pageerror
))
if
(
qa_page_q_single_click_q
(
$question
,
$answers
,
$commentsfollows
,
$closepost
,
$pageerror
))
qa_page_q_refresh
(
$pagestart
);
qa_page_q_refresh
(
$pagestart
);
if
(
qa_clicked
(
'q_dodelete'
)
&&
$question
[
'deleteable'
]
&&
qa_page_q_click_check_form_code
(
$question
,
$pageerror
))
{
if
(
qa_clicked
(
'q_dodelete'
)
&&
$question
[
'deleteable'
]
&&
qa_page_q_click_check_form_code
(
$question
,
$pageerror
))
{
qa_question_delete
(
$question
,
$userid
,
qa_get_logged_in_handle
(),
$cookieid
,
$closepost
);
qa_question_delete
(
$question
,
$userid
,
qa_get_logged_in_handle
(),
$cookieid
,
$closepost
);
qa_redirect
(
''
);
// redirect since question has gone
qa_redirect
(
''
);
// redirect since question has gone
}
}
// Process edit or save button for question
// Process edit or save button for question
if
(
$question
[
'editbutton'
]
||
$question
[
'retagcatbutton'
])
{
if
(
$question
[
'editbutton'
]
||
$question
[
'retagcatbutton'
])
{
if
(
qa_clicked
(
'q_doedit'
))
if
(
qa_clicked
(
'q_doedit'
))
qa_page_q_refresh
(
$pagestart
,
'edit-'
.
$questionid
);
qa_page_q_refresh
(
$pagestart
,
'edit-'
.
$questionid
);
elseif
(
qa_clicked
(
'q_dosave'
)
&&
qa_page_q_permit_edit
(
$question
,
'permit_edit_q'
,
$pageerror
,
'permit_retag_cat'
))
{
if
(
qa_page_q_edit_q_submit
(
$question
,
$answers
,
$commentsfollows
,
$closepost
,
$qin
,
$qerrors
))
qa_redirect
(
qa_q_request
(
$questionid
,
$qin
[
'title'
]));
// don't use refresh since URL may have changed
else
{
elseif
(
qa_clicked
(
'q_dosave'
)
&&
qa_page_q_permit_edit
(
$question
,
'permit_edit_q'
,
$pageerror
,
'permit_retag_cat'
))
{
$formtype
=
'q_edit'
;
// keep editing if an error
if
(
qa_page_q_edit_q_submit
(
$question
,
$answers
,
$commentsfollows
,
$closepost
,
$qin
,
$qerrors
))
$pageerror
=@
$qerrors
[
'page'
];
// for security code failure
qa_redirect
(
qa_q_request
(
$questionid
,
$qin
[
'title'
]));
// don't use refresh since URL may have changed
}
else
{
$formtype
=
'q_edit'
;
// keep editing if an error
$pageerror
=
@
$qerrors
[
'page'
];
// for security code failure
}
}
elseif
((
$pagestate
==
(
'edit-'
.
$questionid
)
)
&&
qa_page_q_permit_edit
(
$question
,
'permit_edit_q'
,
$pageerror
,
'permit_retag_cat'
))
}
elseif
(
$pagestate
==
(
'edit-'
.
$questionid
)
&&
qa_page_q_permit_edit
(
$question
,
'permit_edit_q'
,
$pageerror
,
'permit_retag_cat'
))
$formtype
=
'q_edit'
;
$formtype
=
'q_edit'
;
if
(
$formtype
==
'q_edit'
)
{
// get tags for auto-completion
if
(
$formtype
==
'q_edit'
)
{
// get tags for auto-completion
if
(
qa_opt
(
'do_complete_tags'
))
if
(
qa_opt
(
'do_complete_tags'
))
$completetags
=
array_keys
(
qa_db_select_with_pending
(
qa_db_popular_tags_selectspec
(
0
,
QA_DB_RETRIEVE_COMPLETE_TAGS
)));
$completetags
=
array_keys
(
qa_db_select_with_pending
(
qa_db_popular_tags_selectspec
(
0
,
QA_DB_RETRIEVE_COMPLETE_TAGS
)));
else
else
$completetags
=
array
();
$completetags
=
array
();
}
}
}
}
// Process adding a comment to question (shows form or processes it)
// Process adding a comment to question (shows form or processes it)
if
(
$question
[
'commentbutton'
])
{
if
(
$question
[
'commentbutton'
])
{
if
(
qa_clicked
(
'q_docomment'
))
if
(
qa_clicked
(
'q_docomment'
))
qa_page_q_refresh
(
$pagestart
,
'comment-'
.
$questionid
,
'C'
,
$questionid
);
qa_page_q_refresh
(
$pagestart
,
'comment-'
.
$questionid
,
'C'
,
$questionid
);
if
(
qa_clicked
(
'c'
.
$questionid
.
'_doadd'
)
||
(
$pagestate
==
(
'comment-'
.
$questionid
)
))
if
(
qa_clicked
(
'c'
.
$questionid
.
'_doadd'
)
||
$pagestate
==
(
'comment-'
.
$questionid
))
qa_page_q_do_comment
(
$question
,
$question
,
$commentsfollows
,
$pagestart
,
$usecaptcha
,
$cnewin
,
$cnewerrors
,
$formtype
,
$formpostid
,
$pageerror
);
qa_page_q_do_comment
(
$question
,
$question
,
$commentsfollows
,
$pagestart
,
$usecaptcha
,
$cnewin
,
$cnewerrors
,
$formtype
,
$formpostid
,
$pageerror
);
}
}
// Process clicked buttons for answers
// Process clicked buttons for answers
foreach
(
$answers
as
$answerid
=>
$answer
)
{
foreach
(
$answers
as
$answerid
=>
$answer
)
{
$prefix
=
'a'
.
$answerid
.
'_'
;
$prefix
=
'a'
.
$answerid
.
'_'
;
if
(
qa_page_q_single_click_a
(
$answer
,
$question
,
$answers
,
$commentsfollows
,
true
,
$pageerror
))
if
(
qa_page_q_single_click_a
(
$answer
,
$question
,
$answers
,
$commentsfollows
,
true
,
$pageerror
))
qa_page_q_refresh
(
$pagestart
,
null
,
'A'
,
$answerid
);
qa_page_q_refresh
(
$pagestart
,
null
,
'A'
,
$answerid
);
if
(
$answer
[
'editbutton'
])
{
if
(
$answer
[
'editbutton'
])
{
if
(
qa_clicked
(
$prefix
.
'doedit'
))
if
(
qa_clicked
(
$prefix
.
'doedit'
))
qa_page_q_refresh
(
$pagestart
,
'edit-'
.
$answerid
);
qa_page_q_refresh
(
$pagestart
,
'edit-'
.
$answerid
);
elseif
(
qa_clicked
(
$prefix
.
'dosave'
)
&&
qa_page_q_permit_edit
(
$answer
,
'permit_edit_a'
,
$pageerror
))
{
elseif
(
qa_clicked
(
$prefix
.
'dosave'
)
&&
qa_page_q_permit_edit
(
$answer
,
'permit_edit_a'
,
$pageerror
))
{
$editedtype
=
qa_page_q_edit_a_submit
(
$answer
,
$question
,
$answers
,
$commentsfollows
,
$aeditin
[
$answerid
],
$aediterrors
[
$answerid
]);
$editedtype
=
qa_page_q_edit_a_submit
(
$answer
,
$question
,
$answers
,
$commentsfollows
,
$aeditin
[
$answerid
],
$aediterrors
[
$answerid
]);
if
(
isset
(
$editedtype
))
if
(
isset
(
$editedtype
))
qa_page_q_refresh
(
$pagestart
,
null
,
$editedtype
,
$answerid
);
qa_page_q_refresh
(
$pagestart
,
null
,
$editedtype
,
$answerid
);
else
{
else
{
$formtype
=
'a_edit'
;
$formtype
=
'a_edit'
;
$formpostid
=
$answerid
;
// keep editing if an error
$formpostid
=
$answerid
;
// keep editing if an error
}
}
elseif
((
$pagestate
==
(
'edit-'
.
$answerid
))
&&
qa_page_q_permit_edit
(
$answer
,
'permit_edit_a'
,
$pageerror
))
{
$formtype
=
'a_edit'
;
$formpostid
=
$answerid
;
}
}
}
if
(
$answer
[
'commentbutton'
])
{
}
elseif
(
$pagestate
==
(
'edit-'
.
$answerid
)
&&
qa_page_q_permit_edit
(
$answer
,
'permit_edit_a'
,
$pageerror
))
{
if
(
qa_clicked
(
$prefix
.
'docomment'
))
$formtype
=
'a_edit'
;
qa_page_q_refresh
(
$pagestart
,
'comment-'
.
$answerid
,
'C'
,
$answerid
);
$formpostid
=
$answerid
;
if
(
qa_clicked
(
'c'
.
$answerid
.
'_doadd'
)
||
(
$pagestate
==
(
'comment-'
.
$answerid
)))
qa_page_q_do_comment
(
$question
,
$answer
,
$commentsfollows
,
$pagestart
,
$usecaptcha
,
$cnewin
,
$cnewerrors
,
$formtype
,
$formpostid
,
$pageerror
);
}
}
}
if
(
qa_clicked
(
$prefix
.
'dofollow'
))
{
if
(
$answer
[
'commentbutton'
])
{
$params
=
array
(
'follow'
=>
$answerid
);
if
(
qa_clicked
(
$prefix
.
'docomment'
))
if
(
isset
(
$question
[
'categoryid'
]))
qa_page_q_refresh
(
$pagestart
,
'comment-'
.
$answerid
,
'C'
,
$answerid
);
$params
[
'cat'
]
=
$question
[
'categoryid'
];
qa_redirect
(
'ask'
,
$params
);
if
(
qa_clicked
(
'c'
.
$answerid
.
'_doadd'
)
||
$pagestate
==
(
'comment-'
.
$answerid
))
}
qa_page_q_do_comment
(
$question
,
$answer
,
$commentsfollows
,
$pagestart
,
$usecaptcha
,
$cnewin
,
$cnewerrors
,
$formtype
,
$formpostid
,
$pageerror
);
}
}
if
(
qa_clicked
(
$prefix
.
'dofollow'
))
{
$params
=
array
(
'follow'
=>
$answerid
);
if
(
isset
(
$question
[
'categoryid'
]))
$params
[
'cat'
]
=
$question
[
'categoryid'
];
// Process hide, show, delete, flag, unflag, edit or save button for comments
qa_redirect
(
'ask'
,
$params
);
}
}
foreach
(
$commentsfollows
as
$commentid
=>
$comment
)
{
if
(
$comment
[
'basetype'
]
==
'C'
)
{
$cparentid
=
$comment
[
'parentid'
];
$commentparent
=
isset
(
$answers
[
$cparentid
])
?
$answers
[
$cparentid
]
:
$question
;
$prefix
=
'c'
.
$commentid
.
'_'
;
if
(
qa_page_q_single_click_c
(
$comment
,
$question
,
$commentparent
,
$pageerror
))
// Process hide, show, delete, flag, unflag, edit or save button for comments
qa_page_q_refresh
(
$pagestart
,
'showcomments-'
.
$cparentid
,
$commentparent
[
'basetype'
],
$cparentid
);
if
(
$comment
[
'editbutton'
])
{
foreach
(
$commentsfollows
as
$commentid
=>
$comment
)
{
if
(
qa_clicked
(
$prefix
.
'doedit'
))
{
if
(
$comment
[
'basetype'
]
==
'C'
)
{
if
(
qa_page_q_permit_edit
(
$comment
,
'permit_edit_c'
,
$pageerror
))
// extra check here ensures error message is visible
$cparentid
=
$comment
[
'parentid'
];
qa_page_q_refresh
(
$pagestart
,
'edit-'
.
$commentid
,
'C'
,
$commentid
);
$commentparent
=
isset
(
$answers
[
$cparentid
])
?
$answers
[
$cparentid
]
:
$question
;
}
$prefix
=
'c'
.
$commentid
.
'_'
;
elseif
(
qa_clicked
(
$prefix
.
'dosave'
)
&&
qa_page_q_permit_edit
(
$comment
,
'permit_edit_c'
,
$pageerror
))
{
if
(
qa_page_q_edit_c_submit
(
$comment
,
$question
,
$commentparent
,
$ceditin
[
$commentid
],
$cediterrors
[
$commentid
]))
if
(
qa_page_q_single_click_c
(
$comment
,
$question
,
$commentparent
,
$pageerror
))
qa_page_q_refresh
(
$pagestart
,
null
,
'C'
,
$commentid
);
qa_page_q_refresh
(
$pagestart
,
'showcomments-'
.
$cparentid
,
$commentparent
[
'basetype'
],
$cparentid
);
else
{
$formtype
=
'c_edit'
;
if
(
$comment
[
'editbutton'
])
{
$formpostid
=
$commentid
;
// keep editing if an error
if
(
qa_clicked
(
$prefix
.
'doedit'
))
{
}
if
(
qa_page_q_permit_edit
(
$comment
,
'permit_edit_c'
,
$pageerror
))
// extra check here ensures error message is visible
}
qa_page_q_refresh
(
$pagestart
,
'edit-'
.
$commentid
,
'C'
,
$commentid
);
elseif
((
$pagestate
==
(
'edit-'
.
$commentid
))
&&
qa_page_q_permit_edit
(
$comment
,
'permit_edit_c'
,
$pageerror
))
{
}
elseif
(
qa_clicked
(
$prefix
.
'dosave'
)
&&
qa_page_q_permit_edit
(
$comment
,
'permit_edit_c'
,
$pageerror
))
{
if
(
qa_page_q_edit_c_submit
(
$comment
,
$question
,
$commentparent
,
$ceditin
[
$commentid
],
$cediterrors
[
$commentid
]))
qa_page_q_refresh
(
$pagestart
,
null
,
'C'
,
$commentid
);
else
{
$formtype
=
'c_edit'
;
$formtype
=
'c_edit'
;
$formpostid
=
$commentid
;
$formpostid
=
$commentid
;
// keep editing if an error
}
}
}
elseif
((
$pagestate
==
(
'edit-'
.
$commentid
))
&&
qa_page_q_permit_edit
(
$comment
,
'permit_edit_c'
,
$pageerror
))
{
$formtype
=
'c_edit'
;
$formpostid
=
$commentid
;
}
}
}
}
}
}
}
// Functions used above - also see functions in qa-page-question-submit.php (which are shared with Ajax)
// Functions used above - also see functions in qa-page-question-submit.php (which are shared with Ajax)
function
qa_page_q_refresh
(
$start
=
0
,
$state
=
null
,
$showtype
=
null
,
$showid
=
null
)
/*
/*
Redirects back to the question page, with the specified parameters
Redirects back to the question page, with the specified parameters
*/
*/
{
function
qa_page_q_refresh
(
$start
=
0
,
$state
=
null
,
$showtype
=
null
,
$showid
=
null
)
$params
=
array
();
{
$params
=
array
();
if
(
$start
>
0
)
if
(
$start
>
0
)
$params
[
'start'
]
=
$start
;
$params
[
'start'
]
=
$start
;
if
(
isset
(
$state
))
if
(
isset
(
$state
))
$params
[
'state'
]
=
$state
;
$params
[
'state'
]
=
$state
;
if
(
isset
(
$showtype
)
&&
isset
(
$showid
))
{
if
(
isset
(
$showtype
)
&&
isset
(
$showid
))
{
$anchor
=
qa_anchor
(
$showtype
,
$showid
);
$anchor
=
qa_anchor
(
$showtype
,
$showid
);
$params
[
'show'
]
=
$showid
;
$params
[
'show'
]
=
$showid
;
}
else
}
else
$anchor
=
null
;
$anchor
=
null
;
qa_redirect
(
qa_request
(),
$params
,
null
,
null
,
$anchor
);
qa_redirect
(
qa_request
(),
$params
,
null
,
null
,
$anchor
);
}
}
function
qa_page_q_permit_edit
(
$post
,
$permitoption
,
&
$error
,
$permitoption2
=
null
)
/*
/*
Returns whether the editing operation (as specified by $permitoption or $permitoption2) on $post is permitted.
Returns whether the editing operation (as specified by $permitoption or $permitoption2) on $post is permitted.
If not, sets the $error variable appropriately
If not, sets the $error variable appropriately
*/
*/
{
function
qa_page_q_permit_edit
(
$post
,
$permitoption
,
&
$error
,
$permitoption2
=
null
)
// The 'login', 'confirm', 'userblock', 'ipblock' permission errors are reported to the user here
{
// The other options ('approve', 'level') prevent the edit button being shown, in qa_page_q_post_rules(...)
// The 'login', 'confirm', 'userblock', 'ipblock' permission errors are reported to the user here
// The other options ('approve', 'level') prevent the edit button being shown, in qa_page_q_post_rules(...)
$permiterror
=
qa_user_post_permit_error
(
$post
[
'isbyuser'
]
?
null
:
$permitoption
,
$post
);
// if it's by the user, this will only check whether they are blocked
if
(
$permiterror
&&
isset
(
$permitoption2
))
{
$permiterror
=
qa_user_post_permit_error
(
$post
[
'isbyuser'
]
?
null
:
$permitoption
,
$post
);
$permiterror2
=
qa_user_post_permit_error
(
$post
[
'isbyuser'
]
?
null
:
$permitoption2
,
$post
);
// if it's by the user, this will only check whether they are blocked
if
(
(
$permiterror
==
'level'
)
||
(
$permiterror
==
'approve'
)
||
(
!
$permiterror2
)
)
// if it's a less strict error
if
(
$permiterror
&&
isset
(
$permitoption2
))
{
$permiterror
=
$permiterror2
;
$permiterror2
=
qa_user_post_permit_error
(
$post
[
'isbyuser'
]
?
null
:
$permitoption2
,
$post
);
}
switch
(
$permiterror
)
{
if
(
$permiterror
==
'level'
||
$permiterror
==
'approve'
||
!
$permiterror2
)
// if it's a less strict error
case
'login'
:
$permiterror
=
$permiterror2
;
$error
=
qa_insert_login_links
(
qa_lang_html
(
'question/edit_must_login'
),
qa_request
());
}
break
;
case
'confirm'
:
switch
(
$permiterror
)
{
$error
=
qa_insert_login_links
(
qa_lang_html
(
'question/edit_must_confirm'
),
qa_request
());
case
'login'
:
break
;
$error
=
qa_insert_login_links
(
qa_lang_html
(
'question/edit_must_login'
),
qa_request
());
break
;
default
:
case
'confirm'
:
$error
=
qa_lang_html
(
'users/no_permission'
);
$error
=
qa_insert_login_links
(
qa_lang_html
(
'question/edit_must_confirm'
),
qa_request
()
);
break
;
break
;
case
false
:
default
:
break
;
$error
=
qa_lang_html
(
'users/no_permission'
)
;
}
break
;
return
!
$permiterror
;
case
false
:
break
;
}
}
return
!
$permiterror
;
}
function
qa_page_q_edit_q_form
(
&
$qa_content
,
$question
,
$in
,
$errors
,
$completetags
,
$categories
)
/*
/*
Returns a $qa_content form for editing the question and sets up other parts of $qa_content accordingly
Returns a $qa_content form for editing the question and sets up other parts of $qa_content accordingly
*/
*/
{
function
qa_page_q_edit_q_form
(
&
$qa_content
,
$question
,
$in
,
$errors
,
$completetags
,
$categories
)
$form
=
array
(
{
'tags'
=>
'method="post" action="'
.
qa_self_html
()
.
'"'
,
$form
=
array
(
'tags'
=>
'method="post" action="'
.
qa_self_html
()
.
'"'
,
'style'
=>
'tall'
,
'style'
=>
'tall'
,
'fields'
=>
array
(
'title'
=>
array
(
'fields'
=>
array
(
'type'
=>
$question
[
'editable'
]
?
'text'
:
'static'
,
'title'
=>
array
(
'label'
=>
qa_lang_html
(
'question/q_title_label'
),
'type'
=>
$question
[
'editable'
]
?
'text'
:
'static'
,
'tags'
=>
'name="q_title"'
,
'label'
=>
qa_lang_html
(
'question/q_title_label'
),
'value'
=>
qa_html
((
$question
[
'editable'
]
&&
isset
(
$in
[
'title'
]))
?
$in
[
'title'
]
:
$question
[
'title'
]),
'tags'
=>
'name="q_title"'
,
'error'
=>
qa_html
(
@
$errors
[
'title'
]),
'value'
=>
qa_html
((
$question
[
'editable'
]
&&
isset
(
$in
[
'title'
]))
?
$in
[
'title'
]
:
$question
[
'title'
]),
),
'error'
=>
qa_html
(
@
$errors
[
'title'
]),
),
'category'
=>
array
(
'label'
=>
qa_lang_html
(
'question/q_category_label'
),
'error'
=>
qa_html
(
@
$errors
[
'categoryid'
]),
),
'content'
=>
array
(
'label'
=>
qa_lang_html
(
'question/q_content_label'
),
'error'
=>
qa_html
(
@
$errors
[
'content'
]),
),
'extra'
=>
array
(
'category'
=>
array
(
'label'
=>
qa_html
(
qa_opt
(
'extra_field_prompt'
)),
'label'
=>
qa_lang_html
(
'question/q_category_label'
),
'tags'
=>
'name="q_extra"'
,
'error'
=>
qa_html
(
@
$errors
[
'categoryid'
]),
'value'
=>
qa_html
(
isset
(
$in
[
'extra'
])
?
$in
[
'extra'
]
:
$question
[
'extra'
]),
),
'error'
=>
qa_html
(
@
$errors
[
'extra'
]),
),
'tags'
=>
array
(
'content'
=>
array
(
'error'
=>
qa_html
(
@
$errors
[
'tags'
]),
'label'
=>
qa_lang_html
(
'question/q_content_label'
),
),
'error'
=>
qa_html
(
@
$errors
[
'content'
]),
),
'extra'
=>
array
(
'label'
=>
qa_html
(
qa_opt
(
'extra_field_prompt'
)),
'tags'
=>
'name="q_extra"'
,
'value'
=>
qa_html
(
isset
(
$in
[
'extra'
])
?
$in
[
'extra'
]
:
$question
[
'extra'
]),
'error'
=>
qa_html
(
@
$errors
[
'extra'
]),
),
),
'buttons'
=>
array
(
'tags'
=>
array
(
'save'
=>
array
(
'error'
=>
qa_html
(
@
$errors
[
'tags'
]),
'tags'
=>
'onclick="qa_show_waiting_after(this, false);"'
,
),
'label'
=>
qa_lang_html
(
'main/save_button'
),
),
'cancel'
=>
array
(
),
'tags'
=>
'name="docancel"'
,
'label'
=>
qa_lang_html
(
'main/cancel_button'
),
'buttons'
=>
array
(
),
'save'
=>
array
(
'tags'
=>
'onclick="qa_show_waiting_after(this, false);"'
,
'label'
=>
qa_lang_html
(
'main/save_button'
),
),
),
'
hidden
'
=>
array
(
'
cancel
'
=>
array
(
'
q_dosave'
=>
'1
'
,
'
tags'
=>
'name="docancel"
'
,
'
code'
=>
qa_get_form_security_code
(
'edit-'
.
$question
[
'postid'
]
),
'
label'
=>
qa_lang_html
(
'main/cancel_button'
),
),
),
)
;
)
,
if
(
$question
[
'editable'
])
{
'hidden'
=>
array
(
$content
=
isset
(
$in
[
'content'
])
?
$in
[
'content'
]
:
$question
[
'content'
];
'q_dosave'
=>
'1'
,
$format
=
isset
(
$in
[
'format'
])
?
$in
[
'format'
]
:
$question
[
'format'
];
'code'
=>
qa_get_form_security_code
(
'edit-'
.
$question
[
'postid'
]),
),
);
$editorname
=
isset
(
$in
[
'editor'
])
?
$in
[
'editor'
]
:
qa_opt
(
'editor_for_qs'
);
if
(
$question
[
'editable'
])
{
$editor
=
qa_load_editor
(
$content
,
$format
,
$editorname
);
$content
=
isset
(
$in
[
'content'
])
?
$in
[
'content'
]
:
$question
[
'content'
];
$format
=
isset
(
$in
[
'format'
])
?
$in
[
'format'
]
:
$question
[
'format'
];
$form
[
'fields'
][
'content'
]
=
array_merge
(
$form
[
'fields'
][
'content'
],
$editorname
=
isset
(
$in
[
'editor'
])
?
$in
[
'editor'
]
:
qa_opt
(
'editor_for_qs'
);
qa_editor_load_field
(
$editor
,
$qa_content
,
$content
,
$format
,
'q_content'
,
12
,
true
)
);
$editor
=
qa_load_editor
(
$content
,
$format
,
$editorname
);
if
(
method_exists
(
$editor
,
'update_script'
))
$form
[
'fields'
][
'content'
]
=
array_merge
(
$form
[
'fields'
][
'content'
],
$form
[
'buttons'
][
'save'
][
'tags'
]
=
'onclick="qa_show_waiting_after(this, false); '
.
$editor
->
update_script
(
'q_content'
)
.
'"'
;
qa_editor_load_field
(
$editor
,
$qa_content
,
$content
,
$format
,
'q_content'
,
12
,
true
))
;
$form
[
'hidden'
][
'q_editor'
]
=
qa_html
(
$editorname
);
if
(
method_exists
(
$editor
,
'update_script'
))
$form
[
'buttons'
][
'save'
][
'tags'
]
=
'onclick="qa_show_waiting_after(this, false); '
.
$editor
->
update_script
(
'q_content'
)
.
'"'
;
}
else
$form
[
'hidden'
][
'q_editor'
]
=
qa_html
(
$editorname
);
unset
(
$form
[
'fields'
][
'content'
]);
if
(
qa_using_categories
()
&&
count
(
$categories
)
&&
$question
[
'retagcatable'
])
}
else
qa_set_up_category_field
(
$qa_content
,
$form
[
'fields'
][
'category'
],
'q_category'
,
$categories
,
unset
(
$form
[
'fields'
][
'content'
]);
isset
(
$in
[
'categoryid'
])
?
$in
[
'categoryid'
]
:
$question
[
'categoryid'
],
qa_opt
(
'allow_no_category'
)
||
!
isset
(
$question
[
'categoryid'
]),
qa_opt
(
'allow_no_sub_category'
));
else
unset
(
$form
[
'fields'
][
'category'
]);
if
(
!
(
$question
[
'editable'
]
&&
qa_opt
(
'extra_field_active'
)))
if
(
qa_using_categories
()
&&
count
(
$categories
)
&&
$question
[
'retagcatable'
])
{
unset
(
$form
[
'fields'
][
'extra'
]);
qa_set_up_category_field
(
$qa_content
,
$form
[
'fields'
][
'category'
],
'q_category'
,
$categories
,
isset
(
$in
[
'categoryid'
])
?
$in
[
'categoryid'
]
:
$question
[
'categoryid'
],
qa_opt
(
'allow_no_category'
)
||
!
isset
(
$question
[
'categoryid'
]),
qa_opt
(
'allow_no_sub_category'
));
}
else
{
unset
(
$form
[
'fields'
][
'category'
]);
}
if
(
qa_using_tags
()
&&
$question
[
'retagcatable'
])
if
(
!
(
$question
[
'editable'
]
&&
qa_opt
(
'extra_field_active'
)))
qa_set_up_tag_field
(
$qa_content
,
$form
[
'fields'
][
'tags'
],
'q_tags'
,
isset
(
$in
[
'tags'
])
?
$in
[
'tags'
]
:
qa_tagstring_to_tags
(
$question
[
'tags'
]),
unset
(
$form
[
'fields'
][
'extra'
]);
array
(),
$completetags
,
qa_opt
(
'page_size_ask_tags'
));
else
unset
(
$form
[
'fields'
][
'tags'
]);
if
(
$question
[
'isbyuser'
])
{
if
(
qa_using_tags
()
&&
$question
[
'retagcatable'
])
{
if
(
!
qa_is_logged_in
())
qa_set_up_tag_field
(
$qa_content
,
$form
[
'fields'
][
'tags'
],
'q_tags'
,
isset
(
$in
[
'tags'
])
?
$in
[
'tags'
]
:
qa_tagstring_to_tags
(
$question
[
'tags'
]),
qa_set_up_name_field
(
$qa_content
,
$form
[
'fields'
],
isset
(
$in
[
'name'
])
?
$in
[
'name'
]
:
@
$question
[
'name'
],
'q_'
);
array
(),
$completetags
,
qa_opt
(
'page_size_ask_tags'
));
}
else
{
unset
(
$form
[
'fields'
][
'tags'
]);
}
qa_set_up_notify_fields
(
$qa_content
,
$form
[
'fields'
],
'Q'
,
qa_get_logged_in_email
(),
if
(
$question
[
'isbyuser'
])
{
isset
(
$in
[
'notify'
])
?
$in
[
'notify'
]
:
!
empty
(
$question
[
'notify'
]),
if
(
!
qa_is_logged_in
())
isset
(
$in
[
'email'
])
?
$in
[
'email'
]
:
@
$question
[
'notify'
],
@
$errors
[
'email'
],
'q_'
);
qa_set_up_name_field
(
$qa_content
,
$form
[
'fields'
],
isset
(
$in
[
'name'
])
?
$in
[
'name'
]
:
@
$question
[
'name'
],
'q_'
);
}
if
(
!
qa_user_post_permit_error
(
'permit_edit_silent'
,
$question
))
qa_set_up_notify_fields
(
$qa_content
,
$form
[
'fields'
],
'Q'
,
qa_get_logged_in_email
(),
$form
[
'fields'
][
'silent'
]
=
array
(
isset
(
$in
[
'notify'
])
?
$in
[
'notify'
]
:
!
empty
(
$question
[
'notify'
]),
'type'
=>
'checkbox'
,
isset
(
$in
[
'email'
])
?
$in
[
'email'
]
:
@
$question
[
'notify'
],
@
$errors
[
'email'
],
'q_'
);
'label'
=>
qa_lang_html
(
'question/save_silent_label'
),
}
'tags'
=>
'name="q_silent"'
,
'value'
=>
qa_html
(
@
$in
[
'silent'
]),
);
return
$form
;
if
(
!
qa_user_post_permit_error
(
'permit_edit_silent'
,
$question
))
{
$form
[
'fields'
][
'silent'
]
=
array
(
'type'
=>
'checkbox'
,
'label'
=>
qa_lang_html
(
'question/save_silent_label'
),
'tags'
=>
'name="q_silent"'
,
'value'
=>
qa_html
(
@
$in
[
'silent'
]),
);
}
}
return
$form
;
}
function
qa_page_q_edit_q_submit
(
$question
,
$answers
,
$commentsfollows
,
$closepost
,
&
$in
,
&
$errors
)
/*
/*
Processes a POSTed form for editing the question and returns true if successful
Processes a POSTed form for editing the question and returns true if successful
*/
*/
{
function
qa_page_q_edit_q_submit
(
$question
,
$answers
,
$commentsfollows
,
$closepost
,
&
$in
,
&
$errors
)
$in
=
array
();
{
$in
=
array
();
if
(
$question
[
'editable'
])
{
$in
[
'title'
]
=
qa_get_post_title
(
'q_title'
);
if
(
$question
[
'editable'
])
{
qa_get_post_content
(
'q_editor'
,
'q_content'
,
$in
[
'editor'
],
$in
[
'content'
],
$in
[
'format'
],
$in
[
'text'
]);
$in
[
'title'
]
=
qa_get_post_title
(
'q_title'
);
$in
[
'extra'
]
=
qa_opt
(
'extra_field_active'
)
?
qa_post_text
(
'q_extra'
)
:
null
;
qa_get_post_content
(
'q_editor'
,
'q_content'
,
$in
[
'editor'
],
$in
[
'content'
],
$in
[
'format'
],
$in
[
'text'
]);
}
$in
[
'extra'
]
=
qa_opt
(
'extra_field_active'
)
?
qa_post_text
(
'q_extra'
)
:
null
;
}
if
(
$question
[
'retagcatable'
])
{
if
(
qa_using_tags
())
$in
[
'tags'
]
=
qa_get_tags_field_value
(
'q_tags'
);
if
(
qa_using_categories
())
if
(
$question
[
'retagcatable'
])
{
$in
[
'categoryid'
]
=
qa_get_category_field_value
(
'q_category'
);
if
(
qa_using_tags
())
}
$in
[
'tags'
]
=
qa_get_tags_field_value
(
'q_tags'
);
if
(
array_key_exists
(
'categoryid'
,
$in
))
{
// need to check if we can move it to that category, and if we need moderation
if
(
qa_using_categories
())
$categories
=
qa_db_select_with_pending
(
qa_db_category_nav_selectspec
(
$in
[
'categoryid'
],
true
));
$in
[
'categoryid'
]
=
qa_get_category_field_value
(
'q_category'
);
$categoryids
=
array_keys
(
qa_category_path
(
$categories
,
$in
[
'categoryid'
]));
}
$userlevel
=
qa_user_level_for_categories
(
$categoryids
);
}
else
if
(
array_key_exists
(
'categoryid'
,
$in
))
{
// need to check if we can move it to that category, and if we need moderation
$userlevel
=
null
;
$categories
=
qa_db_select_with_pending
(
qa_db_category_nav_selectspec
(
$in
[
'categoryid'
],
true
));
$categoryids
=
array_keys
(
qa_category_path
(
$categories
,
$in
[
'categoryid'
]));
$userlevel
=
qa_user_level_for_categories
(
$categoryids
);
if
(
$question
[
'isbyuser'
])
{
}
else
$in
[
'name'
]
=
qa_post_text
(
'q_name'
);
$userlevel
=
null
;
$in
[
'notify'
]
=
qa_post_text
(
'q_notify'
)
!==
null
;
$in
[
'email'
]
=
qa_post_text
(
'q_email'
);
}
if
(
!
qa_user_post_permit_error
(
'permit_edit_silent'
,
$question
))
if
(
$question
[
'isbyuser'
])
{
$in
[
'silent'
]
=
qa_post_text
(
'q_silent'
);
$in
[
'name'
]
=
qa_post_text
(
'q_name'
);
$in
[
'notify'
]
=
qa_post_text
(
'q_notify'
)
!==
null
;
$in
[
'email'
]
=
qa_post_text
(
'q_email'
);
}
// here the $in array only contains values for parts of the form that were displayed, so those are only ones checked by filters
if
(
!
qa_user_post_permit_error
(
'permit_edit_silent'
,
$question
))
$in
[
'silent'
]
=
qa_post_text
(
'q_silent'
);
$errors
=
array
();
// here the $in array only contains values for parts of the form that were displayed, so those are only ones checked by filters
if
(
!
qa_check_form_security_code
(
'edit-'
.
$question
[
'postid'
],
qa_post_text
(
'code'
)))
$errors
=
array
();
$errors
[
'page'
]
=
qa_lang_html
(
'misc/form_security_again'
);
else
{
if
(
!
qa_check_form_security_code
(
'edit-'
.
$question
[
'postid'
],
qa_post_text
(
'code'
)))
$in
[
'queued'
]
=
qa_opt
(
'moderate_edited_again'
)
&&
qa_user_moderation_reason
(
$userlevel
);
$errors
[
'page'
]
=
qa_lang_html
(
'misc/form_security_again'
);
$filtermodules
=
qa_load_modules_with
(
'filter'
,
'filter_question'
);
else
{
foreach
(
$filtermodules
as
$filtermodule
)
{
$in
[
'queued'
]
=
qa_opt
(
'moderate_edited_again'
)
&&
qa_user_moderation_reason
(
$userlevel
);
$oldin
=
$in
;
$filtermodule
->
filter_question
(
$in
,
$errors
,
$question
);
if
(
$question
[
'editable'
])
$filtermodules
=
qa_load_modules_with
(
'filter'
,
'filter_question'
);
qa_update_post_text
(
$in
,
$oldin
);
foreach
(
$filtermodules
as
$filtermodule
)
{
}
$oldin
=
$in
;
$filtermodule
->
filter_question
(
$in
,
$errors
,
$question
);
if
(
array_key_exists
(
'categoryid'
,
$in
)
&&
strcmp
(
$in
[
'categoryid'
],
$question
[
'categoryid'
])
)
if
(
$question
[
'editable'
]
)
if
(
qa_user_permit_error
(
'permit_post_q'
,
null
,
$userlevel
))
qa_update_post_text
(
$in
,
$oldin
);
$errors
[
'categoryid'
]
=
qa_lang_html
(
'question/category_ask_not_allowed'
);
}
if
(
empty
(
$errors
))
{
if
(
array_key_exists
(
'categoryid'
,
$in
)
&&
strcmp
(
$in
[
'categoryid'
],
$question
[
'categoryid'
]
))
{
$userid
=
qa_get_logged_in_userid
();
if
(
qa_user_permit_error
(
'permit_post_q'
,
null
,
$userlevel
))
$
handle
=
qa_get_logged_in_handle
(
);
$
errors
[
'categoryid'
]
=
qa_lang_html
(
'question/category_ask_not_allowed'
);
$cookieid
=
qa_cookie_get
();
}
// now we fill in the missing values in the $in array, so that we have everything we need for qa_question_set_content()
if
(
empty
(
$errors
))
{
// we do things in this way to avoid any risk of a validation failure on elements the user can't see (e.g. due to admin setting changes)
$userid
=
qa_get_logged_in_userid
();
$handle
=
qa_get_logged_in_handle
();
$cookieid
=
qa_cookie_get
();
if
(
!
$question
[
'editable'
])
{
// now we fill in the missing values in the $in array, so that we have everything we need for qa_question_set_content()
$in
[
'title'
]
=
$question
[
'title'
];
// we do things in this way to avoid any risk of a validation failure on elements the user can't see (e.g. due to admin setting changes)
$in
[
'content'
]
=
$question
[
'content'
];
$in
[
'format'
]
=
$question
[
'format'
];
$in
[
'text'
]
=
qa_viewer_text
(
$in
[
'content'
],
$in
[
'format'
]);
$in
[
'extra'
]
=
$question
[
'extra'
];
}
if
(
!
isset
(
$in
[
'tags'
]))
if
(
!
$question
[
'editable'
])
{
$in
[
'tags'
]
=
qa_tagstring_to_tags
(
$question
[
'tags'
]);
$in
[
'title'
]
=
$question
[
'title'
];
$in
[
'content'
]
=
$question
[
'content'
];
$in
[
'format'
]
=
$question
[
'format'
];
$in
[
'text'
]
=
qa_viewer_text
(
$in
[
'content'
],
$in
[
'format'
]);
$in
[
'extra'
]
=
$question
[
'extra'
];
}
if
(
!
array_key_exists
(
'categoryid'
,
$in
))
if
(
!
isset
(
$in
[
'tags'
]
))
$in
[
'categoryid'
]
=
$question
[
'categoryid'
]
;
$in
[
'tags'
]
=
qa_tagstring_to_tags
(
$question
[
'tags'
])
;
if
(
!
isset
(
$in
[
'silent'
]
))
if
(
!
array_key_exists
(
'categoryid'
,
$in
))
$in
[
'silent'
]
=
false
;
$in
[
'categoryid'
]
=
$question
[
'categoryid'
]
;
$setnotify
=
$question
[
'isbyuser'
]
?
qa_combine_notify_email
(
$question
[
'userid'
],
$in
[
'notify'
],
$in
[
'email'
])
:
$question
[
'notify'
];
if
(
!
isset
(
$in
[
'silent'
]))
$in
[
'silent'
]
=
false
;
qa_question_set_content
(
$question
,
$in
[
'title'
],
$in
[
'content'
],
$in
[
'format'
],
$in
[
'text'
],
qa_tags_to_tagstring
(
$in
[
'tags'
]),
$setnotify
=
$question
[
'isbyuser'
]
?
qa_combine_notify_email
(
$question
[
'userid'
],
$in
[
'notify'
],
$in
[
'email'
])
:
$question
[
'notify'
];
$setnotify
,
$userid
,
$handle
,
$cookieid
,
$in
[
'extra'
],
@
$in
[
'name'
],
$in
[
'queued'
],
$in
[
'silent'
]);
if
(
qa_using_categories
()
&&
strcmp
(
$in
[
'categoryid'
],
$question
[
'categoryid'
]))
qa_question_set_content
(
$question
,
$in
[
'title'
],
$in
[
'content'
],
$in
[
'format'
],
$in
[
'text'
],
qa_tags_to_tagstring
(
$in
[
'tags'
]),
qa_question_set_category
(
$question
,
$in
[
'categoryid'
],
$userid
,
$handle
,
$cookieid
,
$setnotify
,
$userid
,
$handle
,
$cookieid
,
$in
[
'extra'
],
@
$in
[
'name'
],
$in
[
'queued'
],
$in
[
'silent'
]);
$answers
,
$commentsfollows
,
$closepost
,
$in
[
'silent'
]);
return
true
;
if
(
qa_using_categories
()
&&
strcmp
(
$in
[
'categoryid'
],
$question
[
'categoryid'
]))
{
qa_question_set_category
(
$question
,
$in
[
'categoryid'
],
$userid
,
$handle
,
$cookieid
,
$answers
,
$commentsfollows
,
$closepost
,
$in
[
'silent'
]);
}
}
}
return
false
;
return
true
;
}
}
}
return
false
;
}
function
qa_page_q_close_q_form
(
&
$qa_content
,
$question
,
$id
,
$in
,
$errors
)
/*
/*
Returns a $qa_content form for closing the question and sets up other parts of $qa_content accordingly
Returns a $qa_content form for closing the question and sets up other parts of $qa_content accordingly
*/
*/
{
function
qa_page_q_close_q_form
(
&
$qa_content
,
$question
,
$id
,
$in
,
$errors
)
$form
=
array
(
{
'tags'
=>
'method="post" action="'
.
qa_self_html
()
.
'"'
,
$form
=
array
(
'tags'
=>
'method="post" action="'
.
qa_self_html
()
.
'"'
,
'id'
=>
$id
,
'id'
=>
$id
,
'style'
=>
'tall'
,
'style'
=>
'tall'
,
'title'
=>
qa_lang_html
(
'question/close_form_title'
),
'title'
=>
qa_lang_html
(
'question/close_form_title'
),
'fields'
=>
array
(
'fields'
=>
array
(
'details'
=>
array
(
'details'
=>
array
(
'tags'
=>
'name="q_close_details" id="q_close_details"'
,
'tags'
=>
'name="q_close_details" id="q_close_details"'
,
'label'
=>
'label'
=>
'<span id="close_label_other">'
.
qa_lang_html
(
'question/close_reason_title'
)
.
'</span>'
,
'<span id="close_label_other">'
.
qa_lang_html
(
'question/close_reason_title'
)
.
'</span>'
,
'value'
=>
@
$in
[
'details'
],
'value'
=>
@
$in
[
'details'
],
'error'
=>
qa_html
(
@
$errors
[
'details'
]),
'error'
=>
qa_html
(
@
$errors
[
'details'
]),
),
),
),
),
'buttons'
=>
array
(
'buttons'
=>
array
(
'close'
=>
array
(
'close'
=>
array
(
'tags'
=>
'onclick="qa_show_waiting_after(this, false);"'
,
'tags'
=>
'onclick="qa_show_waiting_after(this, false);"'
,
'label'
=>
qa_lang_html
(
'question/close_form_button'
),
'label'
=>
qa_lang_html
(
'question/close_form_button'
),
),
'cancel'
=>
array
(
'tags'
=>
'name="docancel"'
,
'label'
=>
qa_lang_html
(
'main/cancel_button'
),
),
),
),
'
hidden
'
=>
array
(
'
cancel
'
=>
array
(
'
doclose'
=>
'1
'
,
'
tags'
=>
'name="docancel"
'
,
'
code'
=>
qa_get_form_security_code
(
'close-'
.
$question
[
'postid'
]
),
'
label'
=>
qa_lang_html
(
'main/cancel_button'
),
),
),
)
;
)
,
$qa_content
[
'focusid'
]
=
'q_close_details'
;
'hidden'
=>
array
(
'doclose'
=>
'1'
,
'code'
=>
qa_get_form_security_code
(
'close-'
.
$question
[
'postid'
]),
),
);
return
$form
;
$qa_content
[
'focusid'
]
=
'q_close_details'
;
}
return
$form
;
}
function
qa_page_q_close_q_submit
(
$question
,
$closepost
,
&
$in
,
&
$errors
)
/*
/*
Processes a POSTed form for closing the question and returns true if successful
Processes a POSTed form for closing the question and returns true if successful
*/
*/
{
function
qa_page_q_close_q_submit
(
$question
,
$closepost
,
&
$in
,
&
$errors
)
$in
=
array
(
{
'details'
=>
trim
(
qa_post_text
(
'q_close_details'
)),
$in
=
array
(
);
'details'
=>
trim
(
qa_post_text
(
'q_close_details'
)),
);
$userid
=
qa_get_logged_in_userid
();
$handle
=
qa_get_logged_in_handle
();
$userid
=
qa_get_logged_in_userid
();
$cookieid
=
qa_cookie_get
();
$handle
=
qa_get_logged_in_handle
();
$cookieid
=
qa_cookie_get
();
$isduplicateurl
=
filter_var
(
$in
[
'details'
],
FILTER_VALIDATE_URL
);
$isduplicateurl
=
filter_var
(
$in
[
'details'
],
FILTER_VALIDATE_URL
);
if
(
!
qa_check_form_security_code
(
'close-'
.
$question
[
'postid'
],
qa_post_text
(
'code'
)))
{
$errors
[
'details'
]
=
qa_lang_html
(
'misc/form_security_again'
);
if
(
!
qa_check_form_security_code
(
'close-'
.
$question
[
'postid'
],
qa_post_text
(
'code'
)))
{
$errors
[
'details'
]
=
qa_lang_html
(
'misc/form_security_again'
);
}
elseif
(
$isduplicateurl
)
{
// be liberal in what we accept, but there are two potential unlikely pitfalls here:
// a) URLs could have a fixed numerical path, e.g. http://qa.mysite.com/1/478/...
// b) There could be a question title which is just a number, e.g. http://qa.mysite.com/478/12345/...
// so we check if more than one question could match, and if so, show an error
$parts
=
preg_split
(
'|[=/&]|'
,
$in
[
'details'
],
-
1
,
PREG_SPLIT_NO_EMPTY
);
$keypostids
=
array
();
foreach
(
$parts
as
$part
)
{
if
(
preg_match
(
'/^[0-9]+$/'
,
$part
))
$keypostids
[
$part
]
=
true
;
}
}
elseif
(
$isduplicateurl
)
{
// be liberal in what we accept, but there are two potential unlikely pitfalls here:
// a) URLs could have a fixed numerical path, e.g. http://qa.mysite.com/1/478/...
// b) There could be a question title which is just a number, e.g. http://qa.mysite.com/478/12345/...
// so we check if more than one question could match, and if so, show an error
$parts
=
preg_split
(
'|[=/&]|'
,
$in
[
'details'
],
-
1
,
PREG_SPLIT_NO_EMPTY
);
$keypostids
=
array
();
foreach
(
$parts
as
$part
)
if
(
preg_match
(
'/^[0-9]+$/'
,
$part
))
$keypostids
[
$part
]
=
true
;
$questionids
=
qa_db_posts_filter_q_postids
(
array_keys
(
$keypostids
));
$questionids
=
qa_db_posts_filter_q_postids
(
array_keys
(
$keypostids
));
if
(
(
count
(
$questionids
)
==
1
)
&&
(
$questionids
[
0
]
!=
$question
[
'postid'
])
)
{
if
(
count
(
$questionids
)
==
1
&&
$questionids
[
0
]
!=
$question
[
'postid'
]
)
{
qa_question_close_duplicate
(
$question
,
$closepost
,
$questionids
[
0
],
$userid
,
$handle
,
$cookieid
);
qa_question_close_duplicate
(
$question
,
$closepost
,
$questionids
[
0
],
$userid
,
$handle
,
$cookieid
);
return
true
;
return
true
;
}
else
}
else
$errors
[
'details'
]
=
qa_lang
(
'question/close_duplicate_error'
);
$errors
[
'details'
]
=
qa_lang
(
'question/close_duplicate_error'
);
}
else
{
if
(
strlen
(
$in
[
'details'
])
>
0
)
{
qa_question_close_other
(
$question
,
$closepost
,
$in
[
'details'
],
$userid
,
$handle
,
$cookieid
);
return
true
;
}
else
}
else
{
$errors
[
'details'
]
=
qa_lang
(
'main/field_required'
);
if
(
strlen
(
$in
[
'details'
])
>
0
)
{
}
qa_question_close_other
(
$question
,
$closepost
,
$in
[
'details'
],
$userid
,
$handle
,
$cookieid
);
return
true
;
return
false
;
}
else
$errors
[
'details'
]
=
qa_lang
(
'main/field_required'
);
}
}
return
false
;
}
function
qa_page_q_edit_a_form
(
&
$qa_content
,
$id
,
$answer
,
$question
,
$answers
,
$commentsfollows
,
$in
,
$errors
)
/*
/*
Returns a $qa_content form for editing an answer and sets up other parts of $qa_content accordingly
Returns a $qa_content form for editing an answer and sets up other parts of $qa_content accordingly
*/
*/
{
function
qa_page_q_edit_a_form
(
&
$qa_content
,
$id
,
$answer
,
$question
,
$answers
,
$commentsfollows
,
$in
,
$errors
)
require_once
QA_INCLUDE_DIR
.
'util/string.php'
;
{
require_once
QA_INCLUDE_DIR
.
'util/string.php'
;
$answerid
=
$answer
[
'postid'
];
$answerid
=
$answer
[
'postid'
];
$prefix
=
'a'
.
$answerid
.
'_'
;
$prefix
=
'a'
.
$answerid
.
'_'
;
$content
=
isset
(
$in
[
'content'
])
?
$in
[
'content'
]
:
$answer
[
'content'
];
$content
=
isset
(
$in
[
'content'
])
?
$in
[
'content'
]
:
$answer
[
'content'
];
$format
=
isset
(
$in
[
'format'
])
?
$in
[
'format'
]
:
$answer
[
'format'
];
$format
=
isset
(
$in
[
'format'
])
?
$in
[
'format'
]
:
$answer
[
'format'
];
$editorname
=
isset
(
$in
[
'editor'
])
?
$in
[
'editor'
]
:
qa_opt
(
'editor_for_as'
);
$editorname
=
isset
(
$in
[
'editor'
])
?
$in
[
'editor'
]
:
qa_opt
(
'editor_for_as'
);
$editor
=
qa_load_editor
(
$content
,
$format
,
$editorname
);
$editor
=
qa_load_editor
(
$content
,
$format
,
$editorname
);
$hascomments
=
false
;
$hascomments
=
false
;
foreach
(
$commentsfollows
as
$commentfollow
)
foreach
(
$commentsfollows
as
$commentfollow
)
{
if
(
$commentfollow
[
'parentid'
]
==
$answerid
)
if
(
$commentfollow
[
'parentid'
]
==
$answerid
)
$hascomments
=
true
;
$hascomments
=
true
;
}
$form
=
array
(
$form
=
array
(
'tags'
=>
'method="post" action="'
.
qa_self_html
()
.
'"'
,
'tags'
=>
'method="post" action="'
.
qa_self_html
()
.
'"'
,
'id'
=>
$id
,
'id'
=>
$id
,
'title'
=>
qa_lang_html
(
'question/edit_a_title'
),
'title'
=>
qa_lang_html
(
'question/edit_a_title'
),
'style'
=>
'tall'
,
'style'
=>
'tall'
,
'fields'
=>
array
(
'fields'
=>
array
(
'content'
=>
array_merge
(
'content'
=>
array_merge
(
qa_editor_load_field
(
$editor
,
$qa_content
,
$content
,
$format
,
$prefix
.
'content'
,
12
),
qa_editor_load_field
(
$editor
,
$qa_content
,
$content
,
$format
,
$prefix
.
'content'
,
12
),
array
(
array
(
'error'
=>
qa_html
(
@
$errors
[
'content'
]),
'error'
=>
qa_html
(
@
$errors
[
'content'
]),
)
)
),
),
),
),
'buttons'
=>
array
(
'buttons'
=>
array
(
'save'
=>
array
(
'save'
=>
array
(
'tags'
=>
'onclick="qa_show_waiting_after(this, false); '
.
'tags'
=>
'onclick="qa_show_waiting_after(this, false); '
.
(
method_exists
(
$editor
,
'update_script'
)
?
$editor
->
update_script
(
$prefix
.
'content'
)
:
''
)
.
'"'
,
(
method_exists
(
$editor
,
'update_script'
)
?
$editor
->
update_script
(
$prefix
.
'content'
)
:
''
)
.
'"'
,
'label'
=>
qa_lang_html
(
'main/save_button'
),
'label'
=>
qa_lang_html
(
'main/save_button'
),
),
'cancel'
=>
array
(
'tags'
=>
'name="docancel"'
,
'label'
=>
qa_lang_html
(
'main/cancel_button'
),
),
),
),
'hidden'
=>
array
(
'cancel'
=>
array
(
$prefix
.
'editor'
=>
qa_html
(
$editorname
),
'tags'
=>
'name="docancel"'
,
$prefix
.
'dosave'
=>
'1'
,
'label'
=>
qa_lang_html
(
'main/cancel_button'
),
$prefix
.
'code'
=>
qa_get_form_security_code
(
'edit-'
.
$answerid
),
),
),
);
),
'hidden'
=>
array
(
$prefix
.
'editor'
=>
qa_html
(
$editorname
),
$prefix
.
'dosave'
=>
'1'
,
$prefix
.
'code'
=>
qa_get_form_security_code
(
'edit-'
.
$answerid
),
),
);
// Show option to convert this answer to a comment, if appropriate
// Show option to convert this answer to a comment, if appropriate
$commentonoptions
=
array
();
$commentonoptions
=
array
();
$lastbeforeid
=
$question
[
'postid'
];
// used to find last post created before this answer - this is default given
$lastbeforeid
=
$question
[
'postid'
];
// used to find last post created before this answer - this is default given
$lastbeforetime
=
$question
[
'created'
];
$lastbeforetime
=
$question
[
'created'
];
if
(
$question
[
'commentable'
])
if
(
$question
[
'commentable'
])
{
$commentonoptions
[
$question
[
'postid'
]]
=
$commentonoptions
[
$question
[
'postid'
]]
=
qa_lang_html
(
'question/comment_on_q'
)
.
qa_html
(
qa_shorten_string_line
(
$question
[
'title'
],
80
));
qa_lang_html
(
'question/comment_on_q'
)
.
qa_html
(
qa_shorten_string_line
(
$question
[
'title'
],
80
));
}
foreach
(
$answers
as
$otheranswer
)
foreach
(
$answers
as
$otheranswer
)
{
if
((
$otheranswer
[
'postid'
]
!=
$answerid
)
&&
(
$otheranswer
[
'created'
]
<
$answer
[
'created'
])
&&
$otheranswer
[
'commentable'
]
&&
!
$otheranswer
[
'hidden'
])
{
if
(
$otheranswer
[
'postid'
]
!=
$answerid
&&
$otheranswer
[
'created'
]
<
$answer
[
'created'
]
&&
$otheranswer
[
'commentable'
]
&&
!
$otheranswer
[
'hidden'
])
{
$commentonoptions
[
$otheranswer
[
'postid'
]]
=
$commentonoptions
[
$otheranswer
[
'postid'
]]
=
qa_lang_html
(
'question/comment_on_a'
)
.
qa_html
(
qa_shorten_string_line
(
qa_viewer_text
(
$otheranswer
[
'content'
],
$otheranswer
[
'format'
]),
80
));
qa_lang_html
(
'question/comment_on_a'
)
.
qa_html
(
qa_shorten_string_line
(
qa_viewer_text
(
$otheranswer
[
'content'
],
$otheranswer
[
'format'
]),
80
));
if
(
$otheranswer
[
'created'
]
>
$lastbeforetime
)
{
if
(
$otheranswer
[
'created'
]
>
$lastbeforetime
)
{
$lastbeforeid
=
$otheranswer
[
'postid'
];
$lastbeforeid
=
$otheranswer
[
'postid'
];
$lastbeforetime
=
$otheranswer
[
'created'
];
$lastbeforetime
=
$otheranswer
[
'created'
];
}
}
}
if
(
count
(
$commentonoptions
))
{
$form
[
'fields'
][
'tocomment'
]
=
array
(
'tags'
=>
'name="'
.
$prefix
.
'dotoc" id="'
.
$prefix
.
'dotoc"'
,
'label'
=>
'<span id="'
.
$prefix
.
'toshown">'
.
qa_lang_html
(
'question/a_convert_to_c_on'
)
.
'</span>'
.
'<span id="'
.
$prefix
.
'tohidden" style="display:none;">'
.
qa_lang_html
(
'question/a_convert_to_c'
)
.
'</span>'
,
'type'
=>
'checkbox'
,
'tight'
=>
true
,
);
$form
[
'fields'
][
'commenton'
]
=
array
(
'tags'
=>
'name="'
.
$prefix
.
'commenton"'
,
'id'
=>
$prefix
.
'commenton'
,
'type'
=>
'select'
,
'note'
=>
qa_lang_html
(
$hascomments
?
'question/a_convert_warn_cs'
:
'question/a_convert_warn'
),
'options'
=>
$commentonoptions
,
'value'
=>
@
$commentonoptions
[
$lastbeforeid
],
);
qa_set_display_rules
(
$qa_content
,
array
(
$prefix
.
'commenton'
=>
$prefix
.
'dotoc'
,
$prefix
.
'toshown'
=>
$prefix
.
'dotoc'
,
$prefix
.
'tohidden'
=>
'!'
.
$prefix
.
'dotoc'
,
));
}
}
}
// Show name and notification field if appropriate
if
(
count
(
$commentonoptions
))
{
$form
[
'fields'
][
'tocomment'
]
=
array
(
'tags'
=>
'name="'
.
$prefix
.
'dotoc" id="'
.
$prefix
.
'dotoc"'
,
'label'
=>
'<span id="'
.
$prefix
.
'toshown">'
.
qa_lang_html
(
'question/a_convert_to_c_on'
)
.
'</span>'
.
'<span id="'
.
$prefix
.
'tohidden" style="display:none;">'
.
qa_lang_html
(
'question/a_convert_to_c'
)
.
'</span>'
,
'type'
=>
'checkbox'
,
'tight'
=>
true
,
);
if
(
$answer
[
'isbyuser'
])
{
$form
[
'fields'
][
'commenton'
]
=
array
(
if
(
!
qa_is_logged_in
())
'tags'
=>
'name="'
.
$prefix
.
'commenton"'
,
qa_set_up_name_field
(
$qa_content
,
$form
[
'fields'
],
isset
(
$in
[
'name'
])
?
$in
[
'name'
]
:
@
$answer
[
'name'
],
$prefix
);
'id'
=>
$prefix
.
'commenton'
,
'type'
=>
'select'
,
'note'
=>
qa_lang_html
(
$hascomments
?
'question/a_convert_warn_cs'
:
'question/a_convert_warn'
),
'options'
=>
$commentonoptions
,
'value'
=>
@
$commentonoptions
[
$lastbeforeid
],
);
qa_set_up_notify_fields
(
$qa_content
,
$form
[
'fields'
],
'A'
,
qa_get_logged_in_email
(),
qa_set_display_rules
(
$qa_content
,
array
(
isset
(
$in
[
'notify'
])
?
$in
[
'notify'
]
:
!
empty
(
$answer
[
'notify'
]),
$prefix
.
'commenton'
=>
$prefix
.
'dotoc'
,
isset
(
$in
[
'email'
])
?
$in
[
'email'
]
:
@
$answer
[
'notify'
],
@
$errors
[
'email'
],
$prefix
);
$prefix
.
'toshown'
=>
$prefix
.
'dotoc'
,
}
$prefix
.
'tohidden'
=>
'!'
.
$prefix
.
'dotoc'
,
));
}
if
(
!
qa_user_post_permit_error
(
'permit_edit_silent'
,
$answer
))
// Show name and notification field if appropriate
$form
[
'fields'
][
'silent'
]
=
array
(
'type'
=>
'checkbox'
,
'label'
=>
qa_lang_html
(
'question/save_silent_label'
),
'tags'
=>
'name="'
.
$prefix
.
'silent"'
,
'value'
=>
qa_html
(
@
$in
[
'silent'
]),
);
return
$form
;
if
(
$answer
[
'isbyuser'
])
{
if
(
!
qa_is_logged_in
())
qa_set_up_name_field
(
$qa_content
,
$form
[
'fields'
],
isset
(
$in
[
'name'
])
?
$in
[
'name'
]
:
@
$answer
[
'name'
],
$prefix
);
qa_set_up_notify_fields
(
$qa_content
,
$form
[
'fields'
],
'A'
,
qa_get_logged_in_email
(),
isset
(
$in
[
'notify'
])
?
$in
[
'notify'
]
:
!
empty
(
$answer
[
'notify'
]),
isset
(
$in
[
'email'
])
?
$in
[
'email'
]
:
@
$answer
[
'notify'
],
@
$errors
[
'email'
],
$prefix
);
}
}
if
(
!
qa_user_post_permit_error
(
'permit_edit_silent'
,
$answer
))
{
$form
[
'fields'
][
'silent'
]
=
array
(
'type'
=>
'checkbox'
,
'label'
=>
qa_lang_html
(
'question/save_silent_label'
),
'tags'
=>
'name="'
.
$prefix
.
'silent"'
,
'value'
=>
qa_html
(
@
$in
[
'silent'
]),
);
}
return
$form
;
}
function
qa_page_q_edit_a_submit
(
$answer
,
$question
,
$answers
,
$commentsfollows
,
&
$in
,
&
$errors
)
/*
/*
Processes a POSTed form for editing an answer and returns the new type of the post if successful
Processes a POSTed form for editing an answer and returns the new type of the post if successful
*/
*/
{
function
qa_page_q_edit_a_submit
(
$answer
,
$question
,
$answers
,
$commentsfollows
,
&
$in
,
&
$errors
)
$answerid
=
$answer
[
'postid'
];
{
$prefix
=
'a'
.
$answerid
.
'_'
;
$answerid
=
$answer
[
'postid'
];
$prefix
=
'a'
.
$answerid
.
'_'
;
$in
=
array
(
'dotoc'
=>
qa_post_text
(
$prefix
.
'dotoc'
),
$in
=
array
(
'commenton'
=>
qa_post_text
(
$prefix
.
'commenton'
),
'dotoc'
=>
qa_post_text
(
$prefix
.
'dotoc'
),
);
'commenton'
=>
qa_post_text
(
$prefix
.
'commenton'
),
);
if
(
$answer
[
'isbyuser'
])
{
$in
[
'name'
]
=
qa_post_text
(
$prefix
.
'name'
);
if
(
$answer
[
'isbyuser'
])
{
$in
[
'notify'
]
=
qa_post_text
(
$prefix
.
'notify'
)
!==
null
;
$in
[
'name'
]
=
qa_post_text
(
$prefix
.
'name'
);
$in
[
'email'
]
=
qa_post_text
(
$prefix
.
'email'
);
$in
[
'notify'
]
=
qa_post_text
(
$prefix
.
'notify'
)
!==
null
;
}
$in
[
'email'
]
=
qa_post_text
(
$prefix
.
'email'
);
}
if
(
!
qa_user_post_permit_error
(
'permit_edit_silent'
,
$answer
))
if
(
!
qa_user_post_permit_error
(
'permit_edit_silent'
,
$answer
))
$in
[
'silent'
]
=
qa_post_text
(
$prefix
.
'silent'
);
$in
[
'silent'
]
=
qa_post_text
(
$prefix
.
'silent'
);
qa_get_post_content
(
$prefix
.
'editor'
,
$prefix
.
'content'
,
$in
[
'editor'
],
$in
[
'content'
],
$in
[
'format'
],
$in
[
'text'
]);
qa_get_post_content
(
$prefix
.
'editor'
,
$prefix
.
'content'
,
$in
[
'editor'
],
$in
[
'content'
],
$in
[
'format'
],
$in
[
'text'
]);
// here the $in array only contains values for parts of the form that were displayed, so those are only ones checked by filters
// here the $in array only contains values for parts of the form that were displayed, so those are only ones checked by filters
$errors
=
array
();
$errors
=
array
();
if
(
!
qa_check_form_security_code
(
'edit-'
.
$answerid
,
qa_post_text
(
$prefix
.
'code'
)))
if
(
!
qa_check_form_security_code
(
'edit-'
.
$answerid
,
qa_post_text
(
$prefix
.
'code'
)))
$errors
[
'content'
]
=
qa_lang_html
(
'misc/form_security_again'
);
$errors
[
'content'
]
=
qa_lang_html
(
'misc/form_security_again'
);
else
{
else
{
$in
[
'queued'
]
=
qa_opt
(
'moderate_edited_again'
)
&&
qa_user_moderation_reason
(
qa_user_level_for_post
(
$answer
));
$in
[
'queued'
]
=
qa_opt
(
'moderate_edited_again'
)
&&
qa_user_moderation_reason
(
qa_user_level_for_post
(
$answer
));
$filtermodules
=
qa_load_modules_with
(
'filter'
,
'filter_answer'
);
$filtermodules
=
qa_load_modules_with
(
'filter'
,
'filter_answer'
);
foreach
(
$filtermodules
as
$filtermodule
)
{
foreach
(
$filtermodules
as
$filtermodule
)
{
$oldin
=
$in
;
$oldin
=
$in
;
$filtermodule
->
filter_answer
(
$in
,
$errors
,
$question
,
$answer
);
$filtermodule
->
filter_answer
(
$in
,
$errors
,
$question
,
$answer
);
qa_update_post_text
(
$in
,
$oldin
);
qa_update_post_text
(
$in
,
$oldin
);
}
}
if
(
empty
(
$errors
))
{
if
(
empty
(
$errors
))
{
$userid
=
qa_get_logged_in_userid
();
$userid
=
qa_get_logged_in_userid
();
$handle
=
qa_get_logged_in_handle
();
$handle
=
qa_get_logged_in_handle
();
$cookieid
=
qa_cookie_get
();
$cookieid
=
qa_cookie_get
();
if
(
!
isset
(
$in
[
'silent'
]))
if
(
!
isset
(
$in
[
'silent'
]))
$in
[
'silent'
]
=
false
;
$in
[
'silent'
]
=
false
;
$setnotify
=
$answer
[
'isbyuser'
]
?
qa_combine_notify_email
(
$answer
[
'userid'
],
$in
[
'notify'
],
$in
[
'email'
])
:
$answer
[
'notify'
];
$setnotify
=
$answer
[
'isbyuser'
]
?
qa_combine_notify_email
(
$answer
[
'userid'
],
$in
[
'notify'
],
$in
[
'email'
])
:
$answer
[
'notify'
];
if
(
$in
[
'dotoc'
]
&&
(
if
(
$in
[
'dotoc'
]
&&
(
((
$in
[
'commenton'
]
==
$question
[
'postid'
])
&&
$question
[
'commentable'
])
||
((
$in
[
'commenton'
]
==
$question
[
'postid'
])
&&
$question
[
'commentable'
])
||
((
$in
[
'commenton'
]
!=
$answerid
)
&&
@
$answers
[
$in
[
'commenton'
]][
'commentable'
])
((
$in
[
'commenton'
]
!=
$answerid
)
&&
@
$answers
[
$in
[
'commenton'
]][
'commentable'
])
))
{
// convert to a comment
)
)
{
// convert to a comment
if
(
qa_user_limits_remaining
(
QA_LIMIT_COMMENTS
))
{
// already checked 'permit_post_c'
if
(
qa_user_limits_remaining
(
QA_LIMIT_COMMENTS
))
{
// already checked 'permit_post_c'
qa_answer_to_comment
(
$answer
,
$in
[
'commenton'
],
$in
[
'content'
],
$in
[
'format'
],
$in
[
'text'
],
$setnotify
,
qa_answer_to_comment
(
$answer
,
$in
[
'commenton'
],
$in
[
'content'
],
$in
[
'format'
],
$in
[
'text'
],
$setnotify
,
$userid
,
$handle
,
$cookieid
,
$question
,
$answers
,
$commentsfollows
,
@
$in
[
'name'
],
$in
[
'queued'
],
$in
[
'silent'
]);
$userid
,
$handle
,
$cookieid
,
$question
,
$answers
,
$commentsfollows
,
@
$in
[
'name'
],
$in
[
'queued'
],
$in
[
'silent'
]);
return
'C'
;
// to signify that redirect should be to the comment
return
'C'
;
// to signify that redirect should be to the comment
}
else
}
else
$errors
[
'content'
]
=
qa_lang_html
(
'question/comment_limit'
);
// not really best place for error, but it will do
$errors
[
'content'
]
=
qa_lang_html
(
'question/comment_limit'
);
// not really best place for error, but it will do
}
else
{
}
else
{
qa_answer_set_content
(
$answer
,
$in
[
'content'
],
$in
[
'format'
],
$in
[
'text'
],
$setnotify
,
qa_answer_set_content
(
$answer
,
$in
[
'content'
],
$in
[
'format'
],
$in
[
'text'
],
$setnotify
,
$userid
,
$handle
,
$cookieid
,
$question
,
@
$in
[
'name'
],
$in
[
'queued'
],
$in
[
'silent'
]);
$userid
,
$handle
,
$cookieid
,
$question
,
@
$in
[
'name'
],
$in
[
'queued'
],
$in
[
'silent'
]);
return
'A'
;
return
'A'
;
}
}
}
}
}
return
null
;
}
}
return
null
;
}
function
qa_page_q_do_comment
(
$question
,
$parent
,
$commentsfollows
,
$pagestart
,
$usecaptcha
,
&
$cnewin
,
&
$cnewerrors
,
&
$formtype
,
&
$formpostid
,
&
$error
)
/*
/*
Processes a request to add a comment to $parent, with antecedent $question, checking for permissions errors
Processes a request to add a comment to $parent, with antecedent $question, checking for permissions errors
*/
*/
{
function
qa_page_q_do_comment
(
$question
,
$parent
,
$commentsfollows
,
$pagestart
,
$usecaptcha
,
&
$cnewin
,
&
$cnewerrors
,
&
$formtype
,
&
$formpostid
,
&
$error
)
// The 'approve', 'login', 'confirm', 'userblock', 'ipblock' permission errors are reported to the user here
{
// The other option ('level') prevents the comment button being shown, in qa_page_q_post_rules(...)
// The 'approve', 'login', 'confirm', 'userblock', 'ipblock' permission errors are reported to the user here
// The other option ('level') prevents the comment button being shown, in qa_page_q_post_rules(...)
$parentid
=
$parent
[
'postid'
];
$parentid
=
$parent
[
'postid'
];
$answer
=
(
$question
[
'postid'
]
==
$parentid
)
?
null
:
$parent
;
$answer
=
(
$question
[
'postid'
]
==
$parentid
)
?
null
:
$parent
;
switch
(
qa_user_post_permit_error
(
'permit_post_c'
,
$parent
,
QA_LIMIT_COMMENTS
))
{
switch
(
qa_user_post_permit_error
(
'permit_post_c'
,
$parent
,
QA_LIMIT_COMMENTS
))
{
case
'login'
:
case
'login'
:
$error
=
qa_insert_login_links
(
qa_lang_html
(
'question/comment_must_login'
),
qa_request
());
$error
=
qa_insert_login_links
(
qa_lang_html
(
'question/comment_must_login'
),
qa_request
());
break
;
break
;
case
'confirm'
:
$error
=
qa_insert_login_links
(
qa_lang_html
(
'question/comment_must_confirm'
),
qa_request
());
break
;
case
'approve
'
:
case
'confirm
'
:
$error
=
qa_lang_html
(
'question/comment_must_be_approved'
);
$error
=
qa_insert_login_links
(
qa_lang_html
(
'question/comment_must_confirm'
),
qa_request
()
);
break
;
break
;
case
'limit
'
:
case
'approve
'
:
$error
=
qa_lang_html
(
'question/comment_limit
'
);
$error
=
qa_lang_html
(
'question/comment_must_be_approved
'
);
break
;
break
;
default
:
case
'limit'
:
$error
=
qa_lang_html
(
'users/no_permission
'
);
$error
=
qa_lang_html
(
'question/comment_limit
'
);
break
;
break
;
case
false
:
default
:
if
(
qa_clicked
(
'c'
.
$parentid
.
'_doadd'
))
{
$error
=
qa_lang_html
(
'users/no_permission'
);
$commentid
=
qa_page_q_add_c_submit
(
$question
,
$parent
,
$commentsfollows
,
$usecaptcha
,
$cnewin
[
$parentid
],
$cnewerrors
[
$parentid
])
;
break
;
if
(
isset
(
$commentid
))
case
false
:
qa_page_q_refresh
(
$pagestart
,
null
,
'C'
,
$commentid
);
if
(
qa_clicked
(
'c'
.
$parentid
.
'_doadd'
))
{
$commentid
=
qa_page_q_add_c_submit
(
$question
,
$parent
,
$commentsfollows
,
$usecaptcha
,
$cnewin
[
$parentid
],
$cnewerrors
[
$parentid
]);
else
{
if
(
isset
(
$commentid
))
$formtype
=
'c_add'
;
qa_page_q_refresh
(
$pagestart
,
null
,
'C'
,
$commentid
);
$formpostid
=
$parentid
;
// show form again
}
}
else
{
else
{
$formtype
=
'c_add'
;
$formtype
=
'c_add'
;
$formpostid
=
$parentid
;
// show form first time
$formpostid
=
$parentid
;
// show form again
}
}
break
;
}
}
else
{
$formtype
=
'c_add'
;
$formpostid
=
$parentid
;
// show form first time
}
break
;
}
}
}
function
qa_page_q_edit_c_form
(
&
$qa_content
,
$id
,
$comment
,
$in
,
$errors
)
/*
/*
Returns a $qa_content form for editing a comment and sets up other parts of $qa_content accordingly
Returns a $qa_content form for editing a comment and sets up other parts of $qa_content accordingly
*/
*/
{
function
qa_page_q_edit_c_form
(
&
$qa_content
,
$id
,
$comment
,
$in
,
$errors
)
$commentid
=
$comment
[
'postid'
];
{
$prefix
=
'c'
.
$commentid
.
'_'
;
$commentid
=
$comment
[
'postid'
];
$prefix
=
'c'
.
$commentid
.
'_'
;
$content
=
isset
(
$in
[
'content'
])
?
$in
[
'content'
]
:
$comment
[
'content'
];
$content
=
isset
(
$in
[
'content'
])
?
$in
[
'content'
]
:
$comment
[
'content'
];
$format
=
isset
(
$in
[
'format'
])
?
$in
[
'format'
]
:
$comment
[
'format'
];
$format
=
isset
(
$in
[
'format'
])
?
$in
[
'format'
]
:
$comment
[
'format'
];
$editorname
=
isset
(
$in
[
'editor'
])
?
$in
[
'editor'
]
:
qa_opt
(
'editor_for_cs'
);
$editorname
=
isset
(
$in
[
'editor'
])
?
$in
[
'editor'
]
:
qa_opt
(
'editor_for_cs'
);
$editor
=
qa_load_editor
(
$content
,
$format
,
$editorname
);
$editor
=
qa_load_editor
(
$content
,
$format
,
$editorname
);
$form
=
array
(
$form
=
array
(
'tags'
=>
'method="post" action="'
.
qa_self_html
()
.
'"'
,
'tags'
=>
'method="post" action="'
.
qa_self_html
()
.
'"'
,
'id'
=>
$id
,
'id'
=>
$id
,
'title'
=>
qa_lang_html
(
'question/edit_c_title'
),
'title'
=>
qa_lang_html
(
'question/edit_c_title'
),
'style'
=>
'tall'
,
'style'
=>
'tall'
,
'fields'
=>
array
(
'fields'
=>
array
(
'content'
=>
array_merge
(
'content'
=>
array_merge
(
qa_editor_load_field
(
$editor
,
$qa_content
,
$content
,
$format
,
$prefix
.
'content'
,
4
,
true
),
qa_editor_load_field
(
$editor
,
$qa_content
,
$content
,
$format
,
$prefix
.
'content'
,
4
,
true
),
array
(
array
(
'error'
=>
qa_html
(
@
$errors
[
'content'
]),
'error'
=>
qa_html
(
@
$errors
[
'content'
]),
)
)
),
),
),
),
'buttons'
=>
array
(
'buttons'
=>
array
(
'save'
=>
array
(
'save'
=>
array
(
'tags'
=>
'onclick="qa_show_waiting_after(this, false); '
.
'tags'
=>
'onclick="qa_show_waiting_after(this, false); '
.
(
method_exists
(
$editor
,
'update_script'
)
?
$editor
->
update_script
(
$prefix
.
'content'
)
:
''
)
.
'"'
,
(
method_exists
(
$editor
,
'update_script'
)
?
$editor
->
update_script
(
$prefix
.
'content'
)
:
''
)
.
'"'
,
'label'
=>
qa_lang_html
(
'main/save_button'
),
'label'
=>
qa_lang_html
(
'main/save_button'
),
),
'cancel'
=>
array
(
'tags'
=>
'name="docancel"'
,
'label'
=>
qa_lang_html
(
'main/cancel_button'
),
),
),
),
'hidden'
=>
array
(
'cancel'
=>
array
(
$prefix
.
'editor'
=>
qa_html
(
$editorname
),
'tags'
=>
'name="docancel"'
,
$prefix
.
'dosave'
=>
'1'
,
'label'
=>
qa_lang_html
(
'main/cancel_button'
),
$prefix
.
'code'
=>
qa_get_form_security_code
(
'edit-'
.
$commentid
),
),
),
);
),
if
(
$comment
[
'isbyuser'
])
{
'hidden'
=>
array
(
if
(
!
qa_is_logged_in
())
$prefix
.
'editor'
=>
qa_html
(
$editorname
),
qa_set_up_name_field
(
$qa_content
,
$form
[
'fields'
],
isset
(
$in
[
'name'
])
?
$in
[
'name'
]
:
@
$comment
[
'name'
],
$prefix
);
$prefix
.
'dosave'
=>
'1'
,
$prefix
.
'code'
=>
qa_get_form_security_code
(
'edit-'
.
$commentid
),
qa_set_up_notify_fields
(
$qa_content
,
$form
[
'fields'
],
'C'
,
qa_get_logged_in_email
(),
),
isset
(
$in
[
'notify'
])
?
$in
[
'notify'
]
:
!
empty
(
$comment
[
'notify'
]),
);
isset
(
$in
[
'email'
])
?
$in
[
'email'
]
:
@
$comment
[
'notify'
],
@
$errors
[
'email'
],
$prefix
);
}
if
(
$comment
[
'isbyuser'
])
{
if
(
!
qa_is_logged_in
())
if
(
!
qa_user_post_permit_error
(
'permit_edit_silent'
,
$comment
))
qa_set_up_name_field
(
$qa_content
,
$form
[
'fields'
],
isset
(
$in
[
'name'
])
?
$in
[
'name'
]
:
@
$comment
[
'name'
],
$prefix
);
$form
[
'fields'
][
'silent'
]
=
array
(
'type'
=>
'checkbox'
,
qa_set_up_notify_fields
(
$qa_content
,
$form
[
'fields'
],
'C'
,
qa_get_logged_in_email
(),
'label'
=>
qa_lang_html
(
'question/save_silent_label'
),
isset
(
$in
[
'notify'
])
?
$in
[
'notify'
]
:
!
empty
(
$comment
[
'notify'
]),
'tags'
=>
'name="'
.
$prefix
.
'silent"'
,
isset
(
$in
[
'email'
])
?
$in
[
'email'
]
:
@
$comment
[
'notify'
],
@
$errors
[
'email'
],
$prefix
);
'value'
=>
qa_html
(
@
$in
[
'silent'
]),
}
);
return
$form
;
if
(
!
qa_user_post_permit_error
(
'permit_edit_silent'
,
$comment
))
{
$form
[
'fields'
][
'silent'
]
=
array
(
'type'
=>
'checkbox'
,
'label'
=>
qa_lang_html
(
'question/save_silent_label'
),
'tags'
=>
'name="'
.
$prefix
.
'silent"'
,
'value'
=>
qa_html
(
@
$in
[
'silent'
]),
);
}
}
return
$form
;
}
function
qa_page_q_edit_c_submit
(
$comment
,
$question
,
$parent
,
&
$in
,
&
$errors
)
/*
/*
Processes a POSTed form for editing a comment and returns true if successful
Processes a POSTed form for editing a comment and returns true if successful
*/
*/
{
function
qa_page_q_edit_c_submit
(
$comment
,
$question
,
$parent
,
&
$in
,
&
$errors
)
$commentid
=
$comment
[
'postid'
];
{
$prefix
=
'c'
.
$commentid
.
'_'
;
$commentid
=
$comment
[
'postid'
];
$prefix
=
'c'
.
$commentid
.
'_'
;
$in
=
array
();
$in
=
array
();
if
(
$comment
[
'isbyuser'
])
{
if
(
$comment
[
'isbyuser'
])
{
$in
[
'name'
]
=
qa_post_text
(
$prefix
.
'name'
);
$in
[
'name'
]
=
qa_post_text
(
$prefix
.
'name'
);
$in
[
'notify'
]
=
qa_post_text
(
$prefix
.
'notify'
)
!==
null
;
$in
[
'notify'
]
=
qa_post_text
(
$prefix
.
'notify'
)
!==
null
;
$in
[
'email'
]
=
qa_post_text
(
$prefix
.
'email'
);
$in
[
'email'
]
=
qa_post_text
(
$prefix
.
'email'
);
}
}
if
(
!
qa_user_post_permit_error
(
'permit_edit_silent'
,
$comment
))
if
(
!
qa_user_post_permit_error
(
'permit_edit_silent'
,
$comment
))
$in
[
'silent'
]
=
qa_post_text
(
$prefix
.
'silent'
);
$in
[
'silent'
]
=
qa_post_text
(
$prefix
.
'silent'
);
qa_get_post_content
(
$prefix
.
'editor'
,
$prefix
.
'content'
,
$in
[
'editor'
],
$in
[
'content'
],
$in
[
'format'
],
$in
[
'text'
]);
qa_get_post_content
(
$prefix
.
'editor'
,
$prefix
.
'content'
,
$in
[
'editor'
],
$in
[
'content'
],
$in
[
'format'
],
$in
[
'text'
]);
// here the $in array only contains values for parts of the form that were displayed, so those are only ones checked by filters
// here the $in array only contains values for parts of the form that were displayed, so those are only ones checked by filters
$errors
=
array
();
$errors
=
array
();
if
(
!
qa_check_form_security_code
(
'edit-'
.
$commentid
,
qa_post_text
(
$prefix
.
'code'
)))
if
(
!
qa_check_form_security_code
(
'edit-'
.
$commentid
,
qa_post_text
(
$prefix
.
'code'
)))
$errors
[
'content'
]
=
qa_lang_html
(
'misc/form_security_again'
);
$errors
[
'content'
]
=
qa_lang_html
(
'misc/form_security_again'
);
else
{
else
{
$in
[
'queued'
]
=
qa_opt
(
'moderate_edited_again'
)
&&
qa_user_moderation_reason
(
qa_user_level_for_post
(
$comment
));
$in
[
'queued'
]
=
qa_opt
(
'moderate_edited_again'
)
&&
qa_user_moderation_reason
(
qa_user_level_for_post
(
$comment
));
$filtermodules
=
qa_load_modules_with
(
'filter'
,
'filter_comment'
);
$filtermodules
=
qa_load_modules_with
(
'filter'
,
'filter_comment'
);
foreach
(
$filtermodules
as
$filtermodule
)
{
foreach
(
$filtermodules
as
$filtermodule
)
{
$oldin
=
$in
;
$oldin
=
$in
;
$filtermodule
->
filter_comment
(
$in
,
$errors
,
$question
,
$parent
,
$comment
);
$filtermodule
->
filter_comment
(
$in
,
$errors
,
$question
,
$parent
,
$comment
);
qa_update_post_text
(
$in
,
$oldin
);
qa_update_post_text
(
$in
,
$oldin
);
}
}
if
(
empty
(
$errors
))
{
if
(
empty
(
$errors
))
{
$userid
=
qa_get_logged_in_userid
();
$userid
=
qa_get_logged_in_userid
();
$handle
=
qa_get_logged_in_handle
();
$handle
=
qa_get_logged_in_handle
();
$cookieid
=
qa_cookie_get
();
$cookieid
=
qa_cookie_get
();
if
(
!
isset
(
$in
[
'silent'
]))
if
(
!
isset
(
$in
[
'silent'
]))
$in
[
'silent'
]
=
false
;
$in
[
'silent'
]
=
false
;
$setnotify
=
$comment
[
'isbyuser'
]
?
qa_combine_notify_email
(
$comment
[
'userid'
],
$in
[
'notify'
],
$in
[
'email'
])
:
$comment
[
'notify'
];
$setnotify
=
$comment
[
'isbyuser'
]
?
qa_combine_notify_email
(
$comment
[
'userid'
],
$in
[
'notify'
],
$in
[
'email'
])
:
$comment
[
'notify'
];
qa_comment_set_content
(
$comment
,
$in
[
'content'
],
$in
[
'format'
],
$in
[
'text'
],
$setnotify
,
qa_comment_set_content
(
$comment
,
$in
[
'content'
],
$in
[
'format'
],
$in
[
'text'
],
$setnotify
,
$userid
,
$handle
,
$cookieid
,
$question
,
$parent
,
@
$in
[
'name'
],
$in
[
'queued'
],
$in
[
'silent'
]);
$userid
,
$handle
,
$cookieid
,
$question
,
$parent
,
@
$in
[
'name'
],
$in
[
'queued'
],
$in
[
'silent'
]);
return
true
;
return
true
;
}
}
}
return
false
;
}
}
return
false
;
/*
}
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
qa-include/pages/question.php
View file @
d057c557
...
@@ -20,453 +20,456 @@
...
@@ -20,453 +20,456 @@
More about this license: http://www.question2answer.org/license.php
More about this license: http://www.question2answer.org/license.php
*/
*/
if
(
!
defined
(
'QA_VERSION'
))
{
// don't allow this page to be requested directly from browser
if
(
!
defined
(
'QA_VERSION'
))
{
// don't allow this page to be requested directly from browser
header
(
'Location: ../'
);
header
(
'Location: ../'
);
exit
;
exit
;
}
}
require_once
QA_INCLUDE_DIR
.
'app/cookies.php'
;
require_once
QA_INCLUDE_DIR
.
'app/cookies.php'
;
require_once
QA_INCLUDE_DIR
.
'app/format.php'
;
require_once
QA_INCLUDE_DIR
.
'app/format.php'
;
require_once
QA_INCLUDE_DIR
.
'db/selects.php'
;
require_once
QA_INCLUDE_DIR
.
'db/selects.php'
;
require_once
QA_INCLUDE_DIR
.
'util/sort.php'
;
require_once
QA_INCLUDE_DIR
.
'util/sort.php'
;
require_once
QA_INCLUDE_DIR
.
'util/string.php'
;
require_once
QA_INCLUDE_DIR
.
'util/string.php'
;
require_once
QA_INCLUDE_DIR
.
'app/captcha.php'
;
require_once
QA_INCLUDE_DIR
.
'app/captcha.php'
;
require_once
QA_INCLUDE_DIR
.
'pages/question-view.php'
;
require_once
QA_INCLUDE_DIR
.
'pages/question-view.php'
;
require_once
QA_INCLUDE_DIR
.
'app/updates.php'
;
require_once
QA_INCLUDE_DIR
.
'app/updates.php'
;
$questionid
=
qa_request_part
(
0
);
$questionid
=
qa_request_part
(
0
);
$userid
=
qa_get_logged_in_userid
();
$userid
=
qa_get_logged_in_userid
();
$cookieid
=
qa_cookie_get
();
$cookieid
=
qa_cookie_get
();
$pagestate
=
qa_get_state
();
$pagestate
=
qa_get_state
();
// Get information about this question
// Get information about this question
$cacheHandler
=
Q2A_Storage_CacheManager
::
getInstance
();
$cacheHandler
=
Q2A_Storage_CacheManager
::
getInstance
();
$cacheKey
=
"page:question:
$questionid
"
;
$cacheKey
=
"page:question:
$questionid
"
;
$useCache
=
$userid
===
null
&&
$cacheHandler
->
isEnabled
()
&&
!
qa_is_http_post
()
&&
empty
(
$pagestate
);
$useCache
=
$userid
===
null
&&
$cacheHandler
->
isEnabled
()
&&
!
qa_is_http_post
()
&&
empty
(
$pagestate
);
$saveCache
=
false
;
$saveCache
=
false
;
if
(
$useCache
)
{
if
(
$useCache
)
{
$questionData
=
$cacheHandler
->
get
(
$cacheKey
);
$questionData
=
$cacheHandler
->
get
(
$cacheKey
);
}
}
if
(
!
isset
(
$questionData
))
{
if
(
!
isset
(
$questionData
))
{
$questionData
=
qa_db_select_with_pending
(
$questionData
=
qa_db_select_with_pending
(
qa_db_full_post_selectspec
(
$userid
,
$questionid
),
qa_db_full_post_selectspec
(
$userid
,
$questionid
),
qa_db_full_child_posts_selectspec
(
$userid
,
$questionid
),
qa_db_full_child_posts_selectspec
(
$userid
,
$questionid
),
qa_db_full_a_child_posts_selectspec
(
$userid
,
$questionid
),
qa_db_full_a_child_posts_selectspec
(
$userid
,
$questionid
),
qa_db_post_parent_q_selectspec
(
$questionid
),
qa_db_post_parent_q_selectspec
(
$questionid
),
qa_db_post_close_post_selectspec
(
$questionid
),
qa_db_post_close_post_selectspec
(
$questionid
),
qa_db_post_duplicates_selectspec
(
$questionid
),
qa_db_post_duplicates_selectspec
(
$questionid
),
qa_db_post_meta_selectspec
(
$questionid
,
'qa_q_extra'
),
qa_db_post_meta_selectspec
(
$questionid
,
'qa_q_extra'
),
qa_db_category_nav_selectspec
(
$questionid
,
true
,
true
,
true
),
qa_db_category_nav_selectspec
(
$questionid
,
true
,
true
,
true
),
isset
(
$userid
)
?
qa_db_is_favorite_selectspec
(
$userid
,
QA_ENTITY_QUESTION
,
$questionid
)
:
null
isset
(
$userid
)
?
qa_db_is_favorite_selectspec
(
$userid
,
QA_ENTITY_QUESTION
,
$questionid
)
:
null
);
);
// whether to save the cache (actioned below, after basic checks)
// whether to save the cache (actioned below, after basic checks)
$saveCache
=
$useCache
;
$saveCache
=
$useCache
;
}
}
list
(
$question
,
$childposts
,
$achildposts
,
$parentquestion
,
$closepost
,
$duplicateposts
,
$extravalue
,
$categories
,
$favorite
)
=
$questionData
;
list
(
$question
,
$childposts
,
$achildposts
,
$parentquestion
,
$closepost
,
$duplicateposts
,
$extravalue
,
$categories
,
$favorite
)
=
$questionData
;
if
(
$question
[
'basetype'
]
!=
'Q'
)
// don't allow direct viewing of other types of post
if
(
$question
[
'basetype'
]
!=
'Q'
)
// don't allow direct viewing of other types of post
$question
=
null
;
$question
=
null
;
if
(
isset
(
$question
))
{
if
(
isset
(
$question
))
{
$q_request
=
qa_q_request
(
$questionid
,
$question
[
'title'
]);
$q_request
=
qa_q_request
(
$questionid
,
$question
[
'title'
]);
if
(
trim
(
$q_request
,
'/'
)
!==
trim
(
qa_request
(),
'/'
))
{
if
(
trim
(
$q_request
,
'/'
)
!==
trim
(
qa_request
(),
'/'
))
{
// redirect if the current URL is incorrect
// redirect if the current URL is incorrect
qa_redirect
(
$q_request
);
qa_redirect
(
$q_request
);
}
}
$question
[
'extra'
]
=
$extravalue
;
$question
[
'extra'
]
=
$extravalue
;
$answers
=
qa_page_q_load_as
(
$question
,
$childposts
);
$answers
=
qa_page_q_load_as
(
$question
,
$childposts
);
$commentsfollows
=
qa_page_q_load_c_follows
(
$question
,
$childposts
,
$achildposts
,
$duplicateposts
);
$commentsfollows
=
qa_page_q_load_c_follows
(
$question
,
$childposts
,
$achildposts
,
$duplicateposts
);
$question
=
$question
+
qa_page_q_post_rules
(
$question
,
null
,
null
,
$childposts
+
$duplicateposts
);
// array union
$question
=
$question
+
qa_page_q_post_rules
(
$question
,
null
,
null
,
$childposts
+
$duplicateposts
);
// array union
if
(
$question
[
'selchildid'
]
&&
(
@
$answers
[
$question
[
'selchildid'
]][
'type'
]
!=
'A'
))
if
(
$question
[
'selchildid'
]
&&
(
@
$answers
[
$question
[
'selchildid'
]][
'type'
]
!=
'A'
))
$question
[
'selchildid'
]
=
null
;
// if selected answer is hidden or somehow not there, consider it not selected
$question
[
'selchildid'
]
=
null
;
// if selected answer is hidden or somehow not there, consider it not selected
foreach
(
$answers
as
$key
=>
$answer
)
{
foreach
(
$answers
as
$key
=>
$answer
)
{
$answers
[
$key
]
=
$answer
+
qa_page_q_post_rules
(
$answer
,
$question
,
$answers
,
$achildposts
);
$answers
[
$key
]
=
$answer
+
qa_page_q_post_rules
(
$answer
,
$question
,
$answers
,
$achildposts
);
$answers
[
$key
][
'isselected'
]
=
(
$answer
[
'postid'
]
==
$question
[
'selchildid'
]);
$answers
[
$key
][
'isselected'
]
=
(
$answer
[
'postid'
]
==
$question
[
'selchildid'
]);
}
}
foreach
(
$commentsfollows
as
$key
=>
$commentfollow
)
{
foreach
(
$commentsfollows
as
$key
=>
$commentfollow
)
{
$parent
=
(
$commentfollow
[
'parentid'
]
==
$questionid
)
?
$question
:
@
$answers
[
$commentfollow
[
'parentid'
]];
$parent
=
(
$commentfollow
[
'parentid'
]
==
$questionid
)
?
$question
:
@
$answers
[
$commentfollow
[
'parentid'
]];
$commentsfollows
[
$key
]
=
$commentfollow
+
qa_page_q_post_rules
(
$commentfollow
,
$parent
,
$commentsfollows
,
null
);
$commentsfollows
[
$key
]
=
$commentfollow
+
qa_page_q_post_rules
(
$commentfollow
,
$parent
,
$commentsfollows
,
null
);
}
}
}
}
// Deal with question not found or not viewable, otherwise report the view event
// Deal with question not found or not viewable, otherwise report the view event
if
(
!
isset
(
$question
))
if
(
!
isset
(
$question
))
return
include
QA_INCLUDE_DIR
.
'qa-page-not-found.php'
;
return
include
QA_INCLUDE_DIR
.
'qa-page-not-found.php'
;
if
(
!
$question
[
'viewable'
])
{
$qa_content
=
qa_content_prepare
();
if
(
$question
[
'queued'
])
if
(
!
$question
[
'viewable'
])
{
$qa_content
[
'error'
]
=
qa_lang_html
(
'question/q_waiting_approval'
);
$qa_content
=
qa_content_prepare
();
elseif
(
$question
[
'flagcount'
]
&&
!
isset
(
$question
[
'lastuserid'
]))
$qa_content
[
'error'
]
=
qa_lang_html
(
'question/q_hidden_flagged'
);
elseif
(
$question
[
'authorlast'
])
$qa_content
[
'error'
]
=
qa_lang_html
(
'question/q_hidden_author'
);
else
$qa_content
[
'error'
]
=
qa_lang_html
(
'question/q_hidden_other'
);
$qa_content
[
'suggest_next'
]
=
qa_html_suggest_qs_tags
(
qa_using_tags
());
if
(
$question
[
'queued'
])
$qa_content
[
'error'
]
=
qa_lang_html
(
'question/q_waiting_approval'
);
elseif
(
$question
[
'flagcount'
]
&&
!
isset
(
$question
[
'lastuserid'
]))
$qa_content
[
'error'
]
=
qa_lang_html
(
'question/q_hidden_flagged'
);
elseif
(
$question
[
'authorlast'
])
$qa_content
[
'error'
]
=
qa_lang_html
(
'question/q_hidden_author'
);
else
$qa_content
[
'error'
]
=
qa_lang_html
(
'question/q_hidden_other'
);
return
$qa_content
;
$qa_content
[
'suggest_next'
]
=
qa_html_suggest_qs_tags
(
qa_using_tags
());
}
$permiterror
=
qa_user_post_permit_error
(
'permit_view_q_page'
,
$question
,
null
,
false
);
return
$qa_content
;
}
if
(
$permiterror
&&
(
qa_is_human_probably
()
||
!
qa_opt
(
'allow_view_q_bots'
))
)
{
$permiterror
=
qa_user_post_permit_error
(
'permit_view_q_page'
,
$question
,
null
,
false
);
$qa_content
=
qa_content_prepare
();
$topage
=
qa_q_request
(
$questionid
,
$question
[
'title'
]);
switch
(
$permiterror
)
{
if
(
$permiterror
&&
(
qa_is_human_probably
()
||
!
qa_opt
(
'allow_view_q_bots'
)))
{
case
'login'
:
$qa_content
=
qa_content_prepare
();
$qa_content
[
'error'
]
=
qa_insert_login_links
(
qa_lang_html
(
'main/view_q_must_login'
),
$topage
);
$topage
=
qa_q_request
(
$questionid
,
$question
[
'title'
]);
break
;
case
'confirm'
:
switch
(
$permiterror
)
{
$qa_content
[
'error'
]
=
qa_insert_login_links
(
qa_lang_html
(
'main/view_q_must_confirm'
),
$topage
);
case
'login'
:
break
;
$qa_content
[
'error'
]
=
qa_insert_login_links
(
qa_lang_html
(
'main/view_q_must_login'
),
$topage
);
break
;
case
'approve
'
:
case
'confirm
'
:
$qa_content
[
'error'
]
=
qa_lang_html
(
'main/view_q_must_be_approved'
);
$qa_content
[
'error'
]
=
qa_insert_login_links
(
qa_lang_html
(
'main/view_q_must_confirm'
),
$topage
);
break
;
break
;
default
:
case
'approve'
:
$qa_content
[
'error'
]
=
qa_lang_html
(
'users/no_permission'
);
$qa_content
[
'error'
]
=
qa_lang_html
(
'main/view_q_must_be_approved'
);
break
;
break
;
}
return
$qa_content
;
default
:
$qa_content
[
'error'
]
=
qa_lang_html
(
'users/no_permission'
);
break
;
}
}
return
$qa_content
;
}
// Save question data to cache (if older than configured limit)
// Save question data to cache (if older than configured limit)
if
(
$saveCache
)
{
if
(
$saveCache
)
{
$questionAge
=
qa_opt
(
'db_time'
)
-
$question
[
'created'
];
$questionAge
=
qa_opt
(
'db_time'
)
-
$question
[
'created'
];
if
(
$questionAge
>
86400
*
qa_opt
(
'caching_q_start'
))
{
if
(
$questionAge
>
86400
*
qa_opt
(
'caching_q_start'
))
{
$cacheHandler
->
set
(
$cacheKey
,
$questionData
,
qa_opt
(
'caching_q_time'
));
$cacheHandler
->
set
(
$cacheKey
,
$questionData
,
qa_opt
(
'caching_q_time'
));
}
}
}
}
// Determine if captchas will be required
// Determine if captchas will be required
$captchareason
=
qa_user_captcha_reason
(
qa_user_level_for_post
(
$question
));
$captchareason
=
qa_user_captcha_reason
(
qa_user_level_for_post
(
$question
));
$usecaptcha
=
(
$captchareason
!=
false
);
$usecaptcha
=
(
$captchareason
!=
false
);
// If we're responding to an HTTP POST, include file that handles all posting/editing/etc... logic
// If we're responding to an HTTP POST, include file that handles all posting/editing/etc... logic
// This is in a separate file because it's a *lot* of logic, and will slow down ordinary page views
// This is in a separate file because it's a *lot* of logic, and will slow down ordinary page views
$pagestart
=
qa_get_start
();
$pagestart
=
qa_get_start
();
$showid
=
qa_get
(
'show'
);
$showid
=
qa_get
(
'show'
);
$pageerror
=
null
;
$pageerror
=
null
;
$formtype
=
null
;
$formtype
=
null
;
$formpostid
=
null
;
$formpostid
=
null
;
$jumptoanchor
=
null
;
$jumptoanchor
=
null
;
$commentsall
=
null
;
$commentsall
=
null
;
if
(
substr
(
$pagestate
,
0
,
13
)
==
'showcomments-'
)
{
if
(
substr
(
$pagestate
,
0
,
13
)
==
'showcomments-'
)
{
$commentsall
=
substr
(
$pagestate
,
13
);
$commentsall
=
substr
(
$pagestate
,
13
);
$pagestate
=
null
;
$pagestate
=
null
;
}
elseif
(
isset
(
$showid
))
{
}
elseif
(
isset
(
$showid
))
{
foreach
(
$commentsfollows
as
$comment
)
foreach
(
$commentsfollows
as
$comment
)
{
if
(
$comment
[
'postid'
]
==
$showid
)
{
if
(
$comment
[
'postid'
]
==
$showid
)
{
$commentsall
=
$comment
[
'parentid'
];
$commentsall
=
$comment
[
'parentid'
];
break
;
break
;
}
}
}
}
}
if
(
qa_is_http_post
()
||
strlen
(
$pagestate
))
if
(
qa_is_http_post
()
||
strlen
(
$pagestate
))
require
QA_INCLUDE_DIR
.
'pages/question-post.php'
;
require
QA_INCLUDE_DIR
.
'pages/question-post.php'
;
$formrequested
=
isset
(
$formtype
);
$formrequested
=
isset
(
$formtype
);
if
((
!
$formrequested
)
&&
$question
[
'answerbutton'
])
{
if
((
!
$formrequested
)
&&
$question
[
'answerbutton'
])
{
$immedoption
=
qa_opt
(
'show_a_form_immediate'
);
$immedoption
=
qa_opt
(
'show_a_form_immediate'
);
if
(
(
$immedoption
==
'always'
)
||
((
$immedoption
==
'if_no_as'
)
&&
(
!
$question
[
'isbyuser'
])
&&
(
!
$question
[
'acount'
]))
)
if
((
$immedoption
==
'always'
)
||
((
$immedoption
==
'if_no_as'
)
&&
(
!
$question
[
'isbyuser'
])
&&
(
!
$question
[
'acount'
]))
)
$formtype
=
'a_add'
;
// show answer form by default
$formtype
=
'a_add'
;
// show answer form by default
}
}
// Get information on the users referenced
// Get information on the users referenced
$usershtml
=
qa_userids_handles_html
(
array_merge
(
array
(
$question
),
$answers
,
$commentsfollows
),
true
);
$usershtml
=
qa_userids_handles_html
(
array_merge
(
array
(
$question
),
$answers
,
$commentsfollows
),
true
);
// Prepare content for theme
// Prepare content for theme
$qa_content
=
qa_content_prepare
(
true
,
array_keys
(
qa_category_path
(
$categories
,
$question
[
'categoryid'
])));
$qa_content
=
qa_content_prepare
(
true
,
array_keys
(
qa_category_path
(
$categories
,
$question
[
'categoryid'
])));
if
(
isset
(
$userid
)
&&
!
$formrequested
)
if
(
isset
(
$userid
)
&&
!
$formrequested
)
$qa_content
[
'favorite'
]
=
qa_favorite_form
(
QA_ENTITY_QUESTION
,
$questionid
,
$favorite
,
$qa_content
[
'favorite'
]
=
qa_favorite_form
(
QA_ENTITY_QUESTION
,
$questionid
,
$favorite
,
qa_lang
(
$favorite
?
'question/remove_q_favorites'
:
'question/add_q_favorites'
));
qa_lang
(
$favorite
?
'question/remove_q_favorites'
:
'question/add_q_favorites'
));
$qa_content
[
'script_rel'
][]
=
'qa-content/qa-question.js?'
.
QA_VERSION
;
$qa_content
[
'script_rel'
][]
=
'qa-content/qa-question.js?'
.
QA_VERSION
;
if
(
isset
(
$pageerror
))
if
(
isset
(
$pageerror
))
$qa_content
[
'error'
]
=
$pageerror
;
// might also show voting error set in qa-index.php
$qa_content
[
'error'
]
=
$pageerror
;
// might also show voting error set in qa-index.php
elseif
(
$question
[
'queued'
])
elseif
(
$question
[
'queued'
])
$qa_content
[
'error'
]
=
$question
[
'isbyuser'
]
?
qa_lang_html
(
'question/q_your_waiting_approval'
)
:
qa_lang_html
(
'question/q_waiting_your_approval'
);
$qa_content
[
'error'
]
=
$question
[
'isbyuser'
]
?
qa_lang_html
(
'question/q_your_waiting_approval'
)
:
qa_lang_html
(
'question/q_waiting_your_approval'
);
if
(
$question
[
'hidden'
])
if
(
$question
[
'hidden'
])
$qa_content
[
'hidden'
]
=
true
;
$qa_content
[
'hidden'
]
=
true
;
qa_sort_by
(
$commentsfollows
,
'created'
);
qa_sort_by
(
$commentsfollows
,
'created'
);
// Prepare content for the question...
// Prepare content for the question...
if
(
$formtype
==
'q_edit'
)
{
// ...in edit mode
if
(
$formtype
==
'q_edit'
)
{
// ...in edit mode
$qa_content
[
'title'
]
=
qa_lang_html
(
$question
[
'editable'
]
?
'question/edit_q_title'
:
$qa_content
[
'title'
]
=
qa_lang_html
(
$question
[
'editable'
]
?
'question/edit_q_title'
:
(
qa_using_categories
()
?
'question/recat_q_title'
:
'question/retag_q_title'
));
(
qa_using_categories
()
?
'question/recat_q_title'
:
'question/retag_q_title'
));
$qa_content
[
'form_q_edit'
]
=
qa_page_q_edit_q_form
(
$qa_content
,
$question
,
@
$qin
,
@
$qerrors
,
$completetags
,
$categories
);
$qa_content
[
'form_q_edit'
]
=
qa_page_q_edit_q_form
(
$qa_content
,
$question
,
@
$qin
,
@
$qerrors
,
$completetags
,
$categories
);
$qa_content
[
'q_view'
][
'raw'
]
=
$question
;
$qa_content
[
'q_view'
][
'raw'
]
=
$question
;
}
else
{
// ...in view mode
}
else
{
// ...in view mode
$qa_content
[
'q_view'
]
=
qa_page_q_question_view
(
$question
,
$parentquestion
,
$closepost
,
$usershtml
,
$formrequested
);
$qa_content
[
'q_view'
]
=
qa_page_q_question_view
(
$question
,
$parentquestion
,
$closepost
,
$usershtml
,
$formrequested
);
$qa_content
[
'title'
]
=
$qa_content
[
'q_view'
][
'title'
];
$qa_content
[
'title'
]
=
$qa_content
[
'q_view'
][
'title'
];
$qa_content
[
'description'
]
=
qa_html
(
qa_shorten_string_line
(
qa_viewer_text
(
$question
[
'content'
],
$question
[
'format'
]),
150
));
$qa_content
[
'description'
]
=
qa_html
(
qa_shorten_string_line
(
qa_viewer_text
(
$question
[
'content'
],
$question
[
'format'
]),
150
));
$categorykeyword
=
@
$categories
[
$question
[
'categoryid'
]][
'title'
];
$categorykeyword
=
@
$categories
[
$question
[
'categoryid'
]][
'title'
];
$qa_content
[
'keywords'
]
=
qa_html
(
implode
(
','
,
array_merge
(
$qa_content
[
'keywords'
]
=
qa_html
(
implode
(
','
,
array_merge
(
(
qa_using_categories
()
&&
strlen
(
$categorykeyword
))
?
array
(
$categorykeyword
)
:
array
(),
(
qa_using_categories
()
&&
strlen
(
$categorykeyword
))
?
array
(
$categorykeyword
)
:
array
(),
qa_tagstring_to_tags
(
$question
[
'tags'
])
qa_tagstring_to_tags
(
$question
[
'tags'
])
)));
// as far as I know, META keywords have zero effect on search rankings or listings, but many people have asked for this
)));
// as far as I know, META keywords have zero effect on search rankings or listings, but many people have asked for this
}
}
$microdata
=
qa_opt
(
'use_microdata'
);
$microdata
=
qa_opt
(
'use_microdata'
);
if
(
$microdata
)
{
if
(
$microdata
)
{
$qa_content
[
'head_lines'
][]
=
'<meta itemprop="name" content="'
.
qa_html
(
$qa_content
[
'q_view'
][
'raw'
][
'title'
])
.
'">'
;
$qa_content
[
'head_lines'
][]
=
'<meta itemprop="name" content="'
.
qa_html
(
$qa_content
[
'q_view'
][
'raw'
][
'title'
])
.
'">'
;
$qa_content
[
'html_tags'
]
=
' itemscope itemtype="http://schema.org/QAPage"'
;
$qa_content
[
'html_tags'
]
=
' itemscope itemtype="http://schema.org/QAPage"'
;
$qa_content
[
'main_tags'
]
=
' itemscope itemtype="http://schema.org/Question"'
;
$qa_content
[
'main_tags'
]
=
' itemscope itemtype="http://schema.org/Question"'
;
}
}
// Prepare content for an answer being edited (if any) or to be added
// Prepare content for an answer being edited (if any) or to be added
if
(
$formtype
==
'a_edit'
)
{
if
(
$formtype
==
'a_edit'
)
{
$qa_content
[
'a_form'
]
=
qa_page_q_edit_a_form
(
$qa_content
,
'a'
.
$formpostid
,
$answers
[
$formpostid
],
$qa_content
[
'a_form'
]
=
qa_page_q_edit_a_form
(
$qa_content
,
'a'
.
$formpostid
,
$answers
[
$formpostid
],
$question
,
$answers
,
$commentsfollows
,
@
$aeditin
[
$formpostid
],
@
$aediterrors
[
$formpostid
]);
$question
,
$answers
,
$commentsfollows
,
@
$aeditin
[
$formpostid
],
@
$aediterrors
[
$formpostid
]);
$qa_content
[
'a_form'
][
'c_list'
]
=
qa_page_q_comment_follow_list
(
$question
,
$answers
[
$formpostid
],
$qa_content
[
'a_form'
][
'c_list'
]
=
qa_page_q_comment_follow_list
(
$question
,
$answers
[
$formpostid
],
$commentsfollows
,
true
,
$usershtml
,
$formrequested
,
$formpostid
);
$commentsfollows
,
true
,
$usershtml
,
$formrequested
,
$formpostid
);
$jumptoanchor
=
'a'
.
$formpostid
;
$jumptoanchor
=
'a'
.
$formpostid
;
}
elseif
((
$formtype
==
'a_add'
)
||
(
$question
[
'answerbutton'
]
&&
!
$formrequested
))
{
}
elseif
((
$formtype
==
'a_add'
)
||
(
$question
[
'answerbutton'
]
&&
!
$formrequested
))
{
$qa_content
[
'a_form'
]
=
qa_page_q_add_a_form
(
$qa_content
,
'anew'
,
$captchareason
,
$question
,
@
$anewin
,
@
$anewerrors
,
$formtype
==
'a_add'
,
$formrequested
);
$qa_content
[
'a_form'
]
=
qa_page_q_add_a_form
(
$qa_content
,
'anew'
,
$captchareason
,
$question
,
@
$anewin
,
@
$anewerrors
,
$formtype
==
'a_add'
,
$formrequested
);
if
(
$formrequested
)
if
(
$formrequested
)
{
$jumptoanchor
=
'anew'
;
$jumptoanchor
=
'anew'
;
elseif
(
$formtype
==
'a_add'
)
}
elseif
(
$formtype
==
'a_add'
)
{
$qa_content
[
'script_onloads'
][]
=
array
(
$qa_content
[
'script_onloads'
][]
=
array
(
"qa_element_revealed=document.getElementById('anew');"
"qa_element_revealed=document.getElementById('anew');"
);
);
}
}
}
// Prepare content for comments on the question, plus add or edit comment forms
// Prepare content for comments on the question, plus add or edit comment forms
if
(
$formtype
==
'q_close'
)
{
if
(
$formtype
==
'q_close'
)
{
$qa_content
[
'q_view'
][
'c_form'
]
=
qa_page_q_close_q_form
(
$qa_content
,
$question
,
'close'
,
@
$closein
,
@
$closeerrors
);
$qa_content
[
'q_view'
][
'c_form'
]
=
qa_page_q_close_q_form
(
$qa_content
,
$question
,
'close'
,
@
$closein
,
@
$closeerrors
);
$jumptoanchor
=
'close'
;
$jumptoanchor
=
'close'
;
}
elseif
(((
$formtype
==
'c_add'
)
&&
(
$formpostid
==
$questionid
))
||
(
$question
[
'commentbutton'
]
&&
!
$formrequested
)
)
{
// ...to be added
}
elseif
(((
$formtype
==
'c_add'
)
&&
(
$formpostid
==
$questionid
))
||
(
$question
[
'commentbutton'
]
&&
!
$formrequested
)
)
{
// ...to be added
$qa_content
[
'q_view'
][
'c_form'
]
=
qa_page_q_add_c_form
(
$qa_content
,
$question
,
$question
,
'c'
.
$questionid
,
$qa_content
[
'q_view'
][
'c_form'
]
=
qa_page_q_add_c_form
(
$qa_content
,
$question
,
$question
,
'c'
.
$questionid
,
$captchareason
,
@
$cnewin
[
$questionid
],
@
$cnewerrors
[
$questionid
],
$formtype
==
'c_add'
);
$captchareason
,
@
$cnewin
[
$questionid
],
@
$cnewerrors
[
$questionid
],
$formtype
==
'c_add'
);
if
((
$formtype
==
'c_add'
)
&&
(
$formpostid
==
$questionid
))
{
if
((
$formtype
==
'c_add'
)
&&
(
$formpostid
==
$questionid
))
{
$jumptoanchor
=
'c'
.
$questionid
;
$jumptoanchor
=
'c'
.
$questionid
;
$commentsall
=
$questionid
;
$commentsall
=
$questionid
;
}
}
}
elseif
((
$formtype
==
'c_edit'
)
&&
(
@
$commentsfollows
[
$formpostid
][
'parentid'
]
==
$questionid
))
{
// ...being edited
}
elseif
((
$formtype
==
'c_edit'
)
&&
(
@
$commentsfollows
[
$formpostid
][
'parentid'
]
==
$questionid
))
{
// ...being edited
$qa_content
[
'q_view'
][
'c_form'
]
=
qa_page_q_edit_c_form
(
$qa_content
,
'c'
.
$formpostid
,
$commentsfollows
[
$formpostid
],
$qa_content
[
'q_view'
][
'c_form'
]
=
qa_page_q_edit_c_form
(
$qa_content
,
'c'
.
$formpostid
,
$commentsfollows
[
$formpostid
],
@
$ceditin
[
$formpostid
],
@
$cediterrors
[
$formpostid
]);
@
$ceditin
[
$formpostid
],
@
$cediterrors
[
$formpostid
]);
$jumptoanchor
=
'c'
.
$formpostid
;
$jumptoanchor
=
'c'
.
$formpostid
;
$commentsall
=
$questionid
;
$commentsall
=
$questionid
;
}
}
$qa_content
[
'q_view'
][
'c_list'
]
=
qa_page_q_comment_follow_list
(
$question
,
$question
,
$commentsfollows
,
$qa_content
[
'q_view'
][
'c_list'
]
=
qa_page_q_comment_follow_list
(
$question
,
$question
,
$commentsfollows
,
$commentsall
==
$questionid
,
$usershtml
,
$formrequested
,
$formpostid
);
// ...for viewing
$commentsall
==
$questionid
,
$usershtml
,
$formrequested
,
$formpostid
);
// ...for viewing
// Prepare content for existing answers (could be added to by Ajax)
// Prepare content for existing answers (could be added to by Ajax)
$qa_content
[
'a_list'
]
=
array
(
$qa_content
[
'a_list'
]
=
array
(
'tags'
=>
'id="a_list"'
,
'tags'
=>
'id="a_list"'
,
'as'
=>
array
(),
'as'
=>
array
(),
);
);
// sort according to the site preferences
// sort according to the site preferences
if
(
qa_opt
(
'sort_answers_by'
)
==
'votes'
)
{
if
(
qa_opt
(
'sort_answers_by'
)
==
'votes'
)
{
foreach
(
$answers
as
$answerid
=>
$answer
)
foreach
(
$answers
as
$answerid
=>
$answer
)
$answers
[
$answerid
][
'sortvotes'
]
=
$answer
[
'downvotes'
]
-
$answer
[
'upvotes'
];
$answers
[
$answerid
][
'sortvotes'
]
=
$answer
[
'downvotes'
]
-
$answer
[
'upvotes'
];
qa_sort_by
(
$answers
,
'sortvotes'
,
'created'
);
qa_sort_by
(
$answers
,
'sortvotes'
,
'created'
);
}
else
}
else
{
qa_sort_by
(
$answers
,
'created'
);
qa_sort_by
(
$answers
,
'created'
);
}
// further changes to ordering to deal with queued, hidden and selected answers
// further changes to ordering to deal with queued, hidden and selected answers
$countfortitle
=
$question
[
'acount'
];
$countfortitle
=
$question
[
'acount'
];
$nextposition
=
10000
;
$nextposition
=
10000
;
$answerposition
=
array
();
$answerposition
=
array
();
foreach
(
$answers
as
$answerid
=>
$answer
)
foreach
(
$answers
as
$answerid
=>
$answer
)
{
if
(
$answer
[
'viewable'
])
{
if
(
$answer
[
'viewable'
])
{
$position
=
$nextposition
++
;
$position
=
$nextposition
++
;
if
(
$answer
[
'hidden'
])
if
(
$answer
[
'hidden'
])
$position
+=
10000
;
$position
+=
10000
;
elseif
(
$answer
[
'queued'
])
{
elseif
(
$answer
[
'queued'
])
{
$position
-=
10000
;
$position
-=
10000
;
$countfortitle
++
;
// include these in displayed count
$countfortitle
++
;
// include these in displayed count
}
elseif
(
$answer
[
'isselected'
]
&&
qa_opt
(
'show_selected_first'
))
}
elseif
(
$answer
[
'isselected'
]
&&
qa_opt
(
'show_selected_first'
))
$position
-=
5000
;
$position
-=
5000
;
$answerposition
[
$answerid
]
=
$position
;
$answerposition
[
$answerid
]
=
$position
;
}
}
}
asort
(
$answerposition
,
SORT_NUMERIC
);
asort
(
$answerposition
,
SORT_NUMERIC
);
// extract IDs and prepare for pagination
// extract IDs and prepare for pagination
$answerids
=
array_keys
(
$answerposition
);
$answerids
=
array_keys
(
$answerposition
);
$countforpages
=
count
(
$answerids
);
$countforpages
=
count
(
$answerids
);
$pagesize
=
qa_opt
(
'page_size_q_as'
);
$pagesize
=
qa_opt
(
'page_size_q_as'
);
// see if we need to display a particular answer
// see if we need to display a particular answer
if
(
isset
(
$showid
))
{
if
(
isset
(
$showid
))
{
if
(
isset
(
$commentsfollows
[
$showid
]))
if
(
isset
(
$commentsfollows
[
$showid
]))
$showid
=
$commentsfollows
[
$showid
][
'parentid'
];
$showid
=
$commentsfollows
[
$showid
][
'parentid'
];
$position
=
array_search
(
$showid
,
$answerids
);
$position
=
array_search
(
$showid
,
$answerids
);
if
(
is_numeric
(
$position
))
if
(
is_numeric
(
$position
))
$pagestart
=
floor
(
$position
/
$pagesize
)
*
$pagesize
;
$pagestart
=
floor
(
$position
/
$pagesize
)
*
$pagesize
;
}
}
// set the canonical url based on possible pagination
// set the canonical url based on possible pagination
$qa_content
[
'canonical'
]
=
qa_path_html
(
qa_q_request
(
$question
[
'postid'
],
$question
[
'title'
]),
$qa_content
[
'canonical'
]
=
qa_path_html
(
qa_q_request
(
$question
[
'postid'
],
$question
[
'title'
]),
(
$pagestart
>
0
)
?
array
(
'start'
=>
$pagestart
)
:
null
,
qa_opt
(
'site_url'
));
(
$pagestart
>
0
)
?
array
(
'start'
=>
$pagestart
)
:
null
,
qa_opt
(
'site_url'
));
// build the actual answer list
// build the actual answer list
$answerids
=
array_slice
(
$answerids
,
$pagestart
,
$pagesize
);
$answerids
=
array_slice
(
$answerids
,
$pagestart
,
$pagesize
);
foreach
(
$answerids
as
$answerid
)
{
foreach
(
$answerids
as
$answerid
)
{
$answer
=
$answers
[
$answerid
];
$answer
=
$answers
[
$answerid
];
if
(
!
((
$formtype
==
'a_edit'
)
&&
(
$formpostid
==
$answerid
)
))
{
if
(
!
(
$formtype
==
'a_edit'
&&
$formpostid
==
$answerid
))
{
$a_view
=
qa_page_q_answer_view
(
$question
,
$answer
,
$answer
[
'isselected'
],
$usershtml
,
$formrequested
);
$a_view
=
qa_page_q_answer_view
(
$question
,
$answer
,
$answer
[
'isselected'
],
$usershtml
,
$formrequested
);
// Prepare content for comments on this answer, plus add or edit comment forms
// Prepare content for comments on this answer, plus add or edit comment forms
if
(((
$formtype
==
'c_add'
)
&&
(
$formpostid
==
$answerid
))
||
(
$answer
[
'commentbutton'
]
&&
!
$formrequested
)
)
{
// ...to be added
if
((
$formtype
==
'c_add'
&&
$formpostid
==
$answerid
)
||
(
$answer
[
'commentbutton'
]
&&
!
$formrequested
)
)
{
// ...to be added
$a_view
[
'c_form'
]
=
qa_page_q_add_c_form
(
$qa_content
,
$question
,
$answer
,
'c'
.
$answerid
,
$a_view
[
'c_form'
]
=
qa_page_q_add_c_form
(
$qa_content
,
$question
,
$answer
,
'c'
.
$answerid
,
$captchareason
,
@
$cnewin
[
$answerid
],
@
$cnewerrors
[
$answerid
],
$formtype
==
'c_add'
);
$captchareason
,
@
$cnewin
[
$answerid
],
@
$cnewerrors
[
$answerid
],
$formtype
==
'c_add'
);
if
((
$formtype
==
'c_add'
)
&&
(
$formpostid
==
$answerid
)
)
{
if
(
$formtype
==
'c_add'
&&
$formpostid
==
$answerid
)
{
$jumptoanchor
=
'c'
.
$answerid
;
$jumptoanchor
=
'c'
.
$answerid
;
$commentsall
=
$answerid
;
$commentsall
=
$answerid
;
}
}
}
elseif
((
$formtype
==
'c_edit'
)
&&
(
@
$commentsfollows
[
$formpostid
][
'parentid'
]
==
$answerid
)
)
{
// ...being edited
}
elseif
(
$formtype
==
'c_edit'
&&
@
$commentsfollows
[
$formpostid
][
'parentid'
]
==
$answerid
)
{
// ...being edited
$a_view
[
'c_form'
]
=
qa_page_q_edit_c_form
(
$qa_content
,
'c'
.
$formpostid
,
$commentsfollows
[
$formpostid
],
$a_view
[
'c_form'
]
=
qa_page_q_edit_c_form
(
$qa_content
,
'c'
.
$formpostid
,
$commentsfollows
[
$formpostid
],
@
$ceditin
[
$formpostid
],
@
$cediterrors
[
$formpostid
]);
@
$ceditin
[
$formpostid
],
@
$cediterrors
[
$formpostid
]);
$jumptoanchor
=
'c'
.
$formpostid
;
$jumptoanchor
=
'c'
.
$formpostid
;
$commentsall
=
$answerid
;
$commentsall
=
$answerid
;
}
}
$a_view
[
'c_list'
]
=
qa_page_q_comment_follow_list
(
$question
,
$answer
,
$commentsfollows
,
$a_view
[
'c_list'
]
=
qa_page_q_comment_follow_list
(
$question
,
$answer
,
$commentsfollows
,
$commentsall
==
$answerid
,
$usershtml
,
$formrequested
,
$formpostid
);
// ...for viewing
$commentsall
==
$answerid
,
$usershtml
,
$formrequested
,
$formpostid
);
// ...for viewing
// Add the answer to the list
// Add the answer to the list
$qa_content
[
'a_list'
][
'as'
][]
=
$a_view
;
$qa_content
[
'a_list'
][
'as'
][]
=
$a_view
;
}
}
}
}
if
(
$question
[
'basetype'
]
==
'Q'
)
{
if
(
$question
[
'basetype'
]
==
'Q'
)
{
$qa_content
[
'a_list'
][
'title_tags'
]
=
'id="a_list_title"'
;
$qa_content
[
'a_list'
][
'title_tags'
]
=
'id="a_list_title"'
;
if
(
$countfortitle
>
0
)
{
if
(
$countfortitle
>
0
)
{
$split
=
$countfortitle
==
1
$split
=
$countfortitle
==
1
?
qa_lang_html_sub_split
(
'question/1_answer_title'
,
'1'
,
'1'
)
?
qa_lang_html_sub_split
(
'question/1_answer_title'
,
'1'
,
'1'
)
:
qa_lang_html_sub_split
(
'question/x_answers_title'
,
$countfortitle
);
:
qa_lang_html_sub_split
(
'question/x_answers_title'
,
$countfortitle
);
if
(
$microdata
)
if
(
$microdata
)
$split
[
'data'
]
=
'<span itemprop="answerCount">'
.
$split
[
'data'
]
.
'</span>'
;
$split
[
'data'
]
=
'<span itemprop="answerCount">'
.
$split
[
'data'
]
.
'</span>'
;
$qa_content
[
'a_list'
][
'title'
]
=
$split
[
'prefix'
]
.
$split
[
'data'
]
.
$split
[
'suffix'
];
$qa_content
[
'a_list'
][
'title'
]
=
$split
[
'prefix'
]
.
$split
[
'data'
]
.
$split
[
'suffix'
];
}
}
else
else
$qa_content
[
'a_list'
][
'title_tags'
]
.=
' style="display:none;" '
;
$qa_content
[
'a_list'
][
'title_tags'
]
.=
' style="display:none;" '
;
}
}
if
(
!
$formrequested
)
if
(
!
$formrequested
)
$qa_content
[
'page_links'
]
=
qa_html_page_links
(
qa_request
(),
$pagestart
,
$pagesize
,
$countforpages
,
qa_opt
(
'pages_prev_next'
),
array
(),
false
,
'a_list_title'
);
$qa_content
[
'page_links'
]
=
qa_html_page_links
(
qa_request
(),
$pagestart
,
$pagesize
,
$countforpages
,
qa_opt
(
'pages_prev_next'
),
array
(),
false
,
'a_list_title'
);
// Some generally useful stuff
// Some generally useful stuff
if
(
qa_using_categories
()
&&
count
(
$categories
))
if
(
qa_using_categories
()
&&
count
(
$categories
))
$qa_content
[
'navigation'
][
'cat'
]
=
qa_category_navigation
(
$categories
,
$question
[
'categoryid'
]);
$qa_content
[
'navigation'
][
'cat'
]
=
qa_category_navigation
(
$categories
,
$question
[
'categoryid'
]);
if
(
isset
(
$jumptoanchor
))
if
(
isset
(
$jumptoanchor
))
$qa_content
[
'script_onloads'
][]
=
array
(
$qa_content
[
'script_onloads'
][]
=
array
(
'qa_scroll_page_to($("#"+'
.
qa_js
(
$jumptoanchor
)
.
').offset().top);'
'qa_scroll_page_to($("#"+'
.
qa_js
(
$jumptoanchor
)
.
').offset().top);'
);
);
// Determine whether this request should be counted for page view statistics.
// Determine whether this request should be counted for page view statistics.
// The lastviewip check is now in the hotness query in order to bypass caching.
// The lastviewip check is now in the hotness query in order to bypass caching.
if
(
if
(
qa_opt
(
'do_count_q_views'
)
&&
qa_opt
(
'do_count_q_views'
)
&&
(
!
$formrequested
)
&&
(
!
$formrequested
)
&&
(
!
qa_is_http_post
())
&&
(
!
qa_is_http_post
())
&&
qa_is_human_probably
()
&&
qa_is_human_probably
()
&&
(
(
!
$question
[
'views'
])
||
(
// if it has more than zero views
(
(
!
$question
[
'views'
])
||
(
// if it has more than zero views
(
(
@
inet_ntop
(
$question
[
'createip'
])
!=
qa_remote_ip_address
())
||
(
!
isset
(
$question
[
'createip'
]))
)
&&
// and different IP from the creator
(
(
@
inet_ntop
(
$question
[
'createip'
])
!=
qa_remote_ip_address
())
||
(
!
isset
(
$question
[
'createip'
]))
)
&&
// and different IP from the creator
(
(
$question
[
'userid'
]
!=
$userid
)
||
(
!
isset
(
$question
[
'userid'
]))
)
&&
// and different user from the creator
(
(
$question
[
'userid'
]
!=
$userid
)
||
(
!
isset
(
$question
[
'userid'
]))
)
&&
// and different user from the creator
(
(
$question
[
'cookieid'
]
!=
$cookieid
)
||
(
!
isset
(
$question
[
'cookieid'
]))
)
// and different cookieid from the creator
(
(
$question
[
'cookieid'
]
!=
$cookieid
)
||
(
!
isset
(
$question
[
'cookieid'
]))
)
// and different cookieid from the creator
)
)
))
)
)
$qa_content
[
'inc_views_postid'
]
=
$questionid
;
$qa_content
[
'inc_views_postid'
]
=
$questionid
;
return
$qa_content
;
return
$qa_content
;
/*
/*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment