public static function disable() { self::$disabled = true; }
/** * Gets the title of a category from its slug * * @param string $categorySlug * @param string $return * @return void * @author Drew McLellan */ function perch_events_category($id_or_slug, $opts = array(), $return = false) { $id_or_slug = rtrim($id_or_slug, '/'); $default_opts = array('template' => 'category.html', 'skip-template' => false, 'cache' => true); if (!is_array($opts)) { $opts = array('template' => $opts); } if (is_array($opts)) { $opts = array_merge($default_opts, $opts); } else { $opts = $default_opts; } if ($opts['skip-template']) { $return = true; } if ($opts['cache']) { $cache_key = 'perch_events_category' . md5($id_or_slug); $cache = PerchEvents_Cache::get_static($cache_key, 10); } if ($cache) { if ($return) { return $cache; } echo $cache; return ''; } $API = new PerchAPI(1.0, 'perch_events'); $Categories = new PerchEvents_Categories($API); if (is_numeric($id_or_slug)) { $catID = intval($id_or_slug); $Category = $Categories->find_by_slug($catID); } else { $Category = $Categories->find_by_slug($id_or_slug); } if (is_object($Category)) { $Template = $API->get('Template'); $Template->set('events/' . $opts['template'], 'events'); $r = $Template->render($Category); if ($r != '' && $opts['cache']) { PerchEvents_Cache::save_static($cache_key, $r); } if ($return) { return $r; } echo $r; } return false; }
$Form->handle_empty_block_generation($Template); $tags = $Template->find_all_tags_and_repeaters(); $Form->require_field('categoryTitle', 'Required'); $Form->set_required_fields_from_template($Template, $details); if ($Form->submitted()) { $postvars = array('categoryTitle'); $data = $Form->receive($postvars); $prev = false; if (isset($details['categoryDynamicFields'])) { $prev = PerchUtil::json_safe_decode($details['categoryDynamicFields'], true); } $dynamic_fields = $Form->receive_from_template_fields($Template, $prev, $Categories, $Category); $data['categoryDynamicFields'] = PerchUtil::json_safe_encode($dynamic_fields); if (!is_object($Category)) { $data['categorySlug'] = PerchUtil::urlify($data['categoryTitle']); $Category = $Categories->create($data); PerchUtil::redirect($API->app_path() . '/categories/edit/?id=' . $Category->id() . '&created=1'); } $Category->update($data); if (is_object($Category)) { $message = $HTML->success_message('Your category has been successfully edited. Return to %scategory listing%s', '<a href="' . $API->app_path() . '/categories">', '</a>'); } else { $message = $HTML->failure_message('Sorry, that category could not be edited.'); } // clear the caches PerchEvents_Cache::expire_all(); $details = $Category->to_array(); } if (isset($_GET['created']) && !$message) { $message = $HTML->success_message('Your category has been successfully created. Return to %scategory listing%s', '<a href="' . $API->app_path() . '/categories">', '</a>'); }