Skip to content

Commit e9a305a

Browse files
authored
Merge pull request #816 from OpenKnowledgeMaps/master
merge master
2 parents 386ca09 + dedbfa4 commit e9a305a

11 files changed

Lines changed: 94 additions & 67 deletions

File tree

local_dev/searchflow-container/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
FROM php:8.0-apache
1+
FROM php:8.2-apache
22

33
LABEL maintainer="Chris Kittel <christopher.kittel@openknowledgemaps.org>"
44

55
RUN a2enmod rewrite
66

77
RUN apt-get update && apt-get install -y \
8-
curl libsqlite3-dev php7.4-sqlite libonig-dev libxml2-dev \
8+
curl libsqlite3-dev libonig-dev libxml2-dev \
99
gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 \
1010
libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 \
1111
libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 \

server/classes/headstart/library/APIClient.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
<?php
22

33
namespace headstart\library;
4+
5+
use Exception;
6+
47
require_once dirname(__FILE__) . '/CommUtils.php';
58

69
class APIClient {
10+
private array $ini_array;
11+
private string $database;
12+
private string $base_route;
13+
private array $settings;
714

815
public function __construct($ini_array) {
9-
1016
$this->load_configs($ini_array);
1117
}
1218

13-
public function load_configs($ini_array) {
19+
public function load_configs(array $ini_array): void {
1420
$this->ini_array = $ini_array;
1521
$this->settings = $this->ini_array["general"];
1622
$this->database = $this->ini_array["connection"]["database"];
@@ -21,46 +27,44 @@ public function load_configs($ini_array) {
2127

2228
public function call_api($endpoint, $payload) {
2329
$route = $this->base_route . $endpoint;
30+
2431
try {
2532
$res = CommUtils::call_api($route, $payload);
33+
2634
if ($res["httpcode"] != 200) {
2735
$res["route"] = $route;
2836
$res = $this->handle_api_errors($res);
2937
}
38+
3039
return $res;
3140
}
3241
catch (Exception $e) {
3342
error_log("Error in APIClient: " . $e);
34-
$res = array("status"=>"error",
35-
"httpcode"=>500,
36-
"reason"=>array("unexpected data processing error"));
43+
$res = array("status"=>"error", "httpcode"=>500, "reason"=>array("unexpected data processing error"));
3744
return $res;
3845
}
39-
finally {
40-
}
4146
}
4247

4348
public function call_persistence($endpoint, $payload) {
4449
$route = $this->base_route . "persistence/" . $endpoint . "/" . $this->database;
50+
4551
try {
4652
$res = CommUtils::call_api($route, $payload);
53+
4754
if ($res["httpcode"] != 200) {
4855
$res["route"] = $route;
4956
$res = $this->handle_api_errors($res);
5057
}
58+
5159
return $res;
5260
}
5361
catch (Exception $e) {
5462
// what happens here is instead of bubbling the error up,
55-
// it is caught and we fake a response that looks like an error
63+
// fake a response that looks like an error
5664
// because of the hardcoded reason we loose the original error information
57-
$res = array("status"=>"error",
58-
"httpcode"=>500,
59-
"reason"=>array("unexpected data processing error"));
65+
$res = array("status"=>"error", "httpcode"=>500, "reason"=>array("unexpected data processing error"));
6066
return $res;
6167
}
62-
finally {
63-
}
6468
}
6569

6670
public function handle_api_errors($res) {
@@ -85,5 +89,4 @@ public function handle_api_errors($res) {
8589
error_log(("Trying to handle API errors: " . print_r($res, true)));
8690
return $res;
8791
}
88-
8992
}

server/services/getPDF.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function extractValidPdfUrls(array $revision_data, string $paper_id, string $vis
144144

145145
$inner_data = json_decode($revision_data["data"], true);
146146
$documents_raw = $inner_data["documents"] ?? null;
147-
$documents = json_decode($documents_raw, true);
147+
$documents = $documents_raw !== null ? json_decode($documents_raw, true) : null;
148148

149149
if (strtolower($vis_type) == 'timeline') {
150150
$inner_data = json_decode($inner_data["data"]);

server/services/search.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,35 @@ function packParamsJSON($params_array, $post_params)
2828
return json_encode($output_array);
2929
}
3030

31+
function encode_string(string $str, string $to_encoding = 'UTF-8'): string {
32+
// Defining constants with known encodings and default one
33+
$DEFAULT_ENCODING = 'ISO-8859-1';
34+
$ENCODINGS = [
35+
'UTF-8',
36+
'Windows-1251',
37+
'ISO-8859-1',
38+
'ASCII',
39+
'KOI8-R',
40+
'CP866'
41+
];
42+
43+
// Trying to define the received string encoding
44+
$str_encoding = mb_detect_encoding($str, $ENCODINGS, true);
45+
46+
// If the received string encoding is unknown the default one will be used
47+
if ($str_encoding === false) {
48+
$str_encoding = $DEFAULT_ENCODING;
49+
}
50+
51+
// Converting encoding and returning updated string back
52+
return mb_convert_encoding($str, $to_encoding, $str_encoding);
53+
}
54+
3155
function utf8_converter($array)
3256
{
3357
array_walk_recursive($array, function (&$item, $key) {
34-
if (!mb_detect_encoding($item, 'utf-8', true)) {
35-
$item = utf8_encode($item);
58+
if ($item !== null && !mb_detect_encoding($item, 'utf-8', true)) {
59+
$item = encode_string($item);
3660
}
3761
});
3862

vis/js/HeadstartRunner.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class HeadstartRunner {
5656
}
5757

5858
async run() {
59-
this.checkBrowserVersion();
59+
this.checkIsSupportedBrowser();
6060
this.renderReact();
6161
this.addBackButtonListener();
6262
this.backendData = await this.fetchData();
@@ -66,16 +66,29 @@ class HeadstartRunner {
6666
this.addWindowResizeListener();
6767
}
6868

69-
checkBrowserVersion() {
69+
private checkIsSupportedBrowser() {
70+
const SUPPORTED = [
71+
"Chrome",
72+
"Firefox",
73+
"Safari",
74+
"Microsoft Edge",
75+
"Opera",
76+
] as const;
77+
7078
const browser = Bowser.getParser(window.navigator.userAgent);
71-
// TODO use proper browser filtering https://www.npmjs.com/package/bowser#filtering-browsers
72-
if (
73-
!["chrome", "firefox", "safari"].includes(browser.getBrowserName(true))
74-
) {
79+
const browserName = browser.getBrowserName(true);
80+
81+
const isSupportedBrowser = SUPPORTED.map((browserName) =>
82+
browserName.toLowerCase()
83+
).includes(browserName);
84+
85+
if (!isSupportedBrowser || !browserName) {
7586
alert(
7687
"You are using an unsupported browser. " +
7788
"This visualization was successfully tested " +
78-
"with the latest versions of Chrome, Firefox and Safari."
89+
"with the latest versions of " +
90+
"Chrome, Firefox, Safari, Edge and Opera. " +
91+
"We strongly recommend using one of these browsers."
7992
);
8093
}
8194
}

vis/js/components/Toolbar.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// @ts-nocheck
2-
32
import React from "react";
43
import { connect } from "react-redux";
54
import ScaleToolbar from "../templates/ScaleToolbar";
@@ -14,8 +13,7 @@ const Toolbar = ({
1413
scaleBaseUnit,
1514
scaleValue,
1615
showCredit,
17-
onInfoClick,
18-
onScaleChange
16+
onScaleChange,
1917
}) => {
2018
if (showScaleToolbar) {
2119
const handleScaleChange = (newScaleBy: string) => {
@@ -34,7 +32,6 @@ const Toolbar = ({
3432
explanations={scaleExplanations}
3533
value={scaleValue}
3634
showCredit={showCredit}
37-
onInfoClick={onInfoClick}
3835
onChange={handleScaleChange}
3936
/>
4037
</div>
@@ -55,7 +52,6 @@ const mapStateToProps = (state) => ({
5552
});
5653

5754
const mapDispatchToProps = (dispatch) => ({
58-
onInfoClick: () => dispatch(openInfoModal()),
5955
onScaleChange: (value, baseUnit, contentBased, sort) =>
6056
dispatch(scaleMap(value, baseUnit, contentBased, sort)),
6157
});

vis/js/i18n/localization.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ export interface Localization {
103103
citations: string;
104104
social: string;
105105
references: string;
106-
scale_by_infolink_label: string;
107106
metrics_label: string;
108107
researcher_details_label: string;
109108
scale_by_explanation: string;
@@ -398,7 +397,6 @@ export const localization: {
398397
citations: "citations",
399398
social: "social media mentions",
400399
references: "references outside academia",
401-
scale_by_infolink_label: "Find out more",
402400
metrics_label: "Metrics",
403401
researcher_details_label: "Researcher details",
404402
scale_by_explanation:
@@ -456,7 +454,6 @@ export const localization: {
456454
citations: "citations",
457455
social: "social media mentions",
458456
references: "references outside academia",
459-
scale_by_infolink_label: "Find out more",
460457
metrics_label: "Metrics",
461458
researcher_details_label: "Researcher details",
462459
scale_by_explanation:
@@ -500,10 +497,8 @@ export const localization: {
500497
publication: "papers",
501498
dataset: "datasets",
502499
items: "items",
503-
scale_by_infolink_label: "notes on use of metrics",
504500
// citations_count_label: "citations",
505501
social_media_count_label: " social media mentions",
506502
references_count_label: "references outside academia",
507-
// scale_by_infolink_label: 'Find out more'
508503
},
509504
};

vis/js/templates/ScaleToolbar.tsx

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const ScaleToolbar = ({
1313
explanations,
1414
showCredit,
1515
onChange,
16-
onInfoClick,
1716
}) => {
1817
const localization = useLocalizationContext();
1918
const { trackEvent } = useMatomo();
@@ -22,12 +21,6 @@ const ScaleToolbar = ({
2221
trackEvent("Added components", "Rescale map", labels[id]);
2322
};
2423

25-
const handleInfoClick = (event) => {
26-
event.preventDefault();
27-
onInfoClick();
28-
trackEvent("Added components", "Open more info modal", "Toolbar");
29-
};
30-
3124
return (
3225
<div className="scale-toolbar btn-group dropup">
3326
<div className="dropdown">
@@ -36,20 +29,31 @@ const ScaleToolbar = ({
3629
noCaret
3730
title={
3831
<>
39-
<span style={{
40-
maxWidth: '100%',
41-
display: 'flex',
42-
justifyContent: 'center',
43-
alignItems: 'center'
44-
}}>
32+
<span
33+
style={{
34+
maxWidth: "100%",
35+
display: "flex",
36+
justifyContent: "center",
37+
alignItems: "center",
38+
}}
39+
>
4540
<span>{localization.scale_by_label}</span>
46-
<span id="curr-filter-type" className="truncate-text" style={{
47-
minWidth: '0px',
48-
marginLeft: "3px"
49-
}}>{labels[value]}</span>
50-
<i className="fas fa-chevron-down chevron" style={{
51-
marginLeft: "3px",
52-
}}/>
41+
<span
42+
id="curr-filter-type"
43+
className="truncate-text"
44+
style={{
45+
minWidth: "0px",
46+
marginLeft: "3px",
47+
}}
48+
>
49+
{labels[value]}
50+
</span>
51+
<i
52+
className="fas fa-chevron-down chevron"
53+
style={{
54+
marginLeft: "3px",
55+
}}
56+
/>
5357
</span>
5458
</>
5559
}
@@ -69,14 +73,6 @@ const ScaleToolbar = ({
6973
</div>
7074
<div className="context-scale-toolbar">
7175
<span id="curr-scale-explanation">{explanations[value]}</span>
72-
<a
73-
id="infolink"
74-
className="scale-infolink"
75-
onClick={handleInfoClick}
76-
href="#"
77-
>
78-
{localization.scale_by_infolink_label}
79-
</a>
8076
</div>
8177
{showCredit && (
8278
<div id="credit">

vis/js/templates/modals/CitationModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const CitationModal = ({
8686
);
8787
};
8888

89-
const mapStateToProps = (state) => (console.log('state here', state),{
89+
const mapStateToProps = (state) => ({
9090
open: state.modals.openCitationModal,
9191
isStreamgraph: state.chartType === STREAMGRAPH_MODE,
9292
query: state.query.text,

vis/js/templates/modals/ResearcherInfoModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const getResearcherInfoTemplate = (service, isStreamgraph, modalType) => {
1414
case "orcid":
1515
return ResearcherInfo;
1616
default:
17-
console.log(`${service} is not a valid service for the ResearcherInfoModal`);
17+
// console.log(`${service} is not a valid service for the ResearcherInfoModal`);
1818
return null;
1919
}
2020
};

0 commit comments

Comments
 (0)