Beispiel #1
0
 /**
  * Méthode qui crée un nouveau commentaire pour l'article $artId
  *
  * @param	artId	identifiant de l'article en question
  * @param	content	tableau contenant les valeurs du nouveau commentaire
  * @return	string
  * @author	Florent MONTHEL, Stéphane F
  **/
 public function newCommentaire($artId, $content)
 {
     # Hook plugins
     if (eval($this->plxPlugins->callHook('plxMotorNewCommentaire'))) {
         return;
     }
     if (strtolower($_SERVER['REQUEST_METHOD']) != 'post' or !isset($_SESSION["capcha_token"]) or !isset($_POST['capcha_token']) or $_SESSION["capcha_token"] != $_POST['capcha_token']) {
         return L_NEWCOMMENT_ERR_ANTISPAM;
     }
     # On vérifie que le capcha est correct
     if ($this->aConf['capcha'] == 0 or $_SESSION['capcha'] == sha1($content['rep'])) {
         if (!empty($content['name']) and !empty($content['content'])) {
             # Les champs obligatoires sont remplis
             $comment = array();
             $comment['type'] = 'normal';
             $comment['author'] = plxUtils::strCheck(trim($content['name']));
             $comment['content'] = plxUtils::strCheck(trim($content['content']));
             # On vérifie le mail
             $comment['mail'] = plxUtils::checkMail(trim($content['mail'])) ? trim($content['mail']) : '';
             # On vérifie le site
             $comment['site'] = plxUtils::checkSite($content['site']) ? $content['site'] : '';
             # On récupère l'adresse IP du posteur
             $comment['ip'] = plxUtils::getIp();
             # index du commentaire
             $idx = $this->nextIdArtComment($idArt);
             # Commentaire parent en cas de réponse
             if (isset($content['parent']) and !empty($content['parent'])) {
                 $comment['parent'] = intval($content['parent']);
             } else {
                 $comment['parent'] = '';
             }
             # On génère le nom du fichier
             $time = time();
             if ($this->aConf['mod_com']) {
                 # On modère le commentaire => underscore
                 $comment['filename'] = '_' . $artId . '.' . $time . '-' . $idx . '.xml';
             } else {
                 # On publie le commentaire directement
                 $comment['filename'] = $artId . '.' . $time . '-' . $idx . '.xml';
             }
             # On peut créer le commentaire
             if ($this->addCommentaire($comment)) {
                 # Commentaire OK
                 if ($this->aConf['mod_com']) {
                     # En cours de modération
                     return 'mod';
                 } else {
                     # Commentaire publie directement, on retourne son identifiant
                     return 'c' . $artId . '-' . $idx;
                 }
             } else {
                 # Erreur lors de la création du commentaire
                 return L_NEWCOMMENT_ERR;
             }
         } else {
             # Erreur de remplissage des champs obligatoires
             return L_NEWCOMMENT_FIELDS_REQUIRED;
         }
     } else {
         # Erreur de vérification capcha
         return L_NEWCOMMENT_ERR_ANTISPAM;
     }
 }
 /**
  * Méthode qui effectue une mise a jour d'un commentaire
  *
  * @param	content	données du commentaire à mettre à jour
  * @param	id	identifiant du commentaire
  * @return	string
  * @author	Stephane F. et Florent MONTHEL
  **/
 public function editCommentaire($content, &$id)
 {
     # Vérification de la validité de la date de publication
     if (!plxDate::checkDate($content['day'], $content['month'], $content['year'], $content['time'])) {
         return plxMsg::Error(L_ERR_INVALID_PUBLISHING_DATE);
     }
     $comment = array();
     # Génération du nom du fichier
     $comment['filename'] = $id . '.xml';
     if (!file_exists(PLX_ROOT . $this->aConf['racine_commentaires'] . $comment['filename'])) {
         # Commentaire inexistant
         return plxMsg::Error(L_ERR_UNKNOWN_COMMENT);
     }
     # Contrôle des saisies
     if (trim($content['mail']) != '' and !plxUtils::checkMail(trim($content['mail']))) {
         return plxMsg::Error(L_ERR_INVALID_EMAIL);
     }
     if (trim($content['site']) != '' and !plxUtils::checkSite($content['site'])) {
         return plxMsg::Error(L_ERR_INVALID_SITE);
     }
     # On récupère les infos du commentaire
     $com = $this->parseCommentaire(PLX_ROOT . $this->aConf['racine_commentaires'] . $comment['filename']);
     # Formatage des données
     $comment['author'] = plxUtils::strCheck(trim($content['author']));
     $comment['site'] = plxUtils::strCheck(trim($content['site']));
     if ($com['type'] != 'admin') {
         $comment['content'] = plxUtils::strCheck(trim($content['content']));
     } else {
         $comment['content'] = strip_tags(trim($content['content']), '<a>,<strong>');
     }
     $comment['ip'] = $com['ip'];
     $comment['type'] = $com['type'];
     $comment['mail'] = $content['mail'];
     $comment['site'] = $content['site'];
     $comment['parent'] = $com['parent'];
     # Génération du nouveau nom du fichier
     $time = explode(':', $content['time']);
     $newtimestamp = mktime($time[0], $time[1], 0, $content['month'], $content['day'], $content['year']);
     $com = $this->comInfoFromFilename($id . '.xml');
     $newid = $com['comStatus'] . $com['artId'] . '.' . $newtimestamp . '-' . $com['comIdx'];
     $comment['filename'] = $newid . '.xml';
     # Suppression de l'ancien commentaire
     $this->delCommentaire($id);
     # Création du nouveau commentaire
     $id = $newid;
     if ($this->addCommentaire($comment)) {
         return plxMsg::Info(L_COMMENT_SAVE_SUCCESSFUL);
     } else {
         return plxMsg::Error(L_COMMENT_UPDATE_ERR);
     }
 }
 /**
  * Méthode qui retourne l'url de base du site
  *
  * @return	string		url de base du site
  **/
 public static function getRacine()
 {
     $protocol = (!empty($_SERVER['HTTPS']) and strtolower($_SERVER['HTTPS']) == 'on') || (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) and strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https') ? 'https://' : "http://";
     $servername = $_SERVER['HTTP_HOST'];
     $serverport = (preg_match('/:[0-9]+/', $servername) or $_SERVER['SERVER_PORT']) == '80' ? '' : ':' . $_SERVER['SERVER_PORT'];
     $dirname = preg_replace('/\\/(core|plugins)\\/(.*)/', '', dirname($_SERVER['SCRIPT_NAME']));
     $racine = rtrim($protocol . $servername . $serverport . $dirname, '/\\') . '/';
     if (!plxUtils::checkSite($racine, false)) {
         die('Error: wrong or invalid url');
     }
     return $racine;
 }
