Classes

File phpboost/config/ContentManagementConfig.class.php

File phpboost/config/ContentManagementConfig.class.php

  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 
<?php
/**
 * @package     PHPBoost
 * @subpackage  Config
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Benoit SAUTEL <ben.popeye@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2018 09 21
 * @since       PHPBoost 3.0 - 2010 07 07
 * @contributor Kevin MASSY <reidlos@phpboost.com>
 * @contributor Julien BRISWALTER <j1.seth@phpboost.com>
 * @contributor Arnaud GENET <elenwii@phpboost.com>
 * @contributor mipel <mipel@phpboost.com>
*/

class ContentManagementConfig extends AbstractConfigData
{
    const ANTI_FLOOD_ENABLED               = 'anti_flood';
    const ANTI_FLOOD_DURATION              = 'anti_flood_duration';
    const USED_CAPTCHA_MODULE              = 'used_captcha_module';
    const NEW_CONTENT_ENABLED              = 'new_content';
    const NEW_CONTENT_DURATION             = 'new_content_duration';
    const NEW_CONTENT_UNAUTHORIZED_MODULES = 'new_content_unauthorized_modules';
    const NOTATION_ENABLED                 = 'new_notation';
    const NOTATION_SCALE                   = 'notation_scale';
    const NOTATION_UNAUTHORIZED_MODULES    = 'notation_unauthorized_modules';
    const CONTENT_SHARING_ENABLED          = 'content_sharing_enabled';
    const CONTENT_SHARING_EMAIL_ENABLED    = 'content_sharing_email_enabled';
    const CONTENT_SHARING_PRINT_ENABLED    = 'content_sharing_print_enabled';
    const CONTENT_SHARING_SMS_ENABLED      = 'content_sharing_sms_enabled';
    const OPENGRAPH_ENABLED                = 'opengraph_enabled';
    const SITE_DEFAULT_PICTURE_URL         = 'site_default_picture_url';

    public function is_anti_flood_enabled()
    {
        return $this->get_property(self::ANTI_FLOOD_ENABLED);
    }

    public function set_anti_flood_enabled($enabled)
    {
        $this->set_property(self::ANTI_FLOOD_ENABLED, $enabled);
    }

    public function get_anti_flood_duration()
    {
        return $this->get_property(self::ANTI_FLOOD_DURATION);
    }

    public function set_anti_flood_duration($duration)
    {
        $this->set_property(self::ANTI_FLOOD_DURATION, $duration);
    }

    public function get_used_captcha_module()
    {
        return $this->get_property(self::USED_CAPTCHA_MODULE);
    }

    public function set_used_captcha_module($module)
    {
        $this->set_property(self::USED_CAPTCHA_MODULE, $module);
    }

    public function is_new_content_enabled()
    {
        return $this->get_property(self::NEW_CONTENT_ENABLED);
    }

    public function set_new_content_enabled($enabled)
    {
        $this->set_property(self::NEW_CONTENT_ENABLED, $enabled);
    }

    public function get_new_content_duration()
    {
        return $this->get_property(self::NEW_CONTENT_DURATION);
    }

    public function set_new_content_duration($duration)
    {
        $this->set_property(self::NEW_CONTENT_DURATION, $duration);
    }

    public function get_new_content_unauthorized_modules()
    {
        return $this->get_property(self::NEW_CONTENT_UNAUTHORIZED_MODULES);
    }

    public function set_new_content_unauthorized_modules(array $modules)
    {
        $this->set_property(self::NEW_CONTENT_UNAUTHORIZED_MODULES, $modules);
    }

    public function is_notation_enabled()
    {
        return $this->get_property(self::NOTATION_ENABLED);
    }

    public function set_notation_enabled($enabled)
    {
        $this->set_property(self::NOTATION_ENABLED, $enabled);
    }

    public function get_notation_scale()
    {
        return $this->get_property(self::NOTATION_SCALE);
    }

    public function set_notation_scale($scale)
    {
        $this->set_property(self::NOTATION_SCALE, $scale);
    }

