<commit_before><?php

/**
 * AdController
 *
 * @author  <NAME>
 * @abstract this is the Ad controller ,
 * do the crud relative to ads : create, show, edit, delete
 */
class AdController extends Zend_Controller_Action {

    public function init() {

        $this->lang = $this->view->lang = $this->_helper->checklang->check();
        $this->location = $this->_helper->checklocation->check();
        $this->view->checkMessages = $this->_helper->checkMessages->check();
        $this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
        $this->view->mensajes = $this->_flashMessenger->getMessages();


        //check if user is locked
        $locked = $this->_helper->checkLockedUser->check();
        if ($locked == 1) {
            $this->_redirect('/' . $this->view->lang . '/auth/logout');
        }

        if ($this->view->checkMessages > 0) {
            $this->_helper->_flashMessenger->addMessage($this->view->translate('You have') . ' ' .
                    '<b><a href="/' . $this->view->lang . '/message/received">' . $this->view->translate('new messages') . ' (' . $this->view->checkMessages . ')</a></b>');
        }
    }

    public function listAction() {

        $woeid = $this->_request->getParam('woeid');
        $status = $this->_request->getParam('status');
        $this->view->ad_type = $ad_type = $this->_request->getParam('ad_type');


        if ($ad_type == 'give') {
            $this->view->page_title .= $this->view->translate('give') . ' - ';
            $type = 'give';
        }

        if ($ad_type == 'want') {
            $this->view->page_title .= $this->view->translate('want') . ' - ';
            $type = 'want';
        }


        $model = $this->_getModel();

        $this->view->woeid = $woeid;
        $this->view->ad = $model->getAdList($woeid, $ad_type, $status);
        $this->view->woeidName = $this->_helper->woeid->name($woeid, $this->lang);
        $short = explode(',', $this->view->woeidName);
        $this->view->woeidNameShort = ' ' . $this->view->translate('in') . ' ' . $short[0];


        //add the link to the proper rss to layout
        $this->view->headLink()->appendAlternate('http://' . $_SERVER['HTTP_HOST'] . '/' . $this->lang . '/rss/feed/woeid/' . $woeid . '/ad_type/' . $ad_type,
                'application/rss+xml',
                $this->view->woeidName . ' - ' . $this->view->translate((string) $type));



        if (empty($this->view->ad)) {
            $this->view->suggestIP = $this->_helper->getLocationGeoIP->suggest();
        }


        //TODO , this sucks, do a better way to not show invalid woeids or null
        if ((empty($woeid) ) || ($woeid < 10) || ($woeid == 29370606)) { //29370606 españa town
            $this->_helper->_flashMessenger->addMessage($this->view->translate('This location is not a valid town. Please, try again.'));
            $this->_redirect('/' . $this->lang . '/location/change');
        }

         //set the location name reg var from the woeid helper
        $aNamespace = new Zend_Session_Namespace('Nolotiro');
        $aNamespace->locationName = $this->view->woeidName;
        $this->view->page_title .= $this->view->woeidName;

        //paginator
        $page = $this->_getParam('page');

        if ($page) {
            $this->view->page_title .= ' - ' . $this->view->translate('page') . ' ' . $page;
        }
        
        $paginator = Zend_Paginator::factory($this->view->ad);
        $paginator->setDefaultScrollingStyle('Elastic');
        $paginator->setItemCountPerPage(10);
        $paginator->setCurrentPageNumber($page);

        $this->view->paginator = $paginator;
    }

