Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3765973
D307.id785.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D307.id785.diff
View Options
diff --git a/page.php b/page.php
--- a/page.php
+++ b/page.php
@@ -108,7 +108,7 @@
$this->get_data();
if ($this->data) {
$this->analyse();
- }
+ }
}
function get_data () {
@@ -121,11 +121,14 @@
return;
}
}
- $encoding = mb_detect_encoding($data, "ISO-8859-15, ISO-8859-1, UTF-8, ASCII, auto");
+ $this->data = $data;
+ $this->encodeData();
+ }
+
+ function encodeData () {
+ $encoding = mb_detect_encoding($this->data, "ISO-8859-15, ISO-8859-1, UTF-8, ASCII, auto");
if ($encoding && $encoding != 'UTF-8') {
- $this->data = Encoding::toUTF8($data);
- } else {
- $this->data = $data;
+ $this->data = Encoding::toUTF8($this->data);
}
}
diff --git a/pages/DownloadWithWget.php b/pages/DownloadWithWget.php
new file mode 100644
--- /dev/null
+++ b/pages/DownloadWithWget.php
@@ -0,0 +1,37 @@
+<?php
+
+trait DownloadWithWget {
+
+ /**
+ * @return string
+ */
+ private function getTemporaryFilename () {
+ $dir = sys_get_temp_dir();
+ return tempnam($dir, "http-client-wget-");
+ }
+
+ /**
+ * Gets the content of the specified URL, using wget to download it
+ *
+ * @return string
+ */
+ function getFileContents ($url) {
+ $file = $this->getTemporaryFilename();
+ $url = escapeshellarg($url);
+
+ system("wget -q -O $file $url");
+ $data = file_get_contents($file);
+ unlink($file);
+
+ return $data;
+ }
+
+ /**
+ * Downloads the URL through wget and fill data properties
+ */
+ function get_data () {
+ $this->data = $this->getFileContents($this->url);
+ $this->encodeData();
+ }
+
+}
diff --git a/tests/DownloadWithWgetTest.php b/tests/DownloadWithWgetTest.php
new file mode 100644
--- /dev/null
+++ b/tests/DownloadWithWgetTest.php
@@ -0,0 +1,34 @@
+<?php
+
+require 'pages/DownloadWithWget.php';
+
+class DownloadWithWgetTest extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * The object under test.
+ *
+ * @var object
+ */
+ private $instance;
+
+ /**
+ * Sets up the fixture.
+ *
+ * This method is called before a test is executed.
+ *
+ * @return void
+ */
+ public function setUp () {
+ $this->instance = $this->getObjectForTrait('DownloadWithWget');
+ }
+
+ /**
+ * Tests getFileContents method
+ */
+ public function testGetFileContents () {
+ $this->assertContains(
+ "* <----- vous êtes ici",
+ $this->instance->getFileContents("http://www.perdu.com")
+ );
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 15:37 (17 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2255844
Default Alt Text
D307.id785.diff (2 KB)
Attached To
Mode
D307: Allow to download with wget
Attached
Detach File
Event Timeline
Log In to Comment