Comunidad de diseño web y desarrollo en internet online

Problema con mi formulario PHP.

Citar            
MensajeEscrito el 10 Ago 2012 03:26 pm
Hola todos.
Tengo un detalle que solucionar con mi formulario.
Tengo 2 formularios en la página web que estoy creando para mi mismo. Los formularios me llegan bien, menos el Elemento de "Adjuntar Archivos" (input type="file").
A continuación adjunto los archivos el código generado por WebSitex5evolution.

Gracias de antemano.
Rubén Morales.

contacto.html----------------------------------------------------------------------------------------------------------------------------

<form id="imObjectForm_1" action="mail/imEmailForm_y5d9k2iu.php" method="post" enctype="multipart/form-data" style="width: 457px; margin: 0; padding: 0; text-align: left;">
<fieldset class="first">
<div>
<div style="float: left; margin: 0; padding: 0 0 2px;"><label for="imObjectForm_1_1" style="vertical-align: top; display: inline-block; margin: 3px 0 2px; width: 443px;">Nombre y Apellidos*</label><br /><input type="text" class="mandatory" style="float: left; width: 443px; margin-right: 10px; vertical-align: top; padding-top: 2px; padding-bottom: 2px;" id="imObjectForm_1_1" name="imObjectForm_1_1" /></div>
<div class="imClear" style="height: 1px; line-height: 1px; width: 457px;"></div>
<div style="float: left; margin: 0; padding: 0 0 2px;"><label for="imObjectForm_1_2" style="vertical-align: top; display: inline-block; margin: 3px 0 2px; width: 443px;">Email*</label><br /><input type="text" class="mandatory valEmail" style="float: left; width: 443px; margin-right: 10px; vertical-align: top; padding-top: 2px; padding-bottom: 2px;" id="imObjectForm_1_2" name="imObjectForm_1_2" /></div>
<div class="imClear" style="height: 1px; line-height: 1px; width: 457px;"></div>
<div style="float: left; margin: 0; padding: 0 0 2px;"><label for="imObjectForm_1_3" style="vertical-align: top; display: inline-block; margin: 3px 0 2px; width: 443px;">Teléfono</label><br /><input type="text" maxlength="20" class="valMaxLength[20]" style="float: left; width: 443px; margin-right: 10px; vertical-align: top; padding-top: 2px; padding-bottom: 2px;" id="imObjectForm_1_3" name="imObjectForm_1_3" /></div>
<div class="imClear" style="height: 1px; line-height: 1px; width: 457px;"></div>
<div style="float: left; margin: 0; padding: 0 0 2px;"><label for="imObjectForm_1_4" style="vertical-align: top; display: inline-block; margin: 3px 0 2px; width: 443px;">Adjuntar Archivo</label><br /><input type="file" class="" style="float: left; width: 443px; margin-right: 10px; vertical-align: top; padding-top: 2px; padding-bottom: 2px;" id="imObjectForm_1_4" name="imObjectForm_1_4" /></div>
<div class="imClear" style="height: 1px; line-height: 1px; width: 457px;"></div>
<div style="float: left; margin: 0; padding: 0 0 2px;"><label for="imObjectForm_1_5" style="vertical-align: top; display: inline-block; margin: 3px 0 2px; width: 443px;">Asunto*</label><br /><input type="text" class="mandatory" style="float: left; width: 443px; margin-right: 10px; vertical-align: top; padding-top: 2px; padding-bottom: 2px;" id="imObjectForm_1_5" name="imObjectForm_1_5" /></div>
<div class="imClear" style="height: 1px; line-height: 1px; width: 457px;"></div>
<div style="float: left; margin: 0; padding: 0 0 2px;"><label for="imObjectForm_1_6" style="vertical-align: top; display: inline-block; margin: 3px 0 2px; width: 443px;">Comentario*</label><br /><textarea class="mandatory" style="float: left; width: 443px; margin-right: 10px; vertical-align: top; padding-top: 2px; padding-bottom: 2px; padding-left: 0; padding-right: 0; height: 180px;" id="imObjectForm_1_6" name="imObjectForm_1_6"></textarea></div>
</div>
</fieldset>
<fieldset>
<div style="width: 457px; text-align: center;">
<label for="imObjectForm_1_captcha" style="padding: 0;"></label><br />
<input type="text" class="imCpt[5]" id="imObjectForm_1_captcha" name="imCpt" style="width: 120px;" maxlength="5" />
</div>
<input type="hidden" id="imObjectForm_1_prot" name="imSpProt" />
</fieldset>
<div style="width: 457px; text-align: center;">
<input type="submit" value="Enviar" />
<input type="reset" value="Resetear" />
</div>
</form>

anunciarte.html------------------------------------------------------------------------------------------------------------------------------

