SplFileObject::SKIP_EMPTY does not work - spl

I'm facing a huge difficulty right now. I did not succeed in finding how to fix it.
I'm trying to display csv datas without empty lines. I thought the SPL library could permit it. But whatever i do i can't find why it's not working.
Could you?
Here's my code (quite simple):
<?php
// Lecture du fichier csv
$csv = new SplFileObject('fichiers/tempo/test.csv', 'r');
// Flags pour ignorer les lignes vides
$csv->setFlags(SplFileObject::READ_CSV | SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE);
$csv->setCsvControl(';');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="style.css" />
<link rel="icon" type="image/png" href="images/favicon.png" />
<title>Nas - Insertion de données</title>
</head>
<body>
<table>
<?php
$tableau = array();
// On parcours les lignes du fichier csv en lecture ==> $csv
foreach($csv as $line){
echo '<tr>';
foreach($line as $var){
echo '<td>-'.$var.'</td>';
}
echo '</tr>';
}
?>
</table>
</body>
</html>
My flags do nothing, and i don't know what i'm doing wrong.....
Thank you.

You should use these flags to ignore empty lines:
$file->setFlags(
SplFileObject::READ_CSV |
SplFileObject::SKIP_EMPTY |
SplFileObject::READ_AHEAD |
SplFileObject::DROP_NEW_LINE
);

