Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [inne][HTML][PHP]Sitemapgenerator błąd
Forum PHP.pl > Forum > Przedszkole
Splatt28
Cześć witajcie, mam problem - chciałem dodać mapę strony do narzędzia webmasterskiego googla i teoretycznie jest wszystko okej ale według googla, plik jest w postaci html (dodałem xml), a po przejściu na stronę mukko.pl/sitemap.xml wyskakuje błąd "Fatal error: Call to a member function query() on null in /home/mukkopl/ftp/www.mukko.pl/engine/modules/sitemap/index.php on line 16"

  1. <?php
  2.  
  3.  
  4. require_once SVROOT . '/engine/lib/sitemap/SitemapGenerator.php';
  5.  
  6. class sitemap extends _engine {
  7.  
  8. public function init() {
  9. $this->sitemap = new SitemapGenerator();
  10. }
  11.  
  12. public function index() {
  13. $this->warA(array('keywords' => 'cms', 'title' => 'cms'));
  14.  
  15. $this->sitemap->add_link('http://localhost/test');
  16. $tab = $this->db->query("SELECT * FROM {$this->v->get('_tresci')}");
  17. foreach ($tab as $key => $val) {
  18. $this->sitemap->add_link("https://" . SVROOT . "/m/tresci/", null, 'weekly', '0.3');
  19. }
  20. file_put_contents(SVROOT . "/sitemap.xml", $this->sitemap->generate(TRUE));
  21.  
  22. $this->warB();
  23. }
  24.  
  25. }


  1. <?php
  2.  
  3. //-----------------------------------------------------------------------------
  4. /**
  5.  * Klasa generująca mapę strony.
  6.  *
  7.  */
  8. class SitemapGenerator {
  9.  
  10. /**
  11.   * Tablica linków.
  12.   * @var array of SGLink
  13.   */
  14. private $link;
  15.  
  16. /**
  17.   * Konstruktor domyślny.
  18.   */
  19. public function __construct() {
  20. $this->clear_link();
  21. }
  22.  
  23. /**
  24.   * Dodaje link. Przekazać poszczególne parametry, albo obiekt SGLink jako
  25.   * pierwszy parametr.
  26.   * @param string|SGLink $loc
  27.   * @param string $lastmod
  28.   * @param string $changefreq
  29.   * @param string $priority
  30.   * @return SitemapGenerator
  31.   */
  32. public function add_link($loc, $lastmod = NULL, $changefreq = NULL, $priority = NULL) {
  33. $this->link[] = ($loc instanceof SGLink) ? $loc : new SGLink($loc, $lastmod, $changefreq, $priority)
  34. ;
  35. return $this;
  36. }
  37.  
  38. /**
  39.   * Czyści link.
  40.   * @return SitemapGenerator
  41.   */
  42. public function clear_link() {
  43. $this->link = array();
  44. return $this;
  45. }
  46.  
  47. /**
  48.   * Zwraca link.
  49.   * @return array of SGLink
  50.   */
  51. public function get_link() {
  52. return $this->link;
  53. }
  54.  
  55. /**
  56.   * Zwraca ostatni element link.
  57.   * @return SGLink
  58.   */
  59. public function get_last_link() {
  60. return end($this->link);
  61. }
  62.  
  63. /**
  64.   * Generuje treść z headerem, albo zwraca string.
  65.   * @param bool $naglowek
  66.   * @return void|string
  67.   */
  68. public function generate($naglowek = FALSE) {
  69. $domdoc = new DOMDocument('1.0', 'UTF-8');
  70. $domdoc->formatOutput = TRUE;
  71.  
  72. $node_urlset = $domdoc->appendChild($domdoc->createElement('urlset'));
  73. $node_urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
  74.  
  75. foreach ($this->get_link() AS $link) {
  76. $node_url = $node_urlset->appendChild($domdoc->createElement('url'));
  77. $link->generate_link($node_url, $domdoc);
  78. }
  79. if ($naglowek) {
  80. header('Content-type: application/xml; charset=utf-8');
  81. echo $domdoc->saveXML();
  82. } else {
  83. return $domdoc->saveXML();
  84. }
  85. }
  86.  
  87. }
  88.  
  89. //-----------------------------------------------------------------------------
  90. /**
  91.  * Klasa reprezentująca link.
  92.  *
  93.  */
  94. class SGLink {
  95.  
  96. /**
  97.   * Adres URL strony.
  98.   * Ten adres URL musi zaczynać się od prefiksu protokołu (na przykład http) i
  99.   * kończyć kreską ułamkową, jeśli wymaga jej Twój serwer internetowy.
  100.   * Ta wartość musi być krótsza niż 2048 znaków.
  101.   * @var string
  102.   */
  103. private $loc;
  104.  
  105. /**
  106.   * Data ostatniej modyfikacji pliku.
  107.   * Ta data powinna mieć format W3C Datetime.
  108.   * Format ten umożliwia pominięcie godziny i podanie samej daty w postaci RRRR-MM-DD.
  109.   * Należy pamiętać, że ten tag jest niezależny od nagłówka If-Modified-Since (304),
  110.   * który może zwracać serwer, a wyszukiwarki mogą używać informacji z tych dwóch
  111.   * źródeł w odmienny sposób.
  112.   * @var string
  113.   */
  114. private $lastmod;
  115.  
  116. /**
  117.   * Częstotliwość zmian strony.
  118.   * Ta wartość podaje wyszukiwarkom ogólne informacje i nie może dokładnie korelować
  119.   * częstotliwości indeksowania strony. Prawidłowe wartości to:
  120.   * always hourly daily weekly monthly yearly never
  121.   * @var string
  122.   */
  123. private $changefreq;
  124.  
  125. /**
  126.   * Priorytet tego adresu URL w odniesieniu do innych adresów URL w witrynie.
  127.   * Prawidłowy jest zakres wartości od 0.0 do 1.0. Ta wartość nie ma wpływu na
  128.   * porównywanie Twoich stron ze stronami innych witryn. Umożliwia ona jedynie
  129.   * wskazanie wyszukiwarkom, które strony powinny być indeksowane przez roboty w
  130.   * pierwszej kolejności. Domyślny priorytet strony jest równy 0.5.
  131.   * @var string
  132.   */
  133. private $priority;
  134.  
  135. /**
  136.   * Konstruktor.
  137.   *
  138.   * @param string $loc
  139.   * @param string $lastmod
  140.   * @param string $changefreq - always|hourly|daily|weekly|monthly|yearly|never
  141.   * @param string $priority
  142.   */
  143. public function __construct($loc, $lastmod = NULL, $changefreq = NULL, $priority = NULL) {
  144. $this->set_loc($loc)
  145. ->set_lastmod($lastmod)
  146. ->set_changefreq($changefreq)
  147. ->set_priority($priority)
  148. ;
  149. }
  150.  
  151. /**
  152.   * Ustawia loc.
  153.   * @param string $loc
  154.   * @return SGLink
  155.   */
  156. public function set_loc($loc) {
  157. $this->loc = strip_tags((string) $loc);
  158. return $this;
  159. }
  160.  
  161. /**
  162.   * Ustawia lastmod.
  163.   * @param string $lastmod - date
  164.   * @return SGLink
  165.   */
  166. public function set_lastmod($lastmod) {
  167. $this->lastmod = strip_tags((string) $lastmod);
  168. return $this;
  169. }
  170.  
  171. /**
  172.   * Ustawia changefreq.
  173.   * @param string $changefreq - always|hourly|daily|weekly|monthly|yearly|never
  174.   * @return SGLink
  175.   */
  176. public function set_changefreq($changefreq) {
  177. $this->changefreq = NULL;
  178. if ($changefreq == 'always' OR $changefreq == 'hourly' OR $changefreq == 'daily' OR
  179. $changefreq == 'weekly' OR $changefreq == 'monthly' OR $changefreq == 'yearly' OR
  180. $changefreq == 'never') {
  181. $this->changefreq = $changefreq;
  182. }
  183. return $this;
  184. }
  185.  
  186. /**
  187.   * Ustawia priority.
  188.   * @param string $priority
  189.   * @return SGLink
  190.   */
  191. public function set_priority($priority) {
  192. $this->priority = strip_tags((string) $priority);
  193. return $this;
  194. }
  195.  
  196. /**
  197.   * Zwraca loc.
  198.   * @return string
  199.   */
  200. public function get_loc() {
  201. return htmlentities($this->loc, ENT_QUOTES, 'UTF-8');
  202. }
  203.  
  204. /**
  205.   * Zwraca lastmod.
  206.   * @return string
  207.   */
  208. public function get_lastmod() {
  209. return date('Y-m-d', strtotime($this->lastmod));
  210. }
  211.  
  212. /**
  213.   * Zwraca changefreq.
  214.   * @return string
  215.   */
  216. public function get_changefreq() {
  217. return $this->changefreq;
  218. }
  219.  
  220. /**
  221.   * Zwraca priority.
  222.   * @return string
  223.   */
  224. public function get_priority() {
  225. return $this->priority;
  226. }
  227.  
  228. /**
  229.   * Generuje DOM link
  230.   * @param DOMNode $node
  231.   * @param DOMDocument $domdoc
  232.   * @return SGLink
  233.   */
  234. public function generate_link(&$node, &$domdoc) {
  235. if ($this->loc) {
  236. $node->appendChild($domdoc->createElement('loc', $this->get_loc()));
  237. if ($this->lastmod) {
  238. $node->appendChild($domdoc->createElement('lastmod', $this->get_lastmod()));
  239. }
  240. if ($this->changefreq) {
  241. $node->appendChild($domdoc->createElement('changefreq', $this->get_changefreq()));
  242. }
  243. if ($this->priority) {
  244. $node->appendChild($domdoc->createElement('priority', $this->get_priority()));
  245. }
  246. }
  247. return $this;
  248. }
  249.  
  250. }
  251.  
  252. //-----------------------------------------------------------------------------
  253. ?>


Ktoś ma jakiś pomysł jakbym mógł to wszystko w miarę prosty sposób ogarnąć?
viking
Masz wszystkie niezbędne informacje do ustalenia błędu. $tab = $this->db->query("SELECT * FROM {$this->v->get('_tresci')}"); $this->db jest nullem czyli np nie było połączenia z bazą.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.