The opinions expressed on the website belong to their authors and do not necessarily reflect the views of the United States Agency for International Development (USAID) or the US Government. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, you can read the copy of GNU General Public License in English here: . For more details about CMS WebAPL 1.0 please contact Enterprise Business Solutions SRL, Republic of Moldova, MD 2001, Ion Inculet 33 Street or send an email to office@ebs.md
Inheritance: extends Eloquent
 /**
  * Registra o Post Type
  */
 public function register()
 {
     $args = $this->get_register_args(array('menu_icon' => 'dashicons-images-alt'));
     register_post_type($this->post_type, $args);
     $taxonomy = new Taxonomy(array('post_type' => 'banner', 'labels' => $this->labels));
     $taxonomy->register();
 }
 public function run()
 {
     parent::run();
     $data = array();
     $id_listen_cat = Category::model()->findAll("taxonomy_id = " . $this->_id_bai_hoc . " and state = 1");
     $id_listen_cat_array = array();
     foreach ($id_listen_cat as $k) {
         $id_listen_cat_array[] = $k->id;
     }
     $id_news_cat = Category::model()->findAll("taxonomy_id = " . $this->_id__tintuc . " and state = 1");
     $id_news_cat_array = array();
     foreach ($id_news_cat as $k) {
         $id_news_cat_array[] = $k->id;
     }
     $comment = Comment::model()->findAll(array("condition" => "state = 1", "limit" => 5, "order" => "id desc"));
     $options = array();
     $i = 0;
     foreach ($comment as $k) {
         $options[$i]['content'] = Content::model()->findByPk($k->content_id);
         $options[$i]['category'] = Category::model()->findByPk($options[$i]['content']->category_id);
         $options[$i]['parent'] = '';
         if ($options[$i]['category']->parent != 0) {
             $options[$i]['parent'] = Category::model()->findByPk($options[$i]['category']->parent);
         }
         $options[$i]['taxonomy'] = Taxonomy::model()->findByPk($options[$i]['category']->taxonomy_id);
         $i++;
     }
     $data['comments'] = $comment;
     $data['options'] = $options;
     $data['news'] = Content::model()->findAll(array("condition" => "state = 1 and category_id in (" . implode(",", $id_news_cat_array) . ")", "limit" => 10, "order" => "id desc"));
     $data['listen'] = Content::model()->findAll(array("condition" => "state = 1 and category_id in (" . implode(",", $id_listen_cat_array) . ")", "limit" => 10, "order" => "id desc"));
     $this->render('news_lession_comment', $data);
 }
Example #3
0
 public function actionView()
 {
     $pid = Yii::app()->request->getParam('pid');
     $cid = Yii::app()->request->getParam('cid');
     $id = Yii::app()->request->getParam('id');
     $category = Category::model()->findByPk($pid);
     if ($category->taxonomy_id == $this->root_id) {
         $data = array();
         $data['item'] = Content::model()->findbyPk($id);
         if ($data['item']->category_id == $cid) {
             $data['cat'] = Category::model()->findbyPk($data['item']->category_id);
             $data['root_cat'] = Taxonomy::model()->findbyPk($data['cat']->taxonomy_id);
             $this->title = $data['item']->title;
             Content::model()->updateByPk($id, array('view' => $data['item']->view + 1));
             $data['comment_model'] = Comment::model()->findAll(array('condition' => 'content_id = :cid and state = 1', 'params' => array(':cid' => $id)));
             if ($data['item']->category_id != $cid) {
                 throw new CHttpException(404, 'PAGE NOT FOUND.');
             }
             $this->render('view', $data);
         } else {
             throw new CHttpException(404, 'PAGE NOT FOUND.');
         }
     } else {
         throw new CHttpException(404, 'PAGE NOT FOUND.');
     }
 }
Example #4
0
 /**
  * Retrieve the parent page
  * @return Array Array containing the content of the parent page
  */
 private function getParent()
 {
     $parent = URL::assemble(URL::popLastSegment(URL::getCurrent()));
     if (Taxonomy::isTaxonomyURL($parent)) {
         $parent = URL::popLastSegment($parent);
     }
     return Content::get($parent);
 }
Example #5
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Taxonomy::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #6
0
 public function run()
 {
     parent::run();
     $criteria = new CDbCriteria();
     $criteria->order = 't.id ASC';
     $criteria->condition = 'state = 1';
     $menus = Taxonomy::model()->findAll($criteria);
     $this->render('menu', array('menus' => $menus, 'total' => count($menus)));
 }
Example #7
0
 /**
  * Exection hook
  *
  * @param Stencil_Interface $controller Controller that initiated this class.
  */
 public function execute(Stencil_Interface $controller)
 {
     $object = get_queried_object();
     if (class_exists('Taxonomy', false)) {
         $controller->set('taxonomy', Taxonomy::get($object->taxonomy));
     } else {
         $controller->set('taxonomy', $object);
     }
 }
Example #8
0
 function __construct()
 {
     parent::__construct();
     $this->beforeFilter(function () {
         if (!Auth::check()) {
             return Redirect::to('auth');
         }
     });
     $this->taxonomy = Taxonomy::get('article');
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validation = Validator::make(Input::all(), Term::$rules);
     if ($validation->fails()) {
         return Redirect::back()->withInput()->withErrors($validation)->with('error', 'There were validation errors.');
     }
     $vocabulary = Vocabulary::findOrFail(Input::get('vocabulary_id'));
     $term = \Taxonomy::createTerm($vocabulary->id, Input::get('name'));
     return Redirect::route($this->route_prefix . 'taxonomy.edit', $vocabulary->id);
 }
Example #10
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postStore(Request $request)
 {
     $validation = Validator::make($request->all(), Term::$rules);
     if ($validation->fails()) {
         return Redirect::back()->withInput()->withErrors($validation)->with('error', 'There were validation errors.');
     }
     $vocabulary = Vocabulary::findOrFail($request->vocabulary_id);
     $term = \Taxonomy::createTerm($vocabulary->id, $request->name);
     return Redirect::to(action('\\Trexology\\Taxonomy\\Controllers\\TermsController@getIndex', ['id' => $vocabulary->id]))->with('success', 'Created');
 }
Example #11
0
 /**
  * Set up custom post type for venues
  *
  * @private
  */
 private static function _set_up_venues()
 {
     // Register Venues custom post types
     PostType::make('venue', 'Venues', 'Venue')->set();
     // Define fields for the metabox
     $fields = array(Field::checkbox('active', array('1' => 'Yes')), Field::checkbox('confirmed', array('1' => 'Yes')), Field::text('address', array('title' => 'Address')), Field::text('city', array('title' => 'City')), Field::text('state', array('title' => 'State')), Field::text('postcode', array('title' => 'Postcode')), Field::text('country', array('title' => 'Country')));
     // Add metabox with custom fields
     Metabox::make('Venue details', 'venue')->set($fields);
     // Add venue types custom taxonomy
     Taxonomy::make('venue_type', 'venue', 'Venue Types', 'Venue Type')->set();
 }
