Author Topic: [developing] Notifications & User Activity v0.1  (Read 30188 times)

0 Members and 1 Guest are viewing this topic.

Offline trez

  • Hero Member
  • *****
  • Posts: 613
    • View Profile
    • blog / photography
[developing] Notifications & User Activity v0.1
« on: October 30, 2011, 07:49:28 PM »
Okay, I think the name of the MOD speaks for itself. I wasn't considering sharing it since I worked a lot on it, but since I love the 4images community I decided to share it and develop it further.
Please keep in mind that this is v0.1 of the MOD - I will release v0.2 soon (after getting some feedback of you).


WHAT

This MOD created something like the notification feed on facebook. If user A comments, votes or add's a photo of user B, user B will get notifications (on the site, not by mail).
A "New Notifications" - count is displayed in the user login info, showng your unseen notifications. After you click on it (and see your new notifications) this number is being reset
(like on facebook) automatically - you don't have to click on anything to mark a notification as read (unlike other similar mod's to mine) . You can browse old notifications.
Please see attached screen-shots to get a feeling (at the end of this topic) (last screenshot is how it can look like with a little customization).

This MOD put's everything that happens to your user's pictures into one place.




WARNING
1) This is the first release - I tested it, but it can contain bug's . Please post if you have any problems, I tested it with 4images 1.7.10 and PHP5.
2) I didn't use language tags, because I am too lazy to do it. If you want to use language tags you can add them yourself.
3) This MOD won't work properly with guests (at least I didn't test it)
4) The MOD assumes that all your userpic files are "*.jpg" - please check your upload settngs (for userpic) and don't allow other file types (only for userpicture)


NEEDED MODS

This MOD supposes you installed V@no's [MOD] Member personal photo v1.1.3. If you want to use my MOD without it with, you can, but it just looks better with it.

Please make sure that you did the step's required to add default user-image, if no user-image is uploaded (otherwise you'll get broken images)


NOTE
The way I did this MOD is certainly not perfect, but it works for the purpose of my website. Please be patient for the User Activity Feed, as of right now I am only uploading the Notification part.


FIXES

31.10.2011 - fixed comment formatting, please do STEP 9  
31.10.2011 - fixed getting notifications when commenting on own pictures, please redo STEP 4 (code updated).  






==================================================================

Okay, be sure to make a backup of your database and your files that are being changed.


STEP 1

run this query in your php-my-admin:

