Skip to content

Commit

Permalink
1.7.0
Browse files Browse the repository at this point in the history
add ip-sperre  issue #4 (#4)
                add option to show "Registered by"
                fix show artwork on non Voted
                fix reset by only change artwork URL
  • Loading branch information
Dennis Reilard committed Aug 7, 2021
1 parent d916a32 commit 345e3ee
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 37 deletions.
31 changes: 25 additions & 6 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class Config extends \Ilch\Config\Install
{
public $config = [
'key' => 'radiohoerercharts',
'version' => '1.6.1',
'version' => '1.7.0',
'icon_small' => 'fa-list-ol',
'author' => 'Reilard, Dennis alias hhunderter ',
'link' => '',
'author' => 'Reilard, Dennis alias hhunderter',
'link' => 'https://github.com/hhunderter/radiohoerercharts',
'official' => false,
'languages' => [
'de_DE' => [
Expand Down Expand Up @@ -163,7 +163,7 @@ public function getUpdate($installedVersion)
$databaseConfig->set('radio_hoerercharts_End_Datetime', '');
$databaseConfig->set('radio_hoerercharts_Program_Name', 'Hörercharts');
$fields = [
'author' => 'Reilard, Dennis alias hhunderter ',
'author' => 'Reilard, Dennis alias hhunderter',
'icon_small' => 'fa-list-ol'
];
$this->db()->update('modules')
Expand Down Expand Up @@ -292,7 +292,7 @@ public function getUpdate($installedVersion)
foreach ($chartsentries as $chartsentriesmodels) {
$hoererchartslistMapper->addEntryToList($chartsentriesmodels->getId(), 1);
}

$databaseConfig = new \Ilch\Config\Database($this->db());
$databaseConfig->set('radio_hoerercharts_show_artwork', '0');
$databaseConfig->set('radio_hoerercharts_active_list', '1');
Expand All @@ -301,7 +301,26 @@ public function getUpdate($installedVersion)
/*
translations update
*/


case "1.6.1":
// update zu 1.7.0
/*
add ip-sperre issue #4 (https://github.com/hhunderter/radiohoerercharts/issues/4)
add option to show "Registered by"
fix show artwork on non Voted
fix reset by only change artwork URL
*/
$this->db()->query('ALTER TABLE `[prefix]_radio_hoerercharts_uservotes` ADD `ip_address` VARCHAR(255) NOT NULL AFTER `session_id`;');
$databaseConfig = new \Ilch\Config\Database($this->db());
$databaseConfig->set('radio_hoerercharts_show_registered_by', '1');
$fields = [
'link' => 'https://github.com/hhunderter/radiohoerercharts'
];
$this->db()->update('modules')
->values($fields)
->where(['key' => 'radiohoerercharts'])
->execute();

}
return 'Update function executed.';
}
Expand Down
6 changes: 4 additions & 2 deletions controllers/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public function indexAction()
$hoererchartsconfig = [ 'guestallow' => $this->getConfig()->get('radio_hoerercharts_Guest_Allow'),
'allowsuggestion' => $this->getConfig()->get('radio_hoerercharts_allow_suggestion'),
'Program_Name' => ($radio_hoerercharts_Program_Name ? $radio_hoerercharts_Program_Name : $this->getTranslator()->trans('hoerercharts')),
'show_artwork' => $this->getConfig()->get('radio_hoerercharts_show_artwork')];
'show_artwork' => $this->getConfig()->get('radio_hoerercharts_show_artwork'),
'show_registered_by' => $this->getConfig()->get('radio_hoerercharts_show_registered_by'),];

$this->getLayout()->getTitle()
->add($hoererchartsconfig['Program_Name']);
Expand Down Expand Up @@ -73,7 +74,7 @@ public function indexAction()
if ($validation->isValid() && !$validation_indb->isValid()) {
$hoererchartsMapper->update($this->getRequest()->getPost('hoerercharts-d'), -1);

$voteId = $hoererchartsuservotesMapper->getEntryByUserSession($this->getUser());
$voteId = $hoererchartsuservotesMapper->getEntryByUserSessionIp($this->getUser());

$date = new \Ilch\Date();
$datenow = new \Ilch\Date($date->format("Y-m-d H:i:s", true));
Expand All @@ -86,6 +87,7 @@ public function indexAction()
$model->setUser_Id($this->getUser()->getId());
}
$model->setSessionId(session_id());
$model->setIp($hoererchartsuservotesMapper->getIp());
$model->setLast_Activity($datenow);
$hoererchartsuservotesMapper->save($model);

Expand Down
7 changes: 5 additions & 2 deletions controllers/admin/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,12 @@ public function treatAction()
$hoererchartsModel->setSetFree($this->getRequest()->getPost('setfree'));
if ($this->getConfig()->get('radio_hoerercharts_show_artwork')) $hoererchartsModel->setArtworkUrl($this->getRequest()->getPost('artworkUrl'));
}
if ($hoererchartsModel->getId() && ($hoererchartsModel->getInterpret() != $this->getRequest()->getPost('interpret') || $hoererchartsModel->getSongTitel() != $this->getRequest()->getPost('songtitel'))) {
$hoererchartsModel->setVotes(0);
}

