PHP code example of vinicius73 / seotools

1. Go to this page and download the library: Download vinicius73/seotools library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vinicius73 / seotools example snippets


// Service provider
'Vinicius73\SEO\Providers\SEOServiceProvider',

// Facades (can customize if preferred)
'SEOMeta'     => 'Vinicius73\SEO\Facades\Meta',
'SEOSitemap'  => 'Vinicius73\SEO\Facades\Sitemap',
'OpenGraph'   => 'Vinicius73\SEO\Facades\OpenGraphHelper',

class CommomController extends BaseController
{

	/**
	 * @return \Illuminate\View\View
	 */
	public function index()
	{
		SEOMeta::setTitle('Home');
        SEOMeta::setDescription('Isto é a minha descrição de página'); // is automatically limited to 160 characters
        OpenGraph::addImage('full-url-to-image-1.png');
        OpenGraph::addImage('full-url-to-image-2.png');
        
		$posts = Post::all();

        return View::make('myindex', compact('posts'));
	}
    
    /**
     * @return \Illuminate\View\View
	 */
    publicc function show($id)
    {
        $post = Post::find($id);
        
        SEOMeta::setTitle($post->title);
        SEOMeta::setDescription($post->resume);
        SEOMeta::addMeta('article:published_time', $post->published_date->toW3CString(), 'property');
        SEOMeta::addMeta('article:section', $post->category, 'property');
        // Vinicius73\SEO\Generators\MetaGenerator::addMeta($meta, $value, $name);
        SEOMeta::setKeywords($post->tags);
        // Vinicius73\SEO\Generators\MetaGenerator::setKeywords(['key1','key2','key3']);
        // Vinicius73\SEO\Generators\MetaGenerator::setKeywords('key1, key2, key3');
        OpenGraph::addImage($post->thumbnail_url);
        
        return View::make('myshow', compact('post'));
    }
}

class SitemapRun
{

    /**
	 * @var \Vinicius73\SEO\Generators\SitemapGenerator
	 */
	public $generator;

	public function __construct($generator)
	{
		$this->generator = $generator;
	}

	/**
	 * Run generator commands
	 */
	public function run()
	{
    	return $this->index();
	}
    
    public function index()
    {
        $this->generator->addRaw(
    		array(
				  'location'         => '/sitemap-posts.xml',
				  'last_modified'    => '2013-12-28',
				  'change_frequency' => 'weekly',
				  'priority'         => '0.95'
			)
		);
        
        return $this->response($this->generator->generate());
    }
    
    public function posts()
    {
        $posts = Post::all();
        
        foreach($posts as $post)
        {
            $images = $post->images;
            
            $element = array(
        			  'location'         => route('route.to.post.show', $post->id),
    				  'last_modified'    => $post->published_date->toW3CString(),
    				  'change_frequency' => 'weekly',
    				  'priority'         => '0.90'
    			);
                
            if ($images):
    			$element['images'] = array();
				foreach ($images as $image):
					$element['images'][] = $image->url();
				endforeach;
			endif;
            
            $this->generator->addRaw($element);
        }
        
        return $this->response($this->generator->generate());
    }
    
    /**
     * @param $sitemap
	 *
	 * @return \Illuminate\Http\Response
	 */
	private function response($sitemap)
	{
		return Response::make($sitemap, 200, array('Content-Type' => 'text/xml'));
	}
}