refactor: add php_codesniffer to define castopod's coding style based on psr-1

- add .editorconfig file
- format all files to comply with castopod's coding style
- switch parsedown dependency with commonmark library to better follow commonmark spec for markdown
- add prettier command to format all project files at once

closes #16
This commit is contained in:
Yassine Doghri 2020-08-04 11:25:22 +00:00
parent 58364bfed1
commit ed6e953010
153 changed files with 2292 additions and 1854 deletions

View File

@ -9,6 +9,7 @@
"[php]": { "[php]": {
"editor.defaultFormatter": "esbenp.prettier-vscode" "editor.defaultFormatter": "esbenp.prettier-vscode"
}, },
"phpSniffer.autoDetect": true,
"color-highlight.markerType": "dot-before" "color-highlight.markerType": "dot-before"
}, },
"extensions": [ "extensions": [
@ -22,6 +23,7 @@
"bradlc.vscode-tailwindcss", "bradlc.vscode-tailwindcss",
"jamesbirtles.svelte-vscode", "jamesbirtles.svelte-vscode",
"dbaeumer.vscode-eslint", "dbaeumer.vscode-eslint",
"stylelint.vscode-stylelint" "stylelint.vscode-stylelint",
"wongjn.php-sniffer"
] ]
} }

12
.editorconfig Normal file
View File

@ -0,0 +1,12 @@
; top-most EditorConfig file
root = true
; Unix-style newlines
[*]
end_of_line = lf
[*.php]
indent_style = spaces
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

7
.phpcs.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Castopod">
<description>Castopod's coding standard based on the PSR-1 standard.</description>
<!-- Include the whole PSR-1 standard -->
<rule ref="PSR1"/>
</ruleset>

View File

@ -5,8 +5,7 @@
"files": "*.php", "files": "*.php",
"options": { "options": {
"phpVersion": "7.2", "phpVersion": "7.2",
"singleQuote": true, "singleQuote": true
"trailingCommaPHP": true
} }
} }
] ]

View File

