";
- $action = "
" . $delete . " | " . $settings . $activate;
+ $action = '
'.$delete.' | '.$settings.$activate;
} else {
$action = '';
}
- return ucfirst($model['name']) . $action;
+
+ return ucfirst($model['name']).$action;
})
- ->addColumn('description', function($model) {
+ ->addColumn('description', function ($model) {
return ucfirst($model['description']);
})
- ->addColumn('author', function($model) {
+ ->addColumn('author', function ($model) {
return ucfirst($model['author']);
})
- ->addColumn('website', function($model) {
- return "
" . $model['website'] . "";
+ ->addColumn('website', function ($model) {
+ return '
'.$model['website'].'';
})
- ->addColumn('version', function($model) {
+ ->addColumn('version', function ($model) {
return $model['version'];
})
->make();
}
/**
- * Reading the Filedirectory
+ * Reading the Filedirectory.
+ *
* @return type
*/
- public function ReadPlugins() {
- $dir = app_path() .DIRECTORY_SEPARATOR.'Plugins';
- $plugins = array_diff(scandir($dir), array('.', '..'));
+ public function ReadPlugins()
+ {
+ $dir = app_path().DIRECTORY_SEPARATOR.'Plugins';
+ $plugins = array_diff(scandir($dir), ['.', '..']);
+
return $plugins;
}
/**
- * After plugin post
+ * After plugin post.
+ *
* @param Request $request
+ *
* @return type
*/
- public function PostPlugins(Request $request) {
+ public function PostPlugins(Request $request)
+ {
$v = $this->validate($request, ['plugin' => 'required|mimes:application/zip,zip,Zip']);
$plug = new Plugin();
$file = $request->file('plugin');
//dd($file);
- $destination = app_path() .DIRECTORY_SEPARATOR.'Plugins';
+ $destination = app_path().DIRECTORY_SEPARATOR.'Plugins';
$zipfile = $file->getRealPath();
- /**
+ /*
* get the file name and remove .zip
*/
$filename2 = $file->getClientOriginalName();
$filename2 = str_replace('.zip', '', $filename2);
$filename1 = ucfirst($file->getClientOriginalName());
$filename = str_replace('.zip', '', $filename1);
- mkdir($destination . DIRECTORY_SEPARATOR . $filename);
- /**
+ mkdir($destination.DIRECTORY_SEPARATOR.$filename);
+ /*
* extract the zip file using zipper
*/
- \Zipper::make($zipfile)->folder($filename2)->extractTo($destination .DIRECTORY_SEPARATOR. $filename);
+ \Zipper::make($zipfile)->folder($filename2)->extractTo($destination.DIRECTORY_SEPARATOR.$filename);
- $file = app_path() .DIRECTORY_SEPARATOR.'Plugins'.DIRECTORY_SEPARATOR. $filename; // Plugin file path
+ $file = app_path().DIRECTORY_SEPARATOR.'Plugins'.DIRECTORY_SEPARATOR.$filename; // Plugin file path
if (file_exists($file)) {
-
- $seviceporvider = $file .DIRECTORY_SEPARATOR.'ServiceProvider.php';
- $config = $file .DIRECTORY_SEPARATOR.'config.php';
+ $seviceporvider = $file.DIRECTORY_SEPARATOR.'ServiceProvider.php';
+ $config = $file.DIRECTORY_SEPARATOR.'config.php';
if (file_exists($seviceporvider) && file_exists($config)) {
- /**
+ /*
* move to faveo config
*/
- $faveoconfig = config_path() .DIRECTORY_SEPARATOR.'plugins' .DIRECTORY_SEPARATOR.$filename . '.php';
+ $faveoconfig = config_path().DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$filename.'.php';
if ($faveoconfig) {
//copy($config, $faveoconfig);
- /**
+ /*
* write provider list in app.php line 128
*/
- $app = base_path() .DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php';
- $str = "\n\n\t\t\t'App\\Plugins\\$filename" . "\\ServiceProvider',";
+ $app = base_path().DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php';
+ $str = "\n\n\t\t\t'App\\Plugins\\$filename"."\\ServiceProvider',";
$line_i_am_looking_for = 144;
$lines = file($app, FILE_IGNORE_NEW_LINES);
$lines[$line_i_am_looking_for] = $str;
file_put_contents($app, implode("\n", $lines));
$plug->create(['name' => $filename, 'path' => $filename, 'status' => 1]);
+
return redirect()->back()->with('success', 'Installed SuccessFully');
} else {
- /**
+ /*
* delete if the plugin hasn't config.php and ServiceProvider.php
*/
$this->deleteDirectory($file);
- return redirect()->back()->with('fails', 'Their is no ' . $file);
+
+ return redirect()->back()->with('fails', 'Their is no '.$file);
}
} else {
- /**
+ /*
* delete if the plugin hasn't config.php and ServiceProvider.php
*/
$this->deleteDirectory($file);
- return redirect()->back()->with('fails', 'Their is no
config.php or ServiceProvider.php ' . $file);
+
+ return redirect()->back()->with('fails', 'Their is no
config.php or ServiceProvider.php '.$file);
}
} else {
- /**
+ /*
* delete if the plugin Name is not equal to the folder name
*/
$this->deleteDirectory($file);
- return redirect()->back()->with('fails', '
Plugin File Path is not exist ' . $file);
+
+ return redirect()->back()->with('fails', '
Plugin File Path is not exist '.$file);
}
}
/**
- * Delete the directory
+ * Delete the directory.
+ *
* @param type $dir
- * @return boolean
+ *
+ * @return bool
*/
- public function deleteDirectory($dir) {
-
+ public function deleteDirectory($dir)
+ {
if (!file_exists($dir)) {
return true;
}
@@ -591,34 +627,37 @@ class SettingsController extends Controller {
if ($item == '.' || $item == '..') {
continue;
}
- chmod($dir . DIRECTORY_SEPARATOR . $item,0777);
- if (!$this->deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) {
+ chmod($dir.DIRECTORY_SEPARATOR.$item, 0777);
+ if (!$this->deleteDirectory($dir.DIRECTORY_SEPARATOR.$item)) {
return false;
}
}
chmod($dir, 0777);
+
return rmdir($dir);
}
- public function ReadConfigs() {
- $dir = app_path() .DIRECTORY_SEPARATOR.'Plugins'.DIRECTORY_SEPARATOR;
+ public function ReadConfigs()
+ {
+ $dir = app_path().DIRECTORY_SEPARATOR.'Plugins'.DIRECTORY_SEPARATOR;
$directories = scandir($dir);
$files = [];
foreach ($directories as $key => $file) {
- if ($file === '.' or $file === '..')
+ if ($file === '.' or $file === '..') {
continue;
+ }
- if (is_dir($dir .DIRECTORY_SEPARATOR. $file)) {
+ if (is_dir($dir.DIRECTORY_SEPARATOR.$file)) {
$files[$key] = $file;
}
}
//dd($files);
- $config=[];
- $plugins = array();
+ $config = [];
+ $plugins = [];
if (count($files) > 0) {
foreach ($files as $key => $file) {
- $plugin = $dir . $file;
- $plugins[$key] = array_diff(scandir($plugin), array('.', '..', 'ServiceProvider.php'));
+ $plugin = $dir.$file;
+ $plugins[$key] = array_diff(scandir($plugin), ['.', '..', 'ServiceProvider.php']);
$plugins[$key]['file'] = $plugin;
}
foreach ($plugins as $plugin) {
@@ -627,27 +666,28 @@ class SettingsController extends Controller {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file == 'config.php') {
- $config[] = $dir .DIRECTORY_SEPARATOR. $file;
+ $config[] = $dir.DIRECTORY_SEPARATOR.$file;
}
}
closedir($dh);
}
}
+
return $config;
} else {
return 'null';
}
}
- public function fetchConfig() {
+ public function fetchConfig()
+ {
$configs = $this->ReadConfigs();
//dd($configs);
- $plug = new Plugin;
+ $plug = new Plugin();
$plug = $plug->select('path', 'status')->orderBy('name')->get()->toArray();
//$fields = [];
if ($configs !== 'null') {
foreach ($configs as $key => $config) {
-
$fields[$key] = include $config;
if ($plug != null) {
@@ -658,48 +698,53 @@ class SettingsController extends Controller {
$fields[$key]['status'] = 0;
}
}
+
return $fields;
}
}
- public function DeletePlugin($slug) {
- $dir = app_path() . DIRECTORY_SEPARATOR . 'Plugins' . DIRECTORY_SEPARATOR . $slug;
+ public function DeletePlugin($slug)
+ {
+ $dir = app_path().DIRECTORY_SEPARATOR.'Plugins'.DIRECTORY_SEPARATOR.$slug;
$this->deleteDirectory($dir);
- /**
+ /*
* remove service provider from app.php
*/
- $str = "'App\\Plugins\\$slug" . "\\ServiceProvider',";
- $path_to_file = base_path() .DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php';
+ $str = "'App\\Plugins\\$slug"."\\ServiceProvider',";
+ $path_to_file = base_path().DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php';
$file_contents = file_get_contents($path_to_file);
- $file_contents = str_replace($str, "//", $file_contents);
+ $file_contents = str_replace($str, '//', $file_contents);
file_put_contents($path_to_file, $file_contents);
$plugin = new Plugin();
$plugin = $plugin->where('path', $slug)->first();
if ($plugin) {
$plugin->delete();
}
+
return redirect()->back()->with('success', 'Deleted Successfully');
}
- public function StatusPlugin($slug) {
- $plugs = new Plugin;
+ public function StatusPlugin($slug)
+ {
+ $plugs = new Plugin();
$plug = $plugs->where('name', $slug)->first();
if (!$plug) {
- $app = base_path() .DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php';
- $str = "'App\\Plugins\\$slug" . "\\ServiceProvider',";
+ $app = base_path().DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php';
+ $str = "'App\\Plugins\\$slug"."\\ServiceProvider',";
$line_i_am_looking_for = 144;
$lines = file($app, FILE_IGNORE_NEW_LINES);
$lines[$line_i_am_looking_for] = $str;
file_put_contents($app, implode("\n", $lines));
$plugs->create(['name' => $slug, 'path' => $slug, 'status' => 1]);
+
return redirect()->back()->with('success', 'Status has changed');
}
$status = $plug->status;
if ($status == 0) {
$plug->status = 1;
- $app = base_path() .DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php';
- $str = "'App\\Plugins\\$slug" . "\\ServiceProvider',";
+ $app = base_path().DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php';
+ $str = "'App\\Plugins\\$slug"."\\ServiceProvider',";
$line_i_am_looking_for = 144;
$lines = file($app, FILE_IGNORE_NEW_LINES);
$lines[$line_i_am_looking_for] = $str;
@@ -707,18 +752,18 @@ class SettingsController extends Controller {
}
if ($status == 1) {
$plug->status = 0;
- /**
+ /*
* remove service provider from app.php
*/
- $str = "'App\\Plugins\\$slug" . "\\ServiceProvider',";
- $path_to_file = base_path() .DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php';
+ $str = "'App\\Plugins\\$slug"."\\ServiceProvider',";
+ $path_to_file = base_path().DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php';
$file_contents = file_get_contents($path_to_file);
- $file_contents = str_replace($str, "//", $file_contents);
+ $file_contents = str_replace($str, '//', $file_contents);
file_put_contents($path_to_file, $file_contents);
}
$plug->save();
+
return redirect()->back()->with('success', 'Status has changed');
}
-
}