Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[+FEATURE] implemented first prototype

  • Loading branch information...
commit 78232eb95b3a78898577539aec7316b758075494 1 parent 5fdd292
@smeuser smeuser authored
View
76 src/app/code/community/Hackathon/TemplateCleanup/Helper/Data.php
@@ -0,0 +1,76 @@
+<?php
+class Hackathon_TemplateCleanup_Helper_Data extends Mage_Core_Helper_Abstract
+{
+ public function extractTemplatesFromBlockNodes($node, &$data)
+ {
+ if($node->{block}) {
+ $this->extractTemplatesFromBlockNodes($node->{block}, $data);
+ }
+
+ if(is_array($node)) {
+ foreach($node as $subnode) {
+ $this->extractTemplatesFromBlockNodes($subnode, $data);
+ }
+ }
+ else if($node->getAttribute('type') && $node->getAttribute('template')) {
+ $data[] = $node->getAttribute('template');
+ }
+ else if($blockType = $node->getAttribute('type')) {
+ try {
+ if(preg_match('/sales\/order/', $blockType)) {
+ $data[] = preg_replace('/_/', '/', $blockType) . '.phtml';
+ }
+ else {
+ switch($blockType) {
+ case 'xmlconnect/customer_giftcardCheck': break;
+ default:
+ $className = Mage::getConfig()->getBlockClassName($node->getAttribute('type'));
+ $template = $this->fetchTemplateFromClassCode($className);
+ if($template) {
+ $data[] = $template;
+ }
+ }
+ }
+ }
+ catch(Exception $e) {
+ Mage::logException(new Exception('extract template from block type \'' . $node->getAttribute('type') . '\' failed.'));
+ }
+ }
+
+ return $data;
+ }
+
+ public function extractTemplatesFromActionNodes($node, &$data)
+ {
+ if(is_array($node)) {
+ $this->extractTemplatesFromActionNodes($node, $data);
+ continue;
+ }
+ else if($node->getAttribute('method') && $node->getAttribute('method') == 'setTemplate' && (string)$node->{template}) {
+ $data[] = (string)$node->{template};
+ }
+
+ return $data;
+ }
+
+ public function fetchTemplateFromClassCode($className)
+ {
+ $reflClass = new ReflectionClass($className);
+ $classCode = file_get_contents($reflClass->getFileName());
+
+ $templates = array();
+ preg_match_all('/this->setTemplate\(\'(.*)\'\)/', $classCode, $templates);
+
+ if(count($templates) > 1 && count($templates[1]) > 0)
+ {
+ return $templates[1][0];
+ }
+ elseif($parentClass = $reflClass->getParentClass())
+ {
+ Zend_Debug::dump($parentClass);
+ return $this->fetchTemplateFromClassCode($parentClass);
+ }
+
+ return false;
+ }
+}
View
38 src/app/code/community/Hackathon/TemplateCleanup/Model/Observer.php
@@ -0,0 +1,38 @@
+<?php
+
+class Hackathon_TemplateCleanup_Model_Observer
+{
+ public function fetchUsedTemplates()
+ {
+ $update = Mage::getModel('core/layout_update');
+ $design = Mage::getDesign();
+ $storeId = 1;
+
+ $result = $update->getFileLayoutUpdatesXml(
+ $design->getArea(),
+ $design->getPackageName(),
+ $design->getTheme('layout'),
+ $storeId
+ );
+
+ $data = array();
+ foreach($result->xpath('//block') as $handle) {
+ Mage::helper('hackathon_templatecleanup')->extractTemplatesFromBlockNodes($handle, $data);
+ }
+
+ foreach($result->xpath('//action') as $handle) {
+ Mage::helper('hackathon_templatecleanup')->extractTemplatesFromActionNodes($handle, $data);
+ }
+
+ Zend_Debug::dump(count($result->xpath('//block')));
+ Zend_Debug::dump(count(array_unique($data)));
+ Zend_Debug::dump(array_unique($data));
+ Zend_Debug::dump(
+ array(
+ 'area' => $design->getArea(),
+ 'package' => $design->getPackageName(),
+ 'theme' => $design->getTheme('layout'),
+ )
+ );
+ }
+}
View
85 src/app/code/community/Hackathon/TemplateCleanup/Model/Sitemap.php
@@ -0,0 +1,85 @@
+<?php
+/*
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * It is available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ *
+ * @category Hackathon
+ * @package TemplateCleanup
+ * @copyright Copyright (c) 2011 Hackathon
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ */
+
+class Hackathon_TemplateCleanup_Model_Sitemap extends Mage_Sitemap_Model_Sitemap
+{
+ /**
+ * Generate XML file
+ *
+ * @return XML
+ */
+ public function generateXml()
+ {
+/* $io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>' . "\n");
+ $io->streamWrite('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'); */
+
+ $storeId = $this->getStoreId();
+ $date = Mage::getSingleton('core/date')->gmtDate('Y-m-d');
+ $baseUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
+
+ $data = new Varien_Object();
+ $data->setLinks(array());
+
+ /**
+ * Generate categories sitemap
+ */
+ $collection = Mage::getResourceModel('sitemap/catalog_category')->getCollection($storeId);
+ foreach ($collection as $item) {
+ array_push($data->getLinks(), $item->getUrl());
+ }
+ unset($collection);
+
+ /**
+ * Generate products sitemap
+ */
+ $changefreq = (string)Mage::getStoreConfig('sitemap/product/changefreq', $storeId);
+ $priority = (string)Mage::getStoreConfig('sitemap/product/priority', $storeId);
+ $collection = Mage::getResourceModel('sitemap/catalog_product')->getCollection($storeId);
+ foreach ($collection as $item) {
+ $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>',
+ htmlspecialchars($baseUrl . $item->getUrl()),
+ $date,
+ $changefreq,
+ $priority
+ );
+ $io->streamWrite($xml);
+ }
+ unset($collection);
+
+ /**
+ * Generate cms pages sitemap
+ */
+ $changefreq = (string)Mage::getStoreConfig('sitemap/page/changefreq', $storeId);
+ $priority = (string)Mage::getStoreConfig('sitemap/page/priority', $storeId);
+ $collection = Mage::getResourceModel('sitemap/cms_page')->getCollection($storeId);
+ foreach ($collection as $item) {
+ $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>',
+ htmlspecialchars($baseUrl . $item->getUrl()),
+ $date,
+ $changefreq,
+ $priority
+ );
+ $io->streamWrite($xml);
+ }
+ unset($collection);
+
+ $io->streamWrite('</urlset>');
+ $io->streamClose();
+
+ $this->setSitemapTime(Mage::getSingleton('core/date')->gmtDate('Y-m-d H:i:s'));
+ $this->save();
+
+ return $this;
+ }
+}
View
20 src/app/code/community/Hackathon/TemplateCleanup/etc/config.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+<config>
+ <modules>
+ <Hackathon_TemplateCleanup>
+ <version>0.0.1</version>
+ </Hackathon_TemplateCleanup>
+ </modules>
+ <global>
+ <models>
+ <hackathon_templatecleanup>
+ <class>Hackathon_TemplateCleanup_Model</class>
+ </hackathon_templatecleanup>
+ </models>
+ <helpers>
+ <hackathon_templatecleanup>
+ <class>Hackathon_TemplateCleanup_Helper</class>
+ </hackathon_templatecleanup>
+ </helpers>
+ </global>
+</config>
View
8 src/app/etc/modules/Hackathon_TemplateCleanup.xml
@@ -0,0 +1,8 @@
+<config>
+ <modules>
+ <Hackathon_TemplateCleanup>
+ <active>true</active>
+ <codePool>community</codePool>
+ </Hackathon_TemplateCleanup>
+ </modules>
+</config>
View
17 src/magento_bootstrap.php
@@ -0,0 +1,17 @@
+<?php
+/*
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * It is available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ *
+ * @category Hackathon
+ * @package TemplateCleanup
+ * @copyright Copyright (c) 2012 Hackathon
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ */
+
+require_once('app/Mage.php');
+Mage::app('default');
+Mage::getModel('hackathon_templatecleanup/observer')->fetchUsedTemplates();
Please sign in to comment.
Something went wrong with that request. Please try again.