Commit 3157101b by Gideon Greenspan

1.6.3-dev-1

parent 24b4af87
1.6.2
\ No newline at end of file
1.6.3-dev-1203
\ No newline at end of file
......@@ -28,6 +28,7 @@ function qa_submit_wall_post(elem, morelink)
params.message=document.forms.wallpost.message.value;
params.handle=document.forms.wallpost.handle.value;
params.start=document.forms.wallpost.start.value;
params.code=document.forms.wallpost.code.value;
params.morelink=morelink ? 1 : 0;
......
......@@ -476,8 +476,7 @@
$publicusername=$logged_in_user['publicusername'];
return '<a href="'.htmlspecialchars($relative_url_prefix.'user/'.urlencode($publicusername)).
'" class="qa-user-link">'.htmlspecialchars($publicusername).'</a>';
return '<a href="'.qa_path_html('user/'.$publicusername).'" class="qa-user-link">'.htmlspecialchars($publicusername).'</a>';
/*
Example 1 - suitable if:
......@@ -547,8 +546,7 @@
$usershtml[$userid]=htmlspecialchars($publicusername);
if ($should_include_link)
$usershtml[$userid]='<a href="'.htmlspecialchars($relative_url_prefix.'user/'.urlencode($publicusername)).
'" class="qa-user-link">'.$usershtml[$userid].'</a>';
$usershtml[$userid]='<a href="'.qa_path_html('user/'.$publicusername).'" class="qa-user-link">'.$usershtml[$userid].'</a>';
}
return $usershtml;
......
......@@ -31,16 +31,15 @@
$tohandle=qa_post_text('handle');
$start=(int)qa_post_text('start');
$usermessages=qa_db_select_with_pending(qa_db_recent_messages_selectspec(null, null, $tohandle, false));
$loginuserid=qa_get_logged_in_userid();
$usermessages=qa_wall_posts_add_rules($usermessages, 0, $loginuserid);
$usermessages=qa_db_select_with_pending(qa_db_recent_messages_selectspec(null, null, $tohandle, false, null, $start));
$usermessages=qa_wall_posts_add_rules($usermessages, $start);
foreach ($usermessages as $message)
if (qa_clicked('m'.$message['messageid'].'_dodelete') && $message['deleteable'])
if (qa_check_form_security_code('wall-'.$tohandle, qa_post_text('code'))) {
qa_wall_delete_post($loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), $message);
qa_wall_delete_post(qa_get_logged_in_userid(), qa_get_logged_in_handle(), qa_cookie_get(), $message);
echo "QA_AJAX_RESPONSE\n1\n";
return;
}
......
......@@ -48,7 +48,7 @@
$touseraccount['wallposts']++; // won't have been updated
$usermessages=qa_db_select_with_pending(qa_db_recent_messages_selectspec(null, null, $touseraccount['userid'], true, qa_opt('page_size_wall')));
$usermessages=qa_wall_posts_add_rules($usermessages, 0, $loginuserid);
$usermessages=qa_wall_posts_add_rules($usermessages, 0);
$themeclass=qa_load_theme_class(qa_get_site_theme(), 'wall', null, null);
......
......@@ -94,6 +94,7 @@
'ko' => 'Korean - 한국어',
'ku-CKB' => 'Kurdish Central - کورد',
'lt' => 'Lithuanian - Lietuvių',
'lv' => 'Latvian - Latviešu',
'nl' => 'Dutch - Nederlands',
'no' => 'Norwegian - Norsk',
'pl' => 'Polish - Polski',
......
......@@ -117,22 +117,28 @@
}
function qa_wall_posts_add_rules($usermessages, $start, $userid)
function qa_wall_posts_add_rules($usermessages, $start)
/*
Return the list of messages in $usermessages (as obtained via qa_db_recent_messages_selectspec()) with additional
fields indicating what actions can be performed on them by user $userid. The messages are retrieved beginning at
offset $start in the database. Currently only 'deleteable' is relevant.
fields indicating what actions can be performed on them by the current user. The messages were retrieved beginning
at offset $start in the database. Currently only 'deleteable' is relevant.
*/
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
$deleteable=($start==0) && isset($userid); // can delete all of the most recent messages...
$userid=qa_get_logged_in_userid();
$userdeleteall=!(qa_user_permit_error('permit_hide_show') || qa_user_permit_error('permit_delete_hidden'));
// reuse "Hiding or showing any post" and "Deleting hidden posts" permissions
$userrecent=($start==0) && isset($userid); // User can delete all of the recent messages they wrote on someone's wall...
foreach ($usermessages as $key => $message) {
if (($message['touserid']!=$userid) && ($message['fromuserid']!=$userid))
$deleteable=false; // ... until we come across one that doesn't involve me
if ($message['fromuserid']!=$userid)
$userrecent=false; // ... until we come across one that they didn't write (which could be a reply)
$usermessages[$key]['deleteable']=$deleteable;
$usermessages[$key]['deleteable'] =
($message['touserid']==$userid) || // if it's this user's wall
($userrecent && ($message['fromuserid']==$userid)) || // if it's one the user wrote that no one replied to yet
$userdeleteall; // if the user has enough permissions to delete from any wall
}
return $usermessages;
......
......@@ -377,19 +377,19 @@
}
function qa_question_set_category($oldquestion, $categoryid, $userid, $handle, $cookieid, $answers, $commentsfollows, $closepost=null)
function qa_question_set_category($oldquestion, $categoryid, $userid, $handle, $cookieid, $answers, $commentsfollows, $closepost=null, $silent=false)
/*
Sets the category (application level) of $oldquestion to $categoryid. Pass details of the user doing this in
$userid, $handle and $cookieid, the database records for all answers to the question in $answers, the database
records for all comments on the question or the question's answers in $commentsfollows ($commentsfollows can also
contain records for follow-on questions which are ignored), and $closepost to match $oldquestion['closedbyid'] (if any).
Handles cached counts and event reports and will reset category IDs and paths for all answers and comments.
See qa-app-posts.php for a higher-level function which is easier to use.
Set $silent to true to not mark the question as edited. Handles cached counts and event reports and will reset category
IDs and paths for all answers and comments. See qa-app-posts.php for a higher-level function which is easier to use.
*/
{
$oldpath=qa_db_post_get_category_path($oldquestion['postid']);
qa_db_post_set_category($oldquestion['postid'], $categoryid, $userid, qa_remote_ip_address());
qa_db_post_set_category($oldquestion['postid'], $categoryid, $silent ? null : $userid, $silent ? null : qa_remote_ip_address());
qa_db_posts_calc_category_path($oldquestion['postid']);
$newpath=qa_db_post_get_category_path($oldquestion['postid']);
......
......@@ -25,8 +25,8 @@
*/
define('QA_VERSION', '1.6.2'); // also used as suffix for .js and .css requests
define('QA_BUILD_DATE', '2013-07-31');
define('QA_VERSION', '1.6.3-dev-1203'); // also used as suffix for .js and .css requests
define('QA_BUILD_DATE', '2013-12-03');
// Execution section of this file - remainder contains function definitions
......
......@@ -41,16 +41,29 @@
function qa_db_table_size()
/*
Return the total size in bytes of all tables in the Q2A database
Return the total size in bytes of all relevant tables in the Q2A database
*/
{
$statuses=qa_db_read_all_assoc(qa_db_query_raw(
"SHOW TABLE STATUS"
));
if (defined('QA_MYSQL_USERS_PREFIX')) { // check if one of the prefixes is a prefix itself of the other
if (stripos(QA_MYSQL_USERS_PREFIX, QA_MYSQL_TABLE_PREFIX)===0)
$prefixes=array(QA_MYSQL_TABLE_PREFIX);
elseif (stripos(QA_MYSQL_TABLE_PREFIX, QA_MYSQL_USERS_PREFIX)===0)
$prefixes=array(QA_MYSQL_USERS_PREFIX);
else
$prefixes=array(QA_MYSQL_TABLE_PREFIX, QA_MYSQL_USERS_PREFIX);
} else
$prefixes=array(QA_MYSQL_TABLE_PREFIX);
$size=0;
foreach ($statuses as $status)
$size+=$status['Data_length']+$status['Index_length'];
foreach ($prefixes as $prefix) {
$statuses=qa_db_read_all_assoc(qa_db_query_raw(
"SHOW TABLE STATUS LIKE '".$prefix."%'"
));
foreach ($statuses as $status)
$size+=$status['Data_length']+$status['Index_length'];
}
return $size;
}
......@@ -178,7 +191,7 @@
*/
{
$results=qa_db_read_all_assoc(qa_db_query_sub(
"SELECT ^users.userid, UNIX_TIMESTAMP(created) AS created, INET_NTOA(createip) AS createip, email, handle, title, content FROM ^users LEFT JOIN ^userprofile ON ^users.userid=^userprofile.userid AND LENGTH(content)>0 WHERE level<# AND NOT (flags&#) ORDER BY created DESC LIMIT #",
"SELECT ^users.userid, UNIX_TIMESTAMP(created) AS created, INET_NTOA(createip) AS createip, email, handle, flags, title, content FROM ^users LEFT JOIN ^userprofile ON ^users.userid=^userprofile.userid AND LENGTH(content)>0 WHERE level<# AND NOT (flags&#) ORDER BY created DESC LIMIT #",
QA_USER_LEVEL_APPROVED, QA_USER_FLAGS_USER_BLOCKED, $count
));
......
......@@ -105,7 +105,7 @@
$sendhandle=isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous'));
$sendcontext=qa_block_words_replace($context, $blockwordspreg);
$sendtext=qa_block_words_replace($params['text'], $blockwordspreg);
$sendurl=qa_q_path($question['postid'], $question['title'], true, $parent['basetype'], $parent['postid']);
$sendurl=qa_q_path($question['postid'], $question['title'], true, 'C', $params['postid']);
if (isset($parent['notify']) && !qa_post_is_by_user($parent, $userid, $cookieid)) {
$senduserid=$parent['userid'];
......
......@@ -124,8 +124,7 @@
{
$publicusername=$logged_in_user['publicusername'];
return '<a href="'.htmlspecialchars($relative_url_prefix.'user/'.urlencode($publicusername)).
'" class="qa-user-link">'.htmlspecialchars($publicusername).'</a>';
return '<a href="'.qa_path_html('user/'.$publicusername).'" class="qa-user-link">'.htmlspecialchars($publicusername).'</a>';
}
......@@ -141,8 +140,7 @@
$usershtml[$userid]=htmlspecialchars($publicusername);
if ($should_include_link)
$usershtml[$userid]='<a href="'.htmlspecialchars($relative_url_prefix.'user/'.urlencode($publicusername)).
'" class="qa-user-link">'.$usershtml[$userid].'</a>';
$usershtml[$userid]='<a href="'.qa_path_html('user/'.$publicusername).'" class="qa-user-link">'.$usershtml[$userid].'</a>';
}
return $usershtml;
......
......@@ -227,6 +227,7 @@
'resume_mailing_button' => 'Resume Mailing',
'save_options_button' => 'Save Options',
'save_recalc_button' => 'Save and Recalculate',
'save_view_button' => 'Save and View',
'send_test_button' => 'Send Test to Me',
'show_defaults_button' => 'Show Defaults',
'show_on_register_form' => 'Show field on user registration form',
......
......@@ -60,11 +60,12 @@
$doconfirms=qa_opt('confirm_user_emails') && ($useraccount['level']<QA_USER_LEVEL_EXPERT);
$isconfirmed=($useraccount['flags'] & QA_USER_FLAGS_EMAIL_CONFIRMED) ? true : false;
$haspassword=isset($useraccount['passsalt']) && isset($useraccount['passcheck']);
$isblocked=qa_user_permit_error() ? true : false;
// Process profile if saved
if (qa_clicked('dosaveprofile')) {
if (qa_clicked('dosaveprofile') && !$isblocked) {
require_once QA_INCLUDE_DIR.'qa-app-users-edit.php';
$inhandle=$changehandle ? qa_post_text('handle') : $useraccount['handle'];
......@@ -135,9 +136,11 @@
}
}
$filtermodules=qa_load_modules_with('filter', 'filter_profile');
foreach ($filtermodules as $filtermodule)
$filtermodule->filter_profile($inprofile, $errors, $useraccount, $userprofile);
if (count($inprofile)) {
$filtermodules=qa_load_modules_with('filter', 'filter_profile');
foreach ($filtermodules as $filtermodule)
$filtermodule->filter_profile($inprofile, $errors, $useraccount, $userprofile);
}
foreach ($userfields as $userfield)
if (!isset($errors[$userfield['fieldid']]))
......@@ -218,6 +221,7 @@
'type' => 'static',
'label' => qa_lang_html('users/member_type'),
'value' => qa_html(qa_user_level_string($useraccount['level'])),
'note' => $isblocked ? qa_lang_html('users/user_blocked') : null,
),
'handle' => array(
......@@ -225,7 +229,7 @@
'tags' => 'name="handle"',
'value' => qa_html(isset($inhandle) ? $inhandle : $useraccount['handle']),
'error' => qa_html(@$errors['handle']),
'type' => $changehandle ? 'text' : 'static',
'type' => ($changehandle && !$isblocked) ? 'text' : 'static',
),
'email' => array(
......@@ -234,6 +238,7 @@
'value' => qa_html(isset($inemail) ? $inemail : $useraccount['email']),
'error' => isset($errors['email']) ? qa_html($errors['email']) :
(($doconfirms && !$isconfirmed) ? qa_insert_login_links(qa_lang_html('users/email_please_confirm')) : null),
'type' => $isblocked ? 'static' : 'text',
),
'messages' => array(
......@@ -288,6 +293,10 @@
if (!qa_opt('mailing_enabled'))
unset($qa_content['form_profile']['fields']['mailings']);
if ($isblocked) {
unset($qa_content['form_profile']['buttons']['save']);
$qa_content['error']=qa_lang_html('users/no_permission');
}
// Avatar upload stuff
......@@ -356,6 +365,7 @@
'value' => qa_html($value),
'error' => qa_html(@$errors[$userfield['fieldid']]),
'rows' => ($userfield['flags'] & QA_FIELD_FLAGS_MULTI_LINE) ? 8 : null,
'type' => $isblocked ? 'static' : 'text',
);
}
......
......@@ -97,6 +97,9 @@
$message['content'].=qa_lang_html('users/email_label').' <a href="mailto:'.$htmlemail.'">'.$htmlemail.'</a>';
if (qa_opt('confirm_user_emails'))
$message['content'].='<small> - '.qa_lang_html(($user['flags'] & QA_USER_FLAGS_EMAIL_CONFIRMED) ? 'users/email_confirmed' : 'users/email_not_confirmed').'</small>';
foreach ($userfields as $userfield)
if (strlen(@$user['profile'][$userfield['title']]))
$message['content'].='<br/>'.qa_html($userfield['content'].': '.$user['profile'][$userfield['title']]);
......
......@@ -270,6 +270,9 @@
$reloadpages=true;
}
}
if (qa_clicked('dosaveview') && empty($errors) && !$isexternal)
qa_redirect($inslug);
}
if ($reloadpages) {
......@@ -417,6 +420,11 @@
'label' => qa_lang_html(isset($editpage['pageid']) ? 'main/save_button' : ($isexternal ? 'admin/add_link_button' : 'admin/add_page_button')),
),
'saveview' => array(
'tags' => 'name="dosaveview"',
'label' => qa_lang_html('admin/save_view_button'),
),
'cancel' => array(
'tags' => 'name="docancel"',
'label' => qa_lang_html('main/cancel_button'),
......@@ -455,6 +463,9 @@
unset($qa_content['form']['fields']['delete']);
}
if ($isexternal || !isset($editpage['pageid']))
unset($qa_content['form']['buttons']['saveview']);
$qa_content['focusid']='name';
} else {
......
......@@ -145,7 +145,7 @@
$cookieid=isset($userid) ? qa_cookie_get() : qa_cookie_get_create(); // create a new cookie if necessary
$questionid=qa_question_create($followanswer, $userid, qa_get_logged_in_handle(), $cookieid,
$in['title'], $in['content'], $in['format'], $in['text'], qa_tags_to_tagstring($in['tags']),
$in['title'], $in['content'], $in['format'], $in['text'], isset($in['tags']) ? qa_tags_to_tagstring($in['tags']) : '',
$in['notify'], $in['email'], $in['categoryid'], $in['extra'], $in['queued'], $in['name']);
qa_redirect(qa_q_request($questionid, $in['title'])); // our work is done here
......
......@@ -72,8 +72,8 @@
$nonetitle, // title if no questions
QA_ALLOW_UNINDEXED_QUERIES ? $categories : null, // categories for navigation
$categoryid, // selected category id
true, // show question counts in category navigation (null since not relevant)
QA_ALLOW_UNINDEXED_QUERIES ? 'hot/' : null, // prefix for links in category navigation (null since no navigation)
true, // show question counts in category navigation
QA_ALLOW_UNINDEXED_QUERIES ? 'hot/' : null, // prefix for links in category navigation (null if no navigation)
qa_opt('feed_for_hot') ? 'hot' : null, // prefix for RSS feed paths (null to hide)
qa_html_suggest_ask() // suggest what to do next
);
......
......@@ -511,7 +511,8 @@
$setnotify, $userid, $handle, $cookieid, $in['extra'], @$in['name'], $in['queued'], $in['silent']);
if (qa_using_categories() && strcmp($in['categoryid'], $question['categoryid']))
qa_question_set_category($question, $in['categoryid'], $userid, $handle, $cookieid, $answers, $commentsfollows, $closepost);
qa_question_set_category($question, $in['categoryid'], $userid, $handle, $cookieid,
$answers, $commentsfollows, $closepost, $in['silent']);
return true;
}
......
......@@ -71,7 +71,7 @@
foreach ($filtermodules as $filtermodule) {
$tempin=$in; // always pass original question in because we aren't modifying anything else
$filtermodule->filter_question($tempin, $temperrors, $question);
$in['queued']=$tempin; // only preserve queued status in loop
$in['queued']=$tempin['queued']; // only preserve queued status in loop
}
$status=$in['queued'] ? QA_POST_STATUS_QUEUED : QA_POST_STATUS_NORMAL;
......@@ -161,7 +161,7 @@
foreach ($filtermodules as $filtermodule) {
$tempin=$in; // always pass original answer in because we aren't modifying anything else
$filtermodule->filter_answer($tempin, $temperrors, $question, $answer);
$in['queued']=$tempin; // only preserve queued status in loop
$in['queued']=$tempin['queued']; // only preserve queued status in loop
}
$status=$in['queued'] ? QA_POST_STATUS_QUEUED : QA_POST_STATUS_NORMAL;
......@@ -246,7 +246,7 @@
foreach ($filtermodules as $filtermodule) {
$tempin=$in; // always pass original comment in because we aren't modifying anything else
$filtermodule->filter_comment($tempin, $temperrors, $question, $parent, $comment);
$in['queued']=$tempin; // only preserve queued status in loop
$in['queued']=$tempin['queued']; // only preserve queued status in loop
}
$status=$in['queued'] ? QA_POST_STATUS_QUEUED : QA_POST_STATUS_NORMAL;
......
......@@ -93,9 +93,11 @@
qa_password_validate($inpassword)
);
$filtermodules=qa_load_modules_with('filter', 'filter_profile');
foreach ($filtermodules as $filtermodule)
$filtermodule->filter_profile($inprofile, $errors, null, null);
if (count($inprofile)) {
$filtermodules=qa_load_modules_with('filter', 'filter_profile');
foreach ($filtermodules as $filtermodule)
$filtermodule->filter_profile($inprofile, $errors, null, null);
}
if (qa_opt('captcha_on_register'))
qa_captcha_validate_post($errors);
......
......@@ -106,12 +106,6 @@
$qdefaults['voteview']=false;
$qdefaults['answersview']=false;
$qdefaults['viewsview']=false;
$fakeoptions=$qdefaults;
$fakeoptions['whoview']=false;
$fakeoptions['whenview']=false;
$fakeoptions['whatview']=false;
break;
}
......@@ -129,6 +123,9 @@
else
continue; // nothing to show here
if (isset($qdefaults['blockwordspreg']))
$result['title']=qa_block_words_replace($result['title'], $qdefaults['blockwordspreg']);
$fields['title']=qa_html($result['title']);
$fields['url']=qa_html($result['url']);
......
......@@ -127,10 +127,10 @@
@$count, // total count
$sometitle, // title if some questions
$nonetitle, // title if no questions
QA_ALLOW_UNINDEXED_QUERIES ? $categories : null, // categories for navigation (null since not shown on this page)
QA_ALLOW_UNINDEXED_QUERIES ? $categoryid : null, // selected category id (null since not relevant)
false, // show question counts in category navigation (null since not relevant)
'unanswered/', // prefix for links in category navigation (null since no navigation)
QA_ALLOW_UNINDEXED_QUERIES ? $categories : null, // categories for navigation (null if not shown on this page)
QA_ALLOW_UNINDEXED_QUERIES ? $categoryid : null, // selected category id (null if not relevant)
false, // show question counts in category navigation
QA_ALLOW_UNINDEXED_QUERIES ? 'unanswered/' : null, // prefix for links in category navigation (null if no navigation)
$feedpathprefix, // prefix for RSS feed paths (null to hide)
qa_html_suggest_qs_tags(qa_using_tags()), // suggest what to do next
$linkparams, // extra parameters for page links
......
......@@ -115,7 +115,7 @@
// This code is similar but not identical to that in to qq-page-user-wall.php
$usermessages=array_slice($usermessages, 0, qa_opt('page_size_wall'));
$usermessages=qa_wall_posts_add_rules($usermessages, 0, $loginuserid);
$usermessages=qa_wall_posts_add_rules($usermessages, 0);
foreach ($usermessages as $message)
if ($message['deleteable'] && qa_clicked('m'.$message['messageid'].'_dodelete')) {
......@@ -181,10 +181,12 @@
qa_db_user_set($userid, 'email', $inemail);
qa_db_user_set_flag($userid, QA_USER_FLAGS_EMAIL_CONFIRMED, false);
}
$filtermodules=qa_load_modules_with('filter', 'filter_profile');
foreach ($filtermodules as $filtermodule)
$filtermodule->filter_profile($inprofile, $errors, $useraccount, $userprofile);
if (count($inprofile)) {
$filtermodules=qa_load_modules_with('filter', 'filter_profile');
foreach ($filtermodules as $filtermodule)
$filtermodule->filter_profile($inprofile, $errors, $useraccount, $userprofile);
}
foreach ($userfields as $userfield)
if (!isset($errors[$userfield['fieldid']]))
......@@ -892,6 +894,9 @@
'style' => 'tall',
'hidden' => array(
'qa_click' => '', // for simulating clicks in Javascript
'handle' => qa_html($useraccount['handle']),
'start' => 0,
'code' => qa_get_form_security_code('wall-'.$useraccount['handle']),
),
),
......@@ -917,9 +922,6 @@
'label' => qa_lang_html('profile/post_wall_button'),
),
);
$qa_content['message_list']['form']['hidden']['handle']=qa_html($useraccount['handle']);
$qa_content['message_list']['form']['hidden']['code']=qa_get_form_security_code('wall-'.$useraccount['handle']);
}
foreach ($usermessages as $message)
......
......@@ -62,7 +62,7 @@
$loginuserid=qa_get_logged_in_userid();
$usermessages=array_slice($usermessages, 0, $pagesize);
$usermessages=qa_wall_posts_add_rules($usermessages, $start, $loginuserid);
$usermessages=qa_wall_posts_add_rules($usermessages, $start);
// Process deleting or adding a wall post (similar but not identical code to qq-page-user-profile.php)
......@@ -78,7 +78,7 @@
else {
qa_wall_delete_post($loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), $message);
qa_redirect(qa_request());
qa_redirect(qa_request(), $_GET);
}
}
......@@ -115,6 +115,9 @@
'style' => 'tall',
'hidden' => array(
'qa_click' => '', // for simulating clicks in Javascript
'handle' => qa_html($useraccount['handle']),
'start' => qa_html($start),
'code' => qa_get_form_security_code('wall-'.$useraccount['handle']),
),
),
......@@ -141,9 +144,6 @@
'label' => qa_lang_html('profile/post_wall_button'),
),
);
$qa_content['message_list']['form']['hidden']['handle']=qa_html($useraccount['handle']);
$qa_content['message_list']['form']['hidden']['code']=qa_get_form_security_code('wall-'.$useraccount['handle']);
}
}
......
......@@ -1016,6 +1016,8 @@
{
$this->form_prefix($field, $style);
$this->output_raw(@$field['html_prefix']);
switch (@$field['type']) {
case 'checkbox':
$this->form_checkbox($field, $style);
......@@ -1044,9 +1046,9 @@
case 'image':
$this->form_image($field, $style);
break;
case 'custom':
echo @$field['html'];
$this->output_raw(@$field['html']);
break;
default:
......@@ -1057,6 +1059,8 @@
break;
}
$this->output_raw(@$field['html_suffix']);
$this->form_suffix($field, $style);
}
......
......@@ -159,57 +159,75 @@
);
}
if ($format=='html')
if ($format=='html') {
$html=$content;
else
$text=$this->html_to_text($content);
} else {
$text=$content;
$html=qa_html($content, true);
}
return array(
'tags' => 'name="'.$fieldname.'"',
'value' => qa_html($html),
'value' => qa_html($text),
'rows' => $rows,
'html_prefix' => '<input name="'.$fieldname.'_ckeditor_ok" id="'.$fieldname.'_ckeditor_ok" type="hidden" value="0"><input name="'.$fieldname.'_ckeditor_data" id="'.$fieldname.'_ckeditor_data" type="hidden" value="'.qa_html($html).'">',
);
}
function load_script($fieldname)
{
return "qa_ckeditor_".$fieldname."=CKEDITOR.replace(".qa_js($fieldname).", window.qa_wysiwyg_editor_config);";
return "if (qa_ckeditor_".$fieldname."=CKEDITOR.replace(".qa_js($fieldname).", window.qa_wysiwyg_editor_config)) { qa_ckeditor_".$fieldname.".setData(document.getElementById(".qa_js($fieldname.'_ckeditor_data').").value); document.getElementById(".qa_js($fieldname.'_ckeditor_ok').").value=1; }";
}
function focus_script($fieldname)
{
return "qa_ckeditor_".$fieldname.".focus();";
return "if (qa_ckeditor_".$fieldname.") qa_ckeditor_".$fieldname.".focus();";
}
function update_script($fieldname)
{
return "qa_ckeditor_".$fieldname.".updateElement();";
return "if (qa_ckeditor_".$fieldname.") qa_ckeditor_".$fieldname.".updateElement();";
}
function read_post($fieldname)
{
$html=qa_post_text($fieldname);
if (qa_post_text($fieldname.'_ckeditor_ok')) { // CKEditor was loaded successfully
$html=qa_post_text($fieldname);
$htmlformatting=preg_replace('/<\s*\/?\s*(br|p)\s*\/?\s*>/i', '', $html); // remove <p>, <br>, etc... since those are OK in text
$htmlformatting=preg_replace('/<\s*\/?\s*(br|p)\s*\/?\s*>/i', '', $html); // remove <p>, <br>, etc... since those are OK in text
if (preg_match('/<.+>/', $htmlformatting)) // if still some other tags, it's worth keeping in HTML
return array(
'format' => 'html',
'content' => qa_sanitize_html($html, false, true), // qa_sanitize_html() is ESSENTIAL for security
);
if (preg_match('/<.+>/', $htmlformatting)) // if still some other tags, it's worth keeping in HTML
return array(
'format' => 'html',
'content' => qa_sanitize_html($html, false, true), // qa_sanitize_html() is ESSENTIAL for security
);
else { // convert to text
$viewer=qa_load_module('viewer', '');
else { // convert to text
$viewer=qa_load_module('viewer', '');
return array(
'format' => '',
'content' => $this->html_to_text($html),
);
}
} else // CKEditor was not loaded so treat it as plain text
return array(
'format' => '',
'content' => $viewer->get_text($html, 'html', array())
'content' => qa_post_text($fieldname),
);
}
}
function html_to_text($html)
{
$viewer=qa_load_module('viewer', '');
return $viewer->get_text($html, 'html', array());
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment