Completed
Push — feature/ss4-upgrade ( f41a3f )
by
unknown
10:12
created

SiteController::GATrackingCode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
3
namespace SilverStripe\Addons\Controllers;
4
5
use SilverStripe\View\Requirements;
6
use SilverStripe\Control\Controller;
7
use SilverStripe\Control\RSS\RSSFeed;
8
use SilverStripe\View\SSViewer;
9
use SilverStripe\ORM\ArrayList;
10
use SilverStripe\ORM\ArrayData;
11
12
/**
13
 * The base site controller.
14
 */
15
class SiteController extends Controller 
16
{
17
18
	public function init() 
19
	{
20
		RSSFeed::linkToFeed("add-ons/rss", "New modules on addons.silverstripe.org");
21
22
		$theme = SSViewer::config()->theme;
23
		
24
		Requirements::javascript("//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js");
25
		Requirements::javascript("themes/{$theme}/bootstrap/js/bootstrap.min.js");
26
		Requirements::javascript("themes/{$theme}/javascript/addons.js");
27
		Requirements::javascript("//www.google.com/jsapi");
28
		Requirements::javascript("themes/{$theme}/javascript/chart.js");
29
		parent::init();
30
	}
31
32
	public function Menu() 
33
	{
34
		$menu = new ArrayList();
35
36
		$menuEntries = array(
37
			//array('controller' => 'HomeController'),
38
			array('controller' => 'AddonsController'),
39
			array(
40
				'link' => Controller::join_links(
41
					singleton('AddonsController')->Link(),
42
					'?type=theme&view=expanded'
43
				),
44
				'title' => 'Themes',
45
			),
46
			array('controller' => 'VendorsController'),
47
			array('controller' => 'AuthorsController'),
48
			array('controller' => 'TagsController'),
49
			array('controller' => 'SubmitAddonController'),
50
		);
51
52
		foreach ($menuEntries as $menuEntry) {
53
			if(isset($menuEntry['controller'])) {
54
				$inst = singleton($menuEntry['controller']);
55
				$active = false;
56
57
				foreach (self::$controller_stack as $candidate) {
58
					$active = (
59
						$candidate instanceof $menuEntry['controller']
60
						&& $this->request->getVar('type') != 'theme'
61
					);
62
				}
63
64
				$menu->push(new ArrayData(array(
65
					'Title' => $inst->Title(),
66
					'Link' => $inst->Link(),
67
					'Active' => $active,
68
					'MenuItemType' => $inst->MenuItemType()
69
				)));	
70
			} else {
71
				$active = ($this->request->getVar('type') == 'theme');
72
				$menu->push(new ArrayData(array(
73
					'Title' => $menuEntry['title'],
74
					'Link' => $menuEntry['link'],
75
					'Active' => $active,
76
					'MenuItemType' => 'link',
77
				)));
78
			}
79
			
80
		}
81
82
		return $menu;
83
	}
84
85
	/**
86
	 * @return String 'link' or 'button'
87
	 */
88
	public function MenuItemType() 
89
	{
90
		return 'link';
91
	}
92
93
	public function GATrackingCode() 
94
	{
95
		return defined('GA_TRACKING_CODE') ? GA_TRACKING_CODE : null;
96
	}
97
98
	public function LinkWithSearch($extraParamStr = '') 
99
	{
100
		$params = array_diff_key($this->request->getVars(), array('url' => null));
101
		parse_str($extraParamStr, $extraParams);
102
		$params = array_merge($params, (array)$extraParams);
103
104
		return Controller::join_links($this->Link(), '?' . http_build_query($params));
105
	}
106
107
}
108