Code: [Select]
CREATE TABLE IF NOT EXISTS `4images_notifications` (
  `id` int(12) unsigned NOT NULL AUTO_INCREMENT,
  `from_id` int(10) unsigned NOT NULL DEFAULT '0',
  `to_id` int(10) unsigned NOT NULL DEFAULT '0',
  `from_username` varchar(255) NOT NULL,
  `to_username` varchar(255) NOT NULL,
  `what_pic` varchar(255) NOT NULL,
  `text1` varchar(255) NOT NULL,
  `text2` varchar(255) NOT NULL,
  `text3` varchar(255) NOT NULL,
  `content` text NOT NULL,
  `content_link` varchar(255) NOT NULL,
  `date` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `from_id` (`from_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;



then, run this sql in your php-my-admin:

Code: [Select]
ALTER TABLE `4images_users` ADD `user_notify` int(10) NOT NULL DEFAULT '0'



==================================================================

STEP 2

open includes/constants.php

find:
Code: [Select]
define('WORDMATCH_TABLE', $table_prefix.'wordmatch');

add below
Code: [Select]
define('NOTIFY_TABLE', $table_prefix.'notifications');


==================================================================

STEP 3

open includes/functions.php


//including FAVORITES (LIGHTBOX) to be shown

find:
Code: [Select]
if (!in_array($id, $lightbox_array)) {

add below:
Code: [Select]

//activity
    $sql = "SELECT cat_id,image_media_file,image_name, image_id, user_id
          FROM ".IMAGES_TABLE."
          WHERE image_active = 1 AND image_id = $id";
 $result = $site_db->query_firstrow($sql);
 $cat = $result['cat_id'];
          $media = $result['image_media_file'];
          $name = $result['image_name'];
 $image_id = $result['image_id'];
 $user_id = $result['user_id'];

        $sql = "INSERT INTO " . NOTIFY_TABLE . "
        (id, from_id, to_id, from_username, to_username, what_pic, text1, text2, text3, content, content_link, date)
        VALUES(NULL, '".$user_info['user_id']."', '" . $user_id . "', '".$user_info['user_name']."', '', '".$cat."' '/' '".$media."', 'added', '".$name."', 'as a favourite', '', 'details.php?image_id=' '".$image_id."', '" . time() . "')";
   $site_db->query($sql);


$sql = "UPDATE ".USERS_TABLE."
SET user_notify=user_notify+1 WHERE user_id = ".$user_id;
$site_db->query($sql);
//activity


//now we are including the rating to be shown


find:
Code: [Select]
function update_image_rating($image_id, $rating) {
  global $site_db;
  $sql = "SELECT cat_id, image_votes, image_rating


replace with:
Code: [Select]
function update_image_rating($image_id, $rating) {
  global $site_db, $user_info;
  $sql = "SELECT cat_id, image_votes, image_rating, user_id, image_media_file, image_name, image_id


find:
    
Code: [Select]
$new_rating = sprintf("%.2f", $new_rating);
insert below:
Code: [Select]
$rating_value = $rating;

find:

Code: [Select]
   $sql = "UPDATE ".IMAGES_TABLE."
            SET image_votes = ($old_votes + 1), image_rating = '$new_rating'
            WHERE image_id = $image_id";
    $site_db->query($sql);



add below:
Code: [Select]

//activity
 $cat = $image_row['cat_id'];
 $to_id = $image_row['user_id'];
          $media = $image_row['image_media_file'];
          $name = $image_row['image_name'];
 $image_id = $image_row['image_id'];
 $user_name = $user_info['user_name'];

$sql = "UPDATE ".USERS_TABLE."
SET user_notify=user_notify+1 WHERE user_id = ".$to_id;
$site_db->query($sql);  

   $sql = "INSERT INTO " . NOTIFY_TABLE . "
        (id, from_id, to_id, from_username, to_username, what_pic, text1, text2, text3, content, content_link, date)
        VALUES(NULL, '".$user_info['user_id']."', '$to_id', '$user_name', '0', '".$cat."' '/' '".$media."' , 'rated', '".$name."', 'with' ' ' '<b>' '$rating_value' '</b>' , '', 'details.php?image_id=' '".$image_id."', '" . time() . "')";
   $site_db->query($sql);
 //activity



==================================================================

STEP 4

open details.php (or ajaxcomments.php if you installed THIS MOD)

find:
Code: [Select]
update_comment_count($id, $user_info['user_id']);

add below:

Code: [Select]

 //activity
    $sql = "SELECT cat_id,image_media_file,image_name, image_id, user_id
          FROM ".IMAGES_TABLE."
          WHERE image_active = 1 AND image_id = $id";
 $result = $site_db->query_firstrow($sql);
 $cat = $result['cat_id'];
 $to_id = $result['user_id'];
          $media = $result['image_media_file'];
          $name = $result['image_name'];
 $image_id = $result['image_id'];

if ($user_info['user_id'] != $result['user_id']) {    
 
$sql = "UPDATE ".USERS_TABLE."
SET user_notify=user_notify+1 WHERE user_id = ".$to_id;
$site_db->query($sql);  
 
   $sql = "INSERT INTO " . NOTIFY_TABLE . "
        (id, from_id, to_id, from_username, to_username, what_pic, text1, text2, text3, content, content_link, date)
        VALUES(NULL, '".$user_info['user_id']."', '$to_id','$user_name', '0', '".$cat."' '/' '".$media."' , 'commented', '".$name."', '', '$comment_text', 'details.php?image_id=' '".$image_id."', '" . time() . "')";
   $site_db->query($sql);

}

 //activity



==================================================================

STEP 5

open includes/page_header.php

find:
 
Code: [Select]
"rss_url" => "",
add below:
Code: [Select]
"sess_user_notify" => $user_info['user_notify'],


==================================================================

STEP 6

open your_template/header.html


find:
Code: [Select]
» <a href="{url_control_panel}">{lang_control_panel}</a><br />
add below:

Code: [Select]
» Notifications <a href="notifications.php?action=new">{sess_user_notify}</a><br />


==================================================================

STEP 7

Upload notifications.php to your 4images root folder
Upload member_notifications.html, member_notifications_bit.html and member_notifications_new.html to your 4images template folder

Files are attached to this post.



==================================================================

STEP 8
Do some testing. If everything works (yeah, it will) start customizing the *.html files to your personal design.



---------------------------------------------------------------------------------------

STEP 9 - FIXES

a - fix comment formatting (bbcode etc).
open notifications.php and find:

Code: [Select]
"content" => $content,

replace with:
Code: [Select]
"comment_text" => format_text($comment_row[$i]['comment_text'], $config['html_comments'], $config['wordwrap_comments'], $config['bb_comments'], $config['bb_img_comments']),

---------------------------------------------------------------------------------------



PLANNED FOR V0.2
- icons for each different notification
- activity wall
- paging for old notifications
- fix own notifications (when commenting own image) --- DONE
- support for guestbooks and various other MOD's



« Last Edit: October 31, 2011, 01:58:23 PM by trez »

Offline Loda

  • Sr. Member
  • ****
  • Posts: 353
    • View Profile
    • Fotosucht Schweiz
Re: [MOD] Notifications & User Activity v0.1
« Reply #1 on: October 31, 2011, 11:25:28 AM »
A little error on my site...
the thumb in the notification is broken..only you added an image in the lightbox.
other activities works fine
i'm not sure.. i've installed the multilightbox mod
it's the tag : {what_pic}
i don't know why..
« Last Edit: October 31, 2011, 11:36:22 AM by Loda »

Offline trez

  • Hero Member
  • *****
  • Posts: 613
    • View Profile
    • blog / photography
Re: [MOD] Notifications & User Activity v0.1
« Reply #2 on: October 31, 2011, 11:34:51 AM »
A little error on my site...
the thumb in the notification is broken..
it's the tag : {what_pic}
i don't know why..

are your files stored in the default folder from the userpic mod, and is the file a JPG ? Your userpics have to look like this:
http://yourdomain.com/4images/data/userpic/1.jpg

PS: The MOD assumes that all your userpic's are "*.jpg" files. If needed just convert them, and forbid uploading of other files than jpg - at least I did it so.


Offline Loda

  • Sr. Member
  • ****
  • Posts: 353
    • View Profile
    • Fotosucht Schweiz
Re: [MOD] Notifications & User Activity v0.1
« Reply #3 on: October 31, 2011, 11:37:06 AM »
upps.. i've update my first posting.. sorry..  :oops:

Offline trez

  • Hero Member
  • *****
  • Posts: 613
    • View Profile
    • blog / photography
Re: [MOD] Notifications & User Activity v0.1
« Reply #4 on: October 31, 2011, 11:41:41 AM »
Please give me a link to your Mulilightbox MOD, so I can see if I can solve your problem (there are many MOD's).

Offline Loda

  • Sr. Member
  • ****
  • Posts: 353
    • View Profile
    • Fotosucht Schweiz
Re: [MOD] Notifications & User Activity v0.1
« Reply #5 on: October 31, 2011, 11:47:07 AM »
ok
http://www.4homepages.de/forum/index.php?topic=10625.0
it doesn't matter if it will not work..

Offline trez

  • Hero Member
  • *****
  • Posts: 613
    • View Profile
    • blog / photography
Re: [developing] Notifications & User Activity v0.1
« Reply #6 on: October 31, 2011, 11:52:16 AM »
Did you install also [MOD] Lightbox for GUESTs v1.2 MOD ? And what version of 4images are you using?

Offline Loda

  • Sr. Member
  • ****
  • Posts: 353
    • View Profile
    • Fotosucht Schweiz
Re: [developing] Notifications & User Activity v0.1
« Reply #7 on: October 31, 2011, 03:20:56 PM »
hy,
no.. and my version is 1.7.10
don't spend so much time for me.. it's only a little mistake and i can live with this.

Offline Loda

  • Sr. Member
  • ****
  • Posts: 353
    • View Profile
    • Fotosucht Schweiz
Re: [developing] Notifications & User Activity v0.1
« Reply #8 on: November 01, 2011, 10:41:34 PM »
hi again...
i think the browser isthe problem..
i see all images with firefox, no image with IE 8, and sometimes images with crome..

Offline trez

  • Hero Member
  • *****
  • Posts: 613
    • View Profile
    • blog / photography
Re: [developing] Notifications & User Activity v0.1
« Reply #9 on: November 01, 2011, 11:16:26 PM »
Please PM  me a link with test account to your site so I can have a look at it

Offline trez

  • Hero Member
  • *****
  • Posts: 613
    • View Profile
    • blog / photography
Re: [developing] Notifications & User Activity v0.1
« Reply #10 on: November 08, 2011, 08:03:47 PM »
Still working on some modifications to make it better. I see that another two people downloaded the files - please give me a little feedback if everything works, do't just leech the files and say nothing (!)

Offline mariano

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: [developing] Notifications & User Activity v0.1
« Reply #11 on: November 12, 2011, 05:48:02 PM »
Great mod Trez!!!!! I installed on my site and works like a charm. Im waiting for your site on line, i think it will be great.

May be Loda have the same litle problem that I have: in member_notifications_bit.html the values width and eight for the image are missing.
« Last Edit: November 12, 2011, 06:03:09 PM by mariano »

Offline Loda

  • Sr. Member
  • ****
  • Posts: 353
    • View Profile
    • Fotosucht Schweiz
Re: [developing] Notifications & User Activity v0.1
« Reply #12 on: November 12, 2011, 10:06:43 PM »
hi,
another little problem..
if the image name is e.g. "shop's" the activity are not save in the database..
anybody else here with the same problem?
Thanks Loda

Offline trez

  • Hero Member
  • *****
  • Posts: 613
    • View Profile
    • blog / photography
Re: [developing] Notifications & User Activity v0.1
« Reply #13 on: November 12, 2011, 10:09:50 PM »
hi,
another little problem..
if the image name is e.g. "shop's" the activity are not save in the database..
anybody else here with the same problem?
Thanks Loda


I will fix that tomorrow, thanks for pointing it out. have to use "stripslashes()" more often ;)

Rembrandt

  • Guest
Re: [developing] Notifications & User Activity v0.1
« Reply #14 on: November 13, 2011, 04:50:46 AM »
...another little problem..
if the image name is e.g. "shop's" the activity are not save in the database..
anybody else here with the same problem?
...

try this http://www.4homepages.de/forum/index.php?topic=29950.msg158671#msg158671

mfg Andi