コード例 #1
0
	/**
	 * @param  null|int     $id
	 * @param  UserTable    $user
	 * @param  stdClass     $model
	 * @param  PluginTable  $plugin
	 */
	private function saveBlogEdit( $id, $user, $model, $plugin )
	{
		global $_CB_framework, $_PLUGINS;

		$blogLimit					=	(int) $plugin->params->get( 'blog_limit', null );
		$cbModerator				=	Application::User( (int) $user->get( 'id' ) )->isGlobalModerator();

		$row						=	new cbblogsBlogTable();

		$canAccess					=	false;

		if ( $row->load( (int) $id ) ) {
			if ( ! $row->get( 'id' ) ) {
				if ( $cbModerator ) {
					$canAccess		=	true;
				} elseif ( $user->get( 'id' ) && Application::MyUser()->canViewAccessLevel( $plugin->params->get( 'blog_create_access', 2 ) ) ) {
					if ( ( ! $blogLimit ) || ( $blogLimit && ( cbblogsModel::getBlogsTotal( null, $user, $user, $plugin ) < $blogLimit ) ) ) {
						$canAccess	=	true;
					}
				}
			} elseif ( $cbModerator || ( $row->get( 'user' ) == $user->get( 'id' ) ) ) {
				$canAccess			=	true;
			}
		}

		$profileUrl					=	$_CB_framework->userProfileUrl( $row->get( 'user', $user->get( 'id' ) ), false, 'cbblogsTab' );

		if ( $canAccess ) {
			if ( $plugin->params->get( 'blog_captcha', 0 ) && ( ! $row->get( 'id' ) ) && ( ! $cbModerator ) ) {
				$_PLUGINS->loadPluginGroup( 'user' );

				$_PLUGINS->trigger( 'onCheckCaptchaHtmlElements', array() );

				if ( $_PLUGINS->is_errors() ) {
					$row->setError( CBTxt::T( $_PLUGINS->getErrorMSG() ) );
				}
			}

			$new					=	( $row->get( 'id' ) ? false : true );

			if ( ! $row->bind( $_POST ) ) {
				$this->showBlogEdit( $id, $user, $model, $plugin, CBTxt::T( 'BLOG_FAILED_TO_BIND_ERROR_ERROR', 'Blog failed to bind! Error: [error]', array( '[error]' => $row->getError() ) ) ); return;
			}

			if ( ! $row->check() ) {
				$this->showBlogEdit( $id, $user, $model, $plugin, CBTxt::T( 'BLOG_FAILED_TO_VALIDATE_ERROR_ERROR', 'Blog failed to validate! Error: [error]', array( '[error]' => $row->getError() ) ) ); return;
			}

			if ( $row->getError() || ( ! $row->store() ) ) {
				$this->showBlogEdit( $id, $user, $model, $plugin, CBTxt::T( 'BLOG_FAILED_TO_SAVE_ERROR_ERROR', 'Blog failed to save! Error: [error]', array( '[error]' => $row->getError() ) ) ); return;
			}

			if ( $new && ( ! $row->get( 'published' ) ) && $plugin->params->get( 'approval_notify', 1 ) && ( ! $cbModerator ) ) {
				$cbUser				=	CBuser::getInstance( (int) $row->get( 'user' ), false );

				$extraStrings		=	array(	'site_name' => $_CB_framework->getCfg( 'sitename' ),
												'site' => '<a href="' . $_CB_framework->getCfg( 'live_site' ) . '">' . $_CB_framework->getCfg( 'sitename' ) . '</a>',
												'blog_id' => (int) $row->get( 'id' ),
												'blog_title' => $row->get( 'title' ),
												'blog_intro' => $row->get( 'blog_intro' ),
												'blog_full' => $row->get( 'blog_full' ),
												'blog_created' => $row->get( 'blog_created' ),
												'blog_user' => (int) $row->get( 'user' ),
												'blog_url' => cbblogsModel::getUrl( $row ),
												'blog_tab_url' => $_CB_framework->viewUrl( 'userprofile', false, array( 'user' => (int) $row->get( 'user_id' ), 'tab' => 'cbblogsTab' ) ),
												'user_name' => $cbUser->getField( 'formatname', null, 'html', 'none', 'profile' ),
												'user' => '<a href="' . $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ) ) ) . '">' . $cbUser->getField( 'formatname', null, 'html', 'none', 'profile' ) . '</a>'
											);

				$subject			=	$cbUser->replaceUserVars( CBTxt::T( 'Blogs - New Blog Created!' ), false, true, $extraStrings, false );
				$message			=	$cbUser->replaceUserVars( CBTxt::T( '[user] created [blog_title] and requires <a href="[blog_tab_url]">approval</a>!' ), false, true, $extraStrings, false );

				$notifications		=	new cbNotification();

				$notifications->sendToModerators( $subject, $message, false, 1 );
			}

			cbRedirect( $profileUrl, CBTxt::T( 'Blog saved successfully!' ) );
		} else {
			cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' );
		}
	}
