For some reason this works flawlesly on my out of the box WAMP yet when uploaded to web server it drops the following error:
Severity: Warning
Message: DOMDocument::load(): I/O warning : failed to load external
entity
"/mounted-storage/home155/sub004/sc81961-YHHB/* * * * * *.com/dev/
2012-10-04 03:15:03
4 2012-10-04 03:25:16
2012-09-17 19:25:11
3
0
1
1
2012-10-04 04:08:18 "
Filename: models/fuel_model.php
Line Number: 74
It's pointing to the applications root folder.
Code:
function get_pos($id)
{
$get = $this->db->query(
"SELECT * FROM holding WHERE id=1"
);
$stream = $get->row_array();
$addr = 'http://api.eveonline.com/corp/StarbaseDetail.xml.aspx?keyID='.$stream['apiid'].
'&vCode='.$stream['apikey'] . '&itemID=' . $id;
$link = new DOMDocument();
$get_cache = $this->db->query(
"SELECT * FROM cache_poses WHERE posid=".$id
);
$cache = $get_cache->row_array();
$posted = strtotime(date("Y-m-d H:i:s"));
if(!empty($cache))
{
$posted = strtotime($cache['cachedon']);
}
$current = strtotime(date("Y-m-d H:i:s"));
$mins = $posted - $current;
$expiry = $mins % 60;
if(empty($cache))
{
$link->load($addr);
$this->db->query("INSERT INTO cache_poses (data, posid) VALUES (" . $this->db->escape($link->saveXML()) . "," . $id .")");
} elseif(!empty($cache) && ($expiry >= 360)) {
$this->db->query("DELETE FROM cache_poses WHERE posid=".$id);
$link->load($addr);
$this->db->query("INSERT INTO cache_poses (data, posid) VALUES (" . $this->db->escape($link->saveXML()) . "," . $id . ")");
} elseif(!empty($cache) && ($expiry < 360)) {
$link->load($cache['data']);
}
$supply = $link->getElementsByTagName('row');
$supplies = array();
foreach ($supply as $fuel) {
$block = $fuel->attributes;
$put = $this->db->query('SELECT name FROM items WHERE typeid='.$block->item(0)->nodeValue);
$lck = $put->row_array();
$supplies[$lck['name']] = $block->item(1)->nodeValue;
}
$info = $this->implode_with_keys($supplies);
return $info;
}
Can you post the XML? It is referencing a DTD that must be accessible on your local dev machine but not on your live server. If the DTD and the entities it defines are not important to your XML, you can suppress the warning, and likely get a performance increase for not loading an extra resource, by disabling the loading of enternal entities before calling DOMDocument::load().
$link->resolveExternals = FALSE;
$link->load($cache['data']);
http://www.php.net/manual/en/class.domdocument.php#domdocument.props.resolveexternals
By the way, DOMDocument::load() accepts a file path. If your $cache['data'] is really a string of XML in the database, you need to use DOMDocument::loadXML().
Related
Currently, I created a system that uses daypilot calendar. For example, when I clicked a date, it will show the list of activities on that selected date.
Below code is successful display the list:
<?php
require_once '../../../config/configPDO.php';
$Fac_ID = strtolower($_GET['Fac_ID']);
$Room_Desc = strtolower($_GET['Room_Desc']);
$stmt = $conn->prepare("SELECT * FROM booking LEFT JOIN room ON booking.Room_ID = room.Room_ID
WHERE room.Fac_ID = '$Fac_ID' AND room.Room_Desc = '$Room_Desc' AND Book_Status <> 'Reject'");
$stmt->execute();
$result = $stmt->fetchAll();
class Event {}
$events = array();
foreach($result as $row) {
$e = new Event();
$e->id = $row['Book_No'];
$e->text = "Meeting Name: ". $row['Meeting_Description']. " || " ."Requested by: ".$row['Requested_by']. " || " ."Location: ".$row['Fac_ID']. ", " .$row['Room_Desc'];
$e->start = $row['StartTime'];
$e->end = $row['EndTime'];
$events[] = $e;
}
header('Content-Type: application/json');
echo json_encode($events);
?>
But, when I change the code (Because want to retrieve json data), the data doesn't display at calendar.
Below is the code:
<?php
require_once '../../../config/configPDO.php';
$Fac_ID = strtolower($_GET['Fac_ID']);
$Room_Desc = strtolower($_GET['Room_Desc']);
//retrieve json
$url = "http://172.20.0.45/TGWebService/TGWebService.asmx/displayPABooking?Fac_ID=$Fac_ID&Room_Desc=$Room_Desc&Room_ID=&Book_No=&Book_Date_From=&Book_Date_To=";
$data = file_get_contents($url); //line 10
$json = json_decode($data);
$result = $json->bookingList; //line 12
class Event {}
$events = array(); //
foreach($result as $row) { //line 17
$e = new Event();
$e->id = $row->bookNo;
$e->text = "Meeting Name: ".$row->desc. " || " ."Requested by: ".$row->requestedBy." || " ."Location: ".$row->facID.", " .$row->roomName;
$e->start = $row->startTime;
$e->end = $row->endTime;
$events[] = $e;
}
header('Content-Type: application/json');
echo json_encode($events);
?>
And, This is the error that I found at console:
PHP Warning: file_get_contents(http://172.20.0.45/TGWebService/TGWebService.asmx/displayPABooking?Fac_ID=TGT&Room_Desc=LEVEL 1 &Room_ID=&Book_No=&Book_Date_From=&Book_Date_To=): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
in C:\inetpub\wwwroot\ebooking\pages\manual_booking\backend\backend_events.php on line 10
PHP Notice: Trying to get property 'bookingList' of non-object in C:\inetpub\wwwroot\ebooking\pages\manual_booking\backend\backend_events.php on line 12
PHP Warning: Invalid argument supplied for foreach() in C:\inetpub\wwwroot\ebooking\pages\manual_booking\backend\backend_events.php on line 17
Can I know where I need to change? Thanks
This is probably because of the space in "Level 1". Try urlencoding your $_GET parameters:
$url = "http://172.20.0.45/TGWebService/TGWebService.asmx/displayPABooking?Fac_ID=" . urlencode($Fac_ID) . "&Room_Desc=" . urlencode($Room_Desc) . "&Room_ID=&Book_No=&Book_Date_From=&Book_Date_To=";
If you want to make the variable substitution more explicit, you could use strtr:
$template = "http://172.20.0.45/TGWebService/TGWebService.asmx/displayPABooking?Fac_ID={Fac_ID}&Room_Desc={Room_Desc}&Room_ID=&Book_No=&Book_Date_From=&Book_Date_To=";
$url = strtr($template, array(
'{Fac_ID}' => $Fac_ID,
'{Room_Desc}' => $Room_Desc
));
I am unable to export my mysql table to XML format using PHP, I receive the following error when I run the below script. I have removed the connection bit, I have gone through already errors but was not able resolve this issue.
Catchable fatal error: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, null given,
Script:
<?php
$query = "SELECT id, name, plate, datetime , time , image_name FROM EarlsdonMSIN_anpr_vega";
$camArray = array();
if ($result = $mysqli->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
array_push($camArray, $row);
}
if(count($camArray)){
createXMLfile($camArray);
}
/* free result set */
$result->free();
}
/* close connection */
$mysqli->close();
function createXMLfile($camArray){
$filePath = '/cam.xml';
$dom = new DOMDocument('1.0', 'utf-8');
$root = $dom->createElement('cam');
for($i=0; $i<count($camArray); $i++){
$camId = $camArray[$i]['id'];
$camName = $camArray[$i]['name'];
$camplate = $camArray[$i]['plate'];
$camdatetime = $camArray[$i]['datetime'];
$camtime = $camArray[$i]['time'];
$camimagename = $camArray[$i]['image_name'];
$cam = $dom->createElement('cam');
$cam->setAttribute('id', $camId);
$name = $dom->createElement('name', camName);
$cam->appendChild($name);
$plate = $dom->createElement('plate', $camplate);
$cam->appendChild($plate);
$datetime = $dom->createElement('datetime', $camdatetime);
$cam->appendChild($datetime);
$time = $dom->createElement('time', $camtime);
$cam->appendChild($time);
$imagename = $dom->createElement('image_name', $camimagename); $cam->appendChild($image_name);
$root->appendChild($cam);
}
$dom->appendChild($root);
$dom->save($filePath);
}
First of thank you for your help.
The code piece "while (sqlite_has_more($dres))" is using sqlite2 and I need sqlite3. If there isn't a replacement for has_more is there another code I can use to still Find whether or not more rows are available?
F.Y.I. The server updated their stuff which included their sqlite and now I have to fix this last peice of code to get the schedule to populate and not give me this error.
Fatal error: Non-static method SQLite3::open() cannot be called statically in /home/server/public_html/current-list.php on line 57
$row_num = 0;
if ($dbh = SQLite3::open($sked_path))
{
$qsql = "SELECT rowid,* FROM sked ORDER BY sk_dow_num, sk_time_start, sk_time_end";
$dres = SQLite3::query($dbh, $qsql);
if (SQLite3::num_Rows($dres) > 0)
{
$last_dow = "";
$last_start = "0000";
$last_end = "0000";
while (sqlite_has_more($dres))
{
$ska = Sqlite3Result::fetchArray($dres, SQLITE3_ASSOC);
$rid = $ska['rowid'];
$dow = $ska['sk_dow_name'];
$start = $ska['sk_time_start'];
$end = $ska['sk_time_end'];
$title = preg_replace("/<br\s*\/*>/", " ", $ska['sk_show_title']);
$show_dow = strtoupper($dow);
$show_start = strtoupper(formatTimeAmPm($start));
$show_end = strtoupper(formatTimeAmPm($end));
$show_style = "";
if (stristr($title, "Encore Show"))
$show_style = " class=\"$text_style\"";
Something like ...
<?php
$dbh = new SQLite3;
if ( !$dbh->open($sked_path) ) {
trigger_error('...error handling...', E_USER_ERROR);
}
else {
$dres = $dbh->query('
SELECT
rowid,*
FROM
sked
ORDER BY
sk_dow_num, sk_time_start, sk_time_end
');
if ( !$dres ) {
trigger_error('...error handling...', E_USER_ERROR);
}
else {
$ska = $dres->fetchArray(SQLITE3_ASSOC);
if ( !$ska ) {
onNoRecords();
}
else {
do {
doSomethingWithRowData($ska);
}
while( false!=($ska=$dres->fetchArray(SQLITE3_ASSOC)) );
}
}
}
(completely untested)
I have the following snippet:
$post_ids = array("307781172646235_739219686169046");
$quoted_post_ids = array();
foreach ($post_ids as $id) {
$quoted_post_ids[] = '"' . $id . '"';
}
$fql = urlencode(
"SELECT attachment FROM stream WHERE post_id IN(" . implode(',', $quoted_post_ids) . ")"
);
$all_photos_url = 'https://graph.facebook.com/fql?q=' . $fql . '&access_token=' . "XXXXXXXX";
$all_photos_result = drupal_http_request($all_photos_url);
$all_photos = json_decode($all_photos_result->data);
dpm($all_photos);
$actual_post = NULL;
foreach ($all_photos->data as $k => $post) {
$actual_post = array();;
foreach ($post->attachment->media as $photo) {
if (isset($photo->photo)) {
$photo_url = 'https://graph.facebook.com/' . $photo->photo->fbid;
$photo_result = drupal_http_request($photo_url);
$photo_info = json_decode($photo_result->data);
if (isset($photo_info->images[0])) {
$candidate_pic_url = $photo_info->images[0]->source;
if (!empty($candidate_pic_url) && valid_url($candidate_pic_url)) {
if (!isset($actual_post['picture_big'])) {
$actual_post['picture_big'] = array();
}
$actual_post['picture_big'][] = $candidate_pic_url;
$actual_post['picture_metadata'][] = $photo_info;
}
}
usleep(500);
}
}
dpm($actual_post);
}
The dpm() is just a Drupal-specific debug helper that outputs the variable. So the issue is that if I execute it at localhost, or on a staging server, it works, but on production, I do not have the image always via the graph API. Sometimes, I have, sometimes i does not have. It's a shared hosting at Gandi (https://www.gandi.net/hosting/simple) . Is it possible that the shared hosting itself becomes rate-limited?
Update:
On production, the second HTTP request gives: "Application request limit reached" OAuth Exception
I export every day the sales of yesterday (Magento) by a custom phpscript.
Since we got directbanking i had to change the code a bit.
The idea was to set the value "direct" in the CC_Type(Visa,JBC,...) so that we have good looking data for our analytics.
The csv looks actually clean and when i do a manually import (where you customize the import) with excel or mssql it works as wished. But when i let it open by it self (like our system would do to import the data in the night) strange things happen.
In the data-/functionbar (fx) you can see that the curser is ON the D and if I insert more letters they are appendet AFTER the p from onlineshop.
the header (first line) and every following dataline become imported without the "", I know that excel sometimes does this, but it never did before with this document.
Well thats a lie i never payed attation if it is so or not, because it simply worked.
//
class Mage_Shell_Compiler extends Mage_Shell_Abstract {
const OUTPUT = false;
const DEL = "\t";
const BR = "\r\n";
const FILEPATH = '../var/export/';
const FILENAME = 'tdtaCash';
protected $_orders = array();
protected $_csv_output = '';
protected $_headers = array(
"dtTag" => false, // Bestelldatum
"fiCBox" => 94,
"fiCashier" => "onlineshop",
"fiCurrency" => array('Visa', 'MC', 'Amex', 'DC', 'JCB', 'Direct'), // Zahlungsart
"dtRev" => false // Bruttoumsatz an diesem Tag mit dieser Zahlungsart
);
/// #see $_headers for details
protected function addOrderToRows($order, $rows) {
$order_data = $order->getOrigData();
$type = $order->getPayment()->getAdditionalInformation('CC_BRAND');
switch ($type) {
case 'VISA':
$type = 'Visa';
break;
case 'MasterCard':
$type = 'MC';
break;
case 'American Express':
$type = 'Amex';
break;
case 'Diners Club':
$type = 'DC';
break;
case 'JCB':
$type = 'JCB';
break;
default:
$brand = $order->getPayment()->getAdditionalInformation('BRAND');
if ($brand == 'DirectEbankingAT') {
$type = 'Direct';
}
break;
}
if (empty($rows[$type])) {
$row = $this->_headers;
$row["dtRev"] = 0;
} else
$row = $rows[$type];
//$row['dtTag'] = date('Y-m-d', strtotime($order_data['created_at']));
$row['dtTag'] = $this->formatDate($order_data['created_at'], 'exportdate', true);
$row["fiCurrency"] = $type;
$row["dtRev"] += $order_data['grand_total'];
$rows[$type] = $row;
return $rows;
}
protected function __($msg) {
if (self::OUTPUT)
print $msg . "\n";
}
/**
* Get Orders instance
*
* #return Mage_Sales_Model_Order
*/
protected function _getOrders($day = 1) {
$timeZoneOffset = Mage::getModel('core/date')->getGmtOffset();
$yesterday = date('Y-m-d', strtotime("-$day day")) . ' 00:00:00';
$yesterday = date('Y-m-d H:i:s', strtotime($yesterday) - $timeZoneOffset);
$day--;
$today = date('Y-m-d', strtotime("-$day day")) . ' 00:00:00';
$today = date('Y-m-d H:i:s', strtotime($today) - $timeZoneOffset);
if (!$this->_orders)
$this->_orders = Mage::getResourceModel('sales/order_collection')
->addAttributeToSelect('*')
/// #note uncommented to remove daily filter
->addAttributeToFilter('created_at', array("from" => $yesterday, "to" => $today))
->addAttributeToFilter('status', array('nin' => array('holded', 'canceled', 'pending_payment', 'pending')));
return $this->_orders;
}
protected function addRowToOutput($row) {
if (isset($row["dtRev"]))
$row["dtRev"] = number_format($row["dtRev"], 2);
$this->_csv_output .= '"' . implode('"' . self::DEL . '"', $row) . '"' . self::BR;
}
protected function addCsvHeader() {
$this->addRowToOutput(array_keys($this->_headers));
}
/**
* Run script
*
*/
public function run() {
if ($this->getArg('export')) {
$day = is_numeric($this->getArg('day')) ? $this->getArg('day') : 1;
$file = self::FILEPATH . self::FILENAME . '.csv';
$this->__('orders to export ' . count($this->_getOrders($day)));
// add header if file is empty
if (!strlen(trim(file_get_contents(dirname(__FILE__) . '/' . $file))))
$this->addCsvHeader();
$rows = array();
foreach ($this->_getOrders($day) as $order)
$rows = $this->addOrderToRows($order, $rows);
while ($row = array_shift($rows))
$this->addRowToOutput($row);
file_put_contents(dirname(__FILE__) . '/' . $file, $this->_csv_output, FILE_APPEND);
$this->__($this->_csv_output);
} else {
echo $this->usageHelp();
}
}
/**
* Retrieve Usage Help Message
*
*/
public function usageHelp() {
return <<<USAGE
Usage: php -f export_tdtaCash.php -- [options]
export ... Appends data to file tdtaCash.csv in Directory var/export/
day ... days to count back
help ... This help
USAGE;
}
}
$shell = new Mage_Shell_Compiler();
$shell->run();
So my question is, may someone can explain me what kind of sourcery is responsable for this effect, and what can i do preventive to not get such results again?!
EDIT:
here is a screenshot of the CSV opend in Notepad++
Change file resolution from CSV to TXT and use Import file, specify TAB character as separator - and you'll be fine!
That's not a C SV, it's a T SV, a tab separated values file.
Excel won't know that unless you tell it and misinterprets the data.