Esempio n. 1
0
 /**
  * reads settings.ini (or defaults.ini if non-existent)
  * and sets configurable constants that are set in the settings db table
  */
 function __setConstants($path = null, $return = false)
 {
     $path = !empty($path) ? $path : CONFIGS;
     if (file_exists($path . 'defaults.ini')) {
         if (file_exists($path . 'settings.ini')) {
             $path .= 'settings.ini';
         } else {
             $path .= 'defaults.ini';
         }
         $settings = parse_ini_file($path, true);
         if ($return == true) {
             $settings = ZuhaSet::array_map_r($settings, 'ZuhaSet::parse_ini_r');
             return $settings;
         } else {
             foreach ($settings as $key => $value) {
                 $key = trim($key);
                 if (!defined(strtoupper($key))) {
                     if (is_array($value)) {
                         define(strtoupper($key), serialize($value));
                     } else {
                         define(strtoupper($key), $value);
                     }
                 }
             }
         }
     } else {
         if (defined(SITE_DIR)) {
             debug('A defaults.ini file is required here : ' . $path . 'defaults.ini');
             exit;
         }
     }
 }
Esempio n. 2
0
 /**
  * Before Render method
  *
  * sets a few variables needed for all views
  */
 public function beforeRender()
 {
     // trying to find a bot that is spamming analytics (but it seems to kill real error log reporting - fyi)
     // CakeLog::write('error', $_SERVER['REMOTE_ADDR']);
     // CakeLog::write('error', $_SERVER['HTTP_USER_AGENT']);
     // CakeLog::write('error', $_SERVER['REQUEST_URI']);
     // CakeLog::write('error', $_SERVER['REQUEST_URI']);
     // CakeLog::write('error', '...
     // ...
     // ...
     // ...
     // ');
     //CakeLog::write('error', print_r($_SERVER, true));
     parent::beforeRender();
     $this->set('referer', $this->referer());
     // used for back button links, could be useful for breadcrumbs possibly
     $this->set('_serialize', array_keys($this->viewVars));
     $this->set('_view', $this->view);
     // do a final permission check on the user field
     $modelName = Inflector::singularize($this->name);
     if (!empty($this->{$modelName})) {
         $this->set('_layout', $this->{$modelName}->theme);
         // set in the themeable behavior
         $this->Acl->check(array('permission' => true), $this->{$modelName}->permissionData);
     }
     // order is important for these automatic view vars
     $this->set('page_title_for_layout', $this->_pageTitleForLayout());
     $alias = ZuhaSet::find_key($this->viewVars, 'Alias');
     $alias = end($alias);
     $this->set('title_for_layout', !empty($alias['title']) ? $alias['title'] : $this->_titleForLayout());
     $this->set('keywords_for_layout', !empty($alias['keywords']) ? $alias['keywords'] : null);
     $this->set('description_for_layout', !empty($alias['description']) ? $alias['description'] : $this->_descriptionForLayout());
 }
Esempio n. 3
0
 /**
  * Sync the template settings.  Usually when a template is updated.
  *
  * @param int        	The id of the page we're making settings for
  * @param array			An array of data to get the template, and template settings from * 
  */
 private function _syncTemplateSettings()
 {
     $templates = $this->find('all', array('conditions' => array($this->alias . '.type' => 'template'), 'order' => array($this->alias . '.modified' => 'DESC')));
     // might need to move this to it's own function if to be used anywhere else.
     // checks for more than one default template being set
     // @todo do it on a per user_role basis, so that you can have defaults per user role
     $defaultTemplates = Set::extract('/Webpage[is_default>0]', $templates);
     if (count($defaultTemplates) > 1) {
         // note : due to order in find statement the first template is the one to keep
         for ($i = 1; $i < count($defaultTemplates); $i++) {
             // note that we start on one not zero
             // go through the template array and remove the one we don't want
             $templates = ZuhaSet::devalue($templates, $defaultTemplates[$i]);
             // then save the default template again to take away the default setting
             $defaultTemplates[$i]['Webpage']['is_default'] = 0;
             $defaultTemplates[$i]['Webpage']['type'] = 'template';
             // database default is content, so this must be set
             $prevId = $this->id;
             $this->create();
             $this->save($defaultTemplates[$i], array('callbacks' => false));
             // no callbacks so that it doesn't come back here in an endless loop
             $this->id = $prevId;
         }
         $defaultTemplates = array_values($defaultTemplates);
         // reset the key index
     }
     // now we can save the settings (we've cleaned it so that there is only one default)
     $i = 0;
     $setting['Setting']['value'] = '';
     $setting['Setting']['type'] = 'App';
     $setting['Setting']['name'] = 'TEMPLATES';
     foreach ($templates as $template) {
         $userRoles = $this->_templateUserRoles($template['Webpage']['user_roles']);
         $value = array('templateName' => $template['Webpage']['name'], 'templateId' => $template['Webpage']['id'], 'isDefault' => $template['Webpage']['is_default'], 'urls' => $this->templateUrls($template), 'userRoles' => $userRoles);
         // deprecated this line in favor of the line right after (so that we can pull the file instead of a db call) 7/22/2013 RK
         $setting['Setting']['value'] .= 'template[' . $template['Webpage']['id'] . '] = "' . base64_encode(gzcompress(serialize($value))) . '"' . PHP_EOL;
         $i++;
     }
     $Setting = ClassRegistry::init('Setting');
     if ($Setting->add($setting)) {
         return true;
     } else {
         return false;
     }
 }
Esempio n. 4
0
 /**
  * Before Render method
  *
  * sets a few variables needed for all views
  */
 public function beforeRender()
 {
     parent::beforeRender();
     $this->set('referer', $this->referer());
     // used for back button links, could be useful for breadcrumbs possibly
     $this->set('_serialize', array_keys($this->viewVars));
     $this->set('_view', $this->view);
     // do a final permission check on the user field
     $modelName = Inflector::singularize($this->name);
     if (!empty($this->{$modelName})) {
         $this->set('_layout', $this->{$modelName}->theme);
         // set in the themeable behavior
         $this->Acl->check(array('permission' => true), $this->{$modelName}->permissionData);
     }
     // order is important for these automatic view vars
     $this->set('page_title_for_layout', $this->_pageTitleForLayout());
     // Brought the below line back 9/13/2015 despite the comment below it.
     // If / when this error comes up again, we need a solution that works, because Alias SEO is not working
     // DO NOT just comment this line out again, find a way to get the Alias array values instead.
     $alias = ZuhaSet::find_key($this->viewVars, 'Alias');
     // can't use find_key because recursive iterator wasn't playing nice with some viewVars (eg. object type datetime)
     $alias = $this->viewVars[Inflector::singularize(Inflector::variable($this->request->controller))]['Alias'];
     // blog_posts controller becomes blogPost['Alias]
     $this->set('title_for_layout', !empty($alias['title']) ? $alias['title'] : $this->_titleForLayout());
     $this->set('keywords_for_layout', !empty($alias['keywords']) ? $alias['keywords'] : null);
     $this->set('description_for_layout', !empty($alias['description']) ? $alias['description'] : $this->_descriptionForLayout());
 }
Esempio n. 5
0
 /**
  * Recursively search an array for a value and return the key
  */
 public static function array_search_recursive($needle, $haystack)
 {
     foreach ($haystack as $key => $value) {
         $currentKey = $key;
         if ($needle === $value or is_array($value) && ZuhaSet::array_search_recursive($needle, $value) !== false) {
             return $currentKey;
         }
     }
     return false;
 }
Esempio n. 6
0
 /**
  * Delete method
  * 
  * Delete both the record and the file on the server
  * 
  * @access public
  * @param string
  * @return bool
  */
 public function delete($id = null, $cascade = true)
 {
     $this->id = $id;
     if (!$this->exists()) {
         throw new Exception(__('Invalid file'));
     }
     $image = $this->read(null, $id);
     $fileName = $image['GalleryImage']['filename'];
     $file = $this->rootPath . ZuhaSet::webrootSubPath($image['GalleryImage']['dir']) . $fileName;
     if (parent::delete($id)) {
         if (file_exists($file) && is_file($file)) {
             unlink($file);
             // delete the largest file
         }
         $small = str_replace($fileName, 'thumb' . DS . 'small' . DS . $fileName, $file);
         if (file_exists($small) && is_file($small)) {
             unlink($small);
             // delete the small thumb
         }
         $medium = str_replace($fileName, 'thumb' . DS . 'medium' . DS . $fileName, $file);
         if (file_exists($medium) && is_file($medium)) {
             unlink($medium);
             // delete the medium thumb
         }
         $large = str_replace($fileName, 'thumb' . DS . 'large' . DS . $fileName, $file);
         if (file_exists($large) && is_file($large)) {
             unlink($large);
             // delete the medium thumb
         }
         return true;
     } else {
         throw new Exception(__('Delete failed'));
     }
 }
Esempio n. 7
0
 /**
  * Recursively remove empty values from an array
  */
 public static function array_filter_recursive($haystack)
 {
     foreach ($haystack as $key => $value) {
         if (is_array($value)) {
             $haystack[$key] = ZuhaSet::array_filter_recursive($haystack[$key]);
         }
         if (empty($haystack[$key])) {
             unset($haystack[$key]);
         }
     }
     return is_numeric(key($haystack)) ? array_values($haystack) : $haystack;
     // reindex if keys are sequential instead of associative
 }
Esempio n. 8
0
 /**
  * User method
  *
  */
 public function user($groupId)
 {
     if ($this->request->is('post')) {
         if ($this->UserGroup->user($this->request->data)) {
             $this->Session->setFlash(__('User created, and added to group.'), 'flash_success');
             $this->redirect(array('plugin' => 'users', 'controller' => 'user_groups', 'action' => 'view', $groupId));
         } else {
             $this->Session->setFlash(__('Could not create user.'), 'flash_warning');
         }
     }
     $this->set('userRoles', ZuhaSet::devalue($this->UserGroup->User->UserRole->find('list'), 'guests'));
     $this->set('userGroup', $this->UserGroup->read(null, $groupId));
     $this->request->data['UserGroup']['UserGroup'][] = $groupId;
 }
