Changeset e6b1457


Ignore:
Timestamp:
Sep 6, 2005 3:03:55 AM (15 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
e0e6bde
Parents:
f958342
git-author:
jrandom <jrandom> (09/06/05 03:03:55)
git-committer:
zzz <zzz@…> (09/06/05 03:03:55)
Message:

allow publishing to a remote archive automatically when posting (optionally) with 0 additional clicks
allow transparently attaching any 'public' pet names in your addressbook to a blog post (with a checkbox)

Location:
apps/syndie
Files:
1 added
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • apps/syndie/java/src/net/i2p/syndie/BlogManager.java

    rf958342 re6b1457  
    242242    }
    243243
    244     public String getDefaultProxyHost() { return _context.getProperty("syndie.defaultProxyHost", "localhost"); }
    245     public String getDefaultProxyPort() { return _context.getProperty("syndie.defaultProxyPort", "4444"); }
     244    public String getDefaultProxyHost() { return _context.getProperty("syndie.defaultProxyHost", ""); }
     245    public String getDefaultProxyPort() { return _context.getProperty("syndie.defaultProxyPort", ""); }
    246246   
    247247    public boolean authorizeAdmin(String pass) {
     
    274274            if (defaultSelector != null)
    275275                out.write("syndie.defaultSelector="+defaultSelector.trim() + "\n");
    276             if (defaultProxyHost != null)
    277                 out.write("syndie.defaultProxyHost="+defaultProxyHost.trim() + "\n");
    278276            if (defaultProxyHost != null)
    279277                out.write("syndie.defaultProxyHost="+defaultProxyHost.trim() + "\n");
     
    528526        }
    529527    }
    530    
    531    
     528
    532529    public String addAddress(User user, String name, String protocol, String location, String schema) {
    533530        if (!user.getAuthenticated()) return "Not logged in";
     
    573570   
    574571    private boolean validateAddressName(String name) {
    575         if ( (name == null) || (name.trim().length() <= 0) || (!name.endsWith(".i2p")) ) return false;
     572        if ( (name == null) || (name.trim().length() <= 0) ) return false;
    576573        for (int i = 0; i < name.length(); i++) {
    577574            char c = name.charAt(i);
     
    600597    private boolean validateAddressSchema(String schema) {
    601598        if ( (schema == null) || (schema.trim().length() <= 0) ) return false;
    602         return "eep".equals(schema) || "i2p".equals(schema);
     599        if (true) {
     600            return true;
     601        } else {
     602            return "eep".equals(schema) || "i2p".equals(schema);
     603        }
    603604    }
    604605
  • apps/syndie/java/src/net/i2p/syndie/sml/HTMLPreviewRenderer.java

    rf958342 re6b1457  
    102102                    _postBodyBuffer.append(' ').append(sanitizeString(knownName));
    103103                } else {
    104                     _postBodyBuffer.append(" <a href=\"addaddress.jsp?schema=");
    105                     _postBodyBuffer.append(sanitizeURL(a.schema)).append("&location=");
    106                     _postBodyBuffer.append(sanitizeURL(a.location)).append("&name=");
    107                     _postBodyBuffer.append(sanitizeURL(a.protocol)).append("&protocol=");
    108                     _postBodyBuffer.append(sanitizeURL(a.name));
    109                     _postBodyBuffer.append("\">").append(sanitizeString(a.name));
     104                    _postBodyBuffer.append(" <a href=\"addresses.jsp?network=");
     105                    _postBodyBuffer.append(sanitizeTagParam(a.schema)).append("&location=");
     106                    _postBodyBuffer.append(sanitizeTagParam(a.location)).append("&name=");
     107                    _postBodyBuffer.append(sanitizeTagParam(a.protocol)).append("&protocol=");
     108                    _postBodyBuffer.append(sanitizeTagParam(a.name));
     109                    _postBodyBuffer.append("\">").append(sanitizeString(a.name)).append("</a>");
    110110                }
    111111            }
  • apps/syndie/java/src/net/i2p/syndie/sml/HTMLRenderer.java

    rf958342 re6b1457  
    417417        } else {
    418418            System.err.println("Receiving address [" + location + "]");
    419             _bodyBuffer.append("<a href=\"addaddress.jsp?schema=");
    420             _bodyBuffer.append(sanitizeURL(schema)).append("&name=");
    421             _bodyBuffer.append(sanitizeURL(name)).append("&protocol=");
    422             _bodyBuffer.append(sanitizeURL(protocol)).append("&location=");
    423             _bodyBuffer.append(sanitizeURL(location)).append("\">").append(sanitizeString(anchorText)).append("</a>");
     419            _bodyBuffer.append("<a href=\"addresses.jsp?network=");
     420            _bodyBuffer.append(sanitizeTagParam(schema)).append("&name=");
     421            _bodyBuffer.append(sanitizeTagParam(name)).append("&protocol=");
     422            _bodyBuffer.append(sanitizeTagParam(protocol)).append("&location=");
     423            _bodyBuffer.append(sanitizeTagParam(location)).append("\">").append(sanitizeString(anchorText)).append("</a>");
    424424        }
    425425    }
     
    564564                        _postBodyBuffer.append(' ').append(sanitizeString(knownName));
    565565                    } else {
    566                         _postBodyBuffer.append(" <a href=\"addaddress.jsp?schema=");
    567                         _postBodyBuffer.append(sanitizeURL(a.schema)).append("&location=");
    568                         _postBodyBuffer.append(sanitizeURL(a.location)).append("&name=");
    569                         _postBodyBuffer.append(sanitizeURL(a.name)).append("&protocol=");
    570                         _postBodyBuffer.append(sanitizeURL(a.protocol));
    571                         _postBodyBuffer.append("\">").append(sanitizeString(a.name));
     566                        _postBodyBuffer.append(" <a href=\"addresses.jsp?network=");
     567                        _postBodyBuffer.append(sanitizeTagParam(a.schema)).append("&location=");
     568                        _postBodyBuffer.append(sanitizeTagParam(a.location)).append("&name=");
     569                        _postBodyBuffer.append(sanitizeTagParam(a.name)).append("&protocol=");
     570                        _postBodyBuffer.append(sanitizeTagParam(a.protocol));
     571                        _postBodyBuffer.append("\">").append(sanitizeString(a.name)).append("</a>");
    572572                    }
    573573                }
     
    625625    public void receiveHeader(String header, String value) {
    626626        //System.err.println("Receive header [" + header + "] = [" + value + "]");
    627         _headers.put(header, value);
     627        if (HEADER_PETNAME.equals(header)) {
     628            StringTokenizer tok = new StringTokenizer(value, "\t\n");
     629            if (tok.countTokens() != 4)
     630                return;
     631            String name = tok.nextToken();
     632            String net = tok.nextToken();
     633            String proto = tok.nextToken();
     634            String loc = tok.nextToken();
     635            Address a = new Address();
     636            a.name = sanitizeString(name, false);
     637            a.schema = sanitizeString(net, false);
     638            a.protocol = sanitizeString(proto, false);
     639            a.location = sanitizeString(loc, false);
     640            _addresses.add(a);
     641        } else {
     642            _headers.put(header, value);
     643        }
    628644    }
    629645   
     
    638654    public static final String HEADER_BGCOLOR = "bgcolor";
    639655    public static final String HEADER_IN_REPLY_TO = "InReplyTo";
     656    public static final String HEADER_STYLE = "Style";
     657    public static final String HEADER_PETNAME = "PetName";
    640658   
    641659    private void renderSubjectCell() {
  • apps/syndie/java/src/net/i2p/syndie/sml/RSSRenderer.java

    rf958342 re6b1457  
    251251                if (knownName == null) {
    252252                    StringBuffer url = new StringBuffer(128);
    253                     url.append("addaddress.jsp?schema=");
    254                     url.append(sanitizeURL(a.schema)).append("&location=");
    255                     url.append(sanitizeURL(a.location)).append("&name=");
    256                     url.append(sanitizeURL(a.name)).append("&protocol=");
    257                     url.append(sanitizeURL(a.protocol));
     253                    url.append("addresses.jsp?network=");
     254                    url.append(sanitizeTagParam(a.schema)).append("&location=");
     255                    url.append(sanitizeTagParam(a.location)).append("&name=");
     256                    url.append(sanitizeTagParam(a.name)).append("&protocol=");
     257                    url.append(sanitizeTagParam(a.protocol));
    258258                    out.write("    <enclosure url=\"" + urlPrefix + sanitizeXML(url) + "\" length=\"1\" type=\"text/html\" syndietype=\"address\" />\n");
    259259                }
  • apps/syndie/java/src/net/i2p/syndie/web/PostBean.java

    rf958342 re6b1457  
    1616    private String _headers;
    1717    private String _text;
     18    private String _archive;
    1819    private List _filenames;
    1920    private List _fileStreams;
     
    3132        _text = null;
    3233        _headers = null;
     34        _archive = null;
    3335        _filenames = new ArrayList();
    3436        _fileStreams = new ArrayList();
     
    5254    public void setText(String text) { _text = text; }
    5355    public void setHeaders(String headers) { _headers = headers; }
     56    public void setArchive(String archive) { _archive = archive; }
    5457   
    5558    public String getContentType(int id) {
     
    8285            localStreams.add(new FileInputStream(f));
    8386        }
    84         return BlogManager.instance().createBlogEntry(_user, _subject, _tags, _headers, _text,
    85                                                       _filenames, localStreams, _fileTypes);
     87        BlogURI uri = BlogManager.instance().createBlogEntry(_user, _subject, _tags, _headers, _text,
     88                                                             _filenames, localStreams, _fileTypes);
     89        System.err.println("Posted the entry " + uri.toString() + " (archive = " + _archive + ")");
     90        if ( (uri != null) && (_user.getAllowAccessRemote()) ) {
     91            PetName pn = _user.getPetNameDB().get(_archive);
     92            System.err.println("Archive to petname? " + pn + " (protocol: " + (pn != null ? pn.getProtocol() : "") + ")");
     93            if ( (pn != null) && ("syndiearchive".equals(pn.getProtocol())) ) {
     94                RemoteArchiveBean r = new RemoteArchiveBean();
     95                Map params = new HashMap();
     96                params.put("localentry", new String[] { uri.toString() });
     97                String proxyHost = BlogManager.instance().getDefaultProxyHost();
     98                String port = BlogManager.instance().getDefaultProxyPort();
     99                int proxyPort = 4444;
     100                try { proxyPort = Integer.parseInt(port); } catch (NumberFormatException nfe) {}
     101                System.err.println("Posting the entry " + uri.toString() + " to " + pn.getLocation());
     102                r.postSelectedEntries(_user, params, proxyHost, proxyPort, pn.getLocation());
     103                System.err.println("Post status: " + r.getStatus());
     104            }
     105        }
     106        return uri;
    86107    }
    87108   
  • apps/syndie/java/src/net/i2p/syndie/web/RemoteArchiveBean.java

    rf958342 re6b1457  
    265265       
    266266        if ( (schema == null) || (schema.trim().length() <= 0) ||
    267         (location == null) || (location.trim().length() <= 0) ) {
     267             (location == null) || (location.trim().length() <= 0) ) {
    268268            _statusMessages.add("Location must be specified");
    269269            _fetchIndexInProgress = false;
     
    290290       
    291291        _statusMessages.add("Fetching index from " + HTMLRenderer.sanitizeString(_remoteLocation) +
    292         (_proxyHost != null ? " via " + HTMLRenderer.sanitizeString(_proxyHost) + ":" + _proxyPort : ""));
     292                            (_proxyHost != null ? " via " + HTMLRenderer.sanitizeString(_proxyHost) + ":" + _proxyPort : ""));
    293293        File archiveFile = new File(BlogManager.instance().getTempDir(), user.getBlog().toBase64() + "_remoteArchive.txt");
    294294        archiveFile.delete();
    295295        EepGet eep = new EepGet(I2PAppContext.getGlobalContext(), ((_proxyHost != null) && (_proxyPort > 0)),
    296         _proxyHost, _proxyPort, 0, archiveFile.getAbsolutePath(), location);
     296                                _proxyHost, _proxyPort, 0, archiveFile.getAbsolutePath(), location);
    297297        eep.addStatusListener(new IndexFetcherStatusListener(archiveFile));
    298298        eep.fetch();
     
    507507   
    508508    public void postSelectedEntries(User user, Map parameters) {
     509        postSelectedEntries(user, parameters, _proxyHost, _proxyPort, _remoteLocation);
     510    }
     511    public void postSelectedEntries(User user, Map parameters, String proxyHost, int proxyPort, String location) {
    509512        String entries[] = ArchiveViewerBean.getStrings(parameters, "localentry");
    510513        if ( (entries == null) || (entries.length <= 0) ) return;
     
    512515        for (int i = 0; i < entries.length; i++)
    513516            uris.add(new BlogURI(entries[i]));
    514        
     517        if ( (proxyPort > 0) && (proxyHost != null) && (proxyHost.trim().length() > 0) ) {
     518            _proxyPort = proxyPort;
     519            _proxyHost = proxyHost;
     520        } else {
     521            _proxyPort = -1;
     522            _proxyHost = null;
     523        }
     524        _remoteLocation = location;
    515525        post(uris, user);
    516526    }
  • apps/syndie/jsp/addresses.jsp

    rf958342 re6b1457  
    159159    <tr><form action="addresses.jsp" method="POST"><td><input type="text" name="name" size="20" value="<%=name%>" /></td>
    160160        <td><select name="network">
    161             <option value="i2p" <%="i2p".equals(net) ? " selected=\"true\" " : ""%>>I2P</option>
    162             <option value="syndie" <%="syndie".equals(net) ? " selected=\"true\" " : ""%>>Syndie</option>
    163             <option value="tor" <%="tor".equals(net) ? " selected=\"true\" " : ""%>>Tor</option>
    164             <option value="freenet" <%="freenet".equals(net) ? " selected=\"true\" " : ""%>>Freenet</option>
    165             <option value="internet" <%="internet".equals(net) ? " selected=\"true\" " : ""%>>Internet</option></select></td>
     161            <option value="i2p" <%="i2p".equalsIgnoreCase(net) ? " selected=\"true\" " : ""%>>I2P</option>
     162            <option value="syndie" <%="syndie".equalsIgnoreCase(net) ? " selected=\"true\" " : ""%>>Syndie</option>
     163            <option value="tor" <%="tor".equalsIgnoreCase(net) ? " selected=\"true\" " : ""%>>Tor</option>
     164            <option value="freenet" <%="freenet".equalsIgnoreCase(net) ? " selected=\"true\" " : ""%>>Freenet</option>
     165            <option value="internet" <%="internet".equalsIgnoreCase(net) ? " selected=\"true\" " : ""%>>Internet</option></select></td>
    166166        <td><select name="protocol">
    167             <option value="http" <%="http".equals(proto) ? " selected=\"true\" " : ""%>>HTTP</option>
    168             <option value="irc" <%="irc".equals(proto) ? " selected=\"true\" " : ""%>>IRC</option>
    169             <option value="i2phex" <%="i2phex".equals(proto) ? " selected=\"true\" " : ""%>>I2Phex</option>
    170             <option value="syndiearchive" <%="syndiearchive".equals(proto) ? " selected=\"true\" " : ""%>>Syndie archive</option>
    171             <option value="syndieblog" <%="syndieblog".equals(proto) ? " selected=\"true\" " : ""%>>Syndie blog</option></select></td>
     167            <option value="http" <%="http".equalsIgnoreCase(proto) ? " selected=\"true\" " : ""%>>HTTP</option>
     168            <option value="irc" <%="irc".equalsIgnoreCase(proto) ? " selected=\"true\" " : ""%>>IRC</option>
     169            <option value="i2phex" <%="i2phex".equalsIgnoreCase(proto) ? " selected=\"true\" " : ""%>>I2Phex</option>
     170            <option value="syndiearchive" <%="syndiearchive".equalsIgnoreCase(proto) ? " selected=\"true\" " : ""%>>Syndie archive</option>
     171            <option value="syndieblog" <%="syndieblog".equalsIgnoreCase(proto) ? " selected=\"true\" " : ""%>>Syndie blog</option></select></td>
    172172        <td><input type="text" size="50" name="location" value="<%=loc%>" /></td>
    173173        <td><input type="checkbox" name="isPublic" /></td>
  • apps/syndie/jsp/post.jsp

    rf958342 re6b1457  
    1919  %>You must be logged in to post<%
    2020} else {
    21   String confirm = request.getParameter("confirm");
    22   if ( (confirm != null) && (confirm.equalsIgnoreCase("true")) ) {
     21  String confirm = request.getParameter("action");
     22  if ( (confirm != null) && (confirm.equalsIgnoreCase("confirm")) ) {
     23    String archive = request.getParameter("archive");
     24    post.setArchive(archive);
    2325    BlogURI uri = post.postEntry();
    2426    if (uri != null) {
     
    4446        String entryText = req.getString("entrytext");
    4547        String entryHeaders = req.getString("entryheaders");
     48        String style = req.getString("style");
     49        if ( (style != null) && (style.trim().length() > 0) ) {
     50          if (entryHeaders == null) entryHeaders = HTMLRenderer.HEADER_STYLE + ": " + style;
     51          else entryHeaders = entryHeaders + '\n' + HTMLRenderer.HEADER_STYLE + ": " + style;
     52        }
    4653        String replyTo = req.getString(ArchiveViewerBean.PARAM_IN_REPLY_TO);
    4754        if ( (replyTo != null) && (replyTo.trim().length() > 0) ) {
    4855          byte r[] = Base64.decode(replyTo);
    4956          if (r != null) {
    50             if (entryHeaders == null) entryHeaders = HTMLRenderer.HEADER_IN_REPLY_TO + ": " + new String(r);
    51             else entryHeaders = entryHeaders + '\n' + HTMLRenderer.HEADER_IN_REPLY_TO + ": " + new String(r);
     57            if (entryHeaders == null) entryHeaders = HTMLRenderer.HEADER_IN_REPLY_TO + ": " + new String(r, "UTF-8");
     58            else entryHeaders = entryHeaders + '\n' + HTMLRenderer.HEADER_IN_REPLY_TO + ": " + new String(r, "UTF-8");
    5259          } else {
    5360            replyTo = null;
    5461          }
    5562        }
    56 
     63        String includeNames = req.getString("includenames");
     64        if ( (includeNames != null) && (includeNames.trim().length() > 0) ) {
     65          PetNameDB db = user.getPetNameDB();
     66          if (entryHeaders == null) entryHeaders = "";
     67          for (Iterator iter = db.getNames().iterator(); iter.hasNext(); ) {
     68            PetName pn = db.get((String)iter.next());
     69            if ( (pn != null) && (pn.getIsPublic()) ) {
     70              entryHeaders = entryHeaders + '\n' + HTMLRenderer.HEADER_PETNAME + ": " +
     71                             pn.getName() + "\t" + pn.getNetwork() + "\t" + pn.getProtocol() + "\t" + pn.getLocation();
     72            }
     73          }
     74        }
     75       
    5776        post.setSubject(entrySubject);
    5877        post.setTags(entryTags);
     
    7796
    7897        post.renderPreview(out);
    79         %><hr />Please <a href="post.jsp?confirm=true">confirm</a> that this is ok.  Otherwise, just go back and make changes.<%
     98        %><hr /><form action="post.jsp" method="POST">
     99Please confirm that the above is ok<% if (user.getAllowAccessRemote()) { %>, and select what additional archives you
     100want the post transmitted to.  Otherwise, just hit your browser's back arrow and
     101make changes.
     102<select name="archive">
     103<option name="">-None-</option>
     104<%
     105PetNameDB db = user.getPetNameDB();
     106TreeSet names = new TreeSet();
     107for (Iterator iter = db.getNames().iterator(); iter.hasNext(); ) {
     108  String name = (String)iter.next();
     109  PetName pn = db.get(name);
     110  if ("syndiearchive".equals(pn.getProtocol()))
     111    names.add(pn.getName());
     112}
     113for (Iterator iter = names.iterator(); iter.hasNext(); ) {
     114  String name = (String)iter.next();
     115  out.write("<option value=\"" + HTMLRenderer.sanitizeTagParam(name) + "\">" + HTMLRenderer.sanitizeString(name) + "</option>\n");
     116}
     117%>
     118</select><br /><% } %>
     119<input type="submit" name="action" value="Confirm" /><%
    80120    } else {
    81121      // logged in and not confirmed because they didn't send us anything! 
     
    84124Post subject: <input type="text" size="80" name="entrysubject" value="<%=post.getSubject()%>" /><br />
    85125Post tags: <input type="text" size="20" name="entrytags" value="<%=post.getTags()%>" /><br />
     126Post style: <select name="style">
     127 <option value="default" selected="true">Default</option>
     128 <option value="meta">Meta (hide everything but the metadata)</option>
     129</select><br />
     130Include public names? <input type="checkbox" name="includenames" value="true" /><br />
    86131Post content (in raw SML, no headers):<br />
    87132<textarea rows="6" cols="80" name="entrytext"><%=post.getText()%></textarea><br />
     
    112157<input type="hidden" name="<%=ArchiveViewerBean.PARAM_IN_REPLY_TO%>" value="<%=request.getParameter(ArchiveViewerBean.PARAM_IN_REPLY_TO)%>" />
    113158<% } %>
    114 
    115159Attachment 0: <input type="file" name="entryfile0" /><br />
    116160Attachment 1: <input type="file" name="entryfile1" /><br />
Note: See TracChangeset for help on using the changeset viewer.