    public function listallAction() {

        $model = new Model_Ad();

        $ad_type = $this->_request->getParam('ad_type');

        if ($ad_type == 'give') {
            $this->view->page_title .= $this->view->translate('give') . ' - ';
        }

        if ($ad_type == 'want') {
            $this->view->page_title .= $this->view->translate('want') . ' - ';
        }
        $this->view->ad = $model->getAdListAll($ad_type);
        $this->view->page_title .= $this->view->translate('All the ads');

        //paginator
        $page = $this->_getParam('page');
        if ($page) {
            $this->view->page_title .= ' - ' . $this->view->translate('page') . ' ' . $page;<commit_msg>dont accept other params than give or want in ad type value<commit_after><?php

/**
 * AdController
 *
 * @author  <NAME>
 * @abstract this is the Ad controller ,
 * do the crud relative to ads : create, show, edit, delete
 */
class AdController extends Zend_Controller_Action {

    public function init() {

        $this->lang = $this->view->lang = $this->_helper->checklang->check();
        $this->location = $this->_helper->checklocation->check();
        $this->view->checkMessages = $this->_helper->checkMessages->check();
        $this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
        $this->view->mensajes = $this->_flashMessenger->getMessages();


        //check if user is locked
        $locked = $this->_helper->checkLockedUser->check();
        if ($locked == 1) {
            $this->_redirect('/' . $this->view->lang . '/auth/logout');
        }

        if ($this->view->checkMessages > 0) {
            $this->_helper->_flashMessenger->addMessage($this->view->translate('You have') . ' ' .
                    '<b><a href="/' . $this->view->lang . '/message/received">' . $this->view->translate('new messages') . ' (' . $this->view->checkMessages . ')</a></b>');
        }
    }

    public function listAction() {

        $woeid = $this->_request->getParam('woeid');
        $this->view->ad_type = $ad_type = $this->_request->getParam('ad_type');

        if ($ad_type == 'give') {
            $this->view->page_title .= $this->view->translate('give') . ' - ';
            $type = 'give';
        }
        elseif ($ad_type == 'want') {
            $this->view->page_title .= $this->view->translate('want') . ' - ';
            $type = 'want';
        }
        else {
            //dont accept other values than give/want
            $this->_helper->_flashMessenger->addMessage($this->view->translate('this url does not exist'));
            $this->_redirect('/' . $this->lang . '/woeid/' . $this->location . '/give');
        }
        

        
        $status = $this->_request->getParam('status');
        $f = new Zend_Filter();
        $f->addFilter(new Zend_Filter_HtmlEntities());
        $status = $f->filter($status);

        if ($status) {
            $this->view->page_title .= $this->view->translate($status) . ' - ';
        }



        $model = $this->_getModel();
        $this->view->woeid = $woeid;
        $this->view->ad = $model->getAdList($woeid, $ad_type, $status);
        $this->view->woeidName = $this->_helper->woeid->name($woeid, $this->lang);
        $short = explode(',', $this->view->woeidName);
        $this->view->woeidNameShort = ' ' . $this->view->translate('in') . ' ' . $short[0];


        //add the link to the proper rss to layout
        $this->view->headLink()->appendAlternate('http://' . $_SERVER['HTTP_HOST'] . '/' . $this->lang . '/rss/feed/woeid/' . $woeid . '/ad_type/' . $ad_type,
                'application/rss+xml',
                $this->view->woeidName . ' - ' . $this->view->translate((string) $type));



        if (empty($this->view->ad)) {
            $this->view->suggestIP = $this->_helper->getLocationGeoIP->suggest();
        }


        //TODO , this sucks, do a better way to not show invalid woeids or null
        if ((empty($woeid) ) || ($woeid < 10) || ($woeid == 29370606)) { //29370606 españa town
            $this->_helper->_flashMessenger->addMessage($this->view->translate('This location is not a valid town. Please, try again.'));
            $this->_redirect('/' . $this->lang . '/location/change');
        }

         //set the location name reg var from the woeid helper
        $aNamespace = new Zend_Session_Namespace('Nolotiro');
        $aNamespace->locationName = $this->view->woeidName;
        $this->view->page_title .= $this->view->woeidName;

        //paginator
        $page = $this->_getParam('page');

        if ($page) {
            $this->view->page_title .= ' - ' . $this->view->translate('page') . ' ' . $page;
        }

        $paginator = Zend_Paginator::factory($this->view->ad);
        $paginator->setDefaultScrollingStyle('Elastic');
        $paginator->setItemCountPerPage(10);
        $paginator->setCurrentPageNumber($page);

        $this->view->paginator = $paginator;
    }

    public function listallAction() {

        $model = new Model_Ad();

        $ad_type = $this->_request->getParam('ad_type');

        if ($ad_type == 'give') {
            $this->view->page_title .= $this->view->translate('give') . ' - ';
        }

        if ($ad_type == 'want') {
            $this->view->page_title .= $this->view->translate('want') . ' - ';
        }
        $this->view->ad = $model->getAdListAll($ad_type);
        $this->view->page_title .= $this->view->translate('All the ads');

        //paginator
        $page = $this->_getParam('page');
        if ($page) {
            $this->view->page_title .= ' - ' . $this->view->translate('page') . ' ' . $page;
{'fraction_non_alphanumeric': 0.2002588159171789, 'fraction_numerical': 0.004960638412595708, 'mean_word_length': 2.2666431842197956, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 305, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3940274', 'n_tokens_mistral': 2968, 'n_tokens_neox': 2839, 'n_words': 496}