Thank you for your time. I tried with php 5.4, 5.5, 5.6 and 7.0 but it did nothing. Then i choose to put the following test to every loop:
foreach($csv as $line){
// Ignoring empty lines
if(implode($line) == null)continue;
...
At least it works!
My Csv is something like:
Wine List;;;;;;;;;;
;;;;;;;;;;
;This wine is stored at the chƒteau or at our supplier's warehouse and will be available for collection later on.;;;;;;;;;
;;;;;;;;;;
Product Type;Vintage;Wine;Appellation;Classement;Qty;Size;Price;W-A;W-S;Comments
Red wine;2013;Aiguilhe (d');Castillon - c“tes de bordeaux;;216;750 mL;11,80 ?;87-89s;86-89;
Red wine;2012;Aiguilhe (d');Castillon - c“tes de bordeaux;;168;750 mL;12,50 ?;89-91;89;
Red wine;2011;Aiguilhe (d');Castillon - c“tes de bordeaux;;395;750 mL;12,60 ?;88;89;

Related

DHTMLXGantt and Laravel - Data doesn't display in extended templates

Background
Following this tutorial from Jan 2016, ( https://dhtmlx.com/blog/using-dhtmlxgantt-with-laravel/ ) I began experimenting with DHTMLXGantt (v4.1) and Laravel (v5.4) and ran into some troubles getting the sample data from a mysql/mariadb database to display in the gantt chart. The initial troubles had to do with the DHTMLX connector not staying current with some Laravel changes. For the sake of others who may read this and are struggling with the same issues, the two basic problems I already solved were:
(1) I was referred to this [updated] connector which was compatible with Laravel's recent versions ( https://github.com/mperednya/connector-php/tree/modern ). And,
(2) I specified a date range that matched the dates of the sample data (from 2013), such as...
gantt.config.start_date = new Date(2013, 04, 01);
gantt.config.end_date = new Date(2013, 04, 30);
At this point I was able to successfully use Laravel as a backend server for the DHTMLXGantt chart (including read-write with the sample data).
Problem
The problem I am having now is trying to move from the simplistic sample, to something slightly more complex. Specifically, when I employ Laravel's extended templating I get the gantt chart painted on screen, but no project/task data displays in the chart.
To explain this a little more specifically, a simple Laravel view with the whole page contained within it works as expected. For example, this blade file (gantt.blade.php) works.
<!DOCTYPE html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<script src="codebase/dhtmlxgantt.js"></script>
<link rel="stylesheet" href="codebase/dhtmlxgantt.css">
<link rel="stylesheet" href="codebase/skins/dhtmlxgantt_skyblue.css" type="text/css" media="screen" title="no title" charset="utf-8">
</head>
<body>
<div class="container">
<h1>Placeholder Header</h1>
<div id="gantt_here" style='width:100%; height:500px;'></div>
<script type="text/javascript">
gantt.config.xml_date = "%Y-%m-%d %H:%i:%s";
gantt.config.step = 1;
gantt.config.scale_unit= "week";
gantt.config.autosize = "xy";
gantt.config.fit_tasks = true;
gantt.config.columns = [
{name:"text", label:"Task name", width:"*", tree:true },
{name:"start_date", label:"Start time", align: "center" },
{name:"duration", label:"Duration", align: "center" },
{name:"add", label:"", width:44 }
];
gantt.init("gantt_here");
gantt.load("./gantt_data", "xml");
var dp = new gantt.dataProcessor("./gantt_data");
dp.init(gantt);
</script>
<h1>Placeholder Footer</h1>
</div>
</body>
But if I try using an extended app layout with the intention of building out a standard look & feel across all pages, the Gantt chart appears and is formated as I expect, but no data appears within the gantt chart. Here is top-level layout file (app.blade.php)
<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<link rel="stylesheet" href="codebase/dhtmlxgantt.css">
<link rel="stylesheet" href="codebase/skins/dhtmlxgantt_skyblue.css" type="text/css" media="screen" title="no title" charset="utf-8">
<!-- Scripts -->
<script>
window.Laravel = {!! json_encode([
'csrfToken' => csrf_token(),
]) !!};
</script>
<script src="codebase/dhtmlxgantt.js"></script>
</head>
<body>
<div id="app">
<!-- menus and other bootstrap styling removed for brevity -->
#yield('content')
</div>
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}"></script>
</body>
</html>
And here's the "content" view (index.blade.php)...
#extends('layouts.app')
#section('content')
<div id="gantt_here" style='width:100%; height:500px;'></div>
<script type="text/javascript">
gantt.config.xml_date = "%Y-%m-%d %H:%i:%s";
gantt.config.step = 1;
gantt.config.scale_unit= "week";
gantt.config.autosize = "xy";
gantt.config.fit_tasks = true;
gantt.config.columns = [
{name:"text", label:"Task name", width:"*", tree:true },
{name:"start_date", label:"Start time", align: "center" },
{name:"duration", label:"Duration", align: "center" },
{name:"add", label:"", width:44 }
];
gantt.init("gantt_here");
gantt.load("./gantt_data", "xml");
var dp = new gantt.dataProcessor("./gantt_data");
dp.init(gantt);
</script>
</div>
#endsection
Other things I've tried:
Using Chrome developer tools, I can see that the xml data was properly delivered to the browser in both examples. This made me think maybe it is a timing problem of some sort. So I put a couple links on the page just to test clearing the chart and reloading it. But still no change.
<a onclick="gantt.clearAll()" href="javascript:void(0);">Clear</a>
<a onclick="gantt.load('./gantt_data', 'xml')" href="javascript:void(0);">Refresh</a>
I also tried moving the div block "gantt_here" to various other places above and below Laravel's template directives. It fails in all cases, except when this div block is outside (either above or below) the "app" div tag in "app.blade.php" which, of course, defeats the purpose I am trying to achieve.
My goal is to use this chart within Laravel's extended templating capabilities. But I can't figure out what's wrong. Any ideas?
After further troubleshooting, I discovered the problem. It turns out that in app.blade.php, I was loading the app.js at the bottom of the body tag. When I moved this up to the HTML header area, the data began to display properly.

No able to change some word in English version of my site

I've an e-commerce site in Magento 1.9 with two version: English and French. I've to change some words in both English version and in the French. For example, in the English version, I've to change word "BAG" in the homepage menu.
I've to replace "BAG" with "SHOPPING BAG" but, inserting string "BAG", "SHOPPING BAG" (or "bag","shopping bag", or "Bag", "Shopping bag") into translate.csv of the theme (in the English folder) any change is shown in the frontend. Activating path hints for the English version I notice that the phtml file that builds the block that contains this menu is the following:
<meta http-equiv="Content-Type" content="<?php echo $this->getContentType() ?>" />
<title><?php echo $this->getTitle()?></title>
<meta name="description" content="<?php echo htmlspecialchars($this->getDescription()) ?>" />
<meta name="keywords" content="<?php echo htmlspecialchars($this->getKeywords()) ?>" />
<meta name="robots" content="<?php echo htmlspecialchars($this->getRobots()) ?>" />
<link rel="icon" href="<?php echo $this->getFaviconFile(); ?>" type="image/x-icon" />
<link rel="shortcut icon" href="<?php echo $this->getFaviconFile(); ?>" type="image/x-icon" />
<?php
$currentUrl = Mage::helper('core/url')->getCurrentUrl();
if (preg_match('/^https/', $currentUrl)) {
$currentUrl = str_replace('https://', 'http://', $currentUrl);
}
$exclusions = array(
'checkout/',
'customer/account/'
);
$regexUrl = '/^' . str_replace(array('/', '.'), array('\\/', '\\.'), Mage::getBaseUrl() . '(?:(?:' . implode(')|(?:', $exclusions) . '))') . '/';
if (!preg_match($regexUrl, $currentUrl)) {
echo '<link rel="canonical" href="' . $currentUrl . '" />';
}
?>
<!--[if lt IE 7]>
<script type="text/javascript">
//<![CDATA[
var BLANK_URL = '<?php echo $this->helper('core/js')->getJsUrl('blank.html') ?>';
var BLANK_IMG = '<?php echo $this->helper('core/js')->getJsUrl('spacer.gif') ?>';
//]]>
</script>
<![endif]-->
<?php echo $this->getCssJsHtml() ?>
<?php echo $this->getChildHtml() ?>
<?php echo $this->getIncludes() ?>
I think that there are some function (may be getHtmlChild()) that overwrites my translation because other words are translated adding new strings into traslate.csv.
Which file or function I've to change to see "shopping bag" in the frontend of my site? Why some words are changed with translate.csv and others not? Can you help me, please? Thank you very much!
First, all strings in the translation files are casesensitive.
When I look for a word to translate for example "add to my cart" then I usually do like this:
Open a terminal and go to the root of your magento shop and run:
cd app
git grep "add to my cart" | grep csv
This gets all the hits from all your translation files in your entire project.
My result looks like this:
design/frontend/fortis/eke/locale/sv_SE/translate.csv:1:"Add to Cart","add to my cart"
locale/sv_SE/Mage_Catalog.csv:33:"Add to Cart","add to my cart"
In the result, first you se the path to the file and then the translation.
In my example the string was already translated. But now you know exactly what the base string is. Use this in you own translation file.
If you don´t get a hit in the translation files then the word or sentence might come from a cms-block or cms-page. To search for it there you have to connect to your SQL server and run some querys like this (one at the time):
select * from cms_block where content like '%add to my cart%';
select * from cms_page where content like '%add to my cart%';
From the result you can see what the block or page with the string is named. Go the backend and edit it.

Bash-Shell script show source code, not html

It's weird that my shell script in website show the whole source code, not the html that I want.
My script is:
#!/bin/sh
echo "Content-type: text/html"
echo ""
cat << EOF
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<title>test</title>
<link type="text/css" href="../jquery/css/redmond/jquery-ui-custom.min.css" rel="stylesheet">
<script type="text/javascript" src="../jquery/js/jquery.min.js"></script>
<script type="text/javascript" src="../jquery/js/jquery-ui-custom.min.js"></script>
<script type="text/javascript">
//<![CDATA[
if(verifiedUser == "")
window.top.location.href = "/";
//]]>
</script>
</head>
<body>
<table align="center">
<tr><td align="right">Product Name</td><td align="left">
</td></tr>
<tr><td align="right">Hardware Version</td><td align="left">
</td></tr>
<tr><td align="right">Firmware Version</td><td align="left">
</td></tr>
</table>
</body>
</html>
EOF
and what the .cgi file show is just that code!
My cgi file is in the same directory of the html files, because the main directory is in /mnt, so not put in /home/www/cgi-bin/ as usual.
What's the reasonable problem can cause this situation?
Any advice appreciated!
AFAIK, the separator between header section & the html data should be a blank line in CRLF format.
Try this:
echo -e "Content-type: text/html\r"
echo -e "\r"
cat << 'EOF'
---remaining HTML data---
EOF
Note: I have also changed cat << EOF to cat << 'EOF' to prevent any variable expansion. Revert it if variable/command expansion is needed.
#Barmar has the right idea - Your server is very likely not configured to run those files, but rather send the file directly to the client. So it's a configuration issue, not a programming one.

Only first page is saved to pdf from html using dompdf with codeigniter

I am trying to create a pdf from html using dompdf with codeigniter. I have two html pages. My problem is that only the first page is saved in the pdf file. The second one is gone.
Here is my code :
$this->load->library('pdf');
$html = $this->load->view('reports_html/couver1','',true);
$html .= $this->load->view('reports_html/reportContentImageLeft','',true);
$this->pdf->load_html($html);
$this->pdf->render();
other code
$this->data['view'] = $this->load->view('reports_html/reportContentImageLeft','',true);
$html = $this->load->view('reports_html/couver1',$this->data,true);
// $this->pdf->load_html($html);
$this->pdf->load_view('reports_html/couver1',$this->data,true);
$this->pdf->render();
i did like you said but only prints on the pdf file the first page
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>on.plans - reports - cover page 1</title>
<link href="<?php echo base_url()."css/reports.css"?>" rel="stylesheet" type="text/css">
</head>
<body>
<div id="page">
<div id="section" class="cover">
<div class="logo">
<img src="/path/to/officeLogo.jpg" width="300px" height="150px">
</div>
<h1>Meeting date</h1>
<h3>Project name</h3>
</div>
</div>
</body>
</html>
<?php echo $view; ?>
i added the view but its not working
thanks for your answer
You can try something like this:
$data['view'] = $this->load->view('reports_html/reportContentImageLeft','',true);
$html = $this->load->view('reports_html/couver1',$data,true);
$this->pdf->load_html($html);
$this->pdf->render();
$dompdf->stream("test.pdf");
And in your reports_html/couver1 view need do something like this <?=$view;?>
This solution is not the best - but it is work.

Sharing a multi-language website in Google+

I have a multi-language website which correctly detects the user language (the site's language changes accordingly), but can't be correctly shared in Google+.
The site exists in two languages, therefore I have set up two different sets of meta properties, one for each language:
English:
<link rel="canonical" href="http://en.perehana.com/"/>
<meta property="og:title" content="Perehana, the best way to find perfect gifts!"/>
<meta property="og:type" content="website"/>
<meta property="og:url" content="http://www.perehana.com"/>
<meta property="og:image" content="http://www.perehana.com/img/large-icon.jpg"/>
<meta property="og:site_name" content="Perehana"/>
<meta property="og:description" content="No gift ideas for Christmas, birthdays, weddings, births or any other event? Perehana allows you to enter gift ideas and to reserve your family and friends' ideas before buying them."/>
<meta property="og:locale" content="en_GB"/>
<meta property="fb:app_id" content="242045389185230"/>
<meta property="og:locale:alternate" content="fr_FR"/>
<meta itemprop="name" content="Perehana, the best way to find perfect gifts!"/>
<meta itemprop="description" content="No gift ideas for Christmas, birthdays, weddings, births or any other event? Perehana allows you to enter gift ideas and to reserve your family and friends' ideas before buying them."/>
<meta itemprop="image" content="http://www.perehana.com/img/square_logo.png"/>
French:
<link rel="canonical" href="http://fr.perehana.com/"/>
<meta property="og:title" content="Perehana, le meilleur moyen de faire plaisir à coup sûr !"/>
<meta property="og:type" content="website"/>
<meta property="og:url" content="http://www.perehana.com"/>
<meta property="og:image" content="http://www.perehana.com/img/large-icon.jpg"/>
<meta property="og:site_name" content="Perehana"/>
<meta property="og:description" content="En manque d'idées de cadeaux à l'approche de Noël, des anniversaires, des mariages ou des naissances ? Perehana est un site qui vous permet de saisir des idées-cadeaux et de réserver celles de votre famille et de vos amis. Vous pouvez ensuite aller les acheter sans qu'ils le sachent."/>
<meta property="og:locale" content="fr_FR"/>
<meta property="fb:app_id" content="242045389185230"/>
<meta property="og:locale:alternate" content="en_GB"/>
<meta itemprop="name" content="Perehana, le meilleur moyen de faire plaisir à coup sûr !"/>
<meta itemprop="description" content="En manque d'idées de cadeaux à l'approche de Noël, des anniversaires, des mariages ou des naissances ? Perehana vous permet de saisir des idées-cadeaux et de réserver celles de votre famille et de vos amis. Vous pouvez ensuite aller les acheter sans qu'ils le sachent."/>
<meta itemprop="image" content="http://www.perehana.com/img/square_logo.png"/>
As you can see, the locales and alternates are correctly set.
This is how I call the G+ API (this is an example for a French user):
<div class="g-plusone" data-size="medium" data-href="http://www.perehana.com"></div>
<script type="text/javascript">
window.___gcfg = {
lang: 'fr'
};
(function() {
var po = document.createElement('script'); po.type = 'text/javascript';
po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
According to the user's language, the correct properties are displayed.
The problem occurs when I want to share it via Google+, the title and description that Google automatically chooses for the site are in English, even if my G+ user account is in French... :-(
Thanks to anyone who can help!
I assume you're using the Accept-Language HTTP header to do this on your website.
The page fetcher used for sharing on to Google+ does not propagate any of the HTTP headers from the user who initiated the action, so your website will fall back to whatever the default language is.
You can work around this by using GET parameters to set the language. If you are sharing from the +1 button, share button or share link you can then set the current language into the target url parameter, data-href, for that plugin.
It looks like you've already filed a feature request for this in the Google+ issue tracker. If it wasn't you, star the issue to receive update notifications.

Resources