本文整理汇总了PHP中K2HelperPermissions::canAddComment方法的典型用法代码示例。如果您正苦于以下问题:PHP K2HelperPermissions::canAddComment方法的具体用法?PHP K2HelperPermissions::canAddComment怎么用?PHP K2HelperPermissions::canAddComment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类K2HelperPermissions
的用法示例。
在下文中一共展示了K2HelperPermissions::canAddComment方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: display
function display($tpl = null)
{
$mainframe =& JFactory::getApplication();
$user =& JFactory::getUser();
$document =& JFactory::getDocument();
$params =& JComponentHelper::getParams('com_k2');
$limitstart = JRequest::getInt('limitstart', 0);
$view = JRequest::getWord('view');
$task = JRequest::getWord('task');
$db =& JFactory::getDBO();
$jnow =& JFactory::getDate();
$now = $jnow->toMySQL();
$nullDate = $db->getNullDate();
$this->setLayout('item');
//Add link
if (K2HelperPermissions::canAddItem()) {
$addLink = JRoute::_('index.php?option=com_k2&view=item&task=add&tmpl=component');
}
$this->assignRef('addLink', $addLink);
//Get item
$model =& $this->getModel();
$item = $model->getData();
//Prepare item
if ($user->guest) {
$cache =& JFactory::getCache('com_k2_extended');
$hits = $item->hits;
$item->hits = 0;
$item = $cache->call(array('K2ModelItem', 'prepareItem'), $item, $view, $task);
$item->hits = $hits;
} else {
$item = $model->prepareItem($item, $view, $task);
}
//Plugins
$item = $model->execPlugins($item, $view, $task);
//Access check
if ($this->getLayout() == 'form') {
JError::raiseError(403, JText::_("ALERTNOTAUTH"));
}
if ($item->access > $user->get('aid', 0) || $item->category->access > $user->get('aid', 0)) {
JError::raiseError(403, JText::_("ALERTNOTAUTH"));
}
//Published check
if (!$item->published || $item->trash) {
JError::raiseError(404, JText::_("Item not found"));
}
if ($item->publish_up != $nullDate && $item->publish_up > $now) {
JError::raiseError(404, JText::_("Item not found"));
}
if ($item->publish_down != $nullDate && $item->publish_down < $now) {
JError::raiseError(404, JText::_("Item not found"));
}
if (!$item->category->published || $item->category->trash) {
JError::raiseError(404, JText::_("Item not found"));
}
//Increase hits counter
$model->hit($item->id);
//Set default image
K2HelperUtilities::setDefaultImage($item, $view);
//Comments
$item->event->K2CommentsCounter = '';
$item->event->K2CommentsBlock = '';
if ($item->params->get('itemComments')) {
//Trigger comments events
$dispatcher =& JDispatcher::getInstance();
JPluginHelper::importPlugin('k2');
$results = $dispatcher->trigger('onK2CommentsCounter', array(&$item, &$params, $limitstart));
$item->event->K2CommentsCounter = trim(implode("\n", $results));
$results = $dispatcher->trigger('onK2CommentsBlock', array(&$item, &$params, $limitstart));
$item->event->K2CommentsBlock = trim(implode("\n", $results));
//Load K2 native comments system only if there are no plugins overriding it
if (empty($item->event->K2CommentsCounter) && empty($item->event->K2CommentsBlock)) {
//Load reCAPTCHA script
if (!JRequest::getInt('print') && ($item->params->get('comments') == '1' || $item->params->get('comments') == '2' && K2HelperPermissions::canAddComment($item->catid))) {
if ($item->params->get('recaptcha') && $user->guest) {
$document->addScript('http://api.recaptcha.net/js/recaptcha_ajax.js');
$js = 'function showRecaptcha(){
Recaptcha.create("' . $item->params->get('recaptcha_public_key') . '", "recaptcha", {
theme: "' . $item->params->get('recaptcha_theme', 'clean') . '"
});
}
window.addEvent(\'load\', function(){
showRecaptcha();
})';
$document->addScriptDeclaration($js);
}
//Auto complete some fields for registered users
if (!$user->guest) {
$js = "window.addEvent('domready', function(){\n\t\t\t\t\t\t\t\t\t\$('userName').setProperty('value','" . $user->name . "');\n\t\t\t\t\t\t\t\t\t\$('userName').setProperty('disabled','disabled');\n\t\t\t\t\t\t\t\t\t\$('commentEmail').setProperty('value','" . $user->email . "');\n\t\t\t\t\t\t\t\t\t\$('commentEmail').setProperty('disabled','disabled');\n\n\t\t\t\t\t\t\t\t})";
$document->addScriptDeclaration($js);
}
}
$limit = $params->get('commentsLimit');
$comments = $model->getItemComments($item->id, $limitstart, $limit);
$pattern = "@\\b(https?://)?(([0-9a-zA-Z_!~*'().&=+\$%-]+:)?[0-9a-zA-Z_!~*'().&=+\$%-]+\\@)?(([0-9]{1,3}\\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\\.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\\.[a-zA-Z]{2,6})(:[0-9]{1,4})?((/[0-9a-zA-Z_!~*'().;?:\\@&=+\$,%#-]+)*/?)@";
for ($i = 0; $i < sizeof($comments); $i++) {
$comments[$i]->commentText = nl2br($comments[$i]->commentText);
$comments[$i]->commentText = preg_replace($pattern, '<a target="_blank" rel="nofollow" href="\\0">\\0</a>', $comments[$i]->commentText);
$comments[$i]->userImage = K2HelperUtilities::getAvatar($comments[$i]->userID, $comments[$i]->commentEmail, $params->get('commenterImgWidth'));
if ($comments[$i]->userID > 0) {
$comments[$i]->userLink = K2HelperRoute::getUserRoute($comments[$i]->userID);
//.........这里部分代码省略.........
示例2:
}
?>
</ul>
<div class="itemCommentsPagination">
<?php
echo $this->pagination->getPagesLinks();
?>
<div class="clr"></div>
</div>
<?php
}
?>
<?php
if ($this->item->params->get('commentsFormPosition') == 'below' && $this->item->params->get('itemComments') && !JRequest::getInt('print') && ($this->item->params->get('comments') == '1' || $this->item->params->get('comments') == '2' && K2HelperPermissions::canAddComment($this->item->catid))) {
?>
<!-- Item comments form -->
<div class="itemCommentsForm">
<?php
echo $this->loadTemplate('comments_form');
?>
</div>
<?php
}
?>
<?php
$user = JFactory::getUser();
if ($this->item->params->get('comments') == '2' && $user->guest) {
?>
示例3: comment
function comment()
{
$mainframe =& JFactory::getApplication();
jimport('joomla.mail.helper');
JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
$params =& JComponentHelper::getParams('com_k2');
$user = JFactory::getUser();
$config =& JFactory::getConfig();
//Get item
$item =& JTable::getInstance('K2Item', 'Table');
$item->load(JRequest::getInt('itemID'));
//Get category
$category =& JTable::getInstance('K2Category', 'Table');
$category->load($item->catid);
//Access check
if ($item->access > $user->get('aid', 0) || $category->access > $user->get('aid', 0)) {
JError::raiseError(403, JText::_("ALERTNOTAUTH"));
}
//Published check
if (!$item->published || $item->trash) {
JError::raiseError(404, JText::_("Item not found"));
}
if (!$category->published || $category->trash) {
JError::raiseError(404, JText::_("Item not found"));
}
//Check permissions
if ($params->get('comments') == '2' && $user->id > 0 && K2HelperPermissions::canAddComment($item->catid) || $params->get('comments') == '1') {
$row =& JTable::getInstance('K2Comment', 'Table');
if (!$row->bind(JRequest::get('post'))) {
echo $row->getError();
$mainframe->close();
}
$row->commentText = JRequest::getString('commentText');
$datenow =& JFactory::getDate();
$row->commentDate = $datenow->toMySQL();
if (!$user->guest) {
$row->userID = $user->id;
$row->commentEmail = $user->email;
$row->userName = $user->name;
}
$userName = trim($row->userName);
$commentEmail = trim($row->commentEmail);
$commentText = trim($row->commentText);
$commentURL = trim($row->commentURL);
if (empty($userName) || $userName == JText::_('enter your name...') || empty($commentText) || $commentText == JText::_('enter your comment here...') || empty($commentEmail) || $commentEmail == JText::_('enter your e-mail address...')) {
echo JText::_('You need to fill in all required fields!');
$mainframe->close();
}
if (!JMailHelper::isEmailAddress($commentEmail)) {
echo JText::_('Invalid e-mail address!');
$mainframe->close();
}
if ($user->guest) {
$db =& JFactory::getDBO();
$query = "SELECT COUNT(*) FROM #__users WHERE name=" . $db->Quote($userName) . " OR email=" . $db->Quote($commentEmail);
$db->setQuery($query);
$result = $db->loadresult();
if ($result > 0) {
echo JText::_('The name or email address you typed is already in use!');
$mainframe->close();
}
}
if ($params->get('recaptcha')) {
require_once JPATH_COMPONENT . DS . 'lib' . DS . 'recaptchalib.php';
$privatekey = $params->get('recaptcha_private_key');
$resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
echo JText::_("The words you typed did not match the ones displayed. Please try again.");
$mainframe->close();
}
}
if ($commentURL == JText::_('enter your site URL...') || $commentURL == "") {
$row->commentURL = NULL;
} else {
if (substr($commentURL, 0, 7) != 'http://') {
$row->commentURL = 'http://' . $commentURL;
}
}
if ($params->get('commentsPublishing')) {
$row->published = 1;
} else {
$row->published = 0;
}
if (!$row->store()) {
echo $row->getError();
$mainframe->close();
}
if ($params->get('commentsPublishing')) {
if ($config->getValue('config.caching')) {
echo JText::_('Thank you. Your comment will be published shortly.');
} else {
echo '<span class="success">' . JText::_('Comment added! Refreshing page...') . '</span>';
}
} else {
echo JText::_('Comment added and waiting for approval.');
}
}
$mainframe->close();
}
示例4: display
function display($tpl = null)
{
$mainframe =& JFactory::getApplication();
$user =& JFactory::getUser();
$document =& JFactory::getDocument();
$params =& K2HelperUtilities::getParams('com_k2');
$limitstart = JRequest::getInt('limitstart', 0);
$view = JRequest::getWord('view');
$task = JRequest::getWord('task');
$db =& JFactory::getDBO();
$jnow =& JFactory::getDate();
$now = $jnow->toMySQL();
$nullDate = $db->getNullDate();
$this->setLayout('item');
// Add link
if (K2HelperPermissions::canAddItem()) {
$addLink = JRoute::_('index.php?option=com_k2&view=item&task=add&tmpl=component');
}
$this->assignRef('addLink', $addLink);
// Get item
$model =& $this->getModel();
$item = $model->getData();
// Does the item exists?
if (!is_object($item) || !$item->id) {
JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
}
// Prepare item
$item = $model->prepareItem($item, $view, $task);
// Plugins
$item = $model->execPlugins($item, $view, $task);
// User K2 plugins
$item->event->K2UserDisplay = '';
if (isset($item->author) && is_object($item->author->profile) && isset($item->author->profile->id)) {
$dispatcher =& JDispatcher::getInstance();
JPluginHelper::importPlugin('k2');
$results = $dispatcher->trigger('onK2UserDisplay', array(&$item->author->profile, &$params, $limitstart));
$item->event->K2UserDisplay = trim(implode("\n", $results));
}
// Access check
if ($this->getLayout() == 'form') {
JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
}
if (K2_JVERSION == '16') {
if (!in_array($item->access, $user->authorisedLevels()) || !in_array($item->category->access, $user->authorisedLevels())) {
JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
}
} else {
if ($item->access > $user->get('aid', 0) || $item->category->access > $user->get('aid', 0)) {
JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
}
}
// Published check
if (!$item->published || $item->trash) {
JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
}
if ($item->publish_up != $nullDate && $item->publish_up > $now) {
JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
}
if ($item->publish_down != $nullDate && $item->publish_down < $now) {
JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
}
if (!$item->category->published || $item->category->trash) {
JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
}
// Increase hits counter
$model->hit($item->id);
// Set default image
K2HelperUtilities::setDefaultImage($item, $view);
// Comments
$item->event->K2CommentsCounter = '';
$item->event->K2CommentsBlock = '';
if ($item->params->get('itemComments')) {
// Trigger comments events
$dispatcher =& JDispatcher::getInstance();
JPluginHelper::importPlugin('k2');
$results = $dispatcher->trigger('onK2CommentsCounter', array(&$item, &$params, $limitstart));
$item->event->K2CommentsCounter = trim(implode("\n", $results));
$results = $dispatcher->trigger('onK2CommentsBlock', array(&$item, &$params, $limitstart));
$item->event->K2CommentsBlock = trim(implode("\n", $results));
// Load K2 native comments system only if there are no plugins overriding it
if (empty($item->event->K2CommentsCounter) && empty($item->event->K2CommentsBlock)) {
// Load reCAPTCHA script
if (!JRequest::getInt('print') && ($item->params->get('comments') == '1' || $item->params->get('comments') == '2' && K2HelperPermissions::canAddComment($item->catid))) {
if ($item->params->get('recaptcha') && $user->guest) {
$document->addScript('http://api.recaptcha.net/js/recaptcha_ajax.js');
$js = '
function showRecaptcha(){
Recaptcha.create("' . $item->params->get('recaptcha_public_key') . '", "recaptcha", {
theme: "' . $item->params->get('recaptcha_theme', 'clean') . '"
});
}
$K2(window).load(function() {
showRecaptcha();
});
';
$document->addScriptDeclaration($js);
}
}
// Check for inline comment moderation
if (!$user->guest && $user->id == $item->created_by && $params->get('inlineCommentsModeration')) {
//.........这里部分代码省略.........
示例5: comment
function comment()
{
$mainframe = JFactory::getApplication();
jimport('joomla.mail.helper');
JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
$params = K2HelperUtilities::getParams('com_k2');
$user = JFactory::getUser();
$config = JFactory::getConfig();
JLoader::register('Services_JSON', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'lib' . DS . 'JSON.php');
$json = new Services_JSON();
$response = new JObject();
//Get item
$item = JTable::getInstance('K2Item', 'Table');
$item->load(JRequest::getInt('itemID'));
//Get category
$category = JTable::getInstance('K2Category', 'Table');
$category->load($item->catid);
//Access check
if (K2_JVERSION != '15') {
if (!in_array($item->access, $user->getAuthorisedViewLevels()) || !in_array($category->access, $user->getAuthorisedViewLevels())) {
JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
}
} else {
if ($item->access > $user->get('aid', 0) || $category->access > $user->get('aid', 0)) {
JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
}
}
//Published check
if (!$item->published || $item->trash) {
JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
}
if (!$category->published || $category->trash) {
JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
}
//Check permissions
if ($params->get('comments') == '2' && $user->id > 0 && K2HelperPermissions::canAddComment($item->catid) || $params->get('comments') == '1') {
// If new antispam settings are not saved, show a message to the comments form and stop the comment submission
$antispamProtection = $params->get('antispam', null);
if ($antispamProtection === null || ($antispamProtection == 'recaptcha' || $antispamProtection == 'both') && !$params->get('recaptcha_private_key') || ($antispamProtection == 'akismet' || $antispamProtection == 'both') && !$params->get('akismetApiKey')) {
$response->message = JText::_('K2_ANTISPAM_SETTINGS_ERROR');
echo $json->encode($response);
$mainframe->close();
}
$row = JTable::getInstance('K2Comment', 'Table');
if (!$row->bind(JRequest::get('post'))) {
$response->message = $row->getError();
echo $json->encode($response);
$mainframe->close();
}
$row->commentText = JRequest::getString('commentText', '', 'default');
$row->commentText = strip_tags($row->commentText);
//Strip a tags since all urls will be converted to links automatically on runtime.
//Additionaly strip tables to avoid layout issues.
//Also strip all attributes except src, alt and title.
//$filter = new JFilterInput(array('a', 'table'), array('src', 'alt', 'title'), 1);
//$row->commentText = $filter->clean( $row->commentText );
//Clean vars
$filter = JFilterInput::getInstance();
$row->userName = $filter->clean($row->userName, 'username');
if ($row->commentURL && preg_match('/^((http|https|ftp):\\/\\/)?[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,6}((:[0-9]{1,5})?\\/.*)?$/i', $row->commentURL)) {
$url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $row->commentURL);
$url = str_replace(';//', '://', $url);
if ($url != '') {
$url = !strstr($url, '://') ? 'http://' . $url : $url;
$url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&$1', $url);
$row->commentURL = $url;
}
} else {
$row->commentURL = '';
}
$datenow = JFactory::getDate();
$row->commentDate = K2_JVERSION == '15' ? $datenow->toMySQL() : $datenow->toSql();
if (!$user->guest) {
$row->userID = $user->id;
$row->commentEmail = $user->email;
$row->userName = $user->name;
}
$userName = trim($row->userName);
$commentEmail = trim($row->commentEmail);
$commentText = trim($row->commentText);
$commentURL = trim($row->commentURL);
if (empty($userName) || $userName == JText::_('K2_ENTER_YOUR_NAME') || empty($commentText) || $commentText == JText::_('K2_ENTER_YOUR_MESSAGE_HERE') || empty($commentEmail) || $commentEmail == JText::_('K2_ENTER_YOUR_EMAIL_ADDRESS')) {
$response->message = JText::_('K2_YOU_NEED_TO_FILL_IN_ALL_REQUIRED_FIELDS');
echo $json->encode($response);
$mainframe->close();
}
if (!JMailHelper::isEmailAddress($commentEmail)) {
$response->message = JText::_('K2_INVALID_EMAIL_ADDRESS');
echo $json->encode($response);
$mainframe->close();
}
if ($user->guest) {
$db = JFactory::getDBO();
$query = "SELECT COUNT(*) FROM #__users WHERE name=" . $db->Quote($userName) . " OR email=" . $db->Quote($commentEmail);
$db->setQuery($query);
$result = $db->loadresult();
if ($result > 0) {
$response->message = JText::_('K2_THE_NAME_OR_EMAIL_ADDRESS_YOU_TYPED_IS_ALREADY_IN_USE');
echo $json->encode($response);
$mainframe->close();
//.........这里部分代码省略.........
示例6: display
//.........这里部分代码省略.........
}
if ($item->publish_down != $nullDate && $item->publish_down < $now) {
JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
}
if (!$item->category->published || $item->category->trash) {
JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
}
// Increase hits counter
$model->hit($item->id);
// Set default image
K2HelperUtilities::setDefaultImage($item, $view);
// Pass the old parameter to the view in order to avoid layout changes
if ($params->get('antispam') == 'recaptcha' || $params->get('antispam') == 'both') {
$params->set('recaptcha', true);
$item->params->set('recaptcha', true);
} else {
$params->set('recaptcha', false);
$item->params->set('recaptcha', false);
}
// Comments
$item->event->K2CommentsCounter = '';
$item->event->K2CommentsBlock = '';
if ($item->params->get('itemComments')) {
// Trigger comments events
$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin('k2');
$results = $dispatcher->trigger('onK2CommentsCounter', array(&$item, &$params, $limitstart));
$item->event->K2CommentsCounter = trim(implode("\n", $results));
$results = $dispatcher->trigger('onK2CommentsBlock', array(&$item, &$params, $limitstart));
$item->event->K2CommentsBlock = trim(implode("\n", $results));
// Load K2 native comments system only if there are no plugins overriding it
if (empty($item->event->K2CommentsCounter) && empty($item->event->K2CommentsBlock)) {
// Load reCAPTCHA script
if (!JRequest::getInt('print') && ($item->params->get('comments') == '1' || $item->params->get('comments') == '2' && K2HelperPermissions::canAddComment($item->catid))) {
if ($params->get('recaptcha') && ($user->guest || $params->get('recaptchaForRegistered', 1))) {
$document->addScript('https://www.google.com/recaptcha/api/js/recaptcha_ajax.js');
$js = '
function showRecaptcha(){
Recaptcha.create("' . $item->params->get('recaptcha_public_key') . '", "recaptcha", {
theme: "' . $item->params->get('recaptcha_theme', 'clean') . '"
});
}
$K2(window).load(function() {
showRecaptcha();
});
';
$document->addScriptDeclaration($js);
}
}
// Check for inline comment moderation
if (!$user->guest && $user->id == $item->created_by && $params->get('inlineCommentsModeration')) {
$inlineCommentsModeration = true;
$commentsPublished = false;
} else {
$inlineCommentsModeration = false;
$commentsPublished = true;
}
$this->assignRef('inlineCommentsModeration', $inlineCommentsModeration);
// Flag spammer link
$reportSpammerFlag = false;
if (K2_JVERSION != '15') {
if ($user->authorise('core.admin', 'com_k2')) {
$reportSpammerFlag = true;
$document = JFactory::getDocument();
$document->addScriptDeclaration('var K2Language = ["' . JText::_('K2_REPORT_USER_WARNING', true) . '"];');
}