本文整理汇总了PHP中Toolbox::encodeInUtf8方法的典型用法代码示例。如果您正苦于以下问题:PHP Toolbox::encodeInUtf8方法的具体用法?PHP Toolbox::encodeInUtf8怎么用?PHP Toolbox::encodeInUtf8使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Toolbox
的用法示例。
在下文中一共展示了Toolbox::encodeInUtf8方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildTicket
/** function buildTicket - Builds,and returns, the major structure of the ticket to be entered.
*
* @param $i mail ID
* @param $options array of possible options
*
* @return ticket fields array
*/
function buildTicket($i, $options = array())
{
global $CFG_GLPI;
$play_rules = isset($options['play_rules']) && $options['play_rules'];
$head = $this->getHeaders($i);
// Get Header Info Return Array Of Headers
// **Key Are (subject,to,toOth,toNameOth,from,fromName)
$tkt = array();
$tkt['_blacklisted'] = false;
// For RuleTickets
$tkt['_mailgate'] = $options['mailgates_id'];
// Use mail date if it's defined
if ($this->fields['use_mail_date']) {
$tkt['date'] = $head['date'];
}
// Detect if it is a mail reply
$glpi_message_match = "/GLPI-([0-9]+)\\.[0-9]+\\.[0-9]+@\\w*/";
// Check if email not send by GLPI : if yes -> blacklist
if (!isset($head['message_id']) || preg_match($glpi_message_match, $head['message_id'], $match)) {
$tkt['_blacklisted'] = true;
return $tkt;
}
// manage blacklist
$blacklisted_emails = Blacklist::getEmails();
// Add name of the mailcollector as blacklisted
$blacklisted_emails[] = $this->fields['name'];
if (Toolbox::inArrayCaseCompare($head['from'], $blacklisted_emails)) {
$tkt['_blacklisted'] = true;
return $tkt;
}
// max size = 0 : no import attachments
if ($this->fields['filesize_max'] > 0) {
if (is_writable(GLPI_TMP_DIR)) {
$tkt['_filename'] = $this->getAttached($i, GLPI_TMP_DIR . "/", $this->fields['filesize_max']);
$tkt['_tag'] = $this->tags;
} else {
//TRANS: %s is a directory
Toolbox::logInFile('mailgate', sprintf(__('%s is not writable'), GLPI_TMP_DIR . "/"));
}
}
// Who is the user ?
$tkt['_users_id_requester'] = User::getOrImportByEmail($head['from']);
$tkt["_users_id_requester_notif"]['use_notification'] = 1;
// Set alternative email if user not found / used if anonymous mail creation is enable
if (!$tkt['_users_id_requester']) {
$tkt["_users_id_requester_notif"]['alternative_email'] = $head['from'];
}
// Add to and cc as additional observer if user found
if (count($head['ccs'])) {
foreach ($head['ccs'] as $cc) {
if ($cc != $head['from'] && !Toolbox::inArrayCaseCompare($cc, $blacklisted_emails) && ($tmp = User::getOrImportByEmail($cc)) > 0) {
$tkt['_additional_observers'][] = array('users_id' => $tmp, 'use_notification' => 1);
}
}
}
if (count($head['tos'])) {
foreach ($head['tos'] as $to) {
if ($to != $head['from'] && !Toolbox::inArrayCaseCompare($to, $blacklisted_emails) && ($tmp = User::getOrImportByEmail($to)) > 0) {
$tkt['_additional_observers'][] = array('users_id' => $tmp, 'use_notification' => 1);
}
}
}
// Auto_import
$tkt['_auto_import'] = 1;
// For followup : do not check users_id = login user
$tkt['_do_not_check_users_id'] = 1;
$body = $this->getBody($i);
// Do it before using charset variable
$head['subject'] = $this->decodeMimeString($head['subject']);
$tkt['_head'] = $head;
if (!empty($this->charset) && !$this->body_converted) {
$body = Toolbox::encodeInUtf8($body, $this->charset);
$this->body_converted = true;
}
if (!Toolbox::seems_utf8($body)) {
$tkt['content'] = Toolbox::encodeInUtf8($body);
} else {
$tkt['content'] = $body;
}
// See In-Reply-To field
if (isset($head['in_reply_to'])) {
if (preg_match($glpi_message_match, $head['in_reply_to'], $match)) {
$tkt['tickets_id'] = intval($match[1]);
}
}
// See in References
if (!isset($tkt['tickets_id']) && isset($head['references'])) {
if (preg_match($glpi_message_match, $head['references'], $match)) {
$tkt['tickets_id'] = intval($match[1]);
}
}
// See in title
if (!isset($tkt['tickets_id']) && preg_match('/\\[.+#(\\d+)\\]/', $head['subject'], $match)) {
//.........这里部分代码省略.........
示例2: DoXML
/**
* Do XML export
**/
function DoXML()
{
global $DB;
$fp = fopen($this->FilePath, 'wb');
fputs($fp, "<?xml version=\"1.0\"?>\n");
fputs($fp, "<dataxml>\n");
foreach ($this->SqlString as $strqry) {
if ($strqry == "") {
$this->IsError = 1;
$this->ErrorString = "Error the query can't be a null string";
return -1;
}
$result = $DB->query($strqry);
if ($result == FALSE) {
$this->IsError = 1;
$this->ErrorString = "Error in SQL Query: " . $strqry;
return -1;
}
// OK... let's create XML ;)
fputs($fp, " <fields>\n");
$i = 0;
$FieldsVector = array();
while ($i < $DB->num_fields($result)) {
$name = $DB->field_name($result, $i);
fputs($fp, " <field>" . $name . "</field>\n");
$FieldsVector[] = $name;
$i++;
}
fputs($fp, " </fields>\n");
// And NOW the Data ...
fputs($fp, " <rows>\n");
while ($row = $DB->fetch_row($result)) {
fputs($fp, " <row>\n");
for ($j = 0; $j < $i; $j++) {
$FieldName = "";
// Name of TAG
$Attributes = "";
switch ($this->Type) {
case 1:
$FieldName = "data";
break;
case 2:
$FieldName = "data" . $j;
break;
case 3:
$FieldName = $FieldsVector[$j];
break;
case 4:
$FieldName = "data";
$Attributes = " fieldname=\"" . $FieldsVector[$j] . "\"";
}
fputs($fp, " <" . $FieldName . $Attributes . ">" . Toolbox::encodeInUtf8(htmlspecialchars($row[$j])) . "</" . $FieldName . ">\n");
}
fputs($fp, " </row>\n");
}
fputs($fp, " </rows>\n");
$DB->free_result($result);
}
fputs($fp, "</dataxml>");
//OK free ... ;)
fclose($fp);
}
示例3: updateDevices
//.........这里部分代码省略.........
} else {
$tmp = array_search(stripslashes($prevalue . $processor["designation"]), $import_device);
list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
$CompDevice->update(array('id' => $id, 'frequency' => $line["PROCESSORS"]));
unset($import_device[$tmp]);
}
}
}
}
break;
case "Item_DeviceNetworkCard":
//Carte reseau
if ($cfg_ocs["import_device_iface"] || $cfg_ocs["import_ip"]) {
PluginOcsinventoryngNetworkPort::importNetwork($PluginOcsinventoryngDBocs, $cfg_ocs, $ocsid, $computers_id, $dohistory);
}
break;
case "Item_DeviceGraphicCard":
$CompDevice = new $devicetype();
//carte graphique
if ($cfg_ocs["import_device_gfxcard"]) {
$do_clean = true;
$query2 = "SELECT DISTINCT(`NAME`) AS NAME,\n `MEMORY`\n FROM `videos`\n WHERE `HARDWARE_ID` = '{$ocsid}'\n AND `NAME` != ''\n ORDER BY `ID`";
$result2 = $PluginOcsinventoryngDBocs->query($query2);
if ($PluginOcsinventoryngDBocs->numrows($result2) > 0) {
while ($line2 = $PluginOcsinventoryngDBocs->fetch_array($result2)) {
$line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line2));
$video["designation"] = $line2["NAME"];
if (!is_numeric($line2["MEMORY"])) {
$line2["MEMORY"] = 0;
}
if (!in_array(stripslashes($prevalue . $video["designation"]), $import_device)) {
$video["memory_default"] = $line2["MEMORY"];
$DeviceGraphicCard = new DeviceGraphicCard();
$video_id = $DeviceGraphicCard->import($video);
if ($video_id) {
$devID = $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'devicegraphiccards_id' => $video_id, 'memory' => $line2["MEMORY"], 'is_dynamic' => 1, '_no_history' => !$dohistory));
}
} else {
$tmp = array_search(stripslashes($prevalue . $video["designation"]), $import_device);
list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
$CompDevice->update(array('id' => $id, 'memory' => $line2["MEMORY"]));
unset($import_device[$tmp]);
}
}
}
}
break;
case "Item_DeviceSoundCard":
$CompDevice = new $devicetype();
//carte son
if ($cfg_ocs["import_device_sound"]) {
$do_clean = true;
$query2 = "SELECT DISTINCT(`NAME`) AS NAME,\n `DESCRIPTION`\n FROM `sounds`\n WHERE `HARDWARE_ID` = '{$ocsid}'\n AND `NAME` != ''\n ORDER BY `ID`";
$result2 = $PluginOcsinventoryngDBocs->query($query2);
if ($PluginOcsinventoryngDBocs->numrows($result2) > 0) {
while ($line2 = $PluginOcsinventoryngDBocs->fetch_array($result2)) {
$line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line2));
if (!$cfg_ocs["ocs_db_utf8"] && !Toolbox::seems_utf8($line2["NAME"])) {
$line2["NAME"] = Toolbox::encodeInUtf8($line2["NAME"]);
}
$snd["designation"] = $line2["NAME"];
if (!in_array(stripslashes($prevalue . $snd["designation"]), $import_device)) {
if (!empty($line2["DESCRIPTION"])) {
$snd["comment"] = $line2["DESCRIPTION"];
}
$DeviceSoundCard = new DeviceSoundCard();
$snd_id = $DeviceSoundCard->import($snd);
if ($snd_id) {
$devID = $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'devicesoundcards_id' => $snd_id, 'is_dynamic' => 1, '_no_history' => !$dohistory));
}
} else {
$id = array_search(stripslashes($prevalue . $snd["designation"]), $import_device);
unset($import_device[$id]);
}
}
}
}
break;
}
// Delete Unexisting Items not found in OCS
if ($do_clean && count($import_device)) {
foreach ($import_device as $key => $val) {
if (!(strpos($key, $devicetype . '$$') === false)) {
list($type, $id) = explode(self::FIELD_SEPARATOR, $key);
$CompDevice->delete(array('id' => $id, '_no_history' => !$dohistory, 1), true);
}
}
}
//TODO Import IP
if ($do_clean && count($import_ip) && $devicetype == "Item_DeviceNetworkCard") {
foreach ($import_ip as $key => $val) {
if ($key > 0) {
$netport = new NetworkPort();
$netport->delete(array('id' => $key));
}
}
}
//Alimentation
//Carte mere
}
示例4: get_update_content
function get_update_content($DB, $table, $from, $limit, $conv_utf8)
{
$content = "";
$DB->query("SET NAMES latin1");
$result = $DB->query("SELECT *\n FROM `{$table}`\n LIMIT {$from}, {$limit}");
if ($result) {
while ($row = $DB->fetch_assoc($result)) {
if (isset($row["id"])) {
$insert = "UPDATE `{$table}`\n SET ";
foreach ($row as $key => $val) {
$insert .= " `" . $key . "` = ";
if (!isset($val)) {
$insert .= "NULL,";
} else {
if ($val != "") {
if ($conv_utf8) {
// Gestion users AD qui sont deja en UTF8
if ($table != "glpi_users" || !Toolbox::seems_utf8($val)) {
$val = Toolbox::encodeInUtf8($val);
}
}
$insert .= "'" . addslashes($val) . "',";
} else {
$insert .= "'',";
}
}
}
$insert = preg_replace("/,\$/", "", $insert);
$insert .= " WHERE `id` = '" . $row["id"] . "' ";
$insert .= ";\n";
$content .= $insert;
}
}
}
return $content;
}
示例5: exec
if (!empty($data2["mac"])) {
echo "<p><b>{$plugin_shellcommands_shellcommands_id} -> " . $val['host'] . " (" . $val['mac'] . ")</b></p>";
$command = $command_item->sendMagicPacket($val['mac'], $val['ip'], $val['netmask']);
}
}
}
} else {
$host = $item->getField('mac');
echo "<p><b>{$plugin_shellcommands_shellcommands_id} -> " . $host . "</b></p>";
$command = $command_item->sendMagicPacket($host);
}
} else {
echo "<p><b>{$plugin_shellcommands_shellcommands_id} -> " . $host . "</b></p>";
$command = $path . " " . $parameters . " " . $host;
$ouput[] = null;
exec($command, $ouput);
$cmd = count($ouput);
echo " <font color=blue>";
for ($i = 0; $i < $cmd; $i++) {
echo Toolbox::encodeInUtf8($ouput[$i]) . "<br>";
}
echo "</font>";
echo "<br>" . $command;
}
}
echo "</td>";
echo "</tr>";
unset($ouput);
}
echo "</table></div>";
Html::footer();
示例6: sendMagicPacket
function sendMagicPacket($macaddress, $ip = null, $netmask = null)
{
$packet = $this->doMagicPacket($macaddress);
$ip = ip2long($ip);
$mask = ip2long($netmask);
$broadcast = null;
// Si l'IP et le masque sont fournis (et sont valides) on tente de calculer l'adresse de broadcast du reseau
if ($ip !== false && $mask !== false) {
$mask = ~$mask;
$broadcast = long2ip($ip | $mask);
}
$error = 0;
$mcastaddr = "224.0.0.1";
/* TO BE TESTED
$addr_byte = explode(':', $macaddress);
$hw_addr = '';
for ($a=0; $a <6; $a++) $hw_addr .= chr(hexdec($addr_byte[$a]));
$packet = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255);
for ($a = 1; $a <= 16; $a++) $msg .= $hw_addr; */
if (is_null($broadcast)) {
//j'arrive pas a faire du broadcast avec cette methode alors c'est du multicast pour tous les
//postes d'un ss reseau
$sock = fsockopen("udp://" . $mcastaddr, 9, $errno, $errostr);
//$sock = fsockopen("udp://255.255.255.255", 9, $errno, $errostr);
if (!$sock) {
echo __('There is an error with socket creation', 'shellcommands') . " : ";
echo Toolbox::encodeInUtf8($errostr) . " " . Toolbox::encodeInUtf8($errno);
echo "<br />";
$error = 1;
} else {
fwrite($sock, $packet);
fclose($sock);
}
} else {
// Cette methode necessite que php soit compile avec les sockets
$sock = socket_create(AF_INET, SOCK_DGRAM, 0);
//TO BE TESTED $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if ($sock < 0) {
echo "Error creating socket : " . strerror($sock) . "\n";
echo "Error code is '" . socket_last_error($sock) . "' - ";
echo socket_strerror(socket_last_error($sock));
$error = 1;
} else {
$opt_ret = socket_set_option($sock, 1, 6, TRUE);
if ($opt_ret < 0) {
echo "setsockopt() failed, error: " . strerror($opt_ret) . "\n";
$error = 1;
} else {
$send_ret = socket_sendto($sock, $packet, strlen($packet), 0, $broadcast, 9);
//TO BE TESTED $send_ret = socket_sendto($sock, $packet, strlen($packet), 0, $ip, $socket_number) $socket_number=7 ?
if ($send_ret < 0) {
echo "Error when sending packet " . strerror($send_ret) . "<BR>\n";
$error = 1;
} else {
socket_close($sock);
}
}
}
}
if ($error != 1) {
$txt = is_null($broadcast) ? $mcastaddr : $broadcast;
echo __('Magic packet sending to', 'shellcommands') . " " . $macaddress . " (" . $txt . ")";
} else {
echo __('The packet cannot be send', 'shellcommands');
}
}
示例7: updateDevices
//.........这里部分代码省略.........
$video["designation"] = $line2["NAME"];
$video["entities_id"] = $entities_id;
if (!is_numeric($line2["MEMORY"])) {
$line2["MEMORY"] = 0;
}
if (!in_array(stripslashes($prevalue . $video["designation"]), $import_device)) {
$video["memory_default"] = $line2["MEMORY"];
$DeviceGraphicCard = new DeviceGraphicCard();
$video_id = $DeviceGraphicCard->import($video);
if ($video_id) {
$devID = $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'devicegraphiccards_id' => $video_id, 'memory' => $line2["MEMORY"], 'is_dynamic' => 1, '_no_history' => !$dohistory));
}
} else {
$tmp = array_search(stripslashes($prevalue . $video["designation"]), $import_device);
list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
$CompDevice->update(array('id' => $id, 'memory' => $line2["MEMORY"]));
unset($import_device[$tmp]);
}
}
}
}
}
break;
case "Item_DeviceSoundCard":
$CompDevice = new $devicetype();
//carte son
$do_clean = true;
if ($ocsComputer) {
if (isset($ocsComputer['SOUNDS'])) {
foreach ($ocsComputer['SOUNDS'] as $line2) {
$line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line2));
if ($line2['NAME']) {
if (!$cfg_ocs["ocs_db_utf8"] && !Toolbox::seems_utf8($line2["NAME"])) {
$line2["NAME"] = Toolbox::encodeInUtf8($line2["NAME"]);
}
$snd["entities_id"] = $entities_id;
$snd["designation"] = $line2["NAME"];
if (!in_array(stripslashes($prevalue . $snd["designation"]), $import_device)) {
if (!empty($line2["DESCRIPTION"])) {
$snd["comment"] = $line2["DESCRIPTION"];
}
$DeviceSoundCard = new DeviceSoundCard();
$snd_id = $DeviceSoundCard->import($snd);
if ($snd_id) {
$devID = $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'devicesoundcards_id' => $snd_id, 'is_dynamic' => 1, '_no_history' => !$dohistory));
}
} else {
$id = array_search(stripslashes($prevalue . $snd["designation"]), $import_device);
unset($import_device[$id]);
}
}
}
}
}
break;
case "PluginOcsinventoryngItem_DeviceBiosdata":
$CompDevice = new $devicetype();
//Bios
$do_clean = true;
if ($ocsComputer) {
if (isset($ocsComputer['BIOS'])) {
$bios["designation"] = $ocsComputer['BIOS']["BVERSION"];
$bios["assettag"] = $ocsComputer['BIOS']["ASSETTAG"];
$bios["entities_id"] = $entities_id;
//$date = str_replace("/", "-", $ocsComputer['BIOS']["BDATE"]);
//$date = date("Y-m-d", strtotime($date));
示例8: updateDevices
//.........这里部分代码省略.........
if ($line2["NAME"] != "Not Specified") {
$port["designation"] .= " " . $line2["NAME"];
} else {
if ($line2["CAPTION"] != "None") {
$port["designation"] .= " " . $line2["CAPTION"];
}
}
$port["entities_id"] = $entities_id;
if (!empty($port["designation"])) {
if (!in_array(stripslashes($prevalue . $port["designation"]), $import_device)) {
if (!empty($line2["DESCRIPTION"]) && $line2["DESCRIPTION"] != "None") {
$port["comment"] = $line2["DESCRIPTION"];
}
$DevicePci = new DevicePci();
$port_id = $DevicePci->import($port);
if ($port_id) {
$CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'devicepcis_id' => $port_id, 'is_dynamic' => 1), array(), $cfg_ocs['history_devices']);
}
} else {
$tmp = array_search(stripslashes($prevalue . $port["designation"]), $import_device);
unset($import_device[$tmp]);
}
}
}
}
//Slots
if (isset($ocsComputer['SLOTS'])) {
$CompDevice = new $devicetype();
$do_clean = true;
foreach ($ocsComputer['SLOTS'] as $line2) {
$line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line2));
if ($line2['NAME']) {
if (!$cfg_ocs["ocs_db_utf8"] && !Toolbox::seems_utf8($line2["NAME"])) {
$line2["NAME"] = Toolbox::encodeInUtf8($line2["NAME"]);
}
$pci["entities_id"] = $entities_id;
$pci["designation"] = $line2["NAME"];
if (!in_array(stripslashes($prevalue . $pci["designation"]), $import_device)) {
if (!empty($line2["DESCRIPTION"])) {
$pci["comment"] = $line2["DESCRIPTION"];
}
$DevicePci = new DevicePci();
$pci_id = $DevicePci->import($pci);
if ($pci_id) {
$CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'devicepcis_id' => $pci_id, 'is_dynamic' => 1), array(), $cfg_ocs['history_devices']);
}
} else {
$id = array_search(stripslashes($prevalue . $pci["designation"]), $import_device);
unset($import_device[$id]);
}
}
}
}
break;
case "Item_DeviceProcessor":
$CompDevice = new $devicetype();
//Processeurs:
$do_clean = true;
foreach ($ocsComputer as $line2) {
$line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line2));
$processor = array();
$processor["designation"] = $line2["TYPE"];
if (!is_numeric($line2["SPEED"])) {
$line2["SPEED"] = 0;
}
$processor["manufacturers_id"] = Dropdown::importExternal('Manufacturer', self::encodeOcsDataInUtf8($cfg_ocs['ocs_db_utf8'], $line2["MANUFACTURER"]));