Version 3.0.5

This commit is contained in:
Neo committed 2025-12-19 00:31:03 -08:00
1 parent 19b38c7c74
commit 1d4720f3e2
3755 files changed
+508378 -664541

No files matched your search

File diff suppressed because it is too large. Load diff
@@ -0,0 +1 @@
<html>␍<head><title>IP.Board - Bulletin Board System</title></head>␍<body>␍<h1>403: IP.Board -> Forbidden</h1>␍<hr>␍You have reached this page in error, please use your back button to return to the forum.␍<hr>␍<a href="http://www.invisionboard.com/">IP.Board</a>␍</body>␍</html>␍
@@ -0,0 +1,465 @@
<?php
/**
* Invision Power Services
* IP.Board v3.0.5
* IP.Blog attachment parsing
* Last Updated: $Date: 2009-07-21 16:19:42 -0400 (Tue, 21 Jul 2009) $
*
* @author $Author: josh $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.iinvisionpower.com/community/board/license.html
* @package Invision Power Board
* @subpackage IP.Blog
* @link http://www.iinvisionpower.com
* @since 6/24/2008
* @version $Revision: 4923 $
*/
if ( ! defined( 'IN_IPB' ) )
{
print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
exit();
}
class plugin_blogcblock extends class_attach
{
/**
* Module type
*
* @access public
* @var string
*/
public $module = 'blogcblock';
/**
* Returns an array of settings:
* 'siu_thumb' = Allow thumbnail creation?
* 'siu_height' = Height of the generated thumbnail in pixels
* 'siu_width' = Width of the generated thumbnail in pixels
* 'upload_dir' = Base upload directory (must be a full path)
*
* You can omit any of these settings and IPB will use the default
* settings (which are the ones entered into the ACP for post thumbnails)
*
* @access public
* @return boolean
*/
public function getSettings()
{
$this->mysettings = array( 'siu_thumb' => $this->settings['blog_thumb'],
'siu_width' => $this->settings['blog_thumb_width'],
'siu_height' => $this->settings['blog_thumb_height'],
'upload_dir' => $this->settings['blog_upload_dir'],
);
return true;
}
/**
* Checks the attachment and checks for download / show perms
*
* @access public
* @param integer Attachment id
* @return array Attachment data
*/
public function getAttachmentData( $attach_id )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$_ok = 0;
//-----------------------------------------
// Grab 'em
//-----------------------------------------
$this->DB->build( array( 'select' => 'a.*',
'from' => array( 'attachments' => 'a' ),
'where' => "a.attach_rel_module='" . $this->module . "' AND a.attach_id=" . $attach_id,
'add_join' => array( 0 => array( 'select' => 'bcc.cbcus_id',
'from' => array( 'blog_custom_cblocks' => 'bcc' ),
'where' => "bcc.cbcus_id=a.attach_rel_id",
'type' => 'left' ),
1 => array( 'select' => 'cb.blog_id',
'from' => array( 'blog_cblocks' => 'cb' ),
'where' => "cb.cblock_ref_id=bcc.cbcus_id AND cb.cblock_type='custom'",
'type' => 'left' ) )
) );
$attach_sql = $this->DB->execute();
$attach = $this->DB->fetch( $attach_sql );
//-----------------------------------------
// Check..
//-----------------------------------------
if ( ! isset( $attach['blog_id'] ) || ! $attach['blog_id'] )
{
return FALSE;
}
require_once ( IPSLib::getAppDir('blog') . '/sources/lib/lib_blogfunctions.php' );
$blog_std = new blogFunctions( $this->registry );
$blog_std->buildPerms();
$blog = $blog_std->loadBlog( $attach['blog_id'] );
if( !$blog['blog_id'] )
{
return false;
}
return $attach;
}
/**
* Check the attachment and make sure its OK to display
*
* @access public
* @param array Array of ids
* @param array Array of relationship ids
* @return array Attachment data
*/
public function renderAttachment( $attach_ids, $rel_ids=array() )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$rows = array();
$query = '';
//-----------------------------------------
// Check
//-----------------------------------------
if ( ! is_array( $attach_ids ) OR ! count( $attach_ids ) )
{
$attach_ids = array( -2 );
}
if ( is_array( $rel_ids ) and count( $rel_ids ) )
{
$query = " OR attach_rel_id IN (-1," . implode( ",", $rel_ids ) . ")";
}
//-----------------------------------------
// Grab 'em
//-----------------------------------------
$this->DB->build( array( 'select' => '*',
'from' => 'attachments',
'where' => "attach_rel_module='" . $this->module . "' AND ( attach_id IN(-1," . implode( ",", $attach_ids ) . ") " . $query . " )",
) );
$attach_sql = $this->DB->execute();
//-----------------------------------------
// Loop through and filter off naughty ids
//-----------------------------------------
while( $db_row = $this->DB->fetch( $attach_sql ) )
{
$_ok = 1;
//-----------------------------------------
// Ok?
//-----------------------------------------
if ( $_ok )
{
$rows[ $db_row['attach_id'] ] = $db_row;
}
}
//-----------------------------------------
// Return
//-----------------------------------------
return $rows;
}
/**
* Recounts number of attachments for the articles row
*
* @access public
* @param string Post key
* @param integer Related ID
* @param array Arguments for query
* @return array Returns count of items found
*/
public function postUploadProcess( $post_key, $rel_id, $args=array() )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$cnt = array( 'cnt' => 0 );
//-----------------------------------------
// Check..
//-----------------------------------------
if ( ! $post_key )
{
return 0;
}
$this->DB->build( array( "select" => 'COUNT(*) as cnt',
'from' => 'attachments',
'where' => "attach_rel_module='".$this->module."' AND attach_post_key='{$post_key}'") );
$this->DB->execute();
$cnt = $this->DB->fetch();
if ( $cnt['cnt'] )
{
$this->DB->buildAndFetch( array( 'update' => 'blog_custom_cblocks',
'set' => "cbcus_has_attach=cbcus_has_attach+" . $cnt['cnt'],
'where' => "cbcus_id=" . intval( $rel_id ) ) );
}
return array( 'count' => $cnt['cnt'] );
}
/**
* Recounts number of attachments for the articles row
*
* @access public
* @param array Attachment data
* @return boolean
*/
public function attachmentRemovalCleanup( $attachment )
{
//-----------------------------------------
// Check
//-----------------------------------------
if ( ! $attachment['attach_id'] )
{
return FALSE;
}
$this->DB->build( array( 'select' => 'e.cbcus_id',
'from' => array( 'blog_custom_cblocks' => 'e' ),
'where' => 'e.cbcus_id='. intval( $attachment['attach_rel_id'] )
) );
$this->DB->execute();
$cbcus = $this->DB->fetch();
if ( isset( $cbcus['cbcus_id'] ) )
{
$this->DB->build( array( "select" => 'count(*) as cnt',
'from' => 'attachments',
'where' => "attach_rel_module='".$this->module."' AND attach_rel_id = ".$cbcus['cbcus_id'] ) );
$this->DB->execute();
$cnt = $this->DB->fetch();
$count = intval( $cnt['cnt'] );
$this->DB->buildAndFetch( array( 'update' => 'blog_custom_cblocks', 'set' => "cbcus_has_attach=". $count , 'where' => "cbcus_id=".$cbcus['cbcus_id'] ) );
}
return TRUE;
}
/**
* Determines if you have permission for bulk attachment removal
* Returns TRUE or FALSE
* IT really does
*
* @access public
* @param array Ids to check against
* @return boolean
*/
public function canBulkRemove( $attach_rel_ids=array() )
{
return $this->memberData['g_is_supmod'] ? true : false;
}
/**
* Determines if you can remove this attachment
* Returns TRUE or FALSE
* IT really does
*
* @access public
* @param array Attachment data
* @return boolean
*/
public function canRemove( $attachment )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$ok_to_remove = FALSE;
//-----------------------------------------
// Check
//-----------------------------------------
if ( ! $attachment['attach_id'] )
{
return FALSE;
}
//-----------------------------------------
// Allowed to remove?
//-----------------------------------------
if ( $this->memberData['member_id'] == $attachment['attach_member_id'] )
{
if ( $this->settings['blog_allow_cblockchange'] && $this->settings['blog_allow_cblocks'] )
{
$ok_to_remove = TRUE;
}
}
else if ( $this->memberData['g_is_supmod'] )
{
$ok_to_remove = TRUE;
}
elseif ( $this->memberData['_blogmod']['moderate_allow_editcblocks'] )
{
$ok_to_remove = TRUE;
}
return $ok_to_remove;
}
/**
* Returns an array of the allowed upload sizes in bytes.
* Return 'space_allowed' as -1 to not allow uploads.
* Return 'space_allowed' as 0 to allow unlimited uploads
* Return 'max_single_upload' as 0 to not set a limit
*
* @access public
* @param string MD5 post key
* @param id Member ID
* @return array [ 'space_used', 'space_left', 'space_allowed', 'max_single_upload' ]
*/
public function getSpaceAllowance( $post_key='', $member_id='' )
{
$max_php_size = intval( IPSLib::getMaxPostSize() );
$member_id = intval( $member_id ? $member_id : $this->memberData['member_id'] );
$space_left = 0;
$space_used = 0;
$space_allowed = 0;
$max_single_upload = 0;
$space_calculated = 0;
if ( $post_key )
{
//-----------------------------------------
// Check to make sure we're not attempting
// to upload to another's post...
//-----------------------------------------
if ( ! $this->memberData['g_is_supmod'] )
{
$post = $this->DB->buildAndFetch( array( 'select' => '*',
'from' => 'posts',
'where' => "post_key='".$post_key."'" ) );
if ( $post['post_key'] AND ( $post['author_id'] != $member_id ) )
{
$space_allowed = -1;
$space_calculated = 1;
}
}
}
//-----------------------------------------
// Generate total space allowed
//-----------------------------------------
$total_space_allowed = ( $this->memberData['g_blog_attach_per_entry'] ? $this->memberData['g_blog_attach_per_entry'] : $this->memberData['g_blog_attach_max'] ) * 1024;
//-----------------------------------------
// Allowed to attach?
//-----------------------------------------
if ( ! $member_id )
{
$space_allowed = -1;
}
if ( ! $space_calculated )
{
//-----------------------------------------
// Generate space allowed figure
//-----------------------------------------
if ( $total_space_allowed > 0 )
{
if ( $this->memberData['g_blog_attach_per_entry'] )
{
//-----------------------------------------
// Per post limit...
//-----------------------------------------
$_space_used = $this->DB->buildAndFetch( array( 'select' => 'SUM(attach_filesize) as figure',
'from' => 'attachments',
'where' => "attach_post_key='".$post_key."'" ) );
$space_used = intval( $_space_used['figure'] );
$space_allowed = intval( ( $this->memberData['g_blog_attach_per_entry'] * 1024 ) - $space_used );
$space_allowed = $space_allowed < 0 ? 0 : $space_allowed;
}
else
{
//-----------------------------------------
// Global limit...
//-----------------------------------------
$_space_used = $this->DB->buildAndFetch( array( 'select' => 'SUM(attach_filesize) as figure',
'from' => 'attachments',
'where' => 'attach_member_id='.$member_id." AND attach_rel_module in('blogentry','blogcblock')" ) );
$space_used = intval( $_space_used['figure'] );
$space_allowed = intval( ( $this->memberData['g_blog_attach_max'] * 1024 ) - $space_used );
$space_allowed = $space_allowed < 0 ? 0 : $space_allowed;
}
}
else
{
# Unlimited
$space_allowed = 0;
}
//-----------------------------------------
// Generate space left figure
//-----------------------------------------
$space_left = $space_allowed ? $space_allowed : 0;
$space_left = ($space_left < 0) ? 0 : $space_left;
//-----------------------------------------
// Generate max upload size
//-----------------------------------------
if ( ! $max_single_upload )
{
if ( $space_left > 0 AND $space_left < $max_php_size )
{
$max_single_upload = $space_left;
}
else if ( $max_php_size )
{
$max_single_upload = $max_php_size;
}
}
}
$return = array( 'space_used' => $space_used, 'space_left' => $space_left, 'space_allowed' => $space_allowed, 'max_single_upload' => $max_single_upload, 'total_space_allowed' => $total_space_allowed );
return $return;
}
}
@@ -0,0 +1,456 @@
<?php
/**
* Invision Power Services
* IP.Board v3.0.5
* IP.Blog attachment parsing
* Last Updated: $Date: 2009-11-09 08:04:23 -0500 (Mon, 09 Nov 2009) $
*
* @author $Author: matt $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.iinvisionpower.com/community/board/license.html
* @package Invision Power Board
* @subpackage IP.Blog
* @link http://www.iinvisionpower.com
* @since 6/24/2008
* @version $Revision: 5335 $
*/
if ( ! defined( 'IN_IPB' ) )
{
print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
exit();
}
class plugin_blogentry extends class_attach
{
/**
* Module type
*
* @access public
* @var string
*/
public $module = 'blogentry';
/**
* Returns an array of settings:
* 'siu_thumb' = Allow thumbnail creation?
* 'siu_height' = Height of the generated thumbnail in pixels
* 'siu_width' = Width of the generated thumbnail in pixels
* 'upload_dir' = Base upload directory (must be a full path)
*
* You can omit any of these settings and IPB will use the default
* settings (which are the ones entered into the ACP for post thumbnails)
*
* @access public
* @return boolean
*/
public function getSettings()
{
$this->mysettings = array( 'siu_thumb' => $this->settings['blog_thumb'],
'siu_width' => $this->settings['blog_thumb_width'],
'siu_height' => $this->settings['blog_thumb_height'],
'upload_dir' => $this->settings['blog_upload_dir'] ? $this->settings['blog_upload_dir'] : $this->settings['upload_dir'] );
return true;
}
/**
* Checks the attachment and checks for download / show perms
*
* @access public
* @param integer Attachment id
* @return array Attachment data
*/
public function getAttachmentData( $attach_id )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$_ok = 0;
//-----------------------------------------
// Grab 'em
//-----------------------------------------
$this->DB->build( array( 'select' => 'a.*',
'from' => array( 'attachments' => 'a' ),
'where' => "a.attach_rel_module='".$this->module."' AND a.attach_id=".$attach_id,
'add_join' => array( 0 => array( 'select' => 'e.entry_id, e.blog_id',
'from' => array( 'blog_entries' => 'e' ),
'where' => "e.entry_id=a.attach_rel_id",
'type' => 'left' ) )
) );
$attach_sql = $this->DB->execute();
$attach = $this->DB->fetch( $attach_sql );
//-----------------------------------------
// Check..
//-----------------------------------------
if ( ! isset( $attach['blog_id'] ) || ! $attach['blog_id'] )
{
return FALSE;
}
require_once ( IPSLib::getAppDir('blog') . '/sources/classes/blogFunctions.php' );
$blog_std = new blogFunctions( $this->registry );
$blog_std->buildPerms();
$blog = $blog_std->loadBlog( $attach['blog_id'] );
if( !$blog['blog_id'] )
{
return false;
}
return $attach;
}
/**
* Check the attachment and make sure its OK to display
*
* @access public
* @param array Array of ids
* @param array Array of relationship ids
* @return array Attachment data
*/
public function renderAttachment( $attach_ids, $rel_ids=array() )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$rows = array();
$query = '';
//-----------------------------------------
// Check
//-----------------------------------------
if ( ! is_array( $attach_ids ) OR ! count( $attach_ids ) )
{
$attach_ids = array( -2 );
}
if ( is_array( $rel_ids ) and count( $rel_ids ) )
{
$query = " OR attach_rel_id IN (-1," . implode( ",", $rel_ids ) . ")";
}
//-----------------------------------------
// Grab 'em
//-----------------------------------------
$this->DB->build( array( 'select' => '*',
'from' => 'attachments',
'where' => "attach_rel_module='".$this->module."' AND ( attach_id IN(-1,". implode( ",", $attach_ids ) . ") " . $query . " )",
) );
$attach_sql = $this->DB->execute();
//-----------------------------------------
// Loop through and filter off naughty ids
//-----------------------------------------
while( $db_row = $this->DB->fetch( $attach_sql ) )
{
$_ok = 1;
//-----------------------------------------
// Ok?
//-----------------------------------------
if ( $_ok )
{
$rows[ $db_row['attach_id'] ] = $db_row;
}
}
//-----------------------------------------
// Return
//-----------------------------------------
return $rows;
}
/**
* Recounts number of attachments for the articles row
*
* @access public
* @param string Post key
* @param integer Related ID
* @param array Arguments for query
* @return array Returns count of items found
*/
public function postUploadProcess( $post_key, $rel_id, $args=array() )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$cnt = array( 'cnt' => 0 );
//-----------------------------------------
// Check..
//-----------------------------------------
if ( ! $post_key )
{
return 0;
}
$this->DB->build( array( "select" => 'COUNT(*) as cnt',
'from' => 'attachments',
'where' => "attach_rel_module='".$this->module."' AND attach_post_key='{$post_key}'") );
$this->DB->execute();
$cnt = $this->DB->fetch();
if ( $cnt['cnt'] )
{
$this->DB->buildAndFetch( array( 'update' => 'blog_entries',
'set' => "entry_has_attach=entry_has_attach+" . $cnt['cnt'],
'where' => "entry_id=" . intval( $rel_id ) ) );
}
return array( 'count' => $cnt['cnt'] );
}
/**
* Recounts number of attachments for the articles row
*
* @access public
* @param array Attachment data
* @return boolean
*/
public function attachmentRemovalCleanup( $attachment )
{
//-----------------------------------------
// Check
//-----------------------------------------
if ( ! $attachment['attach_id'] )
{
return FALSE;
}
$this->DB->build( array( 'select' => 'entry_id',
'from' => 'blog_entries',
'where' => 'entry_id='. intval( $attachment['attach_rel_id'] )
) );
$this->DB->execute();
$entry = $this->DB->fetch();
if ( isset( $entry['entry_id'] ) )
{
$this->DB->build( array( "select" => 'count(*) as cnt',
'from' => 'attachments',
'where' => "attach_rel_module='blogentry' AND attach_rel_id = ".$entry['entry_id'] ) );
$this->DB->execute();
$cnt = $this->DB->fetch();
$count = intval( $cnt['cnt'] );
$this->DB->build( array( 'update' => 'blog_entries', 'set' => "entry_has_attach=". $count , 'where' => "entry_id=".$entry['entry_id'] ) );
$this->DB->execute();
}
return TRUE;
}
/**
* Determines if you have permission for bulk attachment removal
* Returns TRUE or FALSE
* IT really does
*
* @access public
* @param array Ids to check against
* @return boolean
*/
public function canBulkRemove( $attach_rel_ids=array() )
{
return $this->memberData['g_is_supmod'] ? true : false;
}
/**
* Determines if you can remove this attachment
* Returns TRUE or FALSE
* IT really does
*
* @access public
* @param array Attachment data
* @return boolean
*/
public function canRemove( $attachment )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$ok_to_remove = FALSE;
//-----------------------------------------
// Check
//-----------------------------------------
if ( ! $attachment['attach_id'] )
{
return FALSE;
}
//-----------------------------------------
// Allowed to remove?
//-----------------------------------------
if ( $this->memberData['member_id'] == $attachment['attach_member_id'] )
{
$ok_to_remove = TRUE;
}
else if ( $this->memberData['g_is_supmod'] )
{
$ok_to_remove = TRUE;
}
elseif ( $this->memberData['_blogmod']['moderate_edit_comment'] )
{
$ok_to_remove = TRUE;
}
return $ok_to_remove;
}
/**
* Returns an array of the allowed upload sizes in bytes.
* Return 'space_allowed' as -1 to not allow uploads.
* Return 'space_allowed' as 0 to allow unlimited uploads
* Return 'max_single_upload' as 0 to not set a limit
*
* @access public
* @param string MD5 post key
* @param id Member ID
* @return array [ 'space_used', 'space_left', 'space_allowed', 'max_single_upload' ]
*/
public function getSpaceAllowance( $post_key='', $member_id='' )
{
$max_php_size = intval( IPSLib::getMaxPostSize() );
$member_id = intval( $member_id ? $member_id : $this->memberData['member_id'] );
$space_left = 0;
$space_used = 0;
$space_allowed = 0;
$max_single_upload = 0;
$space_calculated = 0;
if ( $post_key )
{
//-----------------------------------------
// Check to make sure we're not attempting
// to upload to another's post...
//-----------------------------------------
if ( ! $this->memberData['g_is_supmod'] )
{
$post = $this->DB->buildAndFetch( array( 'select' => '*', 'from' => 'posts', 'where' => "post_key='{$post_key}'" ) );
if ( $post['post_key'] AND ( $post['author_id'] != $member_id ) )
{
$space_allowed = -1;
$space_calculated = 1;
}
}
}
//-----------------------------------------
// Generate total space allowed
//-----------------------------------------
$total_space_allowed = ( $this->memberData['g_blog_attach_max'] ? $this->memberData['g_blog_attach_max'] : 0 ) * 1024;
//-----------------------------------------
// Allowed to attach?
//-----------------------------------------
if ( ! $member_id )
{
$space_allowed = -1;
}
if ( ! $space_calculated )
{
//-----------------------------------------
// Generate space allowed figure
//-----------------------------------------
if ( $total_space_allowed > 0 )
{
if ( $this->memberData['g_blog_attach_per_entry'] )
{
//-----------------------------------------
// Per post limit...
//-----------------------------------------
$_space_used = $this->DB->buildAndFetch( array( 'select' => 'SUM(attach_filesize) as figure',
'from' => 'attachments',
'where' => "attach_post_key='".$post_key."'" ) );
$space_used = intval( $_space_used['figure'] );
$space_allowed = intval( ( $this->memberData['g_blog_attach_per_entry'] * 1024 ) - $space_used );
$space_allowed = $space_allowed < 0 ? 0 : $space_allowed;
}
else
{
//-----------------------------------------
// Global limit...
//-----------------------------------------
$_space_used = $this->DB->buildAndFetch( array( 'select' => 'SUM(attach_filesize) as figure',
'from' => 'attachments',
'where' => 'attach_member_id='.$member_id." AND attach_rel_module in('blogentry','blogcblock')" ) );
$space_used = intval( $_space_used['figure'] );
$space_allowed = intval( ( $this->memberData['g_blog_attach_max'] * 1024 ) - $space_used );
$space_allowed = $space_allowed < 0 ? 0 : $space_allowed;
}
}
else
{
# Unlimited
$space_allowed = 0;
}
//-----------------------------------------
// Generate space left figure
//-----------------------------------------
$space_left = $space_allowed ? $space_allowed : 0;
$space_left = ($space_left < 0) ? 0 : $space_left;
//-----------------------------------------
// Generate max upload size
//-----------------------------------------
if ( ! $max_single_upload )
{
if ( $space_left > 0 AND $space_left < $max_php_size )
{
$max_single_upload = $space_left;
}
else if ( $max_php_size )
{
$max_single_upload = $max_php_size;
}
}
}
$return = array( 'space_used' => $space_used, 'space_left' => $space_left, 'space_allowed' => $space_allowed, 'max_single_upload' => $max_single_upload, 'total_space_allowed' => $total_space_allowed );
return $return;
}
}
@@ -0,0 +1,548 @@
<?php
/**
* Invision Power Services
* IP.Board v3.0.5
* IP.Board messenger attachments plugin
* Last Updated: $Date: 2009-09-24 08:06:26 -0400 (Thu, 24 Sep 2009) $
*
* @author $Author: josh $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.iinvisionpower.com/community/board/license.html
* @package Invision Power Board
* @subpackage Core
* @link http://www.iinvisionpower.com
* @since 6/24/2008
* @version $Revision: 5147 $
*/
if ( ! defined( 'IN_IPB' ) )
{
print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
exit();
}
class plugin_msg extends class_attach
{
/**
* Module type
*
* @access public
* @var string
*/
public $module = 'msg';
/**
* Checks the attachment and checks for download / show perms
*
* @access public
* @param integer Attachment id
* @return array Attachment data
*/
public function getAttachmentData( $attach_id )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$_ok = 0;
//-----------------------------------------
// Grab 'em
//-----------------------------------------
$this->DB->build( array( 'select' => 'a.*',
'from' => array( 'attachments' => 'a' ),
'where' => "a.attach_rel_module='".$this->module."' AND a.attach_id=".$attach_id,
'add_join' => array( 0 => array( 'select' => 'p.*',
'from' => array( 'message_posts' => 'p' ),
'where' => "p.msg_id=a.attach_rel_id",
'type' => 'left' ),
1 => array( 'select' => 't.*',
'from' => array( 'message_topics' => 't' ),
'where' => "t.mt_id=p.msg_topic_id",
'type' => 'left' ),
2 => array( 'select' => 'u.*',
'from' => array( 'message_topic_user_map' => 'u' ),
'where' => "u.map_topic_id=t.mt_id AND u.map_user_id=" . $this->memberData['member_id'],
'type' => 'left' ) ) ) );
$attach_sql = $this->DB->execute();
$attach = $this->DB->fetch( $attach_sql );
//-----------------------------------------
// Check..
//-----------------------------------------
if ( ! isset( $attach['msg_id'] ) OR empty( $attach['msg_id'] ) )
{
if( $attach['attach_member_id'] != $this->memberData['member_id'] )
{
return FALSE;
}
}
//-----------------------------------------
// For previews
//-----------------------------------------
if ( $attach['attach_rel_id'] == 0 AND $attach['attach_member_id'] == $this->memberData['member_id'] )
{
$_ok = 1;
}
else if ( $attach['map_user_id'] )
{
$_ok = 1;
}
//-----------------------------------------
// Ok?
//-----------------------------------------
if ( $_ok )
{
return $attach;
}
else
{
return FALSE;
}
}
/**
* Check the attachment and make sure its OK to display
*
* @access public
* @param array Array of ids
* @param array Array of relationship ids
* @return array Attachment data
*/
public function renderAttachment( $attach_ids, $rel_ids=array(), $attach_post_key=0 )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$rows = array();
$query_bits = array();
$query = '';
$match = 0;
//-----------------------------------------
// Check
//-----------------------------------------
if ( is_array( $attach_ids ) AND count( $attach_ids ) )
{
$query_bits[] = "attach_id IN (" . implode( ",", $attach_ids ) .")";
}
if ( is_array( $rel_ids ) and count( $rel_ids ) )
{
// We need to reset the array - this query bit will return everything we need, but
// if we "OR" join the above query bit with this one, it causes bigger mysql loads
$query_bits = array();
$query_bits[] = "attach_rel_id IN (" . implode( ",", $rel_ids ) . ")";
//$query = " OR attach_rel_id IN (-1," . implode( ",", $rel_ids ) . ")";
$match = 1;
}
if ( $attach_post_key )
{
$query_bits[] = "attach_post_key='".$this->DB->addSlashes( $attach_post_key )."'";
//$query .= " OR attach_post_key='".$this->DB->addSlashes( $attach_post_key )."'";
$match = 2;
}
if( !count($query_bits) )
{
$query = "attach_id IN (-1)";
}
else
{
$query = implode( " OR ", $query_bits );
}
//-----------------------------------------
// Grab 'em
//-----------------------------------------
$this->DB->build( array( 'select' => '*', 'from' => 'attachments', 'where' => "attach_rel_module='{$this->module}' AND ( {$query} )" ) );
$attach_sql = $this->DB->execute();
//-----------------------------------------
// Loop through and filter off naughty ids
//-----------------------------------------
while( $db_row = $this->DB->fetch( $attach_sql ) )
{
$_ok = 1;
if ( $match == 1 )
{
if ( ! in_array( $db_row['attach_rel_id'], $rel_ids ) )
{
$_ok = 0;
}
}
else if ( $match == 2 )
{
if ( $db_row['attach_post_key'] != $attach_post_key )
{
$_ok = 0;
}
}
//-----------------------------------------
// Ok?
//-----------------------------------------
if ( $_ok )
{
$rows[ $db_row['attach_id'] ] = $db_row;
}
}
//-----------------------------------------
// Return
//-----------------------------------------
return $rows;
}
/**
* Recounts number of attachments for the articles row
*
* @access public
* @param string Post key
* @param integer Related ID
* @param array Arguments for query
* @return array Returns count of items found
*/
public function postUploadProcess( $post_key, $rel_id, $args=array() )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$cnt = array( 'cnt' => 0 );
//-----------------------------------------
// Check..
//-----------------------------------------
if ( ! $post_key )
{
return 0;
}
$cnt = $this->DB->buildAndFetch( array( "select" => 'COUNT(*) as cnt',
'from' => 'attachments',
'where' => "attach_post_key='{$post_key}'") );
/*if ( $cnt['cnt'] )
{
$this->DB->update( 'message_topics', "mt_hasattach=mt_hasattach+" . $cnt['cnt'], "mt_id=" . intval( $args['mt_id'] ), FALSE, TRUE );
}*/
return array( 'count' => $cnt['cnt'] );
}
/**
* Recounts number of attachments for the articles row
*
* @access public
* @param array Attachment data
* @return boolean
*/
public function attachmentRemovalCleanup( $attachment )
{
//-----------------------------------------
// Check
//-----------------------------------------
if ( ! $attachment['attach_id'] )
{
return FALSE;
}
$message = $this->DB->buildAndFetch( array( 'select' => '*',
'from' => 'message_posts',
'where' => 'msg_id=' . intval( $attachment['attach_rel_id'] ) ) );
if ( isset( $message['msg_topic_id'] ) )
{
//-----------------------------------------
// GET ALL MSG IDS IN THIS TOPIC
//-----------------------------------------
$pids = array();
$count = 0;
$this->DB->build( array( 'select' => 'msg_id',
'from' => 'message_posts',
'where' => "msg_topic_id=". $message['msg_topic_id'] ) );
$this->DB->execute();
while ( $p = $this->DB->fetch() )
{
$pids[] = $p['msg_id'];
}
//-----------------------------------------
// GET ATTACHMENT COUNT
//-----------------------------------------
if ( count( $pids ) )
{
$this->DB->build( array( "select" => 'count(*) as cnt',
'from' => 'attachments',
'where' => "attach_rel_module='msg' AND attach_rel_id IN(".implode(",",$pids).")") );
$this->DB->execute();
$cnt = $this->DB->fetch();
$count = intval( $cnt['cnt'] );
}
$this->DB->update( 'message_topics', array( 'mt_hasattach' => $count ), "mt_id=" . $message['msg_topic_id'] );
}
return TRUE;
}
/**
* Determines if you have permission for bulk attachment removal
* Returns TRUE or FALSE
* IT really does
*
* @access public
* @param array Ids to check against
* @return boolean
*/
public function canBulkRemove( $attach_rel_ids=array() )
{
return $this->memberData['g_is_supmod'] ? true : false;
}
/**
* Determines if you can remove this attachment
* Returns TRUE or FALSE
* IT really does
*
* @access public
* @param array Attachment data
* @return boolean
*/
public function canRemove( $attachment )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$ok_to_remove = FALSE;
//-----------------------------------------
// Check
//-----------------------------------------
if ( ! $attachment['attach_id'] )
{
return FALSE;
}
//-----------------------------------------
// Allowed to remove?
//-----------------------------------------
if ( $this->memberData['member_id'] == $attachment['attach_member_id'] )
{
$ok_to_remove = TRUE;
}
else if ( $this->memberData['g_is_supmod'] )
{
$ok_to_remove = TRUE;
}
else
{
$message = $this->DB->buildAndFetch( array( 'select' => '*',
'from' => 'message_posts',
'where' => 'msg_id=' . intval( $attachment['attach_rel_id'] ) ) );
if ( $this->memberData['member_id'] == $message['msg_author_id'] )
{
$ok_to_remove = TRUE;
}
}
return $ok_to_remove;
}
/**
* Returns an array of the allowed upload sizes in bytes.
* Return 'space_allowed' as -1 to not allow uploads.
* Return 'space_allowed' as 0 to allow unlimited uploads
* Return 'max_single_upload' as 0 to not set a limit
*
* @access public
* @param string MD5 post key
* @param id Member ID
* @return array [ 'space_used', 'space_left', 'space_allowed', 'max_single_upload' ]
*/
public function getSpaceAllowance( $post_key='', $member_id='' )
{
$max_php_size = intval( IPSLib::getMaxPostSize() );
$member_id = intval( $member_id ? $member_id : $this->memberData['member_id'] );
$space_left = 0;
$space_used = 0;
$space_allowed = 0;
$max_single_upload = 0;
//-----------------------------------------
// Allowed to attach?
//-----------------------------------------
if ( ! $member_id )
{
$space_allowed = -1;
}
else
{
//-----------------------------------------
// Generate total space allowed
//-----------------------------------------
$total_space_allowed = ( $this->memberData['g_attach_per_post'] ? $this->memberData['g_attach_per_post'] : $this->memberData['g_attach_max'] ) * 1024;
//-----------------------------------------
// Generate space used figure
//-----------------------------------------
if ( $this->memberData['g_attach_per_post'] )
{
//-----------------------------------------
// Per post limit...
//-----------------------------------------
$_space_used = $this->DB->buildAndFetch( array( 'select' => 'SUM(attach_filesize) as figure',
'from' => 'attachments',
'where' => "attach_post_key='".$post_key."'" ) );
$space_used = intval( $_space_used['figure'] );
}
else
{
//-----------------------------------------
// Global limit...
//-----------------------------------------
$_space_used = $this->DB->buildAndFetch( array( 'select' => 'SUM(attach_filesize) as figure',
'from' => 'attachments',
'where' => 'attach_member_id='.$member_id . " AND attach_rel_module IN( 'post', 'msg' )" ) );
$space_used = intval( $_space_used['figure'] );
}
//-----------------------------------------
// Generate space allowed figure
//-----------------------------------------
if ( $this->memberData['g_attach_max'] > 0 )
{
if ( $this->memberData['g_attach_per_post'] )
{
$_g_space_used = $this->DB->buildAndFetch( array( 'select' => 'SUM(attach_filesize) as figure',
'from' => 'attachments',
'where' => 'attach_member_id='.$member_id . " AND attach_rel_module IN( 'post', 'msg' )" ) );
$g_space_used = intval( $_g_space_used['figure'] );
if( intval( ( $this->memberData['g_attach_max'] * 1024 ) - $g_space_used ) < 0 )
{
$space_used = $g_space_used;
$total_space_allowed = $this->memberData['g_attach_max'] * 1024;
$space_allowed = ( $this->memberData['g_attach_max'] * 1024 ) - $space_used;
$space_allowed = $space_allowed < 0 ? -1 : $space_allowed;
}
else
{
$space_allowed = ( $this->memberData['g_attach_per_post'] * 1024 ) - $space_used;
$space_allowed = $space_allowed < 0 ? -1 : $space_allowed;
}
}
else
{
$space_allowed = ( $this->memberData['g_attach_max'] * 1024 ) - $space_used;
$space_allowed = $space_allowed < 0 ? -1 : $space_allowed;
}
}
else
{
if ( $this->memberData['g_attach_per_post'] )
{
$space_allowed = ( $this->memberData['g_attach_per_post'] * 1024 ) - $space_used;
$space_allowed = $space_allowed < 0 ? -1 : $space_allowed;
}
else
{
# Unlimited
$space_allowed = 0;
}
}
//-----------------------------------------
// Generate space left figure
//-----------------------------------------
$space_left = $space_allowed ? $space_allowed : 0;
$space_left = ($space_left < 0) ? -1 : $space_left;
//-----------------------------------------
// Generate max upload size
//-----------------------------------------
if ( ! $max_single_upload )
{
if ( $space_left > 0 AND $space_left < $max_php_size )
{
$max_single_upload = $space_left;
}
else if ( $max_php_size )
{
$max_single_upload = $max_php_size;
}
}
}
IPSDebug::fireBug( 'info', array( 'Space left: ' . $space_left ) );
IPSDebug::fireBug( 'info', array( 'Max PHP size: ' . $max_php_size ) );
IPSDebug::fireBug( 'info', array( 'Max single file size: ' . $max_single_upload ) );
$return = array( 'space_used' => $space_used, 'space_left' => $space_left, 'space_allowed' => $space_allowed, 'max_single_upload' => $max_single_upload, 'total_space_allowed' => $total_space_allowed );
return $return;
}
/**
* Returns an array of settings:
* 'siu_thumb' = Allow thumbnail creation?
* 'siu_height' = Height of the generated thumbnail in pixels
* 'siu_width' = Width of the generated thumbnail in pixels
* 'upload_dir' = Base upload directory (must be a full path)
*
* You can omit any of these settings and IPB will use the default
* settings (which are the ones entered into the ACP for post thumbnails)
*
* @access public
* @return boolean
*/
public function getSettings()
{
$this->mysettings = array();
return true;
}
}
@@ -0,0 +1,700 @@
<?php
/**
* Invision Power Services
* IP.Board v3.0.5
* IP.Board post attachments plugin
* Last Updated: $Date: 2009-09-22 17:31:43 -0400 (Tue, 22 Sep 2009) $
*
* @author $Author: josh $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.iinvisionpower.com/community/board/license.html
* @package Invision Power Board
* @subpackage Core
* @link http://www.iinvisionpower.com
* @since 6/24/2008
* @version $Revision: 5141 $
*/
if ( ! defined( 'IN_IPB' ) )
{
print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
exit();
}
class plugin_post extends class_attach
{
/**
* Module type
*
* @access public
* @var string
*/
public $module = 'post';
/**
* Constructor
*
* @access public
* @param object ipsRegistry reference
* @return void
*/
public function __construct( ipsRegistry $registry )
{
parent::__construct( $registry );
/* Load and init forums */
if( ipsRegistry::isClassLoaded('class_forums') !== TRUE )
{
try
{
require_once( IPSLib::getAppDir( 'forums' ) . "/sources/classes/forums/class_forums.php" );
$this->registry->setClass( 'class_forums', new class_forums( $registry ) );
}
catch( Exception $error )
{
IPS_exception_error( $error );
}
$this->registry->getClass('class_forums')->strip_invisible = 1;
$this->registry->getClass('class_forums')->forumsInit();
$this->memberData = $this->registry->getClass('class_forums')->setUpModerator( $this->memberData );
}
}
/**
* Checks the attachment and checks for download / show perms
*
* @access public
* @param integer Attachment id
* @return array Attachment data
*/
public function getAttachmentData( $attach_id )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$_ok = 0;
if( ! $attach_id )
{
return FALSE;
}
//-----------------------------------------
// Grab 'em
//-----------------------------------------
$this->DB->build( array(
'select' => 'a.*',
'from' => array( 'attachments' => 'a' ),
'where' => "a.attach_rel_module='{$this->module}' AND a.attach_id={$attach_id}",
'add_join' => array(
array(
'select' => 'p.pid, p.topic_id, p.queued',
'from' => array( 'posts' => 'p' ),
'where' => "p.pid=a.attach_rel_id",
'type' => 'left'
),
array(
'select' => 't.forum_id',
'from' => array( 'topics' => 't' ),
'where' => "t.tid=p.topic_id",
'type' => 'left'
)
)
) );
$attach_sql = $this->DB->execute();
$attach = $this->DB->fetch( $attach_sql );
//-----------------------------------------
// Check..
//-----------------------------------------
if ( ! isset( $attach['pid'] ) OR empty( $attach['pid'] ) )
{
if( $attach['attach_member_id'] != $this->memberData['member_id'] )
{
return FALSE;
}
}
//-----------------------------------------
// Queued post?
//-----------------------------------------
if ( $attach['queued'] )
{
if ( ! ipsRegistry::getClass('class_forums')->canQueuePosts( $attach['forum_id'] ) )
{
return FALSE;
}
}
//-----------------------------------------
// TheWalrus inspired fix for previewing
// the post and clicking the attachment...
//-----------------------------------------
if ( $attach['attach_rel_id'] == 0 AND $attach['attach_member_id'] == $this->memberData['member_id'] )
{
$_ok = 1;
}
else
{
if ( ! ipsRegistry::getClass('class_forums')->forum_by_id[ $attach['forum_id'] ] )
{
//-----------------------------------------
// TheWalrus inspired fix for previewing
// the post and clicking the attachment...
//-----------------------------------------
if ( $attach['attach_rel_id'] == 0 AND $attach['attach_member_id'] == $this->memberData['member_id'] )
{
# We're ok.
}
else
{
return FALSE;
}
}
if ( IPSMember::checkPermissions('read', $attach['forum_id']) === FALSE )
{
return FALSE;
}
if ( IPSMember::checkPermissions('download', $attach['forum_id']) === FALSE )
{
return FALSE;
}
//-----------------------------------------
// Still here?
//-----------------------------------------
$_ok = 1;
}
//-----------------------------------------
// Ok?
//-----------------------------------------
if ( $_ok )
{
return $attach;
}
else
{
return FALSE;
}
}
/**
* Check the attachment and make sure its OK to display
*
* @access public
* @param array Array of ids
* @param array Array of relationship ids
* @return array Attachment data
*/
public function renderAttachment( $attach_ids, $rel_ids=array(), $attach_post_key=0 )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$rows = array();
$query_bits = array();
$query = '';
$match = 0;
//-----------------------------------------
// Check
//-----------------------------------------
if ( is_array( $attach_ids ) AND count( $attach_ids ) )
{
$query_bits[] = "attach_id IN (" . implode( ",", $attach_ids ) .")";
}
if ( is_array( $rel_ids ) and count( $rel_ids ) )
{
// We need to reset the array - this query bit will return everything we need, but
// if we "OR" join the above query bit with this one, it causes bigger mysql loads
$query_bits = array();
$query_bits[] = "attach_rel_id IN (" . implode( ",", $rel_ids ) . ")";
//$query = " OR attach_rel_id IN (-1," . implode( ",", $rel_ids ) . ")";
$match = 1;
}
if ( $attach_post_key )
{
$query_bits[] = "attach_post_key='".$this->DB->addSlashes( $attach_post_key )."'";
//$query .= " OR attach_post_key='".$this->DB->addSlashes( $attach_post_key )."'";
$match = 2;
}
if( !count($query_bits) )
{
$query = "attach_id IN (-1)";
}
else
{
$query = implode( " OR ", $query_bits );
}
//-----------------------------------------
// Grab 'em
//-----------------------------------------
$this->DB->build( array( 'select' => '*', 'from' => 'attachments', 'where' => "attach_rel_module='{$this->module}' AND ( {$query} )" ) );
$attach_sql = $this->DB->execute();
//-----------------------------------------
// Loop through and filter off naughty ids
//-----------------------------------------
while( $db_row = $this->DB->fetch( $attach_sql ) )
{
$_ok = 1;
if ( $match == 1 )
{
if ( ! in_array( $db_row['attach_rel_id'], $rel_ids ) )
{
$_ok = 0;
}
}
else if ( $match == 2 )
{
if ( $db_row['attach_post_key'] != $attach_post_key )
{
$_ok = 0;
}
}
//-----------------------------------------
// Ok?
//-----------------------------------------
if ( $_ok )
{
$rows[ $db_row['attach_id'] ] = $db_row;
}
}
//-----------------------------------------
// Return
//-----------------------------------------
return $rows;
}
/**
* Recounts number of attachments for the articles row
*
* @access public
* @param string Post key
* @param integer Related ID
* @param array Arguments for query
* @return array Returns count of items found
*/
public function postUploadProcess( $post_key, $rel_id, $args=array() )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$cnt = array( 'cnt' => 0 );
//-----------------------------------------
// Check..
//-----------------------------------------
if ( ! $post_key )
{
return 0;
}
$this->DB->build( array( "select" => 'COUNT(*) as cnt', 'from' => 'attachments', 'where' => "attach_post_key='{$post_key}'" ) );
$this->DB->execute();
$cnt = $this->DB->fetch();
if ( $cnt['cnt'] )
{
$this->DB->update( 'topics', "topic_hasattach=topic_hasattach+" . $cnt['cnt'], "tid=" . intval( $args['topic_id'] ), false, true );
}
return array( 'count' => $cnt['cnt'] );
}
/**
* Recounts number of attachments for the articles row
*
* @access public
* @param array Attachment data
* @return boolean
*/
public function attachmentRemovalCleanup( $attachment )
{
//-----------------------------------------
// Check
//-----------------------------------------
if ( ! $attachment['attach_id'] )
{
return FALSE;
}
$this->DB->build( array(
'select' => 'p.pid',
'from' => array( 'posts' => 'p' ),
'where' => 'p.pid='. intval( $attachment['attach_rel_id'] ),
'add_join' => array(
array(
'select' => 't.forum_id, t.tid',
'from' => array( 'topics' => 't' ),
'where' => 't.tid=p.topic_id',
'type' => 'inner'
)
)
) );
$this->DB->execute();
$topic = $this->DB->fetch();
if ( isset( $topic['tid'] ) )
{
//-----------------------------------------
// GET PIDS
//-----------------------------------------
$pids = array();
$count = 0;
$this->DB->build( array( 'select' => 'pid', 'from' => 'posts', 'where' => "topic_id={$topic['tid']}" ) );
$this->DB->execute();
while ( $p = $this->DB->fetch() )
{
$pids[] = $p['pid'];
}
//-----------------------------------------
// GET ATTACHMENT COUNT
//-----------------------------------------
if ( count( $pids ) )
{
$this->DB->build( array(
'select' => 'count(*) as cnt',
'from' => 'attachments',
'where' => "attach_rel_module='post' AND attach_rel_id IN(" . implode( ',', $pids ) . ")") );
$this->DB->execute();
$cnt = $this->DB->fetch();
$count = intval( $cnt['cnt'] );
}
$this->DB->update( 'topics', array( 'topic_hasattach' => $count ), "tid=".$topic['tid'] );
}
return TRUE;
}
/**
* Determines if you have permission for bulk attachment removal
* Returns TRUE or FALSE
* IT really does
*
* @access public
* @param array Ids to check against
* @return boolean
*/
public function canBulkRemove( $attach_rel_ids=array() )
{
return $this->memberData['g_is_supmod'] ? true : false;
}
/**
* Determines if you can remove this attachment
* Returns TRUE or FALSE
* IT really does
*
* @access public
* @param array Attachment data
* @return boolean
*/
public function canRemove( $attachment )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$ok_to_remove = FALSE;
//-----------------------------------------
// Check
//-----------------------------------------
if ( ! $attachment['attach_id'] )
{
return FALSE;
}
//-----------------------------------------
// Allowed to remove?
//-----------------------------------------
if ( $this->memberData['member_id'] == $attachment['attach_member_id'] )
{
$ok_to_remove = TRUE;
}
else if ( $this->memberData['g_is_supmod'] )
{
$ok_to_remove = TRUE;
}
else
{
//-----------------------------------------
// Moderstor? Get forum ID
//-----------------------------------------
if ( $this->memberData['forumsModeratorData'] )
{
$_moderator = $this->memberData['forumsModeratorData'];
$this->DB->build( array(
'select' => 'p.pid',
'from' => array( 'posts' => 'p' ),
'where' => 'p.pid='. intval( $attachment['attach_rel_id'] ),
'add_join' => array(
array(
'select' => 't.forum_id, t.tid',
'from' => array( 'topics' => 't' ),
'where' => 't.tid=p.topic_id',
'type' => 'inner'
)
)
) );
$this->DB->execute();
$topic = $this->DB->fetch();
if ( isset( $topic['forum_id'] ) )
{
if ( isset($_moderator[ $topic['forum_id'] ]['edit_post']) and $_moderator[ $topic['forum_id'] ]['edit_post'] )
{
$ok_to_remove = TRUE;
}
}
}
}
return $ok_to_remove;
}
/**
* Returns an array of the allowed upload sizes in bytes.
* Return 'space_allowed' as -1 to not allow uploads.
* Return 'space_allowed' as 0 to allow unlimited uploads
* Return 'max_single_upload' as 0 to not set a limit
*
* @access public
* @param string MD5 post key
* @param id Member ID
* @return array [ 'space_used', 'space_left', 'space_allowed', 'max_single_upload' ]
*/
public function getSpaceAllowance( $post_key='', $member_id='' )
{
$max_php_size = intval( IPSLib::getMaxPostSize() );
$member_id = intval( $member_id ? $member_id : $this->memberData['member_id'] );
$forum_id = intval( ipsRegistry::$request['forum_id'] ? ipsRegistry::$request['forum_id'] : ipsRegistry::$request['f'] );
$space_left = 0;
$space_used = 0;
$space_allowed = 0;
$max_single_upload = 0;
$space_calculated = 0;
if ( $post_key )
{
//-----------------------------------------
// Check to make sure we're not attempting
// to upload to another's post...
//-----------------------------------------
if ( ! $this->memberData['g_is_supmod'] AND !$this->memberData['is_mod'] )
{
$post = $this->DB->buildAndFetch( array( 'select' => '*', 'from' => 'posts', 'where' => "post_key='{$post_key}'" ) );
if ( $post['post_key'] AND ( $post['author_id'] != $member_id ) )
{
$space_allowed = -1;
$space_calculated = 1;
}
}
}
//-----------------------------------------
// Generate total space allowed
//-----------------------------------------
$total_space_allowed = ( $this->memberData['g_attach_per_post'] ? $this->memberData['g_attach_per_post'] : $this->memberData['g_attach_max'] ) * 1024;
//-----------------------------------------
// Allowed to attach?
//-----------------------------------------
if ( ! $member_id OR ! $forum_id )
{
$space_allowed = -1;
}
if ( IPSMember::checkPermissions('upload', $forum_id ) !== TRUE )
{
$space_allowed = -1;
}
else if ( ! $space_calculated )
{
//-----------------------------------------
// Generate space allowed figure
//-----------------------------------------
if ( $this->memberData['g_attach_per_post'] )
{
//-----------------------------------------
// Per post limit...
//-----------------------------------------
$_space_used = $this->DB->buildAndFetch( array(
'select' => 'SUM(attach_filesize) as figure',
'from' => 'attachments',
'where' => "attach_post_key='{$post_key}'"
) );
$space_used = intval( $_space_used['figure'] );
}
else
{
//-----------------------------------------
// Global limit...
//-----------------------------------------
$_space_used = $this->DB->buildAndFetch( array(
'select' => 'SUM(attach_filesize) as figure',
'from' => 'attachments',
'where' => "attach_member_id={$member_id} AND attach_rel_module IN( 'post', 'msg' )"
) );
$space_used = intval( $_space_used['figure'] );
}
if ( $this->memberData['g_attach_max'] > 0 )
{
if ( $this->memberData['g_attach_per_post'] )
{
$_g_space_used = $this->DB->buildAndFetch( array(
'select' => 'SUM(attach_filesize) as figure',
'from' => 'attachments',
'where' => "attach_member_id={$member_id} AND attach_rel_module IN( 'post', 'msg' )"
) );
$g_space_used = intval( $_g_space_used['figure'] );
if( intval( ( $this->memberData['g_attach_max'] * 1024 ) - $g_space_used ) < 0 )
{
$space_used = $g_space_used;
$total_space_allowed = $this->memberData['g_attach_max'] * 1024;
$space_allowed = ( $this->memberData['g_attach_max'] * 1024 ) - $space_used;
$space_allowed = $space_allowed < 0 ? -1 : $space_allowed;
}
else
{
$space_allowed = ( $this->memberData['g_attach_per_post'] * 1024 ) - $space_used;
$space_allowed = $space_allowed < 0 ? -1 : $space_allowed;
}
}
else
{
$space_allowed = ( $this->memberData['g_attach_max'] * 1024 ) - $space_used;
$space_allowed = $space_allowed < 0 ? -1 : $space_allowed;
}
}
else
{
if ( $this->memberData['g_attach_per_post'] )
{
$space_allowed = ( $this->memberData['g_attach_per_post'] * 1024 ) - $space_used;
$space_allowed = $space_allowed < 0 ? -1 : $space_allowed;
}
else
{
# Unlimited
$space_allowed = 0;
}
}
//-----------------------------------------
// Generate space left figure
//-----------------------------------------
$space_left = $space_allowed ? $space_allowed : 0;
$space_left = ($space_left < 0) ? -1 : $space_left;
//-----------------------------------------
// Generate max upload size
//-----------------------------------------
if ( ! $max_single_upload )
{
if ( $space_left > 0 AND $space_left < $max_php_size )
{
$max_single_upload = $space_left;
}
else if ( $max_php_size )
{
$max_single_upload = $max_php_size;
}
}
}
IPSDebug::fireBug( 'info', array( 'Space left: ' . $space_left ) );
IPSDebug::fireBug( 'info', array( 'Max PHP size: ' . $max_php_size ) );
IPSDebug::fireBug( 'info', array( 'Max single file size: ' . $max_single_upload ) );
$return = array( 'space_used' => $space_used, 'space_left' => $space_left, 'space_allowed' => $space_allowed, 'max_single_upload' => $max_single_upload, 'total_space_allowed' => $total_space_allowed );
return $return;
}
/**
* Returns an array of settings:
* 'siu_thumb' = Allow thumbnail creation?
* 'siu_height' = Height of the generated thumbnail in pixels
* 'siu_width' = Width of the generated thumbnail in pixels
* 'upload_dir' = Base upload directory (must be a full path)
*
* You can omit any of these settings and IPB will use the default
* settings (which are the ones entered into the ACP for post thumbnails)
*
* @access public
* @return boolean
*/
public function getSettings()
{
$this->mysettings = array();
return true;
}
}
@@ -0,0 +1,345 @@
<?php
/**
* Invision Power Services
* IP.Board v3.0.5
* Library of shared methods for hooks installation/configuration
* Last Updated: $LastChangedDate: 2009-06-30 12:06:12 -0400 (Tue, 30 Jun 2009) $
*
* @author $Author: josh $
* @author Based on original "Report Center" by Luke Scott
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.iinvisionpower.com/community/board/license.html
* @package Invision Power Board
* @subpackage Core
* @link http://www.iinvisionpower.com
* @version $Rev: 4829 $
*
*/
if ( ! defined( 'IN_IPB' ) )
{
print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
exit();
}
class hooksFunctions
{
/**#@+
* Registry objects
*
* @access protected
* @var object
*/
protected $registry;
protected $DB;
protected $settings;
protected $request;
protected $lang;
protected $member;
protected $memberData;
protected $cache;
protected $caches;
/**#@-*/
/**
* Constructor
*
* @access public
* @param object Registry object
* @return void
*/
public function __construct( ipsRegistry $registry )
{
//-----------------------------------------
// Make object
//-----------------------------------------
$this->registry = $registry;
$this->DB = $this->registry->DB();
$this->settings =& $this->registry->fetchSettings();
$this->request =& $this->registry->fetchRequest();
$this->member = $this->registry->member();
$this->memberData =& $this->registry->member()->fetchMemberData();
$this->cache = $this->registry->cache();
$this->caches =& $this->registry->cache()->fetchCaches();
$this->lang = $this->registry->class_localization;
$this->lang->loadLanguageFile( array( 'admin_applications' ) );
}
/**
* Get all the available hook ids in a function for a given type
*
* @access public
* @param string Skin Function
* @param string Hook type [foreach|if]
* @return array Settings for dropdown
*/
public function getHookIds( $template='', $type='' )
{
if( !$template )
{
return array();
}
$type = $type ? $type : 'foreach';
$return = array( array( 0, $this->lang->words['h_selectid'] ) );
$seenids = array();
$presort = array();
$this->DB->build( array( 'select' => 'template_content', 'from' => 'skin_templates', 'where' => "template_name='{$template}'" ) );
$this->DB->execute();
while( $r = $this->DB->fetch() )
{
/* Use regex to try to find the ids */
$matches = array();
if( $type == 'foreach' )
{
preg_match_all( "#\<foreach\s+loop=\"(.+?)\:(.+?)\"\>#i", $r['template_content'], $matches );
}
else
{
preg_match_all( "#\<if\s+test=\"(.+?)\:\|\:(.+?)\"\>#i", $r['template_content'], $matches );
}
if( is_array($matches[1]) AND count($matches[1]) )
{
foreach( $matches[1] as $match )
{
$presort[ $match ] = array( $match, $match );
}
}
}
/* Put the ids in alphabetical order, kinda hacky, oh well ;) */
ksort( $presort );
foreach( $presort as $k => $v )
{
$return[$k] = $v;
}
return $return;
}
/**
* Get all the available skin files
*
* @access public
* @return array Settings for dropdown
*/
public function getSkinGroups()
{
$return = array( array( 0, $this->lang->words['h_selectfile'] ) );
$this->DB->build( array( 'select' => $this->DB->buildDistinct( 'template_group' ), 'from' => 'skin_templates', 'order' => 'template_group ASC' ) );
$this->DB->execute();
while( $r = $this->DB->fetch() )
{
$return[] = array( $r['template_group'], $r['template_group'] );
}
return $return;
}
/**
* Get all the available skin templates in a skin group
*
* @access public
* @param string Skin Group
* @return array Settings for dropdown
*/
public function getSkinMethods( $file='' )
{
if( !$file )
{
return array();
}
$return = array( array( 0, $this->lang->words['h_selecttemp'] ) );
$this->DB->build( array( 'select' => $this->DB->buildDistinct( 'template_name' ), 'from' => 'skin_templates', 'where' => "template_group='{$file}'", 'order' => 'template_name ASC' ) );
$this->DB->execute();
while( $r = $this->DB->fetch() )
{
$return[] = array( $r['template_name'], $r['template_name'] );
}
return $return;
}
/**
* Retrieve setting groups for multiselect
*
* @access public
* @return array Settings for multiselect
*/
public function getSettingGroups()
{
$return = array();
$this->DB->build( array( 'select' => 'conf_title_id, conf_title_title', 'from' => 'core_sys_settings_titles', 'order' => 'conf_title_title ASC' ) );
$this->DB->execute();
while( $r = $this->DB->fetch() )
{
$return[] = array( $r['conf_title_id'], $r['conf_title_title'] );
}
return $return;
}
/**
* Retrieve settings for multiselect
*
* @access public
* @return array Settings for multiselect
*/
public function getSettings()
{
$return = array();
$this->DB->build( array( 'select' => 'conf_id, conf_title', 'from' => 'core_sys_conf_settings', 'order' => 'conf_title ASC' ) );
$this->DB->execute();
while( $r = $this->DB->fetch() )
{
$return[] = array( $r['conf_id'], $r['conf_title'] );
}
return $return;
}
/**
* Retrieve available modules for export
*
* @access public
* @return array Settings for multiselect
*/
public function getModules()
{
$return = array();
$this->DB->build(
array(
'select' => 'm.sys_module_key, m.sys_module_title, m.sys_module_admin',
'from' => array( 'core_sys_module' => 'm' ),
'order' => 'a.app_title ASC, m.sys_module_title ASC',
'add_join' => array(
array(
'select' => 'a.app_title',
'from' => array( 'core_applications' => 'a' ),
'where' => 'a.app_directory=m.sys_module_application',
'type' => 'left'
)
)
)
);
$this->DB->execute();
while( $r = $this->DB->fetch() )
{
$admin = $r['sys_module_admin'] ? $this->lang->words['hook_admin_module'] : $this->lang->words['hook_public_module'];
$return[] = array( $r['sys_module_key'], $r['app_title'] . ':: ' . $r['sys_module_title'] . $admin );
}
return $return;
}
/**
* Retrieve available Help Files for export
*
* @access public
* @return array Settings for multiselect
*/
public function getHelpFiles()
{
$return = array();
$this->DB->build( array( 'select' => 'id, title', 'from' => 'faq', 'order' => 'title ASC' ) );
$this->DB->execute();
while( $r = $this->DB->fetch() )
{
$return[] = array( $r['id'], $r['title'] );
}
return $return;
}
/**
* Retrieve available tasks for export
*
* @access public
* @return array Settings for multiselect
*/
public function getTasks()
{
$return = array();
$this->DB->build( array( 'select' => 'task_id, task_title', 'from' => 'task_manager', 'order' => 'task_title ASC' ) );
$this->DB->execute();
while( $r = $this->DB->fetch() )
{
$return[] = array( $r['task_id'], $r['task_title'] );
}
return $return;
}
/**
* Get all the available language files
*
* @access public
* @return array Settings for dropdown
*/
public function getLanguageFiles()
{
$return = array( array( 0, 'Select a File' ) );
$this->DB->build( array( 'select' => $this->DB->buildDistinct( 'word_pack' ), 'from' => 'core_sys_lang_words', 'order' => 'word_pack ASC' ) );
$this->DB->execute();
while( $r = $this->DB->fetch() )
{
$return[] = array( $r['word_pack'], $r['word_pack'] );
}
return $return;
}
/**
* Get all the available language strings in a given file
*
* @access public
* @param string Language file
* @return array Settings for multiselect
*/
public function getStrings( $file='' )
{
if( !$file )
{
return array();
}
$return = array();
$this->DB->build( array( 'select' => $this->DB->buildDistinct( 'word_key' ), 'from' => 'core_sys_lang_words', 'where' => "word_pack='{$file}'", 'order' => 'word_key ASC' ) );
$this->DB->execute();
while( $r = $this->DB->fetch() )
{
$return[] = array( $r['word_key'], $r['word_key'] );
}
return $return;
}
}
@@ -0,0 +1 @@
<html>␍<head><title>IP.Board - Bulletin Board System</title></head>␍<body>␍<h1>403: IP.Board -> Forbidden</h1>␍<hr>␍You have reached this page in error, please use your back button to return to the forum.␍<hr>␍<a href="http://www.invisionboard.com/">IP.Board</a>␍</body>␍</html>␍
@@ -0,0 +1,431 @@
<?php
/**
* Invision Power Services
* IP.Board v3.0.5
* Library for reported content
* Last Updated: $LastChangedDate: 2009-10-01 10:02:08 -0400 (Thu, 01 Oct 2009) $
*
* @author $Author: bfarber $
* @author Based on original "Report Center" by Luke Scott
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.iinvisionpower.com/community/board/license.html
* @package Invision Power Board
* @subpackage Core
* @link http://www.iinvisionpower.com
* @version $Rev: 5190 $
*
*/
if ( ! defined( 'IN_IPB' ) )
{
print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
exit();
}
class reportLibrary
{
/**#@+
* Registry objects
*
* @access protected
* @var object
*/
protected $registry;
protected $DB;
protected $settings;
protected $request;
protected $lang;
protected $member;
protected $cache;
/**#@-*/
/**
* Group Ids
*
* @access protected
* @var array
*/
protected $member_group_ids;
/**
* Array of plugin objects
*
* @access public
* @var array
*/
public $plugins;
/**
* Status for new reports
*
* @access public
* @var integer
*/
public $report_is_new = 0;
/**
* Status for complete reports
*
* @access public
* @var integer
*/
public $report_is_complete = 0;
/**
* Cache of status/flag images
*
* @access public
* @var array
*/
public $flag_cache = array();
/**
* Cache of HTML status dropdown
*
* @access public
* @var string
*/
public $flag_body = '';
/**
* Constructor
*
* @access public
* @param object Registry object
* @return void
*/
public function __construct( ipsRegistry $registry )
{
//-----------------------------------------
// Make object
//-----------------------------------------
$this->registry = $registry;
$this->DB = $this->registry->DB();
$this->settings =& $this->registry->fetchSettings();
$this->request =& $this->registry->fetchRequest();
$this->member = $this->registry->member();
$this->memberData =& $this->registry->member()->fetchMemberData();
$this->cache = $this->registry->cache();
$this->caches =& $this->registry->cache()->fetchCaches();
$this->member_group_ids = array( $this->memberData['member_group_id'] );
$this->member_group_ids = array_diff( array_merge( $this->member_group_ids, explode( ',', $this->memberData['mgroup_others'] ) ), array('') );
}
/**
* Rebuild the member cache array if it is outdated
*
* @access public
* @return integer New 'total reports' count
*/
public function rebuildMemberCacheArray()
{
$this->DB->loadCacheFile( IPSLib::getAppDir('core') . '/sql/' . ips_DBRegistry::getDriverType() . '_report_queries.php', 'report_sql_queries' );
$class_perm = $this->buildQueryPermissions();
$total = $this->DB->buildAndFetch( array(
'select' => 'COUNT(*) as reports',
'from' => array( 'rc_reports_index' => 'rep' ),
'where' => $class_perm . " AND stat.is_active=1",
'add_join' => array(
array(
'from' => array( 'rc_classes' => 'rcl' ),
'where' => 'rcl.com_id=rep.rc_class'
),
array(
'from' => array( 'rc_status' => 'stat' ),
'where' => 'stat.status=rep.status'
),
)
) );
$reports_by_plugin = array();
$this->DB->build( array(
'select' => 'rep.id, rep.title, rep.num_reports, rep.exdat1, rep.exdat2, rep.exdat3',
'from' => array( 'rc_reports_index' => 'rep' ),
'where' => $class_perm . " AND (stat.is_active=1 OR stat.is_new=1) AND rcl.onoff=1",
'order' => 'stat.is_new ASC',
'add_join' => array(
array(
'select' => 'stat.is_active, stat.is_new',
'from' => array( 'rc_status' => 'stat' ),
'where' => 'stat.status=rep.status'
),
array(
'select' => 'rcl.com_id, rcl.com_id, rcl.my_class, rcl.extra_data',
'from' => array( 'rc_classes' => 'rcl' ),
'where' => 'rcl.com_id=rep.rc_class'
),
)
) );
$this->DB->execute();
while( $row = $this->DB->fetch() )
{
if( $row['my_class'] != '' )
{
$reports_by_plugin[ $row['my_class'] ][] = $row;
}
}
$build_member_cache_array['report_temp'] = array();
foreach( $reports_by_plugin as $plugin_name => $reports_array )
{
$this->loadPlugin( $plugin_name );
$this->plugins[ $plugin_name ]->updateReportsTimestamp( $reports_array, $build_member_cache_array );
}
$build_member_cache_array['report_last_updated'] = time();
$build_member_cache_array['report_num'] = $total['reports'];
if( count($build_member_cache_array) > 0 )
{
IPSMember::packMemberCache( $this->memberData['member_id'], $build_member_cache_array );
}
return $total['reports'];
}
/**
* Builds permissions for several sql queries for various functions
*
* @access public
* @param string based on mods or users
* @return string
*/
public function buildQueryPermissions( $check='mod' )
{
//-----------------------------------------
// Are we checking user or mod permissions?
//-----------------------------------------
if( $check == 'mod' )
{
$col = 'mod_group_perm';
}
else
{
$col = 'group_can_report';
}
//-----------------------------------------
// Get components we have access to...
//-----------------------------------------
$this->DB->buildFromCache( 'get_class_permissions', array( 'COL' => $col, 'GROUP_IDS' => $this->member_group_ids ), 'report_sql_queries' );
$res = $this->DB->execute();
while( $row = $this->DB->fetch( $res ) )
{
if( $row['my_class'] != '' )
{
$spec_perm = '';
$this->loadPlugin( $row['my_class'] );
if( $row['extra_data'] && $row['extra_data'] != 'N;' )
{
$this->plugins[ $row['my_class'] ]->_extra = unserialize( $row['extra_data'] );
}
else
{
$this->plugins[ $row['my_class'] ]->_extra = array();
}
if( $this->plugins[ $row['my_class'] ]->getReportPermissions( $check, $row, $this->member_group_ids, $spec_perm ) )
{
$cids[ $row['com_id'] ] = $spec_perm;
}
}
}
return $this->DB->fetchLoadedClass('report_sql_queries')->join_com_permissions( array( 'NOTCACHE' => 1, 'COMS' => $cids ) );
}
/**
* Loads plugins into $this->plugins object for later use
*
* @access public
* @param string plugin name (>name<.php)
* @return void
*/
public function loadPlugin( $plugin_name )
{
if( ! $this->plugins[ $plugin_name ] )
{
require_once( IPSLib::getAppDir('core') . '/sources/reportPlugins/' . $plugin_name . '.php' );
$class_name = $plugin_name . '_plugin';
$this->plugins[ $plugin_name ] = new $class_name( $this->registry );
}
}
/**
* Process a URL
*
* @access public
* @param string URL
* @param string FURL Title
* @param string FURL Template
* @return string Full URL if existing URL was short
*/
public function processUrl( $url, $friendlyTitle='', $friendlyTemplate='' )
{
if( $url && ! preg_match( "/(http|https)\:\/\//", $url ) )
{
$returnUrl = str_replace( '/index.php?', '', $url );
$returnUrl = $this->registry->output->buildSEOUrl( $returnUrl, 'public', $friendlyTitle, $friendlyTemplate );
return $returnUrl;
}
else
{
return $url;
}
}
/**
* Fixes the member's RSS Key if none set
*
* @access public
* @return void
*/
public function checkMemberRSSKey()
{
if( ! $this->memberData['_cache']['rc_rss_key'] )
{
$new_rss_key = md5( uniqid( microtime(), true ) );
$this->DB->build( array( 'select' => '*', 'from' => 'rc_modpref', 'where' => "mem_id=" . $this->memberData['member_id'] ) );
$this->DB->execute();
if( $this->DB->getTotalRows() == 1 )
{
$this->DB->update( 'rc_modpref', array( 'rss_key' => $new_rss_key ), "mem_id=" . $this->memberData['member_id'] );
}
else
{
$this->DB->insert( 'rc_modpref', array( 'rss_key' => $new_rss_key, 'mem_id' => $this->memberData['member_id'], 'rss_cache' => '' ) );
}
$memberCache = $this->memberData['_cache'];
$memberCache['rc_rss_key'] = $new_rss_key;
$this->member->setProperty( '_cache', $memberCache );
IPSMember::packMemberCache( $this->memberData['member_id'], array( 'rc_rss_key' => $new_rss_key ) );
}
}
/**
* Generates report form HTML
*
* @access public
* @param string Title - What is being reported
* @param string URL - what the user can click on (title)
* @param array Extra data passed on to the form for processing
* @return string
*/
public function showReportForm( $name, $url, $ex_data=array() )
{
$extra_input = '';
if( is_array( $ex_data ) && count( $ex_data ) > 0 )
{
foreach( $ex_data as $bname => $value )
{
$extra_input .= "<input type='hidden' name='{$bname}' value='{$value}' />";
}
}
return $this->registry->getClass('output')->getTemplate('reports')->basicReportForm( $name, $url, $extra_input );
}
/**
* Updates global 'cache time' which forces 'mod caches' to re-cache
*
* @access public
* @return void
*/
public function updateCacheTime()
{
$cache = $this->cache->getCache('report_cache');
$cache['last_updated'] = time();
$this->cache->setCache( 'report_cache', $cache, array( 'array' => 1, 'donow' => 1 ) );
}
/**
* Builds the status information (and maybe drop down html)
*
* @access public
* @param boolean Do we need the drop down?
* @return string HTML body
*/
public function buildStatuses( $ignore_html = false )
{
if( !$this->flag_cache )
{
$stat_set = array();
$this->body = '';
$this->DB->build( array(
'select' => 'stat.status, stat.title, stat.is_new, stat.is_complete',
'from' => array( 'rc_status' => 'stat' ),
'order' => 'stat.rorder ASC, star.points ASC',
'add_join' => array(
array(
'select' => 'star.img, star.width, star.height, star.points, star.is_png',
'from' => array( 'rc_status_sev' => 'star' ),
'where' => 'stat.status=star.status'
)
)
) );
$this->DB->execute();
while( $row = $this->DB->fetch() )
{
if( ! $stat_set[ $row['status'] ] )
{
$this->body .= "<option value='{$row['status']}'>{$row['title']}</option>";
if( $row['is_new'] == 1 )
{
$this->report_is_new = $row['status'];
}
elseif( $row['is_complete'] == 1 )
{
$this->report_is_complete = $row['status'];
}
}
$stat_set[ $row['status'] ] = true;
$this->flag_cache[ $row['status'] ][ $row['points'] ] = array(
'img' => $row['img'],
'width' => $row['width'],
'height' => $row['height'],
'is_png' => $row['is_png'],
'title' => $row['title'],
);
if( $row['points'] == 0 )
{
$this->flag_cache[ $row['status'] ][ NULL ] = array(
'img' => $row['img'],
'width' => $row['width'],
'height' => $row['height'],
'is_png' => $row['is_png'],
'title' => $row['title'],
);
}
}
}
return $ignore_html ? '' : $this->body;
}
}
@@ -0,0 +1,370 @@
<?php
/**
* Invision Power Services
* IP.Board v3.0.5
* Notifications class for reported content
* Last Updated: $LastChangedDate: 2009-09-24 08:06:26 -0400 (Thu, 24 Sep 2009) $
*
* @author $Author: josh $
* @author Based on original "Report Center" by Luke Scott
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.iinvisionpower.com/community/board/license.html
* @package Invision Power Board
* @subpackage Core
* @link http://www.iinvisionpower.com
* @version $Rev: 5147 $
*/
if ( ! defined( 'IN_IPB' ) )
{
print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
exit();
}
class reportNotifications
{
/**#@+
* Registry objects
*
* @access protected
* @var object
*/
protected $registry;
protected $DB;
protected $settings;
protected $request;
protected $lang;
protected $member;
protected $cache;
/**#@-*/
/**
* Messenger object
*
* @access protected
* @var object
*/
protected $messenger;
/**
* Data for the members
*
* @access public
* @var array
*/
public $my_data;
/**
* Data for the reported content
*
* @access public
* @var array
*/
public $my_report_data;
/**
* Constructor
*
* @access public
* @param object Registry object
* @return void
*/
public function __construct( ipsRegistry $registry )
{
//-----------------------------------------
// Make object
//-----------------------------------------
$this->registry = $registry;
$this->DB = $this->registry->DB();
$this->settings =& $this->registry->fetchSettings();
$this->request =& $this->registry->fetchRequest();
$this->member = $this->registry->member();
$this->memberData =& $this->registry->member()->fetchMemberData();
$this->cache = $this->registry->cache();
$this->caches =& $this->registry->cache()->fetchCaches();
$this->lang = $this->registry->getClass('class_localization');
require_once( IPSLib::getAppDir( 'members' ) . '/sources/classes/messaging/messengerFunctions.php' );
$this->messenger = new messengerFunctions( $this->registry );
}
/**
* Initialize library
*
* @access public
* @param array Member data
* @param array Reported content
* @return void
*/
public function initNotify( $data, $report_data )
{
$this->my_data = $data;
$this->my_report_data = $report_data;
}
/**
* Send the notifications
*
* @access public
* @return void
*/
public function sendNotifications()
{
if( $this->my_data['PM'] && $this->settings['report_pm_enabled'] == 1 )
{
$this->_sendPMNotifications( $this->my_data['PM'], $this->my_report_data );
}
if( $this->my_data['EMAIL'] && $this->settings['report_nemail_enabled'] == 1 )
{
$this->_sendEmailNotifications( $this->my_data['EMAIL'], $this->my_report_data );
}
$this->_buildRSSFeed( $this->my_data['RSS'], $this->my_report_data );
}
/**
* Send the PM Notifications
*
* @access private
* @return void
*/
private function _sendPMNotifications( $data, $report_data )
{
foreach( $data as $user )
{
IPSText::getTextClass( 'email' )->getTemplate("report_emailpm");
IPSText::getTextClass( 'email' )->buildMessage( array(
'MOD_NAME' => $user['name'],
'USERNAME' => $this->memberData['members_display_name'],
'LINK' => $this->registry->getClass('reportLibrary')->processUrl( $report_data['SAVED_URL'], $report_data['SEOTITLE'], $report_data['TEMPLATE'] ),
'REPORTLINK'=> $this->settings['base_url'] . 'app=core&module=reports&do=show_report&rid=' . $report_data['REPORT_INDEX'],
'REPORT' => $report_data['REPORT'],
)
);
try
{
$this->messenger = new messengerFunctions( $this->registry );
$this->messenger->sendNewPersonalTopic( $user['member_id'],
$this->memberData['member_id'],
array(),
$this->lang->words['subject_report'] . ' ' . $this->memberData['members_display_name'],
IPSText::getTextClass( 'editor' )->method == 'rte' ? nl2br(IPSText::getTextClass( 'email' )->message) : IPSText::getTextClass( 'email' )->message,
array( 'origMsgID' => 0,
'fromMsgID' => 0,
'postKey' => md5(microtime()),
'trackMsg' => 0,
'addToSentFolder' => 0,
'hideCCUser' => 0,
'forcePm' => 1,
'isSystem' => TRUE
)
);
}
catch( Exception $error )
{
$msg = $error->getMessage();
if( $msg != 'CANT_SEND_TO_SELF' )
{
$toMember = IPSMember::load( $user['member_id'], 'core' );
if ( strstr( $msg, 'BBCODE_' ) )
{
$msg = str_replace( 'BBCODE_', '', $msg );
$this->registry->output->showError( $msg, 10149 );
}
else if ( isset($this->lang->words[ 'err_' . $msg ]) )
{
$this->lang->words[ 'err_' . $msg ] = $this->lang->words[ 'err_' . $msg ];
$this->lang->words[ 'err_' . $msg ] = str_replace( '#NAMES#' , implode( ",", $this->messenger->exceptionData ), $this->lang->words[ 'err_' . $msg ] );
$this->lang->words[ 'err_' . $msg ] = str_replace( '#TONAME#' , $toMember['members_display_name'] , $this->lang->words[ 'err_' . $msg ] );
$this->lang->words[ 'err_' . $msg ] = str_replace( '#FROMNAME#', $this->memberData['members_display_name'], $this->lang->words[ 'err_' . $msg ] );
$this->registry->output->showError( 'err_' . $msg, 10150 );
}
else
{
$_msgString = $this->lang->words['err_UNKNOWN'] . ' ' . $msg;
$this->registry->output->showError( 'err_UNKNOWN', 10151 );
}
}
}
}
}
/**
* Send the PM Notifications
*
* @access private
* @return void
*/
private function _sendEmailNotifications( $data, $report_data )
{
foreach( $data as $user )
{
IPSText::getTextClass( 'email' )->getTemplate( "report_emailpm", $user['language'] );
IPSText::getTextClass( 'email' )->buildMessage( array(
'MOD_NAME' => $user['name'],
'USERNAME' => $this->memberData['members_display_name'],
'LINK' => $this->registry->getClass('reportLibrary')->processUrl($report_data['SAVED_URL'], $report_data['SEOTITLE'], $report_data['TEMPLATE'] ),
'REPORTLINK'=> $this->settings['base_url'] . 'app=core&module=reports&do=show_report&rid=' . $report_data['REPORT_INDEX'],
'REPORT' => $report_data['REPORT'],
)
);
IPSText::getTextClass( 'email' )->subject = $this->lang->words['subject_report'] . ' ' . $this->memberData['members_display_name'];
IPSText::getTextClass( 'email' )->to = $user['email'];
IPSText::getTextClass( 'email' )->sendMail();
}
}
/**
* Build a private RSS feed for the member to monitor reports
*
* @access private
* @return void
*/
private function _buildRSSFeed( $data=array(), $report_data )
{
$ids = array();
$this->registry->getClass('class_localization')->loadLanguageFile( array( 'public_reports' ), 'core' );
if( is_array($data) AND count($data) )
{
foreach( $data as $user )
{
$ids[] = $user['member_id'];
}
}
if( count( $ids ) == 0 )
{
return;
}
require_once( IPS_KERNEL_PATH . 'classRss.php' );
$status = array();
$this->DB->build( array( 'select' => 'status, is_new, is_complete',
'from' => 'rc_status',
'where' => "is_new=1 OR is_complete=1",
) );
$this->DB->execute();
while( $row = $this->DB->fetch() )
{
if( $row['is_new'] == 1 )
{
$status['new'] = $row['status'];
}
elseif( $row['is_complete'] == 1 )
{
$status['complete'] = $row['status'];
}
}
//-----------------------------------------
// Now, we loop over each of the member ids
//-----------------------------------------
foreach( $ids as $id )
{
//-----------------------------------------
// Clear out for new RSS doc and add channel
//-----------------------------------------
$rss = new classRss();
$channel_id = $rss->createNewChannel( array( 'title' => $this->lang->words['rss_feed_title'],
'link' => $this->settings['board_url'],
'description' => $this->lang->words['reports_rss_desc'],
'pubDate' => $rss->formatDate( time() )
) );
//-----------------------------------------
// Now we need to find all open reports for
// this member
//-----------------------------------------
$this->DB->build( array(
'select' => 'i.*',
'from' => array( 'rc_reports_index' => 'i' ),
'where' => 's.is_active=1',
'add_join' => array(
array(
'from' => array( 'rc_status' => 's' ),
'where' => 's.status=i.status',
'type' => 'left',
),
array(
'select' => 'c.my_class, c.mod_group_perm',
'from' => array( 'rc_classes' => 'c' ),
'where' => 'c.com_id=i.rc_class',
'type' => 'left',
),
)
) );
$outer = $this->DB->execute();
while( $r = $this->DB->fetch($outer) )
{
//-----------------------------------------
// Fix stuff....this is hackish :(
//-----------------------------------------
if( $r['my_class'] == 'post' )
{
$r['FORUM_ID'] = $r['exdat1'];
}
//-----------------------------------------
// Found all open reports, can we access?
//-----------------------------------------
require_once( IPSLib::getAppdir('core') . '/sources/reportPlugins/' . $r['my_class'] . '.php' );
$class = $r['my_class'] . '_plugin';
$object = new $class( $this->registry );
$notify = $object->getNotificationList( IPSText::cleanPermString( $r['mod_group_perm'] ), $r );
$pass = false;
if( is_array($notify['RSS']) AND count($notify['RSS']) )
{
foreach( $notify['RSS'] as $memberAccount )
{
if( $memberAccount['mem_id'] == $id )
{
$pass = true;
break;
}
}
}
if( $pass )
{
$url = $this->registry->getClass('reportLibrary')->processUrl( str_replace( '&amp;', '&', $r['url'] ) );
$rss->addItemToChannel( $channel_id, array( 'title' => $url,
'link' => $url,
'description' => $r['title'],
'content' => $r['title'],
'pubDate' => $rss->formatDate( $r['date_updated'] )
) );
}
}
$rss->createRssDocument();
$this->DB->update( 'rc_modpref', array( 'rss_cache' => $rss->rss_document ), "mem_id=" . $id );
}
}
}