aboutsummaryrefslogtreecommitdiff
path: root/src/java/com/juick
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/juick')
-rw-r--r--src/java/com/juick/Message.java171
-rw-r--r--src/java/com/juick/Tag.java35
-rw-r--r--src/java/com/juick/User.java53
-rw-r--r--src/java/com/juick/http/www/Main.java39
-rw-r--r--src/java/com/juick/http/www/RSS.java113
-rw-r--r--src/java/com/juick/http/www/Reader.java111
-rw-r--r--src/java/com/juick/http/www/Utils.java1
7 files changed, 395 insertions, 128 deletions
diff --git a/src/java/com/juick/Message.java b/src/java/com/juick/Message.java
new file mode 100644
index 00000000..65c9c015
--- /dev/null
+++ b/src/java/com/juick/Message.java
@@ -0,0 +1,171 @@
+/*
+ * Juick
+ * Copyright (C) 2008-2011, Ugnich Anton
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.juick;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+
+/**
+ *
+ * @author Ugnich Anton
+ */
+public class Message {
+
+ public int MID = 0;
+ public int RID = 0;
+ public int ReplyTo = 0;
+ public String Text = null;
+ public User User = null;
+ public ArrayList<String> Tags = new ArrayList<String>();
+ public Date Timestamp = null;
+ public String TimestampString = null;
+ public int TimeAgo = 0;
+ public int Privacy = 1;
+ public boolean FriendsOnly = false;
+ public boolean ReadOnly = false;
+ public boolean Hidden = false;
+ public boolean VisitorCanComment = true;
+ public int Replies = 0;
+ public String RepliesBy = null;
+ public String AttachmentType = null;
+ public String Photo = null;
+ public String Video = null;
+ public int Likes = 0;
+ public boolean UserLike = false;
+ public ArrayList<Message> childs = new ArrayList<Message>();
+
+ public Message() {
+ }
+
+ public Message(Message msg) {
+ MID = msg.MID;
+ RID = msg.RID;
+ ReplyTo = msg.ReplyTo;
+ Text = msg.Text;
+ User = msg.User;
+ Tags = msg.Tags;
+ Timestamp = msg.Timestamp;
+ TimestampString = msg.TimestampString;
+ TimeAgo = msg.TimeAgo;
+ Privacy = msg.Privacy;
+ FriendsOnly = msg.FriendsOnly;
+ ReadOnly = msg.ReadOnly;
+ Hidden = msg.Hidden;
+ Replies = msg.Replies;
+ AttachmentType = msg.AttachmentType;
+ Photo = msg.Photo;
+ Video = msg.Video;
+ Likes = msg.Likes;
+ UserLike = msg.UserLike;
+ childs = msg.childs;
+ }
+
+ public void parseTags(String strTags) {
+ Tags.addAll(Arrays.asList(strTags.split(" ")));
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof Message)) {
+ return false;
+ }
+ Message jmsg = (Message) obj;
+ return (this.MID == jmsg.MID && this.RID == jmsg.RID);
+ }
+
+ public int compareTo(Object obj) throws ClassCastException {
+ if (!(obj instanceof Message)) {
+ throw new ClassCastException();
+ }
+ Message jmsg = (Message) obj;
+
+ if (this.MID != jmsg.MID) {
+ if (this.MID > jmsg.MID) {
+ return -1;
+ } else {
+ return 1;
+ }
+ }
+
+ if (this.RID != jmsg.RID) {
+ if (this.RID < jmsg.RID) {
+ return -1;
+ } else {
+ return 1;
+ }
+ }
+
+ return 0;
+ }
+
+ public int getChildsCount() {
+ int cnt = childs.size();
+ for (int i = 0; i < childs.size(); i++) {
+ cnt += childs.get(i).getChildsCount();
+ }
+ return cnt;
+ }
+
+ public void cleanupChilds() {
+ if (!childs.isEmpty()) {
+ for (int i = 0; i < childs.size(); i++) {
+ childs.get(i).cleanupChilds();
+ }
+ childs.clear();
+ }
+ }
+
+ public String getAttachmentURL() {
+ if (AttachmentType != null) {
+ String url = "http://i.juick.com/";
+ url += AttachmentType.equals("mp4") ? "video" : "photos-1024";
+ url += "/" + MID;
+ if (RID > 0) {
+ url += "-" + RID;
+ }
+ url += "." + AttachmentType;
+ return url;
+ } else {
+ return null;
+ }
+ }
+
+ public String getTagsString() {
+ String ret = "";
+ for (int i = 0; i < Tags.size(); i++) {
+ ret += " *" + Tags.get(i);
+ }
+ if (FriendsOnly) {
+ ret += " *friends";
+ }
+ if (Privacy == -2) {
+ ret += " *private";
+ }
+ if (Privacy == -1) {
+ ret += " *friends";
+ }
+ if (Privacy == 2) {
+ ret += " *public";
+ }
+ if (ReadOnly) {
+ ret += " *readonly";
+ }
+ return ret;
+ }
+}
diff --git a/src/java/com/juick/Tag.java b/src/java/com/juick/Tag.java
new file mode 100644
index 00000000..3cee3358
--- /dev/null
+++ b/src/java/com/juick/Tag.java
@@ -0,0 +1,35 @@
+/*
+ * Juick
+ * Copyright (C) 2008-2011, Ugnich Anton
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.juick;
+
+/**
+ *
+ * @author Ugnich Anton
+ */
+public class Tag implements Comparable<Tag> {
+
+ public String Name = null;
+ public int TID = 0;
+ public int SynonymID = 0;
+ public int UsageCnt = 0;
+
+ @Override
+ public int compareTo(Tag o) {
+ return this.Name.compareTo(o.Name);
+ }
+}
diff --git a/src/java/com/juick/User.java b/src/java/com/juick/User.java
new file mode 100644
index 00000000..e3fc0ae7
--- /dev/null
+++ b/src/java/com/juick/User.java
@@ -0,0 +1,53 @@
+/*
+ * Juick
+ * Copyright (C) 2008-2011, Ugnich Anton
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.juick;
+
+/**
+ *
+ * @author Ugnich Anton
+ */
+public class User {
+
+ public int UID = 0;
+ public String UName = null;
+ public Object Avatar = null;
+ public String FullName = null;
+ public String JID = null;
+ public int MessagesCount = 0;
+ public String AuthHash = null;
+ public boolean Banned = false;
+
+ public User() {
+ }
+
+ public User(User u) {
+ UID = u.UID;
+ UName = u.UName;
+ Avatar = u.Avatar;
+ FullName = u.FullName;
+ JID = u.JID;
+ MessagesCount = u.MessagesCount;
+ AuthHash = u.AuthHash;
+ Banned = u.Banned;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return (obj instanceof User && ((User) obj).UID == this.UID);
+ }
+}
diff --git a/src/java/com/juick/http/www/Main.java b/src/java/com/juick/http/www/Main.java
index 0fe93173..56aa439f 100644
--- a/src/java/com/juick/http/www/Main.java
+++ b/src/java/com/juick/http/www/Main.java
@@ -17,6 +17,7 @@
*/
package com.juick.http.www;
+import com.juick.server.UserQueries;
import com.juick.xmpp.JID;
import com.juick.xmpp.Stream;
import com.juick.xmpp.StreamComponent;
@@ -43,13 +44,12 @@ import ru.sape.Sape;
@WebServlet(name = "Main", urlPatterns = {"/"})
@MultipartConfig(fileSizeThreshold = 1024 * 1024, maxRequestSize = 1024 * 1024 * 10)
public class Main extends HttpServlet implements Stream.StreamListener {
-
+
Connection sql;
Connection sqlSearch;
Stream xmpp;
Home home = new Home();
Discover discover = new Discover();
- Reader reader = new Reader();
PM pm = new PM();
Login login = new Login();
Help help = new Help();
@@ -60,29 +60,30 @@ public class Main extends HttpServlet implements Stream.StreamListener {
VKontakteLogin loginVK = new VKontakteLogin();
SignUp signup = new SignUp();
Settings settings = new Settings();
-
+ RSS rss = new RSS();
+
@Override
public void init() throws ServletException {
super.init();
try {
Properties conf = new Properties();
conf.load(new FileInputStream("/etc/juick/www.conf"));
-
+
Class.forName("com.mysql.jdbc.Driver");
sql = DriverManager.getConnection("jdbc:mysql://localhost/juick?autoReconnect=true&user=" + conf.getProperty("mysql_username", "") + "&password=" + conf.getProperty("mysql_password", ""));
sqlSearch = DriverManager.getConnection("jdbc:mysql://127.0.0.1:9306?autoReconnect=true&characterEncoding=utf8&maxAllowedPacket=512000", "", "");
-
+
setupXmppComponent(conf.getProperty("xmpp_password"));
-
+
PageTemplates.sape = new Sape(conf.getProperty("sape_user"), "juick.com", 2000, 3600);
} catch (Exception e) {
log(null, e);
}
}
-
+
public void setupXmppComponent(final String password) {
Thread thr = new Thread(new Runnable() {
-
+
@Override
public void run() {
try {
@@ -97,17 +98,17 @@ public class Main extends HttpServlet implements Stream.StreamListener {
});
thr.start();
}
-
+
@Override
public void onStreamFail(String msg) {
System.err.println("XMPP STREAM FAIL: " + msg);
}
-
+
@Override
public void onStreamReady() {
System.err.println("XMPP STREAM READY");
}
-
+
@Override
public void destroy() {
super.destroy();
@@ -142,7 +143,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
request.setCharacterEncoding("UTF-8");
}
String uri = request.getRequestURI();
-
+
if (uri.equals("/")) {
String tag = request.getParameter("tag");
if (tag != null) {
@@ -151,10 +152,6 @@ public class Main extends HttpServlet implements Stream.StreamListener {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
home.doGet(sql, sqlSearch, request, response, visitor);
}
- } else if (uri.equals("/reader")) {
- reader.doGet(sql, request, response);
- } else if (uri.equals("/_out")) {
- reader.doGetOut(sql, request, response);
} else if (uri.equals("/post")) {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor != null) {
@@ -181,6 +178,14 @@ public class Main extends HttpServlet implements Stream.StreamListener {
Errors.doGet404(sql, request, response);
}
}
+ } else if (uri.startsWith("/rss/")) {
+ String uname = uri.substring(5);
+ int uid = UserQueries.getUIDbyName(sql, uname);
+ if (uid > 0) {
+ rss.doGet(sql, request, response, uid, uname);
+ } else {
+ response.sendError(404);
+ }
} else if (uri.equals("/logout")) {
login.doGetLogout(sql, request, response);
} else if (uri.equals("/settings")) {
@@ -274,7 +279,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
if (request.getCharacterEncoding() == null) {
request.setCharacterEncoding("UTF-8");
}
-
+
String uri = request.getRequestURI();
if (uri.equals("/post")) {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
diff --git a/src/java/com/juick/http/www/RSS.java b/src/java/com/juick/http/www/RSS.java
new file mode 100644
index 00000000..ab96221e
--- /dev/null
+++ b/src/java/com/juick/http/www/RSS.java
@@ -0,0 +1,113 @@
+/*
+ * Juick
+ * Copyright (C) 2008-2013, ugnich
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.juick.http.www;
+
+import com.juick.Message;
+import com.juick.server.MessagesQueries;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ * @author ugnich
+ */
+public class RSS {
+
+ private static final SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ private static final SimpleDateFormat sdfRSS = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
+
+ protected void doGet(Connection sql, HttpServletRequest request, HttpServletResponse response, int uid, String uname) throws ServletException, IOException {
+ ArrayList<Integer> mids = MessagesQueries.getUserBlog(sql, uid, 0, 0);
+ if (mids.isEmpty()) {
+ response.sendError(404);
+ return;
+ }
+
+ ArrayList<Message> msgs = MessagesQueries.getMessages(sql, mids);
+
+ response.setContentType("application/rss+xml; charset=UTF-8");
+ PrintWriter out = response.getWriter();
+ try {
+ out.println("<?xml version='1.0' encoding='utf-8'?>");
+ out.println("<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:slash='http://purl.org/rss/1.0/modules/slash/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:media='http://search.yahoo.com/mrss/' xmlns:juick='http://juick.com/'>");
+ out.println("<channel>");
+ out.println("<atom:link href='http://rss.juick.com/" + uname + "/blog' rel='self' type='application/rss+xml'/>");
+ out.println("<title>" + uname + " - Juick</title>");
+ out.println("<link>http://juick.com/" + uname + "/</link>");
+ out.println("<description>The latest messages by @" + uname + " at Juick</description>");
+ out.println("<image><url>http://i.juick.com/a/" + uid + ".png</url><title>" + uname + " - Juick</title><link>http://juick.com/" + uname + "/</link></image>");
+
+ Iterator<Message> i = msgs.iterator();
+ while (i.hasNext()) {
+ Message msg = i.next();
+
+ out.println("<item>");
+ out.println("<link>http://juick.com/" + msg.User.UName + "/" + msg.MID + "</link>");
+ out.println("<guid>http://juick.com/" + msg.User.UName + "/" + msg.MID + "</guid>");
+
+ out.print("<title><![CDATA[@" + msg.User.UName + ":");
+ if (!msg.Tags.isEmpty()) {
+ for (int n = 0; n < msg.Tags.size(); n++) {
+ out.print(" *" + msg.Tags.get(n));
+ }
+ }
+ out.println("]]></title>");
+ out.println("<description><![CDATA[" + PageTemplates.formatMessage(msg.Text) + "]]></description>");
+
+ synchronized (sdfSQL) {
+ try {
+ Date date = sdfSQL.parse(msg.TimestampString);
+ out.println("<pubDate>" + sdfRSS.format(date) + "</pubDate>");
+ } catch (Exception e) {
+ System.err.println("PARSE EXCEPTION: " + msg.TimestampString);
+ }
+ }
+
+ out.println("<comments>http://juick.com/" + msg.User.UName + "/" + msg.MID + "</comments>");
+ if (!msg.Tags.isEmpty()) {
+ for (int n = 0; n < msg.Tags.size(); n++) {
+ out.println("<category>" + msg.Tags.get(n) + "</category>");
+ }
+ }
+ if (msg.AttachmentType != null) {
+ if (msg.AttachmentType.equals("jpg")) {
+ out.println("<media:content url='http://i.juick.com/photos-1024/" + msg.MID + ".jpg' type='image/jpeg'/>");
+ out.println("<media:thumbnail url='http://i.juick.com/ps/" + msg.MID + ".jpg'/>");
+ } else if (msg.AttachmentType.equals("png")) {
+ out.println("<media:content url='http://i.juick.com/photos-1024/" + msg.MID + ".png' type='image/png'/>");
+ out.println("<media:thumbnail url='http://i.juick.com/ps/" + msg.MID + ".png'/>");
+ }
+ }
+ out.println("<juick:user uid='" + msg.User.UID + "'/>");
+ out.println("</item>");
+ }
+
+ out.println("</channel></rss>");
+ } finally {
+ out.close();
+ }
+ }
+}
diff --git a/src/java/com/juick/http/www/Reader.java b/src/java/com/juick/http/www/Reader.java
deleted file mode 100644
index 75a0e774..00000000
--- a/src/java/com/juick/http/www/Reader.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Juick
- * Copyright (C) 2008-2011, Ugnich Anton
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package com.juick.http.www;
-
-import com.juick.server.MessagesQueries;
-import com.juick.server.TagQueries;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- *
- * @author Ugnich Anton
- */
-public class Reader {
-
- protected void doGet(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
-
- response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
- String head = "<meta name=\"robots\" content=\"noindex,nofollow\"/>";
- PageTemplates.pageHead(out, "Ссылки", head);
- PageTemplates.pageNavigation(out, visitor, null);
- out.println("<section id=\"content\" style=\"width: 95%; margin-left: 15px\">");
-
- out.println("<ul id=\"readerlinks\">");
-
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try {
- stmt = sql.prepareStatement("SELECT link_id,rss_id,url,title FROM reader_links ORDER BY ts DESC LIMIT 100");
- rs = stmt.executeQuery();
- rs.beforeFirst();
- while (rs.next()) {
- out.println("<li><img src=\"//i.juick.com/rss-icons/" + rs.getInt(2) + ".png\" width=\"16\" height=\"16\"/><a href=\"" + rs.getString(3) + "\" data-lid=\""+rs.getInt(1)+"\" onmousedown=\"readerLinkReplace(this)\" rel=\"nofollow\" target=\"_blank\">" + rs.getString(4) + "</a></li>");
- }
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(rs, stmt);
- }
-
- out.println("</ul>");
-
- out.println("</section>");
- PageTemplates.pageFooter(request, out, visitor, true);
- PageTemplates.pageEnd(out);
- } finally {
- out.close();
- }
- }
-
- protected void doGetOut(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
- int lid = Utils.parseInt(request.getParameter("lid"), 0);
- if (lid == 0) {
- response.sendError(404);
- return;
- }
-
- String url = null;
-
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try {
- stmt = sql.prepareStatement("SELECT url FROM reader_links WHERE link_id=?");
- stmt.setInt(1, lid);
- rs = stmt.executeQuery();
- if (rs.first()) {
- url = rs.getString(1);
- }
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(rs, stmt);
- }
-
- if (url == null) {
- response.sendError(404);
- return;
- }
-
- Utils.sendTemporaryRedirect(response, url);
- }
-}
diff --git a/src/java/com/juick/http/www/Utils.java b/src/java/com/juick/http/www/Utils.java
index e20be893..afaf131e 100644
--- a/src/java/com/juick/http/www/Utils.java
+++ b/src/java/com/juick/http/www/Utils.java
@@ -188,6 +188,7 @@ public class Utils {
in.close();
return b.toString();
} catch (Exception e) {
+ System.err.println("fetchURL: "+e.toString());
return null;
}
}