Example #12
0
 public function testGeneralTaxonomy()
 {
     $cat = Taxonomy::category()->slug('php')->posts()->first();
     $this->assertEquals('php', $cat->name);
     $cat = Taxonomy::where('taxonomy', 'category')->slug('php')->with('posts')->get();
     $cat->each(function ($category) {
         $this->assertEquals('php', $category->name);
     });
     $cat = Category::slug('php')->posts()->first();
     $post = $cat->posts()->first();
     $this->assertEquals('hello-world', $post->post_name);
 }
Example #13
0
 function __construct()
 {
     parent::__construct();
     $this->beforeFilter(function () {
         if (!Auth::check()) {
             return Redirect::to('auth');
         }
     });
     $this->taxonomy = Taxonomy::get('page');
     Event::listen('page_attachment', function ($page) {
         echo View::make('sections.feed.attachment-page', array('post' => $page->toArray(), 'list' => Feed::orderBy('name', 'asc')->get()));
     });
 }
 protected function renderContent()
 {
     $model = new Taxonomy();
     //The type of the content we want to create
     $type = isset($_GET['type']) ? strtolower(trim($_GET['type'])) : '';
     //If it has guid, it means this is a translated version
     $guid = isset($_GET['guid']) ? strtolower(trim($_GET['guid'])) : '';
     //Get the list of Content Type
     $types = GxcHelpers::getAvailableContentType();
     //List of language that should exclude not to translate
     $lang_exclude = array();
     //List of translated versions
     $versions = array();
     if ($type != '' && !array_key_exists($type, $types)) {
         throw new CHttpException(404, t('Page Not Found'));
     } else {
         // If the guid is not empty, it means we are creating a translated version of a content
         // We will exclude the translated language and include the name of the translated content to $versions
         if ($guid != '') {
             $taxonomy_object = Taxonomy::model()->findAll('guid=:gid', array(':gid' => $guid));
             $langs = GxcHelpers::getAvailableLanguages();
             if (count($taxonomy_object) > 0) {
                 foreach ($taxonomy_object as $obj) {
                     $lang_exclude[] = $obj->lang;
                     $versions[] = $obj->name . ' - ' . $langs[$obj->lang]['name'];
                 }
             }
             $model->guid = $guid;
         }
         // if it is ajax validation request
         if (isset($_POST['ajax']) && $_POST['ajax'] === 'taxonomy-form') {
             echo CActiveForm::validate($model);
             Yii::app()->end();
         }
         // collect user input data
         if (isset($_POST['Taxonomy'])) {
             $model->attributes = $_POST['Taxonomy'];
             if ($model->save()) {
                 user()->setFlash('success', t('cms', 'Create new Taxonomy Successfully!'));
                 $model = new Taxonomy();
                 Yii::app()->controller->redirect(array('create'));
             }
         }
         $this->render('cmswidgets.views.taxonomy.taxonomy_form_widget', array('model' => $model, 'lang_exclude' => $lang_exclude, 'versions' => $versions, 'type' => $type));
     }
 }
Example #15
0
 public function unbind($repository)
 {
     if (is_array($repository)) {
         foreach ($repository as $repo) {
             $this->unbind($repo);
         }
     } else {
         if (!is_object($repository)) {
             if ($repository = Taxonomy::instance($repository)) {
                 /* Taxonomy */
             } else {
                 return;
             }
         }
         if ($repository instanceof Taxonomy) {
             $repository->unbind($this);
         }
     }
 }
Example #16
0
File: pi.pages.php Project: nob/joi
 /**
  * Lists entries based on passed parameters
  *
  * @return array|string
  */
 public function listing()
 {
     $folders = $this->fetchParam('folder', $this->fetchParam('folders', ltrim($this->fetchParam('from', URL::getCurrent()), "/")));
     $folders = $folders === "/" ? "" : $folders;
     if ($this->fetchParam('taxonomy', false, null, true, null)) {
         $taxonomy_parts = Taxonomy::getCriteria(URL::getCurrent());
         $taxonomy_type = $taxonomy_parts[0];
         $taxonomy_slug = Config::get('_taxonomy_slugify') ? Slug::humanize($taxonomy_parts[1]) : urldecode($taxonomy_parts[1]);
         $content_set = ContentService::getContentByTaxonomyValue($taxonomy_type, $taxonomy_slug, $folders);
     } else {
         $content_set = ContentService::getContentByFolders($folders);
     }
     // filter
     $content_set->filter(array('show_all' => $this->fetchParam('show_hidden', false, null, true, false), 'since' => $this->fetchParam('since'), 'until' => $this->fetchParam('until'), 'show_past' => $this->fetchParam('show_past', TRUE, NULL, TRUE), 'show_future' => $this->fetchParam('show_future', FALSE, NULL, TRUE), 'type' => 'pages', 'conditions' => trim($this->fetchParam('conditions', ""))));
     // sort
     $content_set->sort($this->fetchParam('sort_by', 'order_key'), $this->fetchParam('sort_dir'));
     // grab total entries for setting later
     $total_entries = $content_set->count();
     // limit
     $limit = $this->fetchParam('limit', null, 'is_numeric');
     $offset = $this->fetchParam('offset', 0, 'is_numeric');
     $paginate = $this->fetchParam('paginate', true, null, true, false);
     if ($limit || $offset) {
         if ($limit && $paginate && !$offset) {
             // pagination requested, isolate the appropriate page
             $content_set->isolatePage($limit, URL::getCurrentPaginationPage());
         } else {
             // just limit
             $content_set->limit($limit, $offset);
         }
     }
     // manually supplement
     $content_set->supplement(array('total_found' => $total_entries));
     // check for results
     if (!$content_set->count()) {
         return array('no_results' => true);
     }
     // if content is used in this entries loop, parse it
     $parse_content = (bool) preg_match(Pattern::USING_CONTENT, $this->content);
     return Parse::tagLoop($this->content, $content_set->get($parse_content));
 }
