4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: trez on October 30, 2011, 07:49:28 PM

Title: [developing] Notifications & User Activity v0.1
Post by: trez 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 (http://www.4homepages.de/forum/index.php?topic=6797.0). 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 (http://www.4homepages.de/forum/index.php?topic=23866.0) 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



Title: Re: [MOD] Notifications & User Activity v0.1
Post by: Loda 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..
Title: Re: [MOD] Notifications & User Activity v0.1
Post by: trez 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.

Title: Re: [MOD] Notifications & User Activity v0.1
Post by: Loda on October 31, 2011, 11:37:06 AM
upps.. i've update my first posting.. sorry..  :oops:
Title: Re: [MOD] Notifications & User Activity v0.1
Post by: trez 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).
Title: Re: [MOD] Notifications & User Activity v0.1
Post by: Loda 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..
Title: Re: [developing] Notifications & User Activity v0.1
Post by: trez 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?
Title: Re: [developing] Notifications & User Activity v0.1
Post by: Loda 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.
Title: Re: [developing] Notifications & User Activity v0.1
Post by: Loda 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..
Title: Re: [developing] Notifications & User Activity v0.1
Post by: trez 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
Title: Re: [developing] Notifications & User Activity v0.1
Post by: trez 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 (!)
Title: Re: [developing] Notifications & User Activity v0.1
Post by: mariano 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.
Title: Re: [developing] Notifications & User Activity v0.1
Post by: Loda 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
Title: Re: [developing] Notifications & User Activity v0.1
Post by: trez 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 ;)
Title: Re: [developing] Notifications & User Activity v0.1
Post by: Rembrandt 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
Title: Re: [developing] Notifications & User Activity v0.1
Post by: Loda on November 13, 2011, 01:08:05 PM
thank you very much for your help!
This unfortunately does not solve the problem on the notification.php  :cry:
Best regards
Loda
Title: Re: [developing] Notifications & User Activity v0.1
Post by: asms on November 20, 2011, 01:32:55 PM
thx ... ^_^
i really like it
and yeah i put it in my site and its WOrk so good.. ^_^
just TO let YOu know..  :lol:
Title: Re: [developing] Notifications & User Activity v0.1
Post by: auftrip on November 20, 2011, 08:14:18 PM
what kind of data do i have to open for:
STEP 1

run this query in your php-my-admin:


I dont know where i have to input this:
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 ;


could someone help me plz
Title: Re: [developing] Notifications & User Activity v0.1
Post by: Rembrandt on November 20, 2011, 09:56:09 PM
what kind of data do i have to open for:
....

in your Database
Title: Re: [developing] Notifications & User Activity v0.1
Post by: auftrip on November 21, 2011, 04:21:43 PM
and how can i do this?
i made a new install.php and insert the things of step 1. after i opened install.php in root order but nothing happend.
i dont know what to do
Title: Re: [developing] Notifications & User Activity v0.1
Post by: Rembrandt on November 21, 2011, 05:34:46 PM
copy the install_notifi.php from the attachment in your gallery/root and call it on.

mfg Andi
Title: Re: [developing] Notifications & User Activity v0.1
Post by: auftrip on November 21, 2011, 07:18:25 PM
danke rembrandt.
jetzt hab ich noch ein prob und zwar find ich
» <a href="{url_control_panel}">{lang_control_panel}</a><br /> nicht im header.html
mein header sieht so aus. wo müsste ich dann » Notifications <a href="notifications.php?action=new">{sess_user_notify}</a><br />
einfügen?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html dir="{direction}">
<head>
<title>{prepend_head_title}{site_name}</title>
<meta http-equiv="content-type" content="text/html; charset={charset}">
<meta name="description" content="{detail_meta_description}{site_name}">
<meta name="keywords" content="{detail_meta_keywords}">
<meta name="robots" content="index,follow">
<meta name="revisit-after" content="10 days">
<meta http-equiv="imagetoolbar" content="no">
<link rel="stylesheet" href="{template_url}/style.css" type="text/css">
<link rel="shortcut icon" href="../../../images/favicon.ico">
<script language="javascript" type="text/javascript">
<!--

  var captcha_reload_count = 0;
var captcha_image_url = "{url_captcha_image}";
  function new_captcha_image() {
    if (captcha_image_url.indexOf('?') == -1) {
  document.getElementById('captcha_image').src= captcha_image_url+'?c='+captcha_reload_count;
} else {
  document.getElementById('captcha_image').src= captcha_image_url+'&c='+captcha_reload_count;
}

    document.getElementById('captcha_input').value="";
    document.getElementById('captcha_input').focus();
    captcha_reload_count++;
  }

