Piero V.

Flatpress: Next/Prev Page link and PrettyURLs

Italiano

(See below for English)

Come ho già detto in qualche post fa, sto facendo un plugin per implementare i tag su flatpress.

Dopo alcuni giorni di lavoro, pensando di averlo finito, mi accorgo di un bug: dalla seconda pagina non funziona più il filtro dei tag (e me ne sono accorto per puro caso!!)

La colpa è di Pretty URLs, che gestisce gli url delle pagine ricreandoli dall’inizio.

Le soluzioni sono quattro:

  1. Fare un plugin che non supporta PrettyURLs
  2. Fare un plugin che usi delle estensioni PECL
  3. Fare un plugin solo per PHP 4 (e io uso PHP5 😊 )
  4. Fare una classe sostitutiva a pretty urls

L’unica che mi pare accettabile è la quarta, ed ecco il codice (testato, sembra funzionare):

## Replacement Class for PrettyURLs Plugin
if(class_exists('Plugin_PrettyURLs')) {
	class class_name {
		function class_name(&$original) { # Constructor
			$this->original=&$original;
			$this->baseurl=&$original->baseurl;
		}
		function permalink($str, $id) {
			return $this->original->permalink($str, $id);
		}
		function commentlink($str, $id) {
			return $this->original->commentlink($str, $id);
		}
		function feedlink($str, $type) {
			return $this->original->feedlink($str, $type);
		}
		function commentsfeedlink($str, $type, $id) {
			return $this->original->commentsfeedlink($str, $type, $id);
		}
		function staticlink($str, $id) {
			return $this->original->staticlink($str, $id);
		}
		function categorylink($str, $catid) {
			return $this->original->categorylink($str, $catid);
		}
		function yearlink($str, $y) {
			return $this->original->yearlink($str, $y);
		}
		function monthlink($str, $y, $m) {
			return $this->original->monthlink($str, $y, $m);
		}
		function daylink($str, $y, $m, $d) {
			return $this->original->daylink($str, $y, $m, $d);
		}
		function nextprevlink($nextprev, $v) {
			if(!empty($fp_params['myparam'])) {
				## My code here
			} else
				return $this->original->nextprevlink($nextprev, $v);
		}
	}
}

Si fa il backup di $plugin_prettyurls, quindi si dà a $plugin_prettyurls questa classe:

$pretty_old=$plugin_prettyurls;
$plugin_prettyurls=new class_name($pretty_old);

Quelle sono le funzioni che occorrono all’integrazione con flatpress.

Si può modificare ciò che si vuole, basta che queste funzioni rimangano.

Io vi consiglio di chiamare la vostra classe solo se ce n’è veramente bisogno altrimenti di lasciare pretty urls originale.

English

As I’ve already said, I’m writing a tag implementation for flatpress..

After several days of work, I’ve found a bug: from the second page the tag filter doesn’t work.

Fault of PrettyURLs.

Solutions are four:

  1. Write a plugin without PrettyURLs support
  2. Write a plugin that requires PECL extensions
  3. Write a plugin only for PHP4 (and I’m using PHP5 😊 )
  4. Make a replacement for PrettyURLs class (keeping also the original class)

The Fourth is the only suitable solution (tested, it seems it works).

See code above.

To use this code, you backup $plugin_prettyurls, then you assign the class at $plugin_prettyurls (code above).

Those are functions that flatpress requires.

You can change the code, as long as these functions remain.

I advise you to call the replacement class only if it’s necessary, otherwise, don’t do it.