예제 #1
0
	public function check( )
	{

		if ( $this->get( 'title' ) == '' ) {
			$this->setError( CBTxt::T( 'Title not specified!' ) );

			return false;
		} elseif ( ! $this->get( 'created_by' ) ) {
			$this->setError( CBTxt::T( 'User not specified!' ) );

			return false;
		} elseif ( $this->get( 'created_by' ) && ( ! CBuser::getUserDataInstance( (int) $this->get( 'created_by' ) )->id ) ) {
			$this->setError( CBTxt::T( 'User specified does not exist!' ) );

			return false;
		} elseif ( $this->get( 'access' ) === '' ) {
			$this->setError( CBTxt::T( 'Access not specified!' ) );

			return false;
		} elseif ( ! $this->get( 'catid' ) ) {
			$this->setError( CBTxt::T( 'Category not specified!' ) );

			return false;
		} elseif ( ! in_array( $this->get( 'catid' ), cbblogsModel::getCategoriesList( true ) ) ) {
			$this->setError( CBTxt::T( 'Category not allowed!' ) );

			return false;
		}

		return true;
	}
예제 #2
0
 /**
  * Renders the Blogs tab
  *
  * @param  OrderedTable[]  $rows       Blogs to render
  * @param  cbPageNav       $pageNav    Pagination
  * @param  boolean         $searching  Currently searching
  * @param  string[]        $input      HTML of input elements
  * @param  UserTable       $viewer     Viewing user
  * @param  UserTable       $user       Viewed user
  * @param  stdClass        $model      The model reference
  * @param  TabTable        $tab        Current Tab
  * @param  PluginTable     $plugin     Current Plugin
  * @return string                      HTML
  */
 static function showBlogTab($rows, $pageNav, $searching, $input, $viewer, $user, $model, $tab, $plugin)
 {
     global $_CB_framework;
     $blogLimit = (int) $plugin->params->get('blog_limit', null);
     $tabPaging = $tab->params->get('tab_paging', 1);
     $canSearch = $tab->params->get('tab_search', 1) && ($searching || $pageNav->total);
     $canCreate = false;
     $profileOwner = $viewer->get('id') == $user->get('id');
     $cbModerator = Application::User((int) $viewer->get('id'))->isGlobalModerator();
     $canPublish = $cbModerator || $profileOwner && !$plugin->params->get('blog_approval', 0);
     if ($profileOwner) {
         if ($cbModerator) {
             $canCreate = true;
         } elseif ($user->get('id') && Application::User((int) $viewer->get('id'))->canViewAccessLevel((int) $plugin->params->get('blog_create_access', 2))) {
             if (!$blogLimit || $blogLimit && $pageNav->total < $blogLimit) {
                 $canCreate = true;
             }
         }
     }
     $return = '<div class="blogsTab">' . '<form action="' . $_CB_framework->userProfileUrl($user->get('id'), true, $tab->tabid) . '" method="post" name="blogForm" id="blogForm" class="blogForm">';
     if ($canCreate || $canSearch) {
         $return .= '<div class="blogsHeader row" style="margin-bottom: 10px;">';
         if ($canCreate) {
             $return .= '<div class="' . (!$canSearch ? 'col-sm-12' : 'col-sm-8') . ' text-left">' . '<button type="button" onclick="location.href=\'' . $_CB_framework->pluginClassUrl($plugin->element, false, array('action' => 'blogs', 'func' => 'new')) . '\';" class="blogsButton blogsButtonNew btn btn-success"><span class="fa fa-plus-circle"></span> ' . CBTxt::T('New Blog') . '</button>' . '</div>';
         }
         if ($canSearch) {
             $return .= '<div class="' . (!$canCreate ? 'col-sm-offset-8 ' : null) . 'col-sm-4 text-right">' . '<div class="input-group">' . '<span class="input-group-addon"><span class="fa fa-search"></span></span>' . $input['search'] . '</div>' . '</div>';
         }
         $return .= '</div>';
     }
     $menuAccess = $cbModerator || $profileOwner || $canPublish;
     $return .= '<table class="blogsContainer table table-hover table-responsive">' . '<thead>' . '<tr>' . '<th style="width: 50%;" class="text-left">' . CBTxt::T('Title') . '</th>' . '<th style="width: 25%;" class="text-left hidden-xs">' . CBTxt::T('Category') . '</th>' . '<th style="width: 24%;" class="text-left hidden-xs">' . CBTxt::T('Created') . '</th>' . ($menuAccess ? '<th style="width: 1%;" class="text-right">&nbsp;</th>' : null) . '</tr>' . '</thead>' . '<tbody>';
     if ($rows) {
         foreach ($rows as $row) {
             $return .= '<tr>' . '<td style="width: 50%;" class="text-left">' . ($row->get('published') ? '<a href="' . cbblogsModel::getUrl($row, true, 'article') . '">' . $row->get('title') . '</a>' : $row->get('title')) . '</td>' . '<td style="width: 25%;" class="text-left hidden-xs">' . ($row->get('category_published') ? '<a href="' . cbblogsModel::getUrl($row, true, 'category') . '">' . $row->get('category') . '</a>' : $row->get('category')) . '</td>' . '<td style="width: 24%;" class="text-left hidden-xs">' . cbFormatDate($row->get('created')) . '</td>';
             if ($menuAccess) {
                 $menuItems = '<ul class="blogsMenuItems dropdown-menu" style="display: block; position: relative; margin: 0;">';
                 if ($cbModerator || $profileOwner) {
                     $menuItems .= '<li class="blogsMenuItem"><a href="' . $_CB_framework->pluginClassUrl($plugin->element, true, array('action' => 'blogs', 'func' => 'edit', 'id' => (int) $row->get('id'))) . '"><span class="fa fa-edit"></span> ' . CBTxt::T('Edit') . '</a></li>';
                 }
                 if ($canPublish) {
                     if ($row->get('published')) {
                         $menuItems .= '<li class="blogsMenuItem"><a href="javascript: void(0);" onclick="if ( confirm( \'' . addslashes(CBTxt::T('Are you sure you want to unpublish this Blog?')) . '\' ) ) { location.href = \'' . $_CB_framework->pluginClassUrl($plugin->element, false, array('action' => 'blogs', 'func' => 'unpublish', 'id' => (int) $row->get('id'))) . '\'; }"><span class="fa fa-times-circle"></span> ' . CBTxt::T('Unpublish') . '</a></li>';
                     } else {
                         $menuItems .= '<li class="blogsMenuItem"><a href="' . $_CB_framework->pluginClassUrl($plugin->element, true, array('action' => 'blogs', 'func' => 'publish', 'id' => (int) $row->get('id'))) . '"><span class="fa fa-check"></span> ' . CBTxt::T('Publish') . '</a></li>';
                     }
                 }
                 if ($cbModerator || $profileOwner) {
                     $menuItems .= '<li class="blogsMenuItem"><a href="javascript: void(0);" onclick="if ( confirm( \'' . addslashes(CBTxt::T('Are you sure you want to delete this Blog?')) . '\' ) ) { location.href = \'' . $_CB_framework->pluginClassUrl($plugin->element, false, array('action' => 'blogs', 'func' => 'delete', 'id' => (int) $row->get('id'))) . '\'; }"><span class="fa fa-trash-o"></span> ' . CBTxt::T('Delete') . '</a></li>';
                 }
                 $menuItems .= '</ul>';
                 $menuAttr = cbTooltip(1, $menuItems, null, 'auto', null, null, null, 'class="btn btn-default btn-xs" data-cbtooltip-menu="true" data-cbtooltip-classes="qtip-nostyle"');
                 $return .= '<td style="width: 1%;" class="text-right">' . '<div class="blogsMenu btn-group">' . '<button type="button"' . $menuAttr . '><span class="fa fa-cog"></span> <span class="fa fa-caret-down"></span></button>' . '</div>' . '</td>';
             }
             $return .= '</tr>';
         }
     } else {
         $return .= '<tr>' . '<td colspan="' . ($menuAccess ? 4 : 3) . '" class="text-left">';
         if ($searching) {
             $return .= CBTxt::T('No blog search results found.');
         } else {
             if ($viewer->id == $user->id) {
                 $return .= CBTxt::T('You have no blogs.');
             } else {
                 $return .= CBTxt::T('This user has no blogs.');
             }
         }
         $return .= '</td>' . '</tr>';
     }
     $return .= '</tbody>';
     if ($tabPaging && $pageNav->total > $pageNav->limit) {
         $return .= '<tfoot>' . '<tr>' . '<td colspan="' . ($menuAccess ? 4 : 3) . '" class="text-center">' . $pageNav->getListLinks() . '</td>' . '</tr>' . '</tfoot>';
     }
     $return .= '</table>' . $pageNav->getLimitBox(false) . '</form>' . '</div>';
     return $return;
 }