// -->
</script>
{if has_rss}
<link rel="alternate" type="application/rss+xml" title="{rss_title}" href="{rss_url}">
{endif has_rss}
</head>
<body bgcolor="#FFFFFF" text="#0F5475" link="#0F5475" vlink="#0F5475" alink="#0F5475">
<script type="text/javascript">
SOI = (typeof(SOI) != 'undefined') ? SOI : {};(SOI.ac21fs = SOI.ac21fs || []).push(function() {
(new SOI.DateTimeService("49502871433", "DE")).setWithWeekday(false).start();});
(function() {if (typeof(SOI.scrAc21) == "undefined") { SOI.scrAc21=document.createElement('script');SOI.scrAc21.type='text/javascript'; SOI.scrAc21.async=true;SOI.scrAc21.src=((document.location.protocol == 'https:') ? 'https://' : 'http://') + 'homepage-tools.schnelle-online.info/Homepage/atomicclock2_1.js';(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(SOI.scrAc21);}})();
</script>
<script type="text/javascript">
  var framefenster = document.getElementsByTagName("iFrame");
  var auto_resize_timer = window.setInterval("autoresize_frames()", 400);
  function autoresize_frames() {
    for (var i = 0; i < framefenster.length; ++i) {
        if(framefenster[i].contentWindow.document.body){
          var framefenster_size = framefenster[i].contentWindow.document.body.offsetHeight;
          if(document.all && !window.opera) {
            framefenster_size = framefenster[i].contentWindow.document.body.scrollHeight;
          }
          framefenster[i].style.height = framefenster_size + 'px';
        }
    }
  }
</script>
Title: Re: [developing] Notifications & User Activity v0.1
Post by: Rembrandt on November 21, 2011, 07:28:41 PM
im prinzip ist es egal wo du sie rein schreibst, in die header würde ich pers. sie nicht rein schreiben.
du könntest die zeile z.b. in die user_logininfo.html schreiben.


in eigener sache:
(http://www.4homepages.de/forum/index.php?action=dlattach;topic=30282.0;attach=6722) <-- ein langer weg  :mrgreen:
Title: Re: [developing] Notifications & User Activity v0.1
Post by: auftrip on November 21, 2011, 07:50:59 PM
vielendank jetzt klapps super:)
Title: Re: [developing] Notifications & User Activity v0.1
Post by: Rembrandt on November 21, 2011, 07:56:21 PM
np  :)
Title: Re: [developing] Notifications & User Activity v0.1
Post by: auftrip on November 24, 2011, 03:43:04 PM
is it possible to include this MOD http://www.4homepages.de/forum/index.php?topic=29164.0?
 
i mean:
if person 1 loads up an image.
and person 2 writes a comment and press on the like button.
then person 3 writes a comment under the picture of person 1.
--> so only person 1 gets an notification. it would be great, that person 2 who liked the pictureand wrote a comment, gets a notification, too.

i hope you understand my bad english:)
Title: Re: [developing] Notifications & User Activity v0.1
Post by: auftrip on December 06, 2011, 07:48:13 PM
if somebody have this MOD http://www.4homepages.de/forum/index.php?topic=29164.0?
than he could inclde the like me button, too. so he get Notifications about the peolpe who liked your picture.

open details.php an serach:
    $sql = "UPDATE ".IMAGES_TABLE."
            SET image_likeme = '".$likeme.(($likeme)?",":"").$user_info['user_name']."'
            WHERE image_id = $image_id";
    $site_db->query($sql);

add after:
//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."' , 'likes', '".$name."', '' ' ' '<b>' '$rating_value' '</b>' , '', 'details.php?image_id=' '".$image_id."', '" . time() . "')";
    $site_db->query($sql);
  //activity

Title: Re: [developing] Notifications & User Activity v0.1
Post by: MrAndrew on December 19, 2011, 08:28:34 AM
I would like to offer to do the following:

When user haven`t notifications hide counter...

But when user have new notification show count with RED NUMBER i.e.

Anyone may help me with this?
Title: Re: [developing] Notifications & User Activity v0.1
Post by: V@no on December 19, 2011, 12:46:21 PM
Did you try use something like this?
Code: [Select]
{if sess_user_notify}» Notifications <a href="notifications.php?action=new">{sess_user_notify}</a><br />{endif sess_user_notify}
Title: Re: [developing] Notifications & User Activity v0.1
Post by: auftrip on December 19, 2011, 03:13:28 PM
thanks works great:)
Title: Re: [developing] Notifications & User Activity v0.1
Post by: MrAndrew on December 19, 2011, 05:16:32 PM
Thanks, really work! Need to be in the first post!  :wink:
Title: Re: [developing] Notifications & User Activity v0.1
Post by: TRAKTOR_WEB on April 29, 2013, 09:52:01 AM

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']),




Заменить на...
Code: [Select]
"content" => format_text($notify_row['content'], $config['html_comments'], $config['wordwrap_comments'], $config['bb_comments'], $config['bb_img_comments']),