]> 91.132.146.200 Git - bibliotheca-php.git/commitdiff
adding #2 and some php syntax features
authorBanana <mail@bananas-playground.net>
Sun, 31 Jan 2021 17:08:03 +0000 (18:08 +0100)
committerBanana <mail@bananas-playground.net>
Sun, 31 Jan 2021 17:08:03 +0000 (18:08 +0100)
CHANGELOG
documentation/tool-imdbweb.txt
webclient/config/config-imdb.php.default [deleted file]
webclient/config/config-imdbweb.php.default [new file with mode: 0644]
webclient/lib/gorenest.class.php
webclient/lib/tentacle.class.php
webclient/view/default/managecollectionfields/managecollectionfields.html
webclient/view/default/tool/tool-imdbweb.html
webclient/view/default/tool/tool-imdbweb.php

index c16af1daba3f7c075ce4c5843e3257c11514294b..7b38ab05fb2330d7b8dc434bd4fed11634f3bf6d 100644 (file)
--- 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
index 4d19473be2668c3f243f0f037782e64374e8bb00..e3c4b29f1ddfbd8c2df25ac5964c92fabf8e508e 100644 (file)
@@ -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-imdb.php.default
deleted file mode 100644 (file)
index 85375b1..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<?php
-/**
- * Options for the grabber
- *
- * TOOL_IMDBWEB_SEARCH can be 'movie','tv','episode','game','all'. Default is movie
- * TOOL_IMDBWEB_FIELDS is an array to define which fields from IMDB are displayed for selection
- *             an empty array() shows all.
- *             getAka, getAkas, getAspectRatio, getAwards, getBudget, getCast, getCastAndCharacter, CastAndCharacterAsUrl,
- *             getCastAsUrl, getCertification, getColor, getCompany, getCompanyAsUrl, getCountry, getCountryAsUrl,
- *             getCreator, getCreatorAsUrl, getDescription, getDirector, getDirectorAsUrl, getGenre, getGenreAsUrl,
- *             getGross, getLanguage, getLanguageAsUrl, getLocation, getLocationAsUrl, getLocations, getMpaa, getPlot,
- *             getPlotKeywords, getPoster, getRating, getRatingCount, getReleaseDate, getReleaseDates, getRuntime,
- *             getSeasons, getSeasonsAsUrl, getSoundMix, getTagline, getTitle, getTrailerAsUrl, getUrl, getUserReview,
- *             getVotes, getWriter, getWriterAsUrl, getYear
- * 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_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');
-define('TOOL_IMDBWEB_BROWSER_ACCEPT_LANG','en-US,en;q=0.5');
diff --git a/webclient/config/config-imdbweb.php.default b/webclient/config/config-imdbweb.php.default
new file mode 100644 (file)
index 0000000..187b95b
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Options for the grabber
+ *
+ * TOOL_IMDBWEB_SEARCH can be 'movie','tv','episode','game','all'. Default is movie
+ * TOOL_IMDBWEB_FIELDS is an array to define which fields from IMDB are displayed for selection
+ *             an empty array() shows all.
+ *             getAka, getAkas, getAspectRatio, getAwards, getBudget, getCast, getCastAndCharacter, CastAndCharacterAsUrl,
+ *             getCastAsUrl, getCertification, getColor, getCompany, getCompanyAsUrl, getCountry, getCountryAsUrl,
+ *             getCreator, getCreatorAsUrl, getDescription, getDirector, getDirectorAsUrl, getGenre, getGenreAsUrl,
+ *             getGross, getLanguage, getLanguageAsUrl, getLocation, getLocationAsUrl, getLocations, getMpaa, getPlot,
+ *             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_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');
+define('TOOL_IMDBWEB_BROWSER_ACCEPT_LANG','en-US,en;q=0.5');
index c7f10e42656cb2d01bbfe755af9f9afa2fd0640d..5c14f6c0277d6b719235a5ec83c140ebf8755a75 100644 (file)
@@ -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;
        }
 }
index 7e6bab423d0df34d72656972989bb5cf491d4a18..66ccd3902d23bf76a20201500a02ef49096419fa 100644 (file)
@@ -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'),
index 8b4be134f487af736637cef9192e01f0d29fdee0..332a2b12643633f2f0054d954baa6f00f87835db 100644 (file)
@@ -14,7 +14,7 @@
                        <?php foreach($TemplateData['existingFields'] as $k=>$v) { ?>
                        <div data-field-id="<?php echo $k; ?>">
                                <span class="uk-sortable-handle uk-margin-small-right" uk-icon="icon: table"></span>
-                               <?php echo $v['displayname']; ?> (<?php echo $v['type']; ?>)
+                               <?php echo $v['displayname']; ?> (<?php echo $v['type'],'; ',$v['identifier']; ?>)
                        </div>
                        <?php } ?>
                </div>
@@ -35,7 +35,7 @@
                        <?php foreach($TemplateData['availableFields'] as $k=>$v) { ?>
                        <div data-field-id="<?php echo $k; ?>">
                                <span class="uk-sortable-handle uk-margin-small-right" uk-icon="icon: table"></span>
-                               <?php echo $v['displayname']; ?> (<?php echo $v['type']; ?>)
+                               <?php echo $v['displayname']; ?> (<?php echo $v['type'],'; ',$v['identifier']; ?>)
                        </div>
                        <?php } ?>
                </div>
index 2009d4360907919222f96e14732a1a8aa17db7ed..a2f2b0de83a3c953f9a5d2d4f248bf66ca1ce98f 100644 (file)
@@ -37,7 +37,7 @@
        <div class="uk-width-1-2@s">
                <select class="uk-select" name="fdata[into][<?php echo $k; ?>]">
                        <option value="">None</option>
-                       <?php echo $TemplateData['saveToSelection']; ?>
+                       <?php echo toolMethod_GetTargetSelection($TemplateData['saveToSelection'],$k); ?>
                </select>
        </div>
 
index 68e6b406c8913905af85de85c82eff7160f9963a..b3e3601ec76b2dd24aff753dd98167b5f7e6f665 100644 (file)
@@ -46,7 +46,7 @@ $TemplateData['showMatchingForm'] = false;
 $collectionFields = $ManangeCollectionsFields->getExistingFields(false, true);
 if(!empty($collectionFields)) {
        foreach ($collectionFields as $k=>$v) {
-               $TemplateData['saveToSelection'] .= "<option value='".$k."'>".$v['displayname']."</option>\n";
+               $TemplateData['saveToSelection'] .= "<option value='".$k."' sel_".$v['identifier'].">".$v['displayname']."</option>\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;
+}