SuperSatellite ||

Subscribe (?) Subscribe to RSS

Posts Tagged ‘php’

Advanced kPlaylist

Published on April 1st, 2008 in No Comments »

The following information is accurate as of the latest development build of kPlaylist, which is v1.7 rev479 that was released on the 1st of April, 2008. Get the most current version from kPlaylist’s download page. Revisions are issued pretty regularly, while the 1.7 base came out in 2006. I’m really not sure why he uses that kind of setup for versioning.

UPDATE (08.04.02): I just got word that version 1.8 of kPlaylist will be coming out once the current development code is deemed stable. This will be sometime after revision 480. Following that release, they will probably begin making regular development revisions based on the 1.8 code base, similar to what they are doing now on 1.7.

kPlaylist logoThis was surprisingly well timed, given that a year ago I published my little review in which I endorsed a piece of media streaming software called kPlaylist that I selected over a couple others when I was looking for a way to listen to my music when I wasn’t at home. It is by sheer coincidence that I decided now to go back and touch more on that software, giving a slightly more in depth look, and sharing some tricks and one of my tweaks that aren’t so well documented. Feel free to comment below and add your own advice, or correct any mistakes I might make (not that I ever make mistakes, who are we kidding?).

For those that are unfamiliar, kPlaylist is a PHP based script that allows you to store audio and video files on a web server, and output playlists that allow you to stream said files to the computer you are at. This is very handy if you have encoded a lot of CDs, and prefer to listen to them at work or at a friends house, without lugging the discs all over. You could also use it to share podcasts, or to create a band site where people can listen to and download your garage recordings, and anything along those lines. This does require you have access to a web server with ample storage space of course. I prefer to run my own from home, using No-IP.com to attach a domain name to my box on my internet connection. Just be sure you run a firewall, and that you have permission to share what you are with who you are. I won’t discuss the setup side of this. I assume you can set up your own MySQL database and connect to it and upload files and all that jazz. If you can’t, there’s support forums to help you out with that.

kPlaylist runs off one single file in its simplest form. We can refer to the kPlaylist site for a few of the software’s features:

  • Supports multiple music sources (drives, directories, nmb, smbfs, nfs, etc)
  • Multiuser based, includes automatic sign-up tool and user editor
  • Secure and safe, used daily in hundreds of installations worldwide
  • Upload, multiple upload, download and multi download support.
  • Inbuilt bulletin board to communicate with users
  • Randomizer function to find new and popular music and common music between users
  • Balance network load with the inbuilt streaming engine during streams and download.
  • Supports LAME to re-encode streams on-the-fly (transcoding)
  • History of activity, including detailed track use.
  • Mail functionality for attaching and sending a music file instantly.
  • Easy to get started; automatic upgrade and install.
  • International; supports 29 languages
  • Runs on all operating systems that support PHP and MySQL.
  • Audio support including, but not limited to mp3, ogg, wma, rma, wav, etc.
  • Tested with RealPlayer, XMMS, Windows Media Player, iTunes and Winamp.
  • Plus much, much more.

kPlaylist Screenshot 1So, let’s assume that you get everything set up and running. If so, you probably see something like what we have at the left (granted, I’ve already dug down into an album). If you are running off of the default install you probably notice that my setup looks a little different from yours. I’ve taken advantage some of the features that allow custom theming of kPlaylist. It also supports custom icon packs, so you can really get into how things display. The theme capabilities aren’t necessarily as robust as other applications, but you can still get in enough to have fun with it. Look at the left bar, and click on the button for Admin Control > Settings. This will get you into the settings console where you can start tweaking some of this stuff. Specifically, we want to look at the Customize tab.

kPlaylist Screenshot 2That would be this baby right here. First, if you’d like to embed kPlaylist into another app, like a CMS (Content Management System), you can turn off the Include Headers feature. This is useful if you want to integrate it with a community running on something like Drupal, Joomla, e107, or others. Otherwise, leave it on (which you normally will). The External Images path allows you to tell kPlaylist where to find alternative icons that you want to use. This is relative to the install root of kPlaylist. So, if you installed kPlaylist in a folder called /media, then theme/images/ would translate to http://www.yoursite.com/media/themes/images/. The best thing to do is download the default icon pack, and just start changing the ones you want. I do this, and rename the originals with a .bak extension, just in case I ever need to revert. Likewise, the External CSS (Cascading Style Sheets) File path works the same, allowing you to override default colors and layout settings for kPlaylist. Download the original at the link I just mentioned for images, and start tweaking, then upload it (probably near your custom images), and tell it to find it. You can do the same with Javascript and AJAX (Asynchronous Javascript And XML) frameworks for other options.

kPlaylist Screenshot 3In this case, if you use something like Prototype for AJAX functionality, you can enable additional features like the live Last Streams feed in the system. This can keep you apprised, live, of what people are listening too without the need to refresh the page. Hopefully, we’ll see more AJAX functionality like live-edit playlists soon. My fingers are crossed, and tempted to start coding such functionality myself…we’ll see. There’s a lot of room for growth of AJAX functionality in kPlaylist.

If you are anything like me, you’ve noticed that there are some pitfalls to the fact that kPlaylist is just a single file script. This is handy for simple setups, but can make upgrading tedious if you are using a lot of custom settings. This is because most of the more advanced settings are hardcoded into the script, rather than stored in the database (I’d love to see this change soon…). Actually, there’s a clever tool for simplifying upgrades without a lot of work remembering which variables you changed. You can create your own file, call it kpconfig.php, put it in with you kplaylist install, and store all your custom settings there. Then, each time that you upgrade, all your settings are still right there. The standard kPlaylist install will load this file after all the default settings are loaded, overwriting anything that you want customized. Here’s a sample of my kpconfig.php file:

  1. <?php
  2. $cfg[‘frontbulletinchars’] = 120;
  3. $cfg[‘enablegetid3′] = 1;
  4. $cfg[‘uploadselections’] = 24;
  5. $cfg[‘numberlogins’] = 1;
  6. $cfg[‘livestreamajax’] = true;
  7. $cfg[‘window_x’] = 420;
  8. $cfg[‘window_y’] = 220;
  9. $cfg[‘xspf_x’] = $cfg[‘window_x’] - 20;
  10. $cfg[‘xspf_y’] = $cfg[‘window_y’] - 20;
  11. $cfg[‘xspf_url’] = ‘xspf_player.swf’;
  12. $cfg[‘xspf_opt’] = ;
  13. $cfg[‘xspf_enable’] = true;
  14.  
  15. $streamtypes_default = array(
  16. 0 => array   (‘mp3′,   ‘audio/mpeg’,               1, 1, 1, 1),
  17. 1 => array   (‘mp2′,   ‘audio/mpeg’,               1, 1, 1, 1),
  18. 2 => array   (‘ogg’,   ‘application/x-ogg’,        1, 2, 1, 1),
  19. 3 => array   (‘wav’,   ‘audio/wave’,               1, 0, 1, 1),
  20. 4 => array   (‘wma’,   ‘audio/x-ms-wma’,           1, 0, 1, 1),
  21. 5 => array   (‘mpg’,   ‘video/mpeg’,               0, 0, 1, 1),
  22. 6 => array   (‘mpeg’,  ‘video/mpeg’,               0, 0, 1, 1),
  23. 7 => array   (‘avi’,   ‘video/avi’,                0, 0, 1, 1),
  24. 8 => array   (‘wmv’,   ‘video/x-ms-wmv’,           0, 0, 1, 1),
  25. 9 => array   (‘asf’,   ‘application/vnd.ms-asf’,   0, 0, 1, 1),
  26. 10 => array  (‘m3u’,   ‘audio/x-mpegurl’,          0, 0, 0, 0),
  27. 11 => array  (‘flac’,  ‘audio/x-flac’,             1, 0, 1, 1),
  28. 12 => array  (‘jpg’,   ‘image/jpeg’,               0, 0, 0, 0),
  29. 13 => array  (‘gif’,   ‘image/gif’,                0, 0, 0, 0),
  30. 14 => array  (‘png’,   ‘image/png’,                0, 0, 0, 0)
  31. );
  32. ?>

You might notice two things there. One, I’ve opted to enable a Flash based media player (by turning on xspf_enable and setting xspf_url), so that I can play my music right through a web page (if you can’t figure out how to get it to work after setting it up, go into My > Options > Playlist, and set it as XSPF). You can upload any Flash media player that accepts XSPF playlists (Try out Lacy Morrow’s player, or the JW FLV Media Player for instance). kPlaylist recommends the XSPF Web Music Player, but it’s just awfully lightweight for my tastes. That leads me to the second thing you might notice about my config file. I have two variables that aren’t in the original product. This is for a mod that allows me to control the size of my Flash player in the popup window. The variable window_x and window_y let you control the window’s size, but the players themselves don’t always cooperate with that.