[b]<form id="imObjectForm_2" action="mail/imEmailForm_698sa253.php" method="post" enctype="multipart/form-data" style="width: 457px; margin: 0; padding: 0; text-align: left;">
<fieldset class="first">
<div>
<div style="float: left; margin: 0; padding: 0 0 2px;"><label for="imObjectForm_2_1" style="vertical-align: top; display: inline-block; margin: 3px 0 2px; width: 443px;">Nombre y Apellidos*</label><br /><input type="text" class="mandatory" style="float: left; width: 443px; margin-right: 10px; vertical-align: top; padding-top: 2px; padding-bottom: 2px;" id="imObjectForm_2_1" name="imObjectForm_2_1" /></div>
<div class="imClear" style="height: 1px; line-height: 1px; width: 457px;"></div>
<div style="float: left; margin: 0; padding: 0 0 2px;"><label for="imObjectForm_2_2" style="vertical-align: top; display: inline-block; margin: 3px 0 2px; width: 443px;">Email*</label><br /><input type="text" class="mandatory valEmail" style="float: left; width: 443px; margin-right: 10px; vertical-align: top; padding-top: 2px; padding-bottom: 2px;" id="imObjectForm_2_2" name="imObjectForm_2_2" /></div>
<div class="imClear" style="height: 1px; line-height: 1px; width: 457px;"></div>
<div style="float: left; margin: 0; padding: 0 0 2px;"><label for="imObjectForm_2_3" style="vertical-align: top; display: inline-block; margin: 3px 0 2px; width: 443px;">Teléfono*</label><br /><input type="text" class="mandatory" style="float: left; width: 443px; margin-right: 10px; vertical-align: top; padding-top: 2px; padding-bottom: 2px;" id="imObjectForm_2_3" name="imObjectForm_2_3" /></div>
<div class="imClear" style="height: 1px; line-height: 1px; width: 457px;"></div>
<div style="float: left; margin: 0; padding: 0 0 2px;"><label for="imObjectForm_2_4" style="vertical-align: top; display: inline-block; margin: 3px 0 2px; width: 443px;">Modalidad de Contratación*</label><br /><select class="mandatory" style="float: left; width: 443px; margin-right: 10px; vertical-align: top; padding-top: 2px; padding-bottom: 2px;" id="imObjectForm_2_4" name="imObjectForm_2_4"><option value="">-</option><option value="Mensual = 5€">Mensual = 5€</option><option value="Anual = 50 €">Anual = 50 €</option></select></div>
<div class="imClear" style="height: 1px; line-height: 1px; width: 457px;"></div>
<div style="float: left; margin: 0; padding: 0 0 2px;"><label for="imObjectForm_2_5" style="vertical-align: top; display: inline-block; margin: 3px 0 2px; width: 443px;">Tarjeta de Visita</label><br /><input type="file" class="" style="float: left; width: 443px; margin-right: 10px; vertical-align: top; padding-top: 2px; padding-bottom: 2px;" id="imObjectForm_2_5" name="imObjectForm_2_5" /></div>
<div class="imClear" style="height: 1px; line-height: 1px; width: 457px;"></div>
<div style="float: left; margin: 0; padding: 0 0 2px;"><label for="imObjectForm_2_6" style="vertical-align: top; display: inline-block; margin: 3px 0 2px; width: 443px;">Pagina Web</label><br /><input type="text" class="" style="float: left; width: 443px; margin-right: 10px; vertical-align: top; padding-top: 2px; padding-bottom: 2px;" id="imObjectForm_2_6" name="imObjectForm_2_6" /></div>
<div class="imClear" style="height: 1px; line-height: 1px; width: 457px;"></div>
<div style="float: left; margin: 0; padding: 0 0 2px;"><label style="vertical-align: top; display: inline-block; margin: 3px 0 2px; width: 443px;">¿Necesitas P. Web o T.Visita?</label><br /><span style="display: inline-block; width: 443px; margin-right: 10px;"><span style="display: block; float: left; clear: left; width: 442px; margin: 0; padding: 0;" class="radiobutton"><input type="radio" class="" style="vertical-align: middle;" id="imObjectForm_2_7_0" name="imObjectForm_2_7" value="Si Solicitar Presupuesto" />Si Solicitar Presupuesto</span><br /><span style="display: block; float: left; clear: left; width: 442px; margin: 0; padding: 0;" class="radiobutton"><input type="radio" class="" style="vertical-align: middle;" id="imObjectForm_2_7_1" name="imObjectForm_2_7" value="No Solicitar Presupuesto" />No Solicitar Presupuesto</span><br /></span></div>
<div class="imClear" style="height: 1px; line-height: 1px; width: 457px;"></div>
<div style="float: left; margin: 0; padding: 0 0 2px;"><label style="vertical-align: top; display: inline-block; margin: 3px 0 2px; width: 443px;">Aceptar condiciones*</label><br /><span style="display: inline-block; width: 443px; margin-right: 10px;"><span style="display: block; float: left; clear: left; width: 442px; margin: 0; padding: 0;" class="radiobutton"><input type="radio" class="mandatory" style="vertical-align: middle;" id="imObjectForm_2_8_0" name="imObjectForm_2_8" value="Acepto la condiciones de uso" />Acepto la condiciones de uso</span><br /></span></div>
</div>
</fieldset>
<fieldset>
<div style="width: 457px; text-align: center;">
<label for="imObjectForm_2_captcha" style="padding: 0;"></label><br />
<input type="text" class="imCpt[5]" id="imObjectForm_2_captcha" name="imCpt" style="width: 120px;" maxlength="5" />
</div>
<input type="hidden" id="imObjectForm_2_prot" name="imSpProt" />
</fieldset>
<div style="width: 457px; text-align: center;">
<input type="submit" value="Enviar" />
<input type="reset" value="Resetear" />
</div>
</form>


imemail.inc.php------------------------------------------------------------------------------------------------------------------------------
<?php
//Incomedia WebSite X5 EMail Class. All rights reserved.

class imEMail {
var $from;
var $to;
var $subject;
var $charset;
var $text;
var $html;

var $attachments;

function imEMail($from,$to,$subject,$charset) {
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->charset = $charset;
}

function setFrom($from) {
$this->from = $from;
}

function setTo($to) {
$this->to = $to;
}

function setSubject($subject) {
$this->subject = $subject;
}

function setCharset($charset) {
$this->charset = $charset;
}

function setText($text) {
$this->text = $text;
}

function setHTML($html) {
$this->html = $html;
}

function attachFile($name,$content,$mime_type) {
$attachment['name'] = $name;
$attachment['content'] = base64_encode($content);
$attachment['mime_type'] = $mime_type;
$this->attachments[] = $attachment;
}

function send() {
$headers = "";
$msg = "";

if($this->from == "" || $this->to == "" || ($this->text == "" && $this->html == ""))
return false;

$boundary_file = md5(time() . "_attachment");
$boundary_alt = md5(time() . "_alternative");

$headers .= "From: " . $this->from . "\r\n";
$headers .= "Message-ID: <" . time() . rand(0,9) . rand(0,9) . "@websitex5.users>\r\n";
$headers .= "X-Mailer: WebSiteX5 Mailer\r\n";
$headers .= "MIME-Version: 1.0\r\n";

if(is_array($this->attachments)) {
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $boundary_file . "\"\r\n\r\n";
$headers .= "--" . $boundary_file . "\r\n";
}

if($this->html == "") {
$headers .= "Content-Type: text/plain; charset=" . strtoupper($this->charset) . "\r\n";
if (strtolower($this->charset) != "utf-8")
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
else
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$msg .= $this->text . "\r\n\r\n";
}
else if($this->text == "") {
$headers .= "Content-Type: text/html; charset=" . strtoupper($this->charset) . "\r\n";
if (strtolower($this->charset) != "utf-8")
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
else
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$msg .= $this->html . "\r\n\r\n";
}
else {
$headers .= "Content-Type: multipart/alternative; boundary=\"" . $boundary_alt . "\"\r\n";

$msg .= "--" .$boundary_alt . "\r\n";
$msg .= "Content-Type: text/plain; charset=" . strtoupper($this->charset) . "\r\n";
if (strtolower($this->charset) != "utf-8")
$msg .= "Content-Transfer-Encoding: 7bit\r\n";
else
$msg .= "Content-Transfer-Encoding: 8bit\r\n";
$msg .= "\r\n";
$msg .= $this->text . "\r\n\r\n";

$msg .= "--" . $boundary_alt . "\r\n";
$msg .= "Content-Type: text/html; charset=" . strtoupper($this->charset) . "\r\n";
if (strtolower($this->charset) != "utf-8")
$msg .= "Content-Transfer-Encoding: 7bit\r\n";
else
$msg .= "Content-Transfer-Encoding: 8bit\r\n";
$msg .= "\r\n";
$msg .= $this->html . "\r\n\r\n";

$msg .= "--" . $boundary_alt . "--\r\n\r\n";
}

if(is_array($this->attachments)) {
foreach($this->attachments as $attachment) {
$msg .= "--" . $boundary_file . "\r\n";
$msg .= "Content-Type: " . $attachment["mime_type"] . "; name=\"" . $attachment["name"] . "\"\r\n";
$msg .= "Content-Transfer-Encoding: base64\r\n";
$msg .= "Content-Disposition: attachment; filename=\"" . $attachment["name"] . "\"\r\n\r\n";
$msg .= chunk_split($attachment["content"]) . "\r\n\r\n";
}

$msg .= "--" . $boundary_file . "--\r\n\r\n";
}

@ini_set("sendmail_from", $this->from);

$r = @mail($this->to, $this->subject, $msg, $headers, "-f" . $this->from);
if(!$r) {
$headers = "To: " . $this->to . "\r\n" . $headers;
$r = @mail($this->to, $this->subject, $msg, $headers);
}
return $r;
}
}