Esempio n. 9
0
 /**
  * Build method
  * 
  */
 public function build()
 {
     $currentlyLoadedPlugins = CakePlugin::loaded();
     CakePlugin::loadAll();
     foreach (CakePlugin::loaded() as $plugin) {
         $Plugin = ClassRegistry::init($plugin . '.' . $plugin . 'AppModel');
         if (method_exists($Plugin, 'menuInit')) {
             $plugins[] = $plugin;
         }
     }
     $this->set('plugins', $plugins);
     //$plugins = array_diff(CakePlugin::loaded(), array('Activities', 'Answers', 'Categories', 'Connections', 'Contacts', 'Drafts', 'Facebook', 'Feeds', 'Forms', 'Media', 'Privileges', 'Recaptcha', 'Searchable', 'Subscribers', 'Tags', 'Twitter', 'Utils', 'Webpages', 'Wizards', 'Workflows')));
     CakePlugin::unload();
     CakePlugin::load($currentlyLoadedPlugins);
     // create some links to, and install the plugin if it isn't already
     if (($this->request->is('post') || $this->request->is('put')) && $this->request->data['WebpageMenuItem']['page_type'] == 'plugin') {
         $this->request->data['WebpageMenuItem']['item_text'] = $plugins[$this->request->data['WebpageMenuItem']['item_text']];
         // if not already installed, then install the plugin
         if (!in_array($this->request->data['WebpageMenuItem']['item_text'], $currentlyLoadedPlugins)) {
             $this->_plugin($this->request->data['WebpageMenuItem']['item_text']);
         }
         // create the menu (independent of the plugin - we can always install later)
         $MenuItem = ClassRegistry::init('Webpages.WebpageMenuItem');
         if ($MenuItem->saveAll($this->request->data)) {
             $this->Session->setFlash(__('Flow updated.'));
         } else {
             $this->Session->setFlash(__('Error occurred, please try again.'));
         }
     }
     $this->layout = 'default';
     App::uses('UserRole', 'Users.Model');
     $UserRole = new UserRole();
     $this->set('userRoles', $userRoles = $UserRole->find('all'));
     $this->set('userRoleOptions', Set::combine($userRoles, '{n}.UserRole.session_user_role_id', '{n}.UserRole.name'));
     App::uses('Template', 'Model');
     $Template = new Template();
     $this->set('templates', $templates = $Template->find('all', array('conditions' => array('Template.install NOT' => null))));
     $this->set('page_title_for_layout', 'SITE buildrr');
     $this->set('title_for_layout', 'SITE buildrr');
     $defaultTemplate = Set::combine(templateSettings(), '{n}.isDefault', '{n}');
     $defaultTemplate = Set::extract('/Template[layout=' . $defaultTemplate[1]['templateName'] . ']', $templates);
     $defaultTemplate = !empty($defaultTemplate) ? $defaultTemplate : $Template->placeholder();
     $this->set(compact('defaultTemplate'));
     $Menu = ClassRegistry::init('Webpages.WebpageMenu');
     foreach ($userRoles as $userRole) {
         $varName = preg_replace("/[^A-Za-z]/", '', $userRole['UserRole']['name']) . 'Sections';
         $conditions = $userRole['UserRole']['id'] == __SYSTEM_GUESTS_USER_ROLE_ID ? array('OR' => array(array('WebpageMenu.user_role_id' => ''), array('WebpageMenu.user_role_id' => null))) : array('WebpageMenu.user_role_id' => $userRole['UserRole']['id']);
         $menu = $Menu->find('threaded', array('conditions' => $conditions));
         // remove --Home from Home menu
         for ($i = 0; $i < count($menu[0]['children']); $i++) {
             if ($menu[0]['children'][$i]['WebpageMenu']['name'] == $menu[0]['WebpageMenu']['name']) {
                 unset($menu[0]['children'][$i]);
             }
         }
         $this->set($varName, $menu);
     }
     //$this->set('sections', $Menu->find('threaded', array('conditions' => array('WebpageMenu.lft >=' => $menu['WebpageMenu']['lft'], 'WebpageMenu.rght <=' => $menu['WebpageMenu']['rght']))));
     // used for re-ordering items $this->request->data['WebpageMenu']['children'] = $this->WebpageMenu->find('count', array('conditions' => array('WebpageMenu.lft >' => $menu['WebpageMenu']['lft'], 'WebpageMenu.rght <' => $menu['WebpageMenu']['rght'])));
     //$this->set('sections', $sections = $Menu->find('all', array('conditions' => array('OR' => array(array('WebpageMenu.parent_id' => null), array('WebpageMenu.parent_id' => ''))))));
     $menus = $Menu->generateTreeList(null, null, null, '--');
     foreach ($menus as $menu) {
         if (strpos($menu, '-') !== 0) {
             // this key should be removed, because if there is a link to the same page as the menu name
             $menus = ZuhaSet::devalue($menus, '--' . $menu, true);
         }
     }
     $this->set(compact('menus'));
 }