A tumblelog CMS built on AJAX, PHP and MySQL.

feedreplacement.php 2.8KB

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