From f170eeac3b0f177f7f551f761df80baf9e4337bd Mon Sep 17 00:00:00 2001 From: Banana Date: Sun, 31 Jan 2021 18:08:03 +0100 Subject: [PATCH] adding #2 and some php syntax features --- CHANGELOG | 2 ++ documentation/tool-imdbweb.txt | 2 ++ ...php.default => config-imdbweb.php.default} | 19 ++++++++++++++- webclient/lib/gorenest.class.php | 6 ++--- webclient/lib/tentacle.class.php | 11 +++++---- .../managecollectionfields.html | 4 ++-- webclient/view/default/tool/tool-imdbweb.html | 2 +- webclient/view/default/tool/tool-imdbweb.php | 24 ++++++++++++++++++- 8 files changed, 57 insertions(+), 13 deletions(-) rename webclient/config/{config-imdb.php.default => config-imdbweb.php.default} (64%) diff --git a/CHANGELOG b/CHANGELOG index c16af1d..7b38ab0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,8 @@ * Documentation for tools * Documentation for tool imdbweb grabber. Default config added. * Fixed bug #3 + * Added feature #2. There is now a new definition which defines the default targets of the imdb grabber values. + See the config-imdbweb.php.default for more details 1.0 - Castle 20210106 * First usable version diff --git a/documentation/tool-imdbweb.txt b/documentation/tool-imdbweb.txt index 4d19473..e3c4b29 100644 --- a/documentation/tool-imdbweb.txt +++ b/documentation/tool-imdbweb.txt @@ -11,3 +11,5 @@ It searches for movies only. Which fields are available for you to select, are configured in the config.imdbweb.php file to make it easier since not every field the tool provides are needed. Follow the comments in the file for more details. + +An option to make the target fields automatically selected by default to given values. diff --git a/webclient/config/config-imdb.php.default b/webclient/config/config-imdbweb.php.default similarity index 64% rename from webclient/config/config-imdb.php.default rename to webclient/config/config-imdbweb.php.default index 85375b1..187b95b 100644 --- a/webclient/config/config-imdb.php.default +++ b/webclient/config/config-imdbweb.php.default @@ -12,11 +12,28 @@ * getPlotKeywords, getPoster, getRating, getRatingCount, getReleaseDate, getReleaseDates, getRuntime, * getSeasons, getSeasonsAsUrl, getSoundMix, getTagline, getTitle, getTrailerAsUrl, getUrl, getUserReview, * getVotes, getWriter, getWriterAsUrl, getYear + * TOOL_IMDBWEB_FIELDS_TO is a array to define which imdbwebfield (see TOOL_IMDBWEB_FIELDS) should be saved into + * a bibliotheca field. Those or the fields a collection can have. Use the identifier of a field. + * Depends on your settings so make sure everything is setup first. Leave it commented if not needed. * TOOL_IMDBWEB_BROWSERSTRING a current browser agent string. Should be updated from time to time. See default config file. * TOOL_IMDBWEB_BROWSER_ACCEPT_LANG should define in which language the content returns */ define('TOOL_IMDBWEB_SEARCH','movie'); -define('TOOL_IMDBWEB_FIELDS', array('getCast','getDescription', 'getDirector', 'getGenre', 'getPlot', 'getRating', 'getRuntime','getTitle', 'getWriter', 'getYear')); +define('TOOL_IMDBWEB_FIELDS', + array( + 'getCast','getDescription', 'getDirector', 'getGenre', 'getPlot', 'getRating', 'getRuntime','getTitle', + 'getWriter', 'getYear' + ) +); +/* +define('TOOL_IMDBWEB_FIELDS_TO', + array( + 'getCast' => 'actors','getDescription' => 'description', 'getDirector' => 'directors', 'getGenre' => 'genres', + 'getPlot' => 'content', 'getRating' => 'imdbrating', 'getRuntime' => 'runtime','getTitle' => 'title', + 'getWriter' => 'writers', 'getYear' => 'year' + ) +); +*/ define('TOOL_IMDBWEB_BROWSER_AGENT','Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0'); define('TOOL_IMDBWEB_BROWSER_ACCEPT','text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'); diff --git a/webclient/lib/gorenest.class.php b/webclient/lib/gorenest.class.php index c7f10e4..5c14f6c 100644 --- a/webclient/lib/gorenest.class.php +++ b/webclient/lib/gorenest.class.php @@ -56,7 +56,7 @@ class GoreNest { * @param mysqli $db * @param Doomguy $user */ - public function __construct($db, $user) { + public function __construct(mysqli $db, Doomguy $user) { $this->_DB = $db; $this->_User = $user; } @@ -98,7 +98,7 @@ class GoreNest { * @param bool $reload * @return array */ - public function get($category,$reload=false) { + public function get(string $category, $reload=false) { $ret = array(); if(empty($category)) return false; @@ -120,7 +120,7 @@ class GoreNest { * * @return array */ - public function allowedPageRequests() { + public function allowedPageRequests(): array { return $this->_allowedPageRequests; } } diff --git a/webclient/lib/tentacle.class.php b/webclient/lib/tentacle.class.php index 7e6bab4..66ccd39 100644 --- a/webclient/lib/tentacle.class.php +++ b/webclient/lib/tentacle.class.php @@ -40,8 +40,9 @@ class Tentacle { * * @param mysqli $databaseConnectionObject * @param Doomguy $userObj + * */ - public function __construct($databaseConnectionObject, $userObj) { + public function __construct(mysqli $databaseConnectionObject, Doomguy $userObj) { $this->_DB = $databaseConnectionObject; $this->_User = $userObj; } @@ -50,10 +51,10 @@ class Tentacle { * Validate if given action is a valid tool and if the user has access * * @param string $identifier - * @return bool|mixed + * @return array */ - public function validate($identifier) { - $ret = false; + public function validate(string $identifier): array { + $ret = array(); $queryStr = "SELECT `name`,`description`,`action` FROM `".DB_PREFIX."_tool` @@ -79,7 +80,7 @@ class Tentacle { * * @return array */ - public function getDefaultCreationInfo() { + public function getDefaultCreationInfo(): array { return array( 'id' => $this->_User->param('id'), 'group' => $this->_User->param('baseGroupId'), diff --git a/webclient/view/default/managecollectionfields/managecollectionfields.html b/webclient/view/default/managecollectionfields/managecollectionfields.html index 8b4be13..332a2b1 100644 --- a/webclient/view/default/managecollectionfields/managecollectionfields.html +++ b/webclient/view/default/managecollectionfields/managecollectionfields.html @@ -14,7 +14,7 @@ $v) { ?>
- () + ()
@@ -35,7 +35,7 @@ $v) { ?>
- () + ()
diff --git a/webclient/view/default/tool/tool-imdbweb.html b/webclient/view/default/tool/tool-imdbweb.html index 2009d43..a2f2b0d 100644 --- a/webclient/view/default/tool/tool-imdbweb.html +++ b/webclient/view/default/tool/tool-imdbweb.html @@ -37,7 +37,7 @@
diff --git a/webclient/view/default/tool/tool-imdbweb.php b/webclient/view/default/tool/tool-imdbweb.php index 68e6b40..b3e3601 100644 --- a/webclient/view/default/tool/tool-imdbweb.php +++ b/webclient/view/default/tool/tool-imdbweb.php @@ -46,7 +46,7 @@ $TemplateData['showMatchingForm'] = false; $collectionFields = $ManangeCollectionsFields->getExistingFields(false, true); if(!empty($collectionFields)) { foreach ($collectionFields as $k=>$v) { - $TemplateData['saveToSelection'] .= "\n"; + $TemplateData['saveToSelection'] .= "\n"; } } @@ -157,3 +157,25 @@ if(isset($_POST['submitFormSave'])) { } } } + + +/** + * Helper function. Takes the prebuild options for the target selection field and search for a matching key. + * Since the optionString is prebuild, avoiding looping over and over again, the selection needs to be done + * by search and replace. + * Checks if TOOL_IMDBWEB_FIELDS_TO is defined and a matching key=>value pair is available + * + * @param string $optionString + * @param string $imdbKey + * @return string + */ +function toolMethod_GetTargetSelection(string $optionString, string $imdbKey): string { + if(defined('TOOL_IMDBWEB_FIELDS_TO') & !empty($imdbKey)) { + if(isset(TOOL_IMDBWEB_FIELDS_TO[$imdbKey])) { + $_k = "sel_".TOOL_IMDBWEB_FIELDS_TO[$imdbKey]; + $optionString = str_replace($_k,'selected="selected"',$optionString); + } + } + + return $optionString; +} -- 2.39.5