// End of file imemail.inc.php

x5engine.php---------------------------------------------------------------------------------------------------------------------------------

<?php
/**
* This file contains all the classes used by the PHP code created by WebSite X5
* @author Incomedia Srl (http://www.incomedia.eu)
* @version 1.0
*/

@session_start();

$imSettings = Array();
$l10n = Array();
$phpError = false;

@include("imemail.inc.php"); // Email class - Static
@include("x5settings.php"); // Basic settings - Dynamically created by WebSite X5
@include("blog.inc.php"); // Blog data - Dynamically created by WebSite X5
@include("cart.inc.php"); // E-commerce cart data - Dynamically created by WebSite X5
@include("access.inc.php"); // Private area data - Dynamically created by WebSite X5
@include("l10n.php"); // Localizations - Dynamically created by WebSite X5
@include("search.inc.php"); // Search engine data - Dynamically created by WebSite X5

/**
* Contains the methods used to format and send emails
* @access public
*/
class imSendEmail {

/**
* Send the E-commerce cart order/email
* @access public
* @param post The data sent by the form of the e-commerce cart at step 4 (array)
*/
function sendCartEmail($post_data) {

global $imSettings;
global $l10n;

$separationLine = "<tr><td colspan=\"2\" style=\"margin: 10px 0; height: 10px; font-size: 0.1px; border-bottom: 1px solid " . $imSettings['email']['email_background'] . ";\">&nbsp;</td></tr>\n";
$PayMsg = $imSettings['cart']['confirmationEmail'];
$ownerEmail = $imSettings['cart']['owner_email'];
$imOpt = 0;
$imVat = 0;
$imOrderNo = $post_data["order_no"];
$imUserData = $post_data["form"];
$imShippingDataTxt = "";
$imShippingDataHtml = "";
$imUserDataTxt = "";
$imUserDataHtml = "";
$imUserDataCSVH = "";
$imUserDataCSV = "";

$i = 0;
if(is_array($imUserData)) {
foreach($imUserData as $key => $value) {
// Is it an email?
if (preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])' . '(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', $value['imValue'])) {
$f = "<td><b>" . str_replace(array("\\'", '\\"'), array("'", '"'), $value['name']) . ":</b></td><td><a href=\"mailto:" . $value['imValue'] . "\">". $value['imValue'] . "</a></td>";
} else if (preg_match('/^http[s]?:\/\/[a-zA-Z0-9\.\-]{2,}\.[a-zA-Z]{2,}/', $value['imValue'])) {
// Is it an URL?
$f = "<td><b>" . str_replace(array("\\'", '\\"'), array("'", '"'), $value['name']) . ":</b></td><td><a href=\"" . $value['imValue'] . "\">". $value['imValue'] . "</a></td>";
} else {
$f = "<td><b>" . str_replace(array("\\'", '\\"'), array("'", '"'), $value['name']) . ":</b></td><td>" . str_replace(array("\\'", '\\"'), array("'", '"'), $value['imValue']) . "</td>";
}

if (substr($key, -strlen("_shipping")) == "_shipping") {
$imShippingDataTxt .= $value['name'] . ": " . $value['imValue'] . "\n";
$imShippingDataHtml .= "\n\t\t\t\t<tr" . ($i%2 ? " bgcolor=\"" . $imSettings['email']['body_background_odd'] . "\"" : "") . ">" . $f . "</tr>";
$imShippingDataCSVH[] = $value['name'];
$imShippingDataCSV[] = $value['imValue'];
} else {
$imUserDataTxt .= $value['name'] . ": " . $value['imValue'] . "\n";
$imUserDataHtml .= "\n\t\t\t\t<tr" . ($i%2 ? " bgcolor=\"" . $imSettings['email']['body_background_odd'] . "\"" : "") . ">" . $f . "</tr>";
$imUserDataCSVH[] = $value['name'];
$imUserDataCSV[] = $value['imValue'];
}
$i++;
}
if ($imUserDataHtml != "")
$imUserDataHtml = "<table width=\"100%\" style=\"font: inherit;\">" . $imUserDataHtml . "</table>";

if ($imShippingDataHtml != "")
$imShippingDataHtml = "<table width=\"100%\" style=\"font: inherit;\">" . $imShippingDataHtml . "</table>";
}
$imUserDataCSV = @implode(";",$imUserDataCSVH) . "\n" . @implode(";",$imUserDataCSV);
$imShippingDataCSV = @implode(";",$imShippingDataCSVH) . "\n" . @implode(";",$imShippingDataCSV);

$imOrderData = $post_data["products"];
$imOrderDataTxt = "";
$imOrderDataHTML = "";
$imOrderDataCSV = "";
$i = 0;
if(is_array($imOrderData)) {
foreach($imOrderData as $p) {
if($p["option"] != "null")
$imOpt = 1;
if ($p["vat"] != "null" && $p["vat"] != 0)
$imVat = 1;
}
$colspan = 3 + $imOpt + $imVat;
$imOrderDataHTML = "<table cellpadding=\"5\" width=\"100%\" style=\"font: inherit; border-collapse: collapse;\"><tr bgcolor=\"" . $imSettings['email']['body_background_odd'] . "\"><td style=\"border: 1px solid " . $imSettings['email']['body_background_border'] . ";\"><b>" . $l10n["cart_name"] . "</b></td>" . ($imOpt ? "<td style=\"border: 1px solid " . $imSettings['email']['body_background_border'] . ";\"><b>" . $l10n["product_option"] . "</b></td>" : "") . "<td style=\"border: 1px solid " . $imSettings['email']['body_background_border'] . ";\"><b>" . $l10n["cart_qty"] . "</b></td><td style=\"border: 1px solid " . $imSettings['email']['body_background_border'] . ";\"><b>" . $l10n["cart_price"] . "</b></td>" . ($imVat ? "<td style=\"border: 1px solid " . $imSettings['email']['body_background_border'] . ";\"><b>" . $l10n["cart_VAT"] ."</b></td>" : "") . "<td style=\"border: 1px solid " . $imSettings['email']['body_background_border'] . "; width: " . $priceFieldWidth . "\"><b>" . $l10n["cart_subtot"] . "</b></td></tr>\n";
$imOrderDataCSV = $l10n["cart_name"] . ";" . $l10n["cart_descr"] . ";" . ($imOpt ? $l10n["product_option"] . ";" : "") . $l10n["cart_qty"] . ";" . $l10n["cart_price"] . ";" . ($imVat ? $l10n["cart_vat"] .";" : "") . $l10n["cart_subtot"];
foreach($imOrderData as $od) {
$imOrderDataCSV .= "\n" . strip_tags(str_replace(array("\n", "\r"), "", $od["name"])) . ";" . strip_tags(str_replace(array("\n", "\r"), "", $od["description"])) . ";" . (($imOpt && $od["option"] != "null") ? $this->restoreSpecialChars(urldecode($od["option"])) . ";" : "") . $od["quantity"] . ";" . $od["single_price"] . ";" . ($imVat ? $od["price_vat"] .";" : "") . $od["price_vat"];
$imOrderDataTxt .= strip_tags(str_replace(array("\n", "\r"), "", $od["name"])) . " - " . strip_tags(str_replace(array("\n", "\r"), "", $od["description"])) . (($imOpt && $od["option"] != "null") ? " " . $this->restoreSpecialChars(urldecode($od["option"])) . ";" : "") . "\n " . $od["quantity"] . " x " . $od["single_price"] . " " . ($imVat ? "+ " . $l10n["cart_vat"] . " " . $od["vat_f"] : "") . " = " . $od["price_vat"] . "\n\n";
$imOrderDataHTML .= "\n\t\t\t\t<tr valign=\"top\" style=\"vertical-align: top\"" . ($i%2 ? " bgcolor=\"#EEEEEE\"" : "") . "><td style=\"border: 1px solid " . $imSettings['email']['body_background_border'] . ";\">" . $od["name"] . "<br />" . $od["description"] . "</td>" . ($imOpt ? "<td style=\"border: 1px solid " . $imSettings['email']['body_background_border'] . ";\">" . (($od["option"] != "null") ? $this->restoreSpecialChars(urldecode($od["option"])) : "") . "</td>" : "") . "<td style=\"border: 1px solid " . $imSettings['email']['body_background_border'] . "; text-align: right;\">" . $od["quantity"] . "</td><td style=\"border: 1px solid " . $imSettings['email']['body_background_border'] . "; text-align: right;\">" . $od["single_price"] . "</td>" . ($imVat ? "<td style=\"border: 1px solid " . $imSettings['email']['body_background_border'] . "; text-align: right;\">" . (($od["vat"] != "null") ? $od["vat"]*100 . "% / " . $od["vat_f"] : "") ."</td>" : "") . "<td style=\"border: 1px solid " . $imSettings['email']['body_background_border'] . "; text-align: right; width: " . $priceFieldWidth . "\">" . $od["price_vat"] . "</td></tr>\n";
$i++;
}

// Payment Price

if (isset($post_data['payment']['price']) && $post_data['payment']['price'] != null && $post_data['payment']['price'] != "null") {
$imOrderDataHTML .= "<tr><td colspan=\"" . $colspan . "\" style=\"border: 1px solid " . $imSettings['email']['body_background_border'] . "; text-align: right;\">" . $l10n['cart_payment'] . ": " . $post_data['payment']['name'] . "</td><td style=\"border: 1px solid " . $imSettings['email']['body_background_border'] . "; text-align: right;\">" . $post_data['payment']['price'] . "</td></tr>";
$imOrderDataTxt .= "\n" . $l10n['cart_payment'] . " - " . $post_data['payment']['name'] . ": " . $post_data['payment']['price'];
}
if (isset($post_data['shipping']['price']) && $post_data['shipping']['price'] != null && $post_data['shipping']['price'] != "null") {
$imOrderDataHTML .= "<tr><td colspan=\"" . $colspan . "\" style=\"border: 1px solid " . $imSettings['email']['body_background_border'] . "; text-align: right;\">" . $l10n['cart_shipping'] . ": " . $post_data['shipping']['name'] . "</td><td style=\"border: 1px solid " . $imSettings['email']['body_background_border'] . "; text-align: right;\">" . $post_data['shipping']['price'] . "</td></tr>";
$imOrderDataTxt .= "\n" . $l10n['cart_shipping'] . " - " . $post_data['shipping']['name'] . ": " . $post_data['shipping']['price'];
}

$imOrderDataHTML .= "<tr><td colspan=\"" . $colspan . "\" style=\"border: 1px solid " . $imSettings['email']['body_background_border'] . "; text-align: right;\">" . $l10n['cart_total_vat'] . "</td><td style=\"border: 1px solid " . $imSettings['email']['body_background_border'] . "; text-align: right;\">" . $post_data['total'] . "</td></tr>";
$imOrderDataTxt .= "\n" . $l10n['cart_total_vat'] . ": " . $post_data['total'];

$imOrderDataHTML .= "</table>";
}

//#################################################
//
// Email to Customer
//
//#################################################

$htmlMsg = $imSettings['email']['header'];

$htmlMsg .= "<table border=0 width=\"100%\" style=\"font: inherit;\">\n";
// Opening message
$htmlMsg .= "<tr><td colspan=\"2\">" . $imSettings['cart']['email_opening'] . "</td></tr>\n";
$txtMsg = str_replace("<br>", "\n", $imSettings['cart']['email_opening']);

// Order number
$htmlMsg .= "<tr><td colspan=\"2\" style=\"text-align: center; font-weight: bold;\">" . $l10n['cart_order_no'] . ": " . $imOrderNo . "</td></tr>\n";
$txtMsg .= "\n\n" . str_replace("<br>", "\n", $l10n['cart_order_no'] . ": " . $imOrderNo);

// Customer's data
if ($imShippingDataHtml != "") {
$htmlMsg .= "<tr style=\"vertical-align: top\" valign=\"top\"><td style=\"width: 50%; padding: 20px 0;\"><h3 style=\"font-size: 1.11em\">" . $l10n['cart_vat_address'] . "</h3>" . $imUserDataHtml . "</td>";
$htmlMsg .= "<td style=\"width: 50%; padding: 20px 0;\"><h3 style=\"font-size: 1.11em\">" . $l10n['cart_shipping_address'] . "</h3>" . $imShippingDataHtml . "</td></tr>";

$txtMsg .= "\n" . str_replace("<br />", "\n", $l10n['cart_vat_address'] . "\n" . $imUserDataTxt);
$txtMsg .= "\n" . str_replace("<br />", "\n", $l10n['cart_shipping_address'] . "\n" . $imShippingDataTxt );
} else {
$htmlMsg .= "<tr><td colspan=\"2\" style=\"padding: 20px 0 0 0;\"><h3 style=\"font-size: 1.11em\">" . $l10n['cart_vat_address'] . "/" . $l10n['cart_shipping_address'] . "</h3>" . $imUserDataHtml . "</td></tr>";
$txtMsg .= "\n" . str_replace("<br />", "\n", $l10n['cart_vat_address'] . "/" . $l10n['cart_shipping_address'] . "\n" . $imUserDataTxt);
}

$htmlMsg .= $separationLine;

// Products
$htmlMsg .= "<tr><td colspan=\"2\" style=\"padding: 5px 0 0 0;\"><h3 style=\"font-size: 1.11em\">" . $l10n['cart_product_list'] . "</h3>" . $imOrderDataHTML . "</td></tr>";
$txtMsg .= "\n\n" . str_replace("<br>", "\n", $l10n['cart_product_list'] . "\n" . $imOrderDataTxt);

$htmlMsg .= $separationLine;

// Payment
$htmlMsg .= "<tr><td colspan=\"2\" style=\"padding: 5px 0 0 0;\"><h3 style=\"font-size: 1.11em\">" . $l10n['cart_payment'] . "</h3>" . str_replace(array("\\'", '\\"'), array("'", '"'), str_replace("\\\"", "\"", preg_replace('/[\n\r\t]*/', "", nl2br($post_data['payment']['email']))));
if ($post_data['payment']['html'] != null && $post_data['payment']['html'] != "" && $post_data['payment']['html'] != "null")
$htmlMsg .= "<br><br><div style=\"text-align: center;\">" . str_replace("\\\"", "\"", $post_data['payment']['html']) . "</div>";
$htmlMsg .= "</td></tr>";
$txtMsg .= "\n\n" . str_replace("<br>", "\n", $l10n['cart_payment'] . "\n" . str_replace(array("\\'", '\\"'), array("'", '"'), str_replace("\\\"", "\"", $post_data['payment']['email'])));

$htmlMsg .= $separationLine;

// Shipping
$htmlMsg .= "<tr><td colspan=\"2\" style=\"padding: 5px 0 0 0;\"><h3 style=\"font-size: 1.11em\">" . $l10n['cart_shipping'] . "</h3>" . str_replace(array("\\'", '\\"'), array("'", '"'), str_replace("\\\"", "\"", preg_replace('/[\n\r\t]*/', "", nl2br($post_data['shipping']['email'])))) . "</td></tr>";
$txtMsg .= "\n\n" . str_replace("<br>", "\n", $l10n['cart_shipping'] . "\n" . str_replace(array("\\'", '\\"'), array("'", '"'), str_replace("\\\"", "\"", $post_data['shipping']['email'])));

// Closing message
$htmlMsg .= $separationLine;
$htmlMsg .= "<tr><td colspan=\"2\" style=\"padding: 5px 0 0 0;\">" . str_replace(array("\\'", '\\"'), array("'", '"'), str_replace("\\\"", "\"", $imSettings['cart']['email_closing'])) . "</td></tr>\n";
$txtMsg .= "\n\n" . str_replace(array("\\'", "\\\"", "<br>", "<br>"), array("'", "\"", "\n", "\n"), $imSettings['cart']['email_closing']);

$htmlMsg .= "</table>\n";

$htmlMsg .= $imSettings['email']['footer'];

//Send email to user
$oEmail = new imEMail($ownerEmail,$post_data["form"]["imCartEmail"]["imValue"],$l10n['cart_order_no'] . " " . $imOrderNo,"utf-8");
$oEmail->setText($txtMsg);
$oEmail->setHTML($htmlMsg);
$oEmail->send();

//#################################################
//
// Email to the site's owner
//
//#################################################

//Send email to owner
$txtMsg = "";
$htmlMsg = $imSettings['email']['header'];
$htmlMsg .= "<table border=0 width=\"100%\" style=\"font: inherit;\">\n";
// Order number
$htmlMsg .= "<tr><td colspan=\"2\" style=\"text-align: center; font-weight: bold;\">" . $l10n['cart_order_no'] . ": " . $imOrderNo . "</td></tr>\n";
$txtMsg .= "\n\n" . str_replace("<br>", "\n", $l10n['cart_order_no'] . ": " . $imOrderNo);

// Customer's data
if ($imShippingDataHtml != "") {
$htmlMsg .= "<tr style=\"vertical-align: top\" valign=\"top\"><td style=\"width: 50%; padding: 20px 0;\"><h3 style=\"font-size: 1.11em\">" . $l10n['cart_vat_address'] . "</h3>" . $imUserDataHtml . "</td>";
$htmlMsg .= "<td style=\"width: 50%; padding: 20px 0;\"><h3 style=\"font-size: 1.11em\">" . $l10n['cart_shipping_address'] . "</h3>" . $imShippingDataHtml . "</td></tr>";

$txtMsg .= "\n" . str_replace("<br />", "\n", $l10n['cart_vat_address'] . "\n" . $imUserDataTxt);
$txtMsg .= "\n" . str_replace("<br />", "\n", $l10n['cart_shipping_address'] . "\n" . $imShippingDataTxt );
} else {
$htmlMsg .= "<tr><td colspan=\"2\" style=\"padding: 20px 0 0 0;\"><h3 style=\"font-size: 1.11em\">" . $l10n['cart_vat_address'] . "/" . $l10n['cart_shipping_address'] . "</h3>" . $imUserDataHtml . "</td></tr>";
$txtMsg .= "\n" . str_replace("<br />", "\n", $l10n['cart_vat_address'] . "/" . $l10n['cart_shipping_address'] . "\n" . $imUserDataTxt);
}

$htmlMsg .= $separationLine;

// Products
$htmlMsg .= "<tr><td colspan=\"2\" style=\"padding: 5px 0 0 0;\"><h3 style=\"font-size: 1.11em\">" . $l10n['cart_product_list'] . "</h3>" . $imOrderDataHTML . "</td></tr>";
$txtMsg .= "\n\n" . str_replace("<br>", "\n", $l10n['cart_product_list'] . "\n" . $imOrderDataTxt);

$htmlMsg .= $separationLine;

// Payment
$htmlMsg .= "<tr><td colspan=\"2\" style=\"padding: 5px 0 0 0;\"><h3 style=\"font-size: 1.11em\">" . $l10n['cart_payment'] . "</h3>" . str_replace(array("\\'", '\\"'), array("'", '"'), str_replace("\\\"", "\"", preg_replace('/[\n\r\t]*/', "", nl2br($post_data['payment']['email']))));
$htmlMsg .= "</td></tr>";
$txtMsg .= "\n\n" . str_replace("<br>", "\n", $l10n['cart_payment'] . "\n" . str_replace(array("\\'", '\\"'), array("'", '"'), str_replace("\\\"", "\"", $post_data['payment']['email'])));

$htmlMsg .= $separationLine;

// Shipping
$htmlMsg .= "<tr><td colspan=\"2\" style=\"padding: 5px 0 0 0;\"><h3 style=\"font-size: 1.11em\">" . $l10n['cart_shipping'] . "</h3>" . str_replace(array("\\'", '\\"'), array("'", '"'), str_replace("\\\"", "\"", preg_replace('/[\n\r\t]*/', "", nl2br($post_data['shipping']['email'])))) . "</td></tr>";
$txtMsg .= "\n\n" . str_replace("<br>", "\n", $l10n['cart_shipping'] . "\n" . str_replace(array("\\'", '\\"'), array("'", '"'), str_replace("\\\"", "\"", $post_data['shipping']['email'])));

$oEmailO = new imEMail($ownerEmail,$ownerEmail,$l10n['cart_order_no'] . " " . $imOrderNo,"utf-8");
if ($imSettings['cart']['useCSV']) {
$txtMsg .= $imUserDataCSV . "\n" . $imOrderDataCSV;
$oEmailO->attachFile("user_data.csv",$imUserDataCSV,"text/csv");
$oEmailO->attachFile("order_data.csv",$imOrderDataCSV,"text/csv");
}
$oEmailO->setText($txtMsg);
$oEmailO->setHTML($htmlMsg);
return $oEmailO->send();
}

