public function __construct($data = array()) { if (!isset($data['id'])) { throw new Exception('The role id is missing'); } if (!isset($data['name'])) { throw new Exception('The role name is missing'); } // required data $this->id = $data['id']; $this->name = $data['name']; if (isset($data['permissions']) and is_array($data['permissions'])) { $this->permissions = a::merge($this->permissions, $data['permissions']); } else { if (isset($data['permissions']) and $data['permissions'] === false) { $this->permissions = array_fill_keys(array_keys($this->permissions), false); } else { $this->permissions = $this->permissions; } } // fallback permissions support for old 'panel' role variable if (isset($data['panel']) and is_bool($data['panel'])) { $this->permissions['panel.access'] = $data['panel']; } // is this role the default role? if (isset($data['default'])) { $this->default = $data['default'] === true; } }
/** * Creates a new Uniform instance. * * @param string $id The unique ID of this form. * @param array $options Array of uniform options, including the actions. */ public function __construct($id, $options) { if (empty($id)) { throw new Error('No Uniform ID was given.'); } $this->id = $id; $this->erroneousFields = array(); $this->options = array('guard' => a::get($options, 'guard', 'honeypot'), 'required' => a::get($options, 'required', array()), 'validate' => a::get($options, 'validate', array()), 'actions' => a::get($options, 'actions', array())); // required fields will also be validated by default $this->options['validate'] = a::merge($this->options['validate'], $this->options['required']); // initialize output array with the output of the plugin itself $this->actionOutput = array('_uniform' => array('success' => false, 'message' => '')); // the token is stored as session variable until the form is sent // successfully $this->token = s::get($this->id); if (!$this->token) { $this->generateToken(); } // get the data to be sent (if there is any) $this->data = get(); if ($this->requestValid()) { if (empty($this->options['actions'])) { throw new Error('No Uniform actions were given.'); } if ($this->dataValid()) { // uniform is done, now it's the actions turn $this->actionOutput['_uniform']['success'] = true; } } }
/** * Aggregates all the fields present in the given event object. * @param array $events An array of Event objects. */ private static function findEventFields($events) { $fields = array(); foreach ($events as $event) { $fields = a::merge($fields, $event->getFieldKeys()); } // make an associative array with the same keys as values return array_combine($fields, $fields); }
/** * Create a new CrazyMailer * * @var array $config data, accepts same as Email::__construct() */ public function __construct($config) { $defaults = ['to' => KirbyConfig::get('mailer.to'), 'from' => KirbyConfig::get('mailer.from'), 'service' => 'mailgun', 'options' => ['key' => KirbyConfig::get('mailgun.key'), 'domain' => KirbyConfig::get('mailgun.domain')]]; $this->emailer = new KirbyEmailer(KirbyArray::merge($defaults, $config)); $this->enabled = env('MAILER_ENABLED', false); $handler = new StreamHandler(kirby()->roots()->site() . '/../logs/emailer.log', Logger::WARNING); $this->logger = new Logger('crazy'); $this->logger->pushHandler($handler); }
public function _extend($params) { $extends = $params['extends']; $snippet = f::resolve(kirby()->roots()->blueprints() . DS . 'fields' . DS . $extends, array('yml', 'php', 'yaml')); if (empty($snippet)) { throw new Exception(l('fields.error.extended')); } $yaml = data::read($snippet, 'yaml'); $params = a::merge($yaml, $params); return $params; }
public function _extend($params) { $extends = $params['extends']; $files = glob(kirby()->roots()->blueprints() . DS . 'fields' . DS . $extends . '.{yml,yaml,php}', GLOB_BRACE); if (empty($files)) { throw new Exception(l('fields.error.extended')); } $yaml = data::read($files[0], 'yaml'); $params = a::merge($yaml, $params); return $params; }
public function _extend($params) { $extends = $params['extends']; $file = kirby()->get('blueprint', 'fields/' . $extends); if (empty($file) || !is_file($file)) { throw new Exception(l('fields.error.extended')); } $yaml = data::read($file, 'yaml'); $params = a::merge($yaml, $params); return $params; }
/** * Creates a new Uniform instance. * * @param string $id The unique ID of this form. * @param array $options Array of uniform options, including the actions. */ public function __construct($id, $options) { if (empty($id)) { throw new Error('No Uniform ID was given.'); } $this->id = $id; $this->erroneousFields = array(); $this->options = array('guard' => a::get($options, 'guard', 'honeypot'), 'honeypot' => a::get($options, 'honeypot', 'website'), 'required' => a::get($options, 'required', array()), 'validate' => a::get($options, 'validate', array()), 'actions' => a::get($options, 'actions', array())); // required fields will also be validated by default $this->options['validate'] = a::merge($this->options['validate'], $this->options['required']); // initialize output array with the output of the plugin itself $this->actionOutput = array('_uniform' => array('success' => false, 'message' => '')); // the token is stored as session variable until the form is sent // successfully $this->token = s::get($this->id); if (!$this->token) { $this->generateToken(); } // get the data to be sent (if there is any) $this->data = get(); // if($this->data) { // print_r($this->data); // } if ($this->requestValid()) { // remove uniform specific fields from form data unset($this->data['_submit']); if (empty($this->options['actions'])) { throw new Error('No Uniform actions were given.'); } if ($this->dataValid()) { // uniform is done, now it's the actions turn $this->actionOutput['_uniform']['success'] = true; } } else { // generate new token to spite the bots }:-) $this->generateToken(); // clear the data array // see https://github.com/mzur/kirby-uniform/issues/48 $this->data = array(); } }
/** * @param string $id The unique ID of this form. * * @param string $recipient e-mail adress the form content should be sent to. * * @param array $options Array of sendform options. */ public function __construct($id, $recipient, $options) { if (empty($id)) { throw new Error('No SendForm ID was given.'); } if (empty($recipient)) { throw new Error('No SendForm recipient was given.'); } $this->id = $id; $this->erroneousFields = array(); // the token is stored as session variable until the form is sent // successfully $this->token = s::get($this->id); if (!$this->token) { $this->generateToken(); } // get the data to be sent (if there is any) $this->data = get(); if ($this->requestValid()) { $this->options = array('subject' => str::template(a::get($options, 'subject', l::get('sendform-default-subject')), $this->data), 'snippet' => a::get($options, 'snippet', false), 'copy' => a::get($options, 'copy', array()), 'required' => a::get($options, 'required', array()), 'validate' => a::get($options, 'validate', array()), 'to' => $recipient, 'service' => a::get($options, 'service', 'mail'), 'service-options' => a::get($options, 'service-options', array())); // remove newlines to prevent malicious modifications of the email // header $this->options['subject'] = str_replace("\n", '', $this->options['subject']); // extend the data array so email snippets get these fields, too $this->data['_subject'] = $this->options['subject']; $this->data['_to'] = $this->options['to']; if (array_key_exists('_receive_copy', $this->data)) { array_unshift($this->options['copy'], $this->data['_from']); } $this->sentSuccessful = false; $this->message = ''; $requiredFields = a::merge($this->options['required'], array('_from' => 'email')); $validateFields = a::merge($this->options['validate'], $requiredFields); if ($this->dataValid($requiredFields, $validateFields)) { $this->sendForm(); } } }
/** * Returns a new combined collection * * @return Collection */ public function merge($collection2) { $collection = clone $this; $collection->data = a::merge($collection->data, $collection2->data); return $collection; }
public function i18n() { // load the interface language file if ($user = $this->site()->user()) { $this->language = $user->language(); } else { $this->language = $this->kirby()->option('panel.language', 'en'); } $translation = (require $this->roots()->languages() . DS . 'en.php'); $translation = a::merge($translation, require $this->roots()->languages() . DS . $this->language . '.php'); // set all language variables l::$data = $translation['data']; // set language direction (ltr is default) if (isset($translation['direction']) and $translation['direction'] == 'rtl') { l::set('language.direction', 'rtl'); } else { l::set('language.direction', 'ltr'); } }
/** * Sends the constructed email * * @param array $params Optional way to set values for the email * @return boolean */ public function send($params = null) { try { // fail silently if sending emails is disabled if (static::$disabled) { throw new Error('Sending emails is disabled', static::ERROR_DISABLED); } // overwrite already set values if (is_array($params) && !empty($params)) { foreach (a::merge($this->toArray(), $params) as $key => $val) { $this->set($key, $val); } } // reset all errors $this->error = null; // default service if (empty($this->service)) { $this->service = 'mail'; } // if there's no dedicated reply to address, use the from address if (empty($this->replyTo)) { $this->replyTo = $this->from; } // validate the email $this->validate(); // check if the email service is available if (!isset(static::$services[$this->service])) { throw new Error('The email service is not available: ' . $this->service, static::ERROR_INVALID_SERVICE); } // run the service call(static::$services[$this->service], $this); // reset the error $this->error = null; return true; } catch (Exception $e) { $this->error = $e; return false; } }