Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,722 members, 7,820,507 topics. Date: Tuesday, 07 May 2024 at 04:10 PM

How Can I Build A Twitter like @mention System In PHP? - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / How Can I Build A Twitter like @mention System In PHP? (5789 Views)

How Can I Build An E-library For School? / Online Banking Source Code In PHP, MSQL / How Do I Build A Forum Like Nairaland? (2) (3) (4)

(1) (2) (Reply) (Go Down)

How Can I Build A Twitter like @mention System In PHP? by Nobody: 10:31pm On Oct 07, 2016
I hope I got your attention...
I'm asking not because I don't know it/I can't implement it but because I want to learn more, so I'm asking all the PHP dare-devils and e-wolves in the house to "help me work this thing out".

Note: Please, I prefer us to do more code than talking, lot's of people will also learn from this thread.

First off: My implementation on CodeIgniter was done using preg_replace (regexp) to strip out the @ and fetch the values after the '@' sign then pass it on to a controller that queries the db through a model for the value after the @ sign in my users table on the db. What I'm saying plainly is that, when you type: @FooBar, I strip off the '@' and search for any user called 'FooBar' in my users_table, If found, return a click able link to the view (front-end).
Now, how will you go about implementing yours?
Re: How Can I Build A Twitter like @mention System In PHP? by braine(m): 11:00pm On Oct 07, 2016
I'm very new to database querying, but why do you need to put the @ with the username when a user wants to search - in the search box(I guess)? The @ is supposes to be for mentioning..
Re: How Can I Build A Twitter like @mention System In PHP? by Nobody: 11:27pm On Oct 07, 2016
braine:
I'm very new to database querying, but why do you need to put the @ with the username when a user wants to search - in the search box(I guess)? The @ is supposes to be for mentioning..

Not using it in the search box, using it anywhere, comments box, reply and message boxes. Although I can also add it to the search box for a better UX.
Re: How Can I Build A Twitter like @mention System In PHP? by Kodejuice: 11:28pm On Oct 07, 2016
braine:
I'm very new to database querying, but why do you need to put the @ with the username when a user wants to search - in the search box(I guess)? The @ is supposes to be for mentioning..
WTF?!, its not a search system its a mention system
Re: How Can I Build A Twitter like @mention System In PHP? by Kodejuice: 11:34pm On Oct 07, 2016
DanielTheGeek:
I hope I got your attention...
I'm asking not because I don't know it/I can't implement it but because I want to learn more, so I'm asking all the PHP dare-devils and e-wolves in the house to "help me work this thing out".

Note: Please, I prefer us to do more code than talking, lot's of people will also learn from this thread.

First off: My implementation on CodeIgniter was done using preg_replace (regexp) to strip out the @ and fetch the values after the '@' sign then pass it on to a controller that queries the db through a model for the value after the @ sign in my users table on the db. What I'm saying plainly is that, when you type: @FooBar, I strip off the '@' and search for any user called 'FooBar' in my users_table, If found, return a click able link to the view (front-end).
Now, how will you go about implementing yours?

Your approach is fine, i can not even tink of any other now.

1 Like

Re: How Can I Build A Twitter like @mention System In PHP? by braine(m): 12:46am On Oct 08, 2016
Kodejuice:
WTF?!, its not a search system its a mention system

You could have answered without the drama. undecided

1 Like

Re: How Can I Build A Twitter like @mention System In PHP? by babatope88(m): 3:11am On Oct 08, 2016
DanielTheGeek:
I hope I got your attention...
I'm asking not because I don't know it/I can't implement it but because I want to learn more, so I'm asking all the PHP dare-devils and e-wolves in the house to "help me work this thing out".

Note: Please, I prefer us to do more code than talking, lot's of people will also learn from this thread.

First off: My implementation on CodeIgniter was done using preg_replace (regexp) to strip out the @ and fetch the values after the '@' sign then pass it on to a controller that queries the db through a model for the value after the @ sign in my users table on the db. What I'm saying plainly is that, when you type: @FooBar, I strip off the '@' and search for any user called 'FooBar' in my users_table, If found, return a click able link to the view (front-end).
Now, how will you go about implementing yours?
If I'm to do something like this, the way you explain it is the best way I can think of for now. Replace the @ symbol with URL resource and fetch.