/**
* Send the email message sent by the Email Object form
* @access public
* @param form The form settings in an associative array (array)
* @param form_data The posted text data in an associative array (array)
* @param files_data The posted files data in an associative array (array)
* @param user_only Set TRUE to send the email only to the customer who filled the form. This is used when the data is stored in a DB and a confirmation email is sent too (bool)
*/
function sendFormEmail($form, $form_data, $files_data, $user_only = FALSE) {
global $imSettings;
if (!is_array($form))
$settings = $imSettings['email_form'][$form_id];
else
$settings = $form;
//Form Data
$txtData = "";
$htmData = "";
$csvHeader = "";
$csvData = "";
$keys = array_keys($form_data);
foreach ($keys as $key) {
if (is_array($form_data[$key])) {
$txtData .= $key . ": " . implode(", ", $form_data[$key]) . "\r\n";
$htmData .= "<tr valign=\"top\"><td width=\"25%\"><b>" . $key . ":</b></td><td>" . implode(", ", $form_data[$key]) . "</td></tr>";
if ($settings['customer_csv'] || $settings['owner_csv']) {
$csvHeader .= $key . ";";
$csvData .= implode(", ", $form_data[$key]) . ";";
}
} else {
$txtData .= $key . ": " . $form_data[$key] . "\r\n";
// Is it an email?
if (preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])' . '(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', $form_data[$key])) {
$htmData .= "<tr valign=\"top\"><td width=\"25%\"><b>" . str_replace(array("\\'", '\\"'), array("'", '"'), $key) . ":</b></td><td><a href=\"mailto:" . $form_data[$key] . "\">". $form_data[$key] . "</a></td></tr>";
} else if (preg_match('/^http[s]?:\/\/[a-zA-Z0-9\.\-]{2,}\.[a-zA-Z]{2,}/', $form_data[$key])) {
// Is it an URL?
$htmData .= "<tr valign=\"top\"><td width=\"25%\"><b>" . str_replace(array("\\'", '\\"'), array("'", '"'), $key) . ":</b></td><td><a href=\"" . $form_data[$key] . "\">". $form_data[$key] . "</a></td></tr>";
} else {
$htmData .= "<tr valign=\"top\"><td width=\"25%\"><b>" . str_replace(array("\\'", '\\"'), array("'", '"'), $key) . ":</b></td><td>" . str_replace(array("\\'", '\\"'), array("'", '"'), $form_data[$key]) . "</td></tr>";
}
if ($settings['customer_csv'] || $settings['owner_csv']) {
$csvHeader .= str_replace(array("\\'", '\\"'), array("'", '"'), $key) . ";";
$csvData .= str_replace(array("\\'", '\\"'), array("'", '"'), $form_data[$key]) . ";";
}
}
}

