/** * Mark a message as read for the active Phorum user. * * @param mixed $message_ids * The message_id of the message to mark read in the active forum or an * array description of messages to mark read. Elements in this array * can be: * - Simple message_id values, to mark messages read in the active forum. * - An array containing two fields: "forum" containing a forum_id and * "id" containing a message_id. This notation can be used to mark * messages read in other forums than te active one. */ function phorum_db_newflag_add_read($message_ids) { $PHORUM = $GLOBALS['PHORUM']; // Find the number of newflags for the user $num_newflags = phorum_db_newflag_get_count(); if (!is_array($message_ids)) { $message_ids = array(0 => $message_ids); } // Delete newflags which would exceed the maximum number of // newflags that are allowed in the database per user. $num_end = $num_newflags + count($message_ids); if ($num_end > PHORUM_MAX_READ_COUNT_PER_FORUM) { phorum_db_newflag_delete($num_end - PHORUM_MAX_READ_COUNT_PER_FORUM); } // Insert newflags. $inserts = array(); foreach ($message_ids as $id => $data) { if (is_array($data)) { $user_id = $PHORUM['user']['user_id']; $forum_id = (int) $data['forum']; $message_id = (int) $data['id']; } else { $user_id = $PHORUM['user']['user_id']; $forum_id = $PHORUM['forum_id']; $message_id = (int) $data; } $values = "({$user_id},{$forum_id},{$message_id})"; $inserts[$values] = $values; } if (count($inserts)) { $inserts_str = implode(",", $inserts); // Try to insert the values. $res = phorum_db_interact(DB_RETURN_RES, "INSERT INTO {$PHORUM['user_newflags_table']}\n (user_id, forum_id, message_id)\n VALUES {$inserts_str}", NULL, DB_DUPKEYOK | DB_MASTERQUERY); // If inserting the values failed, then this most probably means // that one of the values already existed in the database, causing // a duplicate key error. In this case, fallback to one-by-one // insertion, so the other records in the list will be created. if (!$res && count($inserts) > 1) { foreach ($inserts as $values) { $res = phorum_db_interact(DB_RETURN_RES, "INSERT INTO {$PHORUM['user_newflags_table']}\n (user_id, forum_id, message_id)\n VALUES {$values}", NULL, DB_DUPKEYOK | DB_MASTERQUERY); } } } }
/** * Mark a message as read for the active Phorum user. * * @param mixed $message_ids * The message_id of the message to mark read in the active forum or an * array description of messages to mark read. Elements in this array * can be: * - Simple message_id values, to mark messages read in the active forum. * - An array containing two fields: "forum" containing a forum_id and * "id" containing a message_id. This notation can be used to mark * messages read in other forums than te active one. */ function phorum_db_newflag_add_read($message_ids) { $PHORUM = $GLOBALS['PHORUM']; // Find the number of newflags for the user $num_newflags = phorum_db_newflag_get_count(); if (!is_array($message_ids)) { $message_ids = array(0 => $message_ids); } // Delete newflags which would exceed the maximum number of // newflags that are allowed in the database per user. $num_end = $num_newflags + count($message_ids); if ($num_end > PHORUM_MAX_READ_COUNT_PER_FORUM) { phorum_db_newflag_delete($num_end - PHORUM_MAX_READ_COUNT_PER_FORUM); } // Insert newflags. foreach ($message_ids as $id => $data) { if (is_array($data)) { $user_id = $PHORUM['user']['user_id']; $forum_id = (int) $data['forum']; $message_id = (int) $data['id']; } else { $user_id = $PHORUM['user']['user_id']; $forum_id = $PHORUM['forum_id']; $message_id = (int) $data; } // We ignore duplicate record errors here. phorum_db_interact(DB_RETURN_RES, "INSERT INTO {$PHORUM['user_newflags_table']}\n (user_id, forum_id, message_id)\n VALUES ({$user_id}, {$forum_id}, {$message_id})", NULL, DB_DUPKEYOK | DB_MASTERQUERY); } }
/** * This function marks a message as read */ function phorum_db_newflag_add_read($message_ids) { $PHORUM = $GLOBALS["PHORUM"]; $num_newflags=phorum_db_newflag_get_count(); // maybe got just one message if(!is_array($message_ids)) { $message_ids=array(0=>(int)$message_ids); } // deleting messages which are too much $num_end=$num_newflags+count($message_ids); if($num_end > PHORUM_MAX_NEW_INFO) { phorum_db_newflag_delete($num_end - PHORUM_MAX_NEW_INFO); } // building the query $values=array(); $cnt=0; foreach($message_ids as $id=>$data) { if(is_array($data)) { $values[]="({$PHORUM['user']['user_id']},{$data['forum']},{$data['id']})"; } else { $values[]="({$PHORUM['user']['user_id']},{$PHORUM['forum_id']},$data)"; } $cnt++; } if($cnt) { $insert_sql="INSERT INTO ".$PHORUM['user_newflags_table']." (user_id,forum_id,message_id) VALUES".join(",",$values); // fire away $conn = phorum_db_postgresql_connect(); $res = pg_query($conn, $insert_sql); if ($err = pg_last_error()) phorum_db_pg_last_error("$err: $insert_sql"); } }