Exemple #1
0
 protected function parse_data(array $data)
 {
     foreach ($data as $nid => $obj) {
         if ($obj->parentid) {
             $this->parentid[$nid] = $obj->parentid;
         }
         unset($obj->parentid);
         if ($obj->locationid) {
             $this->locationid[$nid] = $obj->locationid;
         }
         unset($obj->locationid);
         if (empty($obj->contents)) {
             \ICanBoogie\log("page {$nid} has no content");
         } else {
             $contents = (array) $obj->contents;
             $editors = (array) $obj->editors;
             foreach ($contents as $contentid => &$content) {
                 if (($content[0] == '{' || $content[0] == '[') && $content[1] == '"') {
                     $content = json_decode($content, true);
                 }
             }
             foreach ($editors as $contentid => $editor_name) {
                 if ($editor_name != 'widgets' || empty($contents[$contentid])) {
                     continue;
                 }
                 $content =& $contents[$contentid];
                 $content = array_combine($content, array_fill(0, count($content), 'on'));
             }
             $obj->contents = $contents;
             $obj->editors = $editors;
         }
     }
     return parent::parse_data($data);
 }
Exemple #2
0
 /**
  * Rescues a missing record by providing the best matching one.
  *
  * Match is computed from the slug of the module's own visible records, thus rescue if only
  * triggered if 'slug' is defined in the conditions.
  *
  * @return Content|null The record best matching the condition slug, or null if
  * none was similar enough.
  *
  * @throws RecordNotFound if the record could not be rescued.
  *
  * @todo-20140429 This should be in an exception rescue listener.
  */
 protected function rescue()
 {
     $conditions = $this->conditions;
     if (!empty($conditions['nid']) || empty($conditions['slug'])) {
         return;
     }
     $slug = $conditions['slug'];
     $model = $this->module->model;
     $tries = $model->select('nid, slug')->own->visible->order('date DESC')->pairs;
     $key = null;
     $max = 0;
     foreach ($tries as $nid => $compare) {
         similar_text($slug, $compare, $p);
         if ($p > $max) {
             $key = $nid;
             if ($p > 90) {
                 break;
             }
             $max = $p;
         }
     }
     if ($p < 60) {
         throw new RecordNotFound('Record not found.', []);
     } else {
         if ($key) {
             $record = $model[$key];
             \ICanBoogie\log('The record %title was rescued!', ['title' => $record->title]);
             throw new ForceRedirect($record->url, 301);
         }
     }
 }
Exemple #3
0
 /**
  * Notify users that a reply to their comment has been posted.
  *
  * @param int $commentid
  */
 protected function notify($commentid)
 {
     global $core;
     $form_id = $core->site->metas['comments.form_id'];
     if (!$form_id) {
         return;
     }
     try {
         $form = $core->models['forms'][$form_id];
     } catch (\Exception $e) {
         return;
     }
     $options = unserialize($form->metas['comments/reply']);
     if (!$options) {
         return;
     }
     $model = $this->module->model;
     $comment = $model[$commentid];
     #
     # search previous message for notify
     #
     $records = $model->where('nid = ? AND `{primary}` < ? AND (`notify` = "yes" OR `notify` = "author") AND author_email != ?', $comment->nid, $commentid, $comment->author_email)->all;
     if (!$records) {
         return;
     }
     #
     # prepare subject and message
     #
     $patron = new \Patron\Engine();
     $subject = $patron($options['subject'], $comment);
     $message = $patron($options['template'], $comment);
     $from = $options['from'];
     $bcc = $options['bcc'];
     foreach ($records as $entry) {
         #
         # notify only if the author of the node post a comment
         #
         if ($entry->notify == 'author' && $comment->uid != $comment->node->uid) {
             continue;
         }
         \ICanBoogie\log('Send notify to %author (email: %email, message n°%commentid, mode: %notify)', array('%author' => $entry->author, '%email' => $entry->author_email, '%commentid' => $entry->commentid, '%notify' => $entry->notify));
         $mailer = new Mailer(array(Mailer::T_DESTINATION => $entry->author_email, Mailer::T_FROM => $from, Mailer::T_BCC => $bcc, Mailer::T_MESSAGE => $message, Mailer::T_SUBJECT => $subject, Mailer::T_TYPE => 'plain'));
         if (!$mailer()) {
             \ICanBoogie\log_error('Unable to send notify to %author', array('%author' => $entry->author));
             continue;
         }
         $entry->notify = 'done';
         $entry->save();
     }
 }