    public function get_notation_unauthorized_modules()
    {
        return $this->get_property(self::NOTATION_UNAUTHORIZED_MODULES);
    }

    public function set_notation_unauthorized_modules(array $modules)
    {
        $this->set_property(self::NOTATION_UNAUTHORIZED_MODULES, $modules);
    }

    public function is_content_sharing_enabled()
    {
        return $this->get_property(self::CONTENT_SHARING_ENABLED);
    }

    public function set_content_sharing_enabled($enabled)
    {
        $this->set_property(self::CONTENT_SHARING_ENABLED, $enabled);
    }

    public function is_content_sharing_email_enabled()
    {
        return $this->get_property(self::CONTENT_SHARING_EMAIL_ENABLED);
    }

    public function set_content_sharing_email_enabled($enabled)
    {
        $this->set_property(self::CONTENT_SHARING_EMAIL_ENABLED, $enabled);
    }

    public function is_content_sharing_print_enabled()
    {
        return $this->get_property(self::CONTENT_SHARING_PRINT_ENABLED);
    }

    public function set_content_sharing_print_enabled($enabled)
    {
        $this->set_property(self::CONTENT_SHARING_PRINT_ENABLED, $enabled);
    }

    public function is_content_sharing_sms_enabled()
    {
        return $this->get_property(self::CONTENT_SHARING_SMS_ENABLED);
    }

    public function set_content_sharing_sms_enabled($enabled)
    {
        $this->set_property(self::CONTENT_SHARING_SMS_ENABLED, $enabled);
    }

    public function is_opengraph_enabled()
    {
        return $this->get_property(self::OPENGRAPH_ENABLED);
    }

    public function set_opengraph_enabled($enabled)
    {
        $this->set_property(self::OPENGRAPH_ENABLED, $enabled);
    }

    public function get_site_default_picture_url()
    {
        return new Url($this->get_property(self::SITE_DEFAULT_PICTURE_URL));
    }

    public function set_site_default_picture_url($url)
    {
        $this->set_property(self::SITE_DEFAULT_PICTURE_URL, $url);
    }

    public function module_new_content_is_enabled($module_id)
    {
        return $this->is_new_content_enabled() && !in_array($module_id, $this->get_new_content_unauthorized_modules());
    }

    public function module_new_content_is_enabled_and_check_date($module_id, $date)
    {
        return $this->module_new_content_is_enabled($module_id) && $this->check_date($date);
    }

    private function check_date($date)
    {
        return (time() - $date) <= $this->get_new_content_duration()*86400;
    }

    public function module_notation_is_enabled($module_id)
    {
        return $this->is_notation_enabled() && !in_array($module_id, $this->get_notation_unauthorized_modules());
    }

    protected function get_default_values()
    {
        return array(
            self::ANTI_FLOOD_ENABLED               => false,
            self::ANTI_FLOOD_DURATION              => 7,
            self::USED_CAPTCHA_MODULE              => 'QuestionCaptcha',
            self::NEW_CONTENT_ENABLED              => true,
            self::NEW_CONTENT_DURATION             => 5,
            self::NEW_CONTENT_UNAUTHORIZED_MODULES => array(),
            self::NOTATION_ENABLED                 => true,
            self::NOTATION_SCALE                   => 5,
            self::NOTATION_UNAUTHORIZED_MODULES    => array(),
            self::CONTENT_SHARING_ENABLED          => true,
            self::CONTENT_SHARING_EMAIL_ENABLED    => true,
            self::CONTENT_SHARING_PRINT_ENABLED    => true,
            self::CONTENT_SHARING_SMS_ENABLED      => true,
            self::OPENGRAPH_ENABLED                => true,
            self::SITE_DEFAULT_PICTURE_URL         => ''
        );
    }

    /**
     * Returns the configuration.
     * @return ContentManagementConfig
     */
    public static function load()
    {
        return ConfigManager::load(__CLASS__, 'kernel', 'content-management');
    }

    /**
     * Saves the configuration in the database. Has it become persistent.
     */
    public static function save()
    {
        ConfigManager::save('kernel', self::load(), 'content-management');
    }
}
?>