Beispiel #4
0
 /**
  * Méthode qui édite le fichier XML des produits selon le tableau $content
  *
  * @param    content    tableau multidimensionnel des produits
  * @param    action    permet de forcer la mise àjour du fichier
  * @return    string
  * @author    David L.
  **/
 public function editProducts($content, $action = false)
 {
     $save = $this->aProds;
     # suppression
     if (!empty($content['selection']) and $content['selection'] == 'delete' and isset($content['idProduct'])) {
         foreach ($content['idProduct'] as $product_id) {
             $filename = PLX_ROOT . 'data/products/' . $product_id . '.' . $this->aProds[$product_id]['url'] . '.php';
             if (is_file($filename)) {
                 unlink($filename);
             }
             # si le produit supprimée est en page d'accueil on met à jour le parametre
             unset($this->aProds[$product_id]);
             $action = true;
         }
     } elseif (!empty($content['update'])) {
         foreach ($content['productNum'] as $product_id) {
             $stat_name = $content[$product_id . '_name'];
             if ($stat_name != '') {
                 $url = isset($content[$product_id . '_url']) ? trim($content[$product_id . '_url']) : '';
                 $stat_url = $url != '' ? plxUtils::title2url($url) : plxUtils::title2url($stat_name);
                 if ($stat_url == '') {
                     $stat_url = L_DEFAULT_NEW_PRODUCT_URL;
                 }
                 # On vérifie si on a besoin de renommer le fichier du produit
                 if (isset($this->aProds[$product_id]) and $this->aProds[$product_id]['url'] != $stat_url) {
                     $oldfilename = PLX_ROOT . 'data/products/' . $product_id . '.' . $this->aProds[$product_id]['url'] . '.php';
                     $newfilename = PLX_ROOT . 'data/products/' . $product_id . '.' . $stat_url . '.php';
                     if (is_file($oldfilename)) {
                         rename($oldfilename, $newfilename);
                     }
                 }
                 $this->aProds[$product_id]['pcat'] = trim($content[$product_id . '_pcat']);
                 $this->aProds[$product_id]['menu'] = trim($content[$product_id . '_menu']);
                 $this->aProds[$product_id]['group'] = isset($this->aProds[$product_id]['group']) ? $this->aProds[$product_id]['group'] : '';
                 $this->aProds[$product_id]['name'] = $stat_name;
                 $this->aProds[$product_id]['url'] = plxUtils::checkSite($url) ? $url : $stat_url;
                 $this->aProds[$product_id]['active'] = $content[$product_id . '_active'];
                 $this->aProds[$product_id]['ordre'] = intval($content[$product_id . '_ordre']);
                 $this->aProds[$product_id]['template'] = isset($this->aProds[$product_id]['template']) ? $this->aProds[$product_id]['template'] : $this->getParam('template');
                 $this->aProds[$product_id]['title_htmltag'] = isset($this->aProds[$product_id]['title_htmltag']) ? $this->aProds[$product_id]['title_htmltag'] : '';
                 $this->aProds[$product_id]['image'] = isset($this->aProds[$product_id]['image']) ? $this->aProds[$product_id]['image'] : '';
                 $this->aProds[$product_id]['noaddcart'] = isset($this->aProds[$product_id]['noaddcart']) ? $this->aProds[$product_id]['noaddcart'] : '';
                 $this->aProds[$product_id]['notice_noaddcart'] = isset($this->aProds[$product_id]['notice_noaddcart']) ? $this->aProds[$product_id]['notice_noaddcart'] : '';
                 $this->aProds[$product_id]['pricettc'] = isset($this->aProds[$product_id]['pricettc']) ? $this->aProds[$product_id]['pricettc'] : '';
                 $this->aProds[$product_id]['poidg'] = isset($this->aProds[$product_id]['poidg']) ? $this->aProds[$product_id]['poidg'] : '';
                 $this->aProds[$product_id]['meta_description'] = isset($this->aProds[$product_id]['meta_description']) ? $this->aProds[$product_id]['meta_description'] : '';
                 $this->aProds[$product_id]['meta_keywords'] = isset($this->aProds[$product_id]['meta_keywords']) ? $this->aProds[$product_id]['meta_keywords'] : '';
                 $action = true;
             }
         }
         # On va trier les clés selon l'ordre choisi
         if (sizeof($this->aProds) > 0) {
             uasort($this->aProds, create_function('$a, $b', 'return $a["ordre"]>$b["ordre"];'));
         }
     }
     # sauvegarde
     if ($action) {
         //var_dump($content); exit;
         $products_name = array();
         $products_url = array();
         # On génére le fichier XML
         $xml = "<?xml version=\"1.0\" encoding=\"" . PLX_CHARSET . "\"?>\n";
         $xml .= "<document>\n";
         if (isset($this->aProds) && is_array($this->aProds)) {
             foreach ($this->aProds as $product_id => $product) {
                 # control de l'unicité du titre de la page
                 if (in_array($product['name'], $products_name)) {
                     return plxMsg::Error(L_ERR_PRODUCT_ALREADY_EXISTS . ' : ' . plxUtils::strCheck($product['name']));
                 } else {
                     $products_name[] = $product['name'];
                 }
                 # control de l'unicité de l'url de la page
                 if (in_array($product['url'], $products_url)) {
                     $this->aProds = $save;
                     return plxMsg::Error(L_ERR_URL_ALREADY_EXISTS . ' : ' . plxUtils::strCheck($product['url']));
                 } else {
                     $products_url[] = $product['url'];
                 }
                 $xml .= "\t<product number=\"" . $product_id . "\" active=\"" . $product['active'] . "\" url=\"" . $product['url'] . "\" template=\"" . basename($product['template']) . "\">";
                 $xml .= "<pcat><![CDATA[" . plxUtils::cdataCheck($product['pcat']) . "]]></pcat>";
                 $xml .= "<menu><![CDATA[" . plxUtils::cdataCheck($product['menu']) . "]]></menu>";
                 $xml .= "<group><![CDATA[" . plxUtils::cdataCheck($product['group']) . "]]></group>";
                 $xml .= "<name><![CDATA[" . plxUtils::cdataCheck($product['name']) . "]]></name>";
                 $xml .= "<image><![CDATA[" . plxUtils::cdataCheck($product['image']) . "]]></image>";
                 $xml .= "<noaddcart><![CDATA[" . plxUtils::cdataCheck($product['noaddcart']) . "]]></noaddcart>";
                 $xml .= "<notice_noaddcart><![CDATA[" . plxUtils::cdataCheck($product['notice_noaddcart']) . "]]></notice_noaddcart>";
                 $xml .= "<pricettc><![CDATA[" . plxUtils::cdataCheck($product['pricettc']) . "]]></pricettc>";
                 $xml .= "<poidg><![CDATA[" . plxUtils::cdataCheck($product['poidg'] == 0 ? "0.0" : $product['poidg']) . "]]></poidg>";
                 $xml .= "<meta_description><![CDATA[" . plxUtils::cdataCheck($product['meta_description']) . "]]></meta_description>";
                 $xml .= "<meta_keywords><![CDATA[" . plxUtils::cdataCheck($product['meta_keywords']) . "]]></meta_keywords>";
                 $xml .= "<title_htmltag><![CDATA[" . plxUtils::cdataCheck($product['title_htmltag']) . "]]></title_htmltag>";
                 # Hook plugins
                 //eval($this->plxPlugins->callHook('plxAdminEditProductsXml'));
                 $xml .= "</product>\n";
             }
         }
         $xml .= "</document>";
         # On écrit le fichier si une action valide a été faite
         if (plxUtils::write($xml, PLX_ROOT . PLX_CONFIG_PATH . 'products.xml')) {
             return plxMsg::Info(L_SAVE_SUCCESSFUL);
         } else {
             $this->aProds = $save;
             return plxMsg::Error(L_SAVE_ERR . ' ' . PLX_ROOT . PLX_CONFIG_PATH . 'products.xml');
         }
     }
 }
