Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+81
View File
@@ -0,0 +1,81 @@
<?php
/**
* @brief Base mutator class for polls
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 8 Dec 2018
*/
namespace IPS\Poll\Api\GraphQL;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @brief Base mutator class for polls
*/
class _PollMutator
{
/**
* Vote in a poll
*
* @param \IPS\Poll $poll Poll reference
* @return void
*/
protected function _vote( $poll, $votes )
{
if( !$poll instanceof \IPS\Poll )
{
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_POLL', 'GQL/0007/1', 403 );
}
if( !$poll->canVote() )
{
throw new \IPS\Api\GraphQL\SafeException( 'CANNOT_VOTE', 'GQL/0007/2', 403 );
}
// A null vote is viewing the results and forfeiting the ability to vote again
if( $votes === NULL || !\count( $votes ) )
{
$vote = \IPS\Poll\Vote::fromForm( NULL );
}
else
{
$voteAsForm = array();
// Rebuild the vote array to match form input
foreach( $votes as $vote )
{
if( \is_array( $vote['choices'] ) )
{
if( \count( $vote['choices'] ) === 1 )
{
// When coming from a form we save this as a string without typecasting first, so replicating here for consistency
$choice = (string) \intval( $vote['choices'][0] );
}
else
{
$choice = $vote['choices'];
}
}
else
{
// When coming from a form we save this as a string without typecasting first, so replicating here for consistency
$choice = (string) \intval( $vote['choices'] );
}
$voteAsForm[ $vote['id'] ] = $choice;
}
$vote = \IPS\Poll\Vote::fromForm( $voteAsForm );
}
$poll->addVote( $vote, \IPS\Member::loggedIn() );
}
}
View File
Whitespace-only changes.
View File
Whitespace-only changes.
+3 -3
View File
@@ -12,7 +12,7 @@
namespace IPS\Poll;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -58,9 +58,9 @@ class _Iterator extends \FilterIterator
{
$row = $this->getInnerIterator()->current();
if ( is_array( $row->member_choices[ $this->question ] ) )
if ( \is_array( $row->member_choices[ $this->question ] ) )
{
return (bool) in_array( $this->option, $row->member_choices[ $this->question ] );
return (bool) \in_array( $this->option, $row->member_choices[ $this->question ] );
}
return $row->member_choices[ $this->question ] == $this->option;
+18 -8
View File
@@ -11,7 +11,7 @@
namespace IPS;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -213,7 +213,7 @@ class _Poll extends \IPS\Patterns\ActiveRecord implements \SplSubject
{
$choices[ $k ] = array(
'question' => $questionData['title'],
'multi' => intval( isset( $questionData['multichoice'] ) ),
'multi' => \intval( isset( $questionData['multichoice'] ) ),
'choice' => array(),
'votes' => array(),
);
@@ -225,7 +225,8 @@ class _Poll extends \IPS\Patterns\ActiveRecord implements \SplSubject
} ), '<a><img>' );
/* AllowedElements strips <___base_url___> */
$answerData['value'] = preg_replace( '#(<img\s+?src=[\'"])___base_url___/#', '\1<___base_url___>/', $answerData['value'] );
$answerData['value'] = preg_replace( '#(\s+?src=[\'"])___base_url___/#', '\1<___base_url___>/', $answerData['value'] );
$answerData['value'] = preg_replace( '#(\s+?data-src=[\'"])___base_url___/#', '\1<___base_url___>/', $answerData['value'] );
$count = isset( $existing[ $k ]['votes'][ $answerId ] ) ? $existing[ $k ]['votes'][ $answerId ] : 0;
if ( trim( $answerData['value'] ) !== "" )
@@ -234,7 +235,7 @@ class _Poll extends \IPS\Patterns\ActiveRecord implements \SplSubject
if ( isset( $answerData['count'] ) and \IPS\Member::loggedIn()->modPermission('can_edit_poll_votes') )
{
$count = ( $answerData['count'] > 0 ? intval( $answerData['count'] ) : 0 );
$count = ( $answerData['count'] > 0 ? \intval( $answerData['count'] ) : 0 );
}
}
@@ -263,6 +264,13 @@ class _Poll extends \IPS\Patterns\ActiveRecord implements \SplSubject
}
$closeDate = new \IPS\DateTime( \IPS\Helpers\Form\Date::_convertDateFormat( $data['poll_close_date'] ) . $time, $timezone );
/* Moderator Log */
if( $this->poll_close_date instanceof \IPS\DateTime AND $closeDate != $this->poll_close_date )
{
\IPS\Session::i()->modLog( 'modlog__poll_autoclose', array( $this->pid => FALSE, $closeDate->rfc1123() => FALSE) );
}
$this->poll_close_date = $closeDate;
/* Close date is in the past, make sure the poll is closed */
@@ -343,7 +351,7 @@ class _Poll extends \IPS\Patterns\ActiveRecord implements \SplSubject
{
return FALSE;
}
return TRUE;
}
@@ -392,7 +400,7 @@ class _Poll extends \IPS\Patterns\ActiveRecord implements \SplSubject
$pollChoices = $this->choices;
foreach ( $vote->member_choices as $key => $value )
{
if ( is_array( $value ) )
if ( \is_array( $value ) )
{
foreach ( $value as $k => $v )
{
@@ -492,7 +500,7 @@ class _Poll extends \IPS\Patterns\ActiveRecord implements \SplSubject
try
{
/* Pre 4.x data can be bad */
if ( !is_array( $this->choices ) || !count( $this->choices ) )
if ( !\is_array( $this->choices ) || !\count( $this->choices ) )
{
return '';
}
@@ -510,7 +518,8 @@ class _Poll extends \IPS\Patterns\ActiveRecord implements \SplSubject
$this->displayTemplate = array( \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' ), 'poll' );
}
$output = call_user_func( $this->displayTemplate, $this, ( $this->url ?: \IPS\Request::i()->url() ) );
$template = $this->displayTemplate;
$output = $template( $this, ( $this->url ?: \IPS\Request::i()->url() ) );
if( \IPS\Request::i()->isAjax() && \IPS\Request::i()->fetchPoll )
{
@@ -546,6 +555,7 @@ class _Poll extends \IPS\Patterns\ActiveRecord implements \SplSubject
{
if ( ! $this->getVote() )
{
\IPS\Session::i()->csrfCheck();
$this->addVote( \IPS\Poll\Vote::fromForm( NULL ) );
return TRUE;
+1 -1
View File
@@ -11,7 +11,7 @@
namespace IPS\Poll;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
+2 -2
View File
@@ -11,7 +11,7 @@
namespace IPS\Poll;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -152,7 +152,7 @@ class _Vote extends \IPS\Patterns\ActiveRecord
{
if ( isset( $choices[ $k ] ) ) // If the question has been deleted since this vote was cast, this won't be set
{
if ( is_array( $v ) )
if ( \is_array( $v ) )
{
foreach ( $v as $key => $memberValues )
{