actions.class.php 5.12 KB
Newer Older
Яков's avatar
first  
Яков committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php

class pagesActions extends sfActions
{
    public function executeIndex(sfWebRequest $request)
    {
        $this->setLayout('layoutHome');
    }

    public function executeShow(sfWebRequest $request)
    {
        $this->page = $this->getRoute()->getObject();
    }

    public function executeContacts(sfWebRequest $request)
    {
        if ($request->isMethod('post'))
        {
            $text = $request->getParameter('text');
            $name = $request->getParameter('name');

            if ($name && $text)
            {
                $newFeedback = new Feedback();
                $newFeedback->setAuthorName(trim(strip_tags($name)));
                $newFeedback->setMsg(trim(strip_tags($text)));
                $newFeedback->save();

                sfContext::getInstance()->getConfiguration()->loadHelpers('Partial');

                if ($this->getUser()->isAuthenticated())
                {
                    $param = array(
                        'organization' => $this->getUser()->getAccount()->getOrganization(),
                        'username' => $this->getUser()->getUsername(),
                        'text' => trim(strip_tags($text)),
                        'time' => $newFeedback->getCreatedAt()
                    );
                }
                else
                {
                    $param = array(
                        'organization' => false,
                        'username' => false,
                        'text' => trim(strip_tags($text)),
                        'time' => $newFeedback->getCreatedAt()
                    );
                }

                get_component('pages', 'emailSender',
                    array(
                        'type' => 'adminNotificationAboutFeedback',
                        'emailTo' => 'admin',
                        'param' => $param
                    )
                );

                echo 'ok';

                return sfView::NONE;

            }
        }
    }



    public function executeService(sfWebRequest $request)
    {

    }

    public function executePartners(sfWebRequest $request)
    {

    }

    public function executeHow_to_buy(sfWebRequest $request)
    {

    }

    public function executeAbout(sfWebRequest $request)
    {

    }

    public function executeDelivery(sfWebRequest $request)
    {

    }

    public function executeError404(sfWebRequest $request)
    {
        $this->setLayout('layout404');
    }
    public function executeSitemap(sfWebRequest $request)
    {
        $this->getResponse()->setHttpHeader('Content-type', 'text/xml');
        $this->getResponse()->sendHttpHeaders();
        echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";


        sfApplicationConfiguration::getActive()->loadHelpers(array('Url'));

        $routes = array(
            'homepage',
            'catalog',
            'video',
            'article',
            'review'
        );

        echo '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';

        foreach ($routes as $route)
        {
            $url = sfConfig::get('app_protocol') . '://' . $request->getHost() . url_for('@' . $route);
            echo '<url><loc>' . $url . '</loc><lastmod>' . date('c') . '</lastmod><priority>1.0</priority></url>';
        }


        $products = Doctrine_Query::create()
            ->select("p.alias")
            ->from("Product p")
            ->where('p.is_delete = 0')
            ->fetchArray()
        ;

        foreach ($products as $product)
        {
            $url = sfConfig::get('app_protocol') . '://' . $request->getHost() . url_for('@product_show?alias=' . $product['alias']);
            echo '<url><loc>' . $url . '</loc><lastmod>' . date('c') . '</lastmod><priority>1.0</priority></url>';
        }

        $catalogs = Doctrine_Query::create()
            ->select("c.alias")
            ->from("Cat c")
            ->fetchArray()
        ;
        foreach ($catalogs as $catalog)
        {
            $url = sfConfig::get('app_protocol') . '://' . $request->getHost() . url_for('@catalog_show?alias=' . $catalog['alias']);
            echo '<url><loc>' . $url . '</loc><lastmod>' . date('c') . '</lastmod><priority>1.0</priority></url>';
        }

        $pages = Doctrine_Query::create()
            ->select("p.alias")
            ->from("Page p")
            ->fetchArray()
        ;
        foreach ($pages as $page)
        {
            $url = sfConfig::get('app_protocol') . '://' . $request->getHost() . url_for('@page_show?alias=' . $page['alias']);
            echo '<url><loc>' . $url . '</loc><lastmod>' . date('c') . '</lastmod><priority>0.5</priority></url>';
        }

        echo '</urlset>';
        return sfView::NONE;
    }

    public function executeRobots(sfWebRequest $request)
    {

        $this->getResponse()->setHttpHeader('Content-type', 'text/plain');
        $this->getResponse()->sendHttpHeaders();
        $this->host = sfConfig::get('app_protocol') . '://' . $request->getHost();


        $this->setLayout(false);
    }

}