Pretty Permalink Filter Community Forum (for Running WordPress with Quercus)

88 views
Skip to first unread message

Kaz Nishimura

unread,
Jan 8, 2015, 7:18:49 PM1/8/15
to caucho-...@googlegroups.com
I just made a community forum for my Pretty Permalink Filter for the product support.  If you are trying to run WordPress with my Pretty Permalink Filter and have any problem, please ask there (sign-up required) so that your question could help others tomorrow.

I can still answer questions about Pretty Permalink Filter here, but please avoid replying in private mail (instead use Reply To All or somthing like that) as it cannot help others but you.

Ashish

unread,
Jan 9, 2015, 2:34:41 PM1/9/15
to caucho-...@googlegroups.com
Hi,

I have followed all the instructions and kept the jar file in lib directory and also updated web.xml. But still I get 404 error.

Actually I have installed wordpress in tomcat/webapps/blog/.

Can you please help me on this.

Thanks,
Ashish

Kaz Nishimura

unread,
Jan 9, 2015, 5:58:26 PM1/9/15
to caucho-...@googlegroups.com
Could you make WordPress work without my Pretty Permalink Filter?  If not, Quercus Servlet must be configured first.  I have just described how to make permalinks work on WordPress with Quercus Servlet configured.

Ashish

unread,
Jan 10, 2015, 12:50:21 AM1/10/15
to caucho-...@googlegroups.com
Yes, wordpress is working without the filter (Quercus has been configured). I can see all the posts with the "default" setting of permalinks. But when I choose "postname", it fails and gives me 404 error.

That's the reason, I used your Pretty Permalink Filter.

Kaz Nishimura

unread,
Jan 10, 2015, 1:31:14 AM1/10/15
to caucho-...@googlegroups.com
Thank you for describing your problem.  It is possible that the 'Post name' option confuses the filter.  Please note that the current implimentation just sees only the request path.

Can you try other options and check whether it works or not?

Ashish

unread,
Jan 10, 2015, 1:45:37 AM1/10/15
to caucho-...@googlegroups.com
I have tried other options as well, but only the default one works.

Did I miss anything ?

Kaz Nishimura

unread,
Jan 10, 2015, 1:52:15 AM1/10/15
to caucho-...@googlegroups.com
OK, I confirmed what causes the problem.  'index.php' was appended after the trailing slash, probably by the web application server.

I will try to cope with the case and make a new release.

Ashish

unread,
Jan 10, 2015, 1:58:49 AM1/10/15
to caucho-...@googlegroups.com
That would be great. Thanks for considering my problem.

Kaz Nishimura

unread,
Jan 10, 2015, 1:59:07 AM1/10/15
to caucho-...@googlegroups.com
Created a new issue.  Please wait for a while.

Kaz Nishimura

unread,
Jan 10, 2015, 2:32:32 AM1/10/15
to caucho-...@googlegroups.com
I just made the release of version 2.0.  It should work with all permalink options now.  The new version will be available soon at <http://search.maven.org/#browse|773662449>.

Thank you for finding a bug!

Ashish

unread,
Jan 10, 2015, 3:37:35 AM1/10/15
to caucho-...@googlegroups.com
Thanks for the update. I will be waiting for the new jar.

Kaz Nishimura

unread,
Jan 10, 2015, 5:34:14 PM1/10/15
to caucho-...@googlegroups.com
https://oss.sonatype.org/content/repositories/releases/org/vx68k/pretty-permalink-filter/2.0/pretty-permalink-filter-2.0.jar

If you are in a hurry, try the above link to pick the new jar.   Distribution seems being delayed.

Ashish

unread,
Jan 11, 2015, 5:57:16 AM1/11/15
to caucho-...@googlegroups.com
Thanks a lot. Its working now.

mkot...@gmail.com

unread,
Sep 15, 2015, 5:03:34 PM9/15/15
to Quercus, ash...@bookcab.in
It's not working. When I click on the heading of a post, I get:

com.caucho.quercus.QuercusException: com.caucho.quercus.lib.date.DateTime.setISODate: `DateTime::setISODate()' has not been implemented. A more recent version of Quercus may be available at http://www.caucho.com/download Requests for unimplemented features can be entered in the bugtracking system at http://bugs.caucho.com

Kaz Nishimura

unread,
Sep 15, 2015, 7:29:59 PM9/15/15
to Quercus
I have a plan to implement DateTime::setISODate but I don't have time to do it yet. DateTime::setISODate has some complexity that week 1 of a year must have at least 4 days, so some coding must be needed!

mkot...@gmail.com

unread,
Sep 15, 2015, 8:05:30 PM9/15/15
to Quercus
How about this piece of code to get you started on setISODate() [without this function, WordPress + Quercus is useless because all permalinks fail and sitemap with individual posts cannot be created]:

// See http://stackoverflow.com/questions/147178/what-is-a-good-simple-way-to-compute-iso-8601-week-number
private static Date setISODate(int weekYear, int weekOfYear, int dayOfWeek) {
Calendar calendar = Calendar.getInstance();
calendar.setMinimalDaysInFirstWeek(4);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
if (dayOfWeek > 7) {
weekOfYear += dayOfWeek / 7;
dayOfWeek = ((dayOfWeek - 1) % 7) + 1;
}
int calDayOfWeek = 0;
switch (dayOfWeek) {
case 1:
calDayOfWeek = Calendar.MONDAY;
break;
case 2:
calDayOfWeek = Calendar.TUESDAY;
break;
case 3:
calDayOfWeek = Calendar.WEDNESDAY;
break;
case 4:
calDayOfWeek = Calendar.THURSDAY;
break;
case 5:
calDayOfWeek = Calendar.FRIDAY;
break;
case 6:
calDayOfWeek = Calendar.SATURDAY;
break;
case 7:
calDayOfWeek = Calendar.SUNDAY;
break;
default:
throw new IllegalArgumentException("Invalid dayOfWeek: " + dayOfWeek);
}
calendar.setWeekDate(weekYear, weekOfYear, calDayOfWeek);
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}

// This is an overloaded version of the above function that does not require the dayOfWeek
// I am not sure how the @Optional annotation works in Quercus,
// so you may need to combine the two functions into one.
private static Date setISODate(int weekYear, int weekOfYear) {
return setISODate(weekYear, weekOfYear, 1);
}

// This is a simple test per the original PHP function
// http://php.net/manual/en/datetime.setisodate.php
private static void testSetISODate() {
System.out.println(setISODate(2008, 2));
System.out.println(setISODate(2008, 2, 7));
System.out.println(setISODate(2008, 2, 8));
System.out.println(setISODate(2008, 53, 7));
}

Kaz Nishimura

unread,
Sep 15, 2015, 8:42:08 PM9/15/15
to Quercus
I feel your implementation is mostly good, but you could optimize the switch-case block by using a table, or by using simple expression as Calendar.MONDAY etc. are int values (Calendar.SUNDAY == 1 and other days follow it).

mkot...@gmail.com

unread,
Sep 15, 2015, 9:12:16 PM9/15/15
to Quercus
Yes, I was considering a table lookup on the dayOfWeek conversion, but in the end decided against it for code clarity and also a "free" default statement that would otherwise have to be implemented separately. (The JIT compiler should convert this switch statement to be table-driven anyway.) Using an expression would not be advised because you are not supposed to make assumptions about values of Calendar.MONDAY..Calendar.SUNDAY (i.e. contiguous and rising, just like dayOfWeek = 1..7).

A few potential enhancements:
1. Check that weekYear >= 1583 or >= 1875 (see https://en.wikipedia.org/wiki/ISO_8601)
2. Handling of non-positive dayOfWeek (I know very little about PHP, but the description of the original function suggests that such values are supported and treated as negative offsets vs. Monday = 1).
3. Use one instance of Calendar and make it multi-threaded with synchronized() if required [creation of Calendar is apparently expensive].

Anyway, feel free to use/change this code as you see fit and check it into Quercus (the lack of setISODate() is a blocking issue for me and others).

Kaz Nishimura

unread,
Sep 16, 2015, 1:38:25 AM9/16/15
to mkot...@gmail.com, Quercus
I uses archives/* style and it works fine. I hope year/month/* style should work, too.
2015年9月16日(水) 10:12 <mkot...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "Quercus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caucho-quercu...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kaz Nishimura

unread,
Sep 16, 2015, 1:48:20 AM9/16/15
to Quercus
Calendar.SUNDAY == 1 and so on are part of public Java API. I consider it is safe to assume it won't change in the future.

2015年9月16日(水) 10:12 <mkot...@gmail.com>:

realwor...@gmail.com

unread,
Sep 16, 2015, 6:05:40 AM9/16/15
to Quercus

Add me to the list of those who would like setISODate support. Kudos on the current version of Pretty Permalink Filter - it is absolutely plug-and-play in our Tomcat / Quercos environment. Just dropped the jar in, restarted Tomcat, changed my permalinks to "postname" and was done. Very nice. I was skeptical about the maturity of the software, but it absolutely works as advertised. Alas, all of our existing posts have Month+Name permalinks... Feature request!

realwor...@gmail.com

unread,
Sep 16, 2015, 6:36:37 AM9/16/15
to Quercus, realwor...@gmail.com

>
> Add me to the list of those who would like setISODate support. Kudos on the current version of Pretty Permalink Filter - it is absolutely plug-and-play in our Tomcat / Quercos environment. Just dropped the jar in, restarted Tomcat, changed my permalinks to "postname" and was done. Very nice. I was skeptical about the maturity of the software, but it absolutely works as advertised. Alas, all of our existing posts have Month+Name permalinks... Feature request!

We can redirect all the Month+Name permalinks to point at the new Postname permalinks.

But we cannot redirect our archives (Year+Month). Any blog that makes their archives available will need setISODate support.

Pretty Permalink Filter is wonderful, nonetheless. Thank you!

mkot...@gmail.com

unread,
Sep 16, 2015, 10:02:36 AM9/16/15
to Quercus, realwor...@gmail.com
OK, so here is a modified piece of code that uses table-driven dayOfWeek conversion and accommodates dayOfWeek < 1 (equivalent to negative day-of-week offsets):

// index = 0..6
private static final int[] calDaysOfWeek = {
Calendar.MONDAY,
Calendar.TUESDAY,
Calendar.WEDNESDAY,
Calendar.THURSDAY,
Calendar.FRIDAY,
Calendar.SATURDAY,
Calendar.SUNDAY
};

// http://stackoverflow.com/questions/147178/what-is-a-good-simple-way-to-compute-iso-8601-week-number


private static Date setISODate(int weekYear, int weekOfYear, int dayOfWeek) {
Calendar calendar = Calendar.getInstance();
calendar.setMinimalDaysInFirstWeek(4);
calendar.setFirstDayOfWeek(Calendar.MONDAY);

if (dayOfWeek < 1) {
// e.g. dayOfWeek == 0 is offset -1 (or 1 week) from dayOfWeek == 1 == Monday
// e.g. dayOfWeek == -6 is offset -7 (or still 1 week) from dayOfWeek == 1 == Monday
weekOfYear -= (7 - dayOfWeek) / 7;

// e.g. dayOfWeek == 0 is offset -1 from dayOfWeek == 1 == Monday, which means dayOfWeek == 6 ==Sunday
// e.g. dayOfWeek == -6 is offset -7 from dayOfWeek == 1 == Monday, which means dayOfWeek == 1 == Monday
dayOfWeek = 7 - ((-dayOfWeek) % 7);
}
else if (dayOfWeek > 7) {
// e.g. if dayOfWeek == 8, then advance by 1 week


weekOfYear += dayOfWeek / 7;
dayOfWeek = ((dayOfWeek - 1) % 7) + 1;
}

assert 1 <= dayOfWeek && dayOfWeek <= 7;
int calDayOfWeek = calDaysOfWeek[dayOfWeek - 1];


calendar.setWeekDate(weekYear, weekOfYear, calDayOfWeek);
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}

private static Date setISODate(int weekYear, int weekOfYear) {
return setISODate(weekYear, weekOfYear, 1);
}

mkot...@gmail.com

unread,
Sep 17, 2015, 1:46:40 PM9/17/15
to Quercus
In the above piece of code, one of the comments should read:
// e.g. dayOfWeek == 0 is offset -1 from dayOfWeek == 1 == Monday, which means dayOfWeek == 7 == Sunday

Kaz: Given that I have done most of the implementation work, when will you check in this code and make Quercus 4.0.40 available? Without setISODate(), WordPress on Quercus is not production-ready.

We also have to implement the simplexml_import_dom(). Without it, the key plugin wordpress-importer does not work, which means all posts (potentially, hundreds or thousands) from a WordPress export file would have to be manually imported. This, again, makes WordPress on Quercus not production-ready. Unfortunately, I do not have sufficient knowledge to implement this function. Perhaps someone else could step in and provide sample code?

Kaz Nishimura

unread,
Sep 17, 2015, 7:09:17 PM9/17/15
to Quercus
Because Quercus is not my first priority, I cannot promise it will be implemented soon as long as it works for me. If anyone could post bounties on Bountysource, I would try to resolve it sooner but unfortunately bugs.caucho.com is not supported there. 

mkot...@gmail.com

unread,
Sep 17, 2015, 7:45:48 PM9/17/15
to Quercus
I understand. I can try to produce a Quercus war file with the setISODate() implementation but I would like to incorporate all other fixes that have been made on top of the last official version 4.0.39. Can you point me to the latest source code? Otherwise, I will have to use 4.0.39.

Kaz Nishimura

unread,
Sep 17, 2015, 9:04:39 PM9/17/15
to Quercus
I am maintaining a fork of the public Caucho Resin Subversion repository here including official tags  The 'default' branch should be identical to their repository except for file renames for Mavenizing, and the 'modified' branch has my changes with Maven project files.

Please note that importing new changes from their repository are performed by hand and it may be behind several commits.  If you are interested, I can also publish the full Caucho Resin repository without renames but it won't be interesting for Quercus-only users.

Kaz Nishimura

unread,
Sep 19, 2015, 10:53:23 PM9/19/15
to Quercus
This is my implementation of DateTime::setISODate. It works the same way as the examples in th PHP Manual but I do not know how it should work if an out-of-range value is passed.

  public void setISODate(int year,
                         int week, //yes, week, not month
                         @Optional("1") int day)
  {
    // Adjusts the day starts at Sunday and within 7 days.
    final int dayOfWeek = day % 7;
    if (dayOfWeek == 0) {
      day -= 7;
    }
    week += (day - dayOfWeek) / 7;

    GregorianCalendar calendar =
            new GregorianCalendar(year, Calendar.JANUARY, 1);
    calendar.setFirstDayOfWeek(Calendar.MONDAY);
    calendar.setMinimalDaysInFirstWeek(4);
    // The year was already set.
    calendar.set(Calendar.WEEK_OF_YEAR, week);
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY + dayOfWeek);
    _qDate.setDate(
        calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
        calendar.get(Calendar.DAY_OF_MONTH));

Kaz Nishimura

unread,
Sep 20, 2015, 12:47:12 AM9/20/15
to Quercus
I finally committed a slightly modified version to my repository. If you are interested, see <https://bitbucket.org/kazssym/quercus/commits/2407fd7adb81af796410d4db2f2e85a33228037e>

Kaz Nishimura

unread,
Sep 20, 2015, 9:35:48 AM9/20/15
to Quercus
All of the predefined permalink styles worked here!
Reply all
Reply to author
Forward
0 new messages