Version 3.4.5

This commit is contained in:
Neo committed 2025-12-19 00:38:12 -08:00
1 parent fb6b5baabc
commit e4478369d8
1360 files changed
+228921 -179445

No files matched your search

+175 -32
View File
@@ -4,11 +4,11 @@
*~TERABYTE_DOC_READY~
* $Copyright: (c) 2001 - 2011 Invision Power Services, Inc.$
* $License: http://www.invisionpower.com/company/standards.php#license$
* $Author: ips_terabyte $
* $Author: bfarber $
* @since 11th October 2010
* $LastChangedDate: 2012-06-18 11:11:25 -0400 (Mon, 18 Jun 2012) $
* @version v3.3.4
* $Revision: 10937 $
* $LastChangedDate: 2013-05-17 19:05:15 -0400 (Fri, 17 May 2013) $
* @version v3.4.5
* $Revision: 12259 $
*
* <b>Example Usage:</b>
* @code
@@ -166,6 +166,67 @@ class classes_like_registry
trigger_error( "Member ID missing in " . __CLASS__ . '::' . __FUNCTION__, E_USER_WARNING );
}
}
/**
* Build key for SQL query
*
*
* @param integer $relId Relationship ID
* @param string $memberField Member Field or value
* @return @e binary Binary key
*/
static public function getKeyForSql( $relId, $memberField=NULL )
{
/* Check */
if ( empty( $relId ) AND empty( $memberField ) )
{
//var_dump(IPSDebug::prettifyBackTrace(debug_backtrace()));exit;
trigger_error( "Relationship ID missing in " . __CLASS__ . '::' . __FUNCTION__, E_USER_WARNING );
}
if ( $memberField === null )
{
/* For relative item only */
return ipsRegistry::DB()->buildMd5Statement( ipsRegistry::DB()->buildConcat( array(
array( self::$app, 'string' ),
array( ';', 'string' ),
array( self::$area, 'string' ),
array( ';', 'string' ),
array( $relId, 'string' ),
) ) );
}
else if ( ! empty( $memberField ) )
{
if ( $relId === null )
{
/* For member speciifc relative item */
return ipsRegistry::DB()->buildMd5Statement( ipsRegistry::DB()->buildConcat( array(
array( self::$app, 'string' ),
array( ';', 'string' ),
array( self::$area, 'string' ),
array( ';', 'string' ),
array( $memberField ),
) ) );
}
else
{
/* For member speciifc relative item */
return ipsRegistry::DB()->buildMd5Statement( ipsRegistry::DB()->buildConcat( array(
array( self::$app, 'string' ),
array( ';', 'string' ),
array( self::$area, 'string' ),
array( ';', 'string' ),
array( $relId, 'string' ),
array( ';', 'string' ),
array( $memberField ),
) ) );
}
}
else
{
trigger_error( "Member ID missing in " . __CLASS__ . '::' . __FUNCTION__, E_USER_WARNING );
}
}
}
@@ -406,6 +467,14 @@ abstract class classes_like_composite
*/
protected $_area;
/**
* Can bypass permission checks
*
* @var $_area
*/
protected $_bypassPermissionChecks = false;
/**
* Init all. Yes, it is.
*
@@ -549,6 +618,16 @@ abstract class classes_like_composite
trigger_error( "Data missing in " . __CLASS__ . '::' . __FUNCTION__, E_USER_WARNING );
}
if ( isset( $notificationOpts['notification_bypass_permission_checks'] ) && $notificationOpts['notification_bypass_permission_checks'] === true )
{
$this->_bypassPermissionChecks = true;
}
else
{
/* Make sure this is reset (Not used currently) */
$this->_bypassPermissionChecks = false;
}
$type = is_array($type) ? $type : array( $type );
/* Use session expiration, unless it is longer than 1 hour, then limit to 1 hour */
@@ -630,10 +709,10 @@ abstract class classes_like_composite
/* Add in unsubscribe link */
$key = $row['like_app'] . ';' . $row['like_area'] . ';' . $row['like_rel_id'] . ';' . $row['like_member_id'] . ';' . $row['member_id'] . ';' . $row['email'];
$buildMessage['UNSUBCRIBE_URL'] = $this->registry->output->buildSEOUrl( 'app=core&amp;module=global&amp;section=like&amp;do=unsubscribe&amp;key=' . IPSText::base64_encode_urlSafe( $key ), 'public', 'unsubscribe', 'likeunsubscribe' );
$buildMessage['UNSUBCRIBE_URL'] = $this->registry->output->buildSEOUrl( 'app=core&amp;module=global&amp;section=like&amp;do=unsubscribe&amp;key=' . IPSText::base64_encode_urlSafe( $key ), 'publicNoSession', 'unsubscribe', 'likeunsubscribe' );
IPSText::getTextClass('email')->setPlainTextTemplate( IPSText::getTextClass('email')->getTemplate( $notificationOpts['email_template'], $row['language'], trim($notificationOpts['email_lang_file']), trim($notificationOpts['email_lang_app']) ) );
IPSText::getTextClass('email')->buildMessage( $buildMessage );
IPSText::getTextClass('email')->buildPlainTextContent( $buildMessage );
$notifyLibrary->setMember( $row );
$notifyLibrary->setFrom( $notificationOpts['from'] ? $notificationOpts['from'] : $this->memberData );
@@ -641,6 +720,7 @@ abstract class classes_like_composite
$notifyLibrary->setNotificationUrl( $notificationOpts['notification_url'] );
$notifyLibrary->setNotificationText( IPSText::getTextClass('email')->getPlainTextContent() );
$notifyLibrary->setNotificationTitle( $notificationOpts['email_subject'] ? $notificationOpts['email_subject'] : IPSText::getTextClass('email')->subject );
$notifyLibrary->setNotificationHtml( IPSText::getTextClass('email')->buildHtmlContent( $buildMessage ) );
if ( ! empty( $notificationOpts['email_only_subject'] ) && $notificationOpts['email_only_subject'] != IPSText::getTextClass('email')->subject )
{
@@ -672,12 +752,13 @@ abstract class classes_like_composite
* @see allowedFrequencies()
*/
public function sendDigestNotifications( $type, $sendMax=null )
{
{
/* Fetch data */
$blackhole = time(); // mktime( 0, 0 ); - http://community.invisionpower.com/tracker/issue-35320-daily-digests-every-2-days
$time = ( $type == 'daily' ) ? $blackhole - ( 86400 ) : $blackhole - ( 86400 * 7 );
// The below has been changed based on troubleshooting in a ticket, 10.17.2012. With the code below not commented out, for a weekly digest we grab 15-7 days ago, rather than 8-0 days ago to send.
$time = $blackhole; //( $type == 'daily' ) ? $blackhole - ( 86400 ) : $blackhole - ( 86400 * 7 );
$data = $this->getDataByAreaAndLastSentOlderThanDate( $time, array( $type ), false, $sendMax );
if ( ! count( $data ) )
{
return false;
@@ -699,7 +780,8 @@ abstract class classes_like_composite
if ( $oldestPossDate )
{
$this->DB->update( 'core_like', array( 'like_notify_sent' => IPS_UNIX_TIME_NOW ), 'like_notify_sent < ' . $oldestPossDate );
$this->DB->update( 'core_like', array( 'like_notify_sent' => IPS_UNIX_TIME_NOW ),
'like_app=\'' . classes_like_registry::getApp() . '\' AND like_area=\'' . classes_like_registry::getArea() . '\' AND like_notify_sent < ' . $oldestPossDate . " AND like_notify_freq='{$type}'" );
}
$classToLoad = IPSLib::loadLibrary( IPS_ROOT_PATH . '/sources/classes/member/notifications.php', 'notifications' );
@@ -729,7 +811,7 @@ abstract class classes_like_composite
continue;
}
$buildMessage = array();
if ( is_array( $notificationOpts['build_message_array'] ) and count( $notificationOpts['build_message_array'] ) )
@@ -744,23 +826,28 @@ abstract class classes_like_composite
$buildMessage[$k] = $v;
}
}
/* Add in unsubscribe link */
$key = $row['like_app'] . ';' . $row['like_area'] . ';' . $row['like_rel_id'] . ';' . $row['like_member_id'] . ';' . $row['member_id'] . ';' . $row['email'];
$buildMessage['UNSUBCRIBE_URL'] = $this->registry->output->buildSEOUrl( 'app=core&amp;module=global&amp;section=like&amp;do=unsubscribe&amp;key=' . IPSText::base64_encode_urlSafe( $key ), 'publicNoSession', 'unsubscribe', 'likeunsubscribe' );
IPSText::getTextClass('email')->setPlainTextTemplate( IPSText::getTextClass('email')->getTemplate( $notificationOpts['email_template'], $row['language'], trim($notificationOpts['email_lang_file']), trim($notificationOpts['email_lang_app']) ) );
IPSText::getTextClass('email')->buildPlainTextContent( $buildMessage );
IPSText::getTextClass('email')->getTemplate( $notificationOpts['email_template'], $row['language'], trim($notificationOpts['email_lang_file']), trim($notificationOpts['email_lang_app']) );
IPSText::getTextClass('email')->buildMessage( $buildMessage );
$notifyLibrary->setMember( $row );
$notifyLibrary->setFrom( $notificationOpts['from'] ? $notificationOpts['from'] : $this->memberData );
$notifyLibrary->setNotificationKey( $notificationOpts['notification_key'] );
$notifyLibrary->setNotificationUrl( $notificationOpts['notification_url'] );
$notifyLibrary->setNotificationText( IPSText::getTextClass('email')->message );
$notifyLibrary->setNotificationText( IPSText::getTextClass('email')->getPlainTextContent() );
$notifyLibrary->setNotificationTitle( $notificationOpts['email_subject'] ? $notificationOpts['email_subject'] : IPSText::getTextClass('email')->subject );
$notifyLibrary->setNotificationHtml( IPSText::getTextClass('email')->buildHtmlContent( $buildMessage ) );
try
{
$notifyLibrary->sendNotification();
}
catch( Exception $e ){ }
/* Update sent timestamp */
$this->DB->update( 'core_like', array( 'like_notify_sent' => IPS_UNIX_TIME_NOW ), 'like_id=\'' . classes_like_registry::getKey( $row['like_rel_id'], $row['like_member_id'] ) . '\'' );
}
@@ -923,7 +1010,7 @@ abstract class classes_like_composite
/* Do it? */
if ( count( $dupes ) )
{
$this->DB->delete( 'core_like' , "like_cache IN('" . implode( "','", array_map( 'addslashes', $dupes ) ) . "')" );
$this->DB->delete( 'core_like' , "like_id IN('" . implode( "','", array_map( 'addslashes', $dupes ) ) . "')" );
}
/* Now re-update so that hashes are correct */
@@ -1227,23 +1314,31 @@ abstract class classes_like_composite
$members = array();
$rows = array();
$followType = is_array( $followType ) ? $followType : array( $followType );
$_isAnon = $skipAnon ? 'AND like_is_anon=0' : '';
$_whereB = $this->memberData['member_id'] ? " OR like_id='" . classes_like_registry::getKey( $relId, $this->memberData['member_id'] ) . "'" : '';
/* Determine where clause */
$where = array( "like_visible=1", "like_is_anon" . ( $skipAnon ? '=0' : ' IN(0,1)' ) );
/*if( $this->memberData['member_id'] )
{
$where[] = "(like_lookup_id='" . classes_like_registry::getKey( $relId ) . "' OR like_id='" . classes_like_registry::getKey( $relId, $this->memberData['member_id'] ) . "')";
}
else
{*/
$where[] = "like_lookup_id='" . classes_like_registry::getKey( $relId ) . "'";
//}
/* Add in follow type */
if ( count( $followType ) )
{
$_whereB .= " AND like_notify_freq IN ('" . implode( "','", $followType ) ."')";
$where[] = "like_notify_freq IN ('" . implode( "','", $followType ) ."')";
}
/* Fetch data */
$this->DB->build( array( 'select' => '*',
'from' => 'core_like',
'where' => "((like_lookup_id='" . classes_like_registry::getKey( $relId ) . "' {$_isAnon}) {$_whereB}) AND like_visible=1",
'where' => implode( " AND ", $where ),
'order' => 'like_added DESC',
'limit' => array( 0, 500 ) ) );
$o = $this->DB->execute();
while( $row = $this->DB->fetch( $o ) )
@@ -1329,18 +1424,16 @@ abstract class classes_like_composite
if ( in_array( 'weekly', $types ) )
{
/* Grab 8 days to account for timezone differences */
$oldestPossDate = $date - ( 86400 * 8 );
$oldestPossDate = $date - ( 86400 * 7 );
}
else
{
/* Grab 2 days to account for timezone differences */
$oldestPossDate = $date - ( 86400 * 2 );
$oldestPossDate = $date - ( 86400 );
}
if ( $oldestPossDate )
{
$where .= ' AND ( CASE WHEN l.like_notify_sent > 0 THEN l.like_notify_sent ELSE l.like_added END ) > ' . intval( $oldestPossDate );
$where .= ' AND ( CASE WHEN l.like_notify_sent > 0 THEN l.like_notify_sent ELSE l.like_added END ) < ' . intval( $oldestPossDate );
}
/* Fetch data */
@@ -1351,6 +1444,7 @@ abstract class classes_like_composite
'limit' => array( 0, $sendMax ),
'add_join' => $joins ) );
$o = $this->DB->execute();
while( $row = $this->DB->fetch( $o ) )
@@ -1361,7 +1455,10 @@ abstract class classes_like_composite
/* Need to apply secondary groups and grab g_perm_id if $parseMembers is false (default)
@link http://community.invisionpower.com/tracker/issue-34691-digest-notifications-not-going-out/ */
$row['mgroup_others'] = ($row['mgroup_others'] != '') ? IPSText::cleanPermString($row['mgroup_others']) : '';
//by denchu
if (is_array($this->caches['group_cache'][ $row['member_group_id'] ])){
$row = array_merge( $row, $this->caches['group_cache'][ $row['member_group_id'] ] );
}
$row = $this->registry->member()->setUpSecondaryGroups( $row );
if( $row['topic_last_post'] )
@@ -1372,7 +1469,7 @@ abstract class classes_like_composite
/* @link http://community.invisionpower.com/tracker/issue-32204-dailyweekly-notifications */
$data[ $row['like_member_id'] ][ $row['like_id'] ] = $row;
}
/* Just the one? */
if ( $parseMembers && count($mids) )
{
@@ -1647,6 +1744,52 @@ abstract class classes_like_composite
return $langString;
}
/**
* Replace all likes on one item with another
* Used when merging two items
*
* @param int $id1 The ID of the item being deleted
* @param int $id2 The ID of the item being kept
*/
public function merge( $id1, $id2 )
{
/* We need to tell the driver not to escape our md5 compilation statements */
$_fieldEncapsulate = $this->DB->fieldEncapsulate;
$this->DB->fieldEncapsulate = '';
$this->DB->manual_addslashes = TRUE;
/* Run the query - this looks a bit nuts, but basically we're setting any records for
likes on the old item to now be likes on the new, unelss the user has already liked
the new, in which case do nothing and we'll delete the left-overs in a minute */
$this->DB->update(
array( 'core_like' => 'a' ),
$this->DB->compileUpdateString( array(
'a.like_id' => classes_like_registry::getKeyForSql( $id2, 'a.like_member_id' ),
'a.like_lookup_id' => classes_like_registry::getKeyForSql( $id2 ),
'a.like_lookup_area'=> classes_like_registry::getKeyForSql( null, 'a.like_member_id' ),
'a.like_rel_id' => intval( $id2 ),
) ),
"a.like_app='{$this->_app}' AND a.like_area='{$this->_area}' AND a.like_rel_id={$id1} AND b.like_id " . $this->DB->buildIsNull(),
false,
true,
array( array(
'from' => array( 'core_like' => 'b' ),
'where' => "b.like_app='{$this->_app}' AND b.like_area='{$this->_area}' AND b.like_rel_id={$id2}",
) )
);
/* Reset the DB driver */
$this->DB->manual_addslashes = FALSE;
$this->DB->fieldEncapsulate = $_fieldEncapsulate;
/* Remove any stragglers (would happen if user was subscribed to both topics */
$this->remove( $id1 );
/* Reset the cache */
classes_like_cache::getInstance()->isNowStale( $id1 );
classes_like_cache::getInstance()->isNowStale( $id2 );
}
}
/**
@@ -1836,7 +1979,7 @@ class classes_like_cache
'where' => 'like_lookup_id=\'' . classes_like_registry::getKey( $relId ) . '\' AND like_is_anon=0 AND like_visible=1',
'order' => 'like_added DESC',
'limit' => array( 0, 5 ) ) );
$o = $this->DB->execute();
while( $row = $this->DB->fetch($o) )
@@ -1844,7 +1987,7 @@ class classes_like_cache
$items[ $row['like_rel_id'] ] = $row;
$mids[ $row['like_member_id'] ] = $row['like_member_id'];
}
/* Load members */
$members = IPSMember::load( $mids, 'core' );