Skip to content

Commit

Permalink
basic add and del files in pages
Browse files Browse the repository at this point in the history
  • Loading branch information
nekocari committed Oct 13, 2024
1 parent 9ba85e9 commit 69ba7db
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 11 deletions.
63 changes: 63 additions & 0 deletions app/controllers/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ public function pagesIndex() {
$this->auth()->setRequirements('roles', ['Admin']);
//$this->auth()->setRequirements('rights', ['EditPages']);
$this->redirectNotAuthorized();

if(isset($_POST['add_page'])){
$this->pagesAdd();
}
if(isset($_POST['del_page'])){
$this->pagesDelete();
}

$pages = array();
foreach(SUPPORTED_LANGUAGES as $lang_key => $lang_name){
Expand Down Expand Up @@ -278,6 +285,62 @@ public function pagesEdit() {

$this->layout()->render('admin/pages/edit.php',['file'=>$file]);
}

private function pagesAdd() {
try{
if(empty($_POST['filename']) or !isset($_POST['lang'])){
$this->layout()->addSystemMessage('error', 'folder_not_found');
return false;
}

// check if filename is valid
if(!preg_match('/^[\w\.]+$/', $_POST['filename'])){
$this->layout()->addSystemMessage('error', 'input_invalid_character');
return false;
}

$new_file_folder = str_replace('[lang]', strtolower($_POST['lang']), DEFAULT_FOLDER_PAGES);
// add slash if missing
if(substr($new_file_folder, strlen($new_file_folder)-1,1) != '/'){
$new_file_folder = $new_file_folder."/";
}
$new_file_path = $new_file_folder.strtolower($_POST['filename']).".php";

// check if folder exists
if(!is_dir(substr($new_file_folder,0,-1))){
$this->layout()->addSystemMessage('error', 'folder_not_found');
return false;
}

if(file_exists($new_file_path)){
$this->layout()->addSystemMessage('error', 'file_exists');
return false;
}

$file = fopen($new_file_path, 'w');
fclose($file);

$this->layout()->addSystemMessage('success', 'file_created');
return true;
}
catch (Exception $e){
error_log($e->getMessage().PHP_EOL,3,ERROR_LOG);
return false;
}
}

private function pagesDelete() {
try{
$file_path = $_POST['del_page'];
if(file_exists($file_path) and unlink($file_path)){
$this->layout()->addSystemMessage('success', 'file_deleted');
}
}
catch (Exception $e){
error_log($e->getMessage().PHP_EOL,3,ERROR_LOG);
return false;
}
}


/**
Expand Down
31 changes: 31 additions & 0 deletions app/views/de/admin/pages/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@

<?php echo $this->renderMessage('info','Selbst erstellte Seiten haben <b>keine Route</b>! Weitere Infos im <a target="_blank" href="https://github.com/nekocari/miniTCG/wiki/Add-a-new-page">Wiki auf GitHub</a>.'); ?>

<form method="post" action="">
<div class="row">
<div class="col-12 col-md">
<div class="input-group">
<div class="input-group-text">neue Seite:</div>
<input class="form-control" type="text" name="filename" value="" placeholder="dateiname" pattern="[a-z0-9_\-]+">
<div class="input-group-text">.php</div>
</div>
</div>
<div class="col-12 col-md">
<div class="input-group">
<div class="input-group-text">Sprache:</div>
<select class="form-select" name="lang">
<?php foreach(SUPPORTED_LANGUAGES as $key => $lang){ ?>
<option value="<?php echo $key; ?>"><?php echo $lang; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-12 col-md">
<button class="btn btn-primary" type="submit" name="add_page" value="1">anlegen</button>
</div>
</div>
</form>

<div class="table-responsive">

<table class="table table-striped">
Expand All @@ -25,6 +50,12 @@
<td><?php echo SUPPORTED_LANGUAGES[$page['language']]; ?></td>
<td><?php echo $page['filename']; ?></td>
<td class="text-right">
<form class="d-inline" method="POST" action="">
<button class="btn btn-sm btn-danger" name="del_page" value="<?php echo $page['path']; ?>" type="submit"
onclick="return confirm('Sicher?')">
<i class="fas fa-times"></i> <span class="d-none d-md-inline">löschen</span>
</button>
</form>
<form class="d-inline" method="POST" action="<?php echo ROUTES::getUri('admin_pages_edit'); ?>">
<button class="btn btn-sm btn-primary" name="file_path" value="<?php echo $page['path']; ?>" type="submit">
<i class="fas fa-pencil-alt"></i> <span class="d-none d-md-inline">bearbeiten</span>
Expand Down
15 changes: 8 additions & 7 deletions config/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
define('MYSQL_PASS', ''); // password
define('MYSQL_DATABASE', 'miniDevTCG'); // database ame

define('BASE_URI', 'http://localhost/eclipse/miniTCG/'); // base path (keep the '/' at the end) even with top level domain (e.g. https://domain.com/)
define('BASE_URI', 'http://localhost/eclipse/miniTCG/'); // base path, keep the '/' at the end(!) even with top level domain (e.g. https://domain.com/)

define('DEFAULT_TIMEZONE','Europe/Berlin'); // default application timezone

Expand All @@ -29,9 +29,9 @@
* --------------
* Feel free to add more languages!
* To do so, add a new key value pair to the array above. (e.g. 'fr'=>'Français')
* Copy the view files form another language folder into a new folder, named after your new key,
* Copy the view files you want to translate, form another language folder into a new folder, named after your new key,
* and translate the texts.
* You might also want to add your new language to the system messages
* You might also want to add your new language to the system messages (config/system_messages.php)
*/


Expand All @@ -42,10 +42,11 @@

// no need to edit here -------------------------------------------------------------------------------------
define('APP_VERSION','v1.3.1.1 beta');
define('PATH', dirname(__FILE__).'/../'); // relativer Pfad
define('SERVER_URL', $_SERVER['SERVER_NAME']);
define('ERROR_LOG', PATH.'app_error.log'); // to be used in later versions
define('SESSION_PREFIX','mtcg');
define('PATH', dirname(__FILE__).'/../'); // relative path
define('DEFAULT_FOLDER_PAGES','app/views/[lang]/pages/'); // default path for pages without controller setup
define('SERVER_URL', $_SERVER['SERVER_NAME']); // current server
define('ERROR_LOG', PATH.'app_error.log'); // to be used more in later versions
define('SESSION_PREFIX','mtcg'); // change in case of multtiple installs in different folders



Expand Down
11 changes: 9 additions & 2 deletions config/system_messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,18 @@
'en' => 'Changes saved.',
'de' => 'Änderungen gespeichert.'
]);
$sys_msg_text_handler->addCode('file_created', [
'en' => 'A file was created.',
'de' => 'Eine Datei wurde erstellt.'
]);
$sys_msg_text_handler->addCode('element_deleted', [
'en' => 'Element was deleted.',
'de' => 'Element wurde gelöscht.'
]);
$sys_msg_text_handler->addCode('folder_not_found',[
'en'=>'Folder not found.',
'de'=>'Verzeichnis nicht gefunden.'
]);