Beispiel #5
0
 /**
  * Méthode qui affiche la liste des pages statiques.
  *
  * @param	extra			si renseigné: nom du lien vers la page d'accueil affiché en première position
  * @param	format			format du texte pour chaque page (variable : #static_id, #static_status, #static_url, #static_name, #group_id, #group_class, #group_name)
  * @param	format_group	format du texte pour chaque groupe (variable : #group_class, #group_name)
  * @param	menublog		position du menu Blog (si non renseigné le menu n'est pas affiché)
  * @return	stdout
  * @scope	global
  * @author	Stephane F
  **/
 public function staticList($extra = '', $format = '<li id="#static_id" class="#static_class"><a href="#static_url" class="#static_status" title="#static_name">#static_name</a></li>', $format_group = '<span class="#group_class">#group_name</span>', $menublog = false)
 {
     $menus = array();
     # Hook Plugins
     if (eval($this->plxMotor->plxPlugins->callHook('plxShowStaticListBegin'))) {
         return;
     }
     $home = ((empty($this->plxMotor->get) or preg_match('/^page[0-9]*/', $this->plxMotor->get)) and basename($_SERVER['SCRIPT_NAME']) == "index.php");
     # Si on a la variable extra, on affiche un lien vers la page d'accueil (avec $extra comme nom)
     if ($extra != '') {
         $stat = str_replace('#static_id', 'static-home', $format);
         $stat = str_replace('#static_class', 'static-group', $stat);
         $stat = str_replace('#static_url', $this->plxMotor->urlRewrite(), $stat);
         $stat = str_replace('#static_name', plxUtils::strCheck($extra), $stat);
         $stat = str_replace('#static_status', $home == true ? "active" : "noactive", $stat);
         $menus[][] = $stat;
     }
     if ($this->plxMotor->aStats) {
         foreach ($this->plxMotor->aStats as $k => $v) {
             if ($v['active'] == 1 and $v['menu'] == 'oui') {
                 # La page  est bien active et dispo ds le menu
                 $stat = str_replace('#static_id', 'static-' . intval($k), $format);
                 $stat = str_replace('#static_class', 'static-menu', $stat);
                 if ($v['url'][0] == '?') {
                     # url interne commençant par ?
                     $stat = str_replace('#static_url', $this->plxMotor->urlRewrite($v['url']), $stat);
                 } elseif (plxUtils::checkSite($v['url'], false)) {
                     # url externe en http ou autre
                     $stat = str_replace('#static_url', $v['url'], $stat);
                 } else {
                     # url page statique
                     $stat = str_replace('#static_url', $this->plxMotor->urlRewrite('?static' . intval($k) . '/' . $v['url']), $stat);
                 }
                 $stat = str_replace('#static_name', plxUtils::strCheck($v['name']), $stat);
                 $stat = str_replace('#static_status', ($home === false and $this->staticId() == intval($k)) ? 'static active' : 'noactive', $stat);
                 if ($v['group'] == '') {
                     $menus[][] = $stat;
                 } else {
                     $menus[$v['group']][] = $stat;
                 }
             }
         }
     }
     if ($menublog) {
         if ($this->plxMotor->aConf['homestatic'] != '' and isset($this->plxMotor->aStats[$this->plxMotor->aConf['homestatic']])) {
             if ($this->plxMotor->aStats[$this->plxMotor->aConf['homestatic']]['active']) {
                 $menu = str_replace('#static_id', 'page-blog', $format);
                 if ($this->plxMotor->get and preg_match('/^(blog|categorie|archives|tag|article)/', $_SERVER['QUERY_STRING'])) {
                     $menu = str_replace('#static_status', 'active', $menu);
                 } else {
                     $menu = str_replace('#static_status', 'noactive', $menu);
                 }
                 $menu = str_replace('#static_url', $this->plxMotor->urlRewrite('?blog'), $menu);
                 $menu = str_replace('#static_name', L_PAGEBLOG_TITLE, $menu);
                 $menu = str_replace('#static_class', '', $menu);
                 array_splice($menus, intval($menublog) - 1, 0, array($menu));
             }
         }
     }
     # Hook Plugins
     if (eval($this->plxMotor->plxPlugins->callHook('plxShowStaticListEnd'))) {
         return;
     }
     # Affichage des pages statiques + menu Accueil et Blog
     if ($menus) {
         foreach ($menus as $k => $v) {
             if (is_numeric($k)) {
                 echo "\n" . (is_array($v) ? $v[0] : $v);
             } else {
                 $group = str_replace('#group_id', 'static-group-' . plxUtils::title2url($k), $format_group);
                 $group = str_replace('#group_class', 'static group', $group);
                 $group = str_replace('#group_name', plxUtils::strCheck($k), $group);
                 echo "\n<li>\n\t" . $group . "\n\t<ul id=\"static-" . plxUtils::title2url($k) . "\">\t\t";
                 foreach ($v as $kk => $vv) {
                     echo "\n\t\t" . $vv;
                 }
                 echo "\n\t</ul>\n</li>\n";
             }
         }
         echo "\n";
     }
 }
