Filelist Widget (CMS)
Gestern gabs in ContentLion das Pagelist Widget und heute ist das FileList Widget dran 😉 Dabei handelt es sich um die Auflistung der Dateien im neuen Backend. Im Prinzip machen wir auch ähnliches. Wir kopieren die Grundfunktionen von /admin/includes/files.php in das neue Plugin filelistplugin.
Dessen /system/plugins/filelistplugin/info.php sieht so aus:
<?PHP $pluginInfo = new PluginInfo(); $pluginInfo->path = "filelistwidget"; $pluginInfo->name = "FileList Widget"; $pluginInfo->description = "Listet die Dateien im Dashboard auf"; $pluginInfo->authorName = "ContentLion"; $pluginInfo->authorLink = "http://contentlion.org"; $pluginInfo->version = "1.0.0"; $this->Add($pluginInfo); ?>
Das Template /system/templates/files.html zieht nach /system/plugins/filelistwidget/templates/filelist.html um:
{IF:FILES_EXIST} <table> <tbody> {LOOP:FILES} <tr> <td>{VAR:IMAGE}</td> <td>{VAR:FILELINK}</td> <td> <a href="{VAR:DELETEURL}"> <img src="{ICON:CROSS}" /> </a> </td> </tr> {/LOOP:FILES} </tbody> </table> {/IF:FILES_EXIST} {IF:NOFILES} <p>{LANG:NO_FILES}</p> {/IF:NOFILES}
Die Plugin-Klasse /system/plugins/filelistwidget/filelistwidget.php sieht so aus:
<?PHP class FileListWidget extends WidgetBase{ public function load(){ $this->headline = $GLOBALS['language']->getString("FILES"); $uploadpath = getSetting("global","global","root")."content/uploads/"; $template = new Template(); $template->load("plugin_filelistwidget_filelist"); $template->assign_var("UPLOADURL","/admin/index.php?page=upload"); $template->assign_var("DIR",htmlentities($_GET['dir'])); $template->assign_var("NEWFOLDERURL","/admin/index.php?page=files&dir=".urlencode($_GET['dir'])); $dir = $_GET['dir']; if($_POST['newFolder']){ FileServer::createFolder($uploadpath.$dir,$_POST['name']); } if($_GET['unlink']){ unlink($uploadpath.$_GET['dir']."/".$_GET['unlink']); $template->assign_var("MESSAGE",$language->getString("FILE")." ".htmlentities($_GET['unlink'])." ".$language->getString("WAS_DELETED")); } if($_GET['rmdir']){ rmdir($uploadpath.$_GET['rmdir']); $template->assign_var("MESSAGE",$language->getString("DIR")." ".htmlentities($_GET['rmdir'])." ".$language->getString("WAS_DELETED")); } $verzeichnis = openDir($uploadpath.$dir); $pre = ""; foreach(split("/",$dir) as $cDir){ $index = $template->add_loop_item("PATH"); $path .= "/".$cDir; if($path == "/"){ $template->assign_loop_var("PATH", $index, "URL","/admin/index.php?page=files"); $template->assign_loop_var("PATH", $index, "LABEL","/"); $path = ""; } else{ $template->assign_loop_var("PATH", $index, "URL","/admin/index.php?page=files&dir=".$path); $template->assign_loop_var("PATH", $index, "LABEL",$cDir); } } $subFolders = FileServer::getFolders($uploadpath.$dir); if($subFolders){ foreach($subFolders as $folder){ $index = $template->add_loop_item("DIRS"); $template->assign_loop_var("DIRS",$index,"URL","/admin/index.php?page=files&dir=".$dir."/".$folder); $template->assign_loop_var("DIRS",$index,"LABEL",$folder); } } if(trim($_GET['dir']) != "" & trim($_GET['dir']) != "/"){ $template->assign_var("DELETEFOLDERLINK","<a href="/admin/index.php?page=files&rmdir=".$_GET['dir']."">Ordner löschen</a>"); } else{ $template->assign_var("DELETEFOLDERLINK",""); } $files = FileServer::getFiles($uploadpath.$dir); if($files){ $template->show_if("FILES_EXIST",true); $template->show_if("NOFILES",false); foreach($files as $file){ $index = $template->add_loop_item("FILES"); $path_info = pathinfo($uploadpath.$dir."/".$file); if(strtolower($path_info['extension'] == 'jpg') or strtolower($path_info['extension'] == 'jpeg') or strtolower($path_info['extension'] == 'gif') or strtolower($path_info['extension'] == 'png') or strtolower($path_info['extension'] == 'bmp')){ $template->assign_loop_var("FILES",$index,"IMAGE","<img src="/content/uploads/".$dir."/".$file."" style="max-width:100px;max-height:100px;" />"); } else{ $template->assign_loop_var("FILES",$index,"IMAGE",""); } $template->assign_loop_var("FILES",$index,"FILELINK","<a href="../content/uploads".$dir."/".$file."">".$file."</a>"); $template->assign_loop_var("FILES",$index,"DELETEURL","/admin/index.php?page=files&dir=".urlencode($_GET['dir'])."&unlink=".urlencode($file)); } } else{ $template->show_if("FILES_EXIST",false); $template->show_if("NOFILES",true); } $template->assign_var("MESSAGE",""); $this->content = $template->getCode(); } } ?>
Die ist ähnlich wie die Datei aus dem „Admin-Bereich“. Fehlt nur noch die Änderung im /installer/installer.php:
mysql_query("INSERT INTO `".$this->params[3]['praefix']."dashboards` VALUES ('admin/home', 3, 1, 'filelistwidget/filelistwidget.php');"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."widgets` VALUES ('lookaround/widget.php', 'LookAround', 'LookAround');"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."widgets` VALUES ('pagelistwidget/pagelistwidget.php', 'PageList', 'PageListWidget');"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."widgets` VALUES ('filelistwidget/filelistwidget.php', 'FileList', 'FileListWidget');"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."role_rights` VALUES (1,1);"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."role_rights` VALUES (1,2);"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."role_rights` VALUES (1,3);"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."role_rights` VALUES (2,1);"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."role_rights` VALUES (2,2);"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."role_rights` VALUES (2,3);"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."role_rights` VALUES (3,1);"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."role_rights` VALUES (3,2);"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."role_rights` VALUES (3,3);"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."role_rights` VALUES (2,4);"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."role_rights` VALUES (2,5);"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."role_rights` VALUES (2,6);"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."role_rights` VALUES (2,7);"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."role_rights` VALUES (2,8);"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."role_rights` VALUES (2,9);"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."role_rights` VALUES (2,10);"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."role_rights` VALUES (2,11);"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."activated_plugins` VALUES ('lookaround');"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."activated_plugins` VALUES ('pagelistwidget');"); mysql_query("INSERT INTO `".$this->params[3]['praefix']."activated_plugins` VALUES ('filelistwidget');"); }
Selbstverständlich auch heute wieder mit Einstiegspunkt:
http://blog.stevieswebsite.de/download/190.zip
Als nächstes werden wir ein paar „Schönheitsfehler“ von ContentLion beseitigen 😉
Du arbeitest in einer Agentur oder als Freelancer?
Dann wirf doch mal einen Blick auf unsere Software FeatValue.
Über uns
![Stefan Wienströer](/i/stefan-264.png)
Wir entwickeln Webanwendungen mit viel Leidenschaft. Unser Wissen geben wir dabei gerne weiter. Mehr über a coding project