Example #17
0
 public function actionView($id = '')
 {
     $cid = Yii::app()->request->getParam('tid');
     $category = Category::model()->findByPk($cid);
     if ($category->taxonomy_id == $this->root_id) {
         $data = array();
         $data['item'] = Content::model()->findbyPk($id);
         if ($data['item']->category_id == $cid) {
             $data['cat'] = Category::model()->findbyPk($data['item']->category_id);
             $data['root_cat'] = Taxonomy::model()->findbyPk($data['cat']->taxonomy_id);
             $this->title = $data['item']->title;
             Content::model()->updateByPk($id, array('view' => $data['item']->view + 1));
             if ($data['item']->category_id != $cid) {
                 throw new CHttpException(404, 'PAGE NOT FOUND.');
             }
             $this->render('view', $data);
         } else {
             throw new CHttpException(404, 'PAGE NOT FOUND.');
         }
     } else {
         throw new CHttpException(404, 'PAGE NOT FOUND.');
     }
 }
Example #18
0
 public function run()
 {
     parent::run();
     $data = array();
     $this->r_slug = Taxonomy::model()->findByPk($this->tax_id)->slug;
     $current = Content::model()->findByPk($this->p_id);
     $data['cat'] = Category::model()->findByPk($this->c_id);
     $id = Category::model()->findAll(array('condition' => 'taxonomy_id =  ' . $data['cat']->taxonomy_id));
     $arr_id = array();
     foreach ($id as $k) {
         $arr_id[] = $k->id;
         $data['category_'][$k->id] = $k->slug;
     }
     $this->own = Content::model()->find(array('condition' => 'id < :pid and category_id = :cid ', 'params' => array(':pid' => $this->p_id, ':cid' => $this->c_id)));
     $this->new = Content::model()->find(array('condition' => 'id > :pid and category_id = :cid ', 'params' => array(':pid' => $this->p_id, ':cid' => $this->c_id)));
     $data['same_thread'] = Content::model()->findAll(array('condition' => 'id != :pid and category_id in ( :cid ) and state = 1', 'params' => array(':pid' => $this->p_id, ':cid' => implode(",", $arr_id)), 'order' => 'rand()', 'limit' => 3));
     if (count($this->own) == 0) {
         $this->own = $current;
     }
     if (count($this->new) == 0) {
         $this->new = $current;
     }
     $this->render('more_listen', $data);
 }
