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

Multiple compatibility fixes #14

Open
wants to merge 6 commits 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
Binary file added .DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions assets/.listing
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
drwxr-xr-x 2 w014b45c w014b45c 4096 Jun 19 2018 .
drwxr-xr-x 6 w014b45c w014b45c 4096 Jun 20 2018 ..
-rw-r--r-- 1 w014b45c w014b45c 1641 Jun 19 2018 importcsv.css
-rw-r--r-- 1 w014b45c w014b45c 397 Jun 19 2018 importcsv.js
-rw-r--r-- 1 w014b45c w014b45c 3187 Jun 19 2018 import.js
5 changes: 5 additions & 0 deletions content/.listing
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
drwxr-xr-x 2 w014b45c w014b45c 4096 Jun 19 2018 .
drwxr-xr-x 6 w014b45c w014b45c 4096 Jun 20 2018 ..
-rw-r--r-- 1 w014b45c w014b45c 20368 Jun 20 2018 content.index.php
-rw-r--r-- 1 w014b45c w014b45c 5474 Jun 19 2018 index.xsl
-rw-r--r-- 1 w014b45c w014b45c 3877 Jun 19 2018 step2.xsl
8 changes: 4 additions & 4 deletions content/content.index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
require_once(EXTENSIONS . '/importcsv/lib/parsecsv-0.3.2/parsecsv.lib.php');
require_once(EXTENSIONS . '/importcsv/lib/parsecsv-1.3.2/parsecsv.lib.php');

class contentExtensionImportcsvIndex extends AdministrationPage
{
Expand All @@ -11,7 +11,7 @@ public function __construct(&$parent)
}
*/

