/** * 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 display the board conent view **/ function dispBoardContentView() { // get the variable value $document_srl = Context::get('document_srl'); $page = Context::get('page'); // generate document model object $oDocumentModel = getModel('document'); /** * if the document exists, then get the document information **/ if ($document_srl) { $oDocument = $oDocumentModel->getDocument($document_srl, false, true); // if the document is existed if ($oDocument->isExists()) { // if the module srl is not consistent if ($oDocument->get('module_srl') != $this->module_info->module_srl) { return $this->stop('msg_invalid_request'); } // check the manage grant if ($this->grant->manager) { $oDocument->setGrant(); } // if the consultation function is enabled, and the document is not a notice if ($this->consultation && !$oDocument->isNotice()) { $logged_info = Context::get('logged_info'); if ($oDocument->get('member_srl') != $logged_info->member_srl) { $oDocument = $oDocumentModel->getDocument(0); } } // if the document is TEMP saved, check Grant if ($oDocument->getStatus() == 'TEMP') { if (!$oDocument->isGranted()) { $oDocument = $oDocumentModel->getDocument(0); } } } else { // if the document is not existed, then alert a warning message Context::set('document_srl', '', true); $this->alertMessage('msg_not_founded'); } /** * if the document is not existed, get an empty document **/ } else { $oDocument = $oDocumentModel->getDocument(0); } /** *check the document view grant **/ if ($oDocument->isExists()) { if (!$this->grant->view && !$oDocument->isGranted()) { $oDocument = $oDocumentModel->getDocument(0); Context::set('document_srl', '', true); $this->alertMessage('msg_not_permitted'); } else { // add the document title to the browser Context::setCanonicalURL($oDocument->getPermanentUrl()); $seo_title = config('seo.document_title') ?: '$SITE_TITLE - $DOCUMENT_TITLE'; getController('module')->replaceDefinedLangCode($seo_title); Context::setBrowserTitle($seo_title, array('site_title' => Context::getSiteTitle(), 'site_subtitle' => Context::getSiteSubtitle(), 'subpage_title' => $this->module_info->browser_title, 'document_title' => $oDocument->getTitleText(), 'page' => Context::get('page') ?: 1)); // update the document view count (if the document is not secret) if (!$oDocument->isSecret() || $oDocument->isGranted()) { $oDocument->updateReadedCount(); } // disappear the document if it is secret if ($oDocument->isSecret() && !$oDocument->isGranted()) { $oDocument->add('content', lang('thisissecret')); } } } Context::set('update_view', $this->grant->update_view); // setup the document oject on context $oDocument->add('module_srl', $this->module_srl); Context::set('oDocument', $oDocument); /** * add javascript filters **/ Context::addJsFilter($this->module_path . 'tpl/filter', 'insert_comment.xml'); // return new Object(); }