@ -10,7 +10,7 @@ PHP Dependencies:
- [GeoIP2 PHP API](https://github.com/maxmind/GeoIP2-php) ([Apache License 2.0](https://github.com/maxmind/GeoIP2-php/blob/master/LICENSE)) - [GeoIP2 PHP API](https://github.com/maxmind/GeoIP2-php) ([Apache License 2.0](https://github.com/maxmind/GeoIP2-php/blob/master/LICENSE))
- [getID3](https://github.com/JamesHeinrich/getID3) ([GNU General Public License v3](https://github.com/JamesHeinrich/getID3/blob/2.0/licenses/license.gpl-30.txt)) - [getID3](https://github.com/JamesHeinrich/getID3) ([GNU General Public License v3](https://github.com/JamesHeinrich/getID3/blob/2.0/licenses/license.gpl-30.txt))
- [myth-auth](https://github.com/lonnieezell/myth-auth) ([MIT license](https://github.com/lonnieezell/myth-auth/blob/develop/LICENSE.md)) - [myth-auth](https://github.com/lonnieezell/myth-auth) ([MIT license](https://github.com/lonnieezell/myth-auth/blob/develop/LICENSE.md))
- [parsedown](https://github.com/erusev/parsedown) ([MIT license](https://github.com/erusev/parsedown/blob/master/LICENSE.txt)) - [commonmark](https://commonmark.thephpleague.com/) ([BSD 3-Clause "New" or "Revised" License](https://github.com/thephpleague/commonmark/blob/latest/LICENSE))
Javascript dependencies: Javascript dependencies:

View File

@ -1,4 +1,6 @@
<?php namespace App\Authorization; <?php
namespace App\Authorization;
class FlatAuthorization extends \Myth\Auth\Authorization\FlatAuthorization class FlatAuthorization extends \Myth\Auth\Authorization\FlatAuthorization
{ {
@ -49,26 +51,26 @@ class FlatAuthorization extends \Myth\Auth\Authorization\FlatAuthorization
/** /**
* Makes a member a part of multiple groups. * Makes a member a part of multiple groups.
* *
* @param $user_id * @param $userId
* @param array|null $groups // Either collection of ID or names * @param array|null $groups // Either collection of ID or names
* *
* @return bool * @return bool
*/ */
public function setUserGroups(int $user_id, $groups) public function setUserGroups(int $userId, $groups)
{ {
if (empty($user_id) || !is_numeric($user_id)) { if (empty($userId) || !is_numeric($userId)) {
return null; return null;
} }
// remove user from all groups before resetting it in new groups // remove user from all groups before resetting it in new groups
$this->groupModel->removeUserFromAllGroups($user_id); $this->groupModel->removeUserFromAllGroups($userId);
if (empty($groups)) { if (empty($groups)) {
return true; return true;
} }
foreach ($groups as $group) { foreach ($groups as $group) {
$this->addUserToGroup($user_id, $group); $this->addUserToGroup($userId, $group);
} }
return true; return true;

View File

@ -1,4 +1,6 @@
<?php namespace App\Authorization; <?php
namespace App\Authorization;
class GroupModel extends \Myth\Auth\Authorization\GroupModel class GroupModel extends \Myth\Auth\Authorization\GroupModel
{ {

View File

@ -1,4 +1,6 @@
<?php namespace App\Authorization; <?php
namespace App\Authorization;
class PermissionModel extends \Myth\Auth\Authorization\PermissionModel class PermissionModel extends \Myth\Auth\Authorization\PermissionModel
{ {

View File

@ -1,4 +1,5 @@
<?php <?php
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| ERROR DISPLAY | ERROR DISPLAY

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
use CodeIgniter\Config\BaseConfig; use CodeIgniter\Config\BaseConfig;

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
/** /**
* Database Configuration * Database Configuration

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
/** /**
* DocTypes * DocTypes

View File

@ -1,4 +1,5 @@
<?php <?php
namespace Config; namespace Config;
use CodeIgniter\Config\BaseConfig; use CodeIgniter\Config\BaseConfig;

View File

@ -1,4 +1,5 @@
<?php <?php
namespace Config; namespace Config;
use CodeIgniter\Config\BaseConfig; use CodeIgniter\Config\BaseConfig;

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
use CodeIgniter\Events\Events; use CodeIgniter\Events\Events;

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
/** /**
* Setup how the exception handler works. * Setup how the exception handler works.

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
use CodeIgniter\Config\BaseConfig; use CodeIgniter\Config\BaseConfig;

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
class ForeignCharacters extends \CodeIgniter\Config\ForeignCharacters class ForeignCharacters extends \CodeIgniter\Config\ForeignCharacters
{ {

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
use CodeIgniter\Config\BaseConfig; use CodeIgniter\Config\BaseConfig;

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
use CodeIgniter\Config\BaseConfig; use CodeIgniter\Config\BaseConfig;

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
use CodeIgniter\Config\BaseConfig; use CodeIgniter\Config\BaseConfig;

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
use CodeIgniter\Config\BaseConfig; use CodeIgniter\Config\BaseConfig;
use Kint\Renderer\Renderer; use Kint\Renderer\Renderer;

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
use CodeIgniter\Config\BaseConfig; use CodeIgniter\Config\BaseConfig;

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
use CodeIgniter\Config\BaseConfig; use CodeIgniter\Config\BaseConfig;

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
/* /*
| ------------------------------------------------------------------- | -------------------------------------------------------------------

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
// Cannot extend BaseConfig or looping resources occurs. // Cannot extend BaseConfig or looping resources occurs.
class Modules class Modules

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
use CodeIgniter\Config\BaseConfig; use CodeIgniter\Config\BaseConfig;

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
/** /**
* Holds the paths that are used by the system to * Holds the paths that are used by the system to

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
use CodeIgniter\Config\Services as CoreServices; use CodeIgniter\Config\Services as CoreServices;
use CodeIgniter\Model; use CodeIgniter\Model;

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
use CodeIgniter\Config\BaseConfig; use CodeIgniter\Config\BaseConfig;

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
use CodeIgniter\Config\BaseConfig; use CodeIgniter\Config\BaseConfig;

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
class Validation class Validation
{ {

View File

@ -1,4 +1,6 @@
<?php namespace Config; <?php
namespace Config;
class View extends \CodeIgniter\Config\View class View extends \CodeIgniter\Config\View
{ {

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -66,7 +67,9 @@ class Contributor extends BaseController
return redirect() return redirect()
->back() ->back()
->withInput() ->withInput()
->with('errors', [lang('Contributor.alreadyAddedError')]); ->with('errors', [
lang('Contributor.messages.alreadyAddedError'),
]);
} }
return redirect()->route('contributor_list', [$this->podcast->id]); return redirect()->route('contributor_list', [$this->podcast->id]);
@ -77,7 +80,7 @@ class Contributor extends BaseController
$data = [ $data = [
'podcast' => $this->podcast, 'podcast' => $this->podcast,
'user' => $this->user, 'user' => $this->user,
'contributor_group_id' => (new PodcastModel())->getContributorGroupId( 'contributorGroupId' => (new PodcastModel())->getContributorGroupId(
$this->user->id, $this->user->id,
$this->podcast->id $this->podcast->id
), ),
@ -104,27 +107,27 @@ class Contributor extends BaseController
return redirect() return redirect()
->back() ->back()
->with('errors', [ ->with('errors', [
lang('Contributor.removeOwnerContributorError'), lang('Contributor.messages.removeOwnerContributorError'),
]); ]);
} }
$podcast_model = new PodcastModel(); $podcastModel = new PodcastModel();
if ( if (
!$podcast_model->removePodcastContributor( !$podcastModel->removePodcastContributor(
$this->user->id, $this->user->id,
$this->podcast->id $this->podcast->id
) )
) { ) {
return redirect() return redirect()
->back() ->back()
->with('errors', $podcast_model->errors()); ->with('errors', $podcastModel->errors());
} }
return redirect() return redirect()
->back() ->back()
->with( ->with(
'message', 'message',
lang('Contributor.removeContributorSuccess', [ lang('Contributor.messages.removeContributorSuccess', [
'username' => $this->user->username, 'username' => $this->user->username,
'podcastTitle' => $this->podcast->title, 'podcastTitle' => $this->podcast->title,
]) ])

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -20,9 +21,8 @@ class Episode extends BaseController
$this->podcast = (new PodcastModel())->find($params[0]); $this->podcast = (new PodcastModel())->find($params[0]);
if (count($params) > 1) { if (count($params) > 1) {
$episode_model = new EpisodeModel();
if ( if (
!($this->episode = $episode_model !($this->episode = (new EpisodeModel())
->where([ ->where([
'id' => $params[1], 'id' => $params[1],
'podcast_id' => $params[0], 'podcast_id' => $params[0],
@ -78,7 +78,7 @@ class Episode extends BaseController
->with('errors', $this->validator->getErrors()); ->with('errors', $this->validator->getErrors());
} }
$new_episode = new \App\Entities\Episode([ $newEpisode = new \App\Entities\Episode([
'podcast_id' => $this->podcast->id, 'podcast_id' => $this->podcast->id,
'title' => $this->request->getPost('title'), 'title' => $this->request->getPost('title'),
'slug' => $this->request->getPost('slug'), 'slug' => $this->request->getPost('slug'),
@ -95,13 +95,13 @@ class Episode extends BaseController
'block' => (bool) $this->request->getPost('block'), 'block' => (bool) $this->request->getPost('block'),
]); ]);
$episode_model = new EpisodeModel(); $episodeModel = new EpisodeModel();
if (!$episode_model->save($new_episode)) { if (!$episodeModel->save($newEpisode)) {
return redirect() return redirect()
->back() ->back()
->withInput() ->withInput()
->with('errors', $episode_model->errors()); ->with('errors', $episodeModel->errors());
} }
return redirect()->route('episode_list', [$this->podcast->id]); return redirect()->route('episode_list', [$this->podcast->id]);
@ -112,7 +112,6 @@ class Episode extends BaseController
helper(['form']); helper(['form']);
$data = [ $data = [
'podcast' => $this->podcast,
'episode' => $this->episode, 'episode' => $this->episode,
]; ];
@ -158,13 +157,13 @@ class Episode extends BaseController
$this->episode->image = $image; $this->episode->image = $image;
} }
$episode_model = new EpisodeModel(); $episodeModel = new EpisodeModel();
if (!$episode_model->save($this->episode)) { if (!$episodeModel->save($this->episode)) {
return redirect() return redirect()
->back() ->back()
->withInput() ->withInput()
->with('errors', $episode_model->errors()); ->with('errors', $episodeModel->errors());
} }
return redirect()->route('episode_list', [$this->podcast->id]); return redirect()->route('episode_list', [$this->podcast->id]);
@ -172,8 +171,7 @@ class Episode extends BaseController
public function delete() public function delete()
{ {
$episode_model = new EpisodeModel(); (new EpisodeModel())->delete($this->episode->id);
$episode_model->delete($this->episode->id);
return redirect()->route('episode_list', [$this->podcast->id]); return redirect()->route('episode_list', [$this->podcast->id]);
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -25,7 +26,7 @@ class Myaccount extends BaseController
public function attemptChange() public function attemptChange()
{ {
$auth = Services::authentication(); $auth = Services::authentication();
$user_model = new UserModel(); $userModel = new UserModel();
// Validate here first, since some things, // Validate here first, since some things,
// like the password, can only be validated properly here. // like the password, can only be validated properly here.
@ -40,7 +41,7 @@ class Myaccount extends BaseController
return redirect() return redirect()
->back() ->back()
->withInput() ->withInput()
->with('errors', $user_model->errors()); ->with('errors', $userModel->errors());
} }
$credentials = [ $credentials = [
@ -52,22 +53,22 @@ class Myaccount extends BaseController
return redirect() return redirect()
->back() ->back()
->withInput() ->withInput()
->with('errors', $user_model->errors()); ->with('errors', $userModel->errors());
} }
user()->password = $this->request->getPost('new_password'); user()->password = $this->request->getPost('new_password');
$user_model->save(user()); $userModel->save(user());
if (!$user_model->save(user())) { if (!$userModel->save(user())) {
return redirect() return redirect()
->back() ->back()
->withInput() ->withInput()
->with('errors', $user_model->errors()); ->with('errors', $userModel->errors());
} }
// Success! // Success!
return redirect() return redirect()
->route('myAccount') ->route('myAccount')
->with('message', lang('MyAccount.passwordChangeSuccess')); ->with('message', lang('MyAccount.messages.passwordChangeSuccess'));
} }
} }

View File

@ -1,9 +1,11 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Controllers\Admin; namespace App\Controllers\Admin;
use App\Models\CategoryModel; use App\Models\CategoryModel;
@ -29,7 +31,7 @@ class Podcast extends BaseController
public function myPodcasts() public function myPodcasts()
{ {
$data = [ $data = [
'all_podcasts' => (new PodcastModel())->getUserPodcasts(user()->id), 'podcasts' => (new PodcastModel())->getUserPodcasts(user()->id),
]; ];
return view('admin/podcast/list', $data); return view('admin/podcast/list', $data);
@ -41,7 +43,7 @@ class Podcast extends BaseController
return redirect()->route('my_podcasts'); return redirect()->route('my_podcasts');
} }
$data = ['all_podcasts' => (new PodcastModel())->findAll()]; $data = ['podcasts' => (new PodcastModel())->findAll()];
return view('admin/podcast/list', $data); return view('admin/podcast/list', $data);
} }
@ -62,7 +64,7 @@ class Podcast extends BaseController
$data = [ $data = [
'languages' => $languageModel->findAll(), 'languages' => $languageModel->findAll(),
'categories' => $categoryModel->findAll(), 'categories' => $categoryModel->findAll(),
'browser_lang' => get_browser_language( 'browserLang' => get_browser_language(
$this->request->getServer('HTTP_ACCEPT_LANGUAGE') $this->request->getServer('HTTP_ACCEPT_LANGUAGE')
), ),
]; ];
@ -106,26 +108,26 @@ class Podcast extends BaseController
'custom_html_head' => $this->request->getPost('custom_html_head'), 'custom_html_head' => $this->request->getPost('custom_html_head'),
]); ]);
$podcast_model = new PodcastModel(); $podcastModel = new PodcastModel();
$db = \Config\Database::connect(); $db = \Config\Database::connect();
$db->transStart(); $db->transStart();
if (!($new_podcast_id = $podcast_model->insert($podcast, true))) { if (!($newPodcastId = $podcastModel->insert($podcast, true))) {
$db->transComplete(); $db->transComplete();
return redirect() return redirect()
->back() ->back()
->withInput() ->withInput()
->with('errors', $podcast_model->errors()); ->with('errors', $podcastModel->errors());
} }
$authorize = Services::authorization(); $authorize = Services::authorization();
$podcast_admin_group = $authorize->group('podcast_admin'); $podcastAdminGroup = $authorize->group('podcast_admin');
$podcast_model->addPodcastContributor( $podcastModel->addPodcastContributor(
user()->id, user()->id,
$new_podcast_id, $newPodcastId,
$podcast_admin_group->id $podcastAdminGroup->id
); );
$db->transComplete(); $db->transComplete();
@ -137,12 +139,10 @@ class Podcast extends BaseController
{ {
helper('form'); helper('form');
$languageModel = new LanguageModel();
$categoryModel = new CategoryModel();
$data = [ $data = [
'podcast' => $this->podcast, 'podcast' => $this->podcast,
'languages' => $languageModel->findAll(), 'languages' => (new LanguageModel())->findAll(),
'categories' => $categoryModel->findAll(), 'categories' => (new CategoryModel())->findAll(),
]; ];
echo view('admin/podcast/edit', $data); echo view('admin/podcast/edit', $data);
@ -188,13 +188,13 @@ class Podcast extends BaseController
'custom_html_head' 'custom_html_head'
); );
$podcast_model = new PodcastModel(); $podcastModel = new PodcastModel();
if (!$podcast_model->save($this->podcast)) { if (!$podcastModel->save($this->podcast)) {
return redirect() return redirect()
->back() ->back()
->withInput() ->withInput()
->with('errors', $podcast_model->errors()); ->with('errors', $podcastModel->errors());
} }
return redirect()->route('podcast_list'); return redirect()->route('podcast_list');
@ -202,8 +202,7 @@ class Podcast extends BaseController
public function delete() public function delete()
{ {
$podcast_model = new PodcastModel(); (new PodcastModel())->delete($this->podcast->id);
$podcast_model->delete($this->podcast->id);
return redirect()->route('podcast_list'); return redirect()->route('podcast_list');
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -18,8 +19,7 @@ class User extends BaseController
public function _remap($method, ...$params) public function _remap($method, ...$params)
{ {
if (count($params) > 0) { if (count($params) > 0) {
$user_model = new UserModel(); if (!($this->user = (new UserModel())->find($params[0]))) {
if (!($this->user = $user_model->find($params[0]))) {
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(); throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
} }
} }
@ -29,7 +29,7 @@ class User extends BaseController
public function list() public function list()
{ {
$data = ['all_users' => (new UserModel())->findAll()]; $data = ['users' => (new UserModel())->findAll()];
return view('admin/user/list', $data); return view('admin/user/list', $data);
} }
@ -45,12 +45,12 @@ class User extends BaseController
public function attemptCreate() public function attemptCreate()
{ {
$user_model = new UserModel(); $userModel = new UserModel();
// Validate here first, since some things, // Validate here first, since some things,
// like the password, can only be validated properly here. // like the password, can only be validated properly here.
$rules = array_merge( $rules = array_merge(
$user_model->getValidationRules(['only' => ['username']]), $userModel->getValidationRules(['only' => ['username']]),
[ [
'email' => 'required|valid_email|is_unique[users.email]', 'email' => 'required|valid_email|is_unique[users.email]',
'password' => 'required|strong_password', 'password' => 'required|strong_password',
@ -74,11 +74,11 @@ class User extends BaseController
// Force user to reset his password on first connection // Force user to reset his password on first connection
$user->forcePasswordReset(); $user->forcePasswordReset();
if (!$user_model->save($user)) { if (!$userModel->save($user)) {
return redirect() return redirect()
->back() ->back()
->withInput() ->withInput()
->with('errors', $user_model->errors()); ->with('errors', $userModel->errors());
} }
// Success! // Success!
@ -86,7 +86,7 @@ class User extends BaseController
->route('user_list') ->route('user_list')
->with( ->with(
'message', 'message',
lang('User.createSuccess', [ lang('User.messages.createSuccess', [
'username' => $user->username, 'username' => $user->username,
]) ])
); );
@ -114,7 +114,7 @@ class User extends BaseController
->route('user_list') ->route('user_list')
->with( ->with(
'message', 'message',
lang('User.rolesEditSuccess', [ lang('User.messages.rolesEditSuccess', [
'username' => $this->user->username, 'username' => $this->user->username,
]) ])
); );
@ -122,13 +122,13 @@ class User extends BaseController
public function forcePassReset() public function forcePassReset()
{ {
$user_model = new UserModel(); $userModel = new UserModel();
$this->user->forcePasswordReset(); $this->user->forcePasswordReset();
if (!$user_model->save($this->user)) { if (!$userModel->save($this->user)) {
return redirect() return redirect()
->back() ->back()
->with('errors', $user_model->errors()); ->with('errors', $userModel->errors());
} }
// Success! // Success!
@ -136,7 +136,7 @@ class User extends BaseController
->route('user_list') ->route('user_list')
->with( ->with(
'message', 'message',
lang('User.forcePassResetSuccess', [ lang('User.messages.forcePassResetSuccess', [
'username' => $this->user->username, 'username' => $this->user->username,
]) ])
); );
@ -149,27 +149,27 @@ class User extends BaseController
return redirect() return redirect()
->back() ->back()
->with('errors', [ ->with('errors', [
lang('User.banSuperAdminError', [ lang('User.messages.banSuperAdminError', [
'username' => $this->user->username, 'username' => $this->user->username,
]), ]),
]); ]);
} }
$user_model = new UserModel(); $userModel = new UserModel();
// TODO: add ban reason? // TODO: add ban reason?
$this->user->ban(''); $this->user->ban('');
if (!$user_model->save($this->user)) { if (!$userModel->save($this->user)) {
return redirect() return redirect()
->back() ->back()
->with('errors', $user_model->errors()); ->with('errors', $userModel->errors());
} }
return redirect() return redirect()
->route('user_list') ->route('user_list')
->with( ->with(
'message', 'message',
lang('User.banSuccess', [ lang('User.messages.banSuccess', [
'username' => $this->user->username, 'username' => $this->user->username,
]) ])
); );
@ -177,20 +177,20 @@ class User extends BaseController
public function unBan() public function unBan()
{ {
$user_model = new UserModel(); $userModel = new UserModel();
$this->user->unBan(); $this->user->unBan();
if (!$user_model->save($this->user)) { if (!$userModel->save($this->user)) {
return redirect() return redirect()
->back() ->back()
->with('errors', $user_model->errors()); ->with('errors', $userModel->errors());
} }
return redirect() return redirect()
->route('user_list') ->route('user_list')
->with( ->with(
'message', 'message',
lang('User.unbanSuccess', [ lang('User.messages.unbanSuccess', [
'username' => $this->user->username, 'username' => $this->user->username,
]) ])
); );
@ -203,20 +203,19 @@ class User extends BaseController
return redirect() return redirect()
->back() ->back()
->with('errors', [ ->with('errors', [
lang('User.deleteSuperAdminError', [ lang('User.messages.deleteSuperAdminError', [
'username' => $this->user->username, 'username' => $this->user->username,
]), ]),
]); ]);
} }
$user_model = new UserModel(); (new UserModel())->delete($this->user->id);
$user_model->delete($this->user->id);
return redirect() return redirect()
->back() ->back()
->with( ->with(
'message', 'message',
lang('User.deleteSuccess', [ lang('User.messages.deleteSuccess', [
'username' => $this->user->username, 'username' => $this->user->username,
]) ])
); );

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class Analytics * Class Analytics
* Creates Analytics controller * Creates Analytics controller
@ -44,9 +45,9 @@ class Analytics extends Controller
} }
// Add one hit to this episode: // Add one hit to this episode:
public function hit($p_podcast_id, $p_episode_id, ...$filename) public function hit($p_podcastId, $p_episodeId, ...$filename)
{ {
podcast_hit($p_podcast_id, $p_episode_id); podcast_hit($p_podcastId, $p_episodeId);
return redirect()->to(media_url(implode('/', $filename))); return redirect()->to(media_url(implode('/', $filename)));
} }
} }

View File

@ -50,8 +50,8 @@ class BaseController extends Controller
set_user_session_referer(); set_user_session_referer();
} }
protected static function triggerWebpageHit($postcast_id) protected static function triggerWebpageHit($podcastId)
{ {
webpage_hit($postcast_id); webpage_hit($podcastId);
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -17,14 +18,13 @@ class Episode extends BaseController
public function _remap($method, ...$params) public function _remap($method, ...$params)
{ {
$podcast_model = new PodcastModel(); $this->podcast = (new PodcastModel())
->where('name', $params[0])
->first();
$this->podcast = $podcast_model->where('name', $params[0])->first();
if (count($params) > 1) {
$episode_model = new EpisodeModel();
if ( if (
!($this->episode = $episode_model count($params) > 1 &&
!($this->episode = (new EpisodeModel())
->where([ ->where([
'podcast_id' => $this->podcast->id, 'podcast_id' => $this->podcast->id,
'slug' => $params[1], 'slug' => $params[1],
@ -33,7 +33,6 @@ class Episode extends BaseController
) { ) {
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(); throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
} }
}
return $this->$method(); return $this->$method();
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,16 +13,15 @@ use CodeIgniter\Controller;
class Feed extends Controller class Feed extends Controller
{ {
public function index($podcast_name) public function index($podcastName)
{ {
helper('rss');
$podcast_model = new PodcastModel();
$podcast = $podcast_model->where('name', $podcast_name)->first();
// The page cache is set to a decade so it is deleted manually upon podcast update // The page cache is set to a decade so it is deleted manually upon podcast update
$this->cachePage(DECADE); $this->cachePage(DECADE);
helper('rss');
$podcast = (new PodcastModel())->where('name', $podcastName)->first();
return $this->response->setXML(get_rss_feed($podcast)); return $this->response->setXML(get_rss_feed($podcast));
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -15,15 +16,15 @@ class Home extends BaseController
{ {
$model = new PodcastModel(); $model = new PodcastModel();
$all_podcasts = $model->findAll(); $allPodcasts = $model->findAll();
// check if there's only one podcast to redirect user to it // check if there's only one podcast to redirect user to it
if (count($all_podcasts) == 1) { if (count($allPodcasts) == 1) {
return redirect()->route('podcast', [$all_podcasts[0]->name]); return redirect()->route('podcast', [$allPodcasts[0]->name]);
} }
// default behavior: list all podcasts on home page // default behavior: list all podcasts on home page
$data = ['podcasts' => $all_podcasts]; $data = ['podcasts' => $allPodcasts];
return view('home', $data); return view('home', $data);
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3

View File

@ -1,9 +1,11 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Controllers; namespace App\Controllers;
use App\Models\PodcastModel; use App\Models\PodcastModel;
@ -15,9 +17,8 @@ class Podcast extends BaseController
public function _remap($method, ...$params) public function _remap($method, ...$params)
{ {
if (count($params) > 0) { if (count($params) > 0) {
$podcast_model = new PodcastModel();
if ( if (
!($this->podcast = $podcast_model !($this->podcast = (new PodcastModel())
->where('name', $params[0]) ->where('name', $params[0])
->first()) ->first())
) { ) {

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -6,14 +7,15 @@
*/ */
namespace App\Controllers; namespace App\Controllers;
use CodeIgniter\Controller; use CodeIgniter\Controller;
class UnknownUserAgents extends Controller class UnknownUserAgents extends Controller
{ {
public function index($last_known_id = 0) public function index($lastKnownId = 0)
{ {
$model = new \App\Models\UnknownUserAgentsModel(); $model = new \App\Models\UnknownUserAgentsModel();
return $this->response->setJSON($model->getUserAgents($last_known_id)); return $this->response->setJSON($model->getUserAgents($lastKnownId));
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AddCategories * Class AddCategories
* Creates categories table in database * Creates categories table in database

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AddLanguages * Class AddLanguages
* Creates languages table in database * Creates languages table in database

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AddPodcasts * Class AddPodcasts
* Creates podcasts table in database * Creates podcasts table in database

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AddEpisodes * Class AddEpisodes
* Creates episodes table in database * Creates episodes table in database

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AddPlatforms * Class AddPlatforms
* Creates platforms table in database * Creates platforms table in database

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AddPlatformsLinks * Class AddPlatformsLinks
* Creates platform_links table in database * Creates platform_links table in database

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AddAnalyticsEpisodesByCountry * Class AddAnalyticsEpisodesByCountry
* Creates analytics_episodes_by_country table in database * Creates analytics_episodes_by_country table in database
@ -6,6 +7,7 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Database\Migrations; namespace App\Database\Migrations;
use CodeIgniter\Database\Migration; use CodeIgniter\Database\Migration;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AddAnalyticsEpisodesByPlayer * Class AddAnalyticsEpisodesByPlayer
* Creates analytics_episodes_by_player table in database * Creates analytics_episodes_by_player table in database
@ -6,6 +7,7 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Database\Migrations; namespace App\Database\Migrations;
use CodeIgniter\Database\Migration; use CodeIgniter\Database\Migration;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AddAnalyticsPodcastsByCountry * Class AddAnalyticsPodcastsByCountry
* Creates analytics_podcasts_by_country table in database * Creates analytics_podcasts_by_country table in database
@ -6,6 +7,7 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Database\Migrations; namespace App\Database\Migrations;
use CodeIgniter\Database\Migration; use CodeIgniter\Database\Migration;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AddAnalyticsPodcastsByPlayer * Class AddAnalyticsPodcastsByPlayer
* Creates analytics_podcasts_by_player table in database * Creates analytics_podcasts_by_player table in database
@ -6,6 +7,7 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Database\Migrations; namespace App\Database\Migrations;
use CodeIgniter\Database\Migration; use CodeIgniter\Database\Migration;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AddAnalyticsUnknownUseragents * Class AddAnalyticsUnknownUseragents
* Creates analytics_unknown_useragents table in database * Creates analytics_unknown_useragents table in database
@ -6,6 +7,7 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Database\Migrations; namespace App\Database\Migrations;
use CodeIgniter\Database\Migration; use CodeIgniter\Database\Migration;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AddAnalyticsWebsiteByBrowser * Class AddAnalyticsWebsiteByBrowser
* Creates analytics_website_by_browser table in database * Creates analytics_website_by_browser table in database
@ -6,6 +7,7 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Database\Migrations; namespace App\Database\Migrations;
use CodeIgniter\Database\Migration; use CodeIgniter\Database\Migration;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AddAnalyticsWebsiteByCountry * Class AddAnalyticsWebsiteByCountry
* Creates analytics_website_by_country table in database * Creates analytics_website_by_country table in database
@ -6,6 +7,7 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Database\Migrations; namespace App\Database\Migrations;
use CodeIgniter\Database\Migration; use CodeIgniter\Database\Migration;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AddAnalyticsWebsiteByReferer * Class AddAnalyticsWebsiteByReferer
* Creates analytics_website_by_referer table in database * Creates analytics_website_by_referer table in database
@ -6,6 +7,7 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Database\Migrations; namespace App\Database\Migrations;
use CodeIgniter\Database\Migration; use CodeIgniter\Database\Migration;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AddAnalyticsPodcastsStoredProcedure * Class AddAnalyticsPodcastsStoredProcedure
* Creates analytics_podcasts stored procedure in database * Creates analytics_podcasts stored procedure in database
@ -6,6 +7,7 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Database\Migrations; namespace App\Database\Migrations;
use CodeIgniter\Database\Migration; use CodeIgniter\Database\Migration;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AddAnalyticsUnknownUseragentsStoredProcedure * Class AddAnalyticsUnknownUseragentsStoredProcedure
* Creates analytics_unknown_useragents stored procedure in database * Creates analytics_unknown_useragents stored procedure in database
@ -6,6 +7,7 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Database\Migrations; namespace App\Database\Migrations;
use CodeIgniter\Database\Migration; use CodeIgniter\Database\Migration;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AddAnalyticsWebsiteStoredProcedure * Class AddAnalyticsWebsiteStoredProcedure
* Creates analytics_website stored procedure in database * Creates analytics_website stored procedure in database
@ -6,6 +7,7 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Database\Migrations; namespace App\Database\Migrations;
use CodeIgniter\Database\Migration; use CodeIgniter\Database\Migration;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AddLanguages * Class AddLanguages
* Creates languages table in database * Creates languages table in database

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class PermissionSeeder * Class PermissionSeeder
* Inserts permissions * Inserts permissions
@ -224,9 +225,9 @@ class AuthSeeder extends Seeder
], ],
]; ];
static function getGroupIdByName($name, $data_groups) static function getGroupIdByName($name, $dataGroups)
{ {
foreach ($data_groups as $group) { foreach ($dataGroups as $group) {
if ($group['name'] === $name) { if ($group['name'] === $name) {
return $group['id']; return $group['id'];
} }
@ -236,45 +237,45 @@ class AuthSeeder extends Seeder
public function run() public function run()
{ {
$group_id = 0; $groupId = 0;
$data_groups = []; $dataGroups = [];
foreach ($this->groups as $group) { foreach ($this->groups as $group) {
array_push($data_groups, [ array_push($dataGroups, [
'id' => ++$group_id, 'id' => ++$groupId,
'name' => $group['name'], 'name' => $group['name'],
'description' => $group['description'], 'description' => $group['description'],
]); ]);
} }
// Map permissions to a format the `auth_permissions` table expects // Map permissions to a format the `auth_permissions` table expects
$data_permissions = []; $dataPermissions = [];
$data_groups_permissions = []; $dataGroupsPermissions = [];
$permission_id = 0; $permissionId = 0;
foreach ($this->permissions as $context => $actions) { foreach ($this->permissions as $context => $actions) {
foreach ($actions as $action) { foreach ($actions as $action) {
array_push($data_permissions, [ array_push($dataPermissions, [
'id' => ++$permission_id, 'id' => ++$permissionId,
'name' => $context . '-' . $action['name'], 'name' => $context . '-' . $action['name'],
'description' => $action['description'], 'description' => $action['description'],
]); ]);
foreach ($action['has_permission'] as $role) { foreach ($action['has_permission'] as $role) {
// link permission to specified groups // link permission to specified groups
array_push($data_groups_permissions, [ array_push($dataGroupsPermissions, [
'group_id' => $this->getGroupIdByName( 'group_id' => $this->getGroupIdByName(
$role, $role,
$data_groups $dataGroups
), ),
'permission_id' => $permission_id, 'permission_id' => $permissionId,
]); ]);
} }
} }
} }
$this->db->table('auth_permissions')->insertBatch($data_permissions); $this->db->table('auth_permissions')->insertBatch($dataPermissions);
$this->db->table('auth_groups')->insertBatch($data_groups); $this->db->table('auth_groups')->insertBatch($dataGroups);
$this->db $this->db
->table('auth_groups_permissions') ->table('auth_groups_permissions')
->insertBatch($data_groups_permissions); ->insertBatch($dataGroupsPermissions);
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class CategorySeeder * Class CategorySeeder
* Inserts values in categories table in database * Inserts values in categories table in database

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class LanguageSeeder * Class LanguageSeeder
* Inserts values in languages table in database * Inserts values in languages table in database

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class PlatformsSeeder * Class PlatformsSeeder
* Inserts values in platforms table in database * Inserts values in platforms table in database

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class TestSeeder * Class TestSeeder
* Inserts a superadmin user in the database * Inserts a superadmin user in the database
@ -23,7 +24,7 @@ class TestSeeder extends Seeder
$this->db->table('users')->insert([ $this->db->table('users')->insert([
'id' => 1, 'id' => 1,
'username' => 'admin', 'username' => 'admin',
'email' => 'admin@castopod.com', 'email' => 'admin@example.com',
'password_hash' => 'password_hash' =>
'$2y$10$TXJEHX/djW8jtzgpDVf7dOOCGo5rv1uqtAYWdwwwkttQcDkAeB2.6', '$2y$10$TXJEHX/djW8jtzgpDVf7dOOCGo5rv1uqtAYWdwwwkttQcDkAeB2.6',
'active' => 1, 'active' => 1,

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AnalyticsEpisodesByCountry * Class AnalyticsEpisodesByCountry
* Entity for AnalyticsEpisodesByCountry * Entity for AnalyticsEpisodesByCountry
@ -6,6 +7,7 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Entities; namespace App\Entities;
use CodeIgniter\Entity; use CodeIgniter\Entity;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AnalyticsEpisodesByPlayer * Class AnalyticsEpisodesByPlayer
* Entity for AnalyticsEpisodesByPlayer * Entity for AnalyticsEpisodesByPlayer
@ -6,6 +7,7 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Entities; namespace App\Entities;
use CodeIgniter\Entity; use CodeIgniter\Entity;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AnalyticsPodcastsByCountry * Class AnalyticsPodcastsByCountry
* Entity for AnalyticsPodcastsByCountry * Entity for AnalyticsPodcastsByCountry
@ -6,6 +7,7 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Entities; namespace App\Entities;
use CodeIgniter\Entity; use CodeIgniter\Entity;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AnalyticsPodcastsByPlayer * Class AnalyticsPodcastsByPlayer
* Entity for AnalyticsPodcastsByPlayer * Entity for AnalyticsPodcastsByPlayer
@ -6,6 +7,7 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Entities; namespace App\Entities;
use CodeIgniter\Entity; use CodeIgniter\Entity;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AnalyticsUnknownUseragents * Class AnalyticsUnknownUseragents
* Entity for AnalyticsUnknownUseragents * Entity for AnalyticsUnknownUseragents
@ -6,6 +7,7 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Entities; namespace App\Entities;
use CodeIgniter\Entity; use CodeIgniter\Entity;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AnalyticsWebsiteByBrowser * Class AnalyticsWebsiteByBrowser
* Entity for AnalyticsWebsiteByBrowser * Entity for AnalyticsWebsiteByBrowser
@ -6,6 +7,7 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Entities; namespace App\Entities;
use CodeIgniter\Entity; use CodeIgniter\Entity;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class AnalyticsWebsiteByCountry * Class AnalyticsWebsiteByCountry
* Entity for AnalyticsWebsiteByCountry * Entity for AnalyticsWebsiteByCountry
@ -6,6 +7,7 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Entities; namespace App\Entities;
use CodeIgniter\Entity; use CodeIgniter\Entity;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class class AnalyticsWebsiteByReferer * Class class AnalyticsWebsiteByReferer
* Entity for AnalyticsWebsiteByReferer * Entity for AnalyticsWebsiteByReferer
@ -6,6 +7,7 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
namespace App\Entities; namespace App\Entities;
use CodeIgniter\Entity; use CodeIgniter\Entity;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -23,11 +24,10 @@ class Category extends Entity
public function getParent() public function getParent()
{ {
$category_model = new CategoryModel(); $parentId = $this->attributes['parent_id'];
$parent_id = $this->attributes['parent_id'];
return $parent_id != 0 return $parentId != 0
? $category_model->find($this->attributes['parent_id']) ? (new CategoryModel())->findParent($parentId)
: null; : null;
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -9,7 +10,7 @@ namespace App\Entities;
use App\Models\PodcastModel; use App\Models\PodcastModel;
use CodeIgniter\Entity; use CodeIgniter\Entity;
use Parsedown; use League\CommonMark\CommonMarkConverter;
class Episode extends Entity class Episode extends Entity
{ {
@ -43,7 +44,7 @@ class Episode extends Entity
public function setImage(?\CodeIgniter\HTTP\Files\UploadedFile $image) public function setImage(?\CodeIgniter\HTTP\Files\UploadedFile $image)
{ {
if ($image->isValid()) { if (!empty($image) && $image->isValid()) {
// check whether the user has inputted an image and store it // check whether the user has inputted an image and store it
$this->attributes['image_uri'] = save_podcast_media( $this->attributes['image_uri'] = save_podcast_media(
$image, $image,
@ -68,17 +69,17 @@ class Episode extends Entity
return $this; return $this;
} }
public function getImage() public function getImage(): \CodeIgniter\Files\File
{ {
return new \CodeIgniter\Files\File($this->getImageMediaPath()); return new \CodeIgniter\Files\File($this->getImageMediaPath());
} }
public function getImageMediaPath() public function getImageMediaPath(): string
{ {
return media_path($this->attributes['image_uri']); return media_path($this->attributes['image_uri']);
} }
public function getImageUrl() public function getImageUrl(): string
{ {
if ($image_uri = $this->attributes['image_uri']) { if ($image_uri = $this->attributes['image_uri']) {
return media_url($image_uri); return media_url($image_uri);
@ -89,7 +90,7 @@ class Episode extends Entity
public function setEnclosure( public function setEnclosure(
\CodeIgniter\HTTP\Files\UploadedFile $enclosure = null \CodeIgniter\HTTP\Files\UploadedFile $enclosure = null
) { ) {
if ($enclosure->isValid()) { if (!empty($enclosure) && $enclosure->isValid()) {
helper('media'); helper('media');
$this->attributes['enclosure_uri'] = save_podcast_media( $this->attributes['enclosure_uri'] = save_podcast_media(
@ -151,26 +152,25 @@ class Episode extends Entity
public function getPodcast() public function getPodcast()
{ {
$podcast_model = new PodcastModel(); return (new PodcastModel())->find($this->attributes['podcast_id']);
return $podcast_model->find($this->attributes['podcast_id']);
} }
public function getDescriptionHtml() public function getDescriptionHtml()
{ {
$converter = new Parsedown(); $converter = new CommonMarkConverter([
$converter->setBreaksEnabled(true); 'html_input' => 'strip',
'allow_unsafe_links' => false,
]);
if ( if (
$description_footer = $this->getPodcast() $descriptionFooter = $this->getPodcast()->episode_description_footer
->episode_description_footer
) { ) {
return $converter->text($this->attributes['description']) . return $converter->convertToHtml($this->attributes['description']) .
'<footer>' . '<footer>' .
$converter->text($description_footer) . $converter->convertToHtml($descriptionFooter) .
'</footer>'; '</footer>';
} }
return $converter->text($this->attributes['description']); return $converter->convertToHtml($this->attributes['description']);
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -10,7 +11,7 @@ namespace App\Entities;
use App\Models\EpisodeModel; use App\Models\EpisodeModel;
use CodeIgniter\Entity; use CodeIgniter\Entity;
use App\Models\UserModel; use App\Models\UserModel;
use Parsedown; use League\CommonMark\CommonMarkConverter;
class Podcast extends Entity class Podcast extends Entity
{ {
@ -158,9 +159,11 @@ class Podcast extends Entity
public function getDescriptionHtml() public function getDescriptionHtml()
{ {
$converter = new Parsedown(); $converter = new CommonMarkConverter([
$converter->setBreaksEnabled(true); 'html_input' => 'strip',
'allow_unsafe_links' => false,
]);
return $converter->text($this->attributes['description']); return $converter->convertToHtml($this->attributes['description']);
} }
} }

View File

@ -1,4 +1,6 @@
<?php namespace App\Entities; <?php
namespace App\Entities;
use App\Models\PodcastModel; use App\Models\PodcastModel;

View File

@ -1,4 +1,6 @@
<?php namespace App\Filters; <?php
namespace App\Filters;
use App\Models\PodcastModel; use App\Models\PodcastModel;
use Config\Services; use Config\Services;
@ -57,14 +59,12 @@ class Permission implements FilterInterface
count($routerParams) > 0 count($routerParams) > 0
) { ) {
if ( if (
$group_id = (new PodcastModel())->getContributorGroupId( $groupId = (new PodcastModel())->getContributorGroupId(
$authenticate->id(), $authenticate->id(),
$routerParams[0] $routerParams[0]
) )
) { ) {
if ( if ($authorize->groupHasPermission($permission, $groupId)) {
$authorize->groupHasPermission($permission, $group_id)
) {
$result = true; $result = true;
break; break;
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -187,4 +187,3 @@ function podcast_hit($p_podcast_id, $p_episode_id)
} }
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3

View File

@ -1,10 +1,12 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
use App\Libraries\SimpleRSSElement;
use App\Models\CategoryModel; use App\Models\CategoryModel;
use CodeIgniter\I18n\Time; use CodeIgniter\I18n\Time;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3

View File

@ -1,11 +1,12 @@
<? <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
return [ return [
'dashboard' => 'Dashboard', 'dashboard' => 'Dashboard',
'podcasts' => 'Podcasts', 'podcasts' => 'Podcasts',
'users' => 'Users', 'users' => 'Users',
@ -15,5 +16,5 @@
'podcast_create' => 'New podcast', 'podcast_create' => 'New podcast',
'user_list' => 'All users', 'user_list' => 'All users',
'user_create' => 'New user', 'user_create' => 'New user',
'go_to_website' => 'Go to website' 'go_to_website' => 'Go to website',
]; ];

View File

@ -1,4 +1,5 @@
<? <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -6,9 +7,6 @@
*/ */
return [ return [
'removeOwnerContributorError' => 'You can\'t remove the podcast owner!',
'removeContributorSuccess' => 'You have successfully removed {username} from {podcastTitle}',
'alreadyAddedError' => 'The contributor you\'re trying to add has already been added!',
'podcast_contributors' => 'Podcast contributors', 'podcast_contributors' => 'Podcast contributors',
'add' => 'Add contributor', 'add' => 'Add contributor',
'add_contributor' => 'Add a contributor for {0}', 'add_contributor' => 'Add a contributor for {0}',
@ -19,6 +17,13 @@ return [
'user' => 'User', 'user' => 'User',
'role' => 'Role', 'role' => 'Role',
'submit_add' => 'Add contributor', 'submit_add' => 'Add contributor',
'submit_edit' => 'Update role' 'submit_edit' => 'Update role',
] ],
'messages' => [
'removeOwnerContributorError' => 'You can\'t remove the podcast owner!',
'removeContributorSuccess' =>
'You have successfully removed {username} from {podcastTitle}',
'alreadyAddedError' =>
'The contributor you\'re trying to add has already been added!',
],
]; ];

View File

@ -1,4 +1,5 @@
<? <?php
/** /**
* ISO 3166 country codes * ISO 3166 country codes
* @copyright 2020 Podlibre * @copyright 2020 Podlibre

View File

@ -1,4 +1,5 @@
<? <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -10,7 +11,7 @@ return [
'back_to_podcast' => 'Go back to podcast', 'back_to_podcast' => 'Go back to podcast',
'edit' => 'Edit', 'edit' => 'Edit',
'delete' => 'Delete', 'delete' => 'Delete',
'goto_page' => 'Go to page', 'go_to_page' => 'Go to page',
'create' => 'Add an episode', 'create' => 'Add an episode',
'form' => [ 'form' => [
'file' => 'Audio file', 'file' => 'Audio file',
@ -33,5 +34,5 @@ return [
'block' => 'Block', 'block' => 'Block',
'submit_create' => 'Create episode', 'submit_create' => 'Create episode',
'submit_edit' => 'Save episode', 'submit_edit' => 'Save episode',
] ],
]; ];

View File

@ -1,4 +1,5 @@
<? <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3

View File

@ -1,4 +1,5 @@
<? <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -6,7 +7,9 @@
*/ */
return [ return [
'info' => 'My account info',
'messages' => [
'passwordChangeSuccess' => 'Password has been successfully changed!', 'passwordChangeSuccess' => 'Password has been successfully changed!',
'changePassword' => 'Change my password', 'changePassword' => 'Change my password',
'info' => 'My account info' ],
]; ];

View File

@ -1,4 +1,5 @@
<? <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -16,7 +17,7 @@ return [
'delete' => 'Delete podcast', 'delete' => 'Delete podcast',
'see_episodes' => 'See episodes', 'see_episodes' => 'See episodes',
'see_contributors' => 'See contributors', 'see_contributors' => 'See contributors',
'goto_page' => 'Go to page', 'go_to_page' => 'Go to page',
'form' => [ 'form' => [
'title' => 'Title', 'title' => 'Title',
'name' => 'Name', 'name' => 'Name',
@ -156,5 +157,5 @@ return [
'tv_reviews' => 'TV Reviews', 'tv_reviews' => 'TV Reviews',
], ],
'list_of_episodes' => 'List of episodes', 'list_of_episodes' => 'List of episodes',
'no_episode' => 'No episode found' 'no_episode' => 'No episode found',
]; ];

View File

@ -1,4 +1,5 @@
<? <?php
/** /**
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -6,14 +7,6 @@
*/ */
return [ return [
'createSuccess' => 'User created successfully! {username} will be prompted with a password reset upon first authentication.',
'rolesEditSuccess' => '{username}\'s roles have been successfully updated.',
'forcePassResetSuccess' => '{username} will be prompted with a password reset upon next visit.',
'banSuccess' => '{username} has been banned.',
'unbanSuccess' => '{username} has been unbanned.',
'banSuperAdminError' => '{username} is a superadmin, one does not simply ban a superadmin…',
'deleteSuperAdminError' => '{username} is a superadmin, one does not simply delete a superadmin…',
'deleteSuccess' => '{username} has been deleted.',
'edit_roles' => 'Edit {username}\'s roles', 'edit_roles' => 'Edit {username}\'s roles',
'forcePassReset' => 'Force pass reset', 'forcePassReset' => 'Force pass reset',
'ban' => 'Ban', 'ban' => 'Ban',
@ -31,5 +24,20 @@ return [
'roles' => 'Roles', 'roles' => 'Roles',
'submit_create' => 'Create user', 'submit_create' => 'Create user',
'submit_edit' => 'Save', 'submit_edit' => 'Save',
] ],
'messages' => [
'createSuccess' =>
'User created successfully! {username} will be prompted with a password reset upon first authentication.',
'rolesEditSuccess' =>
'{username}\'s roles have been successfully updated.',
'forcePassResetSuccess' =>
'{username} will be prompted with a password reset upon next visit.',
'banSuccess' => '{username} has been banned.',
'unbanSuccess' => '{username} has been unbanned.',
'banSuperAdminError' =>
'{username} is a superadmin, one does not simply ban a superadmin…',
'deleteSuperAdminError' =>
'{username} is a superadmin, one does not simply delete a superadmin…',
'deleteSuccess' => '{username} has been deleted.',
],
]; ];

View File

@ -1,4 +1,5 @@
<? <?php
/** /**
* ISO 3166 country codes * ISO 3166 country codes
* @copyright 2020 Podlibre * @copyright 2020 Podlibre
@ -6,7 +7,8 @@
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
return ['AF ' => 'Afghanistan', return [
'AF ' => 'Afghanistan',
'ZA ' => 'Afrique Du Sud', 'ZA ' => 'Afrique Du Sud',
'AX ' => 'Åland, Îles', 'AX ' => 'Åland, Îles',
'AL ' => 'Albanie', 'AL ' => 'Albanie',

Some files were not shown because too many files have changed in this diff Show More