Перейти к публикации
View in the app

A better way to browse. Learn more.

Дизайн и модификация Invision Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Небольшая модификация приложения Videos 3.3.6

Опубликовано:

Приложение Videos 3.3.6 имеет опцию настройки импорта видео из RSS-потока в категорию.

 

При импорте создается новое видео, у которого в описании (поле Description) добавляется много ненужного с YouTube. Как отключить в коде файла \applications\videos\sources\Import.php импорт описания видео? То есть чтобы не импортировалось и не добавлялось в базу данных вообще.

 

<?php
/**
* @package		Videos
* @author		<a href='https://www.devfuse.com'>DevFuse</a>
* @copyright	(c) 2018-2019 DevFuse
*/

namespace IPS\videos;

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}

/**
* Media Import Node
*/
class _Import extends \IPS\Node\Model
{
/**
 * @brief	[ActiveRecord] Multiton Store
 */
protected static $multitons;

/**
 * @brief	[ActiveRecord] Database Table
 */
public static $databaseTable = 'videos_rss_import';

/**
 * @brief	Database Prefix
 */
public static $databasePrefix = 'video_import_';

/**
 * @brief	[Node] Node Title
 */
public static $nodeTitle = 'videos_rss_import';

/**
 * @brief	[Node] ACP Restrictions
 * @code
 	array(
 		'app'		=> 'core',				// The application key which holds the restrictrions
 		'module'	=> 'foo',				// The module key which holds the restrictions
 		'map'		=> array(				// [Optional] The key for each restriction - can alternatively use "prefix"
 			'add'			=> 'foo_add',
 			'edit'			=> 'foo_edit',
 			'permissions'	=> 'foo_perms',
 			'delete'		=> 'foo_delete'
 		),
 		'all'		=> 'foo_manage',		// [Optional] The key to use for any restriction not provided in the map (only needed if not providing all 4)
 		'prefix'	=> 'foo_',				// [Optional] Rather than specifying each  key in the map, you can specify a prefix, and it will automatically look for restrictions with the key "[prefix]_add/edit/permissions/delete"
 * @endcode
 */
protected static $restrictions = array(
	'app'		=> 'videos',
	'module'	=> 'videos',
	'prefix'	=> 'videoimport_'
);

/**
 * [Node] Get title
 *
 * @return	string
 */
protected function get__title()
{
	return $this->title;
}

/**
 * [Node] Get description
 *
 * @return	string
 */
protected function get__description()
{
	return $this->url;
}

/**
 * [Node] Get whether or not this node is enabled
 *
 * @note	Return value NULL indicates the node cannot be enabled/disabled
 * @return	bool|null
 */
protected function get__enabled()
{
	return $this->enabled;
}

/**
 * [Node] Set whether or not this node is enabled
 *
 * @param	bool|int	$enabled	Whether to set it enabled or disabled
 * @return	void
 */
protected function set__enabled( $enabled )
{
	if ( $enabled )
	{
		\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 1 ), array( '`key`=?', 'importVideos' ) );
	}
	$this->enabled = $enabled;
}

/**
 * [Node] Get buttons to display in tree
 * Example code explains return value
 *
 * @code
 	array(
 		array(
 			'icon'	=>	'plus-circle', // Name of FontAwesome icon to use
 			'title'	=> 'foo',		// Language key to use for button's title parameter
 			'link'	=> \IPS\Http\Url::internal( 'app=foo...' )	// URI to link to
 			'class'	=> 'modalLink'	// CSS Class to use on link (Optional)
 		),
 		...							// Additional buttons
 	);
 * @endcode
 * @param	string	$url		Base URL
 * @param	bool	$subnode	Is this a subnode?
 * @return	array
 */
public function getButtons( $url, $subnode=FALSE )
{
	$buttons = parent::getButtons( $url, $subnode );

	if ( \IPS\Member::loggedIn()->hasAcpRestriction('videoimport_run') )
	{
		$buttons = array_merge( array( 'run' => array(
			'icon'	=> 'refresh',
			'title'	=> 'videos_import_run',
			'link'	=> $url->setQueryString( array( 'do' => 'run', 'id' => $this->_id ) )
		) ), $buttons );
	}

	return $buttons;
}

