diff --git a/src/config/bootstrap.php b/src/config/bootstrap.php index c00b954..906adf0 100644 --- a/src/config/bootstrap.php +++ b/src/config/bootstrap.php @@ -41,6 +41,7 @@ require_once __DIR__ . '/../library/scrapeer.php'; require_once __DIR__ . '/../library/time.php'; require_once __DIR__ . '/../library/curl.php'; require_once __DIR__ . '/../library/valid.php'; +require_once __DIR__ . '/../library/filter.php'; // Vendors autoload require_once __DIR__ . '/../../vendor/autoload.php'; diff --git a/src/library/filter.php b/src/library/filter.php new file mode 100644 index 0000000..72d9e28 --- /dev/null +++ b/src/library/filter.php @@ -0,0 +1,48 @@ +updateMagnetApproved($magnet->magnetId, (bool) $user->approved, time()); } - // Meta - if (MAGNET_TITLE_MIN_LENGTH <= mb_strlen($_POST['title']) && MAGNET_TITLE_MAX_LENGTH >= mb_strlen($_POST['title'])) + // Social + $db->updateMagnetComments($magnet->magnetId, isset($_POST['comments']) ? true : false, time()); + $db->updateMagnetSensitive($magnet->magnetId, isset($_POST['sensitive']) ? true : false, time()); + + if (isset($_POST['public'])) // could be enabled once only because of distributed database model #1 { - $db->updateMagnetTitle($magnet->magnetId, trim(strip_tags(html_entity_decode($_POST['title']))), time()); + $db->updateMagnetPublic($magnet->magnetId, true, time()); + } + + // Title + $response->form->title->valid->success = true; + $response->form->title->valid->message = []; - $response->form->title->valid->success = true; - $response->form->title->valid->message = false; + if (!Valid::magnetTitle($_POST['title'], $response->form->title->valid->message)) + { + $response->form->title->valid->success = false; } + else { - $response->form->title->valid->success = false; - $response->form->title->valid->message = sprintf(_('* required, %s-%s chars'), MAGNET_TITLE_MIN_LENGTH, MAGNET_TITLE_MAX_LENGTH); + $db->updateMagnetTitle( + $magnet->magnetId, + Filter::magnetTitle($_POST['title']), + time() + ); } - if (mb_strlen($_POST['preview']) < MAGNET_PREVIEW_MIN_LENGTH || mb_strlen($_POST['preview']) > MAGNET_PREVIEW_MAX_LENGTH) + // Preview + $response->form->preview->valid->success = true; + $response->form->preview->valid->message = []; + + if (!Valid::magnetPreview($_POST['preview'], $response->form->preview->valid->message)) { $response->form->preview->valid->success = false; - $response->form->preview->valid->message = sprintf(_('* required, %s-%s chars, %s provided'), MAGNET_PREVIEW_MIN_LENGTH, MAGNET_PREVIEW_MAX_LENGTH, mb_strlen($_POST['preview'])); } + else { - $db->updateMagnetPreview($magnet->magnetId, trim(strip_tags(html_entity_decode($_POST['preview']))), time()); + $db->updateMagnetPreview( + $magnet->magnetId, + Filter::magnetPreview($_POST['preview']), + time() + ); } - if (mb_strlen($_POST['description']) < MAGNET_DESCRIPTION_MIN_LENGTH || mb_strlen($_POST['description']) > MAGNET_DESCRIPTION_MAX_LENGTH) + // Description + $response->form->description->valid->success = true; + $response->form->description->valid->message = []; + + if (!Valid::magnetDescription($_POST['description'], $response->form->description->valid->message)) { $response->form->description->valid->success = false; - $response->form->description->valid->message = sprintf(_('* required, %s-%s chars, %s provided'), MAGNET_DESCRIPTION_MIN_LENGTH, MAGNET_DESCRIPTION_MAX_LENGTH, mb_strlen($_POST['description'])); } + else { - $db->updateMagnetDescription($magnet->magnetId, trim(strip_tags(html_entity_decode($_POST['description']))), time()); + $db->updateMagnetDescription( + $magnet->magnetId, + Filter::magnetDescription($_POST['description']), + time() + ); } - // Social - $db->updateMagnetComments($magnet->magnetId, isset($_POST['comments']) ? true : false, time()); - $db->updateMagnetSensitive($magnet->magnetId, isset($_POST['sensitive']) ? true : false, time()); + // Display Name + $response->form->dn->valid->success = true; + $response->form->dn->valid->message = []; - if (isset($_POST['public'])) // could be enabled once only because of distributed database model #1 + if (!Valid::magnetDn($_POST['dn'], $response->form->dn->valid->message)) { - $db->updateMagnetPublic($magnet->magnetId, true, time()); + $response->form->dn->valid->success = false; } - // Display Name - if (isset($_POST['dn'])) + else { - $db->updateMagnetDn($magnet->magnetId, trim(strip_tags(html_entity_decode($_POST['dn']))), time()); + $db->updateMagnetDn( + $magnet->magnetId, + Filter::magnetDn($_POST['dn']), + time() + ); } // Exact Topic @@ -469,6 +501,7 @@ else { $response->form->title->valid->success && $response->form->preview->valid->success && $response->form->description->valid->success && + $response->form->dn->valid->success && $response->form->tr->valid->success && $response->form->as->valid->success && $response->form->xs->valid->success) @@ -643,7 +676,7 @@ else { form->title->valid->message) { ?> -