1 Like

Re: How Can I Build A Twitter like @mention System In PHP? by FrankLampard: 7:20am On Oct 08, 2016
DanielTheGeek:
I hope I got your attention...
I'm asking not because I don't know it/I can't implement it but because I want to learn more, so I'm asking all the PHP dare-devils and e-wolves in the house to "help me work this thing out".

Note: Please, I prefer us to do more code than talking, lot's of people will also learn from this thread.

First off: My implementation on CodeIgniter was done using preg_replace (regexp) to strip out the @ and fetch the values after the '@' sign then pass it on to a controller that queries the db through a model for the value after the @ sign in my users table on the db. What I'm saying plainly is that, when you type: @FooBar, I strip off the '@' and search for any user called 'FooBar' in my users_table, If found, return a click able link to the view (front-end).
Now, how will you go about implementing yours?

Nice solution, in addition to your solution, if you want to add it in the comment system of your app just as you said in one of your comments. My solution would be thus

Create a table called maybe 'notification'
With columns as id | mention | user_id

Use preg_replace_all() to dictect for any @ mmentions, then find if that person is in your db, if yes?

Update your notification table with mention and the @someone user id.

Write some codes that will send the actual notif.

2 Likes

Re: How Can I Build A Twitter like @mention System In PHP? by Nobody: 8:23am On Oct 08, 2016
FrankLampard:


Nice solution, in addition to your solution, if you want to add it in the comment system of your app just as you said in one of your comments. My solution would be thus

Create a table called maybe 'notification'
With columns as id | mention | user_id

Use preg_replace_all() to detect for any @mentions, then find if that person is in your db, if yes?

Update your notification table with mention and the @someone user id.

Write some codes that will send the actual notif.

I've actually implemented this method, Is there any other way you suggest? Has anybody tinkered with PHP7.0 for any major project?
Re: How Can I Build A Twitter like @mention System In PHP? by Nobody: 8:28am On Oct 08, 2016
babatope88:
If I'm to do something like this, the way you explain it is the best way I can think of for now. Replace the @ symbol with URL resource and fetch.
There has to be a less horrific way to do this, I don't like tinkering with regexp in PHP, It's really ugly.
Another way I think will be to do the regexp and stripping off using JavaScript then fetch the link ASAP using AJAX but securing this stuff at the end of the day may be overkill compared to PHP's ugly regexp functions.
Re: How Can I Build A Twitter like @mention System In PHP? by FincoApps(m): 6:22am On Oct 09, 2016
op, I prefer Facebook or Nairaland way of mentioning ie Without visually seeing the '@' symbol. This is because naturally, I really dislike it when people write stuff like "@dhtml I need your help". When if you are actually speaking, you won't be like "at dhtml I need your help".

So the way I would implement this is,

When commenting, to mention a user, simply use a predefined symbol like @ or ^, and when the app detects this symbol, just like Facebook, it brings up a list of people you could mention.... Now when the user selects one of them, an additional parameter is added to the post request that would be submitted so the post request looks something like:

var mentions = [];
var user = {};
user["userid"] = userid;
user["name"] = username;
mentions.push(user) ;

Send that as an extra parameter with the original post request, and on the server, loop through the mentions array and send a notification to each of the mentioned users....

This way, you don't need to see the stupid @ symbol and also this way, you can mention users with maybe the nickname you call them in real life eg (Fincoooooooo, how u dey), but I'll still get the notification.
Re: How Can I Build A Twitter like @mention System In PHP? by Nobody: 6:40am On Oct 09, 2016
FincoApps:
op, I prefer Facebook or Nairaland way of mentioning ie Without visually seeing the '@' symbol. This is because naturally, I really dislike it when people write stuff like "@dhtml I need your help". When if you are actually speaking, you won't be like "at dhtml I need your help".

So the way I would implement this is,

When commenting, to mention a user, simply use a predefined symbol like @ or ^, and when the app detects this symbol, just like Facebook, it brings up a list of people you could mention.... Now when the user selects one of them, an additional parameter is added to the post request that would be submitted so the post request looks something like:

var mentions = [];
var user = {};
user["userid"] = userid;
user["name"] = username;
mentions.push(user) ;

Send that as an extra parameter with the original post request, and on the server, loop through the mentions array and send a notification to each of the mentioned users....

This way, you don't need to see the stupid @ symbol and also this way, you can mention users with maybe the nickname you call them in real life eg (Fincoooooooo, how u dey), but I'll still get the notification.

Rightly said man, but push() there, is that the pusher library function or your own function for explaining yourself.
Re: How Can I Build A Twitter like @mention System In PHP? by FincoApps(m): 7:24am On Oct 09, 2016
DanielTheGeek:


Rightly said man, but push() there, is that the pusher library function or your own function for explaining yourself.

No push is an array method. To push a new element to the array

1 Like

Re: How Can I Build A Twitter like @mention System In PHP? by teampregar(m): 5:15pm On Oct 10, 2016
The php equivalent for .push() is array_push(), do u knw that php has alot of amazing array functions, ie, array_count_values(), which counts frequency of values in an array it can be a useful tool if u want to calculate the number of times a unique users visits your website..
Do u also knw that php now does multi-threading?? with the pthread library..
php is gradually become a powerful language, if i were the team in maintenance of php i will change its name from php to another, then create a runtime environment for it on various machines(just like java's JVM) so that php will fully become a multi-purpose language and it won't be looked down on by others who think php is just about web..
It will be very awsome if that happens because with the easy learning curve it has it will be easy for newbies to code windows,mac and linux softwares, ios, android and windows phone native apps, wont it be cool??
Re: How Can I Build A Twitter like @mention System In PHP? by FrankLampard: 5:35pm On Oct 10, 2016
teampregar:
The php equivalent for .push() is array_push(), do u knw that php has alot of amazing array functions, ie, array_count_values(), which i counts frequency of values in an array it can be a useful tool if u want to calculate the number of times a unique users visits your website..
Do u also knw that php now does multi-threading?? with the pthread library..
php is gradually become a powerful language, if i were the team in maintenance of php i will change its name from php to another, then create a runtime environment for it on various machines(just like java's JVM) so that php will fully become a multi-purpose language and i won't be looked down on by others who think php is just about web..
It will be very awsome if that happens because with the easy learning curve it has it will be easy for newbies to code windows,mac and linux softwares, ios, android and windows phone native apps, wont it be cool??

Nice one
Re: How Can I Build A Twitter like @mention System In PHP? by cowboyemi(m): 5:39pm On Nov 12, 2016
This tutorial is helpful on HOW TO BUILD FACEBOOK LIKE MENTIONS AND HASH TAG SYSTEM USING PHP http://www.codexpresslabs.info/2016/11/how-to-build-facebook-like-mentions-and-hash-tag-using-php.html
Re: How Can I Build A Twitter like @mention System In PHP? by romme2u: 11:59pm On Nov 12, 2016
teampregar:
The php equivalent for .push() is array_push(), do u knw that php has alot of amazing array functions, ie, array_count_values(), which counts frequency of values in an array it can be a useful tool if u want to calculate the number of times a unique users visits your website..
Do u also knw that php now does multi-threading?? with the pthread library..
php is gradually become a powerful language, if i were the team in maintenance of php i will change its name from php to another, then create a runtime environment for it on various machines(just like java's JVM) so that php will fully become a multi-purpose language and it won't be looked down on by others who think php is just about web..
It will be very awsome if that happens because with the easy learning curve it has it will be easy for newbies to code windows,mac and linux softwares, ios, android and windows phone native apps, wont it be cool??

no it won't be. it would go the way of perl.

1 Like

Re: How Can I Build A Twitter like @mention System In PHP? by saintobas: 7:24pm On Nov 13, 2016
DanielTheGeek:
I hope I got your attention...
I'm asking not because I don't know it/I can't implement it but because I want to learn more, so I'm asking all the PHP dare-devils and e-wolves in the house to "help me work this thing out".

Note: Please, I prefer us to do more code than talking, lot's of people will also learn from this thread.

First off: My implementation on CodeIgniter was done using preg_replace (regexp) to strip out the @ and fetch the values after the '@' sign then pass it on to a controller that queries the db through a model for the value after the @ sign in my users table on the db. What I'm saying plainly is that, when you type: @FooBar, I strip off the '@' and search for any user called 'FooBar' in my users_table, If found, return a click able link to the view (front-end).
Now, how will you go about implementing yours?
pls i want to contact on php issue, i have sent a pm. Pls reply
Re: How Can I Build A Twitter like @mention System In PHP? by teampregar(m): 7:58am On Nov 16, 2016
romme2u:

no it won't be. it would go the way of perl.
Lolz, Y u dey wish PHP bad na..
Re: How Can I Build A Twitter like @mention System In PHP? by romme2u: 10:26am On Nov 16, 2016
teampregar:

Lolz, Y u dey wish PHP bad na..

in the late 80's, perl started as a special language with focus on text crunching and network utility displacing tcl, awk and sed. by early 90's, perl was the new bride in town with all programmers embracing it because of its uniqueness especially regular expressions which it pioneer. in the mid 90's to compete with java, more and more features were added to perl in a random and unwieldy manner to make it an all rounder, then php was born.

in the late 00's php tried unsuccessfully to handle COM objects and processes, its failures led to the birth of node.js. More applications and programmers are porting to node.js because of its unique abilities. languages excel when it is used as a tool for special and unique purposes (just take a look at JavaScript). When it becomes general purpose and heavy then the next big thing happens.

1 Like

Re: How Can I Build A Twitter like @mention System In PHP? by teampregar(m): 7:56pm On Nov 16, 2016
romme2u:


in the late 80's, perl started as a special language with focus on text crunching and network utility displacing tcl, awk and sed. by early 90's, perl was the new bride in town with all programmers embracing it because of its uniqueness especially regular expressions which it pioneer. in the mid 90's to compete with java, more and more features were added to perl in a random and unwieldy manner to make it an all rounder, then php was born.

in the late 00's php tried unsuccessfully to handle COM objects and processes, its failures led to the birth of node.js. More applications and programmers are porting to node.js because of its unique abilities. languages excel when it is used as a tool for special and unique purposes (just take a look at JavaScript). When it becomes general purpose and heavy then the next big thing happens.

But python is a general purpose language and its is still being used widely.. Or do u also thing python will soon be given a goodbye message?
Re: How Can I Build A Twitter like @mention System In PHP? by romme2u: 12:15am On Nov 17, 2016
teampregar:


But python is a general purpose language and its is still being used widely.. Or do u also thing python will soon be given a goodbye message?

the crux of the matter is in the design of the language. python, java, c# and ruby are designed to be general purpose languages hence their versatility.

when features are added to a language which changes its original design and purpose, the foundation and uniqueness of the language is destroyed.

i am tempted to give an analogy but i won't. word on the street have it that perl is very wieldy that a programmer cannot read another programmers' code without the doc.

2 Likes

Re: How Can I Build A Twitter like @mention System In PHP? by cbrass(m): 10:34am On Nov 17, 2016
I will do mine this way
$themention
$post
If(stristr($post,$themention ))
{
$content = explode("@",$post)
$content[1]
}
This is not complete sha but that's how I will do it

2 Likes

Re: How Can I Build A Twitter like @mention System In PHP? by godofbrowser(m): 11:29am On Nov 20, 2016
FincoApps:
op, I prefer Facebook or Nairaland way of mentioning ie Without visually seeing the '@' symbol. This is because naturally, I really dislike it when people write stuff like "@dhtml I need your help". When if you are actually speaking, you won't be like "at dhtml I need your help".

So the way I would implement this is,

When commenting, to mention a user, simply use a predefined symbol like @ or ^, and when the app detects this symbol, just like Facebook, it brings up a list of people you could mention.... Now when the user selects one of them, an additional parameter is added to the post request that would be submitted so the post request looks something like:

var mentions = [];
var user = {};
user["userid"] = userid;
user["name"] = username;
mentions.push(user) ;

Send that as an extra parameter with the original post request, and on the server, loop through the mentions array and send a notification to each of the mentioned users....

This way, you don't need to see the stupid @ symbol and also this way, you can mention users with maybe the nickname you call them in real life eg (Fincoooooooo, how u dey), but I'll still get the notification.

After pushing and in situations where i use the backspace key to clear the mention, is there a way to remove already pushed data from the array? you may want to consider this in the design.

I personally will go with the @ for now(API though) until a better approach is discovered. Then spice it up with a UI framework like vue.js, mithril.js or even jQuery... i don't see any security threat in this for now, so long your serverside is equally validating requests and you're also doing TOKEN verification.
Re: How Can I Build A Twitter like @mention System In PHP? by cowboyemi(m): 9:14pm On Dec 10, 2016
Take a look on how this guy implemented at mention system on his app www.thewallclone.com
Re: How Can I Build A Twitter like @mention System In PHP? by micodon(m): 9:40am On Dec 13, 2016
DanielTheGeek:
I hope I got your attention...
I'm asking not because I don't know it/I can't implement it but because I want to learn more, so I'm asking all the PHP dare-devils and e-wolves in the house to "help me work this thing out".

Note: Please, I prefer us to do more code than talking, lot's of people will also learn from this thread.

First off: My implementation on CodeIgniter was done using preg_replace (regexp) to strip out the @ and fetch the values after the '@' sign then pass it on to a controller that queries the db through a model for the value after the @ sign in my users table on the db. What I'm saying plainly is that, when you type: @FooBar, I strip off the '@' and search for any user called 'FooBar' in my users_table, If found, return a click able link to the view (front-end).
Now, how will you go about implementing yours?

Codeigniter in 2016? Naaah Bro.
Re: How Can I Build A Twitter like @mention System In PHP? by Nobody: 4:43am On Dec 19, 2016
micodon:


Codeigniter in 2016? Naaah Bro.
There's nothing wrong with using CodeIgniter especially for a small project. Shine your eyes and stop criticizing.
Re: How Can I Build A Twitter like @mention System In PHP? by micodon(m): 11:10am On Dec 19, 2016
DanielTheGeek:

There's nothing wrong with using CodeIgniter especially for a small project. Shine your eyes and stop criticizing.

if you're really shining your eyes, you'd go through the codeigniter code and see a lot of bad practices. We're living in a PHP7 era and you're hyping a framework that's trying to maintain backwards compatibility up to php5.4.

To load a class, driver or model, you'd have to do this $this->load->model('so_and_so') IN 2016 where composer autoloading is the de facto standard.

Codeigniter was my first love. Then came Lithium, and then Laravel. Bros, ditch codeigniter and go for laravel or better still create your own framework (like i did).
Re: How Can I Build A Twitter like @mention System In PHP? by Nobody: 4:25pm On Dec 20, 2016
micodon:


if you're really shining your eyes, you'd go through the codeigniter code and see a lot of bad practices. We're living in a PHP7 era and you're hyping a framework that's trying to maintain backwards compatibility up to php5.4.

To load a class, driver or model, you'd have to do this $this->load->model('so_and_so') IN 2016 where composer autoloading is the de facto standard.

Codeigniter was my first love. Then came Lithium, and then Laravel. Bros, ditch codeigniter and go for laravel or better still create your own framework (like i did).

Bro, I'm not saying I don't use other frameworks, but when i have a small project, I use CodeIgniter mainly because it's easier to setup and faster to deploy.
Re: How Can I Build A Twitter like @mention System In PHP? by cbrass(m): 2:51pm On Dec 23, 2016
DanielTheGeek:


Bro, I'm not saying I don't use other frameworks, but when i have a small project, I use CodeIgniter mainly because it's easier to setup and faster to deploy.

yes you are right, i wont use a laravel for a tiny project but will code naturally
Re: How Can I Build A Twitter like @mention System In PHP? by Nobody: 2:22pm On Dec 24, 2016
cbrass:


yes you are right, i wont use a laravel for a tiny project but will code naturally
What qualifies as a tiny project this days?

(1) (2) (Reply)

Im A Java Expert Here To Teach Those Who Wants To Learn. / . / Check In: Submit Your C++ Questions Lets Solve

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 76
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.