Example #19
0
 /**
  * Register custom taxonomies.
  *
  * @param array $taxonomies
  */
 public static function taxonomies(array $taxonomies)
 {
     foreach ($taxonomies as $taxonomy) {
         Taxonomy::register($taxonomy['name'], $taxonomy['slug'], $taxonomy['object_type'], $taxonomy['args']);
     }
 }
 protected function renderContent()
 {
     $id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
     $model = GxcHelpers::loadDetailModel('Object', $id);
     //We start to implement the checking Permission HERE
     $param_content_check = array();
     $data_content_check = array();
     $param_content_check['type'] = $model->object_type;
     $param_content_check['new_content'] = false;
     $param_content_check['content_status'] = $model->object_status;
     $param_content_check['content_author'] = $model->object_author;
     //Get current trans_to of the object
     $trans = Transfer::model()->findAll(array('condition' => ' object_id=:obj ', 'params' => array(':obj' => $model->object_id), 'order' => 'transfer_id DESC'));
     $param_content_check['check_trans_note'] = false;
     if ($trans != null && count($trans) > 0) {
         $latest_trans_to = $trans[0];
         $param_content_check['trans_type'] = $latest_trans_to->type;
         $param_content_check['trans_to'] = $latest_trans_to->to_user_id;
         $param_content_check['trans_note'] = $latest_trans_to->note;
     }
     //Get Types list and type of the Object
     $types = GxcHelpers::getAvailableContentType();
     $type = (string) $model->object_type;
     //Import the Content Type Class
     Yii::import('common.content_type.' . $type . '.' . $types[$type]['class']);
     $typeClassObj = new $types[$type]['class']();
     $content_resources = $typeClassObj->Resources();
     //Check if the User has the Permission to update the Content
     if (GxcContentPermission::checkUpdatePermission($param_content_check, $data_content_check, $typeClassObj->Permissions())) {
         //Convert the object date from timestamp to datetime format
         $model->object_date = date('Y-m-d H:i:s', $model->object_date);
         //Get available content Status that the Object can be sent to
         $content_status = GxcContentPermission::getContentStatus($param_content_check, $data_content_check, $typeClassObj->Permissions());
         //If the Object is Pending and being sent to someone, get that person info
         if ($model->object_status == ConstantDefine::OBJECT_STATUS_PENDING) {
             if ($latest_trans_to->type == ConstantDefine::TRANS_PERSON) {
                 $send_to_user = User::model()->findbyPk($latest_trans_to->to_user_id);
                 if ($send_to_user == null) {
                     $model->person = '';
                 } else {
                     $model->person = trim($send_to_user->display_name);
                 }
             }
         }
         //Unset value for Lang Exclude, Version and Guid when updating
         $lang_exclude = array();
         $versions = array();
         $guid = $model->guid;
         // Create new instance Object based on Object Type
         $object = new $types[$type]['class']();
         $object->person = $model->person;
         $object->setAttributes($model->attributes, false);
         // Get Extra Info - Object Meta of the Object Type
         $object_metas = ObjectMeta::model()->findAll('meta_object_id = :obj ', array(':obj' => $model->object_id));
         foreach ($object_metas as $object_meta) {
             $key = (string) $object_meta->meta_key;
             $object->{$key} = $object_meta->meta_value;
         }
         // This is not a new Record
         $object->isNewRecord = false;
         //Set current tags for Object
         $object->_oldTags = $object->tags;
         $object->scenario = 'updateWithTags';
         //Available Terms for this Object Type
         $terms = array();
         //Selected Terms
         $selected_terms = array();
         //Get Term Order
         $term_orders = ConstantDefine::getTermOrder();
         //Get available Taxonomy and Terms for this Object
         $available_taxonomy = Taxonomy::model()->findAll(' type = :type AND lang IN (' . $object->lang . ') ', array(':type' => $type));
         if ($available_taxonomy) {
             foreach ($available_taxonomy as $t) {
                 $temp = array();
                 $temp['id'] = $t->taxonomy_id;
                 $temp['lang'] = $t->lang;
                 $temp['name'] = $t->name;
                 $temp['terms'] = array();
                 $selected_temp = array();
                 $selected_temp['id'] = $t->taxonomy_id;
                 $selected_temp['lang'] = $t->lang;
                 $selected_temp['name'] = $t->name;
                 $selected_temp['terms'] = array();
                 //Look for the Term Items belong to this Taxonomy
                 $list_terms = Term::model()->findAll(array('select' => '*', 'condition' => 'taxonomy_id=:id', 'order' => 't.parent ASC, t.order ASC', 'params' => array(':id' => $t->taxonomy_id)));
                 if ($list_terms) {
                     foreach ($list_terms as $term) {
                         $temp_item['id'] = $term->term_id;
                         $temp_item['name'] = CHtml::encode($term->name);
                         $temp_item['parent'] = $term->parent;
                         $temp['terms']['item_' . $term->term_id] = $temp_item;
                     }
                 }
                 $terms[$t->taxonomy_id] = $temp;
                 //Look for selected Terms belong to this Taxonomy
                 $sl_terms = ObjectTerm::model()->findAll(array('select' => '*', 'condition' => 'object_id=:id', 'params' => array(':id' => $object->object_id)));
                 if ($sl_terms) {
                     foreach ($sl_terms as $sl_term) {
                         if (isset($terms[$t->taxonomy_id]['terms']['item_' . $sl_term->term_id])) {
                             $selected_temp['terms']['item_' . $sl_term->term_id] = $terms[$t->taxonomy_id]['terms']['item_' . $sl_term->term_id];
                             $selected_temp['terms']['item_' . $sl_term->term_id]['data'] = $sl_term->data;
                             $selected_temp['terms']['item_' . $sl_term->term_id]['data_name'] = $term_orders[$sl_term->data];
                         }
                     }
                 }
                 $selected_terms[$t->taxonomy_id] = $selected_temp;
             }
         }
         //IF having the Post Method - Start to working to save it
         if (isset($_POST[$types[$type]['class']])) {
             $object->attributes = $_POST[$types[$type]['class']];
             //Convert the date time publish to timestamp
             $object->object_date = strtotime($object->object_date);
             $object->object_date_gmt = local_to_gmt($object->object_date);
             //Check which button the User click To Send to person or group
             $button = $_POST['which_button'];
             $trans = new Transfer();
             // Get the Terms that the User Choose
             $post_terms = isset($_POST['terms']) ? $_POST['terms'] : array();
             $selected_terms = array();
             if (!empty($post_terms)) {
                 foreach ($post_terms as $t) {
                     $t = explode('_', $t);
                     if (!isset($selected_terms[$t[1]])) {
                         $selected_temp = array();
                         $selected_temp['id'] = $terms[$t[1]]['id'];
                         $selected_temp['lang'] = $terms[$t[1]]['lang'];
                         $selected_temp['name'] = $terms[$t[1]]['name'];
                         $selected_temp['terms']['item_' . $t[0]]['id'] = $t[0];
                         $selected_temp['terms']['item_' . $t[0]]['name'] = $terms[$t[1]]['terms']['item_' . $t[0]]['name'];
                         $selected_temp['terms']['item_' . $t[0]]['parent'] = $terms[$t[1]]['terms']['item_' . $t[0]]['parent'];
                         $selected_temp['terms']['item_' . $t[0]]['data'] = $t[2];
                         $selected_temp['terms']['item_' . $t[0]]['data_name'] = $term_orders[$t[2]];
                         $selected_terms[$t[1]] = $selected_temp;
                     } else {
                         if (!isset($selected_terms['terms']['item_' . $t[0]])) {
                             $selected_terms[$t[1]]['terms']['item_' . $t[0]]['id'] = $t[0];
                             $selected_terms[$t[1]]['terms']['item_' . $t[0]]['name'] = $terms[$t[1]]['terms']['item_' . $t[0]]['name'];
                             $selected_terms[$t[1]]['terms']['item_' . $t[0]]['parent'] = $terms[$t[1]]['terms']['item_' . $t[0]]['parent'];
                             $selected_terms[$t[1]]['terms']['item_' . $t[0]]['data'] = $t[2];
                             $selected_terms[$t[1]]['terms']['item_' . $t[0]]['data_name'] = $term_orders[$t[2]];
                         }
                     }
                 }
             }
             // After having the selected Terms, we need to make sure  all parents
             // of the selected Terms must be added also
             foreach ($selected_terms as $tx_key => $t) {
                 $array_parent_selected_terms = array();
                 foreach ($t['terms'] as $key => $st_terms) {
                     $current_term = $st_terms;
                     while ($current_term['parent'] != 0) {
                         if (!isset($array_parent_selected_terms['item_' . $current_term['parent']]) && !isset($t['terms']['item_' . $current_term['parent']])) {
                             $array_parent_selected_terms['item_' . $current_term['parent']] = $terms[$tx_key]['terms']['item_' . $current_term['parent']];
                             $array_parent_selected_terms['item_' . $current_term['parent']]['data'] = key($term_orders);
                             $array_parent_selected_terms['item_' . $current_term['parent']]['data_name'] = $term_orders[key($term_orders)];
                         }
                         $current_term = $terms[$tx_key]['terms']['item_' . $current_term['parent']];
                     }
                 }
                 $selected_terms[$tx_key]['terms'] = CMap::mergeArray($t['terms'], $array_parent_selected_terms);
             }
             //Re-Set the Status based on what User Chooose
             //The content is sent to ROLES OR STATUS
             if ($button == '1') {
                 //Check if the object_status is number or character
                 if (!is_numeric($object->object_status)) {
                     //Set the status to Pending
                     $trans->note = $object->object_status;
                     $object->object_status = ConstantDefine::OBJECT_STATUS_PENDING;
                     $trans->type = ConstantDefine::TRANS_ROLE;
                     $trans->after_status = ConstantDefine::OBJECT_STATUS_PENDING;
                 } else {
                     $trans->type = ConstantDefine::TRANS_STATUS;
                     $trans->after_status = $object->object_status;
                 }
                 $trans->from_user_id = user()->id;
                 $trans->to_user_id = 0;
                 $trans->before_status = ConstantDefine::OBJECT_STATUS_DRAFT;
             }
             //The content is sent to PERSON DIRECTLY
             if ($button == '2') {
                 $to_user_id = User::findPeople($object->person);
                 //Start to Transfer to the user and set the status to Pending
                 if ($to_user_id) {
                     $object->object_status = ConstantDefine::OBJECT_STATUS_PENDING;
                     $trans->from_user_id = user()->id;
                     $trans->to_user_id = $to_user_id->user_id;
                     $trans->type = ConstantDefine::TRANS_PERSON;
                     $trans->before_status = ConstantDefine::OBJECT_STATUS_PENDING;
                     $trans->after_status = ConstantDefine::OBJECT_STATUS_PENDING;
                 } else {
                     $object->addError('person', t('User not found'));
                 }
             }
             //Work with Resource Binding
             $resource = array();
             $resource_upload = array();
             foreach ($content_resources as $res) {
                 $resource_upload[] = GxcHelpers::getArrayResourceObjectBinding('resource_upload_' . $res['type']);
             }
             $i = 0;
             $count_resource = 0;
             foreach ($content_resources as $cres) {
                 $j = 1;
                 foreach ($resource_upload[$i] as $res_up) {
                     $j++;
                     $count_resource++;
                 }
                 $i++;
             }
             $object->total_number_resource = $count_resource;
             if ($object->save()) {
                 user()->setFlash('success', t('cms', 'Update content Successfully!'));
                 $trans->object_id = $object->object_id;
                 $trans->save();
                 //This is the update process, we should delete old
                 //Object Term binding
                 ObjectTerm::model()->deleteAll('object_id = :id', array(':id' => $object->object_id));
                 // We have all the selected Terms for now
                 // We will add them to Object Terms
                 foreach ($selected_terms as $tx_key => $t) {
                     foreach ($t['terms'] as $key => $st_terms) {
                         $obj_term = new ObjectTerm();
                         $obj_term->object_id = $object->object_id;
                         $obj_term->term_id = $st_terms['id'];
                         $obj_term->data = $st_terms['data'];
                         $obj_term->save();
                         unset($obj_term);
                     }
                 }
                 //Re update for Resource
                 ObjectResource::model()->deleteAll('object_id = :id', array(':id' => $object->object_id));
                 $i = 0;
                 $count_resource = 0;
                 foreach ($content_resources as $cres) {
                     $j = 1;
                     foreach ($resource_upload[$i] as $res_up) {
                         $obj_res = new ObjectResource();
                         $obj_res->resource_id = $res_up['resid'];
                         $obj_res->object_id = $object->object_id;
                         $obj_res->description = '';
                         $obj_res->type = $cres['type'];
                         $obj_res->resource_order = $j;
                         $obj_res->save();
                         $j++;
                         $count_resource++;
                     }
                     $i++;
                 }
             }
             $object->object_date = date('Y-m-d H:i:s', $object->object_date);
         }
         //Start Render the Form
         $render_template = 'cmswidgets.views.object.object_form_widget';
         if (file_exists(Yii::getPathOfAlias('common.content_type.' . strtolower($type) . '.object_form_widget') . '.php')) {
             $render_template = 'common.content_type.' . strtolower($type) . '.object_form_widget';
         }
         $this->render($render_template, array('model' => $object, 'versions' => $versions, 'lang_exclude' => $lang_exclude, 'content_status' => $content_status, 'terms' => $terms, 'selected_terms' => $selected_terms, 'type' => $type, 'content_resources' => $content_resources));
     }
 }
