/** * Check if a row of today's counter status exists * * @param integer $site_srl Site_srl * @return bool */ function isInsertedTodayStatus($site_srl = 0) { $args = new stdClass(); $args->regdate = date('Ymd'); $cache_key = 'counter:insertedTodayStatus:' . $site_srl . '_' . $args->regdate; $insertedTodayStatus = Rhymix\Framework\Cache::get($cache_key); if (!$insertedTodayStatus) { if ($site_srl) { $args->site_srl = $site_srl; $output = executeQuery('counter.getSiteTodayStatus', $args); } else { $output = executeQuery('counter.getTodayStatus', $args); } $insertedTodayStatus = !!$output->data->count; if ($insertedTodayStatus) { Rhymix\Framework\Cache::set($cache_key, true, 0, true); $_old_date = date('Ymd', strtotime('-1 day')); Rhymix\Framework\Cache::delete('counter:insertedTodayStatus:' . $site_srl . '_' . $_old_date); } } return $insertedTodayStatus; }
/** * Get one of layout information created in the DB * Return DB info + XML info of the generated layout * @param int $layout_srl * @return object info of layout */ function getLayout($layout_srl) { // Get information from cache $layout_info = Rhymix\Framework\Cache::get("layout:{$layout_srl}"); if ($layout_info !== null) { return $layout_info; } // Get information from the DB $args = new stdClass(); $args->layout_srl = $layout_srl; $output = executeQuery('layout.getLayout', $args); if (!$output->data) { return; } // Return xml file informaton after listing up the layout and extra_vars $layout_info = $this->getLayoutInfo($layout, $output->data, $output->data->layout_type); // Store in cache Rhymix\Framework\Cache::set("layout:{$layout_srl}", $layout_info); return $layout_info; }
/** * Get cached data * * @param string $key Cache key * @param int $modified_time Unix time of data modified. * If stored time is older then modified time, return false. * @return false|mixed Return false on failure or older then modified time. Return the string associated with the $key on success. */ public function get($key, $modified_time = 0) { $value = Rhymix\Framework\Cache::get($key); return $value === null ? false : $value; }
/** * @brief Get a list of groups */ function getGroups($site_srl = 0) { if (!$GLOBALS['__group_info__'][$site_srl]) { $result = array(); if (!isset($site_srl)) { $site_srl = 0; } $group_list = Rhymix\Framework\Cache::get("member:member_groups:site:{$site_srl}"); if (!$group_list) { $args = new stdClass(); $args->site_srl = $site_srl; $args->sort_index = 'list_order'; $args->order_type = 'asc'; $output = executeQueryArray('member.getGroups', $args); $group_list = $output->data; Rhymix\Framework\Cache::set("member:member_groups:site:{$site_srl}", $group_list, 0, true); } if (!$group_list) { return array(); } foreach ($group_list as $val) { $result[$val->group_srl] = $val; } $GLOBALS['__group_info__'][$site_srl] = $result; } return $GLOBALS['__group_info__'][$site_srl]; }
/** * Add OpenGraph metadata tags. * * @param string $output * @return void */ function _addOpenGraphMetadata() { // Get information about the current request. $page_type = 'website'; $current_module_info = Context::get('current_module_info'); $site_module_info = Context::get('site_module_info'); $document_srl = Context::get('document_srl'); if ($document_srl) { $oDocument = Context::get('oDocument') ?: getModel('document')->getDocument($document_srl, false, false); if ($oDocument instanceof documentItem && $oDocument->document_srl == $document_srl && !$oDocument->isSecret()) { $page_type = 'article'; } } // Add basic metadata. Context::addOpenGraphData('og:title', Context::getBrowserTitle()); Context::addOpenGraphData('og:site_name', Context::getSiteTitle()); if ($page_type === 'article' && config('seo.og_extract_description')) { $description = trim(utf8_normalize_spaces($oDocument->getContentText(200))); } else { $description = Context::getMetaTag('description'); } Context::addOpenGraphData('og:description', $description); Context::addMetaTag('description', $description); // Add metadata about this page. Context::addOpenGraphData('og:type', $page_type); if ($page_type === 'article') { $canonical_url = getFullUrl('', 'mid', $current_module_info->mid, 'document_srl', $document_srl); } elseif (($page = Context::get('page')) > 1) { $canonical_url = getFullUrl('', 'mid', $current_module_info->mid, 'page', $page); } elseif ($current_module_info->module_srl == $site_module_info->module_srl) { $canonical_url = getFullUrl(''); } else { $canonical_url = getFullUrl('', 'mid', $current_module_info->mid); } Context::addOpenGraphData('og:url', $canonical_url); Context::setCanonicalURL($canonical_url); // Add metadata about the locale. $lang_type = Context::getLangType(); $locales = (include \RX_BASEDIR . 'common/defaults/locales.php'); if (isset($locales[$lang_type])) { Context::addOpenGraphData('og:locale', $locales[$lang_type]['locale']); } if ($page_type === 'article' && $oDocument->getLangCode() !== $lang_type && isset($locales[$oDocument->getLangCode()])) { Context::addOpenGraphData('og:locale:alternate', $locales[$oDocument->getLangCode()]); } // Add image. if ($page_type === 'article' && config('seo.og_extract_images')) { if (($document_images = Rhymix\Framework\Cache::get("seo:document_images:{$document_srl}")) === null) { $document_images = array(); if ($oDocument->hasUploadedFiles()) { foreach ($oDocument->getUploadedFiles() as $file) { if ($file->isvalid !== 'Y' || !preg_match('/\\.(?:bmp|gif|jpe?g|png)$/i', $file->uploaded_filename)) { continue; } list($width, $height) = @getimagesize($file->uploaded_filename); if ($width < 100 && $height < 100) { continue; } $image = array('filepath' => $file->uploaded_filename, 'width' => $width, 'height' => $height); if ($file->cover_image === 'Y') { array_unshift($document_images, $image); } else { $document_images[] = $image; } if (count($document_images) >= 1) { break; } } } Rhymix\Framework\Cache::set("seo:document_images:{$document_srl}", $document_images, 0, true); } } else { $document_images = null; } if ($document_images) { $first_image = reset($document_images); $first_image['filepath'] = preg_replace('/^.\\/files\\//', \RX_BASEURL . 'files/', $first_image['filepath']); Context::addOpenGraphData('og:image', Rhymix\Framework\URL::getCurrentDomainURL($first_image['filepath'])); Context::addOpenGraphData('og:image:width', $first_image['width']); Context::addOpenGraphData('og:image:height', $first_image['height']); } elseif ($default_image = getAdminModel('admin')->getSiteDefaultImageUrl($width, $height)) { Context::addOpenGraphData('og:image', Rhymix\Framework\URL::getCurrentDomainURL($default_image)); if ($width && $height) { Context::addOpenGraphData('og:image:width', $width); Context::addOpenGraphData('og:image:height', $height); } } // Add datetime for articles. if ($page_type === 'article' && config('seo.og_use_timestamps')) { Context::addOpenGraphData('article:published_time', $oDocument->getRegdate('c')); Context::addOpenGraphData('article:modified_time', $oDocument->getUpdate('c')); } }
/** * @brief Get module grants */ function getModuleGrants($module_srl) { $output = Rhymix\Framework\Cache::get("site_and_module:module_grants:{$module_srl}"); if ($output === null) { $args = new stdClass(); $args->module_srl = $module_srl; $output = executeQueryArray('module.getModuleGrants', $args); Rhymix\Framework\Cache::set("site_and_module:module_grants:{$module_srl}", $output, 0, true); } return $output; }
/** * Get data from database, and set the value to documentItem object * @param bool $load_extra_vars * @return void */ function _loadFromDB($load_extra_vars = true) { if (!$this->document_srl) { return; } $document_item = false; $cache_put = false; $columnList = array(); $reload_counts = true; if ($this->columnList === false) { $reload_counts = false; } $this->columnList = array(); // cache controll $cache_key = 'document_item:' . getNumberingPath($this->document_srl) . $this->document_srl; $document_item = Rhymix\Framework\Cache::get($cache_key); if ($document_item) { $columnList = array('readed_count', 'voted_count', 'blamed_count', 'comment_count', 'trackback_count'); } if (!$document_item || $reload_counts) { $args = new stdClass(); $args->document_srl = $this->document_srl; $output = executeQuery('document.getDocument', $args, $columnList); } if (!$document_item) { $document_item = $output->data; if ($document_item) { Rhymix\Framework\Cache::set($cache_key, $document_item); } } else { $document_item->readed_count = $output->data->readed_count; $document_item->voted_count = $output->data->voted_count; $document_item->blamed_count = $output->data->blamed_count; $document_item->comment_count = $output->data->comment_count; $document_item->trackback_count = $output->data->trackback_count; } $this->setAttribute($document_item, $load_extra_vars); }
/** * @brief Widget cache handling */ function getCache($widget, $args, $lang_type = null, $ignore_cache = false, $override_sequence = false) { // Use the current language if not otherwise specified if (!$lang_type) { $lang_type = Context::getLangType(); } // Fix the widget sequence if it is missing $widget_sequence = $override_sequence ?: $args->widget_sequence; if (!$widget_sequence) { $widget_sequence = sha1(json_encode($args)); } // Set the widget cache duration $widget_cache = $args->widget_cache; if (preg_match('/^([0-9\\.]+)([smhd])$/i', $widget_cache, $matches)) { $multipliers = array('s' => 1, 'm' => 60, 'h' => 3600, 'd' => 86400); $widget_cache = intval(floatval($matches[1]) * $multipliers[strtolower($matches[2])]); } else { $widget_cache = intval(floatval($widget_cache) * 60); } /** * Even if the cache number and value of the cache and return it to extract data */ if (!$ignore_cache && !$widget_cache) { $oWidget = $this->getWidgetObject($widget); if (!$oWidget || !method_exists($oWidget, 'proc')) { return; } $widget_content = $oWidget->proc($args); $oModuleController = getController('module'); $oModuleController->replaceDefinedLangCode($widget_content); return $widget_content; } $cache_data = Rhymix\Framework\Cache::get('widget_cache:' . $widget_sequence); if ($cache_data) { return preg_replace('@<\\!--#Meta:@', '<!--Meta:', $cache_data); } $oWidget = $this->getWidgetObject($widget); if (!$oWidget || !method_exists($oWidget, 'proc')) { return; } $widget_content = $oWidget->proc($args); $oModuleController = getController('module'); $oModuleController->replaceDefinedLangCode($widget_content); Rhymix\Framework\Cache::set('widget_cache:' . $widget_sequence, $widget_content, $widget_cache, true); return $widget_content; }
/** * Function to retrieve the key values of the extended variable document * $Form_include: writing articles whether to add the necessary extensions of the variable input form * @param int $module_srl * @return array */ function getExtraKeys($module_srl) { if (!isset($GLOBALS['XE_EXTRA_KEYS'][$module_srl])) { $keys = Rhymix\Framework\Cache::get("site_and_module:module_document_extra_keys:{$module_srl}"); $oExtraVar = ExtraVar::getInstance($module_srl); if ($keys === null) { $obj = new stdClass(); $obj->module_srl = $module_srl; $obj->sort_index = 'var_idx'; $obj->order = 'asc'; $output = executeQueryArray('document.getDocumentExtraKeys', $obj); // correcting index order $isFixed = FALSE; if (is_array($output->data)) { $prevIdx = 0; foreach ($output->data as $no => $value) { // case first if ($prevIdx == 0 && $value->idx != 1) { $args = new stdClass(); $args->module_srl = $module_srl; $args->var_idx = $value->idx; $args->new_idx = 1; executeQuery('document.updateDocumentExtraKeyIdx', $args); executeQuery('document.updateDocumentExtraVarIdx', $args); $prevIdx = 1; $isFixed = TRUE; continue; } // case others if ($prevIdx > 0 && $prevIdx + 1 != $value->idx) { $args = new stdClass(); $args->module_srl = $module_srl; $args->var_idx = $value->idx; $args->new_idx = $prevIdx + 1; executeQuery('document.updateDocumentExtraKeyIdx', $args); executeQuery('document.updateDocumentExtraVarIdx', $args); $prevIdx += 1; $isFixed = TRUE; continue; } $prevIdx = $value->idx; } } if ($isFixed) { $output = executeQueryArray('document.getDocumentExtraKeys', $obj); } $oExtraVar->setExtraVarKeys($output->data); $keys = $oExtraVar->getExtraVars(); if (!$keys) { $keys = array(); } Rhymix\Framework\Cache::set("site_and_module:module_document_extra_keys:{$module_srl}", $keys, 0, true); } $GLOBALS['XE_EXTRA_KEYS'][$module_srl] = $keys; } return $GLOBALS['XE_EXTRA_KEYS'][$module_srl]; }