/mods/_standard/rss_feeds/add_feed.php

https://github.com/cindyli/ATutor · PHP · 110 lines · 75 code · 15 blank · 20 comment · 18 complexity · 598a7a67a7974a50af7b863cfe95f17f MD5 · raw file

  1. <?php
  2. /************************************************************************/
  3. /* ATutor */
  4. /************************************************************************/
  5. /* Copyright (c) 2002-2010 */
  6. /* Inclusive Design Institute */
  7. /* http://atutor.ca */
  8. /* */
  9. /* This program is free software. You can redistribute it and/or */
  10. /* modify it under the terms of the GNU General Public License */
  11. /* as published by the Free Software Foundation. */
  12. /************************************************************************/
  13. // $Id$
  14. define('AT_INCLUDE_PATH', '../../../include/');
  15. require(AT_INCLUDE_PATH . 'vitals.inc.php');
  16. admin_authenticate(AT_ADMIN_PRIV_RSS);
  17. if (isset($_POST['cancel'])) {
  18. $msg->addFeedback('CANCELLED');
  19. header("Location: index.php");
  20. exit;
  21. } else if (isset($_POST['submit'])) {
  22. $missing_fields = array();
  23. if (trim($_POST['title']) == '') {
  24. $missing_fields[] = _AT('title');
  25. }
  26. if (trim($_POST['url']) == '') {
  27. $missing_fields[] = _AT('url');
  28. }
  29. if ($missing_fields) {
  30. $missing_fields = implode(', ', $missing_fields);
  31. $msg->addError(array('EMPTY_FIELDS', $missing_fields));
  32. }
  33. if (!$msg->containsErrors()) {
  34. $output = make_cache_file(0);
  35. if (!isset($output) || empty($output)) {
  36. $msg->addError('FEED_NO_CONTENT');
  37. }
  38. }
  39. if ($msg->containsErrors()) {
  40. unset($_POST['confirm']);
  41. }
  42. $hidden_vars['new'] = '1';
  43. $hidden_vars['title'] = $_POST['title'];
  44. $hidden_vars['url'] = $_POST['url'];
  45. $hidden_vars['output'] = $output;
  46. require (AT_INCLUDE_PATH.'header.inc.php');
  47. $msg->addConfirm('ADD_FEED', $hidden_vars);
  48. $msg->printConfirm();
  49. echo $output;
  50. require (AT_INCLUDE_PATH.'footer.inc.php');
  51. exit;
  52. } else if (isset($_POST['submit_no'])) {
  53. $msg->addFeedback('CANCELLED');
  54. require (AT_INCLUDE_PATH.'header.inc.php');
  55. $savant->assign('title', $_POST['title']);
  56. $savant->assign('url', $_POST['url']);
  57. $savant->display('admin/system_preferences/add_feed.tmpl.php');
  58. require (AT_INCLUDE_PATH.'footer.inc.php');
  59. exit;
  60. } else if (isset($_POST['submit_yes'])) {
  61. $_POST['url'] = $addslashes($_POST['url']);
  62. $sql = "INSERT INTO %sfeeds VALUES (NULL, '%s')";
  63. $result = queryDB($sql, array(TABLE_PREFIX, $_POST['url']));
  64. $feed_id = at_insert_id();
  65. //copy load file
  66. copy('load_file.php', AT_CONTENT_DIR.'feeds/'.$feed_id.'_rss.inc.php');
  67. //add language
  68. $title_file = AT_CONTENT_DIR.'feeds/'.$feed_id.'_rss_title.cache';
  69. if ($f = @fopen($title_file, 'w')) {
  70. fwrite ($f, $_POST['title'], strlen($_POST['title']));
  71. fclose($f);
  72. }
  73. //add url
  74. $output = $_POST['output']; //make_cache_file($feed_id);
  75. $output_file = AT_CONTENT_DIR.'feeds/'.$feed_id.'_rss.cache';
  76. if ($fc = @fopen($output_file, 'w')) {
  77. fwrite ($fc, $output);
  78. fclose($fc);
  79. }
  80. $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
  81. header('Location: index.php');
  82. exit;
  83. }
  84. $onload = 'document.form.title.focus();';
  85. //$hidden_vars['new'] = '1';
  86. //$hidden_vars['title'] = $_POST['title'];
  87. //$hidden_vars['url'] = $_POST['url'];
  88. //$msg->addConfirm(array('ADD_FEED', $hidden_vars));
  89. require (AT_INCLUDE_PATH.'header.inc.php');
  90. $msg->printConfirm();
  91. //$savant->assign('msg', $msg);
  92. $savant->assign('output', $output);
  93. $savant->assign('title_file', $title_file);
  94. $savant->display('admin/system_preferences/add_feed.tmpl.php');
  95. require (AT_INCLUDE_PATH.'footer.inc.php'); ?>