My solution takes two steps. First, create the two additional parameters:

  1. $cfg[‘xspf_x’] = $cfg[‘window_x’] - 20;
  2. $cfg[‘xspf_y’] = $cfg[‘window_y’] - 20;

Then, look around line 14,651 for the flashhtml() function. I comment it out, and right after it place this modified version:

  1. function flashhtml()
  2.   {
  3.     global $setctl, $phpenv, $u_cookieid, $u_id, $cfg;
  4.     kprintheader(, 0, 0);
  5.     $playlist = $setctl->get(’streamurl’).$phpenv[’streamlocation’];
  6.     $playlist .= ‘?templist=’.$u_id.‘&amp;c=’.$u_cookieid.‘&amp;file=’.lzero(getrand(1,999999),6).‘.xml’;
  7.     $link = $cfg[‘xspf_url’].‘?’.$cfg[‘xspf_opt’].‘autoplay=true&amp;autoload=true&amp;playlist_url=’.urlencode($playlist);
  8. ?>
  9.     <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="<?php echo $cfg['xspf_x']; ?>" height="<?php echo $cfg['xspf_y']; ?>" id="xspf_player" align="middle">
  10.       <param name="allowScriptAccess" value="always" />
  11.       <param name="movie" value="<?php echo $link; ?>" />
  12.       <param name="quality" value="high" />
  13.       <param name="bgcolor" value="#e6e6e6" />
  14.       <embed src="<?php echo $link; ?>" quality="high" bgcolor="#e6e6e6" width="<?php echo $cfg['xspf_x']; ?>" height="<?php echo $cfg['xspf_y']; ?>" name="xspf_player" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
  15.     </object>
  16. <?php
  17.     kprintend();
  18.   }

That allows the player size to be the full size of the window, minus a few pixels padding. So you can have full flexibility with both the player and its skin size.

There’s this thread in the support forums that you can look at for additional modifications as well, such as DNS (Domain Name Service) lookup on user IP addresses, showing the main directory in a scroll box, and a few others. These require a bit more editing, and will make future upgrades more involved though. You’ll find quite a bit of useful information in the forums that isn’t always available in the normal documentation. If you want to get really crazy, the source code is available too at Get Source page.

kPlaylist is getting increasingly more powerful lately. The enabling of XSPF is older, but still newish in general terms. Video support is being improved, there’s now built in zipping of multiple files (with PHP 5.2), virtual directory support, a network server mode, and more on the way. Still, it’s all around the most lightweight and useful streaming media server software that I’ve used. I do, however, think that there’s room for improvement, and I’m playing with the idea of forking the code and starting a new project based off it. If you’re interested in building a team to do that, contact me and we’ll talk.

Breakthrough!

Published on March 14th, 2008 in 2 Comments »

Today was a day of days for dotCMS and me. A couple weeks ago I started working on integrating a servlet into dotCMS to handle PHP code. This in part to learn if I could, and also because I know PHP way better than Java. It would also help to keep me from needing to rewrite chunks of code that I might want to keep using or from having to maintain a second server and connect it to Tomcat using mod_jk for the purpose of running PHP. Ideally, I wanted it all wrapped up in one, nice package.

Enter the Tomcat Wiki. That’s where I started out at, specifically this entry about using PHP. It definitely got me started. The only thing that was sorta sucky was that the method did not work with PHP5+. Only PHP4. But I figured I could live with that. Better than nothing, right? After spending two days hammering away at it, I gave up. I was able to eventually get rid of all the errors, but the end result was a big goose egg on code execution. I also wasn’t sure if it’d even work with the 4.4.8 codebase I grabbed from PHP. All around, I just decided this wasn’t a worthwhile course to follow.