/**
 * [Node] Add/Edit Form
 *
 * @param	\IPS\Helpers\Form	$form	The form
 * @return	void
 */
public function form( &$form )
{
	$form->addHeader('videos_mediaimport_feed');
	$form->add( new \IPS\Helpers\Form\Url( 'video_import_url', $this->url, TRUE ) );
	$form->add( new \IPS\Helpers\Form\Text( 'video_import_auth_user', $this->auth_user ) );
	$form->add( new \IPS\Helpers\Form\Password( 'video_import_auth_pass', $this->auth_pass ) );

	$form->addHeader('video_import_details');
       $form->add( new \IPS\Helpers\Form\Text( 'video_import_prefix', $this->prefix, FALSE, array( 'trim' => FALSE ) ) );
       $form->add( new \IPS\Helpers\Form\Member( 'video_import_member', $this->member ? \IPS\Member::load( $this->member ) : \IPS\Member::loggedIn(), TRUE ) );
       $form->add( new \IPS\Helpers\Form\Node( 'video_import_category', $this->category, TRUE, array( 'class' => 'IPS\videos\Category', 'permissionCheck' => 'add', 'clubs' => TRUE ) ) );
       $form->add( new \IPS\Helpers\Form\YesNo( 'video_import_tags', $this->tags, FALSE, array() ) );
       $form->add( new \IPS\Helpers\Form\YesNo( 'video_import_lock', $this->lock, FALSE, array() ) );
	$form->add( new \IPS\Helpers\Form\YesNo( 'video_import_hide', $this->hide, FALSE, array() ) );
}

/**
 * [Node] Format form values from add/edit form for save
 *
 * @param	array	$values	Values from the form
 * @return	array
 */
public function formatFormValues( $values )
{
	if( isset( $values['video_import_url'] ) )
	{
		try
		{
			$request = $values['video_import_url']->request();

			if ( $values['video_import_auth_user'] or $values['video_import_auth_pass'] )
			{
				$request = $request->login( $values['video_import_auth_user'], $values['video_import_auth_pass'] );
			}

			$response = $request->get();

			if ( $response->httpResponseCode == 401 )
			{
				throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'video_import_auth' ) );
			}

			$response = $response->decodeXml();
			if ( !( $response instanceof \IPS\Xml\Rss ) and !( $response instanceof \IPS\Xml\Atom ) )
			{
				throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'video_import_invalid' ) );
			}
		}
		catch ( \IPS\Http\Request\Exception $e )
		{
			throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'form_url_bad' ) );
		}
		catch( \RuntimeException $e )
		{
			throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'video_import_invalid' ) );
		}
		catch ( \ErrorException $e )
		{
			throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'video_import_invalid' ) );
		}

		$values['title'] = (string) $request->get()->decodeXml()->title;
	}

	if( isset( $values['video_import_category'] ) )
	{
		$values['category'] = $values['video_import_category']->_id;
		unset( $values['video_import_category'] );
	}

	if( isset( $values['video_import_member'] ) )
	{
		$values['member'] = $values['video_import_member']->member_id;
		unset( $values['video_import_member'] );
	}

	return $values;
}

/**
 * [Node] Perform actions after saving the form
 *
 * @param	array	$values	Values from the form
 * @return	void
 */
public function postSaveForm( $values )
{
       if( $this->enabled )
       {
           $this->run();
       }
}

/**
 * Run Import
 *
 * @return	void
 * @throws	\IPS\Http\Url\Exception
 */
