Easy-Design.Net forum




Aide générale [PBT V4.1] Tutoriel - Créer un service "Pastbin-like"

Myster Membre non connecté

EDN Enraciné(e)

Rang

Avatar

Inscrit le : 19/01/2011 à 16h42

Messages: 871

Le 07/05/2016 à 18h47
Bonsoir,

Dans ce second tutoriel, vous allez pouvoir mettre en place un service "Pastbin-like", en gros c'est fait pour partager votre code HTMl, PHP, Javascript etc ...

1. Connectez-vous à PHPMyAdmin puis exécutez le code suivant:
Code SQL :
 
CREATE TABLE IF NOT EXISTS `phpboost_codes` (
`id` INT(6) NOT NULL,
  `titre` VARCHAR(255) NOT NULL,
  `texte` text NOT NULL,
  `pseudo` VARCHAR(255) NOT NULL,
  `language` VARCHAR(30) NOT NULL
) ENGINE=MyISAM AUTO_INCREMENT=15 DEFAULT CHARSET=latin1;
ALTER TABLE `phpboost_codes`
 ADD PRIMARY KEY (`id`);


Ensuite, créez un dossier nommé code à la racine de votre site, puis dans ce dossier, créez un fichier nommé index.php. Dans index.php veuillez mettre le code suivant:

Code PHP :
 
<?php
 
/*This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 ###################################################*/
define('PATH_TO_ROOT', '..');
//Début du chargement de l'environnement
include_once('../kernel/init.php');
 
//Chargement d'un fichier css, ici le fichier css du module news
define('ALTERNATIVE_CSS', 'design');
 
//Titre de la page, ici Accueil
define('TITLE', 'Vos codes');
 
//Chargement de l'environnement ( header )
require_once('../kernel/header.php');
 
//Chargement des fichiers de langue et autres
global $LANG, $CONFIG;
 
if (!AppContext::get_current_user()->check_level(User::MEMBER_LEVEL))
  {
    echo '<div class="question">Vous n'avez pas le niveau requis ! </div>';
  }
