Created
August 18, 2016 15:17
-
-
Save osrecio/5cd56806bcc493f2a43a7ef9498dbfcb to your computer and use it in GitHub Desktop.
Get all magento Urls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'app/Mage.php'; | |
umask(0); | |
// set store view | |
$store_view_filter = isset($_REQUEST['store_view']) ? $_REQUEST['store_view'] : false; | |
// set export type | |
$export_to = isset($_REQUEST['export_to']) ? $_REQUEST['export_to'] : false; | |
// return values | |
$urls = array(); | |
// get stores data | |
$store_views = Mage::app()->getStores(); | |
foreach ($store_views as $store_view) | |
{ | |
// skip not requested stores | |
if($store_view_filter && $store_view_filter !== $store_view->getCode()) continue; | |
$storeId = $store_view->getStoreId(); | |
$baseUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK); | |
// get categories | |
$collection = Mage::getResourceModel('sitemap/catalog_category')->getCollection($storeId); | |
$categories = new Varien_Object(); | |
$categories->setItems($collection); | |
foreach ($categories->getItems() as $item) | |
{ | |
$urls[] = $baseUrl . $item->getUrl(); | |
} | |
unset($collection); | |
// get products | |
$collection = Mage::getResourceModel('sitemap/catalog_product')->getCollection($storeId); | |
$products = new Varien_Object(); | |
$products->setItems($collection); | |
foreach ($products->getItems() as $item) | |
{ | |
$urls[] = $baseUrl . $item->getUrl(); | |
} | |
unset($collection); | |
// get cms pages | |
$collection = Mage::getResourceModel('sitemap/cms_page')->getCollection($storeId); | |
foreach ($collection as $item) | |
{ | |
$urls[] = $baseUrl . $item->getUrl(); | |
} | |
unset($collection); | |
} | |
// output | |
switch($export_to) | |
{ | |
case 'file': | |
$ioWrite = new Varien_Io_File(); | |
$path = ''; | |
$ioWrite->open(array('path' => $path)); | |
$ioWrite->streamOpen($path . 'urls.txt'); | |
foreach($urls as $url) | |
{ | |
$ioWrite->streamWrite(htmlspecialchars($url . "\r\n")); | |
} | |
$ioWrite->close(); | |
break; | |
default: | |
header_remove(); | |
header('Content-Type: text/plain', true, 200); | |
header('Expires: 0'); | |
header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0'); | |
header('Pragma: no-cache'); | |
while(ob_get_level() > 0) | |
{ | |
@ob_end_clean(); | |
} | |
foreach($urls as $url) | |
{ | |
echo htmlspecialchars($url . "\r\n"); | |
} | |
exit(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment