Skip to content

Commit 9f59ec8

Browse files
committed
Merge pull request #107
2 parents eb43d15 + 0d2a323 commit 9f59ec8

File tree

7 files changed

+139
-34
lines changed

7 files changed

+139
-34
lines changed

.github/workflows/ci.yml

+12-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
env:
2222
PHP_VERSION: ${{ matrix.php-version }}
2323
strategy:
24+
fail-fast: false
2425
matrix:
2526
php-version: ['7.2']
2627
steps:
@@ -114,6 +115,7 @@ jobs:
114115
MYISAM: 0
115116
PHP_VERSION: ${{ matrix.php-version }}
116117
strategy:
118+
fail-fast: false
117119
matrix:
118120
include:
119121
- php-version: '7.2'
@@ -140,6 +142,12 @@ jobs:
140142
- php-version: '8.2'
141143
db-type: 'mariadb'
142144
db-version: '10.6'
145+
- php-version: '8.3'
146+
db-type: 'mariadb'
147+
db-version: '10.11'
148+
- php-version: '8.4'
149+
db-type: 'mariadb'
150+
db-version: '10.11'
143151
steps:
144152
- name: Checkout phpBB
145153
uses: actions/checkout@v4
@@ -227,14 +235,15 @@ jobs:
227235
MYISAM: 0
228236
PHP_VERSION: ${{ matrix.php-version }}
229237
strategy:
238+
fail-fast: false
230239
matrix:
231240
include:
232241
- php-version: '7.2'
233-
db-type: 'postgres'
234-
db-version: '15-alpine'
235-
- php-version: '8.2'
236242
db-type: 'postgres'
237243
db-version: '16-alpine'
244+
- php-version: '8.4'
245+
db-type: 'postgres'
246+
db-version: '17-alpine'
238247
steps:
239248
- name: Checkout phpBB
240249
uses: actions/checkout@v4

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ If available, it will dynamically generate and include the following data inside
3232
<meta property="og:image:type" content="...">
3333
<meta property="og:image:width" content="...">
3434
<meta property="og:image:height" content="...">
35+
<meta property="article:author" content="...">
3536
<meta property="article:published_time" content="...">
3637
<meta property="article:section" content="...">
3738
<meta property="article:publisher" content="...">
@@ -61,7 +62,8 @@ If available, it will dynamically generate and include the following data inside
6162
"image": "...",
6263
"author": {
6364
"@type": "Person",
64-
"name": "..."
65+
"name": "...",
66+
"url": "..."
6567
},
6668
"datePublished": "...",
6769
"articleSection": "...",

build.xml

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project name="SEO Metadata Extension Builder" description="Builds an extension.zip from a git repository" default="all">
2+
<project name="SEO Metadata Extension Builder"
3+
description="Builds an extension.zip from a git repository" default="all">
34
<property name="env" value="production" />
45
<property name="vendor-name" value="alfredoramos" />
56
<property name="extension-name" value="seometadata" />
@@ -18,8 +19,8 @@
1819
<echo msg="Cleaning files and directories" />
1920

2021
<delete dir="${dir}/tests" />
21-
<delete dir="${dir}/.github"/>
22-
<delete dir="${dir}/.vscode"/>
22+
<delete dir="${dir}/.github" />
23+
<delete dir="${dir}/.vscode" />
2324
<delete file="${dir}/.gitignore" />
2425
<delete file="${dir}/.gitattributes" />
2526
<delete file="${dir}/.editorconfig" />
@@ -42,7 +43,8 @@
4243
<!-- DO NOT EDIT BELOW THIS LINE -->
4344
<property name="version" value="HEAD" override="true" />
4445
<property name="build-directory" value="build" override="true" />
45-
<property name="package-directory" value="${build-directory}/package/${vendor-name}/${extension-name}" />
46+
<property name="package-directory"
47+
value="${build-directory}/package/${vendor-name}/${extension-name}" />
4648

4749
<!-- Remove incomplete translations. -->
4850
<property name="exclude-langs" value="" override="true" />
@@ -70,7 +72,8 @@
7072
<!-- Replace invalid characters in language files -->
7173
<target name="clean-lang">
7274
<echo msg="Replacing invalid characters: ${filename}" />
73-
<exec dir="${package-directory}/language" command="sed -ri 's|'\\\\\''|’|g' ${filename}" checkreturn="true" />
75+
<exec dir="${package-directory}/language" command="sed -ri 's|'\\\\\''|’|g' ${filename}"
76+
checkreturn="true" />
7477
</target>
7578

7679
<!-- Clean up the language directory -->
@@ -120,7 +123,8 @@
120123
<equals arg1="${has-dependencies}" arg2="1" />
121124
<then>
122125
<echo msg="Installing dependencies" />
123-
<exec dir="${package-directory}" command="composer update -n --prefer-dist --no-dev" checkreturn="true" />
126+
<exec dir="${package-directory}" command="composer update -n --prefer-dist --no-dev"
127+
checkreturn="true" />
124128
</then>
125129
</if>
126130

@@ -135,25 +139,30 @@
135139
outputProperty='package-version' />
136140

137141
<phingcall target="wrap-package">
138-
<property name="destination-filename" value="${build-directory}/upload/${vendor-name}_${extension-name}_${package-version}" />
142+
<property name="destination-filename"
143+
value="${build-directory}/upload/${vendor-name}_${extension-name}_${package-version}" />
139144
</phingcall>
140145
</target>
141146

142147
<!-- Checkout a given version and install/clean the dependencies -->
143148
<target name="git-checkout">
144149
<echo msg="Getting archive for ${archive-version}" />
145150

146-
<exec command="git archive ${archive-version} --format zip --output ${build-directory}/checkout/${archive-version}.zip"
151+
<exec
152+
command="git archive ${archive-version} --format zip --output ${build-directory}/checkout/${archive-version}.zip"
147153
checkreturn="true" />
148-
<unzip file="${build-directory}/checkout/${archive-version}.zip" todir="${package-directory}" />
154+
<unzip file="${build-directory}/checkout/${archive-version}.zip"
155+
todir="${package-directory}" />
149156
</target>
150157

151158
<!-- Create the zip and tar ball -->
152159
<target name="wrap-package">
153160
<echo msg="Creating archives (${vendor-name}/${extension-name} ${version})" />
154161
<zip basedir="${build-directory}/package/" destfile="${destination-filename}.zip" />
155-
<tar basedir="${build-directory}/package/" destfile="${destination-filename}.tar.gz" compression="gzip" />
156-
<tar basedir="${build-directory}/package/" destfile="${destination-filename}.tar.bz2" compression="bzip2" />
162+
<tar basedir="${build-directory}/package/" destfile="${destination-filename}.tar.gz"
163+
compression="gzip" />
164+
<tar basedir="${build-directory}/package/" destfile="${destination-filename}.tar.bz2"
165+
compression="bzip2" />
157166

158167
<echo msg="Generating checksums" />
159168
<manifest checksum="sha512" file="${build-directory}/upload/checksums.sha512">
@@ -164,4 +173,4 @@
164173
</fileset>
165174
</manifest>
166175
</target>
167-
</project>
176+
</project>

config/services.yml

+1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ services:
3333
- '@upload_imagesize'
3434
- '%core.root_path%'
3535
- '%core.php_ext%'
36+
- '%tables.users%'
3637
- '%tables.posts%'
3738
- '%tables.attachments%'

event/listener.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -96,30 +96,28 @@ public function viewtopic($event)
9696
$first_post_id = $event['topic_data']['topic_first_post_id'];
9797
$post_id = $first_post_id;
9898
$data['title'] = $event['topic_data']['topic_title'];
99-
$data['author'] = $event['topic_data']['topic_first_poster_name'];
99+
$data['author'] = $this->helper->extract_author($event['topic_data']['topic_first_poster_name'], $event['topic_data']['topic_poster']);
100100
$data['published_time'] = (int) $event['topic_data']['topic_time'];
101101
$data['section'] = $event['topic_data']['forum_name'];
102102

103103
// Extract description
104104
if ($this->helper->check_replies() && $this->helper->is_reply($event['post_list'], $first_post_id, $post_id))
105105
{
106106
$data['description'] = $this->helper->extract_description($post_id);
107+
$data['author'] = $this->helper->extract_author(null, null, $post_id);
107108
}
108109
else if ((int) $event['start'] > 0)
109110
{
110111
$data['description'] = $this->helper->extract_description($first_post_id);
112+
$data['author'] = $this->helper->extract_author(null, null, $first_post_id);
111113
}
112114
else if (!empty($event['rowset'][$first_post_id]['post_text']))
113115
{
114116
$data['description'] = $event['rowset'][$first_post_id]['post_text'];
115117
}
116118

117119
// Extract image
118-
$data['image'] = $this->helper->extract_image(
119-
$data['description'],
120-
$post_id,
121-
$event['topic_data']['forum_id']
122-
);
120+
$data['image'] = $this->helper->extract_image($data['description'], $post_id, $event['topic_data']['forum_id']);
123121

124122
$this->helper->set_metadata($data);
125123
}

includes/helper.php

+89-12
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class helper
9595
*
9696
* @return void
9797
*/
98-
public function __construct(database $db, config $config, user $user, request $request, template $template, language $language, filesystem $filesystem, cache $cache, controller_helper $controller_helper, dispatcher $dispatcher, FastImageSize $imagesize, $root_path, $php_ext, $posts_table, $attachments_table)
98+
public function __construct(database $db, config $config, user $user, request $request, template $template, language $language, filesystem $filesystem, cache $cache, controller_helper $controller_helper, dispatcher $dispatcher, FastImageSize $imagesize, $root_path, $php_ext, $users_table, $posts_table, $attachments_table)
9999
{
100100
$this->db = $db;
101101
$this->config = $config;
@@ -116,6 +116,7 @@ public function __construct(database $db, config $config, user $user, request $r
116116
if (empty($this->tables))
117117
{
118118
$this->tables = [
119+
'users' => $users_table,
119120
'posts' => $posts_table,
120121
'attachments' => $attachments_table
121122
];
@@ -170,6 +171,7 @@ public function set_metadata($data = [])
170171
'og:image:type' => $default['image']['type'],
171172
'og:image:width' => $default['image']['width'],
172173
'og:image:height' => $default['image']['height'],
174+
'article:author' => '',
173175
'article:published_time' => '',
174176
'article:section' => '',
175177
'article:publisher' => trim($this->config['seo_metadata_facebook_publisher'])
@@ -184,7 +186,8 @@ public function set_metadata($data = [])
184186
'image' => $default['image']['url'],
185187
'author' => [
186188
'@type' => 'Person',
187-
'name' => ''
189+
'name' => '',
190+
'url' => ''
188191
],
189192
'datePublished' => '',
190193
'articleSection' => '',
@@ -281,7 +284,16 @@ public function set_metadata($data = [])
281284
break;
282285

283286
case 'author':
284-
$this->metadata['json_ld']['author']['name'] = $value;
287+
if (isset($value['name']))
288+
{
289+
$this->metadata['open_graph']['article:author'] = $value['name'];
290+
$this->metadata['json_ld']['author']['name'] = $value['name'];
291+
}
292+
293+
if (isset($value['url']))
294+
{
295+
$this->metadata['json_ld']['author']['url'] = $value['url'];
296+
}
285297
break;
286298
}
287299
}
@@ -333,6 +345,7 @@ public function metadata_template_vars()
333345
if ($data['open_graph']['og:type'] !== 'article')
334346
{
335347
unset(
348+
$data['open_graph']['article:author'],
336349
$data['open_graph']['article:published_time'],
337350
$data['open_graph']['article:section'],
338351
$data['open_graph']['article:publisher']
@@ -600,11 +613,7 @@ public function clean_image($uri = '', $images_dir = true)
600613
}
601614

602615
// Absolute URL
603-
$url = sprintf(
604-
'%s/%s',
605-
generate_board_url(),
606-
$image_path
607-
);
616+
$url = sprintf('%s/%s', generate_board_url(), $image_path);
608617

609618
return $url;
610619
}
@@ -830,7 +839,8 @@ public function extract_image($description = '', $post_id = 0, $forum_id = 0)
830839
}
831840
}
832841

833-
if (in_array($url, $images)) {
842+
if (in_array($url, $images))
843+
{
834844
continue;
835845
}
836846

@@ -1263,9 +1273,7 @@ public function is_reply($post_list = [], $first_post_id = 0, &$post_id = 0)
12631273
// Get post ID
12641274
$pid = $this->request->variable('p', 0);
12651275

1266-
$is_reply = !empty($pid) &&
1267-
in_array($pid, $post_list, true) &&
1268-
$pid !== $first_post_id;
1276+
$is_reply = !empty($pid) && in_array($pid, $post_list, true) && $pid !== $first_post_id;
12691277

12701278
// Update post ID
12711279
if ($is_reply)
@@ -1343,4 +1351,73 @@ public function filter_empty_items($data = [], $depth = 0)
13431351
// Return a copy
13441352
return $data;
13451353
}
1354+
1355+
/**
1356+
* Generate URL for user profile.
1357+
*
1358+
* @param integer $id
1359+
*
1360+
* @return string
1361+
*/
1362+
public function generate_user_url($id = 0)
1363+
{
1364+
$id = (int) $id;
1365+
1366+
if (empty($id))
1367+
{
1368+
return '';
1369+
}
1370+
1371+
return sprintf('%s/memberlist.%s?mode=viewprofile&u=%d', generate_board_url(), $this->php_ext, $id);
1372+
}
1373+
1374+
/**
1375+
* Generate author data from topic or post data.
1376+
*
1377+
* @param string $name
1378+
* @param integer $id
1379+
* @param integer $post_id
1380+
*
1381+
* @return array
1382+
*/
1383+
public function extract_author($name = '', $id = 0, $post_id = 0)
1384+
{
1385+
$id = (int) $id;
1386+
$post_id = (int) $post_id;
1387+
1388+
$data = [
1389+
'name' => $name,
1390+
'url' => $this->generate_user_url($id)
1391+
];
1392+
1393+
if (empty($post_id))
1394+
{
1395+
return $data;
1396+
}
1397+
1398+
$sql_array = [
1399+
'SELECT' => 'u.user_id, u.username',
1400+
'FROM' => [$this->tables['users'] => 'u'],
1401+
'LEFT_JOIN' => [
1402+
[
1403+
'FROM' => [$this->tables['posts'] => 'p'],
1404+
'ON' => 'p.poster_id = u.user_id'
1405+
]
1406+
],
1407+
'WHERE' => 'p.post_id = ' . $post_id
1408+
];
1409+
1410+
$sql = $this->db->sql_build_query('SELECT', $sql_array);
1411+
// Cache query for 24 hours
1412+
$result = $this->db->sql_query($sql, (24 * 60 * 60));
1413+
$user = $this->db->sql_fetchrow($result);
1414+
$this->db->sql_freeresult($result);
1415+
1416+
$data = [
1417+
'name' => $user['username'],
1418+
'url' => $this->generate_user_url($user['user_id'])
1419+
];
1420+
1421+
return $data;
1422+
}
13461423
}

tests/functional/seometadata_test.php

+9
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function test_open_graph()
5353
'image'
5454
],
5555
'article' => [
56+
'author',
5657
'published_time',
5758
'section'
5859
]
@@ -104,6 +105,10 @@ public function test_open_graph()
104105
'http://localhost/images/default_image.jpg',
105106
$elements['image']->attr('content')
106107
);
108+
$this->assertSame(
109+
'admin',
110+
$elements['author']->attr('content')
111+
);
107112
$this->assertSame(
108113
1,
109114
preg_match(
@@ -229,6 +234,10 @@ public function test_json_ld()
229234
'admin',
230235
$elements['author']['name']
231236
);
237+
$this->assertSame(
238+
'http://localhost/memberlist.php?mode=viewprofile&u=2',
239+
$elements['author']['url']
240+
);
232241
$this->assertSame(
233242
1,
234243
preg_match(

0 commit comments

Comments
 (0)