Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

+219 -5
View File
@@ -19,9 +19,9 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
}
/**
* File Model
* Package Item Model
*/
class _Item extends \IPS\Content\Item implements \IPS\Content\Featurable, \IPS\Content\Shareable, \IPS\Content\Embeddable, \IPS\Content\MetaData
class _Item extends \IPS\Content\Item implements \IPS\Content\Featurable, \IPS\Content\Shareable, \IPS\Content\Embeddable, \IPS\Content\MetaData, \IPS\Content\Searchable
{
/**
* @brief Application
@@ -69,7 +69,9 @@ class _Item extends \IPS\Content\Item implements \IPS\Content\Featurable, \IPS\C
'unapproved_reviews' => 'unapproved_reviews',
'hidden_reviews' => 'hidden_reviews',
'rating' => 'rating',
'meta_data' => 'meta_data'
'meta_data' => 'meta_data',
'date' => 'date_added',
'updated' => 'date_updated'
);
/**
@@ -82,6 +84,16 @@ class _Item extends \IPS\Content\Item implements \IPS\Content\Featurable, \IPS\C
*/
public static $icon = 'archive';
/**
* @brief Include In Sitemap
*/
public static $includeInSitemap = FALSE;
/**
* @brief Can this content be moderated normally from the front-end (will be FALSE for things like Pages and Commerce Products)
*/
public static $canBeModeratedFromFrontend = FALSE;
/**
* Get title
*
@@ -288,6 +300,10 @@ class _Item extends \IPS\Content\Item implements \IPS\Content\Featurable, \IPS\C
{
return $this->title;
}
elseif ( $key === 'date' )
{
return $this->date_added;
}
return parent::mapped($key);
}
@@ -298,6 +314,204 @@ class _Item extends \IPS\Content\Item implements \IPS\Content\Featurable, \IPS\C
*/
public static function supportedMetaDataTypes()
{
return array( 'core_FeaturedComments' );
return array();
}
}
/* !Search */
/**
* Title for search index
*
* @return string
*/
public function searchIndexTitle()
{
$titles = array();
foreach ( \IPS\Lang::languages() as $lang )
{
$titles[] = $lang->get("nexus_package_{$this->id}");
}
return implode( ' ', $titles );
}
/**
* Content for search index
*
* @return string
*/
public function searchIndexContent()
{
$descriptions = array();
foreach ( \IPS\Lang::languages() as $lang )
{
try
{
$descriptions[] = $lang->get("nexus_package_{$this->id}_desc");
}
catch ( \UnderflowException $e ) { }
}
return implode( ' ', $descriptions );
}
/**
* Search Index Permissions
*
* @return string Comma-delimited values or '*'
* @li Number indicates a group
* @li Number prepended by "m" indicates a member
* @li Number prepended by "s" indicates a social group
*/
public function searchIndexPermissions()
{
return $this->store ? $this->member_groups : '';
}
/**
* Columns needed to query for search result / stream view
*
* @return array
*/
public static function basicDataColumns()
{
return array( 'p_id', 'p_base_price', 'p_reviews', 'p_discounts', 'p_renew_options', 'p_tax', 'p_stock' );
}
/**
* Get URL from index data
*
* @param array $indexData Data from the search index
* @param array $itemData Basic data about the item. Only includes columns returned by item::basicDataColumns()
* @return \IPS\Http\Url
*/
public static function urlFromIndexData( $indexData, $itemData )
{
return \IPS\Http\Url::internal( "app=nexus&module=store&controller=product&id={$indexData['index_item_id']}", 'front', 'store_product', \IPS\Member::loggedIn()->language()->addToStack( 'nexus_package_' . $indexData['index_item_id'], FALSE, array( 'seotitle' => TRUE ) ) );
}
/**
* Get HTML for search result display
*
* @param array $indexData Data from the search index
* @param array $authorData Basic data about the author. Only includes columns returned by \IPS\Member::columnsForPhoto()
* @param array $itemData Basic data about the item. Only includes columns returned by item::basicDataColumns()
* @param array|NULL $containerData Basic data about the container. Only includes columns returned by container::basicDataColumns()
* @param array $reputationData Array of people who have given reputation and the reputation they gave
* @param int|NULL $reviewRating If this is a review, the rating
* @param bool $iPostedIn If the user has posted in the item
* @param string $view 'expanded' or 'condensed'
* @param bool $asItem Displaying results as items?
* @param bool $canIgnoreComments Can ignore comments in the result stream? Activity stream can, but search results cannot.
* @param array $template Optional custom template
* @param array $reactions Reaction Data
* @return string
*/
public static function searchResult( array $indexData, array $authorData, array $itemData, array $containerData = NULL, array $reputationData, $reviewRating, $iPostedIn, $view, $asItem, $canIgnoreComments=FALSE, $template=NULL, $reactions=array() )
{
$indexData['index_title'] = \IPS\Member::loggedIn()->language()->addToStack( 'nexus_package_' . $indexData['index_item_id'] );
return parent::searchResult( $indexData, $authorData, $itemData, $containerData, $reputationData, $reviewRating, $iPostedIn, $view, $asItem, $canIgnoreComments, $template, $reactions );
}
/**
* Query to get additional data for search result / stream view
*
* @param array $items Item data (will be an array containing values from basicDataColumns())
* @return array
*/
public static function searchResultExtraData( $items )
{
$images = iterator_to_array( \IPS\Db::i()->select( array( 'image_product', 'image_location' ), 'nexus_package_images', array( array( \IPS\Db::i()->in( 'image_product', array_keys( $items ) ) ), array( 'image_primary=1' ) ) )->setKeyField( 'image_product' )->setValueField( 'image_location' ) );
$taxIds = array();
foreach ( $items as $k => $data )
{
if ( $data['p_tax'] )
{
$taxIds[ $data['p_tax'] ] = $data['p_tax'];
}
}
$taxData = array();
if ( $taxIds )
{
$taxData = iterator_to_array( \IPS\Db::i()->select( '*', 'nexus_tax', \IPS\Db::i()->in( 't_id', $taxIds ) )->setKeyField('t_id') );
}
$return = array();
foreach ( $items as $k => $data )
{
$return[ $k ]['image'] = isset( $images[ $k ] ) ? $images[ $k ] : NULL;
$return[ $k ]['tax'] = ( $data['p_tax'] and isset( $taxData[ $data['p_tax'] ] ) ) ? $taxData[ $data['p_tax'] ] : NULL;
}
return $return;
}
/**
* Get snippet HTML for search result display
*
* @param array $indexData Data from the search index
* @param array $authorData Basic data about the author. Only includes columns returned by \IPS\Member::columnsForPhoto()
* @param array $itemData Basic data about the item. Only includes columns returned by item::basicDataColumns()
* @param array|NULL $containerData Basic data about the container. Only includes columns returned by container::basicDataColumns()
* @param array $reputationData Array of people who have given reputation and the reputation they gave
* @param int|NULL $reviewRating If this is a review, the rating
* @param string $view 'expanded' or 'condensed'
* @return callable
*/
public static function searchResultSnippet( array $indexData, array $authorData, array $itemData, array $containerData = NULL, array $reputationData, $reviewRating, $view )
{
$url = static::urlFromIndexData( $indexData, $itemData );
/* Work out the price to display @todo - make this more efficient */
try
{
$customer = \IPS\nexus\Customer::loggedIn();
$currency = ( isset( $_SESSION['currency'] ) and in_array( $_SESSION['currency'], \IPS\nexus\Money::currencies() ) ) ? $_SESSION['currency'] : $customer->defaultCurrency();
$priceMayChange = FALSE;
$priceNotIncludingDiscounts = NULL;
$renewOptions = $itemData['p_renew_options'] ? json_decode( $itemData['p_renew_options'], TRUE ) : array();
$price = \IPS\nexus\Package::lowestPriceFromData( $customer, $currency, $indexData['index_item_id'], json_decode( $itemData['p_base_price'], TRUE ), json_decode( $itemData['p_discounts'], TRUE ), $renewOptions, $itemData['p_stock'], $itemData['extra']['tax'] ? \IPS\nexus\Tax::constructFromData( $itemData['extra']['tax'] ) : NULL, $priceMayChange, $priceNotIncludingDiscounts );
if ( $price < $priceNotIncludingDiscounts )
{
$price = \IPS\Theme::i()->getTemplate( 'store', 'nexus' )->priceDiscounted( new \IPS\nexus\Money( $priceNotIncludingDiscounts, $currency ), new \IPS\nexus\Money( $price, $currency ), $priceMayChange, TRUE, 'ipsStream_price' );
}
else
{
$price = \IPS\Theme::i()->getTemplate( 'store', 'nexus' )->price( new \IPS\nexus\Money( $price, $currency ), $priceMayChange, TRUE, 'ipsStream_price' );
}
}
catch ( \OutOfRangeException $e )
{
$price = NULL;
}
/* Display */
return \IPS\Theme::i()->getTemplate( 'global', 'nexus', 'front' )->searchResultProductSnippet( $indexData, $itemData, isset( $itemData['extra']['image'] ) ? $itemData['extra']['image'] : NULL, $url, $price, $view == 'condensed' );
}
/**
* Check Moderator Permission
*
* @param string $type 'edit', 'hide', 'unhide', 'delete', etc.
* @param \IPS\Member|NULL $member The member to check for or NULL for the currently logged in member
* @param \IPS\Node\Model|NULL $container The container
* @return bool
*/
public static function modPermission( $type, \IPS\Member $member = NULL, \IPS\Node\Model $container = NULL )
{
/* Commerce Items have no own content type, so we can use only the general mod permissions */
$member = $member ?: \IPS\Member::loggedIn();
if ( in_array( $type, array( 'hide', 'unhide', 'delete' ) ) and $container )
{
if ( $member->modPermission( "can_{$type}" ) )
{
return TRUE;
}
}
return parent::modPermission( $type, $member, $container );
}
}