Here's the code of the item I created, basically it'll add views to a thread defined by the user. Maybe the possibility to define how many views to increase, instead of a static number (see number 100 at the very end of the simple php script), in order to create different items for different amount of views.
It comes very handy if some nodes are sorted by views, making it challenging for users to use the Views increaser item as much as possible in order to push their thread (or a thread they like) at the top.
Hope you'll consider it for next update, as I'd like to keep using your official code, instead of having to make manual edits every time, thank you
Let me know what you think
Hope it helps.
It comes very handy if some nodes are sorted by views, making it challenging for users to use the Views increaser item as much as possible in order to push their thread (or a thread they like) at the top.
Hope you'll consider it for next update, as I'd like to keep using your official code, instead of having to make manual edits every time, thank you

Code:
<?php
namespace DBTech\Shop\ItemType;
/**
* Class Views
*
* @package DBTech\Shop\ItemType
*/
class HackViews extends AbstractHandler implements ConfigurableInterface
{
protected $defaultUserConfig = [
'contentid' => 0,
];
/**
* @param $context
*
* @return array
*/
protected function getDefaultTemplateParams($context)
{
$params = parent::getDefaultTemplateParams($context);
switch ($context)
{
case 'user_config_view':
$params['thread'] = $this->em()->find('XF:Thread', $this->purchase->configuration['contentid']);
break;
}
return $params;
}
/**
* @return string
*/
public function getAdminConfigTemplate()
{
return '';
}
/**
* @param array $input
*
* @return array
*/
public function filterUserConfig(array $input = [])
{
return $this->app()->inputFilterer()->filterArray($input, [
'contentid' => 'str',
]);
}
/**
* @param array $configuration
* @param null $errors
*
* @return bool
*/
public function validateUserConfig(array &$configuration = [], &$errors = null)
{
if (empty($configuration['contentid']))
{
$errors = \XF::phraseDeferred('please_complete_required_fields');
return false;
}
if (is_numeric($configuration['contentid']))
{
$thread = $this->em()->find('XF:Thread', $configuration['contentid']);
if (!$thread)
{
$errors = \XF::phraseDeferred('no_thread_could_be_found_with_id_x', ['thread_id' => $configuration['contentid']]);
return false;
}
}
else
{
$threadRepo = $this->app()->repository('XF:Thread');
$thread = $threadRepo->getThreadFromUrl($configuration['contentid'], null, $errors);
if (!$thread)
{
return false;
}
$configuration['contentid'] = $thread->thread_id;
}
return true;
}
/**
* @return string
*/
public function getConfigurationForConversation()
{
/** @var \XF\Entity\Thread $thread */
$thread = $this->em()->find('XF:Thread', $this->purchase->configuration['contentid']);
if (!$thread)
{
return '';
}
return \XF::phrase('dbtech_shop_configuration_notice_increase_views', [
'thread_url' => $this->app()->router('public')->buildLink('full:threads', $thread),
'thread' => new \XF\PreEscaped($thread->title)
]);
}
/**
* @param bool $wasConfigured
*
* @throws \XF\PrintableException
*/
protected function afterConfiguration($wasConfigured = false)
{
/** @var \XF\Entity\Thread $thread */
$thread = $this->em()->find('XF:Thread', $this->purchase->configuration['contentid']);
if (!$thread)
{
return;
}
$thread->view_count += 100; // turning 100 into a variable would make sense I guess
$thread->->save();
}
}
Let me know what you think

Hope it helps.
Upvote
0