Beispiel #6
0
     echo '<td>' . $k . '</td><td>';
     $selected = $plxAdmin->aConf['homestatic'] == $k ? ' checked="checked"' : '';
     echo '<input title="' . L_STATICS_PAGE_HOME . '" type="checkbox" name="homeStatic[]" value="' . $k . '"' . $selected . ' onclick="checkBox(\'' . $num . '\')" />';
     echo '</td><td>';
     plxUtils::printInput($k . '_group', plxUtils::strCheck($v['group']), 'text', '10-100');
     echo '</td><td>';
     plxUtils::printInput($k . '_name', plxUtils::strCheck($v['name']), 'text', '10-255');
     echo '</td><td>';
     plxUtils::printInput($k . '_url', $v['url'], 'text', '10-255');
     echo '</td><td>';
     plxUtils::printSelect($k . '_active', array('1' => L_YES, '0' => L_NO), $v['active']);
     echo '</td><td>';
     plxUtils::printInput($k . '_ordre', $ordre, 'text', '1-3');
     echo '</td><td>';
     plxUtils::printSelect($k . '_menu', array('oui' => L_DISPLAY, 'non' => L_HIDE), $v['menu']);
     if (!plxUtils::checkSite($v['url'])) {
         echo '</td><td>';
         echo '<a href="statique.php?p=' . $k . '" title="' . L_STATICS_SRC_TITLE . '">' . L_STATICS_SRC . '</a>';
         if ($v['active']) {
             echo '&nbsp;&nbsp;<a href="' . PLX_ROOT . '?static' . intval($k) . '/' . $v['url'] . '" title="' . L_STATIC_VIEW_PAGE . ' ' . plxUtils::strCheck($v['name']) . ' ' . L_STATIC_ON_SITE . '">' . L_VIEW . '</a>';
         }
         echo '</td></tr>';
     } elseif ($v['url'][0] == '?') {
         echo '</td><td><a href="' . $plxAdmin->urlRewrite($v['url']) . '" title="' . plxUtils::strCheck($v['name']) . '">' . L_VIEW . '</a></td></tr>';
     } else {
         echo '</td><td><a href="' . $v['url'] . '" title="' . plxUtils::strCheck($v['name']) . '">' . L_VIEW . '</a></td></tr>';
     }
 }
 # On récupère le dernier identifiant
 $a = array_keys($plxAdmin->aStats);
 rsort($a);
