Posted tagged ‘php’

Links for 2010-11-08

8. November 2010

TecChannel had a (German) article about one of my favorite tools: Launchy – a program for starting applications or opening web pages …

 

If you are a PHP programmer and interested in CakePHP, CakeFest was a conference for you. Not attended? There are slides online:

And according to Entwickler.COM the conference should be held in 2011 too…

 

If you are a Java programmer unit tests are a standard. Therefore mocking is also a discipline you know. If you are interested in the mock library Mockito, the DZone article „5 minute Mockito“ is worth reading.

 

 

Werbung

Links for 2009-08-05

5. August 2009

CatsWhoCode lists 15 regexps for PHP developers:

  1. Validate domain name
  2. Enlight a word from a text
  3. Enlight search results in your WordPress blog
  4. Get all images from a HTML document
  5. Remove repeated words (case insensitive)
  6. Remove repeated punctuation
  7. Matching a XML/HTML tag
  8. Matching an XHTML/XML tag with a certain attribute value
  9. Matching hexadecimal color values
  10. Find page title
  11. Parsing Apache logs
  12. Replacing double quotes by smart qutotes
  13. Checking password complexity
  14. WordPress: Using regexp to retrieve images from post
  15. Generating automatic smileys

On 4.September there is a Symfony Day in Cologne, Germany. This one day conference about the PHP framework will be helt in English.

Joel Reyes from NoUpe wrote about PHP frameworks. After in introduction he compares

Stefan Priebsch publishes his slides from his webinar „Migration to PHP 5.3“.

Microsoft publishes an eBook about virtualization for free. The title „Understanding Microsoft Virtualization Solutions“.

Links for 2009-07-28

28. Juli 2009

GrepCode is a search index for open source available java code. Searchable codebases are OpenJDK, Maven-Central, JBoss.com, Jetty.Mortbay.org and Eclipse 3.4.2. If you miss ‚your‘ project you could send them a message.

Zend Technologies published seven screencast about PHP development with Eclipse PDT 2.1.

  • Code Navigation
  • Code Analysis and Auto-fix
  • PHP 5.3 Development
  • PHP Code Refactoring
  • RAD Tools
  • Root Cause Analysis
  • Jump Starting Web Application Development
  • Using Zend Studio & Server Integration

Lawers found newsletter about open source topics – in their focus. (Sorry, too much special words for me to translate the German article 😉

Netbeans 6.7 Maven and Hudson Demo

eBook „Mastering PowerShell“ available for free.

Links for 2009-05-29

29. Mai 2009

There is a new Windows 7 Blog by Microsoft MVPs

On DrBacchus is also a short article about the PHP MVC framework CakePHP. And a list of top-10 php frameworks on mustap.com

On MSDN there is a five part webcast series about programming with the task parallel library which will be part of Visual Studio 2010.

In his blog Jason Zander shows the highlights of VS 2010 and .NET 4.0.

Microsoft publishes a free tool for developing secure software.

JBoss 5.1 is out.

On Windowsblog@TheShop.at is a compatibility list of programs on Windows 7.

If you need an additional automat in your office (very nice for lunch) have a look at this video.

MP3-Listing

24. Februar 2009

In the internal of my ensemble NiederrheinBrass we host the records of the last concerts. But I am lazy – why should I update that page each time I upload a new MP3? All required information are online: the URL of the file, title+record date as ID3 tags. And we have PHP…

So first a note: I am not a PHP programmer. I usually write in Java. So maybe these codings are not the best from a PHP view point. But that works …

I use the free Mphp3 script. But I just have seen that this not maintained any more… But you could the principles with another Read-ID3-Tag-Infos-PHP-Skript.

<?php
    // Einbinden der MP3-Funktionalität
    include('mphp3.php');
?>

Generating the content is easy – just

<?php
    // Einbinden der MP3-Funktionalität
    include('mphp3.php');

    $daten = new Daten();
    $daten->run();
?>

Ok – two things here: constructor and run() 😉

I don’t have implemented a constructor. The run() method asks a factory for a Generator and then that generator for the HTML. I use the factory and different generators because I not only need the MP3 listing …

<?php
    // include MP3 functions
    include('mphp3.php');

    $daten = new Daten();
    $daten->run();

    //==============================================================================================        

    /**
     * Create HTML listing.
     */
    class Daten {
        /** Start-Funktion */
        public function run() {
            $generator = $this->createGenerator();
            $generator->ausgabe();
        }

        /**
         * Factory
         * @return generator
         */
        private function createGenerator() {
            if ($_GET['art'] == "aufnahmen") {
                return new Aufnahmen();
            }
            if ($_GET['art'] == "bandstuecke") {
                $rv = new Aufnahmen();
                $rv->art = "bandstuecke";
                return $rv;
            }
            if ($_GET['art'] == "noten") {
                return new Noten();
            }
            return new Fehler();
        }
    }
?>

So the the URL …./index.php?aufnahmen starts my MP3-Generator.

For the generator I use an (abstract) class and four concrete classes. The parent class is not really abstract. It is just not instantiated by the factory. The parent class contains four fields for

  1. what should be generated? (aufnahmen should generate the MP3)
  2. what is the HTML file? (caching the work)
  3. what subdirectories should be scanned?
  4. what is the working directory for the generator?
    /**
     * Baseclass for Generators.
     */
    class Generator {
        var $art;
        var $htmlFile;
        var $dirs = array();
        var $curDir;

        /**
         * Generates HTML.
         */
        public function ausgabe() {
            $this->htmlFile = $this->art . ".html";
            // Caching
            if ($this->needsGeneration()) {
                // Generate
                // Activate buffer and write into that.
                ob_start();
                $this->generate();
                // Write buffer to file
                $html = ob_get_clean();
                $fd = fopen($this->htmlFile, "w");
                fwrite($fd, $html);
                fclose($fd);
            }
            // Just/finally pass file content to client
            readfile($this->htmlFile);
        }

        /**
         * Checks timestamp of the html file against all timestamps of the files.
         * @return true if there a new files
         */
        protected function needsGeneration() {
            if (!file_exists($this->htmlFile)) {
                # No html file, generation required
                return true;
            } else {
                $mtimeHtml = filemtime($this->htmlFile);
                $mtimeDir  = $this->getMTime($this->art);
                if ($mtimeHtml < $mtimeDir) {
                    # HTML too old, new generation required
                    return true;
                } else {
                    # no new content, no generation required
                    return false;
                }
                return $mtimeHtml < $mtimeDir;
            }
        }
&#91;/sourcecode&#93;

The easiest generator is the error generator. The factory creates that if there is an invalid URL argument. It prints an error message. It works as NullObject so I don't need to check all arguments.

&#91;sourcecode language='php'&#93;
    /**
     * "Generator" for error text.
     * @see NullObject Design Pattern
     */
    class Fehler extends Generator {
        // Überschreibe ausgabe() anstelle generate(), um das Caching zu deaktivieren.
        function ausgabe() {
            echo "Fehlerhafte Auswahl. Eventuell ist der Link falsch.";
        }
    }
&#91;/sourcecode&#93;

Before I show the implementation of the MP3-Generator, I show the directory layout used:
<ul>
	<li>Under the index.php (with the generator) there is one directory for each concrete generator. So here <em>aufnahmen</em>.</li>
	<li>The directory layout for each generator could be different. For this generator it contains directories with the date of the concert (yyyyMMdd).</li>
	<li>Each concert directory could contain an ort.inc with the place where we played. I use its content as header.</li>
	<li>Each concert directory could (should) contain *.mp3 files with ID3v2 tags.</li>
</ul>

    class Generator {
        /**
         * Generation. Subclasses should overwrite this.
         */
        protected function generate() {
            $this->dirs = $this->getDirs();
            $firstOpenElement = $this->dirs[0];

            $this->htmlHeader();
            $this->htmlBodyStart($firstOpenElement);
            $this->htmlNavigation();

            echo "
<div id=\"Inhalt\">\n";
            foreach($this->dirs as $dir) {
                $this->curDir = $this->art . "/$dir";
                $titel = $this->getTitel($dir);
                echo "
<div class=\"hideable\" id=\"id$dir\">\n";
                echo "
<h2>$titel</h2>
\n";
                @readfile($this->curDir . "/header.inc");
                echo "
<table border=\"1\" cellspacing=\"0\" cellpadding=\"4\">\n";
                $this->htmlInhaltUeberschrift();
                $files = $this->getFiles($this->curDir);
                foreach($files as $file) {
                    $this->htmlInhaltZeile("$this->curDir/$file", $file);
                }
                echo "</table>
\n";
                echo "</div>
\n";
            }
            echo "</div>
\n\n";

            $this->htmlFooter();
        }
    }

 //==============================================================================================        

    /**
     * Generator for MP3-Listing.
     */
    class Aufnahmen extends Generator {
        /** Construktor. */
        public function Aufnahmen() {
            $this->art = "aufnahmen";
        }

        /*
         * The newest record on top.
         * @Override
         */
        protected function sortDirs($array) {
            $rv = $array;
            sort($rv);
            return array_reverse($rv);
        }

        /* @Override */
        protected function getTitel($dir) {
            $aufnahmeDatum = ereg_replace("(....)(..)(..)", "\\3.\\2.\\1", $dir);
            $incFile = $this->art . "/$dir/ort.inc";
            if (file_exists($incFile)) {
                return $aufnahmeDatum . " " . file_get_contents($incFile);
            } else {
                return $aufnahmeDatum;
            }
        }

        /* @Override */
        protected function htmlInhaltUeberschrift() {
            echo "
<tr>
<th>Name</th>
<th>Interpret</th>
<th>Dauer</th>
<th>Größe</th>
</tr>
\n";
        }

        /* @Override */
        protected function htmlInhaltZeile($file, $filename) {
            ...
        }
    }

The generate() method of the abstract class generates the common HTML layout. Subclasses should overwrite only special methods and hook there content into the common layout. I dont want to write over the layout, the CSS for that or the javascript used there.

The real content should be in a <div> section with the id Inhalt. For each concert directory (subdirectory of the generator) a <div> with the titel and content is placed. The content is a HTML table contained of a header row and a data row for each file. The methods used are htmlInhaltUeberschrift() for the table header row and htmlInhaltZeile() for the data rows.

The header creates columns for name, actor, time and filesize of the file.

/* @Override */
protected function htmlInhaltZeile($file, $filename) {
    if (!$this->endsWith($filename, ".inc")) {
        echo "
<tr>";
        if ($this->endsWith($filename, ".mp3")) {
            $info = new mphp3();
            $info->load($file);
            if ($info->valid) {
                $titel   = ($info->v2_title)  ? $info->v2_title  : $info->v1_title;
                $artist  = ($info->v2_artist) ? $info->v2_artist : $info->v1_artist;
                $dauer   = $info->lengthstring;
                $anzeige = ($titel) ? $titel : $filename;
                echo "    ";
                echo "
<td><a href=\"$file\">$anzeige</a></td>
";
                echo "
<td>$artist</td>
";
                echo "
<td>$dauer min</td>
";
            }
            $size = round(filesize($file) / 1024 / 1024, 1);
            echo "
<td>$size MB</td>
";
        } else {
            echo "
<td colspan=\"3\"><a href=\"$file\">$filename</a></td>
";
        }
        echo "</tr>
\n";
    } else {
        // Keine Ausgabe der *.inc Dateien
    }
}
}

Basically this method

  • ignores *.inc files
  • for *.mp3
    • instantiate the MP3 reader
    • read title, artist and length via that reader (id3v2 if possible, id3v1 else)
    • read the filesize in MB
  • create a data row

Links for 2009-02-20

20. Februar 2009

Entwickler.com announces the availability of SharpDevelop 3. New features and improvements are in F#, FormsDesigner, Boo, XML-documentation and translation.

Microsoft Press published a free eBook about virtualization. Main topics are

  • server virtualization with Hyper-V
  • System Center Virtual Machine Manager
  • application virtualization with App-V
  • presentation virtualization with terminal services

Chip.de solicts the Free M4a to MP3 Converter.  It converts AAC- and MPEG-4-files into MP3- or WAV-files.

If you want to work with PDF files – I mean dividing one PDF into several files and things like that – I got a recommendation for pdfrecycle. „What is pdfrecycle? pdfrecycle creates a PDF file by composing pages from other PDF files. It lets you define PDF bookmarks, scale and rotate pages, put multiple logical pages onto each physical sheet and add metadata. pdfrecycle uses a simple text file format to define the layout and what pages to include. From this input file pdfrecycle creates a LaTeX file and then runs pdflatex to produced the PDF file.“

If you start evaluating an IDE for PHP development, these links could be interesting: an article at SmashingMagazine and a spreadsheet@Google. Evaluated are PDT 1, PDT 2.0, Zend Studio 6, NetBeans 6.5, NetBeans 7 (Development-Version), Aptana PHP, Aptana Studio Pro, Codelobster, Nusphere PhpED 5.6 – IDEs (Integrated Development Environment).

CreateOrDie found a listing of 25 generators for use of building websites or parts of websites: 3D-boxes, preloaders, buttons, …

If you want to teach or learn SQL-Joins this article at CodeProject is worth reading. It shows a nice graphical overview of different SQL commands.

Entwickler.com announced a webcast about software tests in Visual Studio. It is presented by MSDN and includes integration of Team Foundation Server.

Chip.de gives the eBook „Webseiten professionell erstellen“ by Stefan Münz for free. 1200 pages about basics and expert knowledge of static and dynamic web development. It covers HTML, CSS, JavaScript, PHP and MySQL. Also Web 2.0, AJAX and RSS. Setting up the environment with Apache and Linux. The current version 3 is available in your bookstores, the 2nd version here for free.

Computerwoche.de has a nice article about using the Wii remote control for converting a simple wall to a whiteboard. (Sorry, article in German. Maybe there are links to English resources.)

Golem found the announcement of the Fraunhofer Institute about a „conference system for your living room“. They have a booth at Cebit 2009 – hall 13, booth B24. The running system should be presented inside the EU-project „Together Anywhere, Together Anytime“ (TA2) at IFA 2009.

A blog at Technet offers a free e-course about virtualization.

Links for 2008-10-06

6. Oktober 2008

Five tips for better developing PHP applications: use MVC framework, use AJAX library, use IDE, use DB management software, use an O2R mapper. With more details in that blog.

Core Java Refcard Available

Links 2008.09.16

16. September 2008

On DatabaseJournal Sean Hull shows how to use PHP with Oracle instead of LAMP.

xAMP @ Mobile

10. Dezember 2007

Hooray – there will be an AMP-Stack for mobiles 😉

As Golem announced Nokia works on a port of Apache, MySQL and PHP for Symbian S60 operating system.

Mmmh … what could you do with this? A SVN-Server with access over that Apache? A PHP based project wiki and bug tracking? Then just lay your mobile on your desk and you could connect to that „project server“ via bluetooth …

IT-News 2007.10.10

10. Oktober 2007

PHP-Videotutorials for Webdesigners

(English) Article: Concurrency Testing in Java Applications

Create Web services in two clicks thanks to Apache CXF and AOP
This sounds really cool – enhancing existing classes with webservice capability by using AOP. But I could also think about another aproach: deploy a POJO into a container and just describe which methods should be opened … mmh, sounds like Java6 with the information of the annotions in an extra file … But I think document centric development would be better because of interoperability with other languages.

Eclipse ETranslator
Nice – a plugin which translates I18N resource files into other languages … but you (or better a native speaker) should check the results – I dont trust automatic translations …