Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -12,14 +12,14 @@
|
||||
namespace IPS\blog\modules\front\blogs;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* View Blog Entry Controller
|
||||
* View Blog Controller
|
||||
*/
|
||||
class _view extends \IPS\Helpers\CoverPhoto\Controller
|
||||
{
|
||||
@@ -61,11 +61,31 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$this->blog->clubCheckRules();
|
||||
|
||||
/* Build table */
|
||||
$where = array();
|
||||
if ( !in_array( $this->blog->id, array_keys( \IPS\blog\Blog::loadByOwner( \IPS\Member::loggedIn() ) ) ) AND !\IPS\blog\Entry::canViewHiddenItems( \IPS\Member::loggedIn(), $this->blog ) )
|
||||
if ( !\in_array( $this->blog->id, array_keys( \IPS\blog\Blog::loadByOwner( \IPS\Member::loggedIn() ) ) ) AND !\IPS\blog\Entry::canViewHiddenItems( \IPS\Member::loggedIn(), $this->blog ) )
|
||||
{
|
||||
$where[] = array( "entry_status!='draft'" );
|
||||
if ( !( $club = $this->blog->club() AND \in_array( $club->memberStatus( \IPS\Member::loggedIn() ), array( \IPS\Member\Club::STATUS_LEADER, \IPS\Member\Club::STATUS_MODERATOR ) ) ) )
|
||||
{
|
||||
$where[] = array( "entry_status!='draft'" );
|
||||
}
|
||||
}
|
||||
|
||||
/* Are we limiting by category? */
|
||||
try
|
||||
{
|
||||
$category = \IPS\blog\Entry\Category::load( \IPS\Request::i()->cat );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
$category = NULL;
|
||||
}
|
||||
|
||||
if( $category )
|
||||
{
|
||||
$where[] = array( "entry_category_id=?", $category->id );
|
||||
}
|
||||
|
||||
$table = new \IPS\Helpers\Table\Content( 'IPS\blog\Entry', $this->blog->url(), $where, $this->blog );
|
||||
@@ -95,14 +115,21 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
|
||||
);
|
||||
|
||||
/* Online User Location */
|
||||
\IPS\Session::i()->setLocation( $this->blog->url(), array(), 'loc_blog_viewing_blog', array( "blogs_blog_{$this->blog->id}" => TRUE ) );
|
||||
|
||||
/* Output */
|
||||
\IPS\Output::i()->title = $this->blog->_title;
|
||||
|
||||
if( !$this->blog->social_group )
|
||||
{
|
||||
\IPS\Session::i()->setLocation( $this->blog->url(), array(), 'loc_blog_viewing_blog', array( "blogs_blog_{$this->blog->id}" => TRUE ) );
|
||||
}
|
||||
|
||||
if( \IPS\Settings::i()->blog_allow_rss and $this->blog->settings['allowrss'] )
|
||||
{
|
||||
\IPS\Output::i()->rssFeeds['blog_rss_title'] = \IPS\Http\Url::internal( "app=blog&module=blogs&controller=view&id={$this->blog->_id}", 'front', 'blogs_rss', array( $this->blog->seo_name ) );
|
||||
|
||||
if ( \IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
$key = md5( ( \IPS\Member::loggedIn()->members_pass_hash ?: \IPS\Member::loggedIn()->email ) . \IPS\Member::loggedIn()->members_pass_salt );
|
||||
|
||||
\IPS\Output::i()->rssFeeds['blog_rss_title'] = \IPS\Output::i()->rssFeeds['blog_rss_title']->setQueryString( array( 'member' => \IPS\Member::loggedIn()->member_id , 'key' => $key ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Add JSON-ld */
|
||||
@@ -157,8 +184,26 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
|
||||
\IPS\Output::i()->sidebar['contextual'] = \IPS\Theme::i()->getTemplate('view')->blogSidebar( $this->blog->sidebar );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->breadcrumb = array();
|
||||
\IPS\Output::i()->breadcrumb['module'] = array( \IPS\Http\Url::internal( 'app=blog', 'front' ), \IPS\Member::loggedIn()->language()->addToStack( '__app_blog' ) );
|
||||
|
||||
try
|
||||
{
|
||||
foreach( $this->blog->category()->parents() as $parent )
|
||||
{
|
||||
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
|
||||
}
|
||||
\IPS\Output::i()->breadcrumb[] = array( $this->blog->category()->url(), $this->blog->category()->_title );
|
||||
}
|
||||
catch (\OutOfRangeException $e) {}
|
||||
|
||||
\IPS\Output::i()->breadcrumb[] = array( $this->blog->url(), $this->blog->_title );
|
||||
|
||||
/* Categories */
|
||||
$categories = \IPS\blog\Entry\Category::roots( NULL, NULL, array( 'entry_category_blog_id=?', $this->blog->id ) );
|
||||
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_browse.js', 'blog', 'front' ) );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'view' )->view( $this->blog, (string) $table );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'view' )->view( $this->blog, (string) $table, $category );
|
||||
\IPS\Output::i()->contextualSearchOptions[ \IPS\Member::loggedIn()->language()->addToStack( 'search_contextual_item_blogs' ) ] = array( 'type' => 'blog_entry', 'nodes' => $this->blog->_id );
|
||||
}
|
||||
|
||||
@@ -189,7 +234,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
|
||||
{
|
||||
$form->elements['']['blog_name']->error = \IPS\Member::loggedIn()->language()->addToStack('form_required');
|
||||
|
||||
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
|
||||
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -201,7 +246,8 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
|
||||
/* Display form */
|
||||
\IPS\Output::i()->title = $this->blog->_title;
|
||||
\IPS\Output::i()->breadcrumb[] = array( $this->blog->url(), $this->blog->_title );
|
||||
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_view.js', 'blog', 'front' ) );
|
||||
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,33 +305,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
|
||||
\IPS\Output::i()->redirect( $this->blog->url() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* RSS feed
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function rss()
|
||||
{
|
||||
if( !\IPS\Settings::i()->blog_allow_rss or !$this->blog->settings['allowrss'] )
|
||||
{
|
||||
\IPS\Output::i()->error( 'blog_rss_offline', '2B201/5', 403, 'blog_rss_offline_admin' );
|
||||
}
|
||||
|
||||
/* We have to use get() to ensure CDATA tags wrap the blog title properly */
|
||||
$title = $this->blog->member_id ? $this->blog->name : \IPS\Member::loggedIn()->language()->get( "blogs_blog_{$this->blog->id}" );
|
||||
|
||||
$document = \IPS\Xml\Rss::newDocument( $this->blog->url(), $title, $this->blog->description );
|
||||
|
||||
foreach ( \IPS\blog\Entry::getItemsWithPermission( array( array( 'entry_blog_id=?', $this->blog->id ), array( 'entry_status!=?', 'draft' ) ), 'entry_date DESC', 25, 'read', \IPS\Content\Hideable::FILTER_PUBLIC_ONLY, 0, new \IPS\Member ) as $entry )
|
||||
{
|
||||
$document->addItem( $entry->name, $entry->url(), $entry->content, \IPS\DateTime::ts( $entry->date ), $entry->id );
|
||||
}
|
||||
|
||||
/* @note application/rss+xml is not a registered IANA mime-type so we need to stick with text/xml for RSS */
|
||||
\IPS\Output::i()->sendOutput( $document->asXML(), 200, 'text/xml' );
|
||||
}
|
||||
|
||||
/**
|
||||
* RSS imports
|
||||
*
|
||||
@@ -306,12 +326,13 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
|
||||
/* Check for existing feed */
|
||||
try
|
||||
{
|
||||
$existing = \IPS\Db::i()->select( '*', 'blog_rss_import', array( 'rss_blog_id=?', $this->blog->id ) )->first();
|
||||
$feed = \IPS\blog\Blog\Feed::constructFromData( $existing );
|
||||
$existing = \IPS\Db::i()->select( '*', 'core_rss_import', array( 'rss_import_class=? AND rss_import_node_id=?', 'IPS\\blog\\Entry', $this->blog->id ) )->first();
|
||||
$feed = \IPS\core\Rss\Import::constructFromData( $existing );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
$feed = new \IPS\blog\Blog\Feed;
|
||||
$feed = new \IPS\core\Rss\Import;
|
||||
$feed->class = 'IPS\\blog\\Entry';
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
@@ -321,7 +342,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
|
||||
$form->add( new \IPS\Helpers\Form\Url( 'blog_rss_import_url', $feed ? $feed->url : NULL, TRUE, array(), NULL, NULL, NULL, 'blog_rss_import_url' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'blog_rss_import_auth_user', $feed ? $feed->auth_user : NULL, FALSE, array(), NULL, NULL, NULL, 'blog_rss_import_auth_user' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'blog_rss_import_auth_pass', $feed ? $feed->auth_pass : NULL, FALSE, array(), NULL, NULL, NULL, 'blog_rss_import_auth_pass' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'blog_rss_import_show_link', $feed->import_show_link ?: \IPS\Member::loggedIn()->language()->addToStack('blog_rss_import_show_link_default' ), FALSE, array(), NULL, NULL, NULL, 'blog_rss_import_show_link' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'blog_rss_import_show_link', $feed->showlink ?: \IPS\Member::loggedIn()->language()->addToStack('blog_rss_import_show_link_default' ), FALSE, array(), NULL, NULL, NULL, 'blog_rss_import_show_link' ) );
|
||||
|
||||
$options = array( 'autocomplete' => array( 'unique' => TRUE, 'minimized' => FALSE, 'source' => \IPS\Content\Item::definedTags( $this->blog ), 'freeChoice' => ( \IPS\Settings::i()->tags_open_system ? TRUE : FALSE ) ) );
|
||||
if ( \IPS\Settings::i()->tags_force_lower )
|
||||
@@ -383,7 +404,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
|
||||
$extralang[] = \IPS\Member::loggedIn()->language()->addToStack( 'tags_desc_len_max', FALSE, array( 'sprintf' => array( \IPS\Settings::i()->tags_len_max ) ) );
|
||||
}
|
||||
|
||||
$options['autocomplete']['desc'] = \IPS\Member::loggedIn()->language()->addToStack('tags_desc') . ( ( count( $extralang ) ) ? '<br>' . implode( $extralang, ' ' ) : '' );
|
||||
$options['autocomplete']['desc'] = \IPS\Member::loggedIn()->language()->addToStack('tags_desc') . ( ( \count( $extralang ) ) ? '<br>' . implode( ' ', $extralang ) : '' );
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'blog_rss_import_tags', $feed ? json_decode( $feed->tags, TRUE ) : array(), \IPS\Settings::i()->tags_min and \IPS\Settings::i()->tags_min_req, $options, NULL, NULL, NULL, 'blog_rss_import_tags' ) );
|
||||
@@ -409,6 +430,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
|
||||
}
|
||||
|
||||
$response = $response->decodeXml();
|
||||
|
||||
if ( !( $response instanceof \IPS\Xml\Rss ) and !( $response instanceof \IPS\Xml\Atom ) )
|
||||
{
|
||||
$form->error = \IPS\Member::loggedIn()->language()->addToStack( 'rss_import_invalid' );
|
||||
@@ -416,19 +438,21 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
|
||||
|
||||
if( !$form->error )
|
||||
{
|
||||
$feed->blog_id = $this->blog->id;
|
||||
$feed->node_id = $this->blog->id;
|
||||
$feed->url = $values['blog_rss_import_url'];
|
||||
$feed->import_show_link = $values['blog_rss_import_show_link'];
|
||||
$feed->showlink = $values['blog_rss_import_show_link'];
|
||||
$feed->auth_user = $values['blog_rss_import_auth_user'];
|
||||
$feed->auth_pass = $values['blog_rss_import_auth_pass'];
|
||||
$feed->tags = json_encode( $values['blog_rss_import_tags'] );
|
||||
$feed->member = $this->blog->owner() ? $this->blog->owner()->member_id : \IPS\Member::loggedIn()->member_id;
|
||||
|
||||
$feed->settings = json_encode( array( 'tags' => $values['blog_rss_import_tags'] ) );
|
||||
$feed->save();
|
||||
$feed->run();
|
||||
|
||||
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 1 ), array( '`key`=?', 'blogrssimport' ) );
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
$feed->run();
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
|
||||
/* Redirect */
|
||||
\IPS\Output::i()->redirect( $this->blog->url() );
|
||||
}
|
||||
@@ -445,7 +469,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Db::i()->delete( 'blog_rss_import', array( 'rss_blog_id=?', $this->blog->id ) );
|
||||
\IPS\Db::i()->delete( 'core_rss_import', array( 'rss_import_class=? AND rss_import_node_id=?', 'IPS\\blog\\Entry', $this->blog->id ) );
|
||||
|
||||
/* Redirect */
|
||||
\IPS\Output::i()->redirect( $this->blog->url() );
|
||||
@@ -453,7 +477,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output = $form->error ? $form : \IPS\Theme::i()->getTemplate( 'view', 'blog', 'front' )->rssImport( $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) ) );
|
||||
\IPS\Output::i()->output = $form->error ? $form : \IPS\Theme::i()->getTemplate( 'view', 'blog', 'front' )->rssImport( $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -488,4 +512,184 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
|
||||
{
|
||||
return $this->blog->coverPhoto();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return categories as JSON
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function categoriesJson()
|
||||
{
|
||||
$cats = array();
|
||||
foreach( \IPS\blog\Entry\Category::roots( NULL, NULL, array( 'entry_category_blog_id=?', $this->blog->id ) ) as $meow )
|
||||
{
|
||||
$cats[] = array(
|
||||
'id' => $meow->id,
|
||||
'name' => $meow->name
|
||||
);
|
||||
}
|
||||
|
||||
\IPS\Output::i()->json( array( 'categories' => $cats ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manageCategories()
|
||||
{
|
||||
if( !$this->blog->canEdit() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2B201/A', 403, '' );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('blog_manage_entry_categories');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'view', 'blog', 'front' )->manageCategories( \IPS\blog\Entry\Category::roots( NULL, NULL, array( 'entry_category_blog_id=?', $this->blog->id ) ), $this->blog );
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a category name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function editCategoryName()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
if( !$this->blog->canEdit() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2B201/C', 403, '' );
|
||||
}
|
||||
|
||||
if( ! \IPS\Request::i()->name )
|
||||
{
|
||||
\IPS\Output::i()->error( 'blog_error_missing_name', '1B201/B', 403, '' );
|
||||
}
|
||||
|
||||
/* New category? */
|
||||
if ( \IPS\Request::i()->cat === 'new' )
|
||||
{
|
||||
$newCategory = new \IPS\blog\Entry\Category;
|
||||
$newCategory->name = \IPS\Request::i()->name;
|
||||
$newCategory->seo_name = \IPS\Http\Url\Friendly::seoTitle( \IPS\Request::i()->name );
|
||||
|
||||
$newCategory->blog_id = $this->blog->id;
|
||||
$newCategory->save();
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
$category = \IPS\blog\Entry\Category::load( \IPS\Request::i()->cat );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'blog_error_not_find_category', '2B201/D', 403, '' );
|
||||
}
|
||||
|
||||
if( $category->blog_id !== $this->blog->id )
|
||||
{
|
||||
\IPS\Output::i()->error( 'blog_error_not_find_category', '2B201/E', 403, '' );
|
||||
}
|
||||
|
||||
$category->name = \IPS\Request::i()->name;
|
||||
$category->save();
|
||||
}
|
||||
|
||||
\IPS\Output::i()->json( 'OK' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Category
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function deleteCategory()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
if( !$this->blog->canEdit() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2B201/8', 403, '' );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$category = \IPS\blog\Entry\Category::load( \IPS\Request::i()->cat );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->redirect( $this->blog->url() );
|
||||
}
|
||||
|
||||
if( $category->blog_id !== $this->blog->id )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2B201/9', 403, '' );
|
||||
}
|
||||
|
||||
/* Update Entries */
|
||||
\IPS\Db::i()->update( 'blog_entries', array( 'entry_category_id' => NULL ), array( 'entry_category_id=?', $category->id ) );
|
||||
|
||||
$category->delete();
|
||||
|
||||
/* Redirect */
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( 'OK' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( $this->blog->url(), 'deleted' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorder blog entry categories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function categoriesReorder()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
if( !$this->blog->canEdit() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2B201/F', 403, '' );
|
||||
}
|
||||
|
||||
/* Set order */
|
||||
$position = 1;
|
||||
|
||||
if( !\IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Request::i()->ajax_order = explode( ',', \IPS\Request::i()->ajax_order );
|
||||
}
|
||||
|
||||
foreach( \IPS\Request::i()->ajax_order as $category )
|
||||
{
|
||||
$node = \IPS\blog\Entry\Category::load( $category );
|
||||
|
||||
/* No funny business trying to reorder another blog's categories */
|
||||
if( $node->blog_id !== $this->blog->id )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$node->position = $position;
|
||||
$node->save();
|
||||
|
||||
$position++;
|
||||
}
|
||||
|
||||
if( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( 'ok' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( $this->blog->url(), 'saved' );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user