A tumblelog CMS built on AJAX, PHP and MySQL.

feedreplacement.php 2.6KB

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