예제 #3
0
	/**
	 * @param  int[]             $paging
	 * @param  string            $where
	 * @param  UserTable         $viewer
	 * @param  UserTable         $user
	 * @param  PluginTable       $plugin
	 * @return cbblogsBlogTable[]
	 */
	static public function getBlogs( $paging, $where, $viewer, $user, /** @noinspection PhpUnusedParameterInspection */ $plugin )
	{
		global $_CB_database;

		$categories		=	cbblogsModel::getCategoriesList( true );

		$blogs			=	array();

		if ( $categories ) {
			$query		=	'SELECT a.*'
						.	', a.' . $_CB_database->NameQuote( 'created_by' ) . ' AS user'
						.	', a.' . $_CB_database->NameQuote( 'introtext' ) . ' AS blog_intro'
						.	', a.' . $_CB_database->NameQuote( 'fulltext' ) . ' AS blog_full'
						.	', b.' . $_CB_database->NameQuote( 'name' ) . ' AS category'
						.	', b.' . $_CB_database->NameQuote( 'published' ) . ' AS category_published'
						.	', b.' . $_CB_database->NameQuote( 'alias' ) . ' AS category_alias'
						.	"\n FROM " . $_CB_database->NameQuote( '#__k2_items' ) . " AS a"
						.	"\n LEFT JOIN " . $_CB_database->NameQuote( '#__k2_categories' ) . " AS b"
						.	' ON b.' . $_CB_database->NameQuote( 'id' ) . ' = a.' . $_CB_database->NameQuote( 'catid' )
						.	"\n LEFT JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS c"
						.	' ON c.' . $_CB_database->NameQuote( 'id' ) . ' = a.' . $_CB_database->NameQuote( 'created_by' )
						.	"\n WHERE a." . $_CB_database->NameQuote( 'catid' ) . " IN ( " . implode( ',', $categories ) . " )"
						.	"\n AND a." . $_CB_database->NameQuote( 'created_by' ) . " = " . (int) $user->get( 'id' )
						.	( ( $viewer->get( 'id' ) != $user->get( 'id' ) ) && ( ! Application::User( (int) $viewer->get( 'id' ) )->isGlobalModerator() ) ? "\n AND a." . $_CB_database->NameQuote( 'published' ) . " = 1" : null )
						.	( ! Application::Cms()->getClientId() ? "\n AND a." . $_CB_database->NameQuote( 'trash' ) . " = 0" : null )
						.	"\n AND a." . $_CB_database->NameQuote( 'access' ) . " IN " . $_CB_database->safeArrayOfIntegers( Application::MyUser()->getAuthorisedViewLevels() )
						.	$where
						.	"\n ORDER BY a." . $_CB_database->NameQuote( 'created' ) . " DESC";

			if ( $paging ) {
				$_CB_database->setQuery( $query, $paging[0], $paging[1] );
			} else {
				$_CB_database->setQuery( $query );
			}

			$blogs		=	$_CB_database->loadObjectList( null, 'cbblogsBlogTable', array( $_CB_database ) );
		}

		return $blogs;
	}
