[3.3][RC] Autolinks 1.3.3

A place for Extension Authors to post and receive feedback on Extensions still in development. No Extensions within this forum should be used within a live environment!
Suggested Hosts
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: Extensions Development rules

IMPORTANT FOR NEEDED EVENTS!!!
If you need an event for your extension please read this for the steps to follow to request the event(s)
User avatar
pierredu
Registered User
Posts: 1111
Joined: Thu Nov 01, 2012 8:04 am
Location: Paris (France)

Re: [3.3][RC] Autolinks 1.3.3

Post by pierredu »

I just uploaded a corrected version 1.3.3 curing a problem when extracting language strings about entry errors.
andyphp82
Registered User
Posts: 17
Joined: Sat Jun 13, 2020 5:35 pm

Re: [3.3][RC] Autolinks 1.3.3

Post by andyphp82 »

Is there any way to do a mass import of words and links? I need to import about 1000 words (and their corresponding links) into Autolinks and of course I don't want to do this manually because that would be very inconvenient...
User avatar
pierredu
Registered User
Posts: 1111
Joined: Thu Nov 01, 2012 8:04 am
Location: Paris (France)

Re: [3.3][RC] Autolinks 1.3.3

Post by pierredu »

This can be done with a couple of MySQL commands. There is nothing mysterious about the table.
andyphp82
Registered User
Posts: 17
Joined: Sat Jun 13, 2020 5:35 pm

Re: [3.3][RC] Autolinks 1.3.3

Post by andyphp82 »

Could you provide some more info on how I would do this? I have 20+ years of experience in C but I don't know anything about MySQL.

I was thinking of creating a PHP script which reads the words and links from a file but how exactly would I add them to the database then?
User avatar
pierredu
Registered User
Posts: 1111
Joined: Thu Nov 01, 2012 8:04 am
Location: Paris (France)

Re: [3.3][RC] Autolinks 1.3.3

Post by pierredu »

A classical script to throw away, as Plauger would have said...
Read each line, break the line in two pieces (term and URL) and insert in the table, using following command sample:
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
Don't forget the backup first.
andyphp82
Registered User
Posts: 17
Joined: Sat Jun 13, 2020 5:35 pm

Re: [3.3][RC] Autolinks 1.3.3

Post by andyphp82 »

Thanks! This is what I've come up with so far:

Code: Select all

<?php

define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);

include($phpbb_root_path . 'common.' . $phpEx);

global $db;

$handle = fopen("links.txt", "r");

for(;;) {
	
	$word = rtrim(fgets($handle), "\r\n");
	if(empty($word)) break;
	
	$link = rtrim(fgets($handle), "\r\n");

	$sql_array = array(
		'al_word'	=> $word,
		'al_url'	=> $link
	);	
	
	$sql = 'INSERT INTO ' . $table . ' ' . $db->sql_build_array('INSERT', $sql_array);	
	$db->sql_query($sql);
}

fclose($handle);
echo "Done";

?>
Does this look right to you?

There's still one problem: How do I have to initialize $table?
User avatar
pierredu
Registered User
Posts: 1111
Joined: Thu Nov 01, 2012 8:04 am
Location: Paris (France)

Re: [3.3][RC] Autolinks 1.3.3

Post by pierredu »

You don't need to do that within the framework of phpBB. The name of the table is phpbb(3)_autolinks.
andyphp82
Registered User
Posts: 17
Joined: Sat Jun 13, 2020 5:35 pm

Re: [3.3][RC] Autolinks 1.3.3

Post by andyphp82 »

pierredu wrote:
Thu Jun 18, 2020 7:05 am
You don't need to do that within the framework of phpBB. The name of the table is phpbb(3)_autolinks.
Thanks, but when I try the following I get a syntax error:

Code: Select all

$table = 'phpbb(3)_autolinks';
$sql = 'INSERT INTO ' . $table . ' ' . $db->sql_build_array('INSERT', $sql_array);	
$db->sql_query($sql);
This is the error:

Code: Select all

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '3)_autolinks (al_word, al_url) VALUES ('foo', 'http://www.bar.com')' at line 1 [1064]
Last edited by andyphp82 on Thu Jun 18, 2020 2:14 pm, edited 1 time in total.
User avatar
warmweer
Jr. Extension Validator
Posts: 5523
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium

Re: [3.3][RC] Autolinks 1.3.3

Post by warmweer »

andyphp82 wrote:
Thu Jun 18, 2020 1:17 pm
This is the error:

Code: Select all

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '3)_autolinks (al_word, al_url) VALUES ('foo'', 'http://www.bar.com')' at line 1 [1064]
'foo'' at first sight the double '' should be a single

Check your code with a syntax highlighter (standard present in notepad++).
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.
andyphp82
Registered User
Posts: 17
Joined: Sat Jun 13, 2020 5:35 pm

Re: [3.3][RC] Autolinks 1.3.3

Post by andyphp82 »

warmweer wrote:
Thu Jun 18, 2020 1:59 pm
'foo'' at first sight the double '' should be a single
Sorry, that was just a copy & paste error. It's not the actual problem.
User avatar
pierredu
Registered User
Posts: 1111
Joined: Thu Nov 01, 2012 8:04 am
Location: Paris (France)

Re: [3.3][RC] Autolinks 1.3.3

Post by pierredu »

I had written phpbb(3)_autolinks because I don't know the exact prefix you chose.
It should be phpbb_autolinks or phpbb3_autolinks.
andyphp82
Registered User
Posts: 17
Joined: Sat Jun 13, 2020 5:35 pm

Re: [3.3][RC] Autolinks 1.3.3

Post by andyphp82 »

Thanks, now it's working! Table name was phpbb_autolinks.

I've noticed another problem, though: Autolinks doesn't seem to like parentheses in words. For example, I wanted to add an autolink for the word Math.sin() and have the link point to https://developer.mozilla.org/de/docs/W ... s/Math/sin but it doesn't work. If I remove the parentheses, everything is fine but of course I want the parentheses to be part of the autolink. Is that possible somehow?
User avatar
pierredu
Registered User
Posts: 1111
Joined: Thu Nov 01, 2012 8:04 am
Location: Paris (France)

Re: [3.3][RC] Autolinks 1.3.3

Post by pierredu »

Glad you fixed it.

Determining word boundaries is a difficult task.
I don't have a solution off the top of my head. I'm now in holidays and I can't open such a task.
andyphp82
Registered User
Posts: 17
Joined: Sat Jun 13, 2020 5:35 pm

Re: [3.3][RC] Autolinks 1.3.3

Post by andyphp82 »

Surprisingly, it's only parentheses that seem to cause problems. Adding Math.sin as a word works fine, although it has a dot in it and is essentially two words. However, as soon as I add parentheses, e.g. Math.sin() it doesn't work any longer :(
andyphp82
Registered User
Posts: 17
Joined: Sat Jun 13, 2020 5:35 pm

Re: [3.3][RC] Autolinks 1.3.3

Post by andyphp82 »

Another question: Is it possible to have Autolinks also format the text when previewing posts? Currently, the autolinks are only applied when submitting posts. They aren't visible when previewing posts. IMHO it would be nicer if autolinks were already visible when previewing posts...
Post Reply

Return to “Extensions in Development”