/** * Validation rules when editing a comment in backend. * * @param \Cake\Validation\Validator $validator The validator object * @return \Cake\Validation\Validator */ public function validationAnonymous(Validator $validator) { $settings = Plugin::get('Comment')->settings; $validator = $this->validationDefault($validator); if ($settings['allow_anonymous']) { if ($settings['anonymous_name']) { $validator->requirePresence('author_name')->add('author_name', 'nameLength', ['rule' => ['minLength', 3], 'message' => __d('comment', 'Your name need to be at least 3 characters long.')]); if ($settings['anonymous_name_required']) { $validator->notEmpty('author_name', __d('comment', 'You must provide your name.')); } else { $validator->allowEmpty('author_name'); } } if ($settings['anonymous_email']) { $validator->requirePresence('author_email')->add('author_email', 'validEmail', ['rule' => 'email', 'message' => __d('comment', 'e-Mail must be valid.')]); if ($settings['anonymous_email_required']) { $validator->notEmpty('author_email', __d('comment', 'You must provide an email.')); } else { $validator->allowEmpty('anonymous_email'); } } if ($settings['anonymous_web']) { $validator->requirePresence('author_web')->add('author_web', 'validURL', ['rule' => 'url', 'message' => __d('comment', 'Website must be a valid URL.')]); if ($settings['anonymous_web_required']) { $validator->notEmpty('author_web', __d('comment', 'You must provide a website URL.')); } else { $validator->allowEmpty('author_web'); } } } return $validator; }
/** * Gets a collection list of plugin that depends on this plugin. * * @return \Cake\Collection\Collection List of plugins */ public function requiredBy() { if ($cache = $this->config('required_by')) { return collection($cache); } Plugin::dropCache(); $out = []; $plugins = Plugin::get()->filter(function ($v, $k) { return $v->name() !== $this->name(); }); foreach ($plugins as $plugin) { if ($dependencies = $plugin->dependencies($plugin->name)) { $packages = array_map(function ($item) { list(, $package) = packageSplit($item, true); return strtolower($package); }, array_keys($dependencies)); if (in_array(strtolower($this->name()), $packages)) { $out[] = $plugin; } } } $this->config('required_by', $out); return collection($out); }
/** * Gets the given (or in use) theme as a package object. * * ### Example: * * ```php * // current theme * $bgColor = theme()->settings['background_color']; * * // specific theme * $bgColor = theme('BlueTheme')->settings['background_color']; * ``` * * @param string|null $name Name of the theme to get, or null to get the theme * being used in current request * @return \CMS\Core\Package\PluginPackage * @throws \Cake\Error\FatalErrorException When theme could not be found */ function theme($name = null) { if ($name === null) { $option = Router::getRequest()->isAdmin() ? 'back_theme' : 'front_theme'; $name = option($option); } $theme = Plugin::get()->filter(function ($plugin) use($name) { return $plugin->isTheme && $plugin->name == $name; })->first(); if ($theme) { return $theme; } throw new FatalErrorException(__d('cms', 'Theme "{0}" was not found', $name)); }