public function process() { define('PHPFOX_FEED_STREAM_MODE', true); if ($val = $this->request()->get('val')) { Phpfox::isUser(true); // if (isset($aVals['user_status']) && ($iId = Phpfox::getService('user.process')->updateStatus($aVals))) $val['user_status'] = $val['content']; $id = Phpfox::getService('user.process')->updateStatus($val); Feed_Service_Feed::instance()->processAjax($id); echo Phpfox_Ajax::instance()->getData(); exit; } $aFeedCallback = []; if ($module = $this->request()->get('module')) { $aFeedCallback = ['module' => $this->request()->get('module'), 'table_prefix' => $this->request()->get('module') . '_', 'item_id' => $this->request()->get('item_id')]; } $aFeed = Feed_Service_Feed::instance()->callback($aFeedCallback)->get(null, $this->request()->get('id')); header('Content-type: application/javascript'); if (!isset($aFeed[0])) { echo ';__(' . json_encode(['url' => $this->url()->makeUrl('feed.stream', ['id' => $this->request()->get('id')]), 'content' => false]) . ');'; exit; } $this->template()->assign('aGlobalUser', Phpfox::isUser() ? Phpfox::getUserBy(null) : array()); $this->template()->assign('aFeed', $aFeed[0]); $url = $this->url()->makeUrl('feed.stream', ['id' => $this->request()->get('id')]); if ($aFeedCallback) { $this->template()->assign('aFeedCallback', $aFeedCallback); $url = $this->url()->makeUrl('feed.stream', ['id' => $this->request()->get('id'), 'module' => $this->request()->get('module'), 'item_id' => $this->request()->get('item_id')]); } $this->template()->getTemplate('feed.block.entry'); echo ';__(' . json_encode(['url' => $url, 'content' => ob_get_clean()]) . ');'; exit; }
public function getGlobalNotifications() { $iTotal = Phpfox::getService('notification')->getUnseenTotal(); // $iTotal += Phpfox::getService('friend.request')->getUnseenTotal(); if ($iTotal > 0) { Phpfox_Ajax::instance()->call('$(\'#js_total_new_notifications\').html(\'' . (int) $iTotal . '\').css({display: \'block\'}).show();'); } }
public function processAjax($iId) { $oAjax = Phpfox_Ajax::instance(); $aFeeds = Feed_Service_Feed::instance()->get(Phpfox::getUserId(), $iId); if (!isset($aFeeds[0])) { $oAjax->alert(Phpfox::getPhrase('feed.this_item_has_successfully_been_submitted')); $oAjax->call('$Core.resetActivityFeedForm();'); return; } if (isset($aFeeds[0]['type_id'])) { Phpfox_Template::instance()->assign(array('aFeed' => $aFeeds[0], 'aFeedCallback' => array('module' => str_replace('_comment', '', $aFeeds[0]['type_id']), 'item_id' => $aFeeds[0]['item_id'])))->getTemplate(Profile_Service_Profile::instance()->timeline() ? 'feed.block.timeline' : 'feed.block.entry'); } else { Phpfox_Template::instance()->assign(array('aFeed' => $aFeeds[0]))->getTemplate('feed.block.entry'); } $sId = 'js_tmp_comment_' . md5('feed_' . uniqid() . Phpfox::getUserId()) . ''; $sNewContent = '<div id="' . $sId . '" class="js_temp_new_feed_entry js_feed_view_more_entry_holder">' . $oAjax->getContent(false) . '</div>'; if (Profile_Service_Profile::instance()->timeline()) { $oAjax->prepend('.timeline_left_new', '<div class="timeline_feed_row"><div class="timeline_arrow_left">0</div><div class="timeline_float_left">0</div>' . $sNewContent . '</div>'); } else { $oAjax->prepend('#js_new_feed_comment', $sNewContent); } // $oAjax->call('$(\'#' . $sId . '\').highlightFade();'); $oAjax->removeClass('.js_user_feed', 'row_first'); $oAjax->call("iCnt = 0; \$('.js_user_feed').each(function(){ iCnt++; if (iCnt == 1) { \$(this).addClass('row_first'); } });"); if ($oAjax->get('force_form')) { $oAjax->call('tb_remove();'); $oAjax->show('#js_main_feed_holder'); $oAjax->call('$Core.resetActivityFeedForm();'); } else { $oAjax->call('$Core.resetActivityFeedForm();'); } $oAjax->call('$Core.loadInit();'); }
/** * Starts the phpFox engine. Used to get and display the pages controller. * */ public static function run() { if (isset($_REQUEST['m9callback'])) { header('Content-type: application/json'); try { $Home = new Core\Home(PHPFOX_LICENSE_ID, PHPFOX_LICENSE_KEY); $callback = $_REQUEST['m9callback']; unset($_GET['m9callback'], $_GET['do']); if (!$_GET) { $_GET = []; } echo json_encode(call_user_func([$Home, $callback], $_GET)); } catch (\Exception $e) { // throw new \Exception($e->getMessage(), 0, $e); echo json_encode(['error' => $e->getMessage()]); } exit; } $oTpl = Phpfox_Template::instance(); $aLocale = Phpfox_Locale::instance()->getLang(); $oReq = Phpfox_Request::instance(); $oModule = Phpfox_Module::instance(); if ($oReq->segment(1) == 'favicon.ico') { header('Content-type: image/x-icon'); echo file_get_contents('http://www.phpfox.com/favicon.ico'); exit; } $aStaticFolders = ['file', 'static', 'module', 'apps', 'Apps', 'themes']; if (in_array($oReq->segment(1), $aStaticFolders) || $oReq->segment(1) == 'theme' && $oReq->segment(2) != 'demo' && $oReq->segment(1) == 'theme' && $oReq->segment(2) != 'sample') { $sUri = Phpfox_Url::instance()->getUri(); if ($sUri == '/static/ajax.php') { $oAjax = Phpfox_Ajax::instance(); $oAjax->process(); echo $oAjax->getData(); exit; } if (Phpfox::getParam('core.url_rewrite') == '1') { header("HTTP/1.0 404 Not Found"); header('Content-type: application/json'); echo json_encode(['error' => 404]); exit; } $HTTPCache = new Core\HTTP\Cache(); $HTTPCache->checkCache(); $sDir = PHPFOX_DIR; if ($oReq->segment(1) == 'Apps' || $oReq->segment(1) == 'apps' || $oReq->segment(1) == 'themes') { $sDir = PHPFOX_DIR_SITE; } $sPath = $sDir . ltrim($sUri, '/'); if ($oReq->segment(1) == 'themes' && $oReq->segment(2) == 'default') { $sPath = PHPFOX_DIR . str_replace('themes/default', 'theme/default', $sUri); } if ($oReq->segment(3) == 'emoticon') { $sPath = str_replace('/file/pic/emoticon/default/', PHPFOX_DIR . 'static/image/emoticon/', $sUri); } $sType = Phpfox_File::instance()->mime($sUri); $sExt = Phpfox_File::instance()->extension($sUri); if (!file_exists($sPath)) { $sPath = str_replace('PF.Base', 'PF.Base/..', $sPath); // header('Content-type: ' . $sType); if (!file_exists($sPath)) { header("HTTP/1.0 404 Not Found"); header('Content-type: application/json'); echo json_encode(['error' => 404]); exit; } } // header('Content-type: ' . $sType); $HTTPCache->cache($sType, filemtime($sPath), 7); if ($oReq->segment(1) == 'themes') { $Theme = $oTpl->theme()->get(); $Service = new Core\Theme\Service($Theme); if ($sType == 'text/css') { echo $Service->css()->getParsed(); } else { echo $Service->js()->get(); } } else { echo @file_get_contents($sPath); } exit; } ($sPlugin = Phpfox_Plugin::get('run_start')) ? eval($sPlugin) : false; // Load module blocks $oModule->loadBlocks(); if (!Phpfox::getParam('core.branding')) { $oTpl->setHeader(array('<meta name="author" content="PHPfox" />')); } if (strtolower(Phpfox_Request::instance()->get('req1')) == Phpfox::getParam('admincp.admin_cp')) { self::$_bIsAdminCp = true; } $View = $oModule->setController(); if ($View instanceof Core\View) { } else { if (!self::$_bIsAdminCp) { $View = new Core\View(); } } if (!PHPFOX_IS_AJAX_PAGE) { $oTpl->setImage(array('ajax_small' => 'ajax/small.gif', 'ajax_large' => 'ajax/large.gif', 'loading_animation' => 'misc/loading_animation.gif', 'close' => 'misc/close.gif', 'move' => 'misc/move.png', 'calendar' => 'jquery/calendar.gif')); $oTpl->setHeader(array('<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />', '<meta http-equiv="Content-Type" content="text/html; charset=' . $aLocale['charset'] . '" />', '<meta http-equiv="cache-control" content="no-cache" />', '<meta http-equiv="expires" content="-1" />', '<meta http-equiv="pragma" content="no-cache" />', '<link rel="shortcut icon" type="image/x-icon" href="' . Phpfox::getParam('core.path') . 'favicon.ico?v=' . $oTpl->getStaticVersion() . '" />'))->setMeta('keywords', Phpfox_Locale::instance()->convert(Phpfox::getParam('core.keywords')))->setMeta('robots', 'index,follow'); $oTpl->setHeader('cache', Phpfox::getMasterFiles()); if (Phpfox::isModule('friend')) { $oTpl->setPhrase(array('friend.show_more_results_for_search_term')); } if (PHPFOX_DEBUG) { $oTpl->setHeader('cache', array('debug.css' => 'style_css')); } if (!Phpfox::isMobile() && Phpfox::isUser() && Phpfox::getParam('user.enable_user_tooltip')) { $oTpl->setHeader('cache', array('user_info.js' => 'static_script')); } if (Phpfox::isModule('captcha') && Phpfox::getParam('captcha.recaptcha')) { // http://www.phpfox.com/tracker/view/14456/ $sUrl = (Phpfox::getParam('core.force_https_secure_pages') ? 'https' : 'http') . "://www.google.com/recaptcha/api/js/recaptcha_ajax.js"; $oTpl->setHeader('<script type="text/javascript" src="' . $sUrl . '"></script>'); } } if ($sPlugin = Phpfox_Plugin::get('get_controller')) { eval($sPlugin); } $oTpl->assign(['aGlobalUser' => Phpfox::isUser() ? Phpfox::getUserBy(null) : array()]); $oModule->getController(); Phpfox::getService('admincp.seo')->setHeaders(); if (!defined('PHPFOX_DONT_SAVE_PAGE')) { Phpfox::getLib('session')->set('redirect', Phpfox_Url::instance()->getFullUrl(true)); } if (!defined('PHPFOX_NO_CSRF')) { Phpfox::getService('log.session')->verifyToken(); } ($sPlugin = Phpfox_Plugin::get('run')) ? eval($sPlugin) : false; if (!self::isAdminPanel()) { if (!Phpfox::isMobile() && !PHPFOX_IS_AJAX_PAGE && Phpfox::isModule('rss') && !defined('PHPFOX_IS_USER_PROFILE')) { $aFeeds = Phpfox::getService('rss')->getLinks(); if (is_array($aFeeds) && count($aFeeds)) { foreach ($aFeeds as $sLink => $sPhrase) { $oTpl->setHeader('<link rel="alternate" type="application/rss+xml" title="' . $sPhrase . '" href="' . $sLink . '" />'); } } } $aPageLastLogin = Phpfox::isModule('pages') && Phpfox::getUserBy('profile_page_id') ? Phpfox::getService('pages')->getLastLogin() : false; $oTpl->assign(array('aMainMenus' => $oTpl->getMenu('main'), 'aSubMenus' => $oTpl->getMenu(), 'bIsUsersProfilePage' => defined('PHPFOX_IS_USER_PROFILE') ? true : false, 'sGlobalUserFullName' => Phpfox::isUser() ? Phpfox::getUserBy('full_name') : null, 'sFullControllerName' => str_replace(array('.', '/'), '_', Phpfox_Module::instance()->getFullControllerName()), 'iGlobalProfilePageId' => Phpfox::getUserBy('profile_page_id'), 'aGlobalProfilePageLogin' => $aPageLastLogin)); $oTpl->setEditor(); if (Phpfox::isModule('captcha')) { $sCaptchaHeader = Phpfox::getParam('captcha.recaptcha_header'); if (strlen(preg_replace('/\\s\\s+/', '', $sCaptchaHeader)) > 0) { $oTpl->setHeader(array($sCaptchaHeader)); } } if (Phpfox::isModule('notification') && Phpfox::isUser() && Phpfox::getParam('notification.notify_on_new_request')) { $oTpl->setHeader('cache', array('update.js' => 'module_notification')); } } if (!PHPFOX_IS_AJAX_PAGE && ($sHeaderFile = $oTpl->getHeaderFile())) { ($sPlugin = Phpfox_Plugin::get('run_get_header_file_1')) ? eval($sPlugin) : false; require_once $sHeaderFile; } list($aBreadCrumbs, $aBreadCrumbTitle) = $oTpl->getBreadCrumb(); $oTpl->assign(array('aErrors' => Phpfox_Error::getDisplay() ? Phpfox_Error::get() : array(), 'sPublicMessage' => Phpfox::getMessage(), 'sLocaleDirection' => $aLocale['direction'], 'sLocaleCode' => $aLocale['language_code'], 'sLocaleFlagId' => $aLocale['image'], 'sLocaleName' => $aLocale['title'], 'aBreadCrumbs' => $aBreadCrumbs, 'aBreadCrumbTitle' => $aBreadCrumbTitle, 'sCopyright' => '© ' . Phpfox::getPhrase('core.copyright') . ' ' . Phpfox::getParam('core.site_copyright'))); Phpfox::clearMessage(); unset($_SESSION['phpfox']['image']); if (Phpfox::getParam('core.cron')) { require_once PHPFOX_DIR_CRON . 'exec.php'; } if ($oReq->isPost()) { header('X-Is-Posted: true'); exit; } if ($oReq->get('is_ajax_get')) { header('X-Is-Get: true'); exit; } if (defined('PHPFOX_SITE_IS_OFFLINE')) { $oTpl->sDisplayLayout = 'blank'; unset($View); } if (!PHPFOX_IS_AJAX_PAGE && $oTpl->sDisplayLayout && !isset($View) || !PHPFOX_IS_AJAX_PAGE && self::isAdminPanel()) { $oTpl->getLayout($oTpl->sDisplayLayout); } if (PHPFOX_IS_AJAX_PAGE) { header('Content-type: application/json; charset=utf-8'); /* if (isset($View) && $View instanceof \Core\View) { $content = $View->getContent(); } else { Phpfox_Module::instance()->getControllerTemplate(); $content = ob_get_contents(); ob_clean(); } */ if ($View instanceof \Core\View) { $content = $View->getContent(); } else { Phpfox_Module::instance()->getControllerTemplate(); $content = ob_get_contents(); ob_clean(); } $oTpl->getLayout('breadcrumb'); $breadcrumb = ob_get_contents(); ob_clean(); $aHeaderFiles = Phpfox_Template::instance()->getHeader(true); $aCss = []; $aLoadFiles = []; foreach ($aHeaderFiles as $sHeaderFile) { if (!is_string($sHeaderFile)) { continue; } if (preg_match('/<style(.*)>(.*)<\\/style>/i', $sHeaderFile)) { $aCss[] = strip_tags($sHeaderFile); continue; } if (preg_match('/href=(["\']?([^"\'>]+)["\']?)/', $sHeaderFile, $aMatches) > 0 && strpos($aMatches[1], '.css') !== false) { $sHeaderFile = str_replace(array('"', "'"), '', $aMatches[1]); $sHeaderFile = substr($sHeaderFile, 0, strpos($sHeaderFile, '?')); } $sHeaderFile = strip_tags($sHeaderFile); $sNew = preg_replace('/\\s+/', '', $sHeaderFile); if (empty($sNew)) { continue; } $aLoadFiles[] = $sHeaderFile; } $blocks = []; foreach (range(1, 12) as $location) { if ($location == 3) { echo \Phpfox_Template::instance()->getSubMenu(); } $aBlocks = Phpfox_Module::instance()->getModuleBlocks($location); $blocks[$location] = []; foreach ($aBlocks as $sBlock) { Phpfox::getBlock($sBlock); $blocks[$location][] = ob_get_contents(); ob_clean(); } } $oTpl->getLayout('search'); $search = ob_get_contents(); ob_clean(); Phpfox::getBlock('core.template-menusub'); $menuSub = ob_get_contents(); ob_clean(); $h1 = ''; if (isset($aBreadCrumbTitle[1])) { $h1 .= '<h1><a href="' . $aBreadCrumbTitle[1] . '">' . Phpfox_Parse_Output::instance()->clean($aBreadCrumbTitle[0]) . '</a></h1>'; } $oTpl->getLayout('error'); $error = ob_get_contents(); ob_clean(); $controller = Phpfox_Module::instance()->getFullControllerName(); $data = json_encode(['content' => str_replace(['''], ["'"], Phpfox_Parse_Input::instance()->convert($content)), 'title' => html_entity_decode($oTpl->instance()->getTitle()), 'phrases' => Phpfox_Template::instance()->getPhrases(), 'files' => $aLoadFiles, 'css' => $aCss, 'breadcrumb' => $breadcrumb, 'blocks' => $blocks, 'search' => $search, 'menuSub' => $menuSub, 'id' => Phpfox_Module::instance()->getPageId(), 'class' => Phpfox_Module::instance()->getPageClass(), 'h1' => $h1, 'h1_clean' => strip_tags($h1), 'error' => $error, 'controller_e' => Phpfox::isAdmin() ? Phpfox_Url::instance()->makeUrl('admincp.element.edit', ['controller' => base64_encode(Phpfox_Module::instance()->getFullControllerName())]) : null, 'meta' => Phpfox_Template::instance()->getPageMeta(), 'keep_body' => Phpfox_Template::instance()->keepBody()]); // header("Content-length: " . strlen($data)); echo $data; // sleep(4); } else { if (isset($View)) { echo $View->getContent(); } } }
/** * Controller */ public function process() { Phpfox::isUser(true); $bCanEditPersonalData = true; $aCallback = false; if ($this->request()->get('module')) { $this->template()->assign(array('bIsGroup' => '1')); } if (($sModule = $this->request()->get('module')) && Phpfox::isModule($sModule) && ($iItemId = $this->request()->getInt('item')) && Phpfox::hasCallback($sModule, 'addForum')) { $aCallback = Phpfox::callback($sModule . '.addForum', $iItemId); $this->template()->setBreadcrumb(Phpfox::getPhrase('forum.pages'), $this->url()->makeUrl('pages')); $this->template()->setBreadcrumb($aCallback['title'], $aCallback['url_home']); $this->template()->setBreadcrumb(Phpfox::getPhrase('forum.discussions'), $aCallback['url_home'] . 'forum/'); if ($sModule == 'pages' && !Phpfox::getService('pages')->hasPerm($iItemId, 'forum.share_forum')) { return Phpfox_Error::display(Phpfox::getPhrase('forum.unable_to_view_this_item_due_to_privacy_settings')); } } else { $this->template()->setBreadcrumb(Phpfox::getPhrase('forum.forum'), $this->url()->makeUrl('forum')); } $iId = $this->request()->getInt('id'); $aAccess = Forum_Service_Forum::instance()->getUserGroupAccess($iId, Phpfox::getUserBy('user_group_id')); if ($aAccess['can_view_thread_content']['value'] != true) { return Phpfox_Error::display(Phpfox::getPhrase('forum.unable_to_view_this_item_due_to_privacy_settings')); } if (Phpfox::isModule('poll')) { $this->template()->setHeader('cache', array('poll.js' => 'module_poll', '<script type="text/javascript">$Behavior.loadSortableAnswers = function() {$(".sortable").sortable({placeholder: "placeholder", axis: "y"});}</script>')); } $this->template()->setEditor()->setTitle(Phpfox::getPhrase('forum.forum'))->setHeader('cache', array('switch_legend.js' => 'static_script', 'switch_menu.js' => 'static_script', 'pager.css' => 'style_css', 'forum.css' => 'style_css')); $bIsEdit = false; if ($this->request()->get('req3') == 'thread') { if ($iEditId = $this->request()->getInt('edit')) { $aThread = Forum_Service_Thread_Thread::instance()->getForEdit($iEditId); if (!isset($aThread['thread_id'])) { return Phpfox_Error::display(Phpfox::getPhrase('forum.not_a_valid_thread')); } if (Phpfox::getUserParam('forum.can_edit_own_post') && $aThread['user_id'] == Phpfox::getUserId() || Phpfox::getUserParam('forum.can_edit_other_posts') || Phpfox::getService('forum.moderate')->hasAccess($aThread['forum_id'], 'edit_post')) { $bIsEdit = true; if (Phpfox::getUserParam('forum.can_edit_other_posts') && Phpfox::getUserId() != $aThread['user_id']) { $bCanEditPersonalData = false; } $iId = $aThread['forum_id']; if (Phpfox::isModule('tag')) { $aThread['tag_list'] = Tag_Service_Tag::instance()->getForEdit('forum', $aThread['thread_id']); } $this->template()->assign(array('aForms' => $aThread, 'iEditId' => $aThread['thread_id'])); } else { return Phpfox_Error::display(Phpfox::getPhrase('forum.insufficient_permission_to_edit_this_thread')); } } if ($aCallback === false) { $aForum = Phpfox::getService('forum')->id($iId)->getForum(); if (!isset($aForum['forum_id'])) { return Phpfox_Error::display(Phpfox::getPhrase('forum.not_a_valid_forum')); } if ($aForum['is_closed']) { return Phpfox_Error::display(Phpfox::getPhrase('forum.forum_is_closed')); } } if (!$bIsEdit) { $bPass = false; if (Phpfox::getUserParam('forum.can_add_new_thread') || Phpfox::getService('forum.moderate')->hasAccess($aForum['forum_id'], 'add_thread')) { $bPass = true; } if ($bPass === false) { return Phpfox_Error::display(Phpfox::getPhrase('forum.insufficient_permission_to_reply_to_this_thread')); } } if (!Forum_Service_Forum::instance()->hasAccess($iId, 'can_start_thread')) { return Phpfox_Error::display('You are unable to create a new post in this forum.'); } $aValidation = array('title' => Phpfox::getPhrase('forum.provide_a_title_for_your_thread'), 'text' => Phpfox::getPhrase('forum.provide_some_text')); if (Phpfox::isModule('captcha') && Phpfox::getUserParam('forum.enable_captcha_on_posting')) { $aValidation['image_verification'] = Phpfox::getPhrase('captcha.complete_captcha_challenge'); } $oValid = Phpfox_Validator::instance()->set(array('sFormName' => 'js_form', 'aParams' => $aValidation)); $bPosted = false; if ($aVals = $this->request()->getArray('val')) { if (isset($aVals['type_id']) && $aVals['type_id'] == 'announcement') { $bPosted = true; } if ($oValid->isValid($aVals)) { if ($bIsEdit) { $aVals['post_id'] = $aThread['start_id']; $aVals['was_announcement'] = $aThread['is_announcement']; $aVals['forum_id'] = $aThread['forum_id']; if (Phpfox::getService('forum.thread.process')->update($aThread['thread_id'], $aThread['user_id'], $aVals)) { $this->url()->permalink('forum.thread', $aThread['thread_id'], Phpfox::getLib('parse.input')->clean($aVals['title'], 255), true, Phpfox::getPhrase('forum.thread_successfully_updated')); } } else { if (($iFlood = Phpfox::getUserParam('forum.forum_thread_flood_control')) !== 0) { $aFlood = array('action' => 'last_post', 'params' => array('field' => 'time_stamp', 'table' => Phpfox::getT('forum_thread'), 'condition' => 'user_id = ' . Phpfox::getUserId(), 'time_stamp' => $iFlood * 60)); // actually check if flooding if (Phpfox::getLib('spam')->check($aFlood)) { Phpfox_Error::set(Phpfox::getPhrase('forum.posting_a_new_thread_a_little_too_soon') . ' ' . Phpfox::getLib('spam')->getWaitTime()); } } if (Phpfox_Error::isPassed() && ($iId = Phpfox::getService('forum.thread.process')->add($aVals, $aCallback))) { $this->url()->permalink('forum.thread', $iId, Phpfox::getLib('parse.input')->clean($aVals['title'], 255), true); } } } } if ($aCallback === false) { $this->template()->setBreadcrumb($aForum['breadcrumb'])->setBreadcrumb($aForum['name'], $this->url()->permalink('forum', $aForum['forum_id'], $aForum['name']))->setBreadcrumb($bIsEdit ? Phpfox::getPhrase('forum.editing_thread') . ': ' . $aThread['title'] : Phpfox::getPhrase('forum.post_new_thread'), $this->url()->makeUrl('forum.post.thread'), true); } else { $this->template()->setBreadcrumb($bIsEdit ? Phpfox::getPhrase('forum.editing_thread') . ': ' . $aThread['title'] : Phpfox::getPhrase('forum.post_new_thread'), $this->url()->makeUrl('forum.post.thread'), true); } $this->template()->assign(array('iForumId' => $iId, 'iActualForumId' => $iId, 'sFormLink' => $aCallback == false ? $this->url()->makeUrl('forum.post.thread', array('id' => $iId)) : $this->url()->makeUrl('forum.post.thread', array('module' => $sModule, 'item' => $iItemId)), 'sCreateJs' => $oValid->createJS(), 'sGetJsForm' => $oValid->getJsForm(), 'sForumParents' => $aCallback === false ? Phpfox::getUserParam('forum.can_post_announcement') || Phpfox::getService('forum.moderate')->hasAccess($aForum['forum_id'], 'post_announcement') ? Phpfox::getService('forum')->active($aForum['forum_id'])->getJumpTool(true) : '' : '', 'bPosted' => $bPosted, 'sReturnLink' => $bIsEdit ? $aCallback === false ? $this->url()->makeUrl('forum', array($aForum['name_url'] . '-' . $aForum['forum_id'], $aThread['title_url'])) : $this->url()->makeUrl($aCallback['url_home'] . '.forum', $aThread['title_url']) : '', 'bIsEdit' => $bIsEdit, 'aCallback' => $aCallback)); if (Phpfox::getUserParam('forum.can_add_forum_attachments')) { $this->setParam('attachment_share', array('type' => 'forum', 'id' => 'js_forum_form')); } } else { if ($iEditId = $this->request()->getInt('edit')) { $aPost = Phpfox::getService('forum.post')->getForEdit($iEditId); if (!isset($aPost['post_id'])) { return Phpfox_Error::display(Phpfox::getPhrase('forum.not_a_valid_post')); } $bCanEditPost = Phpfox::getUserParam('forum.can_edit_own_post') && $aPost['user_id'] == Phpfox::getUserId() || Phpfox::getUserParam('forum.can_edit_other_posts') || Phpfox::getService('forum.moderate')->hasAccess($aPost['forum_id'], 'edit_post'); if ($bCanEditPost) { $bIsEdit = true; if (Phpfox::getUserParam('forum.can_edit_other_posts') && Phpfox::getUserId() != $aPost['user_id']) { $bCanEditPersonalData = false; } $iId = $aPost['thread_id']; $this->template()->assign(array('aForms' => $aPost, 'iEditId' => $aPost['post_id'])); if (PHPFOX_IS_AJAX) { Phpfox_Ajax::instance()->setTitle(Phpfox::getPhrase('forum.editing_post') . ': ' . (empty($aPost['title']) ? '#' . $aPost['post_id'] : Phpfox::getLib('parse.output')->shorten($aPost['title'], 80, '...'))); } } else { return Phpfox_Error::display(Phpfox::getPhrase('forum.insufficient_permission_to_edit_this_thread')); } } $aThread = Forum_Service_Thread_Thread::instance()->getActualThread($iId, $aCallback); if (!isset($aThread['thread_id'])) { return Phpfox_Error::display(Phpfox::getPhrase('forum.not_a_valid_thread')); } if ($aThread['is_closed'] && (isset($bCanEditPost) && !$bCanEditPost || !isset($bCanEditPost))) { return Phpfox_Error::display(Phpfox::getPhrase('forum.thread_is_closed')); } if ($aCallback === false && $aThread['forum_is_closed']) { return Phpfox_Error::display(Phpfox::getPhrase('forum.forum_is_closed')); } if (!$iEditId && $aThread['is_announcement']) { return Phpfox_Error::display(Phpfox::getPhrase('forum.thread_is_an_announcement_not_allowed_to_leave_a_reply')); } if (!$bIsEdit) { $bPass = false; if (Phpfox::getUserParam('forum.can_reply_to_own_thread') && $aThread['user_id'] == Phpfox::getUserId() || Phpfox::getUserParam('forum.can_reply_on_other_threads') || Phpfox::getService('forum.moderate')->hasAccess($aThread['forum_id'], 'can_reply')) { $bPass = true; } if ($bPass === false) { return Phpfox_Error::display(Phpfox::getPhrase('forum.insufficient_permission_to_reply_to_this_thread')); } } $sExtraText = ''; if ($sSavedText = $this->request()->get('save_text')) { $sExtraText .= Phpfox::getLib('parse.output')->clean($sSavedText); } if (Phpfox::getUserParam('forum.can_multi_quote_forum') && (($iQuote = $this->request()->getInt('quote')) || ($sCookie = Phpfox::getCookie('forum_quote')) && !empty($sCookie))) { $sCookie = Phpfox::getCookie('forum_quote'); if (!empty($sCookie)) { $iQuote = $sCookie . $iQuote; } $sExtraText .= Phpfox::getService('forum.post')->getQuotes($aThread['thread_id'], $iQuote); } if (($iQuoteId = $this->request()->getInt('quote')) && ($aQuotePost = Phpfox::getService('forum.post')->getForEdit($iQuoteId))) { Phpfox_Ajax::instance()->setTitle(Phpfox::getPhrase('forum.replying_to_a_post_by_full_name', array('full_name' => Phpfox::getLib('parse.output')->shorten($aQuotePost['full_name'], 80, '...')))); } $aSubForms = array(); if (isset($aThread['is_subscribed'])) { $aSubForms['is_subscribed'] = $aThread['is_subscribed']; } if (!empty($sExtraText)) { $aSubForms['text'] = $sExtraText; } if (isset($bCanEditPost) && $bCanEditPost) { $aSubForms = array_merge($aSubForms, $aPost); } $this->template()->assign('aForms', $aSubForms); $aValidation = array('text' => Phpfox::getPhrase('forum.provide_some_text')); if (Phpfox::isModule('captcha') && Phpfox::getUserParam('forum.enable_captcha_on_posting')) { $aValidation['image_verification'] = Phpfox::getPhrase('captcha.complete_captcha_challenge'); } $oValid = Phpfox_Validator::instance()->set(array('sFormName' => 'js_form', 'aParams' => $aValidation)); $aForum = Phpfox::getService('forum')->id($aThread['forum_id'])->getForum(); if ($aVals = $this->request()->getArray('val')) { $aVals['forum_id'] = $aThread['forum_id']; if ($oValid->isValid($aVals)) { Phpfox::setCookie('forum_quote', '', -1); if ($bIsEdit) { if (Phpfox::getService('forum.post.process')->update($aPost['post_id'], $aPost['user_id'], $aVals)) { $this->url()->permalink('forum', $aThread['thread_id'], $aThread['title'], true, null, array('post' => $aPost['post_id'])); } } else { if (($iFlood = Phpfox::getUserParam('forum.forum_post_flood_control')) !== 0) { $aFlood = array('action' => 'last_post', 'params' => array('field' => 'time_stamp', 'table' => Phpfox::getT('forum_post'), 'condition' => 'user_id = ' . Phpfox::getUserId(), 'time_stamp' => $iFlood * 60)); // actually check if flooding if (Phpfox::getLib('spam')->check($aFlood)) { Phpfox_Error::set(Phpfox::getPhrase('forum.posting_a_reply_a_little_too_soon') . ' ' . Phpfox::getLib('spam')->getWaitTime()); } } if (Phpfox_Error::isPassed()) { if ($iId = Phpfox::getService('forum.post.process')->add($aVals, $aCallback)) { $this->url()->permalink('forum', $aThread['thread_id'], $aThread['title'], true, null, array('post' => $iId)); } else { if (Phpfox::getUserParam('forum.approve_forum_post')) { $this->url()->permalink('forum', $aThread['thread_id'], $aThread['title'], true, Phpfox::getPhrase('forum.your_post_has_successfully_been_added_however_it_is_pending_an_admins_approval_before_it_can_be_displayed_publicly'), array('post' => $iId)); } } } } } } if ($aCallback === false) { $this->template()->setBreadcrumb($aForum['breadcrumb'])->setBreadcrumb($aForum['name'], $this->url()->makeUrl('forum', $aForum['name_url'] . '-' . $aForum['forum_id'])); } else { } $this->template()->setBreadcrumb($aThread['title'], $aCallback === false ? $this->url()->makeUrl('forum', array($aForum['name_url'] . '-' . $aForum['forum_id'], $aThread['title_url'])) : $this->url()->makeUrl($aCallback['url_home'] . '.forum', $aThread['title_url']))->setBreadcrumb($bIsEdit ? Phpfox::getPhrase('forum.editing_post') . ': ' . (empty($aPost['title']) ? '#' . $aPost['post_id'] : $aPost['title']) : Phpfox::getPhrase('forum.post_new_reply'), $bIsEdit ? $aCallback === false ? $this->url()->makeUrl('forum', array($aThread['forum_url'] . '-' . $aThread['forum_id'], $aThread['title_url'], 'post_' . $aPost['post_id'])) : $this->url()->makeUrl($aCallback['url_home'] . '.forum', array($aThread['title_url'], 'post' => $aPost['post_id'])) : null, true)->assign(array('iThreadId' => $iId, 'iActualForumId' => $aForum['forum_id'], 'sFormLink' => $aCallback === false ? $this->url()->makeUrl('forum.post.reply', array('id' => $iId)) : $this->url()->makeUrl('forum.post.reply', array('id' => $iId, 'module' => $sModule, 'item' => $iItemId)), 'sCreateJs' => $oValid->createJS(), 'sGetJsForm' => $oValid->getJsForm(PHPFOX_IS_AJAX ? false : true), 'sReturnLink' => $bIsEdit ? $aCallback === false ? $this->url()->makeUrl('forum', array($aThread['forum_url'] . '-' . $aThread['forum_id'], $aThread['title_url'], 'post_' . $aPost['post_id'])) : $this->url()->makeUrl($aCallback['url_home'] . '.forum', $aThread['title_url']) : '', 'sThreadReturnLink' => $aCallback === false ? $this->url()->makeUrl('forum', array($aThread['forum_url'] . '-' . $aThread['forum_id'], $aThread['title_url'])) : $this->url()->makeUrl($aCallback['url_home'], array('forum', $aThread['title_url'])), 'aPreviews' => Phpfox::getService('forum.post')->getPreview($aThread['thread_id']), 'iTotalPosts' => $aThread['total_post'], 'bIsEdit' => $bIsEdit, 'aCallback' => $aCallback, 'iTotalPostPreview' => Phpfox::getParam('forum.total_forum_post_preview'))); if (Phpfox::getUserParam('forum.can_add_forum_attachments')) { $this->setParam('attachment_share', array('type' => 'forum', 'inline' => PHPFOX_IS_AJAX ? true : false, 'id' => 'js_forum_form', 'edit_id' => $bIsEdit ? $aPost['post_id'] : '')); } } }
private function _loadLikeBlock($iPage) { $aPage = Phpfox::getService('pages')->getForView($iPage); $oAjax = Phpfox_Ajax::instance(); Phpfox_Template::instance()->assign('aPage', $aPage); Phpfox_Component::setPublicParam('aPage', $aPage); Phpfox::getBlock('pages.like'); $oAjax->html('#js_pages_like_join_holder', $oAjax->getContent(false)); }
public function getGlobalNotifications() { $iTotal = Mail_Service_Mail::instance()->getUnseenTotal(); if ($iTotal > 0) { Phpfox_Ajax::instance()->call('$(\'#js_total_new_messages\').html(\'' . (int) $iTotal . '\').css({display: \'block\'}).show();'); } }
public function getReturn() { if (!$this->_bReturn) { Phpfox_Ajax::instance()->call('$Core.processForm(\'#js_mail_compose_submit\', true);'); } return $this->_bReturn; }
/** * Controller */ public function process() { Phpfox::isUser(true); Phpfox::getUserParam('music.can_upload_music_public', true); $sModule = $this->request()->get('module', false); $iItem = $this->request()->getInt('item', false); $aCallback = false; if ($sModule !== false && $iItem !== false && Phpfox::hasCallback($sModule, 'getMusicDetails')) { if ($aCallback = Phpfox::callback($sModule . '.getMusicDetails', array('item_id' => $iItem))) { $this->template()->setBreadcrumb($aCallback['breadcrumb_title'], $aCallback['breadcrumb_home']); $this->template()->setBreadcrumb($aCallback['title'], $aCallback['url_home']); if ($sModule == 'pages' && !Phpfox::getService('pages')->hasPerm($iItem, 'music.share_music')) { return Phpfox_Error::display('Unable to view this item due to privacy settings.'); } } } $bIsEdit = false; $aValidation = array('title' => Phpfox::getPhrase('music.provide_a_name_for_this_song')); $oValidator = Phpfox_Validator::instance()->set(array('sFormName' => 'js_music_form', 'aParams' => $aValidation)); if (($iId = $this->request()->getInt('id')) && ($aEditSong = Phpfox::getService('music')->getForEdit($iId))) { if ($aEditSong['module_id'] == 'pages') { Phpfox::getService('pages')->setIsInPage(); } $bIsEdit = true; $this->template()->assign(array('aForms' => $aEditSong)); } $sMethod = Phpfox::getParam('music.music_enable_mass_uploader') && $this->request()->get('method', 'massuploader') == 'massuploader' ? 'massuploader' : 'simple'; // used to tell the template where to link for the opposite method $sMethodUrl = str_replace(array('method_simple/', 'method_massuploader/'), '', $this->url()->getFullUrl()) . 'method_' . ($sMethod == 'simple' ? 'massuploader' : 'simple') . '/'; $aVals = $this->request()->getArray('val'); if (isset($aVals['method'])) { $sMethod = $aVals['method']; } if ($bIsEdit && !empty($aVals) && $this->request()->get('upload_via_song')) { if ($oValidator->isValid($aVals)) { if (Music_Service_Process::instance()->update($aEditSong['song_id'], $aVals)) { $this->url()->permalink('music', $aEditSong['song_id'], $aEditSong['title'], true, 'Song successfully updated.'); } } } else { if ($sMethod == 'simple' && !empty($aVals)) { if (isset($aVals['music_title'])) { $aVals['title'] = $aVals['music_title']; } if ($oValidator->isValid($aVals)) { if ($aSong = Music_Service_Process::instance()->upload($aVals, isset($aVals['album_id']) ? (int) $aVals['album_id'] : 0)) { if (isset($aVals['iframe'])) { if (isset($aVals['music_title'])) { $iFeedId = Phpfox::getService('feed.process')->getLastId(); echo "<script type=\"text/javascript\">"; if (Phpfox::isModule('video') && Phpfox::getParam('video.convert_servers_enable')) { echo 'document.domain = "' . Phpfox::getParam('video.convert_js_parent') . '";'; } ($sPlugin = Phpfox_Plugin::get('music.component_controller_upload_feed')) ? eval($sPlugin) : false; echo 'window.parent.$.ajaxCall(\'music.displayFeed\', \'id=' . $iFeedId . '&song_id=' . $aSong['song_id'] . '\', \'GET\');'; echo "</script>"; } else { Phpfox::addMessage(Phpfox::getPhrase('music.song_successfully_uploaded')); echo "<script type=\"text/javascript\">"; echo 'window.parent.location.href = "' . $this->url()->makeUrl('music.album.track', array('id' => $aVals['album_id'], 'method' => 'simple')) . '";'; echo '</script>'; } } else { Phpfox::addMessage(Phpfox::getPhrase('music.song_successfully_uploaded')); echo "<script type=\"text/javascript\">"; echo 'window.parent.location.href = "' . $this->url()->permalink('music', $aSong['song_id'], $aSong['title']) . '";'; echo '</script>'; exit; } exit; } else { if (isset($aVals['music_title'])) { echo "<script type=\"text/javascript\">"; echo 'window.parent.$Core.resetActivityFeedError(\'' . implode('<br />', Phpfox_Error::get()) . '\');'; echo "</script>"; } else { echo "<script type=\"text/javascript\">"; echo 'window.parent.$(\'#js_music_upload_song\').show(); window.parent.$(\'.js_upload_song\').remove();'; echo 'window.parent.alert(\'' . implode('\\n', Phpfox_Error::get()) . '\');'; echo "</script>"; exit; } } } else { if (isset($aVals['music_title'])) { echo "<script type=\"text/javascript\">"; echo 'window.parent.$Core.resetActivityFeedError(\'' . implode('<br />', Phpfox_Error::get()) . '\');'; echo "</script>"; } else { echo '<script type="text/javascript">'; echo 'window.parent.$Core.resetActivityFeedError(\'' . implode('<br />', Phpfox_Error::get()) . '\');'; echo 'window.parent.$Core.music.resetUploadForm(\'' . implode('<br />', Phpfox_Error::get()) . '\');'; echo '</script>'; exit; } } } elseif ($sMethod == 'massuploader' && isset($_FILES['Filedata'])) { $_FILES['mp3'] = $_FILES['Filedata']; if ($aSong = Music_Service_Process::instance()->upload($aVals, isset($aVals['album_id']) ? (int) $aVals['album_id'] : 0)) { if (isset($aVals['inline'])) { $aSong = Phpfox::getService('music')->getSong($aSong['song_id']); $this->template()->assign(array('aSong' => $aSong)); $this->template()->getTemplate('music.block.track-entry'); $sOutput = Phpfox_Ajax::instance()->getContent(false); Phpfox::addMessage(Phpfox::getPhrase('music.song_successfully_uploaded')); echo 'window.location.href = "' . $this->url()->makeUrl('music.album.track', array('id' => $aVals['album_id'])) . '";'; exit; } echo 'window.location.href = "' . $this->url()->permalink('music', $aSong['song_id'], $aSong['title']) . '";'; exit; } else { echo '$(\'#js_music_upload_song\').show(); $(\'.js_upload_song\').remove();'; echo 'alert(\'' . implode('\\n', Phpfox_Error::get()) . '\');'; exit; } } } if ($sMethod == 'massuploader') { $iMaxFileSize = Phpfox::getUserParam('music.music_max_file_size') === 0 ? null : Phpfox::getUserParam('music.music_max_file_size'); $this->template()->setHeader('cache', array('massuploader/swfupload.js' => 'static_script', 'massuploader/upload.js' => 'static_script', '<script type="text/javascript"> $oSWF_settings = { object_holder: function() { return \'swf_music_upload_button_holder\'; }, div_holder: function() { return \'swf_music_upload_button\'; }, get_settings: function() { swfu.setUploadURL("' . $this->url()->makeUrl('music.upload') . '"); swfu.setFileSizeLimit("' . $iMaxFileSize . ' MB"); swfu.setFileUploadLimit(1); swfu.setFileQueueLimit(1); swfu.customSettings.flash_user_id = ' . Phpfox::getUserId() . '; swfu.customSettings.sHash = "' . Phpfox::getService('core')->getHashForUpload() . '"; swfu.setFileTypes("*.mp3","*.mp3"); swfu.atFileQueue = function() { $(\'#js_music_form :input\').each(function(iKey, oObject) { swfu.addPostParam($(oObject).attr(\'name\'), $(oObject).val()); }); } } } </script>', 'upload.css' => 'module_music'))->setPhrase(array('core.name', 'core.status', 'core.in_queue', 'core.upload_failed_your_file_size_is_larger_then_our_limit_file_size', 'core.more_queued_than_allowed')); } $this->template()->setTitle($bIsEdit ? Phpfox::getPhrase('music.editing_song') . ': ' . $aEditSong['title'] : Phpfox::getPhrase('music.upload_a_song'))->setBreadcrumb(Phpfox::getPhrase('music.music'), $aCallback === false ? $this->url()->makeUrl('music') : $aCallback['url_home_photo'])->setBreadcrumb($bIsEdit ? Phpfox::getPhrase('music.editing_song') . ': ' . $aEditSong['title'] : Phpfox::getPhrase('music.upload_a_song'), $bIsEdit ? $this->url()->makeUrl('music.upload', array('id' => $iId)) : $this->url()->makeUrl('music.upload'), true)->setFullSite()->setPhrase(array('music.select_an_mp3'))->setHeader('cache', array('upload.js' => 'module_music', 'progress.css' => 'style_css', 'progress.js' => 'static_script', '<script type="text/javascript">$Behavior.musicUpload = function(){ if ($Core.exists(\'#js_music_form_holder\')) { oProgressBar = {holder: \'#js_music_form_holder\', progress_id: \'#js_progress_bar\', total: 1, max_upload: 1, uploader: \'#js_progress_uploader\', frame_id: \'js_upload_frame\', file_id: \'mp3\'}; $Core.progressBarInit(); }}</script>'))->assign(array('sModule' => $sModule, 'iItem' => $iItem, 'bIsEdit' => $bIsEdit, 'aUploadAlbums' => Phpfox::getService('music.album')->getForUpload($aCallback), 'sCreateJs' => $oValidator->createJS(), 'sGetJsForm' => $oValidator->getJsForm(false), 'iUploadLimit' => Phpfox_File::instance()->getLimit(Phpfox::getUserParam('music.music_max_file_size')), 'aGenres' => Phpfox::getService('music.genre')->getList(), 'sMethod' => $sMethod, 'sMethodUrl' => $sMethodUrl)); }
public function add($aVals, $iUserId = null, $sUserName = null) { $iUserId = $iUserId === null ? Phpfox::getUserId() : (int) $iUserId; $sUserName = $sUserName === null ? Phpfox::getUserBy('full_name') : $sUserName; // http://www.phpfox.com/tracker/view/15205/ // check if user can comment on this item if (Phpfox::isModule('feed') && isset($aVals['is_via_feed']) && !empty($aVals['is_via_feed'])) { $aFeed = $this->database()->select('privacy, privacy_comment, user_id')->from(Phpfox::getT('feed'))->where('item_id = ' . (int) $aVals['item_id'] . ' AND type_id = "' . Phpfox::getLib('parse.input')->clean($aVals['type']) . '"')->execute('getSlaveRow'); if (!empty($aFeed) && !Phpfox::getUserParam('privacy.can_comment_on_all_items')) { if (isset($aFeed['privacy_comment']) && !empty($aFeed['privacy']) && !empty($aFeed['user_id']) && $aFeed['user_id'] != $iUserId) { if ($aFeed['privacy_comment'] == 1 && Friend_Service_Friend::instance()->isFriend($iUserId, $aFeed['user_id']) != true) { return Phpfox_Error::display(Phpfox::getPhrase('feed.unable_to_post_a_comment_on_this_item_due_to_privacy_settings')); } else { if ($aFeed['privacy_comment'] == 2 && Friend_Service_Friend::instance()->isFriendOfFriend($iUserId) != true) { return Phpfox_Error::display(Phpfox::getPhrase('feed.unable_to_post_a_comment_on_this_item_due_to_privacy_settings')); } else { if ($aFeed['privacy_comment'] == 3 && $aFeed['user_id'] != Phpfox::getUserId()) { return Phpfox_Error::display(Phpfox::getPhrase('feed.unable_to_post_a_comment_on_this_item_due_to_privacy_settings')); } else { if ($aFeed['privacy_comment'] == 4 && ($bCheck = Privacy_Service_Privacy::instance()->check($aVals['type'], $aVals['item_id'], $aFeed['user_id'], $aFeed['privacy_comment'], null, true)) != true) { return Phpfox_Error::display(Phpfox::getPhrase('feed.unable_to_post_a_comment_on_this_item_due_to_privacy_settings')); } } } } } // Fallback: if the item is private and it cannot be accessed by the one trying to comment, then, the user should not be able to. if (isset($aFeed['privacy']) && !empty($aFeed['privacy']) && !empty($aFeed['user_id']) && $aFeed['user_id'] != $iUserId) { if ($aFeed['privacy'] == 1 && Friend_Service_Friend::instance()->isFriend($iUserId, $aFeed['user_id']) != true) { return Phpfox_Error::display(Phpfox::getPhrase('feed.unable_to_post_a_comment_on_this_item_due_to_privacy_settings')); } else { if ($aFeed['privacy'] == 2 && Friend_Service_Friend::instance()->isFriendOfFriend($iUserId) != true) { return Phpfox_Error::display(Phpfox::getPhrase('feed.unable_to_post_a_comment_on_this_item_due_to_privacy_settings')); } else { if ($aFeed['privacy'] == 3 && $aFeed['user_id'] != Phpfox::getUserId()) { return Phpfox_Error::display(Phpfox::getPhrase('feed.unable_to_post_a_comment_on_this_item_due_to_privacy_settings')); } else { if ($aFeed['privacy'] == 4 && ($bCheck = Privacy_Service_Privacy::instance()->check($aVals['type'], $aVals['item_id'], $aFeed['user_id'], $aFeed['privacy'], null, true)) != true) { return Phpfox_Error::display(Phpfox::getPhrase('feed.unable_to_post_a_comment_on_this_item_due_to_privacy_settings')); } } } } } } } // END if (isset($aVals['parent_group_id']) && isset($aVals['group_view_id']) && $aVals['group_view_id'] > 0) { define('PHPFOX_SKIP_FEED', true); } if (Phpfox::getParam('comment.comment_hash_check')) { if (Phpfox::getLib('spam.hash', array('table' => 'comment_hash', 'total' => Phpfox::getParam('comment.comments_to_check'), 'time' => Phpfox::getParam('comment.total_minutes_to_wait_for_comments'), 'content' => $aVals['text']))->isSpam()) { return false; } } if ($aVals['type'] != 'app') { $aItem = Phpfox::callback($aVals['type'] . '.getCommentItem', $aVals['item_id']); if (!isset($aItem['comment_item_id'])) { return false; } } else { $feed = $this->database()->select('*')->from(':feed')->where(['feed_id' => $aVals['item_id']])->get(); $aItem['comment_user_id'] = $feed['user_id']; $aItem['comment_view_id'] = 0; } $bIsBlocked = Phpfox::getService('user.block')->isBlocked($aItem['comment_user_id'], Phpfox::getUserId()); if ($bIsBlocked) { Phpfox_Error::set('Unable to leave a comment at this time.'); return false; } $aVals = array_merge($aItem, $aVals); $bCheck = Phpfox::getService('ban')->checkAutomaticBan($aVals['text']); if ($bCheck == false) { return false; } $aInsert = array('parent_id' => $aVals['parent_id'], 'type_id' => $aVals['type'], 'item_id' => $aVals['item_id'], 'user_id' => $iUserId, 'owner_user_id' => $aItem['comment_user_id'], 'time_stamp' => PHPFOX_TIME, 'ip_address' => Phpfox_Request::instance()->getServer('REMOTE_ADDR'), 'view_id' => $aItem['comment_view_id'] == 2 && $aItem['comment_user_id'] != $iUserId ? '1' : '0', 'author' => !empty($aVals['is_via_feed']) ? (int) $aVals['is_via_feed'] : ''); if (!$iUserId) { $aInsert['author'] = substr($aVals['author'], 0, 255); $aInsert['author_email'] = $aVals['author_email']; if (!empty($aVals['author_url']) && Phpfox_Validator::instance()->verify('url', $aVals['author_url'])) { $aInsert['author_url'] = $aVals['author_url']; } } $bIsSpam = false; if (Phpfox::getParam('comment.spam_check_comments')) { if (Phpfox::getLib('spam')->check(array('action' => 'isSpam', 'params' => array('module' => 'comment', 'content' => Phpfox::getLib('parse.input')->prepare($aVals['text']))))) { $aInsert['view_id'] = '9'; $bIsSpam = true; Phpfox_Error::set(Phpfox::getPhrase('comment.your_comment_has_been_marked_as_spam_it_will_have_to_be_approved_by_an_admin')); } } if (Phpfox::getUserParam('comment.approve_all_comments')) { $aInsert['view_id'] = '1'; $bIsSpam = true; Phpfox_Ajax::instance()->sPopupMessage = Phpfox::getPhrase('core.notice'); Phpfox_Error::set(Phpfox::getPhrase('comment.your_comment_has_successfully_been_added_however_it_is_pending_an_admins_approval')); } ($sPlugin = Phpfox_Plugin::get('comment.service_process_add')) ? eval($sPlugin) : false; $iId = $this->database()->insert($this->_sTable, $aInsert); Phpfox::getLib('parse.bbcode')->useVideoImage($aVals['type'] == 'feed' ? true : false); $aVals['text_parsed'] = Phpfox::getLib('parse.input')->prepare($aVals['text'], false, ['comment' => $iId]); $this->database()->insert(Phpfox::getT('comment_text'), array('comment_id' => $iId, 'text' => Phpfox::getLib('parse.input')->clean($aVals['text']), 'text_parsed' => $aVals['text_parsed'])); // http://www.phpfox.com/tracker/view/14660/ $sComment = Phpfox::getLib('parse.input')->clean($aVals['text']); if (Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_hashtag_support')) { Phpfox::getService('tag.process')->add($aInsert['type_id'], $aInsert['item_id'], Phpfox::getUserId(), $sComment, true); } $aVals['comment_id'] = $iId; if (!empty($aVals['parent_id'])) { $this->database()->updateCounter('comment', 'child_total', 'comment_id', (int) $aVals['parent_id']); } if ($bIsSpam === true) { return false; } Phpfox::getService('user.process')->notifyTagged($aVals['text'], $iId, $aVals['type']); // Callback this action to other modules Phpfox::callback($aVals['type'] . '.addComment', $aVals, $iUserId, $sUserName); if ($aItem['comment_view_id'] == 2 && $aItem['comment_user_id'] != $iUserId) { Phpfox::isModule('request') ? Phpfox::getService('request.process')->add('comment_pending', $iId, $aItem['comment_user_id']) : false; return 'pending_moderation'; } // Update user activity Phpfox::getService('user.activity')->update(Phpfox::getUserId(), 'comment'); $sFeedPrefix = ''; $sNewTypeId = $aVals['type']; if (!empty($aItem['parent_module_id']) && ($aItem['parent_module_id'] == 'pages' || $aItem['parent_module_id'] == 'event')) { $sFeedPrefix = $aItem['parent_module_id'] . '_'; if ($sNewTypeId == 'pages') { $sNewTypeId = 'pages_comment'; } if ($sNewTypeId == 'event') { $sNewTypeId = 'event_comment'; } } /* p($sFeedPrefix); p('type_id = \'' . $this->database()->escape($aVals['type']) . '\' AND item_id = ' . (int) $aVals['item_id']); exit; */ Phpfox::getService('feed.process')->clearCache($aVals['type'], $aVals['item_id']); $this->database()->update(Phpfox::getT($sFeedPrefix . 'feed'), array('time_update' => PHPFOX_TIME), 'type_id = \'' . $this->database()->escape($sNewTypeId) . '\' AND item_id = ' . (int) $aVals['item_id']); ($sPlugin = Phpfox_Plugin::get('comment.service_process_add_end')) ? eval($sPlugin) : false; return $iId; }
/** * Controller */ public function process() { $aFeed = $this->getParam('aFeed'); $aFeed['feed_id'] = $aFeed['item_id']; $aFeed['is_view_item'] = true; $sFeedType = isset($aFeed['feed_display']) ? $aFeed['feed_display'] : null; $bForceLoad = false; if (PHPFOX_IS_AJAX && Phpfox_Module::instance()->getFullControllerName() == 'photo.view') { // $bForceLoad = true; } if ((!PHPFOX_IS_AJAX || $bForceLoad) && $sFeedType == 'view' && Phpfox::isModule('comment') && Phpfox::getParam('comment.load_delayed_comments_items')) { // Prepare the param $sDelayedParam = urlencode(json_encode(array('item_id' => $aFeed['item_id'], 'total_like' => $aFeed['total_like'], 'like_type_id' => $aFeed['like_type_id'], 'total_comment' => $aFeed['total_comment'], 'comment_type_id' => $aFeed['comment_type_id'], 'privacy' => $aFeed['privacy'], 'feed_link' => $aFeed['feed_link'], 'feed_title' => $aFeed['feed_title'], 'feed_display' => $aFeed['feed_display']))); $this->template()->assign(array('sDelayedParam' => $sDelayedParam, 'sDelayedParamId' => rand(100, 999))); return 'block'; } else { if (defined('PHPFOX_IS_AJAX') && PHPFOX_IS_AJAX && Phpfox_Ajax::instance()->get('delayedParam') != null) { $aFeed = json_decode(urldecode(Phpfox_Ajax::instance()->get('delayedParam'))); } } if (Phpfox::isModule('comment') && Phpfox::getUserParam('comment.can_delete_comment_on_own_item') && ($iOwnerDeleteCmt = $this->request()->getInt('ownerdeletecmt')) && isset($aFeed['user_id']) && $aFeed['user_id'] == Phpfox::getUserId()) { if (Phpfox::getService('comment.process')->deleteInline($iOwnerDeleteCmt, $aFeed['comment_type_id'], true)) { $this->url()->forward($aFeed['feed_link'], Phpfox::getPhrase('comment.comment_successfully_deleted')); } } $bCanPostComment = true; if (isset($aFeed['comment_privacy']) && $aFeed['user_id'] != Phpfox::getUserId() && (Phpfox::isModule('privacy') && !Phpfox::getUserParam('privacy.can_comment_on_all_items'))) { switch ($aFeed['comment_privacy']) { case 1: if ((int) $aFeed['feed_is_friend'] <= 0) { $bCanPostComment = false; } break; case 2: if ((int) $aFeed['feed_is_friend'] > 0) { $bCanPostComment = true; } else { if (!Friend_Service_Friend::instance()->isFriendOfFriend($aFeed['user_id'])) { $bCanPostComment = false; } } break; case 3: $bCanPostComment = false; break; } } $aFeed['can_post_comment'] = $bCanPostComment; if (isset($aFeed['total_like']) && (int) $aFeed['total_like'] > 0 && Phpfox::isModule('like')) { $aFeed['likes'] = Phpfox::getService('like')->getLikesForFeed($aFeed['like_type_id'], $aFeed['item_id'], (int) $aFeed['feed_is_liked'] > 0 ? true : false, Phpfox::getParam('feed.total_likes_to_display')); } $bHasBeenMarked = Phpfox::isModule('like') ? Phpfox::getService('like')->hasBeenMarked(2, isset($aFeed['type_id']) ? $aFeed['type_id'] : $aFeed['like_type_id'], $aFeed['item_id']) : false; /* Quick check without the actions*/ $aFeed['bShowEnterCommentBlock'] = false; if (Phpfox::isModule('like') && (isset($aFeed['total_like']) && $aFeed['total_like'] > 0 && Phpfox::getParam('like.show_user_photos') == false || isset($aFeed['total_comment']) && $aFeed['total_comment'] > 0 || Phpfox::getParam('like.allow_dislike') && Phpfox::isModule('like') && $bHasBeenMarked)) { $aFeed['bShowEnterCommentBlock'] = true; } $iPageLimit = 2; $mPager = null; $iCommentId = null; $bIsViewingComments = false; if (Phpfox::isModule('comment') && $sFeedType != 'mini') { if ((int) $aFeed['total_comment'] > 0) { if ($sFeedType == 'view') { $iPageLimit = Phpfox::getParam('comment.comment_page_limit'); if ($this->request()->get('stream-mode')) { $iPageLimit = $iPageLimit + 1; if (!defined('PHPFOX_FEED_STREAM_MODE')) { define('PHPFOX_FEED_STREAM_MODE', true); } } $mPager = $aFeed['total_comment']; } if ($this->request()->getInt('comment')) { $iCommentId = $this->request()->getInt('comment'); $bIsViewingComments = true; } $aFeed['comments'] = Comment_Service_Comment::instance()->getCommentsForFeed($aFeed['comment_type_id'], $aFeed['item_id'], $iPageLimit, $mPager, $iCommentId); } } if ($sFeedType == 'view') { Phpfox_Pager::instance()->set(array('ajax' => 'comment.viewMoreFeed', 'page' => Phpfox_Request::instance()->getInt('page'), 'size' => $iPageLimit, 'count' => $mPager, 'phrase' => Phpfox::isModule('comment') ? Phpfox::getPhrase('comment.view_previous_comments') : '', 'icon' => 'misc/comment.png', 'aParams' => array('comment_type_id' => $aFeed['comment_type_id'], 'item_id' => $aFeed['item_id'], 'append' => true, 'pagelimit' => $iPageLimit, 'total' => $mPager))); } $aFeed['type_id'] = !empty($aFeed['type_id']) ? $aFeed['type_id'] : (isset($aFeed['report_module']) ? $aFeed['report_module'] : ''); if ($aFeed['type_id'] == 'forum_reply') { $aFeed['type_id'] = 'forum_post'; } if (!isset($aFeed['feed_like_phrase']) && Phpfox::isModule('like')) { Feed_Service_Feed::instance()->getPhraseForLikes($aFeed); } $this->template()->assign(array('aFeed' => $aFeed, 'sFeedType' => $sFeedType, 'bIsViewingComments' => $bIsViewingComments, 'feedJson' => json_encode($aFeed))); }