Example #21
0
 /**
  * Get taxonomy.
  *
  * @return \yii\db\ActiveRelation
  */
 public function getTaxonomy()
 {
     return $this->hasOne(Taxonomy::className(), ['id' => 'taxonomy_id']);
 }
Example #22
0
		<?php 
echo $form->labelEx($model, 'status');
?>
		<?php 
echo $form->dropDownList($model, 'status', $model->getStatusOptions());
?>
		<?php 
echo $form->error($model, 'status');
?>
	</div>
	<div>
		<?php 
echo $form->labelEx($model, 'tag');
?>
		<?php 
echo $form->checkBoxList($model, 'taxonomy', Taxonomy::model()->listTags('tag'));
?>
		<?php 
echo $form->error($model, 'tag');
?>
	</div>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'meta_description');
?>
		<?php 
echo $form->textArea($model, 'meta_description', array('rows' => 6, 'cols' => 50));
?>
		<?php 
echo $form->error($model, 'meta_description');
Example #23
0
 public function beforeSave()
 {
     $this->type = "tag";
     return parent::beforeSave();
 }
Example #24
0
 /**
  * Supplements the content in the set
  *
  * @param array  $context  Context for supplementing
  * @return void
  */
 public function supplement($context = array())
 {
     $hash = Debug::markStart('content', 'supplementing');
     if ($this->supplemented) {
         return;
     }
     $this->supplemented = true;
     $context = Helper::ensureArray($context);
     // determine context
     $given_context = $context;
     $context = array('locate_with' => isset($given_context['locate_with']) ? $given_context['locate_with'] : null, 'center_point' => isset($given_context['center_point']) ? $given_context['center_point'] : null, 'list_helpers' => isset($given_content['list_helpers']) ? $given_context['list_helpers'] : true, 'context_urls' => isset($given_context['context_urls']) ? $given_context['context_urls'] : true, 'total_found' => isset($given_context['total_found']) ? $given_context['total_found'] : null, 'group_by_date' => isset($given_context['group_by_date']) ? $given_context['group_by_date'] : null, 'inherit_folder_data' => isset($given_context['inherit_folder_data']) ? $given_context['inherit_folder_data'] : true, 'merge_with_data' => isset($given_context['merge_with_data']) ? $given_context['merge_with_data'] : true);
     // set up helper variables
     $center_point = false;
     if ($context['center_point'] && preg_match(Pattern::COORDINATES, $context['center_point'], $matches)) {
         $center_point = array($matches[1], $matches[2]);
     }
     // contextual urls are based on current page, not individual data records
     // we can figure this out once and then set it with each one
     if ($context['context_urls']) {
         $raw_url = Request::getResourceURI();
         $page_url = Path::tidy($raw_url);
     }
     // iteration memory
     $last_date = null;
     // loop through content, supplementing each record with data
     foreach ($this->content as $content_key => $data) {
         // locate
         if ($context['locate_with']) {
             $location_data = isset($data[$context['locate_with']]) ? $data[$context['locate_with']] : null;
             // check that location data is fully set
             if (is_array($location_data) && isset($location_data['latitude']) && $location_data['latitude'] && isset($location_data['longitude']) && $location_data['longitude']) {
                 $data['latitude'] = $location_data['latitude'];
                 $data['longitude'] = $location_data['longitude'];
                 $data['coordinates'] = $location_data['latitude'] . "," . $location_data['longitude'];
                 // get distance from center
                 if ($center_point) {
                     $location = array($data['latitude'], $data['longitude']);
                     $data['distance_km'] = Math::getDistanceInKilometers($center_point, $location);
                     $data['distance_mi'] = Math::convertKilometersToMiles($data['distance_km']);
                 }
             }
         }
         // contextual urls
         if ($context['context_urls']) {
             $data['raw_url'] = $raw_url;
             $data['page_url'] = $page_url;
         }
         // total entries
         if ($context['total_found']) {
             $data['total_found'] = (int) $context['total_found'];
         }
         // group by date
         if ($context['group_by_date'] && $data['datestamp']) {
             $formatted_date = Date::format($context['group_by_date'], $data['datestamp']);
             if ($formatted_date !== $last_date) {
                 $last_date = $formatted_date;
                 $data['grouped_date'] = $formatted_date;
             } else {
                 $data['grouped_date'] = '';
             }
         }
         // loop through content to add data for variables that are arrays
         foreach ($data as $key => $value) {
             // Only run on zero indexed arrays/loops
             if (is_array($value) && isset($value[0]) && !is_array($value[0])) {
                 // list helpers
                 if ($context['list_helpers']) {
                     // make automagic lists
                     $data[$key . "_list"] = join(", ", $value);
                     $data[$key . "_spaced_list"] = join(" ", $value);
                     $data[$key . "_option_list"] = join("|", $value);
                     $data[$key . "_ordered_list"] = "<ol><li>" . join("</li><li>", $value) . "</li></ol>";
                     $data[$key . "_unordered_list"] = "<ul><li>" . join("</li><li>", $value) . "</li></ul>";
                     $data[$key . "_sentence_list"] = Helper::makeSentenceList($value);
                     $data[$key . "_ampersand_sentence_list"] = Helper::makeSentenceList($value, "&", false);
                     // handle taxonomies
                     if (Taxonomy::isTaxonomy($key)) {
                         $url_list = array_map(function ($item) use($data, $key, $value) {
                             return '<a href="' . Taxonomy::getURL($data['_folder'], $key, $item) . '">' . $item . '</a>';
                         }, $value);
                         $data[$key . "_url_list"] = join(", ", $url_list);
                         $data[$key . "_spaced_url_list"] = join(" ", $url_list);
                         $data[$key . "_ordered_url_list"] = "<ol><li>" . join("</li><li>", $url_list) . "</li></ol>";
                         $data[$key . "_unordered_url_list"] = "<ul><li>" . join("</li><li>", $url_list) . "</li></ul>";
                         $data[$key . "_sentence_url_list"] = Helper::makeSentenceList($url_list);
                         $data[$key . "_ampersand_sentence_url_list"] = Helper::makeSentenceList($url_list, "&", false);
                     }
                 }
             }
         }
         // update content with supplemented data merged with global config data
         if ($context['merge_with_data'] || $context['inherit_folder_data']) {
             $folder_data = array();
             $all_config = array();
             if ($context['inherit_folder_data']) {
                 $folder_data = $this->getFolderData($data['_file']);
             }
             if ($context['merge_with_data']) {
                 $all_config = Config::getAll();
             }
             // merge them all together
             $this->content[$content_key] = $data + $folder_data + $all_config;
         } else {
             $this->content[$content_key] = $data;
         }
     }
     Debug::markEnd($hash);
 }
