2017 © Pedro Peláez
 

library website-utilities

Website utilities based on PSR

image

previewtechs/website-utilities

Website utilities based on PSR

  • Thursday, October 5, 2017
  • by shahariaazam
  • Repository
  • 1 Watchers
  • 0 Stars
  • 59 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 7 % Grown

The README.md

Installation

composer require previewtechs/website-utilities, (*1)

General robots.txt

allow('/test')
    ->allow('/me')
    ->disallow('/thanks');

$rulesTwo = new \Previewtechs\WebsiteUtilities\RobotsDotTxtGenerator\RobotsDotTxtRules('GoogleBot');
$rulesTwo->allow('/test')
    ->allow('/me')
    ->disallow('/thanks');

$robotGenerator = new \Previewtechs\WebsiteUtilities\RobotsDotTxtGenerator\RobotsDotTxtGenerator();
$robotGenerator->addRules($rulesOne);
$robotGenerator->addRules($rulesTwo);

//To print directly
echo $robotGenerator;

//To send response directly
return $robotGenerator->respondAsTextFile(\Psr\Http\Message\ResponseInterface $response);
```

Output:
```
User-Agent: *
Allowed: /test
Allowed: /me
Disallow: /thanks

User-Agent: GoogleBot
Allowed: /test
Allowed: /me
Disallow: /thanks
```


## Generate sitemap.xml
```php
 [
        'changefreq' => 'daily',
        'priority' => 1,
        'lastmod' => date('Y-m-d')
    ],
    'https://test.com/another_test.php' => [
        'changefreq' => 'daily',
        'priority' => 2,
        'lastmod' => date('Y-m-d')
    ],
];

$gen = new \Previewtechs\WebsiteUtilities\SitemapGenerator\SitemapGenerator();
$gen->loadUrls($urls);
//If you want to send xml response directly
return $gen->respondAsXML(\Psr\Http\Message\ResponseInterface $response);

//Or, if you want to just print the sitemap
echo $gen;
```

Output:

```xml

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
                http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
    <url>
        <loc>https://site.com/test.php</loc>
        <changefreq>daily</changefreq>
        <priority>1</priority>
        <lastmod>2017-09-30</lastmod>
    </url>
    <url>
        <loc>https://test.com/another_test.php</loc>
        <changefreq>daily</changefreq>
        <priority>2</priority>
        <lastmod>2017-09-30</lastmod>
    </url>
</urlset>

301 Redirect

<?php
require "vendor/autoload.php";

//Application wide middleware
$oldAndNewPathMapping = [
    '/oldPath1' => 'newPath1',
    '/oldPath2' => 'newPath2'
];
$threeZeroOneRedirect = new ThreeZeroOneRedirectPsrMiddleware();
$threeZeroOneRedirect->setPaths($oldAndNewPathMapping);
$app->add($threeZeroOneRedirect);
//End of 301 redirect middleware

Bug & Issues

Please submit issues, questions in GitHub Issues., (*2)

Contributors

Shaharia Azam from Preview Technologies Limited. To see all contributers click here, (*3)

The Versions

05/10 2017

dev-master

9999999-dev

Website utilities based on PSR

  Sources   Download

MIT

The Requires