A tumblelog CMS built on AJAX, PHP and MySQL.

feedreplacement.php 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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;
  51. $feedreplacement_url = $conf->get_option('feedreplacement_url');
  52. if($feedreplacement_url!=""){
  53. $feed = ($conf->urlFriendly?"/rss/":"/rss.php");
  54. $url = $conf->urlGelato.$feed;
  55. $gelato_includes = str_replace($url,$feedreplacement_url,$gelato_includes);
  56. }
  57. }
  58. function feedreplacement_redirect(){
  59. global $conf;
  60. $feedreplacement_url = $conf->get_option('feedreplacement_url');
  61. if (!preg_match("/feedburner|feedvalidator/i", $_SERVER['HTTP_USER_AGENT'])) {
  62. header("Location: ".$feedreplacement_url);
  63. header("HTTP/1.1 302 Temporary Redirect");
  64. exit();
  65. }
  66. }
  67. }
  68. ?>