Quercus phpinfo() Result Page Enter IRC, JT, and Quercus two weeks later. Jason got to talking with Chris and I about it yesterday in the IRC channel (#dotcms on Freenode), and pointed out Quercus. Quercus is a PHP servlet designed by Caucho for their Resin Java application server. Released under the GPL, no less. Unfortunately, at this time, their site sucks, the mailing list bounces, and the forums error out when trying to make a new account. So, I started sniffing around. Rob Sinner’s blog turned out to be a great starting place, and has the bulk of the information you will need. Quercus was also picked up and integrated into the Liferay project, which was where dotCMS started. I figured if they got it working, there’s no reason I shouldn’t be able to.

Here’s how it went down. Go get the current .war file from Caucho (3.1.5 as of right now). Extract it using 7-Zip, or some equally useful unzipping program. First off, copy the three .jar file (quercus.jar, script-10.jar, and resin-util.jar) into /common/lib or /common/lib/ext in your dotCMS root directory. Then, go into /liferay/WEB-INF (dotcms/WEB-INF in version 1.6 and up) and open the web.xml file. Add to it:

  1. <servlet>
  2.   <servlet-name>Quercus Servlet</servlet-name>
  3.   <servlet-class>com.caucho.quercus.servlet.QuercusServlet</servlet-class>
  4. </servlet><servlet-mapping>
  5.   <servlet-name>Quercus Servlet</servlet-name>
  6.   <url-pattern>*.php</url-pattern>
  7. </servlet-mapping>

That sets up the servlet to handle files that it is told to handle that end in .php. There is a sample web.xml folder in the files you extracted from the .war file that has other stuff like datasource and php.ini designations if you want to connect to a database or use custom PHP settings.

Now, shutdown the dotCMS server if you haven’t already. Do an ant clean and ant deploy. Copy a test php file (I used a basic HTML page with <?php phpinfo(); ?> in it) into /liferay/html on the server’s file structure, and start the server back up. Now, you should be able to open the page http://www.yourdomain.com/html/test.php and see the result page above. dotCMS is set to refer to the real file structure when it sees the folder /html in a URI (Uniform Resource Identifier), rather than its internal virtual file structure.

The kicker that fouled us up originally is that you can’t execute PHP pages from within the dotCMS file structure, since it is a virtual file structure and all the files actually exist in /liferay/assets rather than where they appear in dotCMS’s file browser. If you upload a PHP file to a directory in the back end, it will just come out as a 404, because when the Quercus Servlet tries to call the file by dotCMS’s file structure, it can’t find it’s equivalent in the real server file structure. Get it?

The solution is to this is more complicated than simply making it so there’s a way to run PHP code, and I’m working on it with some help and might get it in to 1.6 if we get it figured out fast enough. We’re trying to modify the CMSFilter.java file and extending the QuercusServlet.java file with code from the SpeedyAssetServlet.java file to make it so that when a PHP file within the dotCMS file structure is dropped to the Quercus servlet, it has the ability to ask dotCMS where in the assets folder it is to execute it. In the mean time, the PHP works with the above solution so long as you store the file in the right place.

Creating a profanity filter

Published on December 6th, 2007 in 4 Comments »

So, today I wrote the dirtiest function I have ever written in PHP. I typed more profanity at once than I think I ever have in the past. As part of a new AJAX (Asynchronous Javascript And XML) live search query displayer I wrote for our Google Mini, I had to do some filtering to make sure naughty phrases wouldn’t show up. This is a pretty straightforward script you could incorporate into different applications, like a shoutbox, or comment form.

Alternatively, you could swap in preg_replace() or eregi_replace() instead of preg_match() and censor phrases that way. In this example, I use preg_match() just to test the query, and if the filter matched, I excluded the query from display entirely. I have this set to match anything that occurs in a query, so if the word “butt” was a filter term, it would catch “butts,” “butthole,” and “buttmunch.” That saved a lot of extra typing and filtering. Yes, it increases the likelihood of a false positive, but in this case we weren’t too concerned about an overly aggressive filter.

If the filter makes a match, it returns a boolean value of true. From there, do as you will. You could build in your own handler code as well (especially if you just wanted to censor individual words).

If you have a better idea or refinement, comment below and I can tweak this appropriately.

  1. function profanityFilter($query) {
  2.   /* Set filter terms to exclude from display, including
  3.   word roots or partials. Can be regular expressions. */
  4.   $filter = array("word1","word2","word3");  
  5.  
  6.   for ($i = 0; $i < sizeof($filter); $i++) {
  7.     /* Look for a regex match, case insensitive */
  8.     if (preg_match("/".$filter[$i]."/i", $query)) {
  9.       /* Return a match, or put in your own handler */
  10.       return true;
  11.     }
  12.   }
  13. }
Click to Download This Theme

Login/Register

Sign in with OpenID
Don't have OpenID? Get one here.
(What is OpenID?)
My Vidoop More secure than passwords.

My Tweets

  • ...Got the green light to build the new campus file structure as I see fit. This will end well. 5 hrs ago
  • ...Off to meet with athletics and see if we'll have any luck wrangling them in with the site redesign. 11 hrs ago
  • ...Maintenence release 1.6.0.3 is out for dotCMS. Gentlemen, start your SVN clients. 11 hrs ago
  • More updates...

Posting tweet...

Enjoying...

Teeth30 Days of Night

The End BeginsStardust

My Stuff



Archives


My Zimbio Buddhist Blogs >