$hoererchartsModel->setInterpret($this->getRequest()->getPost('interpret'))
->setSongTitel($this->getRequest()->getPost('songtitel'))
->setVotes(0);
->setSongTitel($this->getRequest()->getPost('songtitel'));

if ($this->getRequest()->getParam('suggestion')) {
$hoererchartssuggestionMapper->save($hoererchartsModel);
Expand Down
7 changes: 5 additions & 2 deletions controllers/admin/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function indexAction()
'Star4' => 'required|numeric|min:1',
'Star5' => 'required|numeric|min:1',
'show_artwork' => 'required|numeric|min:0|max:1',
'show_registered_by' => 'required|numeric|min:0|max:1',
]);
} else {
$validation = Validation::create($this->getRequest()->getPost(), [
Expand All @@ -90,7 +91,8 @@ public function indexAction()
->set('radio_hoerercharts_Star3', $this->getRequest()->getPost('Star3'))
->set('radio_hoerercharts_Star4', $this->getRequest()->getPost('Star4'))
->set('radio_hoerercharts_Star5', $this->getRequest()->getPost('Star5'))
->set('radio_hoerercharts_show_artwork', $this->getRequest()->getPost('show_artwork'));
->set('radio_hoerercharts_show_artwork', $this->getRequest()->getPost('show_artwork'))
->set('radio_hoerercharts_show_registered_by', $this->getRequest()->getPost('show_registered_by'));
} else {
$this->getConfig()->set('radio_hoerercharts_votetext_de', $this->getRequest()->getPost('votetext_de'))
->set('radio_hoerercharts_votetext_en', $this->getRequest()->getPost('votetext_en'));
Expand Down Expand Up @@ -119,7 +121,8 @@ public function indexAction()
->set('Star3', $this->getConfig()->get('radio_hoerercharts_Star3'))
->set('Star4', $this->getConfig()->get('radio_hoerercharts_Star4'))
->set('Star5', $this->getConfig()->get('radio_hoerercharts_Star5'))
->set('show_artwork', $this->getConfig()->get('radio_hoerercharts_show_artwork'));
->set('show_artwork', $this->getConfig()->get('radio_hoerercharts_show_artwork'))
->set('show_registered_by', $this->getConfig()->get('radio_hoerercharts_show_registered_by'));
} else {
if ($this->getTranslator()->shortenLocale($this->getTranslator()->getLocale()) == 'de') {
$language = new \Ilch\Translator('en_EN');
Expand Down
79 changes: 56 additions & 23 deletions mappers/HoererChartsUserVotes.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function getEntriesBy($where = [], $orderBy = ['id' => 'DESC'], $paginati
$entryModel->setId($entries['id']);
$entryModel->setUser_Id($entries['user_id']);
$entryModel->setSessionId($entries['session_id']);
$entryModel->setIp($entries['ip_address']);
$entryModel->setLast_Activity($entries['last_activity']);
$entrys[] = $entryModel;
}
Expand Down Expand Up @@ -103,8 +104,8 @@ public function save(EntriesModel $model)
$fields = [
'user_id' => $model->getUser_Id(),
'session_id' => $model->getSessionId(),
'last_activity' => $model->getLast_Activity()
'last_activity' => $model->getLast_Activity(),
'ip_address' => $model->getIp(),
];

if ($model->getId()) {
Expand Down Expand Up @@ -170,7 +171,7 @@ public function delete_user(int $user_id)
->where(['user_id' => $user_id])
->execute();
}

/**
* Delete user vote with specific session_id.
*
Expand All @@ -184,14 +185,51 @@ public function delete_session(string $session_id)
->execute();
}

/**
* Delete user vote with specific ip_address.
*
* @param string|null $ip_address
* @return boolean
*/
public function delete_ip(string $ip_address)
{
if (!$ip_address) {
$ip_address = $this->getIp();
}

return $this->db()->delete('radio_hoerercharts_uservotes')
->where(['ip_address' => $ip_address])
->execute();
}

/**
* get thi ip_address
*
* @return string
*/
public function getIp()
{
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match("/^[0-9a-zA-Z\/.:]{7,}$/", $_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (preg_match("/^[0-9a-zA-Z\/.:]{7,}$/", $_SERVER['REMOTE_ADDR'])) {
$ip_address = $_SERVER['REMOTE_ADDR'];
} else {
$ip_address = '128.0.0.1';
}

return $ip_address;
}

/**
* Gets the entry by given ID.
*
* @param \Modules\User\Models\User $User
* @return integer
*/
public function getEntryByUserSession($User = null)
public function getEntryByUserSessionIp($User = null)
{
$ip = $this->getIp();

$User_Id = 0;
if ($User) {
$User_Id = $User->getId();
Expand All @@ -212,10 +250,17 @@ public function getEntryByUserSession($User = null)
->fetchCell();
if (!$voteId && $User_Id > 0) {
$voteId = (int) $this->db()->select('id')
->from('radio_hoerercharts_uservotes')
->Where(['user_id >' => 0, 'user_id' => $User_Id])
->execute()
->fetchCell();
->from('radio_hoerercharts_uservotes')
->Where(['user_id >' => 0, 'user_id' => $User_Id])
->execute()
->fetchCell();
}
if (!$voteId && $User_Id === 0) {
$voteId = (int) $this->db()->select('id')
->from('radio_hoerercharts_uservotes')
->Where(['ip_address' => $ip])
->execute()
->fetchCell();
}

return $voteId;
Expand All @@ -228,21 +273,9 @@ public function getEntryByUserSession($User = null)
*/
public function setIsVotedCookie(String $sessionid)
{
if (PHP_VERSION_ID >= 70300) {
setcookie('RadioHoererCharts_is_voted', $sessionid, [
'expires' => strtotime('+1 days'),
'path' => '/',
'domain' => $_SERVER['SERVER_NAME'],
'samesite' => 'Lax',
'secure' => (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'),
'httponly' => true,
]);
} else {
// workaround syntax to set the SameSite attribute in PHP < 7.3
setcookie('RadioHoererCharts_is_voted', $sessionid, strtotime('+1 days'), '/; samesite=Lax', $_SERVER['SERVER_NAME'], (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'), true);
}
setcookieIlch('RadioHoererCharts_is_voted', $sessionid, strtotime('+1 days'));
}

/**
* Check if user has already voted or if guests can vote.
*
Expand All @@ -261,7 +294,7 @@ public function is_voted($User = null)
$User_Id = $User->getId();
}

$voteId = $this->getEntryByUserSession($User);
$voteId = $this->getEntryByUserSessionIp($User);

if ($voteId > 0) {
$returnvalue = true;
Expand Down
29 changes: 29 additions & 0 deletions models/HoererChartsUserVotes.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ class HoererChartsUserVotes extends \Ilch\Model
*/
protected $sessionId;

/**
* The Ip.
*
* @var string
*/
protected $ip;

/**
* The last_activity.
*
Expand Down Expand Up @@ -102,6 +109,28 @@ public function setSessionId(String $sessionId)
$this->sessionId = (string) $sessionId;
}

/**
* Gets the ip.
*
* @return string
*/
public function getIp()
{
return $this->ip;
}
/**
* Sets the ip.
*
* @param string $ip
* @return $this
*/
public function setIp(String $ip)
{
$this->ip = (string) $ip;

return $this;
}

/**
* Gets the last_activity.
*
Expand Down
1 change: 1 addition & 0 deletions translations/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
'active' => 'Aktiv',
'active_list' => 'Aktive Liste',
'list' => 'Liste',
'show_registered_by' => '"Eingetragen von" Info aneigen?',
'show_artwork' => 'Cover anzeigen',
'show_artworkText' => '',
'selectactive_list' => '',
Expand Down
1 change: 1 addition & 0 deletions translations/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
'active' => 'Aktive',
'active_list' => 'Aktive List',
'list' => 'List',
'show_registered_by' => 'Show "Registered by" info? ',
'show_artwork' => 'Show Cover',
'show_artworkText' => '',
'selectactive_list' => '',
Expand Down
18 changes: 17 additions & 1 deletion views/admin/settings/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class="form-control"
</div>
</div>
</div>

<h1><?=$this->getTrans('show_artwork') ?></h1>
<div class="form-group <?=$this->validation()->hasError('show_artwork') ? 'has-error' : '' ?>">
<label for="show_artwork" class="col-lg-2 control-label">
Expand All @@ -90,6 +90,22 @@ class="form-control"
</div>
</div>

<h1><?=$this->getTrans('show_registered_by') ?></h1>
<div class="form-group <?=$this->validation()->hasError('show_registered_by') ? 'has-error' : '' ?>">
<label for="show_registered_by" class="col-lg-2 control-label">
<?=$this->getTrans('show_artworkText') ?>:
</label>
<div class="col-lg-4">
<div class="flipswitch">
<input type="radio" class="flipswitch-input" id="show_registered_by-yes" name="show_registered_by" value="1" <?=($this->originalInput('show_registered_by', $this->get('show_registered_by')))?'checked="checked"':'' ?> />
<label for="show_registered_by-yes" class="flipswitch-label flipswitch-label-on"><?=$this->getTrans('on') ?></label>
<input type="radio" class="flipswitch-input" id="show_registered_by-no" name="show_registered_by" value="0" <?=(!$this->originalInput('show_registered_by', $this->get('show_registered_by')))?'checked="checked"':'' ?> />
<label for="show_registered_by-no" class="flipswitch-label flipswitch-label-off"><?=$this->getTrans('off') ?></label>
<span class="flipswitch-selection"></span>
</div>
</div>
</div>

<h1><?=$this->getTrans('showstars') ?></h1>
<div class="form-group <?=$this->validation()->hasError('showstars') ? 'has-error' : '' ?>">
<label for="showstars" class="col-lg-2 control-label">
Expand Down
Loading

0 comments on commit 345e3ee

Please sign in to comment.