diff --git a/application/classes/Ushahidi/Repository/Post.php b/application/classes/Ushahidi/Repository/Post.php index 65e90ef06f..1f25ed7eab 100644 --- a/application/classes/Ushahidi/Repository/Post.php +++ b/application/classes/Ushahidi/Repository/Post.php @@ -171,6 +171,7 @@ public function getSearchFields() 'parent', 'form', 'set', 'q', /* LIKE title, content */ 'created_before', 'created_after', 'updated_before', 'updated_after', + 'date_before', 'date_after', 'bbox', 'tags', 'values', 'current_stage', 'center_point', 'within_km', 'published_to', @@ -305,6 +306,22 @@ protected function setSearchConditions(SearchData $search) $query->where("$table.updated", '<=', $updated_before); } + if ($search->date_after) + { + $date_after = date_create($search->date_after, new DateTimeZone('UTC')); + // Convert to UTC (needed in case date came with a tz) + $date_after->setTimezone(new DateTimeZone('UTC')); + $query->where("$table.post_date", '>=', $date_after->format('Y-m-d H:i:s')); + } + + if ($search->date_before) + { + $date_before = date_create($search->date_before, new DateTimeZone('UTC')); + // Convert to UTC (needed in case date came with a tz) + $date_before->setTimezone(new DateTimeZone('UTC')); + $query->where("$table.post_date", '<=', $date_before->format('Y-m-d H:i:s')); + } + // Bounding box search // Create geometry from bbox (or create bbox from center & radius) $bounding_box = null; @@ -917,7 +934,7 @@ protected function updatePostTags($post_id, $tags) ->where('post_id', '=', $post_id) ->execute($this->db); } - else + else { // Load existing tags $existing = $this->getTagsForPost($post_id); diff --git a/application/classes/Ushahidi/Validator/Media/Update.php b/application/classes/Ushahidi/Validator/Media/Update.php new file mode 100644 index 0000000000..f16ae8a846 --- /dev/null +++ b/application/classes/Ushahidi/Validator/Media/Update.php @@ -0,0 +1,29 @@ + + * @package Ushahidi\Application + * @copyright 2014 Ushahidi + * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) + */ + +use Ushahidi\Core\Entity; +use Ushahidi\Core\Tool\Validator; + +class Ushahidi_Validator_Media_Update extends Ushahidi_Validator_Media_Create +{ + protected function getRules() + { + return [ + 'user_id' => [ + ['digit'], + ], + 'caption' => [ + // alphas, numbers, punctuation, and spaces + ['regex', [':value', '/^[\pL\pN\pP ]++$/uD']], + ] + ]; + } +}