diff --git a/assets/section.oembed.css b/assets/section.oembed.css
index d6c619a..cd28def 100644
--- a/assets/section.oembed.css
+++ b/assets/section.oembed.css
@@ -5,15 +5,55 @@
/**
* CSS for the blueprintsection driver
- *
+ *
* @author nicolas
*/
div.compact label.oembed-other-title {
- width:90%;
- margin: 0 0 1.5rem 1.5rem;
+ width: calc(100% - 3rem);
+ margin: 0 0 0 3rem;
}
-.oembed-params-settings {
- margin: 0 0 1.5rem 0;
+.field-oembed label > div {
+ margin-top: 2px;
+}
+
+.field-oembed label .frame {
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+ justify-content: center;
+ flex-wrap: wrap;
+}
+
+.field-oembed label .frame > span {
+ display: none;
+}
+
+.field-oembed label .frame > div {
+ order: 99;
+ flex-shrink: 0;
+ width: 100%;
+}
+
+.field-oembed label .frame > a {
+ border-radius: 5px;
+ color: #fff;
+ font-size: 1.1rem;
+ font-style: normal;
+ text-transform: uppercase;
+ line-height: 1.6rem;
+ margin-bottom: 1rem;
+ padding: 0.5rem 1rem;
+ border: none;
+ background: #2f77eb;
+ cursor: pointer;
+}
+
+.field-oembed label .frame > a:hover {
+ background: #3B3D40;
+}
+
+.field-oembed label .frame > a + span + a {
+ margin-left: 1rem;
}
diff --git a/extension.driver.php b/extension.driver.php
index 48bf5a4..9072f9b 100644
--- a/extension.driver.php
+++ b/extension.driver.php
@@ -75,13 +75,11 @@ public function appendJS(Array $context) {
time(),
false
);
-
- return;
}
// section page, new or edit
- if($c['driver'] == 'blueprintssections') {
+ if($c['driver'] == 'blueprintssections' || (isset($c['context']['section_handle']) && in_array($c['context']['page'], array('new', 'edit')))) {
Administration::instance()->Page->addStylesheetToHead(
URL . '/extensions/oembed_field/assets/section.oembed.css',
@@ -89,9 +87,9 @@ public function appendJS(Array $context) {
time() + 1,
false
);
-
- return;
}
+
+ return;
}
@@ -103,26 +101,26 @@ public function appendJS(Array $context) {
public function install() {
// pre v1.3.1
$create = FieldOembed::createFieldTable();
-
+
// v1.3.1
$unique = FieldOembed::updateFieldTable_Unique();
-
+
// v1.3.2
$thumbs = FieldOembed::updateFieldTable_Thumbs();
-
+
// v1.4
$params = FieldOembed::updateFieldTable_QueryParams();
-
+
// v1.6
$ssl = FieldOembed::updateFieldTable_ForceSSL();
-
+
// v1.7.3
$uniqueMedia = FieldOembed::updateFieldTable_UniqueMedia();
-
+
return $create && $unique && $thumbs && $params && $ssl && $uniqueMedia;
-
+
}
-
+
/**
* Creates the table needed for the settings of the field
*/
@@ -133,45 +131,45 @@ public function update($previousVersion = false) {
if ($ret && version_compare($previousVersion,'1.3.1') == -1) {
// update for unique setting
$ret_unique = FieldOembed::updateFieldTable_Unique();
-
+
// set the return value
$ret = $ret_unique;
}
-
+
// are we updating from lower than 1.3.2 ?
if ($ret && version_compare($previousVersion, '1.3.2') == -1) {
-
+
// update for the thumbs settings
$ret_thumbs = FieldOembed::updateFieldTable_Thumbs();
-
+
// v1.4
// update for the params settings
$ret_params = FieldOembed::updateFieldTable_QueryParams();
-
+
// update for the driver column && set all drivers as allowed by default
$ret_driver = FieldOembed::updateFieldTable_Driver() &&
FieldOembed::updateFieldData_Driver();
-
+
// set the return value
$ret = $ret_thumbs && $ret_params && $ret_driver;
}
-
+
// are we updating from lower or equal to 1.4 ?
if ($ret && version_compare($previousVersion, '1.4') < 1) {
// Fixes issue #22
$ret = FieldOembed::updateDataTable_Driver();
}
-
+
// are we updating from lower then 1.6 ?
if ($ret && version_compare($previousVersion, '1.6') < 0) {
$ret = FieldOembed::updateFieldTable_ForceSSL();
}
-
+
// are we updating from lower then 1.7.3 ?
if ($ret && version_compare($previousVersion, '1.7.3') < 0) {
$ret = FieldOembed::updateFieldTable_UniqueMedia();
}
-
+
// are we updating from lower then 1.8 ?
if ($ret && version_compare($previousVersion, '1.8') < 0) {
$ret = FieldOembed::updateFieldTable_UniqueKey();
@@ -180,10 +178,10 @@ public function update($previousVersion = false) {
if ($ret && version_compare($previousVersion, '1.8') < 0) {
$ret = FieldOembed::updateDataTable_UniqueKey();
}
-
+
return $ret;
}
-
+
/**
*
* Drops the table needed for the settings of the field
@@ -191,8 +189,8 @@ public function update($previousVersion = false) {
public function uninstall() {
// pre v1.3.2
$field = FieldOembed::deleteFieldTable();
-
+
return $field;
}
-
- }
\ No newline at end of file
+
+ }
diff --git a/extension.meta.xml b/extension.meta.xml
index 88f5897..33ddacf 100644
--- a/extension.meta.xml
+++ b/extension.meta.xml
@@ -1,6 +1,6 @@
- oEmbed Field
+ Field: oEmbed
Easily embed videos/images from ANY* website that implements the oEmbed format. See http://oembed.com. Supported services:
- **Vimeo**
- **Youtube**
@@ -50,6 +50,10 @@
+
+ - Update for Symphony 4.x
+ - Code refactoring for Database and EQFA
+
- Fix a PHP warning: CURLOPT are constants
- Fix error in PHP 5.3: curl_strerror is 5.4+
@@ -157,57 +161,57 @@
- Refactored the request url parameters feature: You can add values to the oEmbed query string
- YouTube driver fix for the shorten domain (part of issue #19)
- Added the `show thumbnails in table` parameter: if disabled, title or url will be used
- - Changes between the two branches (master and dev) are now synced
+ - Changes between the two branches (master and dev) are now synced
- **This release has never been stable**
- - Minor bug fixes
+ - Minor bug fixes
- Added the `oembed requests parameters sets` field's setting (issue #11) ([see how it work]) (@deprecated)
- Fixed a lot of typos (thanks @brando)
- Tables now uses utf_8 and MyISAM
- Refactored the drivers: They are now more easy to implement
- - Changes between the two branches (master and dev) are now synced
+ - Changes between the two branches (master and dev) are now synced
- Added the Twitter Driver :) Thanks @briandrum !
- - Added assets for the blueprints>section pages
- - Added the 'unique' option - url can now be unique across a section
+ - Added assets for the blueprints>section pages
+ - Added the 'unique' option - url can now be unique across a section
- Added Dailymotion, Qik (fix issue #9) and Viddler drivers (thanks Andrew!, pull request #8)
- - Improved comments (a lot!)
- - Fix a typo (issue #6)
- - Added support for image (thumbnail) in table view (do not forget to add those site in JIT)
+ - Improved comments (a lot!)
+ - Fix a typo (issue #6)
+ - Added support for image (thumbnail) in table view (do not forget to add those site in JIT)
- Refactored how the drivers are managed in the ServiceDispatcher (issue #10)
-
+
- Public methods to get drivers and drivers names
- Drivers are now all loaded by default
- Drivers filename must now respect the `class.service[a-zA-Z0-9]+.php` regular expression
- - Drivers are now listed in section field and publish page
+ - Drivers are now listed in section field and publish page
- - Improved error management - Added a ref flag for that in the public method
- - Added a method that permit change of the root tag name in the oEmbed response
+ - Improved error management - Added a ref flag for that in the public method
+ - Added a method that permit change of the root tag name in the oEmbed response
-
+
- Update the YouTube driver to 1.2 - Fix when the entered url contains a #
-
+
- Update the YouTube driver to 1.1 - Fix the width when the field is in the sidebar
-
+
- Update for Symphony 2.2.2 compatibility
- (do not need to check for the $simulate value as it seems to be always true)
+ (do not need to check for the $simulate value as it seems to be always true)
-
- - Couple of bug fixes
+
+ - Couple of bug fixes
- Adapted the code so oEmbed resources in the sidebar displays correctly
-
+
- Added YouTube
-
+
- First release
-
\ No newline at end of file
+
diff --git a/fields/field.oembed.php b/fields/field.oembed.php
index 5f0433f..7615a8f 100644
--- a/fields/field.oembed.php
+++ b/fields/field.oembed.php
@@ -5,7 +5,8 @@
require_once(TOOLKIT . '/class.field.php');
require_once(EXTENSIONS . '/oembed_field/lib/class.serviceDispatcher.php');
require_once(EXTENSIONS . '/oembed_field/lib/class.serviceDriver.php');
-
+ require_once EXTENSIONS . '/oembed_field/lib/class.entryqueryoembedadapter.php';
+
/**
*
* Field class that will represent an oEmbed resource
@@ -38,6 +39,8 @@ class FieldOembed extends Field {
public function __construct(){
// call the parent constructor
parent::__construct();
+ // set the EQFA
+ $this->entryQueryFieldAdapter = new EntryQueryoEmbedAdapter($this);
// set the name of the field
$this->_name = __('oEmbed Resource');
// permits to make it required
@@ -55,11 +58,11 @@ public function __construct(){
}
public function isSortable(){
- return false; // @todo: should we allow to sort by url/driver ?
+ return true;
}
public function canFilter(){
- return false; // @todo: should we allow to filter by url/driver ?
+ return true;
}
public function canImport(){
@@ -76,7 +79,7 @@ public function canPrePopulate(){
public function mustBeUnique(){
return ($this->get('unique') == 'yes');
}
-
+
/**
* This returns true if resource can only be used once across this field.
*/
@@ -95,7 +98,7 @@ public function requiresSQLGrouping(){
public function allowDatasourceParamOutput(){
return false; // @todo: should we allow to output the url ?
}
-
+
/**
* @return array
*/
@@ -119,23 +122,23 @@ public function forceSSL() {
* @param $message
* @param $entry_id
*/
- public function checkPostFieldData($data, &$message, $entry_id=NULL){
+ public function checkPostFieldData($data, &$message, $entry_id = null){
- $message = NULL;
+ $message = null;
$required = ($this->get('required') == 'yes');
if ($required && strlen($data) == 0){
$message = __("'%s' is a required field.", array($this->get('label')));
return self::__MISSING_FIELDS__;
}
-
+
$url = $data;
-
+
if (strlen($url) > 0 && !filter_var($url, FILTER_VALIDATE_URL)) {
$message = __("%s: '%s' is not a valid URL.", array($this->get('label'), $url));
return self::__INVALID_FIELDS__;
}
-
+
$driver = ServiceDispatcher::getServiceDriver($url, $this->getAllowedDrivers());
// valid driver
@@ -143,13 +146,13 @@ public function checkPostFieldData($data, &$message, $entry_id=NULL){
$message = __("%s: No ServiceDriver
found for '%s'.", array($this->get('label'), $url));
return self::__INVALID_FIELDS__;
}
-
+
// uniqueness
if (strlen($url) > 0 && $this->resourceMustBeUnique() && !$this->checkUniqueness($url, $entry_id)) {
$message = __("%s: This field must be unique. An entry already contains this url.", array($this->get('label'), $url));
return self::__INVALID_FIELDS__;
}
-
+
return self::__OK__;
}
@@ -359,15 +362,15 @@ public function commit() {
$settings['thumbs'] = empty($thumbs) ? 'no' : $thumbs;
// @todo implement this
- // do not comment the next line, as we can not store NULL into it
+ // do not comment the next line, as we can not store null into it
$settings['refresh'] = $refresh;
// Permit only some specific drivers
- $settings['driver'] = empty($drivers) || count($drivers) < 0 ? null : $drivers;
+ $settings['driver'] = empty($drivers) ? null : $drivers;
// Force SSL setting
$settings['force_ssl'] = empty($force_ssl) ? 'no' : $force_ssl;
-
+
// the 'unique media' setting
$settings['unique_media'] = empty($uniqueMedias) ? 'no' : $uniqueMedias;
@@ -429,7 +432,7 @@ public function fetchIncludableElements() {
* @param $wrapper
* @param $data
*/
- public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = NULL, $entry_id = NULL) {
+ public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null) {
if(!is_array($data) || empty($data) || empty($data['url'])) return;
@@ -437,7 +440,7 @@ public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = fa
/*if ((time() - $data['last_updated']) > ($this->_fields['refresh'] * 60)) {
$data = VimeoHelper::updateClipInfo($data['clip_id'], $this->_fields['id'], $wrapper->getAttribute('id'), $this->Database);
}*/
-
+
// store a pointer to the driver
// @todo: use the `driver` column
$driver = ServiceDispatcher::getServiceDriver($data['url'], $this->getAllowedDrivers());
@@ -449,21 +452,21 @@ public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = fa
if ($parser == null) {
throw new Exception('Unable to find parser for format: `' . $apiFormat . '`');
}
-
+
// root for all values
$field = new XMLElement($this->get('element_name'));
-
+
$field->setAttributeArray(array(
'id' => $data['res_id']
));
-
+
$title = new XMLElement('title', General::sanitize($data['title']));
$title->setAttribute('handle', Lang::createHandle($data['title']));
$field->appendChild($title);
$field->appendChild(new XMLElement('url', General::sanitize($data['url'])));
$field->appendChild(new XMLElement('thumbnail', General::sanitize($data['thumbnail_url'])));
$field->appendChild(new XMLElement('driver', General::sanitize($data['driver'])));
-
+
$protocols = new XMLElement('protocols');
if ($driver->supportsSSL()) {
$protocols->appendChild(new XMLElement('item', 'https'));
@@ -555,7 +558,7 @@ public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = fa
* @param string $fieldnamePrefix
* @param string $fieldnamePostfix
*/
- public function displayPublishPanel(XMLElement &$wrapper, $data = NULL, $flagWithError = NULL, $fieldnamePrefix = NULL, $fieldnamePostfix = NULL, $entry_id = NULL) {
+ public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null) {
$isRequired = $this->get('required') == 'yes';
$isUnique = $this->get('unique') == 'yes';
@@ -599,7 +602,7 @@ public function displayPublishPanel(XMLElement &$wrapper, $data = NULL, $flagWit
__('Supported services: ') . implode(', ', $driverlinks)
);
- if (strlen($value) == 0 || $flagWithError != NULL) {
+ if (strlen($value) == 0 || $flagWithError != null) {
// do nothing
@@ -654,7 +657,7 @@ public function displayPublishPanel(XMLElement &$wrapper, $data = NULL, $flagWit
$label->appendChild($drivers);
// error management
- if($flagWithError != NULL) {
+ if($flagWithError != null) {
$wrapper->appendChild(Widget::Error($label, $flagWithError));
} else {
$wrapper->appendChild($label);
@@ -667,13 +670,13 @@ public function displayPublishPanel(XMLElement &$wrapper, $data = NULL, $flagWit
* @param XMLElement $wrapper
* @param array $errors
*/
- public function displaySettingsPanel(XMLElement &$wrapper, $errors=NULL){
+ public function displaySettingsPanel(XMLElement &$wrapper, $errors = null){
/* first line, label and such */
parent::displaySettingsPanel($wrapper, $errors);
/* new line, drivers */
- $driv_wrap = new XMLElement('div', NULL, array('class'=>'oembed-drivers'));
+ $driv_wrap = new XMLElement('div', null, array('class'=>'oembed-drivers'));
$driv_title = new XMLElement('label',__('Supported services Select to enable the service in the publish page'));
$driv_title->appendChild(self::generateDriversSelectOptions($this->get(), 'fields['.$this->get('sortorder').'][driver][]'));
if (isset($errors['driver'])) {
@@ -682,20 +685,20 @@ public function displaySettingsPanel(XMLElement &$wrapper, $errors=NULL){
$driv_wrap->appendChild($driv_title);
/* new line, update settings */
- $set_wrap = new XMLElement('div', NULL, array('class'=>'group'));
+ $set_wrap = new XMLElement('div', null, array('class'=>'group'));
$label = Widget::Label(__('Update cache in minutes (leave blank to never update) Optional'));
$label->appendChild(Widget::Input('fields['.$this->get('sortorder').'][refresh]', $this->get('refresh')));
$set_wrap->appendChild($label);
/* new line, request params */
// Fixes issue #11
- $par_wrap = new XMLElement('div', NULL, array('class'=>'oembed-params-settings'));
+ $par_wrap = new XMLElement('div', null, array('class'=>'oembed-params-settings'));
$par_title = new XMLElement('label', __('Request URL Parameters (Appended to the query string) Optional'));
$par_title->appendChild(Widget::Input('fields['.$this->get('sortorder').'][query_params]', $this->get('query_params')));
$par_wrap->appendChild($par_title);
/* new line, check boxes */
- $chk_wrap = new XMLElement('div', NULL, array('class' => 'compact two columns'));
+ $chk_wrap = new XMLElement('div', null, array('class' => 'compact two columns'));
$chk_wrap->appendChild(new XMLElement('label', __('Other properties'), array('class'=>'oembed-other-title') ));
$this->appendRequiredCheckbox($chk_wrap);
$this->appendShowColumnCheckbox($chk_wrap);
@@ -715,22 +718,22 @@ public static function generateDriversSelectOptions($settings, $name) {
$drivers = ServiceDispatcher::getAllDriversNames();
sort($drivers, SORT_STRING);
$drivers_options = array();
-
+
if (is_array($settings)) {
$settings = (object) $settings;
}
-
+
// patch
$d = $settings->{'driver'};
if (is_array($d)) {
$d = implode(',', $d);
}
-
+
foreach ($drivers as $driver) {
$selected = strpos($d, $driver) > -1;
$drivers_options[] = array($driver, $selected);
}
-
+
return Widget::Select($name, $drivers_options, array('multiple'=>'multiple'));
}
@@ -740,47 +743,47 @@ public static function generateDriversSelectOptions($settings, $name) {
* @param XMLElement $wrapper
*/
private function appendMustBeUniqueCheckbox(&$wrapper) {
- $label = new XMLElement('label', NULL, array('class' => 'column'));
- $chk = new XMLElement('input', NULL, array('name' => 'fields['.$this->get('sortorder').'][unique]', 'type' => 'checkbox'));
-
+ $label = new XMLElement('label', null, array('class' => 'column'));
+ $chk = new XMLElement('input', null, array('name' => 'fields['.$this->get('sortorder').'][unique]', 'type' => 'checkbox'));
+
$label->appendChild($chk);
$label->setValue(__('Make this field unique in the section'), false);
if ($this->get('unique') == 'yes') {
$chk->setAttribute('checked','checked');
}
-
+
$wrapper->appendChild($label);
}
-
+
/**
*
* Utility (private) function to append a checkbox for the 'unique media' setting
* @param XMLElement $wrapper
*/
private function appendResourceMustBeUniqueCheckbox(&$wrapper) {
- $label = new XMLElement('label', NULL, array('class' => 'column'));
- $chk = new XMLElement('input', NULL, array('name' => 'fields['.$this->get('sortorder').'][unique_media]', 'type' => 'checkbox'));
-
+ $label = new XMLElement('label', null, array('class' => 'column'));
+ $chk = new XMLElement('input', null, array('name' => 'fields['.$this->get('sortorder').'][unique_media]', 'type' => 'checkbox'));
+
$label->appendChild($chk);
$label->setValue(__('Make this field checks to insure resources are used only once across the field'), false);
-
+
if ($this->get('unique_media') == 'yes') {
$chk->setAttribute('checked','checked');
}
-
+
$wrapper->appendChild($label);
}
-
-
+
+
/**
*
* Utility (private) function to append a checkbox for the 'thumbs' setting
* @param XMLElement $wrapper
*/
private function appendShowThumbnailCheckbox(&$wrapper) {
- $label = new XMLElement('label', NULL, array('class' => 'column'));
- $chk = new XMLElement('input', NULL, array('name' => 'fields['.$this->get('sortorder').'][thumbs]', 'type' => 'checkbox'));
+ $label = new XMLElement('label', null, array('class' => 'column'));
+ $chk = new XMLElement('input', null, array('name' => 'fields['.$this->get('sortorder').'][thumbs]', 'type' => 'checkbox'));
$label->appendChild($chk);
$label->setValue(__('Show thumbnails in table'), false);
@@ -798,8 +801,8 @@ private function appendShowThumbnailCheckbox(&$wrapper) {
* @param XMLElement $wrapper
*/
private function appendForceSSLCheckbox(&$wrapper) {
- $label = new XMLElement('label', NULL, array('class' => 'column'));
- $chk = new XMLElement('input', NULL, array('name' => 'fields['.$this->get('sortorder').'][force_ssl]', 'type' => 'checkbox'));
+ $label = new XMLElement('label', null, array('class' => 'column'));
+ $chk = new XMLElement('input', null, array('name' => 'fields['.$this->get('sortorder').'][force_ssl]', 'type' => 'checkbox'));
$label->appendChild($chk);
$label->setValue(__('Force protocol-less embeding (allow ssl, only if the drivers supports it)'), false);
@@ -819,15 +822,14 @@ private function appendForceSSLCheckbox(&$wrapper) {
* @param int $entry_id
* @return string - the html of the link
*/
- public function prepareTableValue($data, XMLElement $link=NULL, $entry_id=NULL){
-
+ public function prepareTableValue($data, XMLElement $link = null, $entry_id = null){
$url = $data['url'];
$thumb = $data['thumbnail_url'];
$textValue = $this->prepareTextValue($data, $entry_id);
- $value = NULL;
+ $value = null;
// no url = early exit
- if(strlen($url) == 0) return NULL;
+ if(strlen($url) == 0) return null;
// no thumbnail or the parameter is not set ?
if (empty($thumb) || $this->get('thumbs') != 'yes') {
@@ -835,11 +837,7 @@ public function prepareTableValue($data, XMLElement $link=NULL, $entry_id=NULL){
$value = $textValue;
} else {
// create a image
- $thumb = ServiceDriver::removeHTTPProtocol($thumb);
- $thumb = ServiceDriver::removeRelativeProtocol($thumb);
- $img_path = URL . '/image/1/0/40/1/' . $thumb;
-
- $value = '';
+ $value = '';
}
// does this cell serve as a link ?
@@ -883,131 +881,183 @@ public function prepareTextValue($data, $entry_id = null) {
* Creates table needed for entries of invidual fields
*/
public function createTable(){
- $id = $this->get('id');
-
- return Symphony::Database()->query("
- CREATE TABLE `tbl_entries_data_$id` (
- `id` int(11) unsigned NOT NULL auto_increment,
- `entry_id` int(11) unsigned NOT NULL,
- `res_id` varchar(128),
- `url` varchar(2048),
- `url_oembed_xml` varchar(2048),
- `title` varchar(2048),
- `thumbnail_url` varchar(2048),
- `oembed_xml` text,
- `dateCreated` timestamp DEFAULT CURRENT_TIMESTAMP,
- `driver` varchar(50),
- PRIMARY KEY (`id`),
- UNIQUE KEY `entry_id` (`entry_id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
- ");
+ return Symphony::Database()
+ ->create('tbl_entries_data_' . $this->get('id'))
+ ->ifNotExists()
+ ->fields([
+ 'id' => [
+ 'type' => 'int(11)',
+ 'auto' => true,
+ ],
+ 'entry_id' => 'int(11)',
+ 'res_id' => [
+ 'type' => 'varchar(128)',
+ 'null' => true,
+ ],
+ 'url' => [
+ 'type' => 'varchar(2048)',
+ 'null' => true,
+ ],
+ 'url_oembed_xml' => [
+ 'type' => 'varchar(2048)',
+ 'null' => true,
+ ],
+ 'title' => [
+ 'type' => 'varchar(2048)',
+ 'null' => true,
+ ],
+ 'thumbnail_url' => [
+ 'type' => 'varchar(2048)',
+ 'null' => true,
+ ],
+ 'oembed_xml' => [
+ 'type' => 'text',
+ 'null' => true,
+ ],
+ 'dateCreated' => [
+ 'type' => 'timestamp',
+ 'default' => 'current_timestamp'
+ ],
+ 'driver' => [
+ 'type' => 'varchar(50)',
+ 'null' => auto,
+ ],
+ ])
+ ->keys([
+ 'id' => 'primary',
+ 'entry_id' => 'unique',
+ ])
+ ->execute()
+ ->success();
}
/**
* Creates the table needed for the settings of the field
*/
public static function createFieldTable() {
-
- $tbl = self::FIELD_TBL_NAME;
-
- return Symphony::Database()->query("
- CREATE TABLE IF NOT EXISTS `$tbl` (
- `id` int(11) unsigned NOT NULL auto_increment,
- `field_id` int(11) unsigned NOT NULL,
- `refresh` int(11) unsigned NULL,
- `driver` varchar(250) NOT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `field_id` (`field_id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
- ");
+ return Symphony::Database()
+ ->create(self::FIELD_TBL_NAME)
+ ->ifNotExists()
+ ->fields([
+ 'id' => [
+ 'type' => 'int(11)',
+ 'auto' => true,
+ ],
+ 'field_id' => 'int(11)',
+ 'refresh' => [
+ 'type' => 'int(11)',
+ 'null' => true,
+ ],
+ 'driver' => 'varchar(250)',
+ ])
+ ->keys([
+ 'id' => 'primary',
+ 'field_id' => 'unique',
+ ])
+ ->execute()
+ ->success();
}
/**
* Updates the table for the new settings: `unique`
*/
public static function updateFieldTable_Unique() {
-
- $tbl = self::FIELD_TBL_NAME;
-
- return Symphony::Database()->query("
- ALTER TABLE `$tbl`
- ADD COLUMN `unique` enum('yes','no') NOT NULL DEFAULT 'no'
- ");
+ return Symphony::Database()
+ ->alter(self::FIELD_TBL_NAME)
+ ->add([
+ 'unique' => [
+ 'type' => 'enum',
+ 'values' => ['yes','no'],
+ 'default' => 'no',
+ ],
+ ])
+ ->execute()
+ ->success();
}
/**
* Updates the table for the new settings: `thumbs`
*/
public static function updateFieldTable_Thumbs() {
-
- $tbl = self::FIELD_TBL_NAME;
-
- return Symphony::Database()->query("
- ALTER TABLE `$tbl`
- ADD COLUMN `thumbs` enum('yes','no') NOT NULL DEFAULT 'no'
- ");
+ return Symphony::Database()
+ ->alter(self::FIELD_TBL_NAME)
+ ->add([
+ 'thumbs' => [
+ 'type' => 'enum',
+ 'values' => ['yes','no'],
+ 'default' => 'no',
+ ],
+ ])
+ ->execute()
+ ->success();
}
/**
* Updates the table for the new settings: `params_set_id`
*/
public static function updateFieldTable_QueryParams() {
-
- $tbl = self::FIELD_TBL_NAME;
-
- return Symphony::Database()->query("
- ALTER TABLE `$tbl`
- ADD COLUMN `query_params` varchar(1024) NULL
- ");
+ return Symphony::Database()
+ ->alter(self::FIELD_TBL_NAME)
+ ->add([
+ 'query_params' => [
+ 'type' => 'varchar(2014)',
+ 'null' => true,
+ ],
+ ])
+ ->execute()
+ ->success();
}
public static function updateFieldTable_Driver() {
-
- $tbl = self::FIELD_TBL_NAME;
-
- return Symphony::Database()->query("
- ALTER TABLE `$tbl`
- MODIFY COLUMN `driver` varchar(250) NOT NULL
- ");
+ return Symphony::Database()
+ ->alter(self::FIELD_TBL_NAME)
+ ->modify([
+ 'driver' => 'varchar(250)',
+ ])
+ ->execute()
+ ->success();
}
public static function updateFieldData_Driver() {
-
- $tbl = self::FIELD_TBL_NAME;
-
- // allow all drivers for fields that already exists
- $drivers = MySQL::cleanValue( implode(',',ServiceDispatcher::getAllDriversNames()) );
-
- return Symphony::Database()->query("
- UPDATE `$tbl`
- SET `driver` = '$drivers'
- ");
+ return Symphony::Database()
+ ->update(self::FIELD_TBL_NAME)
+ ->set([
+ 'driver' => implode(',',ServiceDispatcher::getAllDriversNames()),
+ ])
+ ->execute()
+ ->success();
}
public static function updateDataTable_Driver() {
-
$fields = self::getFields();
-
+
// make sure the new driver column is add to
// fields that already exists
foreach ($fields as $field) {
-
+
$id = $field->get('id');
-
+
// test is the column exist
- $col = Symphony::Database()->fetch("
- SHOW COLUMNS FROM `tbl_entries_data_$id`
- WHERE `field` = 'driver'
- ");
-
+ $col = Symphony::Database()
+ ->showColumns()
+ ->from('tbl_entries_data_' . $id)
+ ->where([
+ 'field' => 'driver',
+ ])
+ ->execute()
+ ->rows();
+
// if the col doest not exists
if (!is_array($col) || count($col) == 0) {
-
- $ret = Symphony::Database()->query("
- ALTER TABLE `tbl_entries_data_$id`
- ADD COLUMN `driver` varchar(50) NOT NULL
- ");
-
+
+ $ret = Symphony::Database()
+ ->alter('tbl_entries_data_' . $id)
+ ->add([
+ 'driver' => 'varchar(50)',
+ ])
+ ->execute()
+ ->success();
+
if (!$ret) {
return false;
}
@@ -1015,71 +1065,81 @@ public static function updateDataTable_Driver() {
}
return true;
}
-
+
private static function getFields() {
$fm = new FieldManager(Symphony::Engine());
// get all entries tables of type oEmbed
$fields = $fm->fetch(null, null, 'ASC', 'id', 'oembed');
-
+
return $fields;
}
-
+
public static function updateDataTable_UniqueKey() {
-
$fields = self::getFields();
-
+
// make sure the new driver column is add to
// fields that already exists
foreach ($fields as $field) {
- $tbl = 'tbl_entries_data_' . $field->get('id');
- return Symphony::Database()->query("
- ALTER TABLE `$tbl`
- ADD UNIQUE (`entry_id`)
- ");
+ return Symphony::Database()
+ ->alter('tbl_entries_data_' . $field->get('id'))
+ ->addKey([
+ 'entry_id' => 'unique',
+ ])
+ ->execute()
+ ->success();
}
return true;
}
-
+
public static function updateFieldTable_ForceSSL() {
-
- $tbl = self::FIELD_TBL_NAME;
-
- return Symphony::Database()->query("
- ALTER TABLE `$tbl`
- ADD COLUMN `force_ssl` ENUM('yes','no') NOT NULL DEFAULT 'no'
- ");
+ return Symphony::Database()
+ ->alter(self::FIELD_TBL_NAME)
+ ->add([
+ 'force_ssl' => [
+ 'type' => 'enum',
+ 'values' => ['yes','no'],
+ 'default' => 'no',
+ ],
+ ])
+ ->execute()
+ ->success();
}
-
+
public static function updateFieldTable_UniqueMedia() {
-
- $tbl = self::FIELD_TBL_NAME;
-
- return Symphony::Database()->query("
- ALTER TABLE `$tbl`
- ADD COLUMN `unique_media` ENUM('yes','no') NOT NULL DEFAULT 'no'
- ");
+ return Symphony::Database()
+ ->alter(self::FIELD_TBL_NAME)
+ ->add([
+ 'unique_media' => [
+ 'type' => 'enum',
+ 'values' => ['yes','no'],
+ 'default' => 'no',
+ ],
+ ])
+ ->execute()
+ ->success();
}
-
+
public static function updateFieldTable_UniqueKey() {
- $tbl = self::FIELD_TBL_NAME;
-
- return Symphony::Database()->query("
- ALTER TABLE `$tbl`
- ADD UNIQUE (`field_id`)
- ");
+ return Symphony::Database()
+ ->alter(self::FIELD_TBL_NAME)
+ ->addKey([
+ 'field_id' => 'unique',
+ ])
+ ->execute()
+ ->success();
}
-
+
/**
*
* Drops the table needed for the settings of the field
*/
public static function deleteFieldTable() {
- $tbl = self::FIELD_TBL_NAME;
-
- return Symphony::Database()->query("
- DROP TABLE IF EXISTS `$tbl`
- ");
+ return Symphony::Database()
+ ->drop(self::FIELD_TBL_NAME)
+ ->ifExists()
+ ->execute()
+ ->success();
}
-
- }
\ No newline at end of file
+
+ }
diff --git a/lib/class.entryqueryoembedadapter.php b/lib/class.entryqueryoembedadapter.php
new file mode 100644
index 0000000..c19b035
--- /dev/null
+++ b/lib/class.entryqueryoembedadapter.php
@@ -0,0 +1,36 @@
+ ['var' => $filter, 'type' => 'string'],
+ ]);
+
+ $columns = ['url', 'title', 'driver'];
+
+ if ($this->isFilterRegex($filter)) {
+ return $this->createFilterRegexp($filter, $columns);
+ } elseif ($this->isFilterSQL($filter)) {
+ return $this->createFilterSQL($filter, $columns);
+ } elseif ($this->isFilterNotEqual($filter)) {
+ return $this->createFilterNotEqual($filter, $columns);
+ }
+ return $this->createFilterEquality($filter, $columns);
+ }
+
+ public function getSortColumns()
+ {
+ return ['title'];
+ }
+}
diff --git a/lib/class.serviceDriver.php b/lib/class.serviceDriver.php
index b3aad72..d4ac665 100644
--- a/lib/class.serviceDriver.php
+++ b/lib/class.serviceDriver.php
@@ -133,7 +133,7 @@ public final function getDataFromSource($params, &$errorFlag) {
} else {
$error = isset($last['curl_error']) ? $last['curl_error'] : '';
}
-
+
$data['error'] = __('Failed to load oEmbed data: %s', array(
$error
));
@@ -145,7 +145,7 @@ public final function getDataFromSource($params, &$errorFlag) {
$parsedAray = @$parser->createArray($response, $this, $url, $errorFlag);
- if (!$errorFlag && $parsedAray !== FALSE) {
+ if (!$errorFlag && $parsedAray !== false) {
// merge the parsed data
$data = array_merge($data, $parsedAray);
} else {
@@ -294,7 +294,7 @@ public function getNeededUrlsToJITimages() {
public function supportsSSL() {
return false;
}
-
+
/**
* This flags indicate that the current driver is a native driver,
* i.e. this driver uses the official oEmbed api of the provider.
@@ -304,13 +304,13 @@ public function supportsSSL() {
* found. Note that enabling multiple non-native drivers is not-recommanded.
*
* See: https://github.com/Solutions-Nitriques/oembed_field/pull/38
- *
+ *
* @since 1.7
*
* @return boolean
*/
public function isNative() {
- return true;
+ return true;
}
/**
@@ -326,7 +326,7 @@ public static function removeHTTPProtocol($value, $replaceValue = '//') {
$value = str_replace('http://', $replaceValue, $value);
return $value;
}
-
+
/**
* Converts // to empty string or the specified
* $replaceValue
@@ -368,4 +368,4 @@ protected function getEmbedSize($options, $size) {
return $options[$size. '_side'];
}
- }
\ No newline at end of file
+ }
diff --git a/lib/drivers/class.serviceYouTube.php b/lib/drivers/class.serviceYouTube.php
index ea53d39..58bc660 100644
--- a/lib/drivers/class.serviceYouTube.php
+++ b/lib/drivers/class.serviceYouTube.php
@@ -43,7 +43,7 @@ public function getOEmbedApiUrl($params) {
// may place the resource ID elsewhere in the hash (#) tag
// if the url contains '#' (the real resource ID is the last part)
- if (strpos($url, '#') !== FALSE) {
+ if (strpos($url, '#') !== false) {
// split on every # or /
$exploded = preg_split('/[\/#]/', $url);
@@ -54,4 +54,4 @@ public function getOEmbedApiUrl($params) {
return 'https://www.youtube.com/oembed?format=xml&url=' . $url . $query_params;
}
- }
\ No newline at end of file
+ }
diff --git a/lib/parsers/class.parser.json.php b/lib/parsers/class.parser.json.php
index c1f5bf0..389c6b6 100644
--- a/lib/parsers/class.parser.json.php
+++ b/lib/parsers/class.parser.json.php
@@ -25,15 +25,15 @@ class serviceParserJSON extends ServiceParser {
public function createArray($source, $driver, $url, &$errorFlag) {
// get the data as an array
$data = @json_decode($source, true);
-
- if ($data === FALSE) {
+
+ if ($data === false) {
$errorFlag = true;
}
-
+
if (!$errorFlag) {
// original content
$xml['xml'] = $source;
-
+
$idTagName = $driver->getIdTagName();
if ($idTagName == null || !isset($data[$idTagName])) {
$xml['id'] = Lang::createHandle($url);
@@ -74,4 +74,4 @@ public function createJSON($source, $driver, $url, &$errorFlag) {
return $source;
}
- }
\ No newline at end of file
+ }
diff --git a/lib/parsers/class.parser.xml.php b/lib/parsers/class.parser.xml.php
index 920dca8..7714d16 100644
--- a/lib/parsers/class.parser.xml.php
+++ b/lib/parsers/class.parser.xml.php
@@ -31,7 +31,7 @@ public function createArray($source, $driver, $url, &$errorFlag) {
if (!$errorFlag) {
$xml['xml'] = @$doc->saveXML();
- if ($xml['xml'] === FALSE) {
+ if ($xml['xml'] === false) {
$errorFlag = true;
}
else {
@@ -76,4 +76,4 @@ public function createJSON($source, $driver, $url, &$errorFlag) {
return json_encode($source);
}
- }
\ No newline at end of file
+ }