Completed
Branch master (6c262f)
by Pierre-Henry
111:59 queued 51:18
created

app/system/core/classes/ValidateSiteCore.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * @author         Pierre-Henry Soria <[email protected]>
4
 * @copyright      (c) 2015-2017, Pierre-Henry Soria. All Rights Reserved.
5
 * @license        GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory.
6
 * @package        PH7 / App / System / Core / Class
7
 */
8
namespace PH7;
9
10
use
0 ignored issues
show
There must be a single space after the USE keyword
Loading history...
11
PH7\Framework\Url\Header,
12
PH7\Framework\Mvc\Router\Uri,
13
PH7\Framework\Date\Various as VDate;
14
15
class ValidateSiteCore
16
{
17
    const SESS_IS_VISITED = 'validatesitebox_visited';
18
19
    /**
20
     * Check if the JS validationbox has to be added and redirect if the site hasn't been validated yet for a while.
21
     *
22
     * @param object \PH7\Framework\Session\Session $oSess
23
     * @return boolean
24
     */
25
    public static function needInject(Framework\Session\Session $oSess)
26
    {
27
        $oVSModel = new ValidateSiteCoreModel;
28
        $iSinceSiteCreated = VDate::getTime(StatisticCoreModel::getDateOfCreation());
29
30
        // After over 2 months, the site is still not validated, maybe the validation box doesn't really work, so we redirected to the page form
31
        if (!$oVSModel->is() && VDate::setTime('-2 months') >= $iSinceSiteCreated && !$oSess->exists(self::SESS_IS_VISITED)) {
32
            Header::redirect(Uri::get('validate-site', 'main', 'validationbox'));
33
        }
34
35
        if (!$oVSModel->is() && VDate::setTime('-2 days') >= $iSinceSiteCreated) {
36
            // OK for adding the validation colorbox
37
            return true;
38
        }
39
        return false;
40
    }
41
}
42