Datenbankklasse Teil 10 (CMS)
In diesem Beitrag vollenden wir die Datenbankumstellung im Admin-Bereich unseres CMSes. Dann können wir ab bald endlich wieder spannendere Sachen machen 😉 Ich werd auch heute die Änderungen nicht mehr groß erleutern, da ihr das System des neuen Datenbankmodells bestimmt schon verstanden habt.
Fangen wir an mit der Datei /system/classes/imageserver.php:
<?PHP class ImageServer{ function insert($path,$name,$description){ $path = $GLOBALS['db']->EscapeString($path); $name = $GLOBALS['db']->EscapeString($name); $description = $GLOBALS['db']->EscapeString($description); $res = $GLOBALS['db']->Execute("INSERT INTO {'dbprefix'}images (path,name,description) VALUES ('".$path."','".$name."','".$description."')"); if($res){ $args['path'] = $path; $args['name'] = $name; $args['description'] = $description; EventManager::raiseEvent("image_registered","../",$args); } return $res; } function getImages(){ return $GLOBALS['db']->ReadRows("SELECT * FROM {'dbprefix'}images"); } } ?>
Die Datei /content/imagelist.php, hier auch mit neuen Imports:
var tinyMCEImageList = new Array( <?PHP include('../system/classes/imageserver.php'); include('../system/classes/database.php'); include('../system/classes/mysql.php'); $db = new MySQL('../system/dbsettings.php'); $db->Connect(); $images = ImageServer::getImages(); if($images){ $i = 1; foreach($images as $image){ ?> ["<?PHP echo $image->name; ?>", "<?PHP echo $image->path; ?>"] <?PHP if($i < count($images)){ echo ","; } $i++; } } ?> );
Datei /system/classes/plugininfo.php:
<?PHP class PluginInfo{ public $path = ''; public $name = ''; public $description = ''; public $authorName = ''; public $authorLink = ''; public $version = ''; public $configurationFile = ''; function isActivated(){ $path = $GLOBALS['db']->EscapeString($this->path); $rowCount = $GLOBALS['db']->ReadField("SELECT COUNT(*) FROM {'dbprefix'}activated_plugins WHERE path = '".$path."'"); if($rowCount){ return $rowCount > 0; } else{ return false; } } function activate(){ $path = $GLOBALS['db']->EscapeString($this->path); @include("../system/plugins/".$path."/activate.php"); return $GLOBALS['db']->Execute("INSERT INTO {'dbprefix'}activated_plugins (path) VALUES ('".$path."')"); } function deactivate(){ $path = $GLOBALS['db']->EscapeString($this->path); @include("../system/plugins/".$path."/deactivate.php"); return $GLOBALS['db']->Execute("DELETE FROM {'dbprefix'}activated_plugins WHERE path = '".$path."'"); } } ?>
Datei /admin/includes/settings.php:
<h1>Einstellungen</h1> <?PHP if($_POST['save']){ foreach($_POST as $property=>$value){ if($property != "save"){ setSetting($property,$value); } } } ?> <form style="float:left;width:600px;" action="/admin/index.php?page=settings" method="POST"> <fieldset style="width:500px;"> <legend>Einstellungen ä;ndern</legend> <table style="width:100%"> <?PHP $rows = $GLOBALS['db']->ReadRows("SELECT * FROM {'dbprefix'}settings WHERE activated = 1"); if($rows){ foreach($rows as $row){ echo "<tr><td><label for="".htmlentities($row->property)."">"; echo $row->description.":"; echo "</label></td><td>"; $control = new $row->type; $control->name = $row->property; $control->value = $row->value; $control->display(); echo "</td></tr>"; } } ?> </table> <br /><input type="submit" name="save" value="Speichern" /> </fieldset> </form> <div style="margin-left:500px;"> <h2>Plugin-Einstellungen</h2> <?PHP $plugins = new PluginList(); $plugins->loadAll(); foreach($plugins->plugins as $plugin){ if($plugin->configurationFile != ''){ ?> <a href="/admin/index.php?page=plugin-settings&plugin=<?PHP echo $plugin->path; ?>"><?PHP echo $plugin->name; ?></a><br /> <?PHP } } ?> </div>
Und die dazugehörigen Funktionen /system/settings.php:
<?PHP function getSetting($property){ return $GLOBALS['db']->ReadField("SELECT value FROM {'dbprefix'}settings WHERE property = '".$property."'"); } function setSetting($property,$value){ $property = $GLOBALS['db']->EscapeString($property); $value = $GLOBALS['db']->EscapeString($value); return $GLOBALS['db']->Execute("UPDATE {'dbprefix'}settings SET value = '".$value."' WHERE property = '".$property."'"); } ?>
Datei /system/classes/skincontroller.php:
<?PHP class SkinController{ function getCurrentSkinId(){ return getSetting("selectedskin"); } function getCurrentSkinName(){ $res = $GLOBALS['db']->ReadField("SELECT name FROM {'dbprefix'}skins WHERE id = '".SkinController::getCurrentSkinId()."'"); if($res){ return $res; } else{ return "default"; } } function getCurrentSkinPath(){ return "system/skins/".SkinController::getCurrentSkinName(); } function getInstalledSkins(){ return $GLOBALS['db']->ReadRows("SELECT * FROM {'dbprefix'}skins"); } } ?>
Datei /system/classes/skinselector.php:
<?PHP class skinselector extends Control{ public function display(){ ?> <input type="hidden" name="<?PHP echo htmlentities($this->name); ?>" value="<?PHP echo htmlentities($this->value); ?>" /> <img id="btnLeft" OnClick="document.getElementsByName('<?PHP echo htmlentities($this->name); ?>')[0].value--; document.getElementById('skinpreview').src='/system/skins/' + skins[document.getElementsByName('<?PHP echo htmlentities($this->name); ?>')[0].value-1]['name'] + '/screenshot.jpg'; document.getElementById('btnRight').style.visibility='visible'; if(1 == document.getElementsByName('<?PHP echo htmlentities($this->name); ?>')[0].value){ document.getElementById('btnLeft').style.visibility='hidden' };" src="/system/images/btnLeft.gif" /> <img id="skinpreview" style="border:1px solid #aaa" src="/system/skins/<?PHP echo SkinController::getCurrentSkinName(); ?>/screenshot.jpg" /> <img id="btnRight" OnClick="document.getElementsByName('<?PHP echo htmlentities($this->name); ?>')[0].value++; document.getElementById('skinpreview').src='/system/skins/' + skins[document.getElementsByName('<?PHP echo htmlentities($this->name); ?>')[0].value-1]['name'] + '/screenshot.jpg'; if(skins.length == document.getElementsByName('<?PHP echo htmlentities($this->name); ?>')[0].value){ document.getElementById('btnRight').style.visibility='hidden'; } document.getElementById('btnLeft').style.visibility='visible';" src="/system/images/btnRight.gif" /> <script language="JavaScript"> var skins = new Array(); <?PHP $i = 0; foreach(SkinController::getInstalledSkins() as $skin){ echo "skins[".$i."] = new Object();"; echo "skins[".$i."]["id"] = "".$skin->id."";"; echo "skins[".$i."]["name"] = "".$skin->name."";"; $i++; } ?> if(skins.length == document.getElementsByName('<?PHP echo htmlentities($this->name); ?>')[0].value){ document.getElementById('btnRight').style.visibility='hidden'; } if(1 == document.getElementsByName('<?PHP echo htmlentities($this->name); ?>')[0].value){ document.getElementById('btnLeft').style.visibility='hidden'; } </script> <?PHP } } ?>
Und zu guter letzt /system/classes/menueselector.php:
<?PHP class menueselector extends Control{ public function display(){ echo "<select name="".$this->name."">"; foreach(sys::getMenues() as $menue){ if($menue->id == $this->value){ echo "<option value="".$menue->id."" selected="1">".$menue->name."</option>"; } else{ echo "<option value="".$menue->id."">".$menue->name."</option>"; } } echo "</select>"; } } ?>
Du arbeitest in einer Agentur oder als Freelancer?
Dann wirf doch mal einen Blick auf unsere Software FeatValue.
Über uns
Wir entwickeln Webanwendungen mit viel Leidenschaft. Unser Wissen geben wir dabei gerne weiter. Mehr über a coding project