From: Banana Date: Sun, 7 May 2023 12:18:38 +0000 (+0200) Subject: Add top 5 tag or category relation stats in the tag and category overview X-Git-Tag: 2.8.2_20230914~20 X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=941699009cc25e10bdcb51bc5c3165f2a09af33e;p=insipid.git Add top 5 tag or category relation stats in the tag and category overview --- diff --git a/ChangeLog b/ChangeLog index c4a7764..5f488ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ -version 2.x - +version 2.x - Dragon Chapel () + + + Add top 5 tag or category relation stats in the tag and category overview version 2.8.1 - Deathwind Chapel (2022-12-31) diff --git a/webroot/lib/lang/eng.lang.ini b/webroot/lib/lang/eng.lang.ini index 67c9980..07f5dcf 100644 --- a/webroot/lib/lang/eng.lang.ini +++ b/webroot/lib/lang/eng.lang.ini @@ -72,6 +72,11 @@ home.input.new.link = "Add new Link" home.input.search.found = "Results found." home.last.added = "Last added" +view.nav.all.tags = "Tags" +view.nav.all.categories = "Categories" +view.nav.back.home = "back home" +view.nav.random = "Random link" + view.name = "Name" view.new.name = "New name" view.deletion = "Deletion" @@ -82,9 +87,11 @@ view.image.of.link = "Image from provided link" view.image.link = "Image Link" view.categories = "Categories" view.category = "Category" +view.category.topcombination = "Top category combinations" view.tag.help = "Enter a new one or select an existing from the suggested and press enter." view.tag = "Tag" view.tags = "Tags" +view.tag.topcombination = "Top tag combinations" view.private = "Private" view.url = "URL" view.image = "Image" @@ -122,12 +129,6 @@ stats.import.xml.help = "Single or multiple" stats.import.xml.file = "Choose a file" stats.import.xml.overwrite = "Overwrite existing" stats.import.xml.import = "Import" - -view.nav.all.tags = "Tags" -view.nav.all.categories = "Categories" -view.nav.back.home = "back home" -view.nav.random = "Random link" - stats.storage.clean.fail = "Something went wrong while storage cleaning" stats.import.missing.file = "Please provide a import file" stats.search.index.fail = "Something went wrong while search index update" diff --git a/webroot/lib/lang/ger.lang.ini b/webroot/lib/lang/ger.lang.ini index caf9c00..be20901 100644 --- a/webroot/lib/lang/ger.lang.ini +++ b/webroot/lib/lang/ger.lang.ini @@ -72,6 +72,11 @@ home.input.new.link = "Neuen Link hinzufügen" home.input.search.found = "Ergebnisse gefunden." home.last.added = "Zuletzt hinzugefügt" +view.nav.all.tags = "Tags" +view.nav.all.categories = "Kategorien" +view.nav.back.home = "zurück nach Hause" +view.nav.random = "Zufallslink" + view.name = "Name" view.new.name = "Neuer Name" view.deletion = "Löschung" @@ -82,9 +87,11 @@ view.image.of.link = "Bild vom Link" view.image.link = "Bildverweis" view.categories = "Kategorien" view.category = "Kategorie" +view.category.topcombination = "Top Kategorie Kombinationen" view.tag.help = "Eingabe eines Neuen oder Auswahl eines Bestehenden und danach Enter drücken." view.tag = "Tag" view.tags = "Tags" +view.tag.topcombination = "Top Tag Kombinationen" view.private = "Privat" view.url = "URL" view.image = "Bild" diff --git a/webroot/lib/management.class.php b/webroot/lib/management.class.php index 772c631..1a51661 100644 --- a/webroot/lib/management.class.php +++ b/webroot/lib/management.class.php @@ -944,6 +944,101 @@ class Management { return $ret; } + /** + * Top 5 combinations of either tag or category + * + * array( + * array( + * amount => number + * rel => array(rel, name) + * ) + * ) + * + * @param string $type + * @return array + */ + public function linkRelationStats(string $type='tag'): array { + $ret = array(); + + // build the digit string which describes the tag/cat combination + $_relCombination = array(); + if($type == 'category') { + $queryStr = "SELECT `linkid`, `categoryid` AS rel + FROM `".DB_PREFIX."_categoryrelation` + ORDER BY `linkid`, rel ASC"; + } else { + $queryStr = "SELECT `linkid`, `tagid` AS rel + FROM `".DB_PREFIX."_tagrelation` + ORDER BY `linkid`, rel ASC"; + } + $query = $this->DB->query($queryStr); + if(!empty($query) && $query->num_rows > 0) { + while($result = $query->fetch_assoc()) { + if(isset($_relCombination[$result['linkid']])) { + $_relCombination[$result['linkid']] .= ",".$result['rel']; + } else { + // https://www.php.net/manual/en/language.types.array.php "Strings containing valid decimal ints ... will be cast to the int type + // if not not done the arsort results are messed up + $_relCombination[$result['linkid']] = "0".$result['rel']; + } + } + } + + // now count the unique digit strings + $_relCombination_amount = array(); + if(!empty($_relCombination)) { + foreach($_relCombination as $k=>$v) { + if(isset($_relCombination_amount[$v])) { + $_relCombination_amount[$v]++; + } else { + $_relCombination_amount[$v] = 1; + } + } + } + + // now sort and return top 5 combinations + // also resolve tag/cat name + if(!empty($_relCombination_amount)) { + arsort($_relCombination_amount); + $_top5 = array_splice($_relCombination_amount,0,5); + + foreach($_top5 as $k=>$v) { + $_t = array(); + if($k[0] === "0") { + $k = substr($k,1); + } + + $_t['amount'] = $v; + $_rel = explode(",",$k); + + $_existingRelInfo = array(); // avoid duplicate queries + foreach($_rel as $t) { + if(!isset($_existingRelInfo[$t])) { + if($type == 'category') { + $queryStr = "SELECT `name` FROM `".DB_PREFIX."_category` + WHERE `id` = '".$this->DB->real_escape_string($t)."'"; + } else { + $queryStr = "SELECT `name` FROM `".DB_PREFIX."_tag` + WHERE `id` = '".$this->DB->real_escape_string($t)."'"; + } + $query = $this->DB->query($queryStr); + if(!empty($query) && $query->num_rows > 0) { + $relinfo = $query->fetch_assoc(); + $_existingRelInfo[$t] = $relinfo['name']; + $_t['rel'][$t] = $relinfo['name']; + } + } else { + $_t['rel'][$t] = $_existingRelInfo[$t]; + } + } + $ret[] = $_t; + } + + } + + return $ret; + } + /** * Return the query string for the correct status type * diff --git a/webroot/view/overview.inc.php b/webroot/view/overview.inc.php index 8145e78..b8a1759 100644 --- a/webroot/view/overview.inc.php +++ b/webroot/view/overview.inc.php @@ -65,6 +65,7 @@ $pagination = array('pages' => 0); $displayEditButton = false; $isAwm = false; $sortLink = array(); +$colInfo = array(); if(Summoner::simpleAuthCheck() === true) { $displayEditButton = true; @@ -106,6 +107,7 @@ switch($_requestMode) { # show all the tags we have $tagCollection = $Management->tags(0, true); $subHeadline = $T->t('view.tags').' '; + $colInfo = $Management->linkRelationStats(); } break; case 'category': @@ -124,6 +126,7 @@ switch($_requestMode) { # show all the categories we have $categoryCollection = $Management->categories(0, true); $subHeadline = $T->t('view.categories').' '; + $colInfo = $Management->linkRelationStats('category'); } break; case 'awm': diff --git a/webroot/view/overview.php b/webroot/view/overview.php index af15bd6..0c2a727 100644 --- a/webroot/view/overview.php +++ b/webroot/view/overview.php @@ -132,57 +132,103 @@
-
+
+ + + +
+ + + + + + $v) { ?> + + + + + +
t('view.name'); ?>t('view.num.links'); ?>
+
+
+
+ + t('view.tag.topcombination'); ?> - - + + - $v) { ?> - - - - - + $v) { ?> + + + + +
t('view.name'); ?>t('view.num.links'); ?>#t('view.tags'); ?>
+ $tname) { ?> + + +
+
- - -
-
- - - - - - $v) { ?> - - - - +
t('view.name'); ?>t('view.num.links'); ?>
-
- -
-
- - - t('view.edit.categories'); ?> - +
+ + + + + + $v) { ?> + + + + + +
t('view.name'); ?>t('view.num.links'); ?>
- +
+ + t('view.category.topcombination'); ?> + + + + + + $v) { ?> + + + + + +
#t('view.categories'); ?>
+ $cname) { ?> + + +
+ +
diff --git a/webroot/view/stats.inc.php b/webroot/view/stats.inc.php index 622c219..447c43d 100644 --- a/webroot/view/stats.inc.php +++ b/webroot/view/stats.inc.php @@ -68,35 +68,6 @@ if(isset($_POST['statsCreateDBBackup'])) { echo 'mysqldump-php error: ' . $e->getMessage(); } - /* - require_once 'lib/Mysqldump.php'; - $backupTmpFile = tempnam(sys_get_temp_dir(),'inspid'); - - // mysqldump was modifed to make this work - // include-views was not working while using include-tables - $dumpSettings = array( - 'include-tables' => array( - DB_PREFIX.'_category', - DB_PREFIX.'_categoryrelation', - DB_PREFIX.'_link', - DB_PREFIX.'_tag', - DB_PREFIX.'_tagrelation' - ), - 'include-views' => array( - DB_PREFIX.'_combined' - ), - 'default-character-set' => \Ifsnop\Mysqldump\Mysqldump::UTF8MB4 - ); - $dump = new Ifsnop\Mysqldump\Mysqldump( - 'mysql:host='.DB_HOST.';dbname='.DB_NAME, - DB_USERNAME, - DB_PASSWORD, - $dumpSettings - ); - - $dump->start($backupTmpFile); - */ - header('Content-Type: application/octet-stream'); header("Content-Transfer-Encoding: Binary"); header("Content-disposition: attachment; filename=inspid-db-backup-full.sql"); @@ -131,7 +102,6 @@ if(isset($_POST['statsImportXML'])) { } if(isset($_POST['statsUpdateSearchIndex'])) { - if($Management->updateSearchIndex() === true) { $TemplateData['refresh'] = 'index.php?p=stats'; }