function getCommentsLink() { if ($this->getVar('comments_link_hidden') == 1) { return ''; } $style = $this->getVar('comments_link_style'); $count = $this->getVar('comments-count'); $link = $this->getVar('link-comment'); $css = $this->getVar('link-comments-class'); if ($count == 0) { return '<a href="' . $link . '#addcomments" class="' . $css . '">' . JText::_('Add comment') . '</a>'; } else { $text = JText::sprintf('Read comments', $count); if ($this->getVar('use-plural-forms', 0)) { $comments_pf = JText::_('comments_pf'); if ($comments_pf != '') { global $mainframe; $pf = JoomlaTuneLanguageTools::getPlural($mainframe->getCfg('lang'), $count, $comments_pf); if ($pf != '') { $text = JText::sprintf('COMMENTS2', $count, $pf); } } } switch ($style) { case -1: return '<span class="' . $css . '">' . $text . '</span>'; break; default: return '<a href="' . $link . '#comments" class="' . $css . '">' . $text . '</a>'; break; } } }
public static function plural($string, $n) { $lang = JoomlaTuneLanguage::getInstance(); $args = func_get_args(); $count = count($args); if ($count > 1) { $suffix = JoomlaTuneLanguageTools::getPluralSuffix($lang->getLanguage(), $n); $key = $string . '_' . $suffix; if ($lang->hasKey($key)) { $args[0] = $lang->_($key); } else { $args[0] = $lang->_($string); } } elseif ($count > 0) { $args[0] = $lang->_($string); } return call_user_func_array('sprintf', $args); }
public static function convertLanguages10() { global $mainframe; $joomlaLanguagesPath = $mainframe->getCfg('absolute_path') . '/language'; $componentPath = $mainframe->getCfg('absolute_path') . '/components/com_jcomments'; require_once $componentPath . '/libraries/convert/utf8.class.php'; require_once $componentPath . '/libraries/joomlatune/filesystem.php'; require_once $componentPath . '/libraries/joomlatune/language.tools.php'; $codeMap = JoomlaTuneLanguageTools::getLanguageCodes(); $joomlaLanguageFiles = JoomlaTuneFS::readDirectory($joomlaLanguagesPath, '[a-z]+\\.xml', false, false); $joomlaLanguages = array(); foreach ($joomlaLanguageFiles as $file) { $joomlaLanguages[] = str_replace('.xml', '', $file); } $path = $componentPath . '/languages'; $filter = '[a-z]{2}-[A-Z]{2}\\.com_jcomments\\.ini'; $files = JoomlaTuneFS::readDirectory($path, $filter, false, true); $files2 = JoomlaTuneFS::readDirectory($path . '/administrator', $filter, false, true); $files = array_merge($files, $files2); foreach ($files as $file) { $m = array(); preg_match('#([a-z]{2}-[A-Z]{2})#', (string) $file, $m); $code = $m[0]; $language = isset($codeMap[$code]) ? $codeMap[$code][0] : ''; $charset = isset($codeMap[$code]) ? $codeMap[$code][1] : 'iso-8859-1'; if ($language != '' && in_array($language, $joomlaLanguages)) { if (defined('_ISO2')) { $charset = strtolower(_ISO2); if ($charset == 'utf-8' || $charset == 'utf8') { $newFile = str_replace($code . '.com_jcomments.ini', $language . '.ini', $file); @copy((string) $file, $newFile); } else { JCommentsInstallerLanguageHelper::_convertFile10($file, $code, $charset, $language); } } else { JCommentsInstallerLanguageHelper::_convertFile10($file, $code, $charset, $language); } } } unset($codeMap); }
/** * Returns correct plural form for specified language and number value * * @static * @public * @param string $code language code * @param int $number number value * @param array $pluralForms array of plural forms for specified language * @param string $defaultText default value if no plural form found * @return string */ function getPlural($code, $number, $pluralForms, $defaultText = '') { // source: http://translate.sourceforge.net/wiki/l10n/pluralforms $rules = array('be-BY' => array(3, '(n%10==1 && n%100!=11 ? 0 : (n%10>=2 && n%10< =4 && (n%100<10 || n%100>=20) ? 1 : 2))'), 'bg-BG' => array(2, '(n != 1)'), 'ca-ES' => array(2, '(n != 1)'), 'cs-CZ' => array(3, '(n==1) ? 0 : ((n>=2 && n<=4) ? 1 : 2)'), 'da-DK' => array(2, '(n != 1)'), 'de-DE' => array(2, '(n != 1)'), 'el-GR' => array(2, '(n != 1)'), 'en-GB' => array(2, '(n != 1)'), 'es-ES' => array(2, '(n != 1)'), 'et-EE' => array(2, '(n != 1)'), 'eu-ES' => array(2, '(n != 1)'), 'fi-FI' => array(2, '(n != 1)'), 'fr-FR' => array(2, '(n > 1)'), 'gl-ES' => array(2, '(n != 1)'), 'hr-HR' => array(3, '(n%10==1 && n%100!=11 ? 0 : (n%10>=2 && n%10<=4 && (n%100<10 or n%100>=20) ? 1 : 2))'), 'hu-HU' => array(1, '0'), 'it-IT' => array(2, '(n != 1)'), 'ja-JP' => array(1, '0'), 'lv-LV' => array(3, '(n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2)'), 'nb-NO' => array(2, '(n != 1)'), 'nl-NL' => array(2, '(n != 1)'), 'pl-PL' => array(3, '(n==1 ? 0 : (n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2))'), 'pt-PT' => array(2, '(n != 1)'), 'pt-BR' => array(2, '(n > 1)'), 'ro-RO' => array(3, '(n==1 ? 0 : (n==0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2)'), 'ru-RU' => array(3, '(n%10==1 && n%100!=11 ? 0 : (n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2))'), 'sk-SK' => array(3, '(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2'), 'sl-SL' => array(4, '(n%100==1 ? 0 : (n%100==2 ? 1 : (n%100==3 || n%100==4 ? 2 : 3)))'), 'sr-YU' => array(4, '(n%10==1 && n%100!=11 ? 0 : (n%10>=2 && n%10<=4 && (n%100<10 or n%100>=20) ? 1 : 2))'), 'sv-SE' => array(2, '(n != 1)'), 'th-TH' => array(1, '0'), 'tr-TR' => array(1, '0'), 'uk-UA' => array(3, '(n%10==1 && n%100!=11 ? 0 : (n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2))')); if (!is_array($pluralForms)) { $pluralForms = explode(';', $pluralForms); } if (!preg_match('#([a-z]{2}-[A-Z]{2})#', $code)) { $code = JoomlaTuneLanguageTools::name2code($code); } if (isset($rules[$code])) { $rule = $rules[$code]; if (count($pluralForms) == $rule[0]) { $expression = str_replace('n', '$number', $rule[1]); $idx = 0; eval('$idx = ' . $expression . ';'); if (isset($pluralForms[$idx])) { return $pluralForms[$idx]; } } } return $defaultText; }
function onPrepareContent(&$article, &$params, $limitstart = 0) { require_once (JCOMMENTS_HELPERS . '/content.php'); // check whether plugin has been unpublished if (!JPluginHelper::isEnabled('content', 'jcomments')) { JCommentsContentPluginHelper::clear($article, true); return ''; } $app = JFactory::getApplication('site'); $option = JRequest::getCmd('option'); $view = JRequest::getCmd('view'); if (!isset($article->id) || ($option != 'com_content' && $option != 'com_alphacontent' && $option != 'com_multicategories')) { return ''; } if (!isset($params) || $params == null) { jimport('joomla.html.parameter'); $params = new JParameter(''); } else if (isset($params->_raw) && strpos($params->_raw, 'moduleclass_sfx') !== false) { return ''; } if ($view == 'frontpage' || $view == 'featured') { if ($this->params->get('show_frontpage', 1) == 0) { return ''; } } require_once (JCOMMENTS_BASE . '/jcomments.config.php'); require_once (JCOMMENTS_BASE . '/jcomments.class.php'); JCommentsContentPluginHelper::processForeignTags($article); $config = JCommentsFactory::getConfig(); $categoryEnabled = JCommentsContentPluginHelper::checkCategory($article->catid); $commentsEnabled = JCommentsContentPluginHelper::isEnabled($article) || $categoryEnabled; $commentsDisabled = JCommentsContentPluginHelper::isDisabled($article) || !$commentsEnabled; $commentsLocked = JCommentsContentPluginHelper::isLocked($article); if ($article->state == -1 && $this->params->get('enable_for_archived', 0) == 0) { $commentsLocked = true; } $config->set('comments_on', intval($commentsEnabled)); $config->set('comments_off', intval($commentsDisabled)); $config->set('comments_locked', intval($commentsLocked)); if ($view != 'article') { $user = JFactory::getUser(); if (JCOMMENTS_JVERSION == '1.5') { $checkAccess = $article->access <= $user->get('aid', 0); } else { $authorised = JAccess::getAuthorisedViewLevels($user->get('id')); $checkAccess = in_array($article->access, $authorised); } if ($checkAccess) { require_once(JPATH_ROOT . '/components/com_content/helpers/route.php'); if (JCOMMENTS_JVERSION == '1.5') { $readmore_link = JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catslug, $article->sectionid)); } else { $readmore_link = JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catid)); } $readmore_register = 0; } else { if (JCOMMENTS_JVERSION == '1.5') { $readmore_link = JRoute::_('index.php?option=com_user&task=register'); } else { $returnURL = JRoute::_(ContentHelperRoute::getArticleRoute($article->slug)); $menu = JFactory::getApplication()->getMenu(); $active = $menu->getActive(); $itemId = $active->id; $link1 = JRoute::_('index.php?option=com_users&view=login&Itemid=' . $itemId); $link = new JURI($link1); $link->setVar('return', base64_encode($returnURL)); $readmore_link = $link; } $readmore_register = 1; } // load template for comments & readmore links $tmpl = JCommentsFactory::getTemplate($article->id, 'com_content', false); $tmpl->load('tpl_links'); $tmpl->addVar('tpl_links', 'comments_link_style', ($readmore_register ? -1 : 1)); $tmpl->addVar('tpl_links', 'content-item', $article); $tmpl->addVar('tpl_links', 'show_hits', intval($this->params->get('show_hits', 0) && $params->get('show_hits', 0))); $readmoreDisabled = false; if (($params->get('show_readmore') == 0) || (@$article->readmore == 0)) { $readmoreDisabled = true; } else if (@$article->readmore > 0) { $readmoreDisabled = false; } if ($this->params->get('readmore_link', 1) == 0) { $readmoreDisabled = true; } $tmpl->addVar('tpl_links', 'readmore_link_hidden', intval($readmoreDisabled)); // don't fill any readmore variable if it disabled if (!$readmoreDisabled) { if ($readmore_register == 1) { $readmore_text = JText::_('LINK_REGISTER_TO_READ_MORE'); } else if (isset($params) && $readmore = $params->get('readmore')) { $readmore_text = $readmore; } else { $readmore_text = JText::_('LINK_READ_MORE'); } $tmpl->addVar('tpl_links', 'link-readmore', $readmore_link); $tmpl->addVar('tpl_links', 'link-readmore-text', $readmore_text); $tmpl->addVar('tpl_links', 'link-readmore-title', $article->title); $tmpl->addVar('tpl_links', 'link-readmore-class', $this->params->get('readmore_css_class', 'readmore-link')); } $commentsDisabled = false; if ($config->getInt('comments_off', 0) == 1) { $commentsDisabled = true; } else if ($config->getInt('comments_on', 0) == 1) { $commentsDisabled = false; } $tmpl->addVar('tpl_links', 'comments_link_hidden', intval($commentsDisabled)); $count = 0; // do not query comments count if comments disabled and link hidden if (!$commentsDisabled) { require_once (JCOMMENTS_MODELS . '/jcomments.php'); $anchor = ""; if ($this->params->get('comments_count', 1) != 0) { $acl = JCommentsFactory::getACL(); $options = array(); $options['object_id'] = (int) $article->id; $options['object_group'] = 'com_content'; $options['published'] = $acl->canPublish() || $acl->canPublishForObject($article->id, 'com_content') ? null : 1; $count = JCommentsModel::getCommentsCount($options); $tmpl->addVar('tpl_links', 'comments-count', $count); $anchor = $count == 0 ? '#addcomment' : '#comments'; if ($count == 0) { $link_text = JText::_('LINK_ADD_COMMENT'); } else { if (JCOMMENTS_JVERSION == '1.5') { require_once (JCOMMENTS_LIBRARIES.'/joomlatune/language.tools.php'); $lang = JFactory::getLanguage(); $suffix = JoomlaTuneLanguageTools::getPluralSuffix($lang->getTag(), $count); $string = 'LINK_READ_COMMENTS'; $key = $string . '_' . $suffix; if (!$lang->hasKey($key)) { $key = $string; } $link_text = JText::sprintf($key, $count); } else { $link_text = JText::plural('LINK_READ_COMMENTS', $count); } } } else { $link_text = JText::_('LINK_ADD_COMMENT'); } $tmpl->addVar('tpl_links', 'link-comment', $readmore_link . $anchor); $tmpl->addVar('tpl_links', 'link-comment-text', $link_text); $tmpl->addVar('tpl_links', 'link-comments-class', $this->params->get('comments_css_class', 'comments-link')); } JCommentsContentPluginHelper::clear($article, true); // hide comments link if comments enabled but link disabled in plugin params if ((($this->params->get('comments_count', 1) == 0) || ($count == 0 && $this->params->get('add_comments', 1) == 0) || ($count == 0 && $readmore_register == 1)) && !$commentsDisabled) { $tmpl->addVar('tpl_links', 'comments_link_hidden', 1); } //links_position if ($this->params->get('links_position', 1) == 1) { $article->text .= $tmpl->renderTemplate('tpl_links'); } else { $article->text = $tmpl->renderTemplate('tpl_links') . $article->text; } $tmpl->freeTemplate('tpl_links'); if ($this->params->get('readmore_link', 1) == 1) { $article->readmore = 0; $article->readmore_link = ''; $article->readmore_register = false; } } else { if ($this->params->get('show_comments_event') == 'onPrepareContent') { $isEnabled = ($config->getInt('comments_on', 0) == 1) && ($config->getInt('comments_off', 0) == 0); if ($isEnabled && $view == 'article') { require_once (JCOMMENTS_BASE . '/jcomments.php'); $comments = JComments::show($article->id, 'com_content', $article->title); if (strpos($article->text, '{jcomments}') !== false) { $article->text = str_replace('{jcomments}', $comments, $article->text); } else { $article->text .= $comments; } } } JCommentsContentPluginHelper::clear($article, true); } return ''; }
public static function getPluralText($text, $value) { if (version_compare(JVERSION, '1.6.0', 'ge')) { $result = JText::plural($text, $value); } else { $toolsPath = JPATH_SITE . '/components/com_jcomments/libraries/joomlatune/language.tools.php'; if (is_file($toolsPath)) { require_once $toolsPath; $language = JFactory::getLanguage(); $suffix = JoomlaTuneLanguageTools::getPluralSuffix($language->getTag(), $value); $key = $text . '_' . $suffix; if (!$language->hasKey($key)) { $key = $text; } } else { $key = $text; } $result = JText::sprintf($key, $value); } return $result; }