/**
  * Add an element to the site menu
  *
  * @static
  * @access	public
  * @param	string [$ctl] Controller name
  * @param	string [$name] Name that will be displayed
  * @return	boolean
  */
 public static function add_to_menu($ctl, $name)
 {
     try {
         $db =& Database::load();
         $to_read['table'] = 'setting';
         $to_read['columns'] = array('SETTING_ID');
         $to_read['condition_columns'][':t'] = 'setting_type';
         $to_read['condition_select_types'][':t'] = '=';
         $to_read['condition_values'][':t'] = 'site_menu';
         $to_read['value_types'][':t'] = 'str';
         $setting = $db->read($to_read);
         if (empty($setting)) {
             $setting = new Setting();
             $setting->_name = 'Site Menu';
             $setting->_type = 'site_menu';
             $setting->_data = json_encode(array(array('ctl' => $ctl, 'name' => $name)));
             $setting->create();
         } else {
             $setting = new Setting($setting[0]['SETTING_ID']);
             $data = json_decode($setting->_data, true);
             $data[] = array('ctl' => $ctl, 'name' => $name);
             $setting->_data = json_encode($data);
             $setting->update('_data', 'str');
         }
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
 /**
  * Class constructor
  *
  * @access	public
  */
 public function __construct()
 {
     $this->_db =& Database::load();
     $this->get_setting();
     $this->route();
     //used if blog is set as default page
     $this->_title = $this->_controller->_title;
     $this->_menu = $this->_controller->_menu;
 }
 /**
  * Class constructor
  *
  * Constructor has to be called in each child class constructor before any function
  *
  * In order to verify session validity and then retrieve user permissions
  *
  * @access	protected
  */
 protected function __construct()
 {
     if (!extension_loaded('json')) {
         throw new Exception('Json not loaded');
     }
     $this->_db =& Database::load();
     $this->_session_fct = new Session();
     $this->_session_fct->verify_session();
     $this->permission();
     $this->_display_html = true;
 }
 /**
  * Class constructor
  *
  * Load the database instance and determine some informations about the page viewed
  *
  * This contructor has to be called in each child class before any actions
  *
  * @access	protected
  */
 protected function __construct()
 {
     if (!extension_loaded('json')) {
         $mail = new Mail(WS_EMAIL, 'Json not loaded', 'Lynxpress needs json extension to be loaded');
         $mail->send();
         throw new Exception('Json not loaded');
     }
     $this->_db =& Database::load();
     $this->pid();
     $this->page();
 }
 /**
  * Class constructor
  *
  * @access	public
  * @param	string [$type]
  */
 public function __construct($type = 'rss')
 {
     self::check_ext();
     $this->_db =& Database::load();
     if (in_array($type, array('rss', 'sitemap'))) {
         $this->_type = $type;
     } else {
         $this->_type = 'rss';
     }
     $this->get_content();
     $this->build_xml();
 }
 /**
  * Retrieve share buttons setting
  *
  * @static
  * @access	public
  * @return	array
  */
 public static function get_setting()
 {
     $db =& Database::load();
     $to_read['table'] = 'setting';
     $to_read['columns'] = array('setting_data');
     $to_read['condition_columns'][':t'] = 'setting_type';
     $to_read['condition_select_types'][':t'] = '=';
     $to_read['condition_values'][':t'] = 'share_buttons';
     $to_read['value_types'][':t'] = 'str';
     $array = $db->read($to_read);
     $array = json_decode($array[0]['setting_data']);
     return $array;
 }
 /**
  * Class constructor
  *
  * @access	public
  * @param	mixed [$tables] Tables to backup
  */
 public function __construct($tables = '*')
 {
     $this->_db =& Database::load();
     if ($tables = '*') {
         $this->get_tables();
     } elseif (is_array($tables)) {
         $this->_tables = $tables;
     } else {
         throw new Exception('Invalid request');
     }
     $this->_sql = '# ************************************************************' . "\n";
     $this->_sql .= '# Lynxpress dump' . "\n";
     $this->_sql .= '# Version ' . WS_VERSION . "\n";
     $this->_sql .= '# Database: ' . DB_NAME . "\n";
     $this->_sql .= '# Generation time: ' . date(DATE_ATOM) . "\n";
     $this->_sql .= '# ************************************************************' . "\n\n";
     foreach ($this->_tables as $table) {
         $this->backup_table($table);
     }
 }
 /**
  * Session constructor
  *
  * Check if cookie or session variables exists to retrieve directly informations
  *
  * Otherwise it calls get_browser method
  *
  * @access public
  */
 public function __construct()
 {
     session_start();
     $this->_db =& Database::load();
     if (VCookie::lynxpress()) {
         $array = json_decode(stripslashes(VCookie::lynxpress()), true);
         $_SESSION['html5'] = $array['html5'];
         $_SESSION['renderer'] = $array['renderer'];
         $this->_html5 = VSession::html5();
         $this->_renderer = VSession::renderer();
     } elseif (!VSession::html5() && !VSession::renderer()) {
         $this->get_browser();
         $_SESSION['html5'] = $this->_html5;
         $_SESSION['renderer'] = $this->_renderer;
         setcookie('lynxpress', json_encode(array('html5' => $this->_html5, 'renderer' => $this->_renderer)), time() + 365 * 24 * 60 * 60);
     } else {
         $this->_html5 = VSession::html5();
         $this->_renderer = VSession::renderer();
     }
 }
 /**
  * Class constructor
  *
  * @access	protected
  */
 protected function __construct()
 {
     $this->_db =& Database::load();
     $this->_display_html = false;
 }
 /**
  *Class constructor
  *
  * @access	protected
  */
 protected function __construct()
 {
     $this->_db =& Database::load();
 }
 /**
  * Create a datalist for search input
  *
  * @static
  * @access	public
  * @param	string [$list] Datalist id
  */
 public static function datalist($list)
 {
     $db =& Database::load();
     $to_read['table'] = 'post';
     $to_read['columns'] = array('post_title');
     $to_read['condition_columns'][':s'] = 'post_status';
     $to_read['condition_select_types'][':s'] = '=';
     $to_read['condition_values'][':s'] = 'publish';
     $to_read['value_types'][':s'] = 'str';
     $posts = $db->read($to_read);
     if (is_array($posts)) {
         echo '<datalist id="' . $list . '">';
         foreach ($posts as $value) {
             echo '<option value="' . $value['post_title'] . '">';
         }
         echo '</datalist>';
     }
 }
 /**
  * Return an array of all plugins entry points
  *
  * @static
  * @access	public
  * @return	array
  */
 public static function plugins_infos()
 {
     $db =& Database::load();
     $return = array();
     $to_read['table'] = 'setting';
     $to_read['columns'] = array('setting_data');
     $to_read['condition_columns'][':t'] = 'setting_type';
     $to_read['condition_select_types'][':t'] = '=';
     $to_read['condition_values'][':t'] = 'plugin';
     $to_read['value_types'][':t'] = 'str';
     $plugins = $db->read($to_read);
     if (!empty($plugins)) {
         foreach ($plugins as $plugin) {
             $plugin['setting_data'] = json_decode($plugin['setting_data'], true);
             $return[] = array('name' => $plugin['setting_data']['name'], 'namespace' => $plugin['setting_data']['namespace'], 'entry_point' => $plugin['setting_data']['entry_point']);
         }
     }
     return $return;
 }
 /**
  * Retrieve setting menu to extend website menu
  *
  * @static
  * @access	public
  * @return	array
  */
 public static function extend()
 {
     $db =& Database::load();
     $to_read['table'] = 'setting';
     $to_read['columns'] = array('setting_data');
     $to_read['condition_columns'][':t'] = 'setting_type';
     $to_read['condition_select_types'][':t'] = '=';
     $to_read['condition_values'][':t'] = 'site_menu';
     $to_read['value_types'][':t'] = 'str';
     $data = $db->read($to_read);
     if (empty($data)) {
         return array();
     }
     return json_decode($data[0]['setting_data'], true);
 }
 /**
  * Log an action into database, logs are viewed by administrator in the dashboard
  *
  * @static
  * @access	public
  * @param	string [$msg] Action message to log
  */
 public static function monitor_activity($msg)
 {
     $db =& Database::load();
     $to_create['table'] = 'activity';
     $to_create['columns'] = array(':id' => 'USER_ID', ':data' => 'data', ':date' => 'date');
     $to_create['values'] = array(':id' => VSession::user_id(), ':data' => $msg, ':date' => date('Y-m-d H:i:s'));
     $to_create['types'] = array(':id' => 'int', ':data' => 'str', ':date' => 'str');
     $db->create($to_create);
 }
 /**
  * Retrieve stored roles
  *
  * @access	private
  */
 private function get_content()
 {
     try {
         $db =& Database::load();
         //retrieve array of all roles
         $to_read['table'] = 'setting';
         $to_read['columns'] = array('setting_data');
         $to_read['condition_columns'][':t'] = 'setting_type';
         $to_read['condition_select_types'][':t'] = '=';
         $to_read['condition_values'][':t'] = 'all_roles';
         $to_read['value_types'][':t'] = 'str';
         $all_roles = $db->read($to_read);
         if (!empty($all_roles)) {
             $this->_roles = json_decode($all_roles[0]['setting_data'], true);
         } else {
             $this->_roles = array();
         }
         //end first retrieve
         $to_read = null;
         //retrieve each role with its authorizations
         if (!empty($this->_roles)) {
             $to_read['table'] = 'setting';
             $to_read['columns'] = array('SETTING_ID');
             $to_read['condition_columns'][':t'] = 'setting_type';
             $to_read['condition_select_types'][':t'] = '=';
             $to_read['condition_values'][':t'] = 'role';
             $to_read['value_types'][':t'] = 'str';
             $roles = $db->read($to_read);
             foreach ($roles as $value) {
                 $role = new Setting($value['SETTING_ID']);
                 $name = $role->_name;
                 $this->_roles_auth["_{$name}"] = json_decode($role->_data, true);
             }
         }
         //end second retrieve
     } catch (Exception $e) {
         $this->_roles = array();
         $this->_roles_auth = array();
     }
 }