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
ea166e4b
Commit
ea166e4b
authored
Aug 07, 2015
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix missing title errors when recategorizing questions
parent
41faf774
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
13 deletions
+52
-13
qa-filter-basic.php
qa-include/plugins/qa-filter-basic.php
+52
-13
No files found.
qa-include/plugins/qa-filter-basic.php
View file @
ea166e4b
...
...
@@ -51,23 +51,38 @@ class qa_filter_basic
public
function
filter_question
(
&
$question
,
&
$errors
,
$oldquestion
)
{
$this
->
validate_length
(
$errors
,
'title'
,
@
$question
[
'title'
],
qa_opt
(
'min_len_q_title'
),
max
(
qa_opt
(
'min_len_q_title'
),
min
(
qa_opt
(
'max_len_q_title'
),
QA_DB_MAX_TITLE_LENGTH
)));
if
(
$oldquestion
===
null
)
{
// a new post requires these fields be set
$question
[
'title'
]
=
isset
(
$question
[
'title'
])
?
$question
[
'title'
]
:
''
;
$question
[
'content'
]
=
isset
(
$question
[
'content'
])
?
$question
[
'content'
]
:
''
;
$question
[
'text'
]
=
isset
(
$question
[
'text'
])
?
$question
[
'text'
]
:
''
;
$question
[
'tags'
]
=
isset
(
$question
[
'tags'
])
?
$question
[
'tags'
]
:
array
();
}
$this
->
validate_length
(
$errors
,
'content'
,
@
$question
[
'content'
],
0
,
QA_DB_MAX_CONTENT_LENGTH
);
// for storage
$qminlength
=
qa_opt
(
'min_len_q_title'
);
$qmaxlength
=
max
(
$qminlength
,
min
(
qa_opt
(
'max_len_q_title'
),
QA_DB_MAX_TITLE_LENGTH
));
$this
->
validate_field_length
(
$errors
,
$question
,
'title'
,
$qminlength
,
$qmaxlength
);
$this
->
validate_length
(
$errors
,
'content'
,
@
$question
[
'text'
],
qa_opt
(
'min_len_q_content'
),
null
);
// for display
$this
->
validate_field_length
(
$errors
,
$question
,
'content'
,
0
,
QA_DB_MAX_CONTENT_LENGTH
);
// for storage
$this
->
validate_field_length
(
$errors
,
$question
,
'text'
,
qa_opt
(
'min_len_q_content'
),
null
);
// for display
if
(
isset
(
$question
[
'tags'
]))
{
$counttags
=
count
(
$question
[
'tags'
]);
$mintags
=
min
(
qa_opt
(
'min_num_q_tags'
),
qa_opt
(
'max_num_q_tags'
));
if
(
$counttags
<
$mintags
)
$errors
[
'tags'
]
=
qa_lang_sub
(
'question/min_tags_x'
,
$mintags
);
elseif
(
$counttags
>
qa_opt
(
'max_num_q_tags'
))
$errors
[
'tags'
]
=
qa_lang_sub
(
'question/max_tags_x'
,
qa_opt
(
'max_num_q_tags'
));
else
$this
->
validate_length
(
$errors
,
'tags'
,
qa_tags_to_tagstring
(
$question
[
'tags'
]),
0
,
QA_DB_MAX_TAGS_LENGTH
);
// for storage
$counttags
=
count
(
$question
[
'tags'
]);
$maxtags
=
qa_opt
(
'max_num_q_tags'
);
$mintags
=
min
(
qa_opt
(
'min_num_q_tags'
),
$maxtags
);
if
(
$counttags
<
$mintags
)
{
$errors
[
'tags'
]
=
qa_lang_sub
(
'question/min_tags_x'
,
$mintags
);
}
elseif
(
$counttags
>
$maxtags
)
{
$errors
[
'tags'
]
=
qa_lang_sub
(
'question/max_tags_x'
,
$maxtags
);
}
else
{
$tagstring
=
qa_tags_to_tagstring
(
$question
[
'tags'
]);
if
(
qa_strlen
(
$tagstring
)
>
QA_DB_MAX_TAGS_LENGTH
)
{
// for storage
$errors
[
'tags'
]
=
qa_lang_sub
(
'main/max_length_x'
,
$maxlength
);
}
}
}
$this
->
validate_post_email
(
$errors
,
$question
);
...
...
@@ -113,6 +128,30 @@ class qa_filter_basic
}
/**
* Check that a field meets the length requirements. If we're editing the post we can ignore missing fields.
*
* @param array $errors Array of errors, with keys matching $post
* @param array $post The post containing the field we want to validate
* @param string $key The element of $post to validate
* @param int $minlength
* @param int $maxlength
*/
private
function
validate_field_length
(
&
$errors
,
&
$post
,
$key
,
$minlength
,
$maxlength
)
{
// skip the field is key not set (for example, 'title' when recategorizing questions)
if
(
array_key_exists
(
$key
,
$post
))
{
$length
=
qa_strlen
(
$post
[
$key
]);
if
(
$length
<
$minlength
)
{
$errors
[
$key
]
=
$minlength
==
1
?
qa_lang
(
'main/field_required'
)
:
qa_lang_sub
(
'main/min_length_x'
,
$minlength
);
}
else
if
(
isset
(
$maxlength
)
&&
(
$length
>
$maxlength
))
{
$errors
[
$key
]
=
qa_lang_sub
(
'main/max_length_x'
,
$maxlength
);
}
}
}
/**
* Wrapper function for validating a post's email address.
*
* @deprecated This function will become private in Q2A 1.8. It is specific to this plugin and
...
...
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