Example #25
0
        if ($path !== "/404") {
            $content_found = true;
        }

    // url is taxonomy-based
    } elseif (Taxonomy::isTaxonomyURL($path)) {
        list($type, $slug) = Taxonomy::getCriteria($path);

        // create data array
        $data = array_merge(Config::getAll(), array(
            'homepage'       => Config::getSiteRoot(),
            'raw_url'        => Request::getResourceURI(),
            'page_url'       => Request::getResourceURI(),
            'taxonomy_slug'  => urldecode($slug),
            'taxonomy_name'  => Taxonomy::getTaxonomyName($type, $slug)
        ));

        $template_list[] = "taxonomies";
        $template_list[] = $type;
        $content_found = true;
    }

    
    // content was found
    if ($content_found) {
        // mark milestone for debug panel
        Debug::markMilestone('content found');
        
        // protect
        if (is_array($data) && $data) {
Example #26
0
File: routes.php Project: nob/joi
     // actual file exists
 } elseif (File::exists("{$content_root}/{$path}.{$content_type}")) {
     $add_prev_next = true;
     $template_list[] = 'post';
     $page = basename($path);
     $data = Content::get($complete_current_url);
     $data['current_url'] = $current_url;
     $data['slug'] = basename($current_url);
     if ($path !== "404") {
         $content_found = true;
     }
     // url is taxonomy-based
 } elseif (Taxonomy::isTaxonomyURL($path)) {
     list($type, $slug) = Taxonomy::getCriteria($path);
     // create data array
     $data = array_merge(Config::getAll(), array('homepage' => Config::getSiteRoot(), 'raw_url' => Request::getResourceURI(), 'page_url' => Request::getResourceURI(), 'taxonomy_slug' => urldecode($slug), 'taxonomy_name' => Taxonomy::getTaxonomyName($type, $slug)));
     $template_list[] = "taxonomies";
     $template_list[] = $type;
     $content_found = true;
     // this is a directory,so we look for page.md
 } elseif (is_dir("{$content_root}/{$path}")) {
     $data = Content::get($complete_current_url);
     $content_found = true;
 }
 // Nothing found. 404 O'Clock.
 if (!$content_found || $requesting_xml && (!isset($data['_type']) || $data['_type'] != 'xml')) {
     // determine where user came from for log message
     if (strstr($path, 'favicon.ico')) {
         // Favicons are annoying.
         Log::info("The site favicon could not be found.", "site", "favicon");
     } else {
 protected function renderContent()
 {
     //Get some pre value from URL
     //The type of the content we want to create
     $type = isset($_GET['type']) ? strtolower(trim($_GET['type'])) : '';
     //If it has guid, it means this is a translated version
     $guid = isset($_GET['guid']) ? strtolower(trim($_GET['guid'])) : '';
     //Get the list of Content Type
     $types = GxcHelpers::getAvailableContentType();
     //List of language that should exclude not to translate
     $lang_exclude = array();
     //List of translated versions
     $versions = array();
     //Available Terms for this Object Type
     $terms = array();
     //Selected Terms
     $selected_terms = array();
     //Get Term Order
     $term_orders = ConstantDefine::getTermOrder();
     //If $type is empty then redirect to choose content type page
     if ($type != '') {
         //Check if the type appear in content type Definition
         if (array_key_exists($type, $types)) {
             // If the guid is not empty, it means we are creating a translated version of a content
             // We will exclude the translated language and include the name of the translated content to $versions
             if ($guid != '') {
                 $temp_object = Object::model()->findAll('guid=:gid', array(':gid' => $guid));
                 if (count($temp_object) > 0) {
                     foreach ($temp_object as $obj) {
                         $lang_exclude[] = $obj->lang;
                         $langs = GxcHelpers::getAvailableLanguages();
                         $versions[] = $obj->object_name . ' - ' . $langs[$obj->lang]['name'];
                     }
                 }
             }
             //Import the Content Type Class
             Yii::import('common.content_type.' . $type . '.' . $types[$type]['class']);
             //Init the class
             $typeClassObj = new $types[$type]['class']();
             $content_resources = $typeClassObj->Resources();
             //We start to implement the checking Permission HERE
             $param_content_check = array();
             $data_content_check = array();
             $param_content_check['type'] = $type;
             if (GxcContentPermission::checkCreatePermission($param_content_check, $data_content_check, $typeClassObj->Permissions())) {
                 $param_content_check['new_content'] = true;
                 $content_status = GxcContentPermission::getContentStatus($param_content_check, $data_content_check, $typeClassObj->Permissions());
                 $model = new $types[$type]['class']();
                 // Uncomment the following line if AJAX validation is needed
                 // $this->performAjaxValidation($model);
                 $model->object_date = date('Y-m-d H:i:s');
                 $model->person = '';
                 $model->guid = $guid;
                 $get_languages = GxcHelpers::loadLanguageItems($lang_exclude);
                 $available_languages = array();
                 foreach ($get_languages as $key => $value) {
                     $available_languages[] = $key;
                 }
                 //Get available Taxonomy and Terms for this Object
                 $available_taxonomy = Taxonomy::model()->findAll(' type = :type AND lang IN (' . implode(',', $available_languages) . ') ', array(':type' => $type));
                 if ($available_taxonomy) {
                     foreach ($available_taxonomy as $t) {
                         $temp = array();
                         $temp['id'] = $t->taxonomy_id;
                         $temp['lang'] = $t->lang;
                         $temp['name'] = $t->name;
                         $temp['terms'] = array();
                         //Look for the Term Items belong to this Taxonomy
                         $list_terms = Term::model()->findAll(array('select' => '*', 'condition' => 'taxonomy_id=:id', 'order' => 't.parent ASC, t.order ASC', 'params' => array(':id' => $t->taxonomy_id)));
                         if ($list_terms) {
                             foreach ($list_terms as $term) {
                                 $temp_item['id'] = $term->term_id;
                                 $temp_item['name'] = CHtml::encode($term->name);
                                 $temp_item['parent'] = $term->parent;
                                 $temp['terms']['item_' . $term->term_id] = $temp_item;
                             }
                         }
                         $terms[$t->taxonomy_id] = $temp;
                     }
                 }
                 if (isset($_POST[$types[$type]['class']])) {
                     $model->attributes = $_POST[$types[$type]['class']];
                     //Convert the date time publish to timestamp
                     $model->object_date = strtotime($model->object_date);
                     $model->object_date_gmt = local_to_gmt($model->object_date);
                     //Check which button the User click To Send to person or group
                     $button = $_POST['which_button'];
                     $trans = new Transfer();
                     // Get the Terms that the User Choose
                     //
                     $post_terms = isset($_POST['terms']) ? $_POST['terms'] : array();
                     $selected_terms = array();
                     if (!empty($post_terms)) {
                         foreach ($post_terms as $t) {
                             $t = explode('_', $t);
                             if (!isset($selected_terms[$t[1]])) {
                                 $selected_temp = array();
                                 $selected_temp['id'] = $terms[$t[1]]['id'];
                                 $selected_temp['lang'] = $terms[$t[1]]['lang'];
                                 $selected_temp['name'] = $terms[$t[1]]['name'];
                                 $selected_temp['terms']['item_' . $t[0]]['id'] = $t[0];
                                 $selected_temp['terms']['item_' . $t[0]]['name'] = $terms[$t[1]]['terms']['item_' . $t[0]]['name'];
                                 $selected_temp['terms']['item_' . $t[0]]['parent'] = $terms[$t[1]]['terms']['item_' . $t[0]]['parent'];
                                 $selected_temp['terms']['item_' . $t[0]]['data'] = $t[2];
                                 $selected_temp['terms']['item_' . $t[0]]['data_name'] = $term_orders[$t[2]];
                                 $selected_terms[$t[1]] = $selected_temp;
                             } else {
                                 if (!isset($selected_terms['terms']['item_' . $t[0]])) {
                                     $selected_terms[$t[1]]['terms']['item_' . $t[0]]['id'] = $t[0];
                                     $selected_terms[$t[1]]['terms']['item_' . $t[0]]['name'] = $terms[$t[1]]['terms']['item_' . $t[0]]['name'];
                                     $selected_terms[$t[1]]['terms']['item_' . $t[0]]['parent'] = $terms[$t[1]]['terms']['item_' . $t[0]]['parent'];
                                     $selected_terms[$t[1]]['terms']['item_' . $t[0]]['data'] = $t[2];
                                     $selected_terms[$t[1]]['terms']['item_' . $t[0]]['data_name'] = $term_orders[$t[2]];
                                 }
                             }
                         }
                     }
                     // After having the selected Terms, we need to make sure  all parents
                     // of the selected Terms must be added also
                     foreach ($selected_terms as $tx_key => $t) {
                         $array_parent_selected_terms = array();
                         foreach ($t['terms'] as $key => $st_terms) {
                             $current_term = $st_terms;
                             while ($current_term['parent'] != 0) {
                                 if (!isset($array_parent_selected_terms['item_' . $current_term['parent']]) && !isset($t['terms']['item_' . $current_term['parent']])) {
                                     $array_parent_selected_terms['item_' . $current_term['parent']] = $terms[$tx_key]['terms']['item_' . $current_term['parent']];
                                     $array_parent_selected_terms['item_' . $current_term['parent']]['data'] = key($term_orders);
                                     $array_parent_selected_terms['item_' . $current_term['parent']]['data_name'] = $term_orders[key($term_orders)];
                                 }
                                 $current_term = $terms[$tx_key]['terms']['item_' . $current_term['parent']];
                             }
                         }
                         $selected_terms[$tx_key]['terms'] = CMap::mergeArray($t['terms'], $array_parent_selected_terms);
                     }
                     //Re-Set the Status based on what User Chooose
                     //The content is sent to ROLES OR STATUS
                     if ($button == '1') {
                         //Check if the object_status is number or character
                         if (!is_numeric($model->object_status)) {
                             //Set the status to Pending
                             $trans->note = $model->object_status;
                             $model->object_status = ConstantDefine::OBJECT_STATUS_PENDING;
                             $trans->type = ConstantDefine::TRANS_ROLE;
                             $trans->after_status = ConstantDefine::OBJECT_STATUS_PENDING;
                         } else {
                             $trans->type = ConstantDefine::TRANS_STATUS;
                             $trans->after_status = $model->object_status;
                         }
                         $trans->from_user_id = user()->id;
                         $trans->to_user_id = 0;
                         $trans->before_status = ConstantDefine::OBJECT_STATUS_DRAFT;
                     }
                     //The content is sent to PERSON DIRECTLY
                     if ($button == '2') {
                         $to_user_id = User::findPeople($model->person);
                         //Start to Transfer to the user and set the status to Pending
                         if ($to_user_id) {
                             $model->object_status = ConstantDefine::OBJECT_STATUS_PENDING;
                             $trans->from_user_id = user()->id;
                             $trans->to_user_id = $to_user_id->user_id;
                             $trans->type = ConstantDefine::TRANS_PERSON;
                             $trans->before_status = ConstantDefine::OBJECT_STATUS_PENDING;
                             $trans->after_status = ConstantDefine::OBJECT_STATUS_PENDING;
                         } else {
                             $model->addError('person', t('User not found'));
                         }
                     }
                     //Work with Resource Binding
                     $resource = array();
                     $resource_upload = array();
                     foreach ($content_resources as $res) {
                         $resource_upload[] = GxcHelpers::getArrayResourceObjectBinding('resource_upload_' . $res['type']);
                     }
                     $i = 0;
                     $count_resource = 0;
                     foreach ($content_resources as $cres) {
                         $j = 1;
                         foreach ($resource_upload[$i] as $res_up) {
                             $j++;
                             $count_resource++;
                         }
                         $i++;
                     }
                     $model->total_number_resource = $count_resource;
                     if ($model->save()) {
                         user()->setFlash('success', t('cms', 'Create new Content Successfully!'));
                         $trans->object_id = $model->object_id;
                         $trans->save();
                         // We have all the selected Terms for now
                         // We will add them to Object Terms
                         foreach ($selected_terms as $tx_key => $t) {
                             foreach ($t['terms'] as $key => $st_terms) {
                                 $obj_term = new ObjectTerm();
                                 $obj_term->object_id = $model->object_id;
                                 $obj_term->term_id = $st_terms['id'];
                                 $obj_term->data = $st_terms['data'];
                                 $obj_term->save();
                                 unset($obj_term);
                             }
                         }
                         //Update Resource Binding Here
                         $i = 0;
                         $count_resource = 0;
                         foreach ($content_resources as $cres) {
                             $j = 1;
                             foreach ($resource_upload[$i] as $res_up) {
                                 $obj_res = new ObjectResource();
                                 $obj_res->resource_id = $res_up['resid'];
                                 $obj_res->object_id = $model->object_id;
                                 $obj_res->description = '';
                                 $obj_res->type = $cres['type'];
                                 $obj_res->resource_order = $j;
                                 $obj_res->save();
                                 $j++;
                                 $count_resource++;
                             }
                             $i++;
                         }
                         //Re-init new Model
                         $model = new $types[$type]['class']();
                         $model->object_date = date('Y-m-d H:i:s');
                         Yii::app()->controller->refresh();
                     } else {
                         $model->object_date = date('Y-m-d H:i:s', $model->object_date);
                     }
                 }
                 $render_template = 'cmswidgets.views.object.object_form_widget';
                 if (file_exists(Yii::getPathOfAlias('common.content_type.' . strtolower($type) . '.object_form_widget') . '.php')) {
                     $render_template = 'common.content_type.' . strtolower($type) . '.object_form_widget';
                 }
                 $this->render($render_template, array('model' => $model, 'versions' => $versions, 'lang_exclude' => $lang_exclude, 'content_status' => $content_status, 'terms' => $terms, 'selected_terms' => $selected_terms, 'type' => $type, 'content_resources' => $content_resources));
             }
         } else {
             //The type is not in Content Type Definition
             $this->render('cmswidgets.views.object.object_start_widget', array('types' => $types));
         }
     } else {
         //There is no Type in $_GET
         $this->render('cmswidgets.views.object.object_start_widget', array('types' => $types));
     }
 }
Example #28
0
 /**
  * Create taxonomy repository class.
  *
  * @access public
  *
  * @param  string       $name
  * @param  array|string $args
  */
 public function create_taxonomy($name, $args = [])
 {
     $this->arguments($name, $args);
     return Taxonomy::init($name, $args);
 }
Example #29
0
    /**
     * Returns a ContentSet object with the appropriate content
     *
     * @param array  $settings  Settings for filtering content and such
     * @return ContentSet
     */
    private function getContentSet($settings)
    {
        // create a unique hash for these settings
        $content_hash = Helper::makeHash($settings);

        if ($this->blink->exists($content_hash)) {
            // blink content exists, use that
            $content_set = new ContentSet($this->blink->get($content_hash));
        } else {
            // no blink content exists, get data the hard way
            if ($settings['taxonomy']) {
                $taxonomy_parts  = Taxonomy::getCriteria(URL::getCurrent());
                $taxonomy_type   = $taxonomy_parts[0];
                $taxonomy_slug   = Config::get('_taxonomy_slugify') ? Slug::humanize($taxonomy_parts[1]) : urldecode($taxonomy_parts[1]);

                $content_set = ContentService::getContentByTaxonomyValue($taxonomy_type, $taxonomy_slug, $settings['folders']);
            } else {
                $content_set = ContentService::getContentByFolders($settings['folders']);
            }

            // filter
            $content_set->filter($settings);

            // grab total entries for setting later
            $total_entries = $content_set->count();

            // pre-sort supplement
            $content_set->supplement(array('total_found' => $total_entries) + $settings);

            // sort
            $content_set->multisort($settings['sort']);            
            
            // post-sort supplement
            $content_set->supplement(array(
                'group_by_date' => trim($this->fetchParam("group_by_date", null, null, false, false))
            ), true);

            // store content as blink content for future use
            $this->blink->set($content_hash, $content_set->extract());
        }

        return $content_set;
    }
Example #30
0
 /**
  * Gets the target data from the cache
  *
  * @param array  $config  Configuration array
  * @return array
  */
 public function getData($config)
 {
     // load data
     if ($config['taxonomy']) {
         $taxonomy_parts = Taxonomy::getCriteria(URL::getCurrent());
         $taxonomy_type = $taxonomy_parts[0];
         $taxonomy_slug = Config::get('_taxonomy_slugify') ? Slug::humanize($taxonomy_parts[1]) : urldecode($taxonomy_parts[1]);
         $content_set = ContentService::getContentByTaxonomyValue($taxonomy_type, $taxonomy_slug, $config['folders']);
     } else {
         $content_set = ContentService::getContentByFolders($config['folders']);
     }
     // filters
     $content_set->filter($config);
     // custom filter, remove the 404 page if needed
     if (!$config['include_404']) {
         $content_set->customFilter(function ($item) {
             return $item['url'] !== '/404';
         });
     }
     // custom filter, remove any excluded folders
     if ($config['exclude']) {
         $excluded = Parse::pipeList($config['exclude']);
         $content_set->customFilter(function ($item) use($excluded) {
             foreach ($excluded as $exclude) {
                 if ($exclude === "*" || $exclude === "/*") {
                     // exclude all
                     return false;
                 } elseif (substr($exclude, -1) === "*") {
                     // wildcard check
                     if (strpos($item['_folder'], substr($exclude, 0, -1)) === 0) {
                         return false;
                     }
                 } else {
                     // plain check
                     if ($exclude == $item['_folder']) {
                         return false;
                     }
                 }
             }
             return true;
         });
     }
     $content_set->supplement(array('merge_with_data' => false));
     $content_set->prepare($config['include_content']);
     $data = $content_set->get();
     return $data;
 }