Ejemplo n.º 1
0
 /**
  * Execute search
  *
  * @param  array               $fields
  * @params \Pop\Module\Manager $modules
  * @return array
  */
 public function search($fields, \Pop\Module\Manager $modules)
 {
     $title = strip_tags($fields['title']);
     $selectFields = ['id' => DB_PREFIX . 'content.id', 'type_id' => DB_PREFIX . 'content.type_id', 'parent_id' => DB_PREFIX . 'content.parent_id', 'title' => DB_PREFIX . 'content.title', 'uri' => DB_PREFIX . 'content.uri', 'slug' => DB_PREFIX . 'content.slug', 'status' => DB_PREFIX . 'content.status', 'roles' => DB_PREFIX . 'content.roles', 'order' => DB_PREFIX . 'content.order', 'publish' => DB_PREFIX . 'content.publish', 'expire' => DB_PREFIX . 'content.expire'];
     $sql = Table\Content::sql();
     $sql->select($selectFields);
     $sql->select()->where('status = :status');
     $params = ['status' => 1];
     if (isset($fields['type_id'])) {
         $sql->select()->where('type_id = :type_id');
         $params['type_id'] = $fields['type_id'];
     }
     $sql->select()->where('title LIKE :title');
     $params['title'] = '%' . $title . '%';
     $sql->select()->orderBy('title', 'ASC');
     $results = Table\Content::execute((string) $sql, $params)->rows();
     foreach ($results as $i => $row) {
         $roles = unserialize($row->roles);
         if (count($roles) > 0 && !in_array($this->user_role_id, $roles)) {
             unset($results[$i]);
         } else {
             if ($modules->isRegistered('phire-fields')) {
                 $item = \Phire\Fields\Model\FieldValue::getModelObject('Phire\\Content\\Model\\Content', ['id' => $row->id], 'getById', $this->filters);
                 $results[$i] = new \ArrayObject($item->toArray(), \ArrayObject::ARRAY_AS_PROPS);
             }
         }
     }
     $log = new Searches(['keywords' => $title, 'results' => count($results), 'method' => $_POST ? 'post' : 'get', 'timestamp' => time()]);
     $log->save();
     return $results;
 }
Ejemplo n.º 2
0
 /**
  * Get the feed
  *
  * @param  array               $feedHeaders
  * @param  string              $feedType
  * @param  int                 $feedLimit
  * @param  \Pop\Module\Manager $modules
  * @return Writer
  */
 public function getFeed($feedHeaders, $feedType, $feedLimit, \Pop\Module\Manager $modules)
 {
     $items = [];
     $feed = Table\Feed::findAll();
     foreach ($feed->rows() as $f) {
         if ($f->type == 'content') {
             if ($modules->isRegistered('phire-fields')) {
                 $item = \Phire\Fields\Model\FieldValue::getModelObject('Phire\\Content\\Model\\Content', ['id' => $f->id]);
             } else {
                 $item = new \Phire\Content\Model\Content();
                 $item->getById($f->id);
             }
             if ($item->status == 1 && count($item->roles) == 0) {
                 $items[] = $this->formatItem($item, 'content', $feedType);
             }
         } else {
             if ($f->type == 'media') {
                 if ($modules->isRegistered('phire-fields')) {
                     $item = \Phire\Fields\Model\FieldValue::getModelObject('Phire\\Media\\Model\\Media', ['id' => $f->id]);
                 } else {
                     $item = new \Phire\Media\Model\Media();
                     $item->getById($f->id);
                 }
                 $item->publish = $item->uploaded;
                 $items[] = $this->formatItem($item, 'media', $feedType);
             }
         }
     }
     usort($items, function ($a, $b) {
         $t1 = strtotime($a['publish']);
         $t2 = strtotime($b['publish']);
         return $t2 - $t1;
     });
     if ((int) $feedLimit > 0) {
         if (count($items) > (int) $feedLimit) {
             $items = array_slice($items, 0, (int) $feedLimit);
         }
     }
     $writer = new Writer($feedHeaders, $items);
     if ($feedType == 'atom') {
         $writer->setAtom();
     }
     return $writer;
 }
