protected function _getDefaultMenuItem($menu, $active, $visited = array()) { if (empty($active->query['defaultmenu']) || $active->id == $active->query['defaultmenu']) { // There is no highlighted menu item return null; } $item = $menu->getItem($active->query['defaultmenu']); if (!$item) { // Menu item points to nowhere, abort KunenaError::warning(JText::sprintf('COM_KUNENA_WARNING_MENU_NOT_EXISTS'), 'menu'); return null; } elseif (isset($visited[$item->id])) { // Menu loop detected, abort KunenaError::warning(JText::sprintf('COM_KUNENA_WARNING_MENU_LOOP'), 'menu'); return null; } elseif (empty($item->component) || $item->component != 'com_kunena' || !isset($item->query['view'])) { // Menu item doesn't point to Kunena, abort KunenaError::warning(JText::sprintf('COM_KUNENA_WARNING_MENU_NOT_KUNENA'), 'menu'); return null; } elseif ($item->query['view'] == 'home') { // Menu item is pointing to another Home Page, try to find default menu item from there $visited[$item->id] = 1; $item = $this->_getDefaultMenuItem($menu, $item->query['defaultmenu'], $visited); } return $item; }
/** * Send email notifications from the message. * * @param null|string $url * * @return bool|null */ public function sendNotification($url = null) { $config = KunenaFactory::getConfig(); if (!$config->get('send_emails')) { return null; } if ($this->hold > 1) { return null; } elseif ($this->hold == 1) { $mailsubs = 0; $mailmods = $config->mailmod >= 0; $mailadmins = $config->mailadmin >= 0; } else { $mailsubs = (bool) $config->allowsubscriptions; $mailmods = $config->mailmod >= 1; $mailadmins = $config->mailadmin >= 1; } $once = false; if ($mailsubs) { if (!$this->parent) { // New topic: Send email only to category subscribers $mailsubs = $config->category_subscriptions != 'disabled' ? KunenaAccess::CATEGORY_SUBSCRIPTION : 0; $once = $config->category_subscriptions == 'topic'; } elseif ($config->category_subscriptions != 'post') { // Existing topic: Send email only to topic subscribers $mailsubs = $config->topic_subscriptions != 'disabled' ? KunenaAccess::TOPIC_SUBSCRIPTION : 0; $once = $config->topic_subscriptions == 'first'; } else { // Existing topic: Send email to both category and topic subscribers $mailsubs = $config->topic_subscriptions == 'disabled' ? KunenaAccess::CATEGORY_SUBSCRIPTION : KunenaAccess::CATEGORY_SUBSCRIPTION | KunenaAccess::TOPIC_SUBSCRIPTION; // FIXME: category subscription can override topic $once = $config->topic_subscriptions == 'first'; } } if (!$url) { $url = JUri::getInstance()->toString(array('scheme', 'host', 'port')) . $this->getPermaUrl(); } // Get all subscribers, moderators and admins who should get the email. $emailToList = KunenaAccess::getInstance()->getSubscribers($this->catid, $this->thread, $mailsubs, $mailmods, $mailadmins, KunenaUserHelper::getMyself()->userid); if ($emailToList) { if (!$config->getEmail()) { KunenaError::warning(JText::_('COM_KUNENA_EMAIL_DISABLED')); return false; } elseif (!JMailHelper::isEmailAddress($config->getEmail())) { KunenaError::warning(JText::_('COM_KUNENA_EMAIL_INVALID')); return false; } $topic = $this->getTopic(); // Make a list from all receivers; split the receivers into two distinct groups. $sentusers = array(); $receivers = array(0 => array(), 1 => array()); foreach ($emailToList as $emailTo) { if (!$emailTo->email || !JMailHelper::isEmailAddress($emailTo->email)) { continue; } $receivers[$emailTo->subscription][] = $emailTo->email; $sentusers[] = $emailTo->id; } $mailsender = JMailHelper::cleanAddress($config->board_title); $mailsubject = JMailHelper::cleanSubject($config->board_title . ' ' . $topic->subject . " (" . $this->getCategory()->name . ")"); $subject = $this->subject ? $this->subject : $topic->subject; // Create email. $mail = JFactory::getMailer(); $mail->setSubject($mailsubject); $mail->setSender(array($config->getEmail(), $mailsender)); // Send email to all subscribers. if (!empty($receivers[1])) { $this->attachEmailBody($mail, 1, $subject, $url, $once); KunenaEmail::send($mail, $receivers[1]); } // Send email to all moderators. if (!empty($receivers[0])) { $this->attachEmailBody($mail, 0, $subject, $url, $once); KunenaEmail::send($mail, $receivers[0]); } // Update subscriptions. if ($once && $sentusers) { $sentusers = implode(',', $sentusers); $db = JFactory::getDbo(); $query = $db->getQuery(true)->update('#__kunena_user_topics')->set('subscribed=2')->where("topic_id={$this->thread}")->where("user_id IN ({$sentusers})")->where('subscribed=1'); $db->setQuery($query); $db->execute(); KunenaError::checkDatabaseError(); } } return true; }
public function emailToSubscribers($LastPostUrl = false, $mailsubs = false, $mailmods = false, $mailadmins = false) { if ($LastPostUrl === false) { jimport('joomla.environment.uri'); $uri = JURI::getInstance(JURI::base()); $LastPostUrl = $uri->toString(array('scheme', 'host', 'port')) . CKunenaLink::GetMessageURL($this->get('id'), $this->get('catid'), 0, false); } $once = false; if ($mailsubs) { if (!$this->get('parent')) { // New topic: Send email only to category subscribers $mailsubs = $this->_config->category_subscriptions != 'disabled' ? 3 : 0; $once = $this->_config->category_subscriptions == 'topic'; } elseif ($this->_config->category_subscriptions != 'post') { // Existing topic: Send email only to topic subscribers $mailsubs = $this->_config->topic_subscriptions != 'disabled' ? 2 : 0; $once = $this->_config->topic_subscriptions == 'first'; } else { // Existing topic: Send email to both category and topic subscribers $mailsubs = $this->_config->topic_subscriptions == 'disabled' ? 3 : 1; // FIXME: category subcription can override topic $once = $this->_config->topic_subscriptions == 'first'; } } // Fetch all subscribers, moderators and admins who will get the email $emailToList = CKunenaTools::getEMailToList($this->get('catid'), $this->get('thread'), $mailsubs, $mailmods, $mailadmins, $this->_my->id); if (count($emailToList)) { jimport('joomla.mail.helper'); kimport('html.parser'); if (!$this->_config->email) { KunenaError::warning(JText::_('COM_KUNENA_EMAIL_DISABLED')); return false; } else { if (!JMailHelper::isEmailAddress($this->_config->email)) { KunenaError::warning(JText::_('COM_KUNENA_EMAIL_INVALID')); return false; } } // clean up the message for review $authorname = $this->get('name'); $message = KunenaParser::stripBBCode($this->get('message'), 0, false); $subject = $this->get('subject'); $topicsubject = $this->parent->subject ? $this->parent->subject : $subject; $mailsender = JMailHelper::cleanAddress($this->_config->board_title); $mailsubject = JMailHelper::cleanSubject("[" . $this->_config->board_title . "] " . $topicsubject . " (" . $this->parent->catname . ")"); // Make a list from all receivers $sentusers = array(); $receivers = array(0 => array(), 1 => array()); foreach ($emailToList as $emailTo) { if (!$emailTo->email || !JMailHelper::isEmailAddress($emailTo->email)) { continue; } $receivers[$emailTo->subscription][] = $emailTo->email; $sentusers[] = $emailTo->id; } // Create email $mail = JFactory::getMailer(); $mail->setSubject($mailsubject); $mail->setSender(array($this->_config->email, $mailsender)); // Send email to all subscribers $mail->setBody($this->createEmailBody(1, $subject, $authorname, $LastPostUrl, $message, $once)); $this->sendEmail($mail, $receivers[1]); // Send email to all moderators $mail->setBody($this->createEmailBody(0, $subject, $authorname, $LastPostUrl, $message, $once)); $this->sendEmail($mail, $receivers[0]); // Update subscriptions if ($once && $sentusers) { $sentusers = implode(',', $sentusers); $db = JFactory::getDBO(); $query = "UPDATE #__kunena_subscriptions\n\t\t\t\t\tSET future1=1 WHERE thread={$this->get('thread')} AND userid IN ({$sentusers})"; $db->setQuery($query); $db->query(); KunenaError::checkDatabaseError(); } } }
/** * Returns the global KunenaTemplate object, only creating it if it doesn't already exist. * * @access public * @param int $name Template name or null for default/selected template in your configuration * @return KunenaTemplate The template object. * @since 1.6 */ public static function getInstance($name = null) { $app = JFactory::getApplication(); if (!$name) { $name = JRequest::getString('kunena_template', KunenaFactory::getConfig()->template, 'COOKIE'); } $name = KunenaPath::clean($name); if (empty(self::$_instances[$name])) { // Find overridden template class (use $templatename to avoid creating new objects if the template doesn't exist) $templatename = $name; $classname = "KunenaTemplate{$templatename}"; if (!is_file(KPATH_SITE . "/template/{$templatename}/template.xml") && !is_file(KPATH_SITE . "/template/{$templatename}/config.xml")) { // If template xml doesn't exist, raise warning and use blue eagle instead $file = JPATH_THEMES . "/{$app->getTemplate()}/html/com_kunena/template.php"; $templatename = 'blue_eagle'; $classname = "KunenaTemplate{$templatename}"; if (is_dir(KPATH_SITE . "/template/{$templatename}")) { KunenaError::warning(JText::sprintf('COM_KUNENA_LIB_TEMPLATE_NOTICE_INCOMPATIBLE', $name, $templatename)); } } if (!class_exists($classname) && $app->isSite()) { $file = KPATH_SITE . "/template/{$templatename}/template.php"; if (!is_file($file)) { $classname = "KunenaTemplateBlue_Eagle"; $file = KPATH_SITE . "/template/blue_eagle/template.php"; } if (is_file($file)) { require_once $file; } } if (class_exists($classname)) { self::$_instances[$name] = new $classname($templatename); } else { self::$_instances[$name] = new KunenaTemplate($templatename); } } return self::$_instances[$name]; }
function displayMenu() { jimport('joomla.application.module.helper'); $position = "kunena_menu"; $options = array('style' => 'xhtml'); $modules = JModuleHelper::getModules($position); foreach ($modules as $module) { if ($module->module == 'mod_mainmenu' || $module->module == 'mod_menu') { $app = JFactory::getApplication(); $menu = JSite::getMenu(); $active = $menu->getActive(); $basemenu = KunenaRoute::getCurrentMenu(); if ($basemenu) { $module = clone $module; if (version_compare(JVERSION, '1.6', '>')) { // Joomla 1.6+ $search = array('/"menutype":"([^"]*)"/i', '/"startLevel":"([^"]*)"/', '/"endLevel":"([^"]*)"/'); $replace = array("\"menutype\":\"{$basemenu->menutype}\"", '"startLevel":"' . ($basemenu->level + 1) . '"', '"endLevel":"' . ($basemenu->level + 2) . '"'); } else { // Joomla 1.5 $search = array('/menutype=(.*)(\\s)/', '/startLevel=(.*)(\\s)/', '/endLevel=(.*)(\\s)/'); $replace = array("menutype={$basemenu->menutype}\\2", 'startLevel=' . ($basemenu->sublevel + 1) . '\\2', 'endLevel=' . ($basemenu->sublevel + 2) . '\\2'); } $module->params = preg_replace($search, $replace, $module->params); } else { if ($active) { KunenaError::warning(JText::sprintf('COM_KUNENA_WARNING_NOMENU_ITEMID', $active->route, $active->id), 'nomenu'); } else { KunenaError::warning(JText::sprintf('COM_KUNENA_WARNING_NOMENU_COMPONENT'), 'nomenu'); } } } echo JModuleHelper::renderModule($module, $options); } }
public function sendNotification($url=null) { $config = KunenaFactory::getConfig(); if ($this->hold > 1) { return; } elseif ($this->hold == 1) { $mailsubs = 0; $mailmods = (bool) $config->mailmod; $mailadmins = (bool) $config->mailadmin; } else { $mailsubs = (bool) $config->allowsubscriptions; $mailmods = 0; $mailadmins = 0; } $once = false; if ($mailsubs) { if (!$this->parent) { // New topic: Send email only to category subscribers $mailsubs = $config->category_subscriptions != 'disabled' ? 3 : 0; $once = $config->category_subscriptions == 'topic'; } elseif ($config->category_subscriptions != 'post') { // Existing topic: Send email only to topic subscribers $mailsubs = $config->topic_subscriptions != 'disabled' ? 2 : 0; $once = $config->topic_subscriptions == 'first'; } else { // Existing topic: Send email to both category and topic subscribers $mailsubs = $config->topic_subscriptions == 'disabled' ? 3 : 1; // FIXME: category subcription can override topic $once = $config->topic_subscriptions == 'first'; } } if (!$url) { $url = JURI::root().trim($this->getPermaUrl(null, true), '/'); } //get all subscribers, moderators and admins who will get the email $me = KunenaUserHelper::get(); $acl = KunenaFactory::getAccessControl(); $emailToList = $acl->getSubscribers($this->catid, $this->thread, $mailsubs, $mailmods, $mailadmins, $me->userid); $topic = $this->getTopic(); if (count ( $emailToList )) { jimport('joomla.mail.helper'); if (! $config->email ) { KunenaError::warning ( JText::_ ( 'COM_KUNENA_EMAIL_DISABLED' ) ); return false; } elseif ( ! JMailHelper::isEmailAddress ( $config->email ) ) { KunenaError::warning ( JText::_ ( 'COM_KUNENA_EMAIL_INVALID' ) ); return false; } // clean up the message for review $message = KunenaHtmlParser::plainBBCode ( $this->message ); $mailsender = JMailHelper::cleanAddress ( $config->board_title ); $mailsubject = JMailHelper::cleanSubject ( "[" . $config->board_title . "] " . $topic->subject . " (" . $this->getCategory()->name . ")" ); $subject = $this->subject ? $this->subject : $topic->subject; // Make a list from all receivers $sentusers = array(); $receivers = array(0=>array(), 1=>array()); foreach ( $emailToList as $emailTo ) { if (! $emailTo->email || ! JMailHelper::isEmailAddress ( $emailTo->email )) { continue; } $receivers[$emailTo->subscription][] = $emailTo->email; $sentusers[] = $emailTo->id; } // Create email $mail = JFactory::getMailer(); $mail->setSubject($mailsubject); $mail->setSender(array($this->_config->email, $mailsender)); // Send email to all subscribers if (!empty($receivers[1])) { $mail->setBody($this->createEmailBody(1, $subject, $url, $message, $once)); $this->sendEmail($mail, $receivers[1]); } // Send email to all moderators if (!empty($receivers[0])) { $mail->setBody($this->createEmailBody(0, $subject, $url, $message, $once)); $this->sendEmail($mail, $receivers[0]); } // Update subscriptions if ($once && $sentusers) { $sentusers = implode (',', $sentusers); $db = JFactory::getDBO(); $query = "UPDATE #__kunena_user_topics SET subscribed=2 WHERE topic_id={$this->thread} AND user_id IN ({$sentusers}) AND subscribed=1"; $db->setQuery ($query); $db->query (); KunenaError::checkDatabaseError(); } } }
public function loadMootools() { if (version_compare(JVERSION, '1.6','>')) { // Joomla 1.6+ JHTML::_ ( 'behavior.framework', true ); } else { // Joomla 1.5 jimport ( 'joomla.plugin.helper' ); $mtupgrade = JPluginHelper::isEnabled ( 'system', 'mtupgrade' ); if (! $mtupgrade) { $app = JFactory::getApplication (); if (!class_exists ( 'JHTMLBehavior' )) { if (is_dir ( JPATH_PLUGINS . '/system/mtupgrade' )) { JHTML::addIncludePath ( JPATH_PLUGINS . '/system/mtupgrade' ); } else { KunenaError::warning ( JText::_('COM_KUNENA_LIB_TEMPLATE_MOOTOOLS_NO_UPGRADE').' '.JText::_('COM_KUNENA_LIB_TEMPLATE_MOOTOOLS_WARNING') ); } } } JHTML::_ ( 'behavior.mootools' ); // Get the MooTools version string $mtversion = preg_replace('/[^\d\.]/','', JFactory::getApplication()->get('MooToolsVersion')); if (version_compare($mtversion, '1.2.4', '<')) { KunenaError::warning ( JText::_('COM_KUNENA_LIB_TEMPLATE_MOOTOOLS_LEGACY').' '.JText::_('COM_KUNENA_LIB_TEMPLATE_MOOTOOLS_WARNING') ); } } if (JDEBUG || KunenaFactory::getConfig()->debug) { // Debugging Mootools issues $this->addScript ( 'js/debug.js' ); } }
public function loadMootools() { if (KUNENA_JOOMLA_COMPAT == '1.5') { jimport('joomla.plugin.helper'); $mtupgrade = JPluginHelper::isEnabled('system', 'mtupgrade'); if (!$mtupgrade) { $app = JFactory::getApplication(); if (!class_exists('JHTMLBehavior')) { if (is_dir(JPATH_PLUGINS . '/system/mtupgrade')) { JHTML::addIncludePath(JPATH_PLUGINS . '/system/mtupgrade'); } else { // TODO: translate KunenaError::warning('<em>System - MooTools Upgrade</em> plug-in is not installed into your system. Many features, including the BBCode editor, may be broken.', 'notice'); } } } JHTML::_('behavior.mootools'); // Get the MooTools version string $mtversion = preg_replace('/[^\\d\\.]/', '', JFactory::getApplication()->get('MooToolsVersion')); if (version_compare($mtversion, '1.2.4', '<')) { // TODO: translate KunenaError::warning('Your site is not using <em>System - MooTools Upgrade</em> (or compatible) plug-in. Many features, including the BBCode editor, may be broken.'); } } else { // Joomla 1.6+ JHTML::_('behavior.framework', true); } if (KunenaFactory::getConfig()->debug) { // Debugging Mootools issues CKunenaTools::addScript(KUNENA_DIRECTURL . 'template/default/js/debug-min.js'); } }
function redirect($url) { $app = JFactory::getApplication(); $redirect = (array) $app->getUserState('com_kunena.redirect'); if (isset($redirect[$url])) { // TODO: translate COM_KUNENA_WARNING_MENU_REDIRECT_LOOP KunenaError::warning(JText::sprintf('Infinite redirect loop detected in %s', $url), 'menu'); return; } $redirect[$url] = 1; $app->setUserState('com_kunena.redirect', $redirect); while (@ob_end_clean()) { } $app->redirect($url); }
public function sendNotification($url=null) { $config = KunenaFactory::getConfig(); if ($this->hold > 1) { return; } elseif ($this->hold == 1) { $mailsubs = 0; $mailmods = (bool) $config->mailmod; $mailadmins = (bool) $config->mailadmin; } else { $mailsubs = (bool) $config->allowsubscriptions; $mailmods = 0; $mailadmins = 0; } kimport ('kunena.html.parser'); $once = false; if ($mailsubs) { if (!$this->parent) { // New topic: Send email only to category subscribers $mailsubs = $config->category_subscriptions != 'disabled' ? 3 : 0; $once = $config->category_subscriptions == 'topic'; } elseif ($config->category_subscriptions != 'post') { // Existing topic: Send email only to topic subscribers $mailsubs = $config->topic_subscriptions != 'disabled' ? 2 : 0; $once = $config->topic_subscriptions == 'first'; } else { // Existing topic: Send email to both category and topic subscribers $mailsubs = $config->topic_subscriptions == 'disabled' ? 3 : 1; // FIXME: category subcription can override topic $once = $config->topic_subscriptions == 'first'; } } if (!$url) { $url = JURI::root().trim(CKunenaLink::GetMessageURL($this->id, $this->catid, 0, false), '/'); } //get all subscribers, moderators and admins who will get the email $me = KunenaUserHelper::get(); $acl = KunenaFactory::getAccessControl(); $emailToList = $acl->getSubscribers($this->catid, $this->thread, $mailsubs, $mailmods, $mailadmins, $me->userid); $category = $this->getCategory(); $topic = $this->getTopic(); if (count ( $emailToList )) { jimport('joomla.mail.helper'); if (! $config->email ) { KunenaError::warning ( JText::_ ( 'COM_KUNENA_EMAIL_DISABLED' ) ); return false; } elseif ( ! JMailHelper::isEmailAddress ( $config->email ) ) { KunenaError::warning ( JText::_ ( 'COM_KUNENA_EMAIL_INVALID' ) ); return false; } // clean up the message for review $message = KunenaHtmlParser::plainBBCode ( $this->message ); $mailsender = JMailHelper::cleanAddress ( $config->board_title ); $mailsubject = JMailHelper::cleanSubject ( "[" . $config->board_title . "] " . $topic->subject . " (" . $category->name . ")" ); $subject = $this->subject ? $this->subject : $topic->subject; $sentusers = array(); foreach ( $emailToList as $emailTo ) { if (! $emailTo->email || ! JMailHelper::isEmailAddress ( $emailTo->email )) continue; if ($emailTo->subscription) { $msg1 = $this->parent ? JText::_ ( 'COM_KUNENA_POST_EMAIL_NOTIFICATION1' ) : JText::_ ( 'COM_KUNENA_POST_EMAIL_NOTIFICATION1_CAT' ); $msg2 = $this->parent ? JText::_ ( 'COM_KUNENA_POST_EMAIL_NOTIFICATION2' ) : JText::_ ( 'COM_KUNENA_POST_EMAIL_NOTIFICATION2_CAT' ); } else { $msg1 = JText::_ ( 'COM_KUNENA_POST_EMAIL_MOD1' ); $msg2 = JText::_ ( 'COM_KUNENA_POST_EMAIL_MOD2' ); } $msg = "$emailTo->name,\n\n"; $msg .= $msg1 . " " . $config->board_title . "\n\n"; // DO NOT REMOVE EXTRA SPACE, JMailHelper::cleanBody() removes "Subject:" from the message body $msg .= JText::_ ( 'COM_KUNENA_MESSAGE_SUBJECT' ) . " : " . $subject . "\n"; $msg .= JText::_ ( 'COM_KUNENA_GEN_CATEGORY' ) . " : " . $category->name . "\n"; $msg .= JText::_ ( 'COM_KUNENA_VIEW_POSTED' ) . " : " . $this->name . "\n\n"; $msg .= "URL : {$url}\n\n"; if ($config->mailfull) { $msg .= JText::_ ( 'COM_KUNENA_GEN_MESSAGE' ) . " :\n-----\n"; $msg .= $message; $msg .= "\n-----\n\n"; } $msg .= $msg2 . "\n"; if ($emailTo->subscription && $once) { if ($this->parent) { $msg .= JText::_ ( 'COM_KUNENA_POST_EMAIL_NOTIFICATION_MORE_READ' ) . "\n"; } else { $msg .= JText::_ ( 'COM_KUNENA_POST_EMAIL_NOTIFICATION_MORE_SUBSCRIBE' ) . "\n"; } } $msg .= "\n"; $msg .= JText::_ ( 'COM_KUNENA_POST_EMAIL_NOTIFICATION3' ) . "\n"; $msg = JMailHelper::cleanBody ( $msg ); JUtility::sendMail ( $config->email, $mailsender, $emailTo->email, $mailsubject, $msg ); $sentusers[] = $emailTo->id; } if ($once && $sentusers) { $sentusers = implode (',', $sentusers); $db = JFactory::getDBO(); $query = "UPDATE #__kunena_user_topics SET subscribed=2 WHERE topic_id={$this->thread} AND user_id IN ({$sentusers}) AND subscribed=1"; $db->setQuery ($query); $db->query (); KunenaError::checkDatabaseError(); } } }