Ajout de la fonctionnalité d'ajout de lien dans la reserve

This commit is contained in:
Chouchen 2010-09-24 17:59:16 +00:00
parent 3f3a219861
commit 2861556131
5 changed files with 70 additions and 1 deletions

58
addLink.php Normal file
View File

@ -0,0 +1,58 @@
<?php
$url = $_POST['urlField'];
$popup = $_POST['popupField'];
$img = $_FILES['imgField'];
$title = $_POST['titreField'];
// Préparation de l'image2
$content_dir = 'images/links/'; // dossier où sera déplacé le fichier
$tmp_file = $img['tmp_name']; // Fichier temporaire
// Vérification de l'upload
if( !is_uploaded_file($tmp_file) )
{
exit("Le fichier est introuvable");
}
// on vérifie maintenant l'extension
$type_file = $img['type'];
if( !strstr($type_file, 'jpg') && !strstr($type_file, 'jpeg') && !strstr($type_file, 'png') && !strstr($type_file, 'gif') )
{
exit("Le fichier n'est pas une image");
}
// on copie le fichier dans le dossier de destination
$name_file = $img['name'];
if( preg_match('#[\x00-\x1F\x7F-\x9F/\\\\]#', $name_file) )
{
exit("Nom de fichier non valide");
}
else if( !move_uploaded_file($tmp_file, $content_dir . $name_file) )
{
exit("Impossible de copier le fichier dans $content_dir");
}
$doc = new DOMDocument;
$doc->load('db/links.xml');
$xpath = new DOMXpath($doc);
// Creating new node
$newNode = $doc->createElement('link');
$newURL = $doc->createElement('url', $url);
if($popup == '1')
$newClick = $doc->createElement('onclick', 'popup');
else
$newClick = $doc->createElement('onclick', '');
$newImg = $doc->createElement('img', $name_file);
$newTitle = $doc->createElement('title', $title);
$newNode->appendChild($newURL);
$newNode->appendChild($newClick);
$newNode->appendChild($newImg);
$newNode->appendChild($newTitle);
$searchLabel = $xpath->query('reserve');
$searchLabel->item(0)->appendChild($newNode);
$doc->save('db/links.xml');

View File

@ -13,6 +13,7 @@ class links {
$this->setParams($params);
echo '<script type="text/javascript" src="js/jquery.links.js"></script>
<link rel="stylesheet" href="css/links.css" type="text/css" />
<div style="display:none;"><div id="links-add-fancy"></div></div>
<div class="appscontainer">';
if($links_xml = simplexml_load_file(self::LINKS_FILE)){
$links = $links_xml->label;

View File

@ -76,7 +76,7 @@
#recherche{margin-top:70px;}
#config {width:300px;}
#config-menu, #blog-links-manager, #city-menu , #jclockAdvanced-menu, #links-menu, #ouifm-menu{float:right; margin:12px 10px 0 0;}
#config-menu, #blog-links-manager, #city-menu , #jclockAdvanced-menu, #links-menu, #links-add-menu,#ouifm-menu{float:right; margin:12px 10px 0 0;}
#ouifm{position:absolute;width:144px;height:28px;}
/* Green button class: */

Binary file not shown.

After

Width:  |  Height:  |  Size: 570 B

View File

@ -1,8 +1,18 @@
$(document).ready(function(){
// Réglage des options
$('body').append('<img src="images/interface/link_edit.png" id="links-menu" />');
$('body').append('<img src="images/interface/link_add.png" id="links-add-menu" />');
$('#menu-bar').prepend($('#links-menu'));
$('#menu-bar').prepend($('#links-add-menu'));
$('#links-add-fancy').append('<form action="addLink.php" enctype="multipart/form-data" method="POST"><label for="urlField">URL : </label><input type="text" name="urlField" id="urlField"/><br/><label for="popupField">popup ? </label><input type="checkbox" name="popupField" id="popupField" checked="checked" value="1" /><br/><label for="imgField">Icône : </label><input type="file" name="imgField" id="imgField"/><br/><label for="titreField">Titre : </label><input type="text" name="titreField" id="titreField"/><br/><input type="submit" class="green-button" id="links-add-submit" value="Envoyer"/></form>');
// Apparition du menu d'ajout de lien
$('#links-add-menu').live('click', function(){
$.fancybox(
$('#links-add-fancy').html()
);
});
// Apparition de la reserve de liens
$('#links-menu').live('click', function(){
$.get('ajax/loadReserve.php', function(html){