This script is part of
PLibA few bugs was fixed in this release. I also noted a few new ones but that was mostly in the SyntaxMap class which gererates PHP arrays from the SyntaxMap files.
Changelog for this version
- Fixed a bug where the end of strings (quotes) wasn’t found correctly in languages that has no escape character (like XSL, XML and HTML).
- Also changed the Syntaxer::AutoDetect() method to return the extension of a file if no alias was found. In this way we can pass a path to the method and use the result directly as argument to `Sytaxer::__construct()`
- $file = '/some/path/to/file.xsl';
- $lang = Syntaxer::AutoDetect($file);
- $stx = new Syntaxer($lang);
- $stx->Parse(file_get_contents($file));
The Syntaxer can be read about and downloaded over here.
March 25, 2007 in Misc tagged with So I’ve worked some on Redroom and the main thing was to stop the ability for robots to add comments. It will be interesting to see if it works or not, but if it doesn’t work I have a Captcha solution ready to use.
Since Captcha might be troublesome for people with impaired vision I tried a homebrewed version that doesn’t include an obscured image. The downside is that it doesn’t work with JavaScript turned off but on the other hand that means that robots shouldn’t be able to spam either.
Other than that this version of Redroom doesn’t include any new features. Some minor bug fixing was done and some code cleaning.
This script is part of
PLibI’ve released a new version of my generic syntax highlighting script Syntaxer. I fixed a potential bug where code generated on an operating system that only use \r to define a newline would be messed up (thank you jOOOL at PHPPortalen. Now I’ve bullet proofed (I hope) the way newlines are handled: I replace all \r\n with \r and then replace all \r with \n which means that we always end up with a single \n as the newline character.
The Syntaxer can be downloaded here
March 19, 2007 in Misc tagged with It’s quite fascinating: It didn’t take many days from launcing this site until the first comment spamming began! This was of course something I was aware of but I never thought it would begin so soon. I let it go on for a while just to see what those asholes want and I just don’t get it!
Anyway! I will implement some, or a few, spam filter functions. I’ve looked into Akismet which looks good. And there’s of course Captcha. This will maybe be the project for the weekend!
Go f**k your selfs, spammers!
March 18, 2007 in Misc tagged with This blog post is deprecated
I have built a little home for my various small projects. At the moment I’ve only added my syntax highlighting project Syntaxer there but more will come in the near future. The project site is located at www.poppa.se/projects/.
This script is part of
PLibA couple of years ago I wrote a generic syntax highlighting script. What I did was using the syntax files from Edit+ to determine how to parse a given language. All languages have different keywords, function names, delimiters and so on, and to know how to highlight a certain language you need to know these things. The Edit+ .stx files describes all these things.
Since I have gotten a few years more of knowledge, and PHP5 has arrived, I though I should write a new version of it. I could reuse some of the code but alot was rewritten and redesigned totally. The script has two classes:
- One class to parse the Edit+ syntax files which gets converted into PHP files so that the syntax files doesn’t have to to be parsed for every request. If the given
.stx file has a newer timestamp than the cached PHP file the PHP file will be regenerated. Alot of this code could be reused from the older version
- The actual highlighting class. This class was almost entirely rewritten. Here I loop through every character of the code to highlight. When a keyword, delimiter or something else detectable is matched I grab that and searches forward to where the rule ends. In the older version I had a different approach where the code was splitted on newlines so I looped through line by line and for each line I looped throuh each charachter and did a similar match as in the new version.
The new approach has some advantages:
- There’s no need to duplicate the code wich means a lot less memory is used.
- Fewer flags is needed since when I match a detectable rule I at once search for the end of the rule. This means that fewer
.stx statements is needed wich speeds thing up alot.
And foremost the code got much much cleaner!
Anyhow! There are a few minor bugs but the code is pretty usable (I have implemented it here in the blogging system). I added the scripts with documentation and a simple example on the server for anyone to download.
The Syntaxer2 can be found and downloaded over here. Some bug fixes and more examples will be done in the very near future.
Now I have renamed my blogging system Plogger to Redroom. As I wrote before I noticed that there is a web photo gallery named Plogger written in PHP so I just had to come up with a new name.
I decided to call it Redroom for a couple of reasons:
- It sounds pretty OK I think, short and snappy?!
- A Google search gives no (high rank) hits to anything related to any software project.
- The Red Room is probably the most famous novel by one of Swedens most (in)famous authors August Strindberg. Authors write and so do bloggers so I thought the analogy with Strindberg and The Red Room works rather well
So now I have renamed every occurance of Plogger to RedRoom in the source code. I first thought I should try grep and grep to rename every occurance in all files in one go but since I store the source in Subversion I have a lot of .svn directories that mustn’t be tempered with. What I did was I made a copy of my work area and wrote a Ruby script that did the text replacing and deleted all .svn directories. Then it was just to over write the original directory with the altered copy. All altered files was updated and the .svn directories was untouched so lastly it was just to commit the changes and that was that.
Here’s the little Ruby script:
- #!/usr/bin/ruby
-
- Discart_Files = ["logs", "data"]
-
- def Recurse_Dir(dir)
- Dir.foreach(dir) do |file|
- next if Discart_Files.include?(file) || file =~ /^\\.\\.?$/
- file_dir = dir + File::Separator + file
- `rm -Rf #{file_dir}` and next if file == '.svn'
- if File.directory?(file_dir)
- Recurse_Dir(file_dir)
- else
- if file =~ /\\.php$/
- content = IO.readlines(file_dir).join.gsub(/Plogger/, "RedRoom") \\
- .gsub(/PLOGGER/, 'REDROOM')
- File.open(file_dir, "w") { |f| f.write content }
- end
- end
- end
- end
-
- Recurse_Dir('./blog')
Whats left to rename is the desktop client, but that’s no rush!
Corporate blogging is getting more and more common and me and the editor at work have been talking about trying to get people at work adapting that as well. Since we’re a utility company dealing with stuff like district heating and cooling, waste and recycling, we’re operating power supply systems, municpality broadband network, we’re producing biogas and what not, there are plenty of knowledge in and about our corridors that would be worth writing about.
What’s important I think is that we find the right incentive for people to start blogging. Many people don’t really understand what it’s all about and what the gain would be. I can see two major reasons for blogging:
- Public opinion building/public education
You primarily write to create opinion, to share knowledge, to debate and so forth. In our case I can see how to apply this on our line of business: We do stuff that can have inflictions on the environment but everything we do we do with the environment in mind (we’re ISO 14001 certified). If you live in the municipality of Linköping you most certainly get a bill from Tekniska Verken (we supply water, broadband, heating, waste management, electricity and so on) so of course our activities, pricing and so forth is often up to debate.
I think blogging would be a great way to give the inhabitants of Linköping better insight into what we do, why we do it, how we are govern by the municipality, why our pricings are as they are and so on. We have experts on energy efficency who could educate people on how to decrease their usage of energy (a contradiction of terms for an energy company right!) and so on.
- Personal knowledge aggregation/documentation
You necessarily don’t have to write primarily for the public, but rather write for your self as a way to document your work, to keep gained knowledge/progress at the same place (my primary reason for this blog). Since alot of the work we’re doing is project based blogging could serve as a way to document projects, and of course share knowledge between projects, departments and subsidiaries.
Implementation
So, I think we will manage to find the right incentives to get a few people blogging so I started working on creating a blogging system on our Roxen CMS platform. I think the right way to get people blogging is to go along the line of the second reason above, so I though beginning on the intranet is the way to go. Now, it hit me that we have all the modules (foremost the category module) and that Roxen have alot of to the infrastructure already built in to easily create a blogging system.
The only thing I had to implement from scratch was the commenting feature which I created a Pike module for. The module is a couple of RXML tags; emit blog-comments to list comments to a specific entry, emit blog-comments to save a comment, emit blog-comments does speak for its self, and emit blog-comments which returns 1 if a comment is written by the author of the blog post and 0 otherwise.
Then I fixed some with a few XSL templates and then it was done! It took me about 6 hours to create a multi blog system we’re each blog can have multiple authors and that features searching, archiving and categorization. I don’t know how many hours I’ve spent on my PHP blog engine that I’m running this blog on, but I can tell you it’s 6 multiplied with alot
Roxen simply is really nice to work with!
Well, there’s a little polishing to do and some work to do to sell the blogging idea to the co-workers but I don’t think it will take too long before we’re blogging on the intranet and hopefully we’ll get some blogs out into the public as well later on.