else
  {
?>
<p> RPG Maker MV France, vous rend facile le partage de code avec les autres utilisateurs, pour cela mettez votre code dans le formulaire ci-dessous et laissez la magie opérée</p>
<?php
    if (isset($_POST['envoyer']))
      {
        // Si le code est supérieur à  300 ko on affiche un message d'erreur.
           if (strlen($_POST['code'])>300000) {
           echo '<span class="error">Votre code est beaucoup trop grand.</span>';
          }
        elseif (!empty($_POST['titre']) AND !empty($_POST['code']))
          {
            $titre    = addslashes($_POST['titre']);
            $code     = addslashes(htmlspecialchars($_POST['code']));
            $language = addslashes($_POST['language']);
            $Sql->query_inject("INSERT INTO " . PREFIX . "codes (titre, texte, pseudo, language) VALUES('" . $titre . "','" . $code . " ', '" . $User->get_pseudo() . "', '" . $language . "')", __LINE__, __FILE__);
            $req_code  = PersistenceContext::get_querier()->select("SELECT id,titre,texte,pseudo
        FROM " . PREFIX . "codes WHERE pseudo = '" . $User->get_pseudo() . "' ORDER BY id DESC");
            $req_codes = $req_code->fetch();
            header('Location: http://rpgmakermv.fr/code/code.php?id='.$req_codes['id']);
          exit;
 
          }
        else
          {
            echo '<span class="error">Des champs sont manquants.</span>';
          }
      }
?>
<form action="" method="POST">
 
<center><label for="titre">Titre: <br/><input type="text" name="titre" id="titre" required></input></label><br/>
<label for="code">Code:<textarea id="code" name="code" rows="8" cols="40" class="" onblur=""></textarea></label>
<select id="codecontents" name ="language">
<option value="" selected="" disabled="">Choisissez le code</option>
<optgroup label="Texte">
<option value="text">Text</option>
<option value="sql">Sql</option>
<option value="xml">Xml</option>
</optgroup>
<optgroup label="PHPBoost">
<option value="bbcode">BBCode</option>
<option value="tpl">Template</option>
</optgroup>
<optgroup label="Script">
<option value="php">PHP</option>
<option value="asp">Asp</option>
<option value="python">Python</option>
<option value="perl">Perl</option>
<option value="ruby">Ruby</option>
<option value="bash">Bash</option>
</optgroup>
<optgroup label="Web">
<option value="html">Html</option>
<option value="css">Css</option>
<option value="javascript">Javascript</option>
</optgroup>
<optgroup label="Programmation">
<option value="c">C</option>
<option value="cpp">C++</option>
<option value="c#">C#</option>
<option value="d">D</option>
<option value="java">Java</option>
<option value="pascal">Pascal</option>
<option value="delphi">Delphi</option>
<option value="fortran">Fortran</option>
<option value="vb">Vb</option>
<option value="asm">Asm</option>
</optgroup>
</select><br/><br/>
<button type="submit" class="submit" name="envoyer">Envoyer mon code</button> </center></form> <br/><br/>
 
 
 
<?php
  }
include_once('../kernel/footer.php');
?>


Ensuite, toujours dans le dossier code, créez un fichier code.php et mettez-y ce contenu :

Code PHP :
 
<?php
 
/*This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 ###################################################*/
define('PATH_TO_ROOT', '..');
//Début du chargement de l'environnement
include_once('../kernel/init.php');
 
//Chargement d'un fichier css, ici le fichier css du module news
define('ALTERNATIVE_CSS', 'design');
 
define('TITLE', 'Votre code');
 
//Chargement de l'environnement ( header )
require_once('../kernel/header.php');
require_once('../kernel/lib/php/geshi/geshi.php');
 
//Chargement des fichiers de langue et autres
global $LANG, $CONFIG;
 
 
 
 
$identifiant = is_numeric($_GET['id']);
if (isset($identifiant) AND !empty($identifiant))
  {
    $req_code  = PersistenceContext::get_querier()->select("SELECT *
        FROM " . PREFIX . "codes WHERE id = " . $_GET['id'] . "");
    $req_codes = $req_code->fetch();
 
    $identifiantvalide = $req_codes['id'];
    $code              = $req_codes['texte'];
    $language          = $req_codes['language'];
    $geshi             = new GeSHi(htmlspecialchars_decode($code), $language);
    if ($identifiant == $identifiantvalide)
      {
        echo 'Nom du code: <b>' . $req_codes['titre'] . '</b> dans le language: <b>' . $req_codes['language'] . '</b> par <b>' . $req_codes['pseudo'] . '</b><br/><br/>';
        echo '<div class="code"><pre style="display:inline;">' . $geshi->parse_code() . '</pre></div>';
      }
    else
      {
        echo '<span class="error">Identifiant incorrect</span>';
      }
  }
else
  {
    echo '<span class="error">Il manque un paramètre dans votre adresse URL.</span>';
  }
?>
 
<?php
 
include_once('../kernel/footer.php');
?>


Voilà c'est déjà fini, vous avez désormais un service de "Pastbin-like" pour votre site boosté par PHPBoost v4.1

Et pour finir deux screens:



   
m-ickael Membre non connecté

EDN Maitre-Sage

Rang

Avatar

Inscrit le : 23/02/2010 à 09h15

Messages: 2296

Le 07/05/2016 à 19h01
Merci beau boulot :top
Myster Membre non connecté

EDN Enraciné(e)

Rang

Avatar

Inscrit le : 19/01/2011 à 16h42

Messages: 871

Le 07/05/2016 à 19h03
Merci :) Le prochain ça sera pour créer des badges, genre par exemple, si X posts sur le forum le membre gagne le badge, pareil pour le livre d'or, la zone de téléchargement etc :)
   
m-ickael Membre non connecté

EDN Maitre-Sage

Rang

Avatar

Inscrit le : 23/02/2010 à 09h15

Messages: 2296

Le 07/05/2016 à 19h32
:top
Myster Membre non connecté

EDN Enraciné(e)

Rang

Avatar

Inscrit le : 19/01/2011 à 16h42

Messages: 871

Le 07/05/2016 à 20h55
Pour obtenir les numéros de lignes,

dans le fichier code.php sous :

Code PHP :
$geshi             = new GeSHi(htmlspecialchars_decode($code), $language);


ajoutez:

Code PHP :
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
   
Swan Membre non connecté

Administrateur

Rang

Avatar

Inscrit le : 01/08/2009 à 22h53

Messages: 8431

Le 07/05/2016 à 21h12
pas mal ^^


swan_signature

Site web    
Myster Membre non connecté

EDN Enraciné(e)

Rang

Avatar

Inscrit le : 19/01/2011 à 16h42

Messages: 871

Le 08/05/2016 à 14h25
Merci :D
   
Répondre
Vous n'êtes pas autorisé à écrire dans cette catégorie