forked from WWBN/AVideo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Neto
committed
Nov 14, 2024
1 parent
6865156
commit 011066b
Showing
1,115 changed files
with
55,533 additions
and
2,446 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,265 @@ | ||
<?php | ||
require_once __DIR__.'/../videos/configuration.php'; | ||
|
||
if(!User::isAdmin()){ | ||
forbiddenPage('You Must be admin'); | ||
} | ||
|
||
|
||
if(!empty($global['disableAdvancedConfigurations'])){ | ||
forbiddenPage('Configuration disabled'); | ||
} | ||
|
||
use iamcal\SQLParser; | ||
|
||
$parser = new SQLParser(); | ||
|
||
$pluginName = $_REQUEST['pluginName']; | ||
$sql = $_REQUEST['createTableSQL']; | ||
|
||
$parser->parse($sql); | ||
//var_dump($parser->tables);exit; | ||
$pluginDir = __DIR__."/plugins/{$pluginName}/"; | ||
echo $pluginDir, PHP_EOL; | ||
_mkdir($pluginDir); | ||
|
||
$pluginDirInstall = "{$pluginDir}/install/"; | ||
_mkdir($pluginDirInstall); | ||
file_put_contents($pluginDirInstall . "install.sql", $sql); | ||
|
||
$pluginDirObjects = "{$pluginDir}/Objects/"; | ||
_mkdir($pluginDirObjects); | ||
|
||
$pluginDirView = "{$pluginDir}/View/"; | ||
_mkdir($pluginDirView); | ||
|
||
$includeTables = array(); | ||
$editorNavTabs = array(); | ||
$editorNavContent = array(); | ||
$active = true; | ||
foreach ($parser->tables as $value) { | ||
$classname = ucwords($value['name']); | ||
$tableName = ucwords(str_replace("_", " ", $value['name'])); | ||
$editorNavTabs[] = "<li class=\"" . ($active ? "active" : "") . "\"><a data-toggle=\"tab\" href=\"#{$classname}\"><?php echo __(\"{$tableName}\"); ?></a></li>"; | ||
$editorNavContent[] = "<div id=\"{$classname}\" class=\"tab-pane fade " . ($active ? "in active" : "") . "\" style=\"padding: 10px;\"> | ||
<?php | ||
include \$global['systemRootPath'] . 'plugin/{$pluginName}/View/{$classname}/index_body.php'; | ||
?> | ||
</div>"; | ||
$active = false; | ||
$includeTables[] = "require_once \$global['systemRootPath'] . 'plugin/{$pluginName}/Objects/{$classname}.php';"; | ||
$columnsVars = array(); | ||
$columnsString = array(); | ||
$columnsGet = array(); | ||
$columnsSet = array(); | ||
$columnsForm = array(); | ||
$columnsFooter = array(); | ||
$columnsGrid = array(); | ||
$columnsClearJQuery = array(); | ||
$columnsDatatable = array(); | ||
$columnsEdit = array(); | ||
$columnsAdd = array(); | ||
$columnsGetAll = array(); | ||
|
||
foreach ($value['fields'] as $value2) { | ||
if ($value2['name'] == 'created' || $value2['name'] == 'modified') { | ||
continue; | ||
} | ||
$columnsVars[] = '$' . $value2['name']; | ||
$type = strtolower($value2['type']); | ||
if ($type == 'text' || $type == 'varchar') { | ||
$columnsString[] = "'{$value2['name']}'"; | ||
} | ||
$fieldName = ucwords(str_replace("_", " ", $value2['name'])); | ||
$columnsClearJQuery[] = "$('#{$classname}{$value2['name']}').val('');"; | ||
$columnsEdit[] = "$('#{$classname}{$value2['name']}').val(data.{$value2['name']});"; | ||
if ($value2['name'] != 'id') { | ||
$columnsAdd[] = "\$o->set" . ucfirst($value2['name']) . "(\$_POST['{$value2['name']}']);"; | ||
} | ||
|
||
if ($type == 'int' || $type == 'tinyint') { | ||
$columnsGet[] = " | ||
function get" . ucfirst($value2['name']) . "() { | ||
return intval(\$this->{$value2['name']}); | ||
} "; | ||
|
||
$columnsSet[] = " | ||
function set" . ucfirst($value2['name']) . "(\${$value2['name']}) { | ||
\$this->{$value2['name']} = intval(\${$value2['name']}); | ||
} "; | ||
} else if ($type == 'float') { | ||
$columnsGet[] = " | ||
function get" . ucfirst($value2['name']) . "() { | ||
return floatval(\$this->{$value2['name']}); | ||
} "; | ||
|
||
$columnsSet[] = " | ||
function set" . ucfirst($value2['name']) . "(\${$value2['name']}) { | ||
\$this->{$value2['name']} = floatval(\${$value2['name']}); | ||
} "; | ||
} else { | ||
$columnsGet[] = " | ||
function get" . ucfirst($value2['name']) . "() { | ||
return \$this->{$value2['name']}; | ||
} "; | ||
|
||
$columnsSet[] = " | ||
function set" . ucfirst($value2['name']) . "(\${$value2['name']}) { | ||
\$this->{$value2['name']} = \${$value2['name']}; | ||
} "; | ||
} | ||
|
||
if(preg_match("/^(.*)_id/i", $value2['name'], $matches)){ | ||
|
||
$columnsGetAll[] = "static function getAll" . ucfirst($matches[1]) . "() { | ||
global \$global; | ||
\$table = \"{$matches[1]}\"; | ||
\$sql = \"SELECT * FROM {\$table} WHERE 1=1 \"; | ||
\$sql .= self::getSqlFromPost(); | ||
\$res = sqlDAL::readSql(\$sql); | ||
\$fullData = sqlDAL::fetchAllAssoc(\$res); | ||
sqlDAL::close(\$res); | ||
\$rows = array(); | ||
if (\$res != false) { | ||
foreach (\$fullData as \$row) { | ||
\$rows[] = \$row; | ||
} | ||
} else { | ||
/** | ||
* | ||
* @var array \$global | ||
* @var object \$global['mysqli'] | ||
*/ | ||
_error_log(\$sql . ' Error : (' . \$global['mysqli']->errno . ') ' . \$global['mysqli']->error); | ||
} | ||
return \$rows; | ||
}"; | ||
$columnsForm[] = '<div class="form-group col-sm-12"> | ||
<label for="' . $classname . $value2['name'] . '"><?php echo __("' . $fieldName . '"); ?>:</label> | ||
<select class="form-control input-sm" name="' . $value2['name'] . '" id="' . $classname . $value2['name'] . '"> | ||
<?php | ||
$options = '.$classname.'::getAll' . ucfirst($matches[1]) . '(); | ||
foreach ($options as $value) { | ||
echo \'<option value="\'.$value[\'id\'].\'">\'.$value[\'id\'].\'</option>\'; | ||
} | ||
?> | ||
</select> | ||
</div>'; | ||
}else if ($value2['name'] == 'id') { | ||
$columnsGrid[] = "<th>#</th>"; | ||
$columnsDatatable[] = '{"data": "id"}'; | ||
$columnsForm[] = '<input type="hidden" name="id" id="' . $classname . 'id" value="" >'; | ||
} else if ($value2['name'] == 'status') { | ||
$columnsGrid[] = '<th><?php echo __("' . $fieldName . '"); ?></th>'; | ||
$columnsDatatable[] = '{"data": "' . $value2['name'] . '"}'; | ||
$columnsForm[] = '<div class="form-group col-sm-12"> | ||
<label for="status"><?php echo __("Status"); ?>:</label> | ||
<select class="form-control input-sm" name="status" id="' . $classname . 'status"> | ||
<option value="a"><?php echo __("Active"); ?></option> | ||
<option value="i"><?php echo __("Inactive"); ?></option> | ||
</select> | ||
</div>'; | ||
} else { | ||
$columnsGrid[] = '<th><?php echo __("' . $fieldName . '"); ?></th>'; | ||
$columnsDatatable[] = '{"data": "' . $value2['name'] . '"}'; | ||
if($type == 'text'){ | ||
$columnsForm[] = '<div class="form-group col-sm-12"> | ||
<label for="' . $classname . $value2['name'] . '"><?php echo __("' . $fieldName . '"); ?>:</label> | ||
<textarea id="' . $classname . $value2['name'] . '" name="' . $value2['name'] . '" class="form-control input-sm" placeholder="<?php echo __("' . $fieldName . '"); ?>" required="true"></textarea> | ||
</div>'; | ||
}else if($type == 'int'){ | ||
$columnsForm[] = '<div class="form-group col-sm-12"> | ||
<label for="' . $classname . $value2['name'] . '"><?php echo __("' . $fieldName . '"); ?>:</label> | ||
<input type="number" step="1" id="' . $classname . $value2['name'] . '" name="' . $value2['name'] . '" class="form-control input-sm" placeholder="<?php echo __("' . $fieldName . '"); ?>" required="true"> | ||
</div>'; | ||
}else if($type == 'float'){ | ||
$columnsForm[] = '<div class="form-group col-sm-12"> | ||
<label for="' . $classname . $value2['name'] . '"><?php echo __("' . $fieldName . '"); ?>:</label> | ||
<input type="number" step="0.01" id="' . $classname . $value2['name'] . '" name="' . $value2['name'] . '" class="form-control input-sm" placeholder="<?php echo __("' . $fieldName . '"); ?>" required="true"> | ||
</div>'; | ||
|
||
}else if($type == 'datetime'){ | ||
$columnsForm[] = '<div class="form-group col-sm-12"> | ||
<label for="' . $classname . $value2['name'] . '"><?php echo __("' . $fieldName . '"); ?>:</label> | ||
<input type="text" id="' . $classname . $value2['name'] . '" name="' . $value2['name'] . '" class="form-control input-sm" placeholder="<?php echo __("' . $fieldName . '"); ?>" required="true" autocomplete="off"> | ||
</div>'; | ||
$columnsFooter[] = '<script> $(document).ready(function () {$(\'#' . $classname . $value2['name'] . '\').datetimepicker({format: \'yyyy-mm-dd hh:ii\',autoclose: true });});</script>'; | ||
|
||
}else{ | ||
$columnsForm[] = '<div class="form-group col-sm-12"> | ||
<label for="' . $classname . $value2['name'] . '"><?php echo __("' . $fieldName . '"); ?>:</label> | ||
<input type="text" id="' . $classname . $value2['name'] . '" name="' . $value2['name'] . '" class="form-control input-sm" placeholder="<?php echo __("' . $fieldName . '"); ?>" required="true"> | ||
</div>'; | ||
} | ||
} | ||
} | ||
|
||
$templatesDir = __DIR__.'/templates/'; | ||
|
||
$classFile = "{$pluginDirObjects}{$classname}.php"; | ||
$modelTemplate = file_get_contents("{$templatesDir}model.php"); | ||
$search = array('{classname}', '{tablename}', '{pluginName}', '{columnsVars}', '{columnsString}', '{columnsGetAll}', '{columnsGet}', '{columnsSet}'); | ||
$replace = array($classname, $value['name'], $pluginName, implode(",", $columnsVars), implode(",", $columnsString), implode(PHP_EOL, $columnsGetAll), implode(PHP_EOL, $columnsGet), implode(PHP_EOL, $columnsSet)); | ||
$data = str_replace($search, $replace, $modelTemplate); | ||
file_put_contents($classFile, $data); | ||
|
||
|
||
$dir = "{$pluginDirView}{$classname}/"; | ||
_mkdir($dir); | ||
|
||
$file = "{$dir}index.php"; | ||
$modelTemplate = file_get_contents("{$templatesDir}index.php"); | ||
$search = array('{classname}', '{pluginName}'); | ||
$replace = array($classname, $pluginName); | ||
$data = str_replace($search, $replace, $modelTemplate); | ||
file_put_contents($file, $data); | ||
|
||
$file = "{$dir}index_body.php"; | ||
$modelTemplate = file_get_contents("{$templatesDir}index_body.php"); | ||
$search = array('{classname}','{tablename}', '{pluginName}', '{columnsForm}', '{columnsFooter}', '{columnsGrid}', '{$columnsClearJQuery}', '{columnsDatatable}', '{$columnsEdit}'); | ||
$replace = array($classname,$value['name'], $pluginName, implode(PHP_EOL, $columnsForm), implode(PHP_EOL, $columnsFooter), implode(PHP_EOL, $columnsGrid), implode(PHP_EOL, $columnsClearJQuery), implode("," . PHP_EOL, $columnsDatatable), implode(PHP_EOL, $columnsEdit)); | ||
$data = str_replace($search, $replace, $modelTemplate); | ||
file_put_contents($file, $data); | ||
|
||
$file = "{$dir}list.json.php"; | ||
$modelTemplate = file_get_contents("{$templatesDir}list.json.php"); | ||
$search = array('{classname}', '{pluginName}'); | ||
$replace = array($classname, $pluginName); | ||
$data = str_replace($search, $replace, $modelTemplate); | ||
file_put_contents($file, $data); | ||
|
||
$file = "{$dir}delete.json.php"; | ||
$modelTemplate = file_get_contents("{$templatesDir}delete.json.php"); | ||
$search = array('{classname}', '{pluginName}'); | ||
$replace = array($classname, $pluginName); | ||
$data = str_replace($search, $replace, $modelTemplate); | ||
file_put_contents($file, $data); | ||
|
||
$file = "{$dir}add.json.php"; | ||
$modelTemplate = file_get_contents("{$templatesDir}add.json.php"); | ||
$search = array('{classname}', '{pluginName}', '{columnsAdd}'); | ||
$replace = array($classname, $pluginName, implode(PHP_EOL, $columnsAdd)); | ||
$data = str_replace($search, $replace, $modelTemplate); | ||
file_put_contents($file, $data); | ||
} | ||
|
||
$pluginFile = "{$pluginDir}$pluginName.php"; | ||
$pluginTemplate = file_get_contents("{$templatesDir}plugin.php"); | ||
$search = array('{pluginName}', '{includeTables}', '{tablename}', '{uid}'); | ||
$replace = array($pluginName, implode(PHP_EOL, $includeTables), $pluginName, "5ee8405eaaa16"); | ||
$data = str_replace($search, $replace, $pluginTemplate); | ||
file_put_contents($pluginFile, $data); | ||
|
||
$pluginFile = "{$pluginDir}View/editor.php"; | ||
$pluginTemplate = file_get_contents("{$templatesDir}editor.php"); | ||
$search = array('{pluginName}', '{editorNavTabs}', '{editorNavContent}'); | ||
$replace = array($pluginName, implode(PHP_EOL, $editorNavTabs), implode(PHP_EOL, $editorNavContent)); | ||
$data = str_replace($search, $replace, $pluginTemplate); | ||
file_put_contents($pluginFile, $data); | ||
|
||
function _mkdir($dir) { | ||
if (!is_dir($dir)) { | ||
mkdir($dir); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
require_once __DIR__ . '/../videos/configuration.php'; | ||
|
||
if (!User::isAdmin()) { | ||
forbiddenPage('You Must be admin'); | ||
} | ||
|
||
if (!empty($global['disableAdvancedConfigurations'])) { | ||
forbiddenPage('Configuration disabled'); | ||
} | ||
|
||
$page = new Page('Create plugin'); | ||
?> | ||
<div class="container"> | ||
<div class="panel panel-default"> | ||
<div class="panel-heading"> | ||
<h2>Create New Plugin</h2> | ||
</div> | ||
<div class="panel-body"> | ||
<form id="createPluginForm"> | ||
<div class="form-group"> | ||
<label for="pluginName">Plugin Name</label> | ||
<input type="text" class="form-control" id="pluginName" name="pluginName" placeholder="Enter Plugin Name" required> | ||
</div> | ||
<div class="form-group"> | ||
<label for="createTableSQL">CREATE TABLE SQL</label> | ||
<textarea class="form-control" id="createTableSQL" name="createTableSQL" rows="5" placeholder="Paste your CREATE TABLE SQL here" required></textarea> | ||
</div> | ||
<button type="button" id="createPluginButton" class="btn btn-primary btn-block">Create Plugin</button> | ||
</form> | ||
<div id="responseMessage" class="alert" style="display:none; margin-top: 10px;"></div> | ||
</div> | ||
<div class="panel-footer"> | ||
<h3>Instructions:</h3> | ||
<ul> | ||
<li>Enter the SQL code to create your plugin's table in the text area below.</li> | ||
<li>Provide a name for the plugin. The name must start with an uppercase letter, contain only letters, numbers, and underscores, and should have no spaces.</li> | ||
<li>Invalid characters will be automatically removed as you type.</li> | ||
<li>Click "Create Plugin" to submit the data.</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
<script> | ||
$(document).ready(function() { | ||
// Auto-format plugin name input | ||
$('#pluginName').on('input', function() { | ||
let value = $(this).val(); | ||
// Remove invalid characters and ensure the first letter is uppercase | ||
value = value.replace(/[^a-zA-Z0-9_]/g, ''); // Remove any character that is not a letter, number, or underscore | ||
if (value.length > 0) { | ||
value = value.charAt(0).toUpperCase() + value.slice(1); // Ensure the first letter is uppercase | ||
} | ||
$(this).val(value); | ||
}); | ||
|
||
// AJAX submit on button click | ||
$('#createPluginButton').on('click', function() { | ||
let pluginName = $('#pluginName').val(); | ||
let createTableSQL = $('#createTableSQL').val(); | ||
|
||
if (pluginName && createTableSQL) { | ||
$.ajax({ | ||
url: webSiteRootURL + 'CreatePlugin/create.json.php', | ||
type: 'POST', | ||
data: { | ||
pluginName: pluginName, | ||
createTableSQL: createTableSQL | ||
}, | ||
success: function(response) { | ||
$('#responseMessage').removeClass('alert-danger').addClass('alert-success').text('Plugin created successfully!').show(); | ||
}, | ||
error: function() { | ||
$('#responseMessage').removeClass('alert-success').addClass('alert-danger').text('An error occurred while creating the plugin.').show(); | ||
} | ||
}); | ||
} else { | ||
$('#responseMessage').removeClass('alert-success').addClass('alert-danger').text('Please fill in both fields.').show(); | ||
} | ||
}); | ||
}); | ||
</script> | ||
<?php | ||
$page->print(); | ||
?> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
header('Content-Type: application/json'); | ||
require_once '../../../../videos/configuration.php'; | ||
require_once $global['systemRootPath'] . 'plugin/{pluginName}/Objects/{classname}.php'; | ||
|
||
$obj = new stdClass(); | ||
$obj->error = true; | ||
$obj->msg = ""; | ||
|
||
$plugin = AVideoPlugin::loadPluginIfEnabled('{pluginName}'); | ||
|
||
if(!User::isAdmin()){ | ||
$obj->msg = "You cant do this"; | ||
die(json_encode($obj)); | ||
} | ||
|
||
$o = new {classname}(@$_POST['id']); | ||
{columnsAdd} | ||
|
||
if($id = $o->save()){ | ||
$obj->error = false; | ||
} | ||
|
||
echo json_encode($obj); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
require_once '../../../../videos/configuration.php'; | ||
require_once $global['systemRootPath'] . 'plugin/{pluginName}/Objects/{classname}.php'; | ||
header('Content-Type: application/json'); | ||
|
||
$obj = new stdClass(); | ||
$obj->error = true; | ||
|
||
$plugin = AVideoPlugin::loadPluginIfEnabled('{pluginName}'); | ||
|
||
if(!User::isAdmin()){ | ||
$obj->msg = "You cant do this"; | ||
die(json_encode($obj)); | ||
} | ||
|
||
$id = intval($_POST['id']); | ||
$row = new {classname}($id); | ||
$obj->error = !$row->delete(); | ||
die(json_encode($obj)); | ||
?> |
Oops, something went wrong.