Ejemplo n.º 3
0
 /**
  * Copy template
  *
  * @param  \Pop\Module\Manager $modules
  * @return void
  */
 public function copy(\Pop\Module\Manager $modules)
 {
     $oldId = (int) $this->data['id'];
     $template = Table\Templates::findById($oldId);
     if (isset($template->id)) {
         $i = 1;
         $name = $template->name . ' (Copy ' . $i . ')';
         $dupeTemplate = Table\Templates::findBy(['name' => $name]);
         while (isset($dupeTemplate->id)) {
             $i++;
             $name = $template->name . ' (Copy ' . $i . ')';
             $dupeTemplate = Table\Templates::findBy(['name' => $name]);
         }
         $newTemplate = new Table\Templates(['parent_id' => $template->parent_id, 'name' => $name, 'device' => null !== $template->parent_id ? null : 'desktop', 'template' => $template->template, 'history' => $template->history]);
         $newTemplate->save();
         if ($modules->isRegistered('phire-fields')) {
             $fv = \Phire\Fields\Table\FieldValues::findBy(['model_id' => $oldId]);
             if ($fv->count() > 0) {
                 foreach ($fv->rows() as $value) {
                     $v = new \Phire\Fields\Table\FieldValues(['field_id' => $value->field_id, 'model_id' => $newTemplate->id, 'model' => 'Phire\\Templates\\Model\\Template', 'value' => $value->value, 'timestamp' => time(), 'history' => $value->history]);
                     $v->save();
                 }
             }
         }
         $this->data = array_replace($this->data, $newTemplate->getColumns());
     }
 }
Ejemplo n.º 4
0
 /**
  * Get form submission values
  *
  * @param  \Pop\Module\Manager $modules
  * @return array
  */
 public function getValues(\Pop\Module\Manager $modules = null)
 {
     $values = [];
     $fieldNames = [];
     if (null !== $modules && $modules->isRegistered('phire-fields')) {
         $class = 'Phire\\Forms\\Model\\Form';
         $sql = \Phire\Fields\Table\Fields::sql();
         $sql->select()->where('models LIKE :models');
         $sql->select()->orderBy('order');
         $value = $sql->getDbType() == \Pop\Db\Sql::SQLITE ? '%' . $class . '%' : '%' . addslashes($class) . '%';
         $fields = \Phire\Fields\Table\Fields::execute((string) $sql, ['models' => $value]);
         foreach ($fields->rows() as $field) {
             if ($field->storage == 'eav') {
                 $fv = \Phire\Fields\Table\FieldValues::findBy(['field_id' => $field->id, 'model_id' => $this->id, 'model' => 'Phire\\Forms\\Model\\FormSubmission']);
                 foreach ($fv->rows() as $fv) {
                     $fieldNames[$field->name] = $field->type;
                     $values[$field->name] = json_decode($fv->value, true);
                 }
             } else {
                 $fv = new \Pop\Db\Record();
                 $fv->setPrefix(DB_PREFIX)->setPrimaryKeys(['id'])->setTable('field_' . $field->name);
                 $fv->findRecordsBy(['model_id' => $this->id, 'model' => 'Phire\\Forms\\Model\\FormSubmission', 'revision' => 0]);
                 $fieldNames[$field->name] = $field->type;
                 if ($fv->count() > 1) {
                     $values[$field->name] = [];
                     foreach ($fv->rows() as $f) {
                         $fieldNames[$field->name] = $field->type;
                         $values[$field->name][] = $f->value;
                     }
                 } else {
                     $values[$field->name] = $fv->value;
                 }
             }
         }
     }
     return ['values' => $values, 'fields' => $fieldNames];
 }
