本文整理汇总了PHP中stdClass::to_transient方法的典型用法代码示例。如果您正苦于以下问题:PHP stdClass::to_transient方法的具体用法?PHP stdClass::to_transient怎么用?PHP stdClass::to_transient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stdClass
的用法示例。
在下文中一共展示了stdClass::to_transient方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Renders a displayed gallery on the frontend
* @param C_Displayed_Gallery|stdClass $displayed_gallery
*/
function render($displayed_gallery, $return = FALSE, $mode = null)
{
$retval = '';
$lookup = TRUE;
$cache = C_Photocrati_Cache::get_instance('displayed_gallery_rendering');
// Simply throwing our rendered gallery into a feed will most likely not work correctly.
// The MediaRSS option in NextGEN is available as an alternative.
if (!C_NextGen_Settings::get_instance()->galleries_in_feeds && is_feed()) {
return '';
}
if ($mode == null) {
$mode = 'normal';
}
// Save the displayed gallery as a transient if it hasn't already. Allows for ajax operations
// to add or modify the gallery without losing a retrievable ID
if (!$displayed_gallery->apply_transient()) {
$displayed_gallery->to_transient();
}
// Get the display type controller
$controller = $this->get_registry()->get_utility('I_Display_Type_Controller', $displayed_gallery->display_type);
// Get routing info
$router = $url = C_Router::get_instance();
$url = $router->get_url($router->get_request_uri(), TRUE);
// Should we lookup in cache?
if (is_array($displayed_gallery->container_ids) && in_array('All', $displayed_gallery->container_ids)) {
$lookup = FALSE;
} elseif ($displayed_gallery->source == 'albums' && $controller->param('gallery') or $controller->param('album')) {
$lookup = FALSE;
} elseif ($controller->param('show')) {
$lookup = FALSE;
} elseif ($controller->cachable === FALSE) {
$lookup = FALSE;
}
// Enqueue any necessary static resources
if (!defined('NGG_SKIP_LOAD_SCRIPTS') || !NGG_SKIP_LOAD_SCRIPTS) {
$controller->enqueue_frontend_resources($displayed_gallery);
}
// Try cache lookup, if we're to do so
$key = null;
$html = FALSE;
if ($lookup) {
// The display type may need to output some things
// even when serving from the cache
if ($controller->has_method('cache_action')) {
$retval = $controller->cache_action($displayed_gallery);
}
// Output debug message
$retval .= $this->debug_msg("Lookup!");
// Some settings affect display types
$settings = C_NextGen_Settings::get_instance();
$key_params = apply_filters('ngg_displayed_gallery_cache_params', array($displayed_gallery->get_entity(), $url, $mode, $settings->activateTags, $settings->appendType, $settings->maxImages, $settings->thumbEffect, $settings->thumbCode, $settings->galSort, $settings->galSortDir));
// Any displayed gallery links on the home page will need to be regenerated if the permalink structure
// changes
if (is_home() or is_front_page()) {
$key_params[] = get_option('permalink_structure');
}
// Try getting the rendered HTML from the cache
$key = $cache->generate_key($key_params);
$html = $cache->lookup($key, FALSE);
// Output debug messages
if ($html) {
$retval .= $this->debug_msg("HIT!");
} else {
$retval .= $this->debug_msg("MISS!");
}
// TODO: This is hack. We need to figure out a more uniform way of detecting dynamic image urls
if (strpos($html, C_Photocrati_Settings_Manager::get_instance()->dynamic_thumbnail_slug . '/') !== FALSE) {
$html = FALSE;
// forces the cache to be re-generated
}
} else {
$retval .= $this->debug_msg("Not looking up in cache as per rules");
}
// If we're displaying a variant, I want to know it
if (isset($displayed_gallery->variation) && is_numeric($displayed_gallery->variation) && $displayed_gallery->variation > 0) {
$retval .= $this->debug_msg("Using variation #{$displayed_gallery->variation}!");
}
// If a cached version doesn't exist, then create the cache
if (!$html) {
$retval .= $this->debug_msg("Rendering displayed gallery");
$current_mode = $controller->get_render_mode();
$controller->set_render_mode($mode);
$html = $controller->index_action($displayed_gallery, TRUE);
if ($key != null) {
$cache->update($key, $html, NGG_RENDERING_CACHE_TTL);
}
$controller->set_render_mode($current_mode);
}
$retval .= $html;
if (!$return) {
echo $retval;
}
return $retval;
}
示例2: render
/**
* Renders a displayed gallery on the frontend
* @param C_Displayed_Gallery|stdClass $displayed_gallery
*/
function render($displayed_gallery, $return = FALSE, $mode = null)
{
// Simply throwing our rendered gallery into a feed will most likely not work correctly.
// The MediaRSS option in NextGEN is available as an alternative.
if (is_feed()) {
return '';
}
if ($mode == null) {
$mode = 'normal';
}
// Save the displayed gallery as a transient if it hasn't already. Allows for ajax operations
// to add or modify the gallery without losing a retrievable ID
if (empty($displayed_gallery->transient_id)) {
$displayed_gallery->transient_id = $displayed_gallery->to_transient();
}
// Get the display type controller
$controller = $this->get_registry()->get_utility('I_Display_Type_Controller', $displayed_gallery->display_type);
// Enqueue any necessary static resources
$controller->enqueue_frontend_resources($displayed_gallery);
// Get routing info
$router = $url = C_Router::get_instance();
$url = $router->get_url($router->get_request_uri(), TRUE);
// Should we lookup in cache?
$lookup = TRUE;
if ($displayed_gallery->source == 'random_images') {
$lookup = FALSE;
} elseif (is_array($displayed_gallery->container_ids) && in_array('All', $displayed_gallery->container_ids)) {
$lookup = FALSE;
} elseif ($displayed_gallery->source == 'albums' && $controller->param('gallery') or $controller->param('album')) {
$lookup = FALSE;
} elseif (!$controller->cachable) {
$lookup = FALSE;
}
// Try cache lookup, if we're to do so
$key = null;
$html = FALSE;
if ($lookup) {
// Some settings affect display types
$settings = C_NextGen_Settings::get_instance();
$key_params = apply_filters('ngg_displayed_gallery_cache_params', array($displayed_gallery->get_entity(), $url, $mode, $settings->activateTags, $settings->appendType, $settings->maxImages, $settings->thumbEffect, $settings->thumbCode, $settings->galSort, $settings->galSortDir));
// Try getting the rendered HTML from the cache
$key = C_Photocrati_Cache::generate_key($key_params);
$html = C_Photocrati_Cache::get($key, FALSE);
// TODO: This is hack. We need to figure out a more uniform way of detecting dynamic image urls
if (strpos($html, C_Photocrati_Settings_Manager::get_instance()->dynamic_thumbnail_slug) !== FALSE) {
$html = FALSE;
// forces the cache to be re-generated
}
}
// If a cached version doesn't exist, then create the cache
if (!$html) {
$current_mode = $controller->get_render_mode();
$controller->set_render_mode($mode);
$html = $controller->index_action($displayed_gallery, TRUE);
if ($key != null) {
C_Photocrati_Cache::set($key, $html);
}
$controller->set_render_mode($current_mode);
// Compress the html to avoid wpautop problems
$html = $this->compress_html($html);
}
if (!$return) {
echo $html;
}
return $html;
}