public function run()
{
	/* Skip this if the member is restricted from posting */
	if( \IPS\Member::load( $this->member )->restrict_post or \IPS\Member::load( $this->member )->members_bitoptions['unacknowledged_warnings'] )
	{
		return;
	}

	/* Previously imported videos */
	$previouslyImportedGuids = iterator_to_array( \IPS\Db::i()->select( 'video_imported_guid', 'videos_rss_imported', array( 'video_imported_impid=?', $this->id ) ) );

	$request = \IPS\Http\Url::external( $this->url )->request();
	if ( $this->auth )
	{
		$request = $request->login( $this->auth_user, $this->auth_pass );
	}
	$request = $request->get();

	/* Get video category */
	$container = \IPS\videos\Category::load( $this->category );

	$i = 0;
	$inserts = array();
	$request = $request->decodeXml();

	if( !( $request instanceof \IPS\Xml\RssOne ) AND !( $request instanceof \IPS\Xml\Rss ) AND !( $request instanceof \IPS\Xml\Atom ) )
	{
		throw new \RuntimeException( 'video_import_invalid' );
	}

	$video = NULL;
	foreach ( $request->articles( $this->id ) as $guid => $article )
	{
		if ( !\in_array( $guid, $previouslyImportedGuids ) )
		{
			$video = \IPS\videos\Video::createItem( \IPS\Member::load( $this->member ), NULL, $article['date'], $container, $this->hide );
               $video->title       = $this->prefix . $article['title'];
               $video->description = \IPS\Text\Parser::parseStatic( $article['content'], TRUE, NULL, \IPS\Member::load( $this->member ), 'videos_Videos', TRUE, !(bool) \IPS\Member::load( $this->member )->group['g_dohtml'] );
               $video->video_data  = $article['link'];
               $video->video_type  = 'media_url';
			if( $this->lock )
			{
                   $video->state = 'closed';
			}
               $video->save();
               $video->generateThumbnail();
               $video->generateEmbed();

               /* Try and get media data */
               try
               {
                   $mediaData = \IPS\videos\MediaSite::loadDataFromUrl( $article['link'] );
               }
               catch( \OutOfRangeException $e ){}

               /* Any tags to save? */
               if( $this->tags AND $container->tags_enable AND isset( $mediaData['tags'] ) AND \count( $mediaData['tags'] ) )
               {
                   $tags = $mediaData['tags'];

                   /* Limit tags? */
                   if( \IPS\Settings::i()->tags_max )
                   {
                       $tags = \array_slice( $tags, 0, \IPS\Settings::i()->tags_max );
                   }

                   /* Add tags to video */
                   $video->setTags( $tags );
               }

			/* Send notifications */
			if ( !$this->hide )
			{
                   $video->sendNotifications();
			}

			/* Add to search index */
			\IPS\Content\Search\Index::i()->index( $video );

			$inserts[] = array(
				'video_imported_guid'  => $guid,
				'video_imported_vid'   => $video->tid,
				'video_imported_impid' => $this->id
			);

			$i++;

			if ( $i >= 10 )
			{
				break;
			}
		}
	}

	if( \count( $inserts ) )
	{
		\IPS\Db::i()->insert( 'videos_rss_imported', $inserts );
	}

	$this->last_import = time();
	$this->save();

	if ( $video !== NULL )
	{
           /* Update Category */
           $video->container()->setLastVideo();
           $video->container()->save();
       }
}

/**
 * [ActiveRecord] Delete Record
 *
 * @return	void
 */
public function delete()
{
	\IPS\Db::i()->delete( 'videos_rss_imported', array( "video_imported_impid=?", $this->id ) );
	return parent::delete();
}

/**
 * Search
 *
 * @param	string		$column	Column to search
 * @param	string		$query	Search query
 * @param	string|null	$order	Column to order by
 * @param	mixed		$where	Where clause
 * @return	array
 */
public static function search( $column, $query, $order=NULL, $where=array() )
{	
	if ( $column === '_title' )
	{
		$column = 'video_import_title';
	}
	if ( $order === '_title' )
	{
		$order = 'video_import_title';
	}
	return parent::search( $column, $query, $order, $where );
}
}

Изменено пользователем Zero108

Рекомендованные сообщения

Опубликовано:

Строка отвечающая за описание.

                $video->description = \IPS\Text\Parser::parseStatic( $article['content'], TRUE, NULL, \IPS\Member::load( $this->member ), 'videos_Videos', TRUE, !(bool) \IPS\Member::load( $this->member )->group['g_dohtml'] );

Можно закомментировать.

Создайте аккаунт или войдите в него для комментирования

Сейчас на странице 0

  • Нет пользователей, просматривающих эту страницу.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.