예제 #4
0
	/**
	 * @return array
	 */
	public function categories()
	{
		$options		=	array();

		if ( $this->installed() ) {
			$options	=	cbblogsModel::getCategoriesList();
		}

		return $options;
	}
예제 #5
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' );
		}
	}
예제 #6
0
 /**
  * @param  UserTable  $user
  * @param  int        $status
  */
 public function deleteBlogs($user, $status)
 {
     $plugin = cbblogsClass::getPlugin();
     if ($plugin->params->get('blog_delete', 1)) {
         cbblogsClass::getModel();
         $blogs = cbblogsModel::getBlogs(null, null, $user, $user, $plugin);
         if ($blogs) {
             foreach ($blogs as $blog) {
                 $blog->delete();
             }
         }
     }
 }
예제 #7
0
	/**
	 * @param  UserTable  $user
	 * @param  int        $status
	 */
	public function deleteBlogs( $user, /** @noinspection PhpUnusedParameterInspection */ $status )
	{
		$plugin			=	cbblogsClass::getPlugin();

		if ( $plugin->params->get( 'blog_delete', 1 ) ) {
			cbblogsClass::getModel();

			$blogs		=	cbblogsModel::getBlogs( null, null, $user, $user, $plugin );

			if ( $blogs ) foreach ( $blogs as $blog ) {
				$blog->delete();
			}
		}
	}