Example #1
0
 /**
  * Parse a plugin tag pair equivalent to channel:categories
  *
  * @param  Closure|null $callback receieves a query builder object as the first parameter
  * @return string
  */
 protected function parseCategories(Closure $callback = null)
 {
     foreach ($this->getCategoriesDefaultParameters() as $key => $value) {
         if (!isset(ee()->TMPL->tagparams[$key])) {
             ee()->TMPL->tagparams[$key] = $value;
         }
     }
     $query = $this->app->make('Category')->nested()->tagparams(ee()->TMPL->tagparams);
     $customFieldsEnabled = ee()->TMPL->fetch_param('disable') !== 'category_fields';
     if ($customFieldsEnabled) {
         $query->withFields();
     }
     if (is_callable($callback)) {
         $callback($query);
     }
     $categories = $query->get();
     $prefix = ee()->TMPL->fetch_param('var_prefix') ? ee()->TMPL->fetch_param('var_prefix') . ':' : '';
     if (preg_match('#{if ' . preg_quote($prefix) . 'no_results}(.*?){/if}#s', ee()->TMPL->tagdata, $match)) {
         ee()->TMPL->tagdata = str_replace($match[0], '', ee()->TMPL->tagdata);
         ee()->TMPL->no_results = $match[1];
     }
     if ($categories->isEmpty()) {
         return ee()->TMPL->no_results();
     }
     if (ee()->TMPL->fetch_param('style') === 'nested') {
         $output = '<ul id="' . ee()->TMPL->fetch_param('id', 'nav_categories') . '" class="' . ee()->TMPL->fetch_param('class', 'nav_categories') . '">';
         foreach ($categories as $category) {
             $output .= $this->categoryToList($category, ee()->TMPL->tagdata, $customFieldsEnabled, $prefix);
         }
         $output .= '</ul>';
     } else {
         $variables = array();
         $this->categoryCollectionToVariables($categories, $variables, $customFieldsEnabled, $prefix);
         $output = ee()->TMPL->parse_variables(ee()->TMPL->tagdata, $variables);
         if ($backspace = ee()->TMPL->fetch_param('backspace')) {
             $output = substr($output, 0, -$backspace);
         }
     }
     return $output;
 }
Example #2
0
 /**
  * Set Eloquent to use CodeIgniter's DB connection
  *
  * Set Deep to use upload prefs from config.php,
  * rather than from DB, if applicable.
  *
  * @return void
  */
 protected static function boot()
 {
     Deep::bootEE(\ee());
 }
Example #3
0
 /**
  * Static method call handler
  * @return mixed
  */
 public static function __callStatic($name, $args)
 {
     static::boot();
     return call_user_func_array(array(Deep::getInstance()->make(static::getAccessor()), $name), $args);
 }