A tumblelog CMS built on AJAX, PHP and MySQL.

feedreplacement.php 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /*
  3. Plugin Name: FeedReplacement
  4. Plugin URI: http://plugins.gelatocms.com/feedreplacement/
  5. Description:
  6. Author: Victor Bracco
  7. Author URI: http://www.vbracco.com.ar/
  8. Version: 0.3
  9. */
  10. class feedreplacement extends plugins
  11. {
  12. public function feedreplacement()
  13. {
  14. global $user, $conf, $tumble;
  15. //agregar al los panel de options un input mas
  16. $this->addAction('add_options_panel', 'feedreplacement_setOptionsPanel');
  17. //crea o verifica que la opcion que usa de la tabla de opciones esta creada
  18. $this->addAction('gelato_init', 'feedreplacement_check');
  19. //reemplaza el link del feed de gelato por el link de feedburner
  20. //$this->addAction('add_post', 'dameCinco');
  21. //lo mismo pero con el que esta en el header
  22. $this->addAction('gelato_includes', 'feedreplacement_includeFeed');
  23. //redirecting all trafic
  24. $this->addAction('feed_header', 'feedreplacement_redirect');
  25. //guarda la opcion si viene por POST
  26. if ($user->isAdmin()) {
  27. if (isset($_POST["feedreplacement_url"])) {
  28. if (!$tumble->saveOption($_POST["feedreplacement_url"], "feedreplacement_url")) {
  29. header("Location: ".$conf->urlGelato."/admin/options.php?error=1&des=".$conf->merror);
  30. die();
  31. }
  32. }
  33. }
  34. }
  35. public function feedreplacement_setOptionsPanel()
  36. {
  37. global $conf;
  38. echo '<li><label class="help" for="feedreplacement_url">'.__("Replacement Feed:").'</label>
  39. <input type="text" name="feedreplacement_url" id="feedreplacement_url" value="'.$conf->get_option('feedreplacement_url').'" class="txt help" title="'.__("Introduce your new feed url into this input").'"/></li>';
  40. }
  41. public function feedreplacement_check()
  42. {
  43. global $db,$conf;
  44. $sqlStr = "SELECT COUNT(*) as exist FROM `".$conf->tablePrefix."options` WHERE name='feedreplacement_url' LIMIT 1";
  45. if ($db->ejecutarConsulta($sqlStr)) {
  46. $row=$db->obtenerRegistro();
  47. if ($row["exist"]==0) {
  48. $sql = "INSERT INTO `".$conf->tablePrefix."options` VALUES ('feedreplacement_url', '');";
  49. $db->ejecutarConsulta($sql);
  50. }
  51. }
  52. }
  53. public function feedreplacement_includeFeed()
  54. {
  55. global $conf,$gelato_includes,$feed_url;
  56. $feedreplacement_url = $conf->get_option('feedreplacement_url');
  57. if ($feedreplacement_url!="") {
  58. $feed_url = $feedreplacement_url;
  59. }
  60. }
  61. public function feedreplacement_redirect()
  62. {
  63. global $conf;
  64. $feedreplacement_url = $conf->get_option('feedreplacement_url');
  65. if (!preg_match("/feedburner|feedvalidator/i", $_SERVER['HTTP_USER_AGENT'])) {
  66. header("Location: ".$feedreplacement_url);
  67. header("HTTP/1.1 302 Temporary Redirect");
  68. exit();
  69. }
  70. }
  71. }