public function build()
public function build(array $context = array())
{
parent::build();
parent::addStylesheetToHead(URL . '/extensions/importcsv/assets/importcsv.css');
Expand Down Expand Up @@ -155,7 +155,7 @@ private function __importStep3Page()
$this->__addVar('section-id', $sectionID);
$this->__addVar('unique-action', $uniqueAction);
$this->__addVar('unique-field', $uniqueField);
$this->__addVar('import-url', URL . '/symphony/extension/importcsv/');
$this->__addVar('import-url', SYMPHONY_URL . '/extension/importcsv/');

// Output the CSV-data:
$csvData = $csv->data;
Expand Down Expand Up @@ -233,7 +233,7 @@ private function __ajaxImportRows()
$ignore = false;

// Import this row:
$row = $csvData[$i];
$row = $csvData[$i] ?? false;
if ($row != false) {

// If a unique field is used, make sure there is a field selected for this:
Expand Down
13 changes: 13 additions & 0 deletions drivers/.listing
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
drwxr-xr-x 2 w014b45c w014b45c 4096 Jun 19 2018 .
drwxr-xr-x 6 w014b45c w014b45c 4096 Jun 20 2018 ..
-rw-r--r-- 1 w014b45c w014b45c 2882 Jun 19 2018 ImportDriver_default.php
-rw-r--r-- 1 w014b45c w014b45c 1236 Jun 19 2018 ImportDriver_memberpassword.php
-rw-r--r-- 1 w014b45c w014b45c 1797 Jun 19 2018 ImportDriver_multilingual.php
-rw-r--r-- 1 w014b45c w014b45c 2110 Jun 19 2018 ImportDriver_multilingual_textbox.php
-rw-r--r-- 1 w014b45c w014b45c 5565 Jun 19 2018 ImportDriver_private_upload.php
-rw-r--r-- 1 w014b45c w014b45c 4542 Jun 19 2018 ImportDriver_referencelink.php
-rw-r--r-- 1 w014b45c w014b45c 4183 Jun 19 2018 ImportDriver_selectbox_link.php
-rw-r--r-- 1 w014b45c w014b45c 1501 Jun 19 2018 ImportDriver_select.php
-rw-r--r-- 1 w014b45c w014b45c 1503 Jun 19 2018 ImportDriver_status.php
-rw-r--r-- 1 w014b45c w014b45c 1278 Jun 19 2018 ImportDriver_subsectionmanager.php
-rw-r--r-- 1 w014b45c w014b45c 5461 Jun 19 2018 ImportDriver_upload.php
135 changes: 135 additions & 0 deletions drivers/ImportDriver_association.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

/*
* Import Driver for type: association_field
*/

require_once("ImportDriver_default.php");

class ImportDriver_association extends ImportDriver_default
{
/**
* Constructor
* @return void
*/
public function ImportDriver_association()
{
$this->type = 'association';
}

/**
* Returns related Field ID for this Reference Link
* @todo This only handles a Reference Link that links to one section
* @return integer
*/
private function getRelatedField()
{
// Get the correct ID of the related fields
$related_field = Symphony::Database()->fetchVar('related_field_id', 0, 'SELECT `related_field_id` FROM `tbl_fields_association` WHERE `field_id` = ' . $this->field->get('id'));

return $related_field;
}

/**
* Process the data so it can be imported into the entry.
* @param $value
* The value to import
* @param $entry_id
* If a duplicate is found, an entry ID will be provided.
* @return The data returned by the field object
*/
public function import($value, $entry_id = null)
{
// Import selectbox link:
$related_field_id = $this->getRelatedField();
$data = explode(',', $value);
$related_ids = array('relation_id'=>array());
foreach ($data as $relationValue) {
$related_ids['relation_id'] = $related_ids['relation_id'] ?? null;
$related_ids['relation_id'][] = Symphony::Database()->fetchVar('entry_id', 0, sprintf('
SELECT `entry_id`
FROM `tbl_entries_data_%d`
WHERE `value` = "%s";
',
$related_field_id,
Symphony::Database()->cleanValue(trim($relationValue))
));
}

return $related_ids;
}

/**
* Process the data so it can be exported to a CSV
* @param $data
* The data as provided by the entry
* @param $entry_id
* The ID of the entry that is exported
* @return string
* A string representation of the data to import into the CSV file
*/
public function export($data, $entry_id = null)
{
$data['relation_id'] = $data['relation_id'] ?? null;
if (!is_array($data['relation_id'])) {
$data['relation_id'] = array($data['relation_id']);
}

$related_values = array();
$related_field_id = $this->getRelatedField();
foreach ($data['relation_id'] as $relation_id) {
if (!empty($relation_id)) {
$row = Symphony::Database()->fetchRow(0, 'SELECT * FROM `tbl_entries_data_' . $related_field_id . '` WHERE `entry_id` = ' . $relation_id . ';');
if (isset($row['value'])) {
$related_values[] = trim($row['value']);
} else {
// Fallback to empty value:
$related_values[] = '';
}
}
}

return implode(', ', $related_values);
}

/**
* Scan the database for a specific value
* @param $value
* The value to scan for
* @return null|string
* The ID of the entry found, or null if no match is found.
*/
public function scanDatabase($value)
{
$related_field_id = $this->getRelatedField();
$searchResult = Symphony::Database()->fetchVar('entry_id', 0, sprintf('
SELECT `entry_id`
FROM `tbl_entries_data_%d`
WHERE `value` = "%s";
',
$related_field_id,
Symphony::Database()->cleanValue(trim($value))
));

// If there is a matching result, it means the entry exists in the SBL section
// Now check to see if there is another entry with this value in the current section
if ($searchResult != false) {
$existing = Symphony::Database()->fetchVar('entry_id', 0, sprintf('
SELECT `entry_id`
FROM `tbl_entries_data_%d`
WHERE `relation_id` = %d;
',
$this->field->get('id'),
$searchResult
));

if ($existing != false) {
return $existing;
} else {
return null;
}
} else {
return null;
}
}
}
153 changes: 153 additions & 0 deletions drivers/ImportDriver_image_upload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php

/*
* Import Driver for type: upload
*/

class ImportDriver_image_upload extends ImportDriver_default
{
/**
* Constructor
* @return void
*/
public function ImportDriver_image_upload()
{
$this->type = 'image_upload';
}

/**
* Process the data so it can be imported into the entry.
* @param $value
* The value to import
* @param $entry_id
* If a duplicate is found, an entry ID will be provided.
* @return The data returned by the field object
*/
public function import($value, $entry_id = null)
{
$destination = $this->field->get('destination');
$filename = str_replace('/workspace/', '/', $destination) . '/' . str_replace($destination, '', trim($value));
// Check if the file exists:
if (file_exists(DOCROOT . $destination . '/' . trim($value))) {
// File exists, create the link:
// Check if there already exists an entry with this filename. If so, this entry will not be stored (filename must be unique)
$sql = 'SELECT COUNT(*) AS `total` FROM `tbl_entries_data_' . $this->field->get('id') . '` WHERE `file` = \'' . $filename . '\';';
$total = Symphony::Database()->fetchVar('total', 0, $sql);
if ($total == 0) {
$fileData = $this->field->processRawFieldData($value, $this->field->__OK__);
$fileData['file'] = trim($filename);
$fileData['size'] = filesize(DOCROOT . $destination . '/' . $value);
$fileData['mimetype'] = mime_content_type(DOCROOT . $destination . '/' . $value);
$fileData['meta'] = serialize($this->field->getMetaInfo(DOCROOT . $destination . '/' . $value, $fileData['mimetype']));

return $fileData;
} else {
// File already exists, don't store:
return false;
}
} else {
// File is stored in the CSV, but does not exists. Save it anyway, for database sake:
if (!empty($value)) {
$fileData = $this->field->processRawFieldData($value, $this->field->__OK__);
$fileData['file'] = trim($filename);
$fileData['size'] = filesize(DOCROOT . $destination . '/' . $value);
$fileData['mimetype'] = ''; // mime_content_type(DOCROOT . $destination . '/' . $value);
$fileData['meta'] = serialize($this->field->getMetaInfo(DOCROOT . $destination . '/' . $value, $fileData['mimetype']));

return $fileData;
}
}

return false;
}

/**
* Process the data so it can be exported to a CSV
* @param $data
* The data as provided by the entry
* @param $entry_id
* The ID of the entry that is exported
* @return string
* A string representation of the data to import into the CSV file
*/
public function export($data, $entry_id = null)
{
return trim($data['file']);
}

}

if (!function_exists('mime_content_type')) {

function mime_content_type($filename)
{
$mime_types = array(

'txt' => 'text/plain',
'htm' => 'text/html',
'html' => 'text/html',
'php' => 'text/html',
'css' => 'text/css',
'js' => 'application/javascript',
'json' => 'application/json',
'xml' => 'application/xml',
'swf' => 'application/x-shockwave-flash',
'flv' => 'video/x-flv',

// images
'png' => 'image/png',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'gif' => 'image/gif',
'bmp' => 'image/bmp',
'ico' => 'image/vnd.microsoft.icon',
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
'svg' => 'image/svg+xml',
'svgz' => 'image/svg+xml',

// archives
'zip' => 'application/zip',
'rar' => 'application/x-rar-compressed',
'exe' => 'application/x-msdownload',
'msi' => 'application/x-msdownload',
'cab' => 'application/vnd.ms-cab-compressed',

// audio/video
'mp3' => 'audio/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',

// adobe
'pdf' => 'application/pdf',
'psd' => 'image/vnd.adobe.photoshop',
'ai' => 'application/postscript',
'eps' => 'application/postscript',
'ps' => 'application/postscript',

// ms office
'doc' => 'application/msword',
'rtf' => 'application/rtf',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',

// open office
'odt' => 'application/vnd.oasis.opendocument.text',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
);

$ext = strtolower(array_pop(explode('.', $filename)));
if (array_key_exists($ext, $mime_types)) {
return $mime_types[$ext];
} elseif (function_exists('finfo_open')) {
$finfo = finfo_open(FILEINFO_MIME);
$mimetype = finfo_file($finfo, $filename);
finfo_close($finfo);

return $mimetype;
} else {
return 'application/octet-stream';
}
}
}
2 changes: 2 additions & 0 deletions drivers/ImportDriver_selectbox_link.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function import($value, $entry_id = null)
$data = explode(',', $value);
$related_ids = array('relation_id'=>array());
foreach ($data as $relationValue) {
$related_ids['relation_id'] = $related_ids['relation_id'] ?? null;
$related_ids['relation_id'][] = Symphony::Database()->fetchVar('entry_id', 0, sprintf('
SELECT `entry_id`
FROM `tbl_entries_data_%d`
Expand All @@ -67,6 +68,7 @@ public function import($value, $entry_id = null)
*/
public function export($data, $entry_id = null)
{
$data['relation_id'] = $data['relation_id'] ?? null;
if (!is_array($data['relation_id'])) {
$data['relation_id'] = array($data['relation_id']);
}
Expand Down
2 changes: 1 addition & 1 deletion extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function fetchNavigation()
}
}

public function update()
public function update($previousVersion = false)
{
if (file_exists(TMP.'/importcsv.csv')) {
@unlink(TMP.'/importcsv.csv');
Expand Down
Loading