Exemplo n.º 1
0
 /**
  * Register Shortcode
  */
 public static function register_shortcode($args, $mid_content = null)
 {
     //$dbg = new EssGridMemoryUsageInformation();
     //$dbg->setStart();
     //$dbg->setMemoryUsage('Before ShortCode');
     $caching = get_option('tp_eg_use_cache', 'false');
     $grid = new Essential_Grid();
     extract(shortcode_atts(array('alias' => '', 'settings' => '', 'layers' => '', 'images' => '', 'posts' => '', 'special' => ''), $args, 'ess_grid'));
     $eg_alias = $alias != '' ? $alias : implode(' ', $args);
     if ($settings !== '') {
         $grid->custom_settings = json_decode(str_replace(array('({', '})', "'"), array('[', ']', '"'), $settings), true);
     }
     if ($layers !== '') {
         $grid->custom_layers = json_decode(str_replace(array('({', '})', "'"), array('[', ']', '"'), $layers), true);
     }
     if ($images !== '') {
         $grid->custom_images = explode(',', $images);
     }
     if ($posts !== '') {
         $grid->custom_posts = explode(',', $posts);
     }
     if ($special !== '') {
         $grid->custom_special = $special;
     }
     if ($settings !== '' || $layers !== '' || $images !== '' || $posts !== '' || $special !== '') {
         //disable caching if one of this is set
         $caching = 'false';
     }
     $grid->check_for_shortcodes($mid_content);
     //check for example on gallery shortcode and do stuff
     if ($eg_alias == '') {
         $eg_alias = implode(' ', $args);
     }
     $content = false;
     $grid_id = self::get_id_by_alias($eg_alias);
     if ($grid_id == '0') {
         //grid is created by custom settings. Check if layers and settings are set
         ob_start();
         $grid->output_essential_grid_by_settings();
         $content = ob_get_contents();
         ob_clean();
         ob_end_clean();
     } else {
         if ($caching == 'true') {
             //check if we use total caching
             //add wpml transient
             $lang_code = '';
             if (Essential_Grid_Wpml::is_wpml_exists()) {
                 $lang_code = Essential_Grid_Wpml::get_current_lang_code();
             }
             $content = get_transient('ess_grid_trans_full_grid_' . $grid_id . $lang_code);
         }
         if ($content == false) {
             ob_start();
             $grid->output_essential_grid_by_alias($eg_alias);
             $content = ob_get_contents();
             ob_clean();
             ob_end_clean();
             if ($caching == 'true') {
                 set_transient('ess_grid_trans_full_grid_' . $grid_id . $lang_code, $content, 60 * 60 * 24 * 7);
             }
         }
     }
     $output_protection = get_option('tp_eg_output_protection', 'none');
     //$dbg->setMemoryUsage('After ShortCode');
     //$dbg->setEnd();
     //$dbg->printMemoryUsageInformation();
     //handle output types
     switch ($output_protection) {
         case 'compress':
             $content = str_replace("\n", '', $content);
             $content = str_replace("\r", '', $content);
             return $content;
             break;
         case 'echo':
             echo $content;
             //bypass the filters
             break;
         default:
             //normal output
             return $content;
             break;
     }
 }