Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

@@ -12,7 +12,7 @@
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;
@@ -30,6 +30,16 @@ class _browse extends \IPS\Dispatcher\Controller
*/
protected function manage()
{
/* Category */
try
{
$category = \IPS\blog\Category::loadAndCheckPerms( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
$category = NULL;
}
/* Featured stuff */
$featured = iterator_to_array( \IPS\blog\Entry::featured( 5, '_rand' ) );
$blogs = \IPS\blog\Blog::loadByOwner( \IPS\Member::loggedIn(), array( array( 'blog_disabled=?', 0 ) ) );
@@ -45,6 +55,7 @@ class _browse extends \IPS\Dispatcher\Controller
if ( isset( \IPS\Request::i()->view ) )
{
\IPS\Session::i()->csrfCheck();
\IPS\Request::i()->setCookie( 'blog_view', \IPS\Request::i()->view, ( new \IPS\DateTime )->add( new \DateInterval( 'P1Y' ) ) );
}
@@ -56,7 +67,7 @@ class _browse extends \IPS\Dispatcher\Controller
if ( \IPS\Request::i()->page )
{
$page = intval( \IPS\Request::i()->page );
$page = \intval( \IPS\Request::i()->page );
if ( !$page OR $page < 1 )
{
$page = 1;
@@ -64,8 +75,20 @@ class _browse extends \IPS\Dispatcher\Controller
}
/* @note We cannot check individual member permissions here, so entries in draft status are excluded. */
$count = \IPS\blog\Entry::getItemsWithPermission( array( array( "entry_status!=?", 'draft' ) ), 'entry_date desc', NULL, 'read', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, NULL, FALSE, FALSE, FALSE, TRUE );
$entries = \IPS\blog\Entry::getItemsWithPermission( array( array( "entry_status!=?", 'draft' ) ), 'entry_date desc', array( ( $perpage * ( $page - 1 ) ), $perpage ) );
$where = array();
$where[] = array( "blog_entries.entry_status!=?", 'draft' );
if ( !\IPS\Settings::i()->club_nodes_in_apps )
{
$where[] = array( "blog_blogs.blog_club_id IS NULL" );
}
if( $category )
{
$where[] = array( 'blog_blogs.blog_category_id=?', $category->_id );
}
$count = \IPS\blog\Entry::getItemsWithPermission( $where, 'entry_date desc', NULL, 'read', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, NULL, TRUE, FALSE, FALSE, TRUE );
$entries = \IPS\blog\Entry::getItemsWithPermission( $where, 'entry_date desc', array( ( $perpage * ( $page - 1 ) ), $perpage ), 'read', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, NULL, TRUE );
$pagination = array(
'page' => $page,
'pages' => ceil( $count / $perpage ),
@@ -74,12 +97,16 @@ class _browse extends \IPS\Dispatcher\Controller
);
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'grid.css', 'blog', 'front' ) );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'browse' )->indexGrid( $entries, $featured, $blogs, $pagination, $viewMode );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'browse' )->indexGrid( $entries, $featured, $blogs, $pagination, $viewMode, $category );
}
else
{
/* Blogs table */
$table = new \IPS\blog\Blog\Table( \IPS\Http\Url::internal( 'app=blog&module=blogs&controller=browse', 'front', 'blogs' ) );
if( $category )
{
$table->where[] = array( 'blog_category_id=?', $category->_id );
}
$table->title = 'our_community_blogs';
$table->classes = array( 'cBlogList', 'ipsAreaBackground', 'ipsDataList_large' );
@@ -89,12 +116,25 @@ class _browse extends \IPS\Dispatcher\Controller
'blogs_with_content' => array( 'blog_count_entries>0' )
);
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'browse' )->index( $table, $featured, $blogs, $viewMode );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'browse' )->index( $table, $featured, $blogs, $viewMode, $category );
}
\IPS\Session::i()->setLocation( \IPS\Http\Url::internal( 'app=blog', 'front', 'blogs' ), array(), 'loc_blog_viewing_index' );
/* Display */
if( \count( \IPS\blog\Category::roots() ) > 1 )
{
\IPS\Output::i()->sidebar['contextual'] = \IPS\Theme::i()->getTemplate( 'browse' )->categories( $category );
}
if( $category )
{
foreach( $category->parents() as $parent )
{
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
}
\IPS\Output::i()->breadcrumb[] = array( $category->url(), $category->_title );
}
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_browse.js', 'blog', 'front' ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('blogs');
@@ -12,7 +12,7 @@
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;
@@ -61,12 +61,13 @@ class _create extends \IPS\Dispatcher\Controller
}
\IPS\Session::i()->setLocation( \IPS\Http\Url::internal( 'app=blog', 'front', 'blogs' ), array(), 'loc_blog_creating' );
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_view.js', 'blog', 'front' ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('create_blog');
if( \IPS\Request::i()->isAjax() )
{
\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' ) );
}
else
{
+61 -28
View File
@@ -12,7 +12,7 @@
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;
@@ -72,42 +72,47 @@ class _entry extends \IPS\Content\Controller
protected function manage()
{
parent::manage();
$this->entry->container()->clubCheckRules();
$previous = NULL;
$next = NULL;
/* Prev */
try
{
$previous = \IPS\Db::i()->select(
'*',
'blog_entries',
array( 'entry_blog_id=? AND entry_date<? AND entry_status=? AND entry_is_future_entry=0', $this->entry->blog_id, $this->entry->date, "published" ),
'entry_date DESC'
,1
)->first();
$previous = \IPS\Db::i()->select(
'*',
'blog_entries',
array( 'entry_blog_id=? AND entry_date<? AND entry_status=? AND entry_is_future_entry=0 AND entry_hidden=?', $this->entry->blog_id, $this->entry->date, "published", 1 ),
'entry_date DESC'
,1
)->first();
$previous = \IPS\blog\Entry::constructFromData( $previous );
}
catch ( \UnderflowException $e ) {}
/* Next */
try
{
$next = \IPS\Db::i()->select(
'*',
'blog_entries',
array( 'entry_blog_id=? AND entry_date>? AND entry_status=? AND entry_is_future_entry=0', $this->entry->blog_id, $this->entry->date, "published" ),
'entry_date ASC'
,1
)->first();
$next = \IPS\Db::i()->select(
'*',
'blog_entries',
array( 'entry_blog_id=? AND entry_date>? AND entry_status=? AND entry_is_future_entry=0 AND entry_hidden=?', $this->entry->blog_id, $this->entry->date, "published", 1 ),
'entry_date ASC'
,1
)->first();
$next = \IPS\blog\Entry::constructFromData( $next );
}
catch ( \UnderflowException $e ) {}
/* Online User Location */
\IPS\Session::i()->setLocation( $this->entry->url(), $this->entry->onlineListPermissions(), 'loc_blog_viewing_entry', array( $this->entry->name => FALSE ) );
if( !$this->entry->container()->social_group )
{
\IPS\Session::i()->setLocation( $this->entry->url(), $this->entry->onlineListPermissions(), 'loc_blog_viewing_entry', array( $this->entry->name => FALSE ) );
}
/* Add JSON-ld output */
\IPS\Output::i()->jsonLd['blog'] = array(
@@ -146,7 +151,7 @@ class _entry extends \IPS\Content\Controller
'mainEntityOfPage' => (string) $this->entry->url(),
'name' => $this->entry->mapped('title'),
'headline' => $this->entry->mapped('title'),
'articleBody' => strip_tags( $this->entry->truncated() ),
'articleBody' => $this->entry->truncated( TRUE, NULL ),
'commentCount' => $this->entry->mapped('num_comments'),
'dateCreated' => \IPS\DateTime::ts( $this->entry->date )->format( \IPS\DateTime::ISO8601 ),
'datePublished' => \IPS\DateTime::ts( $this->entry->publish_date )->format( \IPS\DateTime::ISO8601 ),
@@ -157,13 +162,12 @@ class _entry extends \IPS\Content\Controller
'image' => \IPS\Member::load( $this->entry->mapped('author') )->get_photo()
),
'publisher' => array(
'@type' => 'Organization',
'name' => \IPS\Member::load( $this->entry->mapped('author') )->name,
'url' => (string) \IPS\Member::load( $this->entry->mapped('author') )->url(),
'image' => \IPS\Member::load( $this->entry->mapped('author') )->get_photo(),
'logo' => array(
'@type' => 'ImageObject',
'url' => \IPS\Member::load( $this->entry->mapped('author') )->get_photo(),
'@id' => \IPS\Settings::i()->base_url . '#organization',
'member' => array(
'@type' => 'Person',
'name' => \IPS\Member::load( $this->entry->mapped('author') )->name,
'url' => (string) \IPS\Member::load( $this->entry->mapped('author') )->url(),
'image' => \IPS\Member::load( $this->entry->mapped('author') )->get_photo()
)
),
'interactionStatistic' => array(
@@ -257,6 +261,35 @@ class _entry extends \IPS\Content\Controller
{
\IPS\Output::i()->sidebar['contextual'] = \IPS\Theme::i()->getTemplate('view')->blogSidebar( $this->entry->container()->sidebar );
}
/* Breadcrumb */
\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->entry->container()->category()->parents() as $parent )
{
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
}
\IPS\Output::i()->breadcrumb[] = array( $this->entry->container()->category()->url(), $this->entry->container()->category()->_title );
}
catch ( \OutOfRangeException $e ) {}
\IPS\Output::i()->breadcrumb[] = array( $this->entry->container()->url(), $this->entry->container()->_title );
\IPS\Output::i()->breadcrumb[] = array( NULL, $this->entry->name );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'view' )->entry( $this->entry, $previous, $next );
}
/**
* Return the form for editing. Abstracted so controllers can define a custom template if desired.
*
* @param \IPS\Helpers\Form $form The form
* @return string
*/
protected function getEditForm( $form )
{
return $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'submit', 'blog' ), 'submitFormTemplate' ) );
}
}
@@ -12,7 +12,7 @@
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;
@@ -68,7 +68,7 @@ class _submit extends \IPS\Dispatcher\Controller
\IPS\blog\Entry::canCreate( \IPS\Member::loggedIn(), $this->blog, TRUE );
$form = \IPS\blog\Entry::create( $this->blog );
$formTemplate = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'submit', 'blog' ) ), 'submitFormTemplate' ) );
$formTemplate = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'submit', 'blog' ), 'submitFormTemplate' ) );
if ( $club = $this->blog->club() )
{
@@ -83,8 +83,12 @@ class _submit extends \IPS\Dispatcher\Controller
}
}
\IPS\Output::i()->breadcrumb[] = array( $this->blog->url(), $this->blog->_title );
\IPS\Session::i()->setLocation( $this->blog->url(), array(), 'loc_blog_adding_entry', array( $this->blog->_title => FALSE ) );
if( !$this->blog->social_group )
{
\IPS\Session::i()->setLocation( $this->blog->url(), array(), 'loc_blog_adding_entry', array( $this->blog->_title => FALSE ) );
}
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'submit' )->submit( $formTemplate, $this->blog );
}
catch ( \OutOfRangeException $e )
+257 -53
View File
@@ -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' );
}
}
}