Beispiel #7
0
 /**
  * Méthode qui crée un nouveau commentaire pour l'article $artId
  *
  * @param	artId	identifiant de l'article en question
  * @param	content	tableau contenant les valeurs du nouveau commentaire
  * @return	string
  * @author	Florent MONTHEL
  **/
 public function newCommentaire($artId, $content)
 {
     # On verifie que le capcha est correct, si besoin est
     if ($this->aConf['capcha'] == 0 or $content['rep2'] == md5($this->plxCapcha->gds . $content['rep'])) {
         if (!empty($content['name']) and !empty($content['content'])) {
             # Les champs obligatoires sont remplis
             $author = plxUtils::strCheck(trim($content['name']));
             $contenu = plxUtils::strCheck(trim($content['content']));
             $date = time();
             # On verifie le mail
             $mail = plxUtils::checkMail(trim($content['mail'])) ? trim($content['mail']) : '';
             # On verifie le site
             $site = plxUtils::checkSite(trim($content['site'])) ? trim($content['site']) : '';
             # On recupere l'adresse IP du posteur
             $ip = plxUtils::getIp();
             # On genere le nom du fichier selon l'existence ou non d'un fichier du meme nom
             $i = 0;
             do {
                 # On boucle en testant l'existence du fichier (cas de plusieurs commentaires/sec pour un article)
                 $i++;
                 if ($this->aConf['mod_com']) {
                     # On modere le commentaire => underscore
                     $filename = PLX_ROOT . $this->aConf['racine_commentaires'] . '_' . $artId . '.' . $date . '-' . $i . '.xml';
                 } else {
                     # On publie le commentaire directement
                     $filename = PLX_ROOT . $this->aConf['racine_commentaires'] . $artId . '.' . $date . '-' . $i . '.xml';
                 }
             } while (file_exists($filename));
             # On peut creer le commentaire
             if ($this->addCommentaire($filename, $author, 'normal', $ip, $mail, $site, $contenu)) {
                 # Commentaire OK
                 if ($this->aConf['mod_com']) {
                     # En cours de moderation
                     return 'mod';
                 } else {
                     # Commentaire publie directement, on retourne son identifiant
                     return 'c' . $date . '-' . $i;
                 }
             } else {
                 # Erreur lors de la création du commentaire
                 return 'Une erreur s\'est produite lors de la publication de ce commentaire';
             }
         } else {
             # Erreur de remplissage des champs obligatoires
             return 'Merci de remplir tous les champs obligatoires requis';
         }
     } else {
         # Erreur de verification capcha
         return 'La v&eacute;rification anti-spam a &eacute;chou&eacute;';
     }
 }