Ejemplo n.º 5
0
 /**
  * Get tag content
  *
  * @param  Table\Tags          $tag
  * @param  \Pop\Module\Manager $modules
  * @return void
  */
 protected function getTag(Table\Tags $tag, \Pop\Module\Manager $modules)
 {
     if ($modules->isRegistered('phire-fields')) {
         $t = \Phire\Fields\Model\FieldValue::getModelObject('Phire\\Tags\\Model\\Tag', [$tag->id]);
         $data = $t->toArray();
     } else {
         $data = $tag->getColumns();
     }
     $items = [];
     $c2t = Table\TagItems::findBy(['tag_id' => $tag->id], ['order' => 'content_id DESC']);
     if ($c2t->hasRows()) {
         foreach ($c2t->rows() as $c) {
             if ($modules->isRegistered('phire-fields')) {
                 $item = \Phire\Fields\Model\FieldValue::getModelObject('Phire\\Content\\Model\\Content', [$c->content_id], 'getById', $modules['phire-tags']['filters']);
             } else {
                 $class = 'Phire\\Content\\Model\\Content';
                 $model = new $class();
                 call_user_func_array([$model, 'getById'], [$c->content_id]);
                 $item = $model;
             }
             if ($item->status == 1 && count($item->roles) == 0) {
                 $items[$item->id] = new \ArrayObject($item->toArray(), \ArrayObject::ARRAY_AS_PROPS);
             }
         }
     }
     $data['items'] = $items;
     $this->data = array_merge($this->data, $data);
 }
Ejemplo n.º 6
0
 /**
  * Copy form
  *
  * @param  int $id
  * @param  \Pop\Module\Manager $modules
  * @return void
  */
 public function copy($id, \Pop\Module\Manager $modules = null)
 {
     $oldForm = Table\Forms::findById((int) $id);
     if (isset($oldForm->id)) {
         $i = 1;
         $name = $oldForm->name . ' (Copy ' . $i . ')';
         $dupeForm = Table\forms::findBy(['name' => $name]);
         while (isset($dupeForm->id)) {
             $i++;
             $name = $oldForm->name . ' (Copy ' . $i . ')';
             $dupeForm = Table\forms::findBy(['name' => $name]);
         }
         $form = new Table\Forms(['name' => $name, 'method' => !empty($oldForm->method) ? $oldForm->method : null, 'to' => !empty($oldForm->to) ? $oldForm->to : null, 'from' => !empty($oldForm->from) ? $oldForm->from : null, 'reply_to' => !empty($oldForm->reply_to) ? $oldForm->reply_to : null, 'action' => !empty($oldForm->action) ? $oldForm->action : null, 'redirect' => !empty($oldForm->redirect) ? $oldForm->redirect : null, 'attributes' => !empty($oldForm->attributes) ? $oldForm->attributes : null, 'submit_value' => !empty($oldForm->submit_value) ? $oldForm->submit_value : null, 'submit_attributes' => !empty($oldForm->submit_attributes) ? $oldForm->submit_attributes : null, 'use_captcha' => !empty($oldForm->use_captcha) ? (int) $oldForm->use_captcha : null, 'use_csrf' => !empty($oldForm->use_csrf) ? (int) $oldForm->use_csrf : null, 'force_ssl' => !empty($oldForm->force_ssl) ? (int) $oldForm->force_ssl : null]);
         $form->save();
         $flds = null;
         if (null !== $modules && $modules->isRegistered('phire-fields')) {
             $flds = \Phire\Fields\Table\Fields::findAll();
         }
         if (null !== $flds) {
             foreach ($flds->rows() as $f) {
                 if (!empty($f->models)) {
                     $models = unserialize($f->models);
                     print_r($models);
                     foreach ($models as $model) {
                         if ($model['model'] == 'Phire\\Forms\\Model\\Form' && $oldForm->id == $model['type_value']) {
                             $models[] = ['model' => 'Phire\\Forms\\Model\\Form', 'type_field' => 'id', 'type_value' => $form->id];
                             $newField = \Phire\Fields\Table\Fields::findById($f->id);
                             if (isset($newField->id)) {
                                 $newField->models = serialize($models);
                                 $newField->save();
                             }
                         }
                     }
                 }
             }
         }
     }
 }