// SETTINGS
$sys_msg_text_handler->addCode('admin_settings_updated', [
Expand Down Expand Up @@ -186,8 +194,7 @@
$sys_msg_text_handler->addCode('template_not_found',[
'en'=>'Template not found.',
'de'=>'Template Pfad nicht gefunden'
]);

]);



Expand Down
4 changes: 3 additions & 1 deletion import/update-1_3_0beta-to-1_3_2beta.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ ALTER TABLE `trades` CHANGE `utc` `utc` TIMESTAMP NOT NULL;
ALTER TABLE `updates` CHANGE `utc` `utc` TIMESTAMP NOT NULL;

-- add new route for wishlist
INSERT INTO `routing` (`identifier`, `url`, `controller`, `action`, `method`, `deletable`) VALUES ('member_wishlist', 'member/wishlist.php', 'Member', 'wishlist', 'get|post', '0')
INSERT INTO `routing` (`identifier`, `url`, `controller`, `action`, `method`, `deletable`) VALUES ('member_wishlist', 'member/wishlist.php', 'Member', 'wishlist', 'get|post', '0');
-- allow post on pages list
UPDATE `routing` SET `method` = 'get|post' WHERE `routing`.`identifier` = 'admin_pages';
2 changes: 1 addition & 1 deletion setup/structure_v1_3_2beta.sql
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ INSERT INTO `routing` (`identifier`, `url`, `controller`, `action`, `method`, `d
('admin_member_manage_rights', 'admin/members/manage_rights.php', 'Admin', 'manageRights', 'get|post', '0'),
('admin_member_reset_password', 'admin/members/reset_password.php', 'Admin', 'resetPassword', 'get|post', '0'),
('admin_member_search', 'admin/members/search.php', 'Admin', 'searchMember', 'get|post', '0'),
('admin_pages', 'admin/pages/list.php', 'Admin', 'pagesIndex', 'get', '0'),
('admin_pages', 'admin/pages/list.php', 'Admin', 'pagesIndex', 'get|post', '0'),
('admin_pages_edit', 'admin/pages/edit.php', 'Admin', 'pagesEdit', 'get|post', '0'),
('admin_routes_add', 'admin/routes/add.php', 'Admin', 'addRoute', 'get|post', '0'),
('admin_routes_edit', 'admin/routes/edit.php', 'Admin', 'editRoute', 'get|post', '0'),
Expand Down

0 comments on commit 69ba7db

Please sign in to comment.