Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renames the interface Parser to avoid conflicts with other pugins #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions includes/parsers/docx.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
<?php
include_once 'parser.php';

class DocxParser implements Parser {

public static function parse($filename) {
$striped_content = '';
$content = '';

if (!$filename || !file_exists($filename))
return false;

$zip = zip_open($filename);
if (!$zip || is_numeric($zip))
return false;

while ($zip_entry = zip_read($zip)) {

if (zip_entry_open($zip, $zip_entry) == FALSE)
continue;

if (zip_entry_name($zip_entry) != "word/document.xml")
continue;

$content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));

zip_entry_close($zip_entry);
}
zip_close($zip);
$content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content);
$content = str_replace('</w:r></w:p>', "\r\n", $content);
$striped_content = strip_tags($content);

return $striped_content;
}

<?php
include_once 'parser.php';
class DocxParser implements ParserWPfileSearch {
public static function parse($filename) {
$striped_content = '';
$content = '';
if (!$filename || !file_exists($filename))
return false;
$zip = zip_open($filename);
if (!$zip || is_numeric($zip))
return false;
while ($zip_entry = zip_read($zip)) {
if (zip_entry_open($zip, $zip_entry) == FALSE)
continue;
if (zip_entry_name($zip_entry) != "word/document.xml")
continue;
$content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
zip_entry_close($zip_entry);
}
zip_close($zip);
$content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content);
$content = str_replace('</w:r></w:p>', "\r\n", $content);
$striped_content = strip_tags($content);
return $striped_content;
}
}
72 changes: 36 additions & 36 deletions includes/parsers/odt.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
<?php
include_once 'parser.php';

class OdtParser implements Parser {

public static function parse($filename) {
$striped_content = '';
$content = '';

if (!$filename || !file_exists($filename))
return false;

$zip = zip_open($filename);
if (!$zip || is_numeric($zip))
return false;

while ($zip_entry = zip_read($zip)) {

if (zip_entry_open($zip, $zip_entry) == FALSE)
continue;

if (zip_entry_name($zip_entry) != "content.xml")
continue;

$content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));

zip_entry_close($zip_entry);
}
zip_close($zip);
$content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content);
$content = str_replace('</w:r></w:p>', "\r\n", $content);
$striped_content = strip_tags($content);

return $striped_content;
}

<?php
include_once 'parser.php';
class OdtParser implements ParserWPfileSearch {
public static function parse($filename) {
$striped_content = '';
$content = '';
if (!$filename || !file_exists($filename))
return false;
$zip = zip_open($filename);
if (!$zip || is_numeric($zip))
return false;
while ($zip_entry = zip_read($zip)) {
if (zip_entry_open($zip, $zip_entry) == FALSE)
continue;
if (zip_entry_name($zip_entry) != "content.xml")
continue;
$content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
zip_entry_close($zip_entry);
}
zip_close($zip);
$content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content);
$content = str_replace('</w:r></w:p>', "\r\n", $content);
$striped_content = strip_tags($content);
return $striped_content;
}
}
8 changes: 4 additions & 4 deletions includes/parsers/parser.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

interface Parser {
public static function parse($filename);
<?php
interface ParserWPfileSearch {
public static function parse($filename);
}
48 changes: 24 additions & 24 deletions includes/parsers/pdf.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?php

class PdfParser implements Parser {
public static function parse($filename) {
if (!$filename || !file_exists($filename))
return false;

// Parse pdf file and build necessary objects.
$parser = new \Smalot\PdfParser\Parser();

$pdf = $parser->parseFile($filename);

// Retrieve all pages from the pdf file.
$pages = $pdf->getPages();

// Loop over each page to extract text.
$text = "";
foreach ($pages as $page) {
$text .= $page->getText();
}

return $text;
}
}
<?php
class PdfParser implements ParserWPfileSearch {
public static function parse($filename) {
if (!$filename || !file_exists($filename))
return false;
// Parse pdf file and build necessary objects.
$parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseFile($filename);
// Retrieve all pages from the pdf file.
$pages = $pdf->getPages();
// Loop over each page to extract text.
$text = "";
foreach ($pages as $page) {
$text .= $page->getText();
}
return $text;
}
}