/**
  *Function for making static html pages from selected pages in the manage all pages table
  *and then upload it to the specified ftp      
  */
 public function make($pids)
 {
     // turn off layout and ViewRenderer
     $this->_helper->viewRenderer->setNoRender();
     //get Languages
     $langs = NetActionController::getLanguages();
     //get values
     $values = $this->_request->getParams();
     $pageIDs = $pids;
     $pidsArray = explode(",", $pageIDs);
     //$publishedBool = $values['pubval'];
     $publishedBool = "1";
     // This cache doesn't expire, needs to be cleaned manually.
     $frontendOptions = array('caching' => true, 'lifetime' => null, 'ignore_user_abort' => true, 'automatic_serialization' => true);
     $backendOptions = array('cache_dir' => $this->_np . 'exported/');
     $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     if ($pageIDs != "") {
         //if not empty call
         //use all langs for update
         foreach ($langs as $lang) {
             //set value for published to all selected items in manage all pages table
             //$this->_sesija->lang = $lang;
             //file_get_contents($this->_host . "view/change-language/code/$lang");
             foreach ($pidsArray as $item) {
                 $alias = $this->_db->fetchAll("SELECT alias FROM pages_{$lang} WHERE id = ?", array($item));
                 $html = file_get_contents($this->_host . "view/index/id/" . $item . "/lng/{$lang}");
                 $html = str_replace($this->_host, "", $html);
                 $aliasName = urlencode($alias[0]['alias']);
                 $user = $this->_sesija->user . Zend_Session::getId();
                 @mkdir($this->_np . "exported/{$user}", 0755);
                 @mkdir($this->_np . "exported/{$user}/{$lang}", 0755);
                 $filename = $this->_np . "exported/{$user}/{$lang}/{$aliasName}.html";
                 if (!($handle = @fopen($filename, 'w+'))) {
                     $message = "Cannot open file ";
                     //return;
                 }
                 // Write $html to our opened file.
                 if (fwrite($handle, $html) === FALSE) {
                     $message = "Cannot write to file ";
                     //return;
                 }
                 fclose($handle);
             }
         }
         if ($publishedBool == "1") {
             //print_r($pidsArray);
             echo $this->_translateCreator->_('These pages are exported!');
         } else {
             //print_r($pidsArray);
             //echo 'These pages are unpublished!';
         }
     }
 }
 /**
  *Preparing contents from database to be rendered
  *with replacing of the template variables
  *
  *@author NT
  *
  */
 public static function _templatePrepare($outputDB, $content = null, $lang = null, $pageInfo = null)
 {
     $db = Zend_Registry::get('db');
     $title = Zend_Registry::get('pageTitle');
     $langCode = self::$lang;
     $langCode = Zend_Registry::get('langCode');
     if ($langCode == "") {
         //OVO MORA DA SE SKLONI!!!!!
         $langCode = "sr";
     }
     $replaceThis = preg_match_all('/[{].+[}]/', $outputDB, $matches);
     foreach ($matches[0] as $part) {
         $parts = explode(":", $part);
         $Tvars[] = $parts;
     }
     if (count(@$Tvars)) {
         foreach ($Tvars as $Tvarss) {
             $i = 0;
             foreach ($Tvarss as $TV) {
                 $module = trim($TV, "{}");
                 $build2[] = $module;
                 $i++;
             }
             $build[] = $build2;
             $build2 = array();
         }
     }
     //print_r($build);
     //print_r($matches);
     $count = 0;
     $cHI = 0;
     if (count(@$build)) {
         foreach ($build as $build_) {
             @($pattern = $matches[$count]);
             //TITLE OF THE PAGE
             //if (@preg_match("/{title}/", "{" . $build_[0] . "}" )) {
             if (@strstr("{" . $build_[0] . "}", "{title}")) {
                 $output = $title;
                 $outputDB = str_replace('{title}', $output, $outputDB);
             }
             //PAGE INFO HANDLE
             //if (@preg_match("/{searchform}/", "{" . $build_[0] . "}" )) {
             if (@strstr("{" . $build_[0] . "}", "{pageinfo}")) {
                 $output = ViewController::pageInfo($pageInfo);
                 $outputDB = str_replace('{pageinfo}', $output, $outputDB);
             }
             if (@strstr("{" . $build_[0] . "}", "{adminurl}")) {
                 $outputDB = str_replace('{adminurl}', '<a href="' . NetActionController::$hostRW . NetActionController::$adminUrl . '" target="_blank">Admin (FF!/Safari/Chrome)</a>', $outputDB);
             }
             //SEARCH HANDLE
             //if (@preg_match("/{searchform}/", "{" . $build_[0] . "}" )) {
             if (@strstr("{" . $build_[0] . "}", "{searchform}")) {
                 $output = SearchController::showSearchForm();
                 $outputDB = str_replace('{searchform}', $output, $outputDB);
             }
             //HTML PART HANDLE
             if (@strstr("{" . $build_[0], "{html")) {
                 //$codeAll = $build_[1] . ":" . $build_[2];
                 //$countBuild = count($build_);
                 $codeA = "";
                 foreach ($build_ as $countedB) {
                     $codeA .= $countedB . ":";
                 }
                 $codeA = ltrim($codeA, "html:");
                 $codeA = rtrim($codeA, ":");
                 $output = htmlspecialchars_decode($codeA);
                 $output = str_replace('<br />', "", $output);
                 $output = str_replace('<br>', "\n", $output);
                 //$output = '<script type="text/javascript">document.write(' ."\n" . $output . ');</script>';
                 $outputDB = str_replace('{html:' . $codeA . '}', $output, $outputDB);
                 //$outputDB = str_replace('{html' , $output, $outputDB);
             }
             //xHTML PART HANDLE - if this code block is to be xhtml purified
             if (@strstr("{" . $build_[0], "{x-html")) {
                 $codeA = "";
                 foreach ($build_ as $countedB) {
                     $codeA .= $countedB . ":";
                 }
                 $codeA = ltrim($codeA, "x-html:");
                 $codeA = rtrim($codeA, ":");
                 $output = htmlspecialchars_decode($codeA);
                 $output = str_replace('<br />', "", $output);
                 $output = str_replace('<br>', "\n", $output);
                 //$output = '<script type="text/javascript">document.write(' ."\n" . $output . ');</script>';
                 $outputDB = str_replace('{x-html:' . $codeA . '}', $output, $outputDB);
                 //$outputDB = str_replace('{html' , $output, $outputDB);
             }
             //LANGUAGE chooser
             //if (@preg_match("/{language:flags}/", "{" . $build_[0] . ":flags}" )) {
             if (@strstr("{" . $build_[0] . ":flags}", "{language:flags}")) {
                 $langsEnabled = NetActionController::getStaticEnabledLanguages();
                 /*
                 $langQ = $db->fetchAll("SELECT * FROM languages WHERE enabled = '1'");
                 foreach ($langQ as $lang) {
                     $langsEnabled[] = $lang['code'];
                 }
                 */
                 $output = ViewController::showLanguageChooser($langsEnabled);
                 $outputDB = str_replace('{language:flags}', $output, $outputDB);
             }
             //MENU HANDLE
             //if (@preg_match("/menu:display/", "{" . $build_[0] . ":" . $build_[1])) {
             if (@strstr($build_[0] . ":" . $build_[1], "menu:display")) {
                 $menuId = trim($build_[2], '""');
                 @($orientation = $build_[3]);
                 //if ($orientation =! "slide") {
                 //$menuQ = $db->fetchAll("SELECT *, url_en as url,name_en as name,description_en as description FROM menu_items  WHERE menu_id = ?", array($menuId));
                 //} else {
                 $menuQ = $db->fetchAll("SELECT *, menu_items.check_access as chkAccess, menu_items.content_id as cid, url_{$langCode} as url, name_{$langCode} as name, description_{$langCode} as description FROM menu_items LEFT JOIN pages_{$langCode} ON menu_items.content_id = pages_{$langCode}.id WHERE menu_id = ? AND pages_{$langCode}.published = '1' ORDER BY weight ASC", array($menuId));
                 //}
                 //print_r($menuQ );
                 if (!empty($menuQ)) {
                     $output = ViewController::displayMenu($menuQ, $orientation);
                     if ($orientation == "") {
                         $orient = "";
                     } elseif ($orientation == "vertical") {
                         $orient = ":vertical";
                     } elseif ($orientation == "tree") {
                         $orient = ":tree";
                     } elseif ($orientation == "slide") {
                         $orient = ":slide";
                     }
                     $outputDB = str_replace('{menu:display:' . $build_[2] . @$orient . '}', $output, $outputDB);
                 } else {
                     $outputDB = str_replace('{menu:display:' . $build_[2] . @$orient . '}', '<b style="color:red;">{menu:' . $build_[2] . '}Doesn\'t exist or it is empty!</b>', $outputDB);
                 }
             }
             //CATEGORIES
             //if (@preg_match("/category:display/", "{" . $build_[0] . ":" . $build_[1])) {
             if (@strstr($build_[0] . ":" . $build_[1], "category:display")) {
                 $catId = trim($build_[2], '""');
                 @($orientation = $build_[3]);
                 $catQ = $db->fetchAll("SELECT id, title, alias, category, image, description, check_access  FROM pages_{$langCode}  WHERE category = ? AND pages_{$langCode}.published = '1'", array($catId));
                 //$catQ = $db->fetchAll("SELECT id, title, alias, category, image, description, check_access  FROM pages_$langCode WHERE category = ? AND pages_$langCode.published = '1'", array($catId));
                 //$catQ = array();
                 $catItemsArray2 = $db->fetchAll("SELECT DISTINCT *, pages_{$langCode}.id as id, pages_{$langCode}.title as title, pages_{$langCode}.alias as alias, pages_{$langCode}.category as category, pages_{$langCode}.image, pages_{$langCode}.description, pages_{$langCode}.check_access as check_access FROM category_items LEFT JOIN  pages_{$langCode}  ON pages_{$langCode}.id = category_items.content_id WHERE category_items.category_id = ? AND pages_{$langCode}.published = '1' GROUP BY pages_{$langCode}.id DESC ", array($catId));
                 $catQ = array_merge($catQ, $catItemsArray2);
                 //$catQ = $catQ + $catItemsArray2;
                 //print_r($menuQ );
                 if (!empty($catQ)) {
                     $output = ViewController::displayCategory($catQ, $orientation);
                     if ($orientation == "") {
                         $orient = "";
                     } elseif ($orientation == "oldest") {
                         $orient = ":oldest";
                     } elseif ($orientation == "latest") {
                         $orient = ":latest";
                     } elseif ($orientation == "desc") {
                         $orient = ":desc";
                     }
                     $outputDB = str_replace('{category:display:' . $build_[2] . @$orient . '}', $output, $outputDB);
                 } else {
                     $outputDB = str_replace('{category:display:' . $build_[2] . @$orient . '}', '<b style="color:red;">{category:' . $build_[2] . '}Doesn\'t exist or it is empty!</b>', $outputDB);
                 }
             }
             //SLIDE cu3er
             if (@strstr("{" . $build_[0] . "}", "{cu3er}")) {
                 $output = ViewController::slides();
                 $outputDB = str_replace('{cu3er}', $output, $outputDB);
             }
             //DISPLAY IMAGES
             //if (@preg_match("/images:display/", "{" . $build_[0] . ":" . $build_[1])) {
             if (@strstr($build_[0] . ":" . $build_[1], "images:display")) {
                 $folder = trim($build_[2], '""');
                 $folder = trim($folder, "''");
                 @($image = trim($build_[3], "''"));
                 //$menuQ = $db->fetchAll("SELECT *, url_en as url,name_en as name,description_en as description FROM menu_items  WHERE menu_id = ?", array($menuId));
                 //print_r($menuQ );
                 if (!empty($folder)) {
                     if (empty($image)) {
                         $output = ViewController::displayImages($folder);
                         $imageOut = "";
                     } else {
                         $output = ViewController::displayImage($folder, $image);
                         $imageOut = ":'" . $image . "'";
                     }
                     $outputDB = str_replace('{images:display:' . $build_[2] . $imageOut . '}', $output, $outputDB);
                     //$outputDB = str_replace('{images:display:' . $build_[2]  . '}', "AAAAA", $outputDB);
                 } else {
                     $outputDB = str_replace('{images:display:' . $build_[2] . $imageOut . '}', '<b style="color:red;">{images:' . $build_[2] . '}Doesn\'t exist or it is empty!</b>', $outputDB);
                 }
             }
             //EXTERN Joomla!!
             if (@preg_match("/extern:joomla/", "{" . $build_[0] . ":" . $build_[1])) {
                 $folder = trim($build_[2], '""');
                 $folder = trim($folder, "''");
                 $type = trim($build_[2], '""');
                 //print_r($menuQ );
                 if (!empty($type)) {
                     $output = ViewController::displayExternJoomla($type);
                     $imageOut = "";
                     $outputDB = str_replace('{extern:joomla:' . $build_[2] . $imageOut . '}', $output, $outputDB);
                 } else {
                     $outputDB = str_replace('{extern:joomla:' . $build_[2] . $imageOut . '}', '<b style="color:red;">{images:' . $build_[2] . '}Doesn\'t exist or it is empty!</b>', $outputDB);
                 }
             }
             //MODULE 'FORM'
             if (@preg_match("/module:forms/", "{" . $build_[0] . ":" . $build_[1])) {
                 $contactFormName = trim($build_[2], "''");
                 $contactFormId = $db->fetchAll("SELECT *, mod_forms.name as formName FROM mod_forms LEFT JOIN mod_forms_fields ON mod_forms.id = mod_forms_fields.form_id WHERE enabled = '1' AND mod_forms.name = ?", array($contactFormName));
                 //print_r($contactFormId);
                 if (!empty($contactFormId)) {
                     $formId = $contactFormId;
                     $output = FormsController::showForm($formId);
                     $outputDB = str_replace('{module:forms:' . $build_[2] . '}', $output, $outputDB);
                 } else {
                     $outputDB = str_replace('{module:forms:' . $build_[2] . '}', '<b style="color:red;">{module:forms:' . $build_[2] . '}Doesn\'t exist!</b>', $outputDB);
                 }
             }
             $outputString = "";
             $count++;
         }
     } else {
         //$output = ViewController::setDefaultHeaderImage();
         //$outputDB .= $output;
     }
     $outputDB = str_replace('{content}', $content, $outputDB);
     return $outputDB;
 }
 public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array())
 {
     /*CONFIG VARS*/
     $server = explode(".", $_SERVER['HTTP_HOST']);
     $c = count($server);
     @($SERVER = $server[$c - 2] . "." . $server[$c - 1]);
     try {
         $config = new Zend_Config_Ini('config.ini', $_SERVER['HTTP_HOST']);
         $this->_server = $_SERVER['HTTP_HOST'];
     } catch (Exception $e) {
         $config = new Zend_Config_Ini('config.ini', $SERVER);
         $this->_server = $SERVER;
     }
     /*    
         if (!empty($configCheck)) {//if there is a config value in config, use that one
             $config = new Zend_Config_Ini('quickstart.ini',  $_SERVER['HTTP_HOST'] );
             $this->_server =  $_SERVER['HTTP_HOST'];    
         }
     */
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $this->_host = $request->getScheme() . '://' . $config->paths->host;
     self::$host = $request->getScheme() . '://' . $config->paths->host;
     $this->_hostRW = $request->getScheme() . '://' . $config->paths->hostRW;
     self::$hostRW = $request->getScheme() . '://' . $config->paths->hostRW;
     $this->_nps = $config->paths->nps;
     self::$nps = $config->paths->nps;
     $this->_np = $config->paths->np;
     self::$np = $config->paths->np;
     $this->_adminUrl = $config->adminUrl;
     self::$adminUrl = $config->adminUrl;
     $this->setRequest($request)->setResponse($response)->_setInvokeArgs($invokeArgs);
     $this->_helper = new Zend_Controller_Action_HelperBroker($this);
     // This cache doesn't expire, needs to be cleaned manually.
     $frontendOptions = array('caching' => true, 'lifetime' => null, 'ignore_user_abort' => true, 'automatic_serialization' => true);
     $backendOptions = array('cache_dir' => $this->_nps . 'cacheAll/');
     $this->_cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     Zend_Registry::set('cacheSt', $this->_cache);
     // This cache doesn't expire, needs to be cleaned manually.
     $frontendOptions = array('caching' => true, 'lifetime' => null, 'ignore_user_abort' => true, 'automatic_serialization' => true);
     $backendOptions = array('cache_dir' => $this->_nps . 'cache/');
     $this->_cachedPages = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     Zend_Registry::set('cachedPages', $this->_cachedPages);
     //SESSION
     $this->_sesija = new Zend_Session_Namespace('net');
     $defaultLanguage = self::getDefaultLanguage();
     if ($this->_sesija->lang == null) {
         $this->_sesija->lang = $defaultLanguage;
     }
     //$this->_sesija->langAdmin = "en";
     Zend_Registry::set('currentUser', $this->_sesija->user);
     Zend_Registry::set('langCode', $this->_sesija->lang);
     self::setSettings();
     //this was earlier in the bootstrap - is it better here?
     //ACL
     if ($this->_sesija->currentRole == "") {
         $this->_sesija->currentRole = "guest";
     }
     Zend_Registry::set('currentRole', $this->_sesija->currentRole);
     $acl = $this->getAcl();
     Zend_Registry::set('acl', $acl);
     //ACL end
     //TRANSLATOR
     $reqValues = $this->_request->getParams();
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $this->_reqParams = $this->getRequest()->getRequestUri();
     //print_r($this->_reqParams);
     if ($reqValues['controller'] != "creator" && $reqValues['action'] != "admin") {
         //in creator only english - so far
         if (file_exists($this->_np . "languages/" . $this->_sesija->lang . ".php")) {
             $this->_translate = new Zend_Translate('array', $this->_np . 'languages/' . $this->_sesija->lang . '.php', $this->_sesija->lang);
             Zend_Registry::set('Zend_Translate', $this->_translate);
             $this->translator = $this->_translate;
         }
     } else {
         $creatorLanguage = "sr";
         $creatorLanguage = $this->_sesija->creatorLang;
         if (file_exists($this->_np . "languages/creator/" . $creatorLanguage . ".php")) {
             $this->_translate = new Zend_Translate('array', $this->_np . 'languages/creator/' . $creatorLanguage . '.php', $creatorLanguage);
             Zend_Registry::set('Zend_Translate', $this->_translate);
             $this->translator = $this->_translate;
         }
     }
     $creatorLanguage = "sr";
     $creatorLanguage = $this->_sesija->creatorLang;
     if (file_exists($this->_np . "languages/creator/" . $creatorLanguage . ".php")) {
         $this->_translateCreator = new Zend_Translate('array', $this->_np . 'languages/creator/' . $creatorLanguage . '.php', $creatorLanguage);
         Zend_Registry::set('Zend_Translate_Creator', $this->_translateCreator);
     }
     //BASE URL
     $this->_baseUrl = $this->_request->getRequestUri();
     //$this->_sesija->_urlCurrent = $this->_baseUrl;
     //$this->_sesija->bcumbs = array();
     if (!empty($this->_sesija->bcumbs)) {
         $should = 1;
         foreach ($this->_sesija->bcumbs as $bcumb) {
             if (in_array($this->_baseUrl, $bcumb)) {
                 $should = 0;
                 break;
             } else {
                 $should = 1;
             }
         }
         if (strpos($this->_baseUrl, "font.swf") === FALSE && strpos($this->_baseUrl, "lang") === FALSE && $should == 1 && $reqValues['controller'] != "creator") {
             $this->_sesija->bcumbs[$this->_sesija->_i]['url'] = $this->_baseUrl;
             $this->_sesija->bcumbs[$this->_sesija->_i]['title'] = $this->_title . "CCC";
             $this->_sesija->_i++;
         }
         //$this->_sesija->bcumbs[$this->_baseUrl]['url']['title'] = $this->_title . "CCC";
     }
     //AJAX
     $request = $this->getRequest();
     if ($request->isXmlHttpRequest()) {
         $this->_helper->layout()->disableLayout();
     }
     $this->_db = Zend_Registry::get('db');
     $this->_getDefaultTemplate();
     $this->init();
 }
 /**
  *Function for changing the value of the unbound -
  *should the created content be inside the content area defined in the template, 
  *or absolutely positioned on the page          
  */
 public function setBoundAction()
 {
     $this->_checkAccess();
     // turn off ViewRenderer
     $this->_helper->viewRenderer->setNoRender();
     $this->_helper->layout()->disableLayout();
     $values = $this->_request->getParams();
     $val = $values['val'];
     $pageid = $values['page'];
     $langs = NetActionController::getLanguages();
     foreach ($langs as $lang) {
         $this->_db->query("UPDATE " . $this->_tblprefix . "pages_{$lang} SET  unbounded = ? WHERE id = ?", array($val, $pageid));
     }
     $this->cleanCache();
     echo $this->_translateCreator->_("Done!");
 }
 public function delCategoryAction()
 {
     $this->_helper->layout()->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     if ($this->_sesija->superadmin != "1") {
         //SUPERADMIN ONLY
         echo $this->_translate->_("Only superadministrator can do this!");
         return;
     }
     $values = $this->_request->getParams();
     $categoryId = $values['id'];
     if ($categoryId != "") {
         $db = Zend_Registry::get('db');
         $db->query("DELETE FROM categories WHERE category_id =?", array($categoryId));
         //$db->query("DELETE FROM menu_items WHERE menu_id =?", array($categoryId));
         $langs = NetActionController::getLanguages();
         foreach ($langs as $lang) {
             $db->query("UPDATE pages_{$lang} SET category = ? WHERE category = ?", array('0', $categoryId));
         }
         echo $this->_translateCreator->_("Category deleted");
     }
 }
 /**
  *Function for installing of the exported template in the db
  */
 public function installTemplateDbAction()
 {
     $this->_helper->layout()->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     //echo 'here install in the db';
     //print_r($values);
     $db = Zend_Registry::get('db');
     //here should come code for exporting current template
     $values = $this->_request->getParams();
     $file = $values['file'];
     if ($file == '') {
         return;
     }
     $folderName = explode('__', $file);
     if (file_exists($this->_nps . 'templates/' . $folderName[0] . '/' . $file . '.xml')) {
         $xml = simplexml_load_file($this->_nps . 'templates/' . $folderName[0] . '/' . $file . '.xml');
         //print_r($xml);
         $langs = NetActionController::getLanguages();
         foreach ($langs as $lang) {
             $db->query("INSERT INTO templates_{$lang}(userId, title, output, bodyBg, staticFiles) VALUES(?, ?, ?, ?, ?)", array($this->_sesija->userId, $xml->title, $xml->output, $xml->bodyBg, $xml->staticFiles));
         }
         echo 'Template installed!';
     }
     //$res = $db->fetchAll("SELECT title, output, bodyBg, staticFiles FROM templates_$langCode  WHERE id = ?", array($id));
 }