コード例 #2
0
ファイル: cbblogs.php プロジェクト: bobozhangshao/HeartCare
 /**
  * Generates the HTML to display the user profile tab
  *
  * @param  \CB\Database\Table\TabTable   $tab       the tab database entry
  * @param  \CB\Database\Table\UserTable  $user      the user being displayed
  * @param  int                           $ui        1 for front-end, 2 for back-end
  * @return string|boolean                           Either string HTML for tab content, or false if ErrorMSG generated
  */
 public function getDisplayTab($tab, $user, $ui)
 {
     global $_CB_framework, $_CB_database;
     outputCbJs(1);
     outputCbTemplate(1);
     cbimport('cb.pagination');
     $plugin = cbblogsClass::getPlugin();
     $model = cbblogsClass::getModel();
     $viewer = CBuser::getMyUserDataInstance();
     cbblogsClass::getTemplate('tab');
     $limit = (int) $this->params->get('tab_limit', 15);
     $limitstart = $_CB_framework->getUserStateFromRequest('tab_blogs_limitstart{com_comprofiler}', 'tab_blogs_limitstart');
     $filterSearch = $_CB_framework->getUserStateFromRequest('tab_blogs_search{com_comprofiler}', 'tab_blogs_search');
     $where = null;
     if (isset($filterSearch) && $filterSearch != '') {
         if ($model->type != 2) {
             $where .= "\n AND ( a." . $_CB_database->NameQuote('title') . " LIKE " . $_CB_database->Quote('%' . $_CB_database->getEscaped($filterSearch, true) . '%', false) . " OR a." . $_CB_database->NameQuote('introtext') . " LIKE " . $_CB_database->Quote('%' . $_CB_database->getEscaped($filterSearch, true) . '%', false) . " OR a." . $_CB_database->NameQuote('fulltext') . " LIKE " . $_CB_database->Quote('%' . $_CB_database->getEscaped($filterSearch, true) . '%', false) . " )";
         } else {
             $where .= "\n AND ( a." . $_CB_database->NameQuote('title') . " LIKE " . $_CB_database->Quote('%' . $_CB_database->getEscaped($filterSearch, true) . '%', false) . " OR a." . $_CB_database->NameQuote('blog_intro') . " LIKE " . $_CB_database->Quote('%' . $_CB_database->getEscaped($filterSearch, true) . '%', false) . " OR a." . $_CB_database->NameQuote('blog_full') . " LIKE " . $_CB_database->Quote('%' . $_CB_database->getEscaped($filterSearch, true) . '%', false) . " )";
         }
     }
     $searching = $where ? true : false;
     $total = cbblogsModel::getBlogsTotal($where, $viewer, $user, $plugin);
     if ($total <= $limitstart) {
         $limitstart = 0;
     }
     $pageNav = new cbPageNav($total, $limitstart, $limit);
     $pageNav->setInputNamePrefix('tab_blogs_');
     $rows = cbblogsModel::getBlogs($this->params->get('tab_paging', 1) ? array($pageNav->limitstart, $pageNav->limit) : null, $where, $viewer, $user, $plugin);
     $input = array();
     $input['search'] = '<input type="text" name="tab_blogs_search" value="' . htmlspecialchars($filterSearch) . '" onchange="document.blogForm.submit();" placeholder="' . htmlspecialchars(CBTxt::T('Search Blogs...')) . '" class="form-control" />';
     $tab->params = $this->params;
     $class = $plugin->params->get('general_class', null);
     $return = '<div id="cbBlogs" class="cbBlogs' . ($class ? ' ' . htmlspecialchars($class) : null) . '">' . '<div id="cbBlogsInner" class="cbBlogsInner">' . HTML_cbblogsTab::showBlogTab($rows, $pageNav, $searching, $input, $viewer, $user, $model, $tab, $plugin) . '</div>' . '</div>';
     return $return;
 }