1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| <?php
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
$_MAMBOTS->registerFunction( 'onPrepareContent', 'plg_vehicules' );
function plg_vehicules($published, &$row, &$params, $page=0 ) {
if (!$published) {
$row->text = preg_replace( "#{tableau_vehicule}#s", "" , $row->text );
$row->text = preg_replace( "#{resume_vehicule}#s", "" , $row->text );
return;
}
// Variables
global $database, $mainframe, $option, $task, $mosConfig_lang, $mosConfig_absolute_path, $mosConfig_live_site, $my, $Itemid;
$query = "SELECT id FROM #__mambots WHERE element = 'plugin_vehicules' AND folder = 'content'";
$database->setQuery( $query );
$id = $database->loadResult();
$mambot = new mosMambot( $database );
$mambot->load( $id );
$params =& new mosParameters( $mambot->params );
$alternate = $params->get('alternate', 0);
$table_class = $params->get('table_class', '');
if (preg_match_all("#{tableau_vehicule}#s", $row->text, $matches, PREG_PATTERN_ORDER) > 0)
{
// Génération du tableau
$champs = array("Chassis"=>'chassis', "Type"=>'type', "Motorisation"=>'motorisation', "Mise en circulation"=>'mise_en_circulation', "P.T.A.C."=>'ptac', "Puissance administrative"=>'puissance_administrative', "Nb. couchages"=>'nb_couchages', "Nb. places sur carte grise"=>'nb_places_cg', "Nb. places (repas)"=>'nb_places', "Kilométrage"=>'kilometrage', "Longueur"=>'longueur', "Largeur"=>'largeur', "Hauteur"=>'hauteur', "Tarif"=>'tarif');
$html = "";
$one = true;
$nb = 0;
foreach($champs as $key=>$champ)
{
if(!empty($row->$champ))
{
if($one)
{
$html .= "<table border=\"0\" class=\"" . $table_class . "\" cellspacing=\"0\" cellpadding=\"0\">\r\n";
$one = false;
}
$html .= "<tr" . ($alternate ? " class=\"" . ($nb%2 == 1 ? "odd" : "even") . "\"" : "") . "><td class=\"key\">" . $key . "</td><td class=\"value\">" . ($champ == 'type' ? substr($row->$champ, 2) : $row->$champ) . "</td></tr>\r\n";
$nb++;
}
}
if(!$one)
$html .= "</table>";
foreach ($matches[0] as $match)
{
$row->text = preg_replace( "#{tableau_vehicule}#s", $html , $row->text);
}
}
if (preg_match_all("#{resume_vehicule}#s", $row->text, $matches, PREG_PATTERN_ORDER) > 0)
{
// Génération du tableau
$html = "<div class=\"resume_vehicule_header\" ></div>";
$html .= "<div align=\"left\" class=\"resume_vehicule_titre\" ><H5>" . $row->title . "</H5></DIV>";
$html .= '<div style="text-align: center"><img title="' . $row->nom_vehicule . '" style="border: #000000 1px solid; margin: 5px;" alt="' . $row->nom_vehicule . '" src="/images/stories/vehicules/' . $row->id . '/vignette.jpg" align="middle" /></div>';
$html .= "<DIV align=\"center\">";
if(empty($row->chassis)) {
if(!empty($row->motorisation)) {
$html .= $row->motorisation;
}
}
else {
$html .= $row->chassis;
if(!empty($row->motorisation)) {
$html .= " , " . $row->motorisation;
}
}
$html .= "</div>";
$html .= "<DIV align=\"center\">" . (empty($row->mise_en_circulation) ? "" : (strtotime($row->mise_en_circulation) != 0 ? "Année ".date("Y", strtotime($row->mise_en_circulation)) : $row->mise_en_circulation)) . "</DIV>";
$html .= "<div class=\"resume_vehicule_footer\"><SPAN class=\"prix\">Prix : <SPAN class=\"prix_numeraire\">" . (empty($row->tarif) ? "nous contacter" : $row->tarif) . "</SPAN></SPAN></div>";
foreach ($matches[0] as $match)
{
$row->text = preg_replace( "#{resume_vehicule}#s", $html , $row->text);
}
}
if (preg_match_all("#{vignette_vehicule}#s", $row->text, $matches, PREG_PATTERN_ORDER) > 0)
{
if(file_exists('images/stories/vehicules/' . $row->id . '/vignette.jpg'))
$html = '<div style="text-align: center"><img title="' . $row->nom_vehicule . '" style="border: #000000 1px solid; margin: 5px;" alt="' . $row->nom_vehicule . '" src="/images/stories/vehicules/' . $row->id . '/vignette.jpg" align="middle" /></div>';
else
$html = '';
foreach ($matches[0] as $match)
{
$html = "";
$row->text = preg_replace( "#{vignette_vehicule}#s", $html , $row->text);
}
}
if (preg_match_all("#{image_vehicule}#s", $row->text, $matches, PREG_PATTERN_ORDER) > 0)
{
if(file_exists('images/stories/vehicules/' . $row->id . '/vignette.jpg'))
$html = '<div style="text-align: center"><img title="' . $row->nom_vehicule . '" style="border: #000000 1px solid; margin: 5px;" alt="' . $row->nom_vehicule . '" src="/images/stories/vehicules/' . $row->id . '/principale.jpg" align="middle" /></div>';
else
$html = '';
foreach ($matches[0] as $match)
{
$row->text = preg_replace( "#{image_vehicule}#s", $html , $row->text);
}
}
if (preg_match_all("#{photo_vehicule}#s", $row->text, $matches, PREG_PATTERN_ORDER) > 0)
{
if(file_exists('images/stories/vehicules/' . $row->id . '/vignette.jpg'))
$html = '<div style="text-align: center"><img title="' . $row->nom_vehicule . '" style="border: #000000 1px solid; margin: 5px;" alt="' . $row->nom_vehicule . '" src="/images/stories/vehicules/' . $row->id . '/principale.jpg" align="middle" /></div>';
else
$html = '';
foreach ($matches[0] as $match)
{
$row->text = preg_replace( "#{photo_vehicule}#s", $html , $row->text);
}
}
if (preg_match_all("#{galerie_vehicule}#s", $row->text, $matches, PREG_PATTERN_ORDER) > 0)
{
$photos = 0;
$html = "";
if(file_exists('images/stories/vehicules/' . $row->id . '/galerie/'))
{
$dir_handle = opendir('images/stories/vehicules/' . $row->id . "/galerie/");
while($entry = readdir($dir_handle))
if(is_file('images/stories/vehicules/' . $row->id . "/galerie/" . $entry))
$photos++;
closedir($dir_handle);
}
if($photos != 0)
$html = '{gallery}vehicules/' . $row->id . '/galerie{/gallery}';
foreach ($matches[0] as $match)
{
$row->text = preg_replace( "#{galerie_vehicule}#s", $html , $row->text);
}
}
}
?> |
Partager