// Template
$htmHead = $imSettings['email']['header'];
$htmFoot = $imSettings['email']['footer'];

//Send email to owner
if (!$user_only && isset($settings['owner_email_to']) && $settings['owner_email_to'] != "") {
$txtMsg = $settings['owner_message'];
$htmMsg = nl2br($settings['owner_message']);
if (strpos($settings['owner_email_from'], "@") === FALSE)
$settings['owner_email_from'] = $form_data[$settings['owner_email_from']];
if ($settings['owner_email_from'] == "")
$settings['owner_email_from'] = $settings['owner_email_to'];
$oEmail = new imEMail($settings['owner_email_from'],$settings['owner_email_to'],$settings['owner_subject'],"utf-8");
$oEmail->setText($txtMsg . "\n\n" . $txtData);
$oEmail->setHTML($htmHead . $htmMsg . "<br><br><table border=0 width=\"100%\" style=\"" . $imSettings['email']['email_content_style'] . "\">" . $htmData . "</table>" . $htmFoot);
if ($settings['owner_csv'])
$oEmail->attachFile("form_data.csv", $csvHeader . "\n" . $csvData,"text/csv");
if (count($files_data) > 0) {
foreach ($files_data as $file) {
if (file_exists($file['tmp_name']))
$oEmail->attachFile($file['name'], file_get_contents($file['tmp_name']), $file['type']);
}
}
$oEmail->send();
}

//Send email to user
if (isset($settings['customer_email_to']) && $settings['customer_email_to'] != "") {
$txtMsg = $settings['customer_message'];
$htmMsg = nl2br($settings['customer_message']);
if ($settings['customer_email_from'] == "")
$settings['customer_email_from'] = $settings['owner_email_to'];
$oEmail = new imEMail($settings['customer_email_from'],$form_data[$settings['customer_email_to']],$settings['customer_subject'],"utf-8");
if ($settings['customer_csv']) {
$oEmail->setHTML($htmHead . $htmMsg . "<br><br><table border=0 width=\"100%\" style=\"" . $imSettings['email']['email_content_style'] . "\">" . $htmData . "</table>" . $htmFoot);
$oEmail->setText($txtMsg . "\n\n" . $txtData);
} else {
$oEmail->setText($txtMsg);
$oEmail->setHTML($htmHead . $htmMsg . $htmFoot);
}
$oEmail->send();
}
}

/**
* Send the blog emails
* @access public
* @param post The comment data
*/
function sendBlogEmail($post) {
global $imSettings;
global $l10n;
if (isset($post['post_id'])) {
$e = new imEmail($imSettings['blog']['email'],$imSettings['blog']['email'],$l10n['blog_new_comment_object'],"utf-8");
$text = $l10n['blog_new_comment_text'] . " \"" . $imSettings['blog']['posts'][$post['post_id']]['title'] . "\":\n\n";
$text .= $l10n['blog_name'] . " " . stripslashes($post['name']) . "\n";
$text .= $l10n['blog_email'] . " " . $post['email'] . "\n";
$text .= $l10n['blog_website'] . " " . $post['url'] . "\n";
$text .= $l10n['blog_message'] . " " . stripslashes($post['body']) . "\n\n";
$text .= ($imBCommentsApproved ? $l10n['blog_unapprove_link'] : $l10n['blog_approve_link']) . ":\n" . $imSettings['general']['url'] . "/admin/blog.php?post_id=" . $post['post_id'];
$e->setText($text);
return $e->send();
}

return FALSE;
}

/**
* Send the guestbook emails
* @access public
* @param post The comment data
*/
function sendGuestbookEmail($id, $name, $email, $website, $body, $direct_approval, $owner_email) {
global $imSettings;
global $l10n;
if (isset($id)) {
$e = new imEmail($owner_email,$owner_email,str_replace(array("Blog", "blog"), array("Guestbook", "guestbook"), $l10n['blog_new_comment_object']),"utf-8");
$text = str_replace(array("Blog", "blog"), array("Guestbook", "guestbook"), $l10n['blog_new_comment_text']) . " \"" . $id . "\":\n\n";
$text .= $l10n['blog_name'] . " " . stripslashes($name) . "\n";
$text .= $l10n['blog_email'] . " " . $email . "\n";
$text .= $l10n['blog_website'] . " " . $website . "\n";
$text .= $l10n['blog_message'] . " " . stripslashes($body) . "\n\n";
$text .= ($direct_approval ? $l10n['blog_unapprove_link'] : $l10n['blog_approve_link']) . ":\n" . $imSettings['general']['url'] . "/admin/guestbook.php?post_id=" . $id;
$e->setText($text);
return $e->send();
}

return FALSE;
}

/**
* Restore some special chars escaped previously in WSX5
* @access public
* @param str The string to be restored
*/
function restoreSpecialChars($str) {
$str = str_replace("{1}", "'", $str);
$str = str_replace("{2}", "\"", $str);
$str = str_replace("{3}", "\\", $str);
$str = str_replace("{4}", "<", $str);
$str = str_replace("{5}", ">", $str);
return $str;
}
}

/**
* Contains the methods used by the search engine
* @access public
*/
class imSearch {

var $scope;
var $page;
var $results_per_page;

function __construct() {
$this->setScope();
$this->results_per_page = 10;
}

function imSearch() {
$this->setScope();
$this->results_per_page = 10;
}

/**
* Loads the pages defined in search.inc.php to the search scope
* @access public
*/
function setScope() {
global $imSettings;
$scope = $imSettings['search']['general']['defaultScope'];

// Logged users can search in their private pages
$pa = new imPrivateArea();
if ($user = $pa->who_is_logged()) {
foreach ($imSettings['search']['general']['extendedScope'] as $key => $value) {
if (in_array($user['uid'], $imSettings['access']['pages'][$key]))
$scope[] = $value;
}
}

$this->scope = $scope;
}

/**
* Do the pages search
* @access public
* @param queries The search query (array)
*/
function searchPages($queries) {
global $l10n;
global $imSettings;

$html = "";

if (is_array($this->scope)) {
foreach($this->scope as $filename) {
$count = 0;
$weight = 0;
$file_content = @implode("\n",file($filename));

// Remove the breadcrumbs
while (stristr($file_content, "<div id=\"imBreadcrumb\"") !== FALSE) {
$style_start = imstripos($file_content, "<div id=\"imBreadcrumb\"");
$style_end = imstripos($file_content, "</div", $style_start);
$style = substr($file_content, $style_start, $style_end - $style_start);
$file_content = str_replace($style, "", $file_content);
}

// Remove CSS
while (stristr($file_content, "<style") !== FALSE) {
$style_start = imstripos($file_content, "<style");
$style_end = imstripos($file_content, "</style", $style_start);
$style = substr($file_content, $style_start, $style_end - $style_start);
$file_content = str_replace($style, "", $file_content);
}

// Remove JS
while (stristr($file_content, "<script") !== FALSE) {
$style_start = imstripos($file_content, "<script");
$style_end = imstripos($file_content, "</script", $style_start);
$style = substr($file_content, $style_start, $style_end - $style_start);
$file_content = str_replace($style, "", $file_content);
}
$file_title = "";

// Get the title of the page
preg_match('/\<title\>([^\<]*)\<\/title\>/', $file_content, $matches);
if ($matches[1] != null)
$file_title = $matches[1];
else {
preg_match('/\<h2\>([^\<]*)\<\/h2\>/', $file_content, $matches);
if ($matches[1] != null)
$file_title = $matches[1];
}

if($file_title != "") {
foreach($queries as $query) {
$title = strtolower($file_title);
while (($title = stristr($title, $query)) !== FALSE) {
$weight += 5;
$count++;
$title = substr($title,strlen($query));
}
}
}

// Get the keywords
preg_match('/\<meta name\=\"keywords\" content\=\"([^\"]*)\" \/>/', $file_content, $matches);
if ($matches[1] != null) {
$keywords = $matches[1];
foreach($queries as $query) {
$tkeywords = strtolower($keywords);
while (($tkeywords = stristr($tkeywords, $query)) !== FALSE) {
$weight += 4;
$count++;
$tkeywords = substr($tkeywords,strlen($query));
}
}
}

// Get the description
preg_match('/\<meta name\=\"description\" content\=\"([^\"]*)\" \/>/', $file_content, $matches);
if ($matches[1] != null) {
$keywords = $matches[1];
foreach($queries as $query) {
$tkeywords = strtolower($keywords);
while (($tkeywords = stristr($tkeywords, $query)) !== FALSE) {
$weight += 3;
$count++;
$tkeywords = substr($tkeywords,strlen($query));
}
}
}

// Remove the page title from the result
while (stristr($file_content, "<h2") !== FALSE) {
$style_start = strpos($file_content, "<h2");
$style_end = strpos($file_content, "</h2", $style_start);
$style = substr($file_content, $style_start, $style_end - $style_start);
$file_content = str_replace($style, "", $file_content);
}

$page_pos = strpos($file_content,"<div id=\"imContent\">") + strlen("<div id=\"imContent\">");
$page_end = strpos($file_content, "<div id=\"imBtMn\">");
if ($page_end == FALSE)
$page_end = strpos($file_content,"</body>");

$file_content = strip_tags(substr($file_content,$page_pos, $page_end-$page_pos));
$t_file_content = strtolower($file_content);

foreach($queries as $query) {
$file = $t_file_content;
while (($file = stristr($file, $query)) !== FALSE) {
$count++;
$weight++;
$file = substr($file,strlen($query));
}
}

if($count > 0) {
$found_count[$filename] = $count;
$found_weight[$filename] = $weight;
$found_content[$filename] = $file_content;
if ($file_title == "")
$found_title[$filename] = $filename;
else
$found_title[$filename] = $file_title;
}
}
}

if($found_count != null) {
arsort($found_weight);
$i = 0;
$pagine = ceil(count($found_count)/$this->results_per_page);
if(($this->page >= $pagine) || ($this->page < 0))
$this->page = 0;
foreach($found_weight as $name => $weight) {
$count = $found_count[$name];
$i++;
if(($i > $this->page*$this->results_per_page) && ($i <= ($this->page+1)*$this->results_per_page)) {
$title = strip_tags($found_title[$name]);
$file = $found_content[$name];
$file = strip_tags($file);
$ap = 0;
$filelen = strlen($file);
$text = "";
for($j=0;$j<($count > 6 ? 6 : $count);$j++) {
$minpos = $filelen;
foreach($queries as $query) {
if(($pos = strpos(strtoupper($file),strtoupper($query),$ap)) !== FALSE) {
if($pos < $minpos) {
$minpos = $pos;
$word = $query;
}
}
}
$prev = explode(" ",substr($file,$ap,$minpos-$ap));
if(count($prev) > ($ap > 0 ? 9 : 8))
$prev = ($ap > 0 ? implode(" ",array_slice($prev,0,8)) : "") . " ... " . implode(" ",array_slice($prev,-8));
else
$prev = implode(" ",$prev);
$text .= $prev . "<strong>" . substr($file,$minpos,strlen($word)) . "</strong> ";
$ap = $minpos + strlen($word);
}
$next = explode(" ",substr($file,$ap));
if(count($next) > 9)
$text .= implode(" ",array_slice($next,0,8)) . "...";
else
$text .= implode(" ",$next);
$text = str_replace("|", "", $text);
$text = str_replace("<br />", " ", $text);
$text = str_replace("<br>", " ", $text);
$text = str_replace("\n", " ", $text);
$html .= "<div class=\"imSearchPageResult\"><h3><a class=\"imCssLink\" href=\"" . $name . "\">" . $title . "</a></h3>" . $text . "<div class=\"imSearchLink\"><a class=\"imCssLink\" href=\"" . $name . "\">" . $domain . $name . "</a></div></div>\n";
}
}
$html = preg_replace("/\\s+/", " ", $html);
$html .= "<div class=\"imSLabel\">&nbsp;</div>\n";
}

return array("content" => $html, "count" => count($found_content));
}

function searchBlog($queries) {
global $l10n;
global $imSettings;

if (is_array($imSettings['blog']['posts'])) {
foreach($imSettings['blog']['posts'] as $key => $value) {
$count = 0;
$weight = 0;
$filename = 'blog/index.php?id=' . $key;
$file_content = $value['body'];
// Rimuovo le briciole dal contenuto
while (stristr($file_content, "<div id=\"imBreadcrumb\"") !== FALSE) {
$style_start = imstripos($file_content, "<div id=\"imBreadcrumb\"");
$style_end = imstripos($file_content, "</div", $style_start);
$style = substr($file_content, $style_start, $style_end - $style_start);
$file_content = str_replace($style, "", $file_content);
}

// Rimuovo gli stili dal contenuto
while (stristr($file_content, "<style") !== FALSE) {
$style_start = imstripos($file_content, "<style");
$style_end = imstripos($file_content, "</style", $style_start);
$style = substr($file_content, $style_start, $style_end - $style_start);
$file_content = str_replace($style, "", $file_content);
}
// Rimuovo i JS dal contenuto
while (stristr($file_content, "<script") !== FALSE) {
$style_start = imstripos($file_content, "<script");
$style_end = imstripos($file_content, "</script", $style_start);
$style = substr($file_content, $style_start, $style_end - $style_start);
$file_content = str_replace($style, "", $file_content);
}
$file_title = "";

// Rimuovo il titolo dal risultato
while (stristr($file_content, "<h2") !== FALSE) {
$style_start = imstripos($file_content, "<h2");
$style_end = imstripos($file_content, "</h2", $style_start);
$style = substr($file_content, $style_start, $style_end - $style_start);
$file_content = str_replace($style, "", $file_content);
}

// Conto il numero di match nel titolo
foreach ($queries as $query) {
$t_count = preg_match_all('/' . $query . '/', strtolower($value['title']), $matches);
if ($t_count !== FALSE) {
$weight += ($t_count * 4);
$count += $t_count;
}
}

// Conto il numero di match nei tag
foreach ($queries as $query) {
if (in_array($query, $value['tag'])) {
$count++;
$weight += 4;
}
}

$title = "Blog &gt;&gt; " . $value['title'];

// Cerco nel contenuto
foreach($queries as $query) {
$file = strtolower($file_content);
while (($file = stristr($file, $query)) !== FALSE) {
$count++;
$weight++;
$file = substr($file,strlen($query));
}
}

if($count > 0) {
$found_count[$filename] = $count;
$found_weight[$filename] = $weight;
$found_content[$filename] = $file_content;
$found_breadcrumbs[$filename] = "<div class=\"imBreadcrumb\" style=\"display: block; padding-bottom: 3px;\">" . $l10n['blog_published_by'] . "<strong> " . $value['author'] . " </strong>" . $l10n['blog_in'] . " <a href=\"blog/index.php?category=" . $value['category'] . "\" target=\"_blank\" rel=\"nofollow\">" . $value['category'] . "</a> • " . $value['timestamp'] . "</div>";
if ($title == "")
$found_title[$filename] = $filename;
else
$found_title[$filename] = $title;
}
}
}

if($found_count != null) {
arsort($found_weight);
$i = 0;
$pagine = ceil(count($found_count)/$this->results_per_page);
if(($this->page >= $pagine) || ($this->page < 0))
$this->page = 0;
foreach($found_weight as $name => $weight) {
$count = $found_count[$name];
$i++;
if(($i > $this->page*$this->results_per_page) && ($i <= ($this->page+1)*$this->results_per_page)) {
$title = strip_tags($found_title[$name]);
$file = $found_content[$name];
$file = strip_tags($file);
$ap = 0;
$filelen = strlen($file);
$text = "";
for($j=0;$j<($count > 6 ? 6 : $count);$j++) {
$minpos = $filelen;
foreach($queries as $query) {
if($ap < strlen($file) && ($pos = strpos(strtoupper($file),strtoupper($query),$ap)) !== FALSE) {
if($pos < $minpos) {
$minpos = $pos;
$word = $query;
}
}
}
$prev = explode(" ",substr($file,$ap,$minpos-$ap));
if(count($prev) > ($ap > 0 ? 9 : 8))
$prev = ($ap > 0 ? implode(" ",array_slice($prev,0,8)) : "") . " ... " . implode(" ",array_slice($prev,-8));
else
$prev = implode(" ",$prev);
$text .= $prev . "<strong>" . substr($file,$minpos,strlen($word)) . "</strong> ";
$ap = $minpos + strlen($word);
}
$next = explode(" ",substr($file,$ap));
if(count($next) > 9)
$text .= implode(" ",array_slice($next,0,8)) . "...";
else
$text .= implode(" ",$next);
$text = str_replace("|", "", $text);
$html .= "<div class=\"imSearchBlogResult\"><h3><a class=\"imCssLink\" href=\"" . $name . "\">" . $title . "</a></h3>" . $found_breadcrumbs[$name] . "\n" . $text . "<div class=\"imSearchLink\"><a class=\"imCssLink\" href=\"" . $name . "\">" . $domain . $name . "</a></div></div>\n";
}
}
echo " <div class=\"imSLabel\">&nbsp;</div>\n";
}

$html = preg_replace('/\\s+/', ' ', $html);
return array("content" => $html, "count" => count($fo

Por arubenweb

0 de clabLevel



 

chrome
Citar            
MensajeEscrito el 14 Ago 2012 12:21 pm
era necesario pegar toda la clase???

Por SinSemilla

Claber

336 de clabLevel



Genero:Masculino  

i am that i am...

firefox
Citar            
MensajeEscrito el 14 Ago 2012 02:59 pm
Si en efecto ese no es un error... es analizar toda la clase y no creo que sea la del problema... Que te parece si le das una leidita y especificas el problema.

Se que mencionas el attached file, pero puede ser que das mal la URL relativa o que la carpeta no cuenta con los permisos necesarios.

Cuando puedas hechate una vuelta por aca: http://porfirio.mx/wp/category/programacion-y-desarrollo/

Por elporfirio

Claber

652 de clabLevel

1 tutorial

Genero:Masculino  

FullStack Web Developer

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.