Code Monkey home page Code Monkey logo

pico_sitemap's People

Contributors

davekin avatar davekinsella avatar ndm13 avatar robby- avatar theshka avatar wlabarron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pico_sitemap's Issues

exclude List for Sitemap

I added another Var to exclude folders from the Sitemap, for example: slider, home-parts, search
And added the <lastmod> Attribute.

class Pico_Sitemap {
    private $is_sitemap;
    private $exclude;
public function __construct(){
    $this->is_sitemap = false;
    $this->exclude = array('home', 'slider', 'suche');
}
public function get_pages(&$pages, &$current_page, &$prev_page, &$next_page) {
    if($this->is_sitemap) {
        global $config;
        header($_SERVER['SERVER_PROTOCOL'].' 200 OK');
        header('Content-Type: application/xml; charset=UTF-8');
        $xml = '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
        foreach( $pages as $page ) {
            preg_match('/\/('.implode('|', $this->exclude).')\//', $page['url'].'/', $matches);
            if(empty($matches)) {
                $index = '';
                $date = '';
                $path = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'content'.DIRECTORY_SEPARATOR.str_ireplace($config['base_url'], '', $page['url']);
                if(is_dir($path)) { $index = 'index'; }
                $file = realpath($path.$index.'.md');
                if(file_exists($file)) { $date = date ("Y-m-d", filemtime($file)); }
                $xml .= '<url><loc>'.$page['url'].'</loc><lastmod>'.$date.'</lastmod></url>';
            }
        }   
        $xml .= '</urlset>';
        header('Content-Type: text/xml');
        die($xml);
    }
}

add a HTML-Sitemap with Bootstrap 3 Markup

I added a $twig_var for a HTML-Sitemap with Bootstrap3 Markup und combined the other things from my last Issue #5

<?php

/**
 * Generate an xml sitemap for Pico
 *
 * @author Dave Kinsella
 * @link https://github.com/Techn0tic/Pico_Sitemap
 * @license http://opensource.org/licenses/MIT
 */
class Pico_Sitemap {
    private $is_sitemap;
    private $is_html_sitemap;
    private $exclude;
    private $pages;

    public function __construct() {
        $this->is_sitemap = false;
        $this->is_html_sitemap = false;
        $this->exclude = array('home', 'slider', 'suche', 'sitemap');
        $this->pages = array();
    }

    public function request_url(&$url) {
        if($url == 'sitemap') $this->is_html_sitemap = true;
        if($url == 'sitemap.xml') $this->is_sitemap = true;
    }

    public function get_pages($pages) {
        if($this->is_sitemap || $this->is_html_sitemap) {
            global $config;
            foreach($pages as $page) {
                preg_match('/\/('.implode('|', $this->exclude).')\//', $page['url'].'/', $matches);
                if(empty($matches)) {
                    $index = '';
                    $date = false;
                    $path = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'content'.DIRECTORY_SEPARATOR.str_ireplace($config['base_url'], '', $page['url']);
                    if(is_dir($path)) { $index = 'index'; }
                    $file = realpath($path.$index.'.md');
                    if(file_exists($file)) { $date = date ("Y-m-d", filemtime($file)); }
                    array_push($this->pages, array( 'url' => $page['url'], 'title' => $page['title'], 'lastmod' => $date, 'index' => $index == '' ? false : true ));
                }
            }
            sort($this->pages);
        }
    }

    public function before_render(&$twig_vars, &$twig, &$template) {
        if($this->is_sitemap) {
            header($_SERVER['SERVER_PROTOCOL'].' 200 OK');
            header('Content-Type: application/xml; charset=UTF-8');
            $xml = '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
            foreach($this->pages as $page) {
                $xml .= '<url><loc>'.$page['url'].'</loc><lastmod>'.$page['lastmod'].'</lastmod></url>';
            }
            $xml .= '</urlset>';
            header('Content-Type: text/xml');
            die($xml);
        } elseif($this->is_html_sitemap) {
            $panel_raw = '<div class="col-md-4"><div class="panel panel-primary"><div class="panel-heading"><h3 class="panel-title"><a href="%url%">%title%</a></h3></div><div class="list-group">%childs%</div></div></div>';
            $child_raw = '<a href="%url%" class="list-group-item"><i class="icon-link"></i> %title%</a>';

            $panel = '';
            $childs = array();
            $out = '';
            $out .= '<div class="row">';
            foreach($this->pages as $page) {
                if($page['index']) {
                    $panel = str_replace('%childs%', implode('', $childs), $panel);
                    $out .= $panel;
                    $childs = array();
                    $panel = $panel_raw;
                    $panel = str_replace('%url%', $page['url'], $panel);
                    $panel = str_replace('%title%', $page['title'], $panel);
                } else {
                    $child = $child_raw;
                    $child = str_replace('%url%', $page['url'], $child);
                    $child = str_replace('%title%', $page['title'], $child);
                    array_push($childs, $child);
                }
            }
            $panel = str_replace('%childs%', implode('', $childs), $panel);
            $out .= $panel;
            $out .= '</div>';
            $twig_vars['sitemap'] = $out;
        }
    }
}

error on line 1 at column 7

This page contains the following errors:

error on line 1 at column 7: XML declaration allowed only at the start of the document
Below is a rendering of the page up to the first error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.