Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -10,10 +10,18 @@
|
||||
|
||||
namespace IPS\Content;
|
||||
|
||||
use IPS\Member;
|
||||
use IPS\core\ShareLinks\Service;
|
||||
use IPS\Text\Parser;
|
||||
|
||||
use function count;
|
||||
use function defined;
|
||||
use function header;
|
||||
|
||||
/* 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' );
|
||||
header( ($_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0') . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -22,4 +30,85 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
*
|
||||
* @note Content classes will gain special functionality by implementing this interface
|
||||
*/
|
||||
interface Shareable { }
|
||||
trait Shareable
|
||||
{
|
||||
/**
|
||||
* @brief [Content\Item] Sharelink HTML
|
||||
*/
|
||||
protected array $sharelinks = array();
|
||||
|
||||
/**
|
||||
* Can share
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canShare(): bool
|
||||
{
|
||||
if( !$this->actionEnabled( 'share' ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !$this->canView( Member::load( 0 ) ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return sharelinks for this item
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sharelinks(): array
|
||||
{
|
||||
if( !count( $this->sharelinks ) )
|
||||
{
|
||||
if ( $this->canShare() )
|
||||
{
|
||||
$shareUrl = $this->url();
|
||||
if( $this instanceof Item )
|
||||
{
|
||||
$this->sharelinks = Service::getAllServices( $shareUrl, $this->mapped('title'), NULL, $this );
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->sharelinks = Service::getAllServices( $shareUrl, $this->item()->mapped('title'), NULL, $this->item() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->sharelinks = array();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->sharelinks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Web Share Data
|
||||
*
|
||||
* @return array|NULL
|
||||
*/
|
||||
public function webShareData(): array|NULL
|
||||
{
|
||||
if( $this instanceof Item )
|
||||
{
|
||||
return array(
|
||||
'title' => Parser::truncate( $this->mapped('title'), TRUE ),
|
||||
'text' => Parser::truncate( $this->mapped('title'), TRUE ),
|
||||
'url' => (string) $this->url()
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return array(
|
||||
'title' => Parser::truncate( $this->item()->mapped('title'), TRUE ),
|
||||
'text' => $this->truncated( TRUE, NULL ),
|
||||
'url' => (string) $this->url()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user