/** * * Model-specific setup. * * @return void * */ protected function _setup() { $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR; $this->_table_name = $this->_config['prefix'] . Solar_File::load($dir . 'table_name.php'); $this->_table_cols = Solar_File::load($dir . 'table_cols.php'); $this->_belongsTo('comments', array('foreign_class' => 'Foresmo_Model_Comments')); }
/** * * Model-specific setup. * * @return void * */ protected function _setup() { $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR; $this->_table_name = Solar_File::load($dir . 'table_name.php'); $this->_table_cols = Solar_File::load($dir . 'table_cols.php'); $this->_index = Solar_File::load($dir . 'index_info.php'); /** * Special columns */ $this->_serialize_cols[] = 'prefs'; $this->_calculate_cols[] = 'tags_as_string'; /** * Filters */ // make sure the name is unique for its area and model $where = array('inherit = :inherit', 'area_id = :area_id'); $this->_addFilter('name', 'validateUnique', $where); // other filters $this->_addFilter('email', 'validateEmail'); $this->_addFilter('uri', 'validateUri'); $this->_addFilter('editor_ipaddr', 'validateIpv4'); $this->_addFilter('locale', 'validateLocaleCode'); $this->_addFilter('mime', 'validateMimeType'); $this->_addFilter('tags_as_string', 'validateSepWords'); /** * Relationships. */ $this->_belongsTo('area'); $this->_hasMany('taggings'); $this->_hasMany('tags', array('through' => 'taggings')); }
/** * * Loads a class or interface file from the include_path. * * Thanks to Robert Gonzalez for the report leading to this method. * * @param string $name A Solar (or other) class or interface name. * * @return void * * @todo Add localization for errors * */ public static function autoload($name) { // did we ask for a non-blank name? if (trim($name) == '') { throw Solar::exception('Solar_Class', 'ERR_AUTOLOAD_EMPTY', 'No class or interface named for loading.', array('name' => $name)); } // pre-empt further searching for the named class or interface. // do not use autoload, because this method is registered with // spl_autoload already. $exists = class_exists($name, false) || interface_exists($name, false); if ($exists) { return; } // convert the class name to a file path. $file = str_replace('_', DIRECTORY_SEPARATOR, $name) . '.php'; // include the file and check for failure. we use Solar_File::load() // instead of require() so we can see the exception backtrace. Solar_File::load($file); // if the class or interface was not in the file, we have a problem. // do not use autoload, because this method is registered with // spl_autoload already. $exists = class_exists($name, false) || interface_exists($name, false); if (!$exists) { throw Solar::exception('Solar_Class', 'ERR_AUTOLOAD_FAILED', 'Class or interface does not exist in loaded file', array('name' => $name, 'file' => $file)); } }
/** * * Model-specific setup. * * @return void * */ protected function _setup() { $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR; $this->_table_name = Solar_File::load($dir . 'table_name.php'); $this->_table_cols = Solar_File::load($dir . 'table_cols.php'); $this->_belongsTo('node'); }
/** * * Model-specific setup. * * @return void * */ protected function _setup() { $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR; $this->_table_name = $this->_config['prefix'] . Solar_File::load($dir . 'table_name.php'); $this->_table_cols = Solar_File::load($dir . 'table_cols.php'); $this->_hasMany('moduleinfo', array('foreign_class' => 'Foresmo_Model_ModuleInfo', 'foreign_key' => 'module_id')); }
/** * * Model-specific setup. * * @return void * */ protected function _setup() { $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR; $this->_table_name = $this->_config['prefix'] . Solar_File::load($dir . 'table_name.php'); $this->_table_cols = Solar_File::load($dir . 'table_cols.php'); $this->_hasMany('comments'); $this->_hasMany('permissions', array('through' => 'groupspermissions')); }
public function testCallbacks_instanceMethod() { $file = Solar_Class::dir('Mock_Solar') . 'callbacks-instance-method.php'; Solar_File::load($file); $instance = Solar::factory('Solar_Callbacks_Instance_Method'); Solar::callbacks(array(array($instance, 'callback'))); $this->assertTrue($GLOBALS['SOLAR_CALLBACKS_INSTANCE_METHOD']); }
/** * * Model setup. * * @return void * */ protected function _setup() { $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR; $this->_table_name = Solar_File::load($dir . 'table_name.php'); $this->_table_cols = Solar_File::load($dir . 'table_cols.php'); $this->_model_name = 'users'; $this->_index = array('created', 'updated', 'handle' => 'unique'); }
/** * * Model-specific setup. * * @return void * */ protected function _setup() { $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR; $this->_table_name = $this->_config['prefix'] . Solar_File::load($dir . 'table_name.php'); $this->_table_cols = Solar_File::load($dir . 'table_cols.php'); $this->_hasMany('userinfo', array('foreign_class' => 'Foresmo_Model_UserInfo', 'foreign_key' => 'user_id')); $this->_hasOne('groups', array('foreign_class' => 'Foresmo_Model_Groups', 'native_col' => 'group_id', 'foreign_col' => 'id')); }
/** * * Model-specific setup. * * @return void * */ protected function _setup() { $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR; $this->_table_name = $this->_config['prefix'] . Solar_File::load($dir . 'table_name.php'); $this->_table_cols = Solar_File::load($dir . 'table_cols.php'); $this->_belongsTo('tags', array('foreign_key' => 'id')); $this->_belongsTo('posts', array('foreign_key' => 'id')); }
/** * * Model-specific setup. * * @return void * */ protected function _setup() { $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR; $this->_table_name = $this->_config['prefix'] . Solar_File::load($dir . 'table_name.php'); $this->_table_cols = Solar_File::load($dir . 'table_cols.php'); $this->_hasMany('posts_tags', array('foreign_class' => 'Foresmo_Model_PostsTags', 'foreign_key' => 'tag_id')); $this->_hasMany('posts', array('foreign_class' => 'Foresmo_Model_Posts', 'through' => 'posts_tags', 'through_key' => 'post_id', 'through_native_col' => 'tag_id', 'through_foreign_col' => 'post_id', 'conditions' => array('status = ?' => array(1)))); }
/** * * Model setup. * * @return void * */ protected function _setup() { $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR; $this->_table_name = Solar_File::load($dir . 'table_name.php'); $this->_table_cols = Solar_File::load($dir . 'table_cols.php'); $this->_addFilter('email', 'validateEmail'); $this->_addFilter('uri', 'validateUri'); $this->_index_info = array('created', 'updated', 'email' => 'unique', 'uri'); }
/** * * Model setup. * * @return void * */ protected function _setup() { $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR; $this->_table_name = Solar_File::load($dir . 'table_name.php'); $this->_table_cols = Solar_File::load($dir . 'table_cols.php'); $this->_model_name = 'taggings'; $this->_belongsTo('node'); $this->_belongsTo('tag'); $this->_index = array('node_id', 'tag_id'); }
/** * * Model setup. * * @return void * */ protected function _setup() { $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR; $this->_table_name = Solar_File::load($dir . 'table_name.php'); $this->_table_cols = Solar_File::load($dir . 'table_cols.php'); $this->_model_name = 'tags'; $this->_hasMany('taggings'); $this->_hasMany('nodes', array('through' => 'taggings')); $this->_index = array('name' => 'unique'); }
/** * * Model setup. * * @return void * */ protected function _setup() { $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR; $this->_table_name = Solar_File::load($dir . 'table_name.php'); $this->_table_cols = Solar_File::load($dir . 'table_cols.php'); // recognize sequence columns $this->_sequence_cols = array('seq_foo' => 'test_solar_foo', 'seq_bar' => 'test_solar_bar'); // recognize serialize columns $this->_serialize_cols = 'serialize'; }
/** * * Model setup. * * @return void * */ protected function _setup() { $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR; $this->_table_name = Solar_File::load($dir . 'table_name.php'); $this->_table_cols = Solar_File::load($dir . 'table_cols.php'); $this->_model_name = 'areas'; $this->_hasMany('nodes'); $this->_belongsTo('user'); $this->_index = array('created', 'updated', 'user_id'); }
/** * * Model-specific setup. * * @return void * */ protected function _setup() { $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR; $this->_table_name = $this->_config['prefix'] . Solar_File::load($dir . 'table_name.php'); $this->_table_cols = Solar_File::load($dir . 'table_cols.php'); $this->_hasMany('postinfo', array('foreign_class' => 'Foresmo_Model_PostInfo', 'foreign_key' => 'post_id')); $this->_hasMany('comments', array('foreign_class' => 'Foresmo_Model_Comments', 'foreign_key' => 'post_id')); $this->_hasMany('posts_tags', array('foreign_class' => 'Foresmo_Model_PostsTags', 'foreign_key' => 'post_id')); $this->_hasMany('tags', array('foreign_class' => 'Foresmo_Model_Tags', 'through' => 'posts_tags', 'through_key' => 'tag_id')); $this->_hasOne('users', array('foreign_class' => 'Foresmo_Model_Users', 'cols' => array('id', 'username', 'email'), 'native_col' => 'user_id', 'foreign_col' => 'id')); }
/** * * Model setup. * * @return void * */ protected function _setup() { $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR; $this->_table_name = Solar_File::load($dir . 'table_name.php'); $this->_table_cols = Solar_File::load($dir . 'table_cols.php'); $this->_model_name = 'nodes'; $this->_belongsTo('area'); $this->_belongsTo('user'); $this->_hasOne('meta'); $this->_hasMany('comments'); $this->_hasMany('taggings'); $this->_hasManyThrough('tags', 'taggings'); $this->_index = array('created', 'updated', 'area_id', 'user_id', 'node_id', 'inherit'); }
/** * * Model-specific setup. * * @return void * */ protected function _setup() { $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR; $this->_table_name = Solar_File::load($dir . 'table_name.php'); $this->_table_cols = Solar_File::load($dir . 'table_cols.php'); $this->_index = Solar_File::load($dir . 'index_info.php'); /** * Behaviors (serialize, sequence, filter). */ $this->_serialize_cols[] = 'prefs'; /** * Relationships. */ $this->_hasMany('nodes'); }
/** * * Model setup. * * @return void * */ protected function _setup() { $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR; $this->_table_name = Solar_File::load($dir . 'table_name.php'); $this->_table_cols = Solar_File::load($dir . 'table_cols.php'); $this->_model_name = 'nodes'; $this->_belongsTo('area'); $this->_belongsTo('area_false', array('foreign_name' => 'areas', 'where' => '0=1')); $this->_belongsTo('user'); $this->_hasOne('meta'); $this->_hasOne('meta_false', array('foreign_name' => 'metas', 'where' => '0=1')); $this->_hasMany('comments'); $this->_hasMany('comments_false', array('foreign_name' => 'comments', 'where' => '0=1', 'join_flag' => true)); $this->_hasMany('taggings'); $this->_hasManyThrough('tags', 'taggings'); $this->_index = array('created', 'updated', 'area_id', 'user_id', 'node_id', 'inherit'); $this->_hasManyThrough('tags_false', 'taggings', array('foreign_name' => 'tags', 'where' => '0=1')); $this->_hasMany('taggings_false', array('foreign_name' => 'taggings', 'where' => '0=1')); $this->_hasManyThrough('tags_through_false', 'taggings_false', array('foreign_name' => 'tags')); $this->_hasManyThrough('tags_false_through_false', 'taggings_false', array('foreign_name' => 'tags', 'where' => '0=1')); }
/** * * Loads the translation array for a given class. * * @param string $class The class name to load translations for. * * @return void * */ protected function _load($class) { // build the file name. note that we use the fixdir() // method, which automatically replaces '/' with the // correct directory separator. $base = str_replace('_', '/', $class); $file = Solar_Dir::fix($base . '/Locale/') . $this->_code . '.php'; // can we find the file? $target = Solar_File::exists($file); if ($target) { // put the locale values into the shared locale array $this->trans[$class] = (array) Solar_File::load($target); } else { // could not find file. // fail silently, as it's often the case that the // translation file simply doesn't exist. $this->trans[$class] = array(); } }
/** * * Model-specific setup. * * @return void * */ protected function _setup() { $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR; $this->_table_name = $this->_config['prefix'] . Solar_File::load($dir . 'table_name.php'); $this->_table_cols = Solar_File::load($dir . 'table_cols.php'); }
/** * * Runs a series of callbacks using call_user_func_array(). * * The callback array looks like this: * * {{code: php * $callbacks = array( * // static method call * array('Class_Name', 'method', $param1, $param2, ...), * * // instance method call on a registry object * array('registry-key', 'method', $param1, $param2, ...), * * // instance method call * array($object, 'method', $param1, $param2, ...), * * // function call * array(null, 'function', $param1, $param2, ...), * * // file include, as in previous versions of Solar * 'path/to/file.php', * ); * }} * * @param array $callbacks The array of callbacks. * * @return void * * @see start() * * @see stop() * */ public static function callbacks($callbacks) { foreach ((array) $callbacks as $params) { // include a file as in previous versions of Solar if (is_string($params)) { Solar_File::load($params); continue; } // $spec is an object instance, class name, or registry key $spec = array_shift($params); if (!is_object($spec)) { // not an object, so treat as a class name ... $spec = (string) $spec; // ... unless it's a registry key. if (Solar_Registry::exists($spec)) { $spec = Solar_Registry::get($spec); } } // the method to call on $spec $func = array_shift($params); // make the call if ($spec) { call_user_func_array(array($spec, $func), $params); } else { call_user_func_array($func, $params); } } }
/** * * Gets the option settings from the class hierarchy. * * @return array * */ protected function _fetchGetoptOptions() { // the options to be set $options = array(); // find the parents of this class, including this class $parents = Solar_Class::parents($this, true); array_shift($parents); // Solar_Base // get Info/options.php for each class in the stack foreach ($parents as $class) { $file = Solar_Class::file($class, 'Info/options.php'); if ($file) { $options = array_merge($options, (array) Solar_File::load($file)); } } return $options; }
/** * _install * Install a new blog */ public function _install() { $this->_post = $this->_request->post(); if ($this->installed) { $this->error = 'Blog is already installed'; $this->message = 'Blog is already installed'; $this->success = false; return; } if (!empty($this->_post['db_type'])) { $db_type = ucfirst($this->_post['db_type']); $adapter = 'Solar_Sql_Adapter_' . $db_type; } else { $this->error = 'DB Type cannot be blank'; $this->message = 'DB Type cannot be blank'; $this->success = false; return; } Solar_Config::set('Solar_Sql', 'adapter', $adapter); Solar_Config::set($adapter, 'host', $this->_post['db_host']); Solar_Config::set($adapter, 'user', $this->_post['db_username']); Solar_Config::set($adapter, 'pass', $this->_post['db_password']); Solar_Config::set($adapter, 'name', $this->_post['db_name']); Solar_Config::set($adapter, 'prefix', $this->_post['db_prefix']); $adapter = Solar::factory($adapter); try { $adapter->connect(); } catch (Exception $e) { $this->error = $e->getMessage(); $this->message = 'Cannot connect to database! Please ensure valid DB info.'; $this->success = false; return; } $config_file = Solar::$system . '/source/foresmo/config/default.php'; $config_content = $this->_getConfigContent(); if (($handle = @fopen($config_file, 'w')) !== false) { if (@fwrite($handle, $config_content) === false) { fclose($handle); $this->error = "Cannot write to: {$config_file}. Please set the permissions to 777 for this file."; $this->message = "Cannot write to: {$config_file}. Please set the permissions to 777 for this file."; $this->success = false; return; } else { fclose($handle); } } else { $this->error = "Could not open {$config_file}, please ensure that this file exists and is writable by the server."; $this->message = "Could not open {$config_file}, please ensure that this file exists and is writable by the server."; $this->success = false; return; } $schema = Solar::$system . '/source/foresmo/Foresmo/Schemas/' . $db_type . '.php'; $schema_sql = Solar_File::load($schema); $schema_sql = str_replace('[prefix]', $this->_post['db_prefix'], $schema_sql); try { $adapter->query($schema_sql); } catch (Exception $e) { // tables already exist? $this->error = $e->getMessage(); $this->message = 'Error creating database tables, do they already exist?'; $this->success = false; return; } $errors = array(); $matches = array(); $ret_str = ''; $this->_post['blog_user'] = trim($this->_post['blog_user']); if (empty($this->_post['blog_password']) == true || empty($this->_post['blog_password2']) == true || empty($this->_post['blog_user']) == true || empty($this->_post['blog_title']) == true || empty($this->_post['blog_email']) == true) { $errors[] = 'No fields should be left blank!'; } preg_match('/^([.0-9a-z_-]+)@(([0-9a-z-]+\\.)+[0-9a-z]{2,4})$/i', $this->_post['blog_email'], $matches); if (count($matches) == 0) { $errors[] = 'Not a valid email address.'; } if (strlen($this->_post['blog_password']) < 7) { $errors[] = 'The user password must be seven characters or more'; } if ($this->_post['blog_password'] !== $this->_post['blog_password2']) { $errors[] = 'The user password fields did not match!'; } if (count($errors) > 0) { $ret_str .= '<p class="error"><b>Validation Errors:</b></p>'; foreach ($errors as $error) { $ret_str .= '<span class="error">' . $error . '</span><br />'; } $this->error = $ret_str; $this->message = $ret_str; $this->success = false; return; } $username = $this->_post['blog_user']; $password = $this->_post['blog_password']; $hasher = new Foresmo_Hashing(8, false); $pwhash = $hasher->hashPassword($password); $email = trim($this->_post['blog_email']); $table = $this->_post['db_prefix'] . 'groups'; $data = array('name' => 'Admin'); $adapter->insert($table, $data); $last_insert_id = $adapter->lastInsertId($table, 'id'); $permissions = array(); $table = $this->_post['db_prefix'] . 'permissions'; $data = array('name' => 'create_post'); $adapter->insert($table, $data); $permissions[] = $adapter->lastInsertId($table, 'id'); $data = array('name' => 'edit_post'); $adapter->insert($table, $data); $permissions[] = $adapter->lastInsertId($table, 'id'); $data = array('name' => 'delete_post'); $adapter->insert($table, $data); $permissions[] = $adapter->lastInsertId($table, 'id'); $data = array('name' => 'create_page'); $adapter->insert($table, $data); $permissions[] = $adapter->lastInsertId($table, 'id'); $data = array('name' => 'edit_page'); $adapter->insert($table, $data); $permissions[] = $adapter->lastInsertId($table, 'id'); $data = array('name' => 'delete_page'); $adapter->insert($table, $data); $permissions[] = $adapter->lastInsertId($table, 'id'); $data = array('name' => 'manage_modules'); $adapter->insert($table, $data); $permissions[] = $adapter->lastInsertId($table, 'id'); $data = array('name' => 'blog_settings'); $adapter->insert($table, $data); $permissions[] = $adapter->lastInsertId($table, 'id'); $data = array('name' => 'manage_themes'); $adapter->insert($table, $data); $permissions[] = $adapter->lastInsertId($table, 'id'); $table = $this->_post['db_prefix'] . 'groups_permissions'; foreach ($permissions as $permission) { $data = array('group_id' => $last_insert_id, 'permission_id' => (int) $permission); $adapter->insert($table, $data); } $table = $this->_post['db_prefix'] . 'users'; $data = array('group_id' => $last_insert_id, 'username' => $username, 'password' => $pwhash, 'email' => strtolower($email)); $adapter->insert($table, $data); $table = $this->_post['db_prefix'] . 'options'; $data = array('name' => 'blog_installed', 'type' => 1, 'value' => time()); $adapter->insert($table, $data); $data = array('name' => 'blog_theme', 'type' => 0, 'value' => 'default'); $adapter->insert($table, $data); $data = array('name' => 'blog_admin_theme', 'type' => 0, 'value' => 'default'); $adapter->insert($table, $data); $data = array('name' => 'blog_admin_theme_options', 'type' => 0, 'value' => serialize(array())); $adapter->insert($table, $data); $data = array('name' => 'blog_theme_options', 'type' => 0, 'value' => serialize(array())); $adapter->insert($table, $data); $data = array('name' => 'blog_title', 'type' => 0, 'value' => $this->_post['blog_title']); $adapter->insert($table, $data); $data = array('name' => 'blog_date_format', 'type' => 0, 'value' => 'F j, Y, g:ia'); $adapter->insert($table, $data); $data = array('name' => 'blog_timezone', 'type' => 0, 'value' => 'America/New_York'); $adapter->insert($table, $data); $data = array('name' => 'blog_posts_per_page', 'type' => 0, 'value' => 10); $adapter->insert($table, $data); $data = array('name' => 'blog_uid', 'type' => 0, 'value' => sha1($_SERVER['HTTP_HOST'] . substr(md5(uniqid(mt_rand(), TRUE)), 0, 12))); $adapter->insert($table, $data); $data = array('name' => 'blog_comment_link_limit', 'type' => 0, 'value' => 3); $adapter->insert($table, $data); $data = array('name' => 'blog_comment_default_status', 'type' => 0, 'value' => 3); $adapter->insert($table, $data); $table = $this->_post['db_prefix'] . 'posts'; $data = array('slug' => 'my-first-post', 'content_type' => 1, 'title' => 'My first post!', 'content' => "Welcome to {$this->_post['blog_title']}. Look forward to new blog posts soon!", 'excerpt' => "Welcome to {$this->_post['blog_title']}. Look forward to new blog posts soon!", 'user_id' => 1, 'status' => 1, 'pubdate' => time(), 'modified' => time()); $adapter->insert($table, $data); $table = $this->_post['db_prefix'] . 'comments'; $data = array('post_id' => 1, 'name' => 'Foresmo', 'email' => '*****@*****.**', 'url' => 'http://foresmo.com', 'ip' => sprintf("%u", ip2long('192.168.0.1')), 'content' => 'Congratulations!', 'status' => 1, 'date' => time(), 'type' => 0); $adapter->insert($table, $data); $table = $this->_post['db_prefix'] . 'tags'; $data = array('tag' => 'Foresmo', 'tag_slug' => 'foresmo'); $adapter->insert($table, $data); $table = $this->_post['db_prefix'] . 'posts_tags'; $data = array('post_id' => 1, 'tag_id' => 1); $adapter->insert($table, $data); $this->success = true; $this->message = 'Foresmo installed! Click <a href="/">here</a> to check it out! Also, don\'t forget to change the permissions of the config back to read only.'; }
/** * ajax_blog_install * This ajax action handles blog installation * * @param $post_data * @return string */ public function ajax_blog_install($post_data) { if ($this->installed) { return 'Blog is already installed!'; } if (!empty($post_data['db_type'])) { $db_type = ucfirst($post_data['db_type']); $adapter = 'Solar_Sql_Adapter_' . $db_type; } else { return 'DB Type cannot be blank!'; } Solar_Config::set('Solar_Sql', 'adapter', $adapter); Solar_Config::set($adapter, 'host', $post_data['db_host']); Solar_Config::set($adapter, 'user', $post_data['db_username']); Solar_Config::set($adapter, 'pass', $post_data['db_password']); Solar_Config::set($adapter, 'name', $post_data['db_name']); Solar_Config::set($adapter, 'prefix', $post_data['db_prefix']); $adapter = Solar::factory($adapter); try { $adapter->connect(); } catch (Exception $e) { return 'Cannot connect to database! Please ensure valid DB info.'; } $this->random_str = Foresmo::randomString(18); $config_file = Solar::$system . '/config/Solar.config.php'; $config_content = $this->_getConfigContent($post_data); if (($handle = @fopen($config_file, 'w')) !== false) { if (@fwrite($handle, $config_content) === false) { fclose($handle); return "Cannot write to: {$config_file}. Please set the permissions to 777 for this file."; } else { fclose($handle); } } else { return "Could not open {$config_file}, please ensure that this file exists and is writable."; } $schema = Solar::$system . '/source/foresmo/Foresmo/Schemas/' . $db_type . '.php'; $schema_sql = Solar_File::load($schema); $schema_sql = str_replace('[prefix]', $post_data['db_prefix'], $schema_sql); try { $adapter->query($schema_sql); } catch (Exception $e) { // tables already exist? } $errors = array(); $matches = array(); $ret_str = ''; $post_data['blog_user'] = trim($post_data['blog_user']); if (empty($post_data['blog_password']) == true || empty($post_data['blog_password2']) == true || empty($post_data['blog_user']) == true || empty($post_data['blog_title']) == true || empty($post_data['blog_email']) == true) { $errors[] = 'No fields should be left blank!'; } preg_match('/^([.0-9a-z_-]+)@(([0-9a-z-]+\\.)+[0-9a-z]{2,4})$/i', $post_data['blog_email'], $matches); if (count($matches) == 0) { $errors[] = 'Not a valid email address.'; } if (strlen($post_data['blog_password']) < 7) { $errors[] = 'The user password must be seven characters or more'; } if ($post_data['blog_password'] !== $post_data['blog_password2']) { $errors[] = 'The user password fields did not match!'; } if (count($errors) > 0) { $ret_str .= '<p class="error"><b>Validation Errors:</b></p>'; foreach ($errors as $error) { $ret_str .= '<span class="error">' . $error . '</span><br />'; } return $ret_str; } $username = $post_data['blog_user']; $password = $post_data['blog_password']; $password = md5($this->random_str . $password); $email = trim($post_data['blog_email']); $table = $post_data['db_prefix'] . 'groups'; $data = array('name' => 'Admin'); $adapter->insert($table, $data); $last_insert_id = $adapter->lastInsertId($table, 'id'); $permissions = array(); $table = $post_data['db_prefix'] . 'permissions'; $data = array('name' => 'create_post'); $adapter->insert($table, $data); $permissions[] = $adapter->lastInsertId($table, 'id'); $data = array('name' => 'edit_post'); $adapter->insert($table, $data); $permissions[] = $adapter->lastInsertId($table, 'id'); $data = array('name' => 'delete_post'); $adapter->insert($table, $data); $permissions[] = $adapter->lastInsertId($table, 'id'); $data = array('name' => 'create_page'); $adapter->insert($table, $data); $permissions[] = $adapter->lastInsertId($table, 'id'); $data = array('name' => 'edit_page'); $adapter->insert($table, $data); $permissions[] = $adapter->lastInsertId($table, 'id'); $data = array('name' => 'delete_page'); $adapter->insert($table, $data); $permissions[] = $adapter->lastInsertId($table, 'id'); $table = $post_data['db_prefix'] . 'groups_permissions'; foreach ($permissions as $permission) { $data = array('group_id' => $last_insert_id, 'permission_id' => (int) $permission); $adapter->insert($table, $data); } $table = $post_data['db_prefix'] . 'users'; $data = array('group_id' => $last_insert_id, 'username' => $username, 'password' => $password, 'email' => strtolower($email)); $adapter->insert($table, $data); $table = $post_data['db_prefix'] . 'options'; $data = array('name' => 'blog_installed', 'type' => 1, 'value' => time()); $adapter->insert($table, $data); $data = array('name' => 'blog_theme', 'type' => 0, 'value' => 'default'); $adapter->insert($table, $data); $data = array('name' => 'blog_title', 'type' => 0, 'value' => $post_data['blog_title']); $adapter->insert($table, $data); $data = array('name' => 'blog_date_format', 'type' => 0, 'value' => 'F j, Y, g:ia'); $adapter->insert($table, $data); $data = array('name' => 'blog_timezone', 'type' => 0, 'value' => '-4:00'); $adapter->insert($table, $data); $data = array('name' => 'blog_posts_per_page', 'type' => 0, 'value' => 10); $adapter->insert($table, $data); $data = array('name' => 'blog_comment_link_limit', 'type' => 0, 'value' => 3); $adapter->insert($table, $data); $table = $post_data['db_prefix'] . 'posts'; $data = array('slug' => 'my-first-post', 'content_type' => 1, 'title' => 'My first post!', 'content' => "Welcome to {$post_data['blog_title']}. Look forward to new blog posts soon!", 'user_id' => 1, 'status' => 1, 'pubdate' => time(), 'modified' => time()); $adapter->insert($table, $data); $table = $post_data['db_prefix'] . 'comments'; $data = array('post_id' => 1, 'name' => 'Foresmo', 'email' => '*****@*****.**', 'url' => 'http://foresmo.com', 'ip' => sprintf("%u", ip2long('192.168.0.1')), 'content' => 'Congratulations!', 'status' => 1, 'date' => time(), 'type' => 0); $adapter->insert($table, $data); $table = $post_data['db_prefix'] . 'tags'; $data = array('tag' => 'Foresmo', 'tag_slug' => 'foresmo'); $adapter->insert($table, $data); $table = $post_data['db_prefix'] . 'posts_tags'; $data = array('post_id' => 1, 'tag_id' => 1); $adapter->insert($table, $data); $table = $post_data['db_prefix'] . 'modules'; $data = array('name' => 'Pages', 'enabled' => 1); $adapter->insert($table, $data); $data = array('name' => 'Search', 'enabled' => 1); $adapter->insert($table, $data); $data = array('name' => 'Calendar', 'enabled' => 1); $adapter->insert($table, $data); $data = array('name' => 'Tags', 'enabled' => 1); $adapter->insert($table, $data); $data = array('name' => 'Links', 'enabled' => 1); $adapter->insert($table, $data); $data = array('name' => 'Archives', 'enabled' => 1); $adapter->insert($table, $data); $data = array('name' => 'Flickr', 'enabled' => 0); $adapter->insert($table, $data); $data = array('name' => 'Twitter', 'enabled' => 0); $adapter->insert($table, $data); $data = array('name' => 'Sections', 'enabled' => 0); $adapter->insert($table, $data); $table = $post_data['db_prefix'] . 'module_info'; $data = array('module_id' => 3, 'name' => 'start_of_week', 'type' => 0, 'value' => 0); $adapter->insert($table, $data); if ($db_type == 'Mysql') { $data = array('module_id' => 2, 'name' => 'search_adapter', 'type' => 0, 'value' => 'mysql'); } else { $data = array('module_id' => 2, 'name' => 'search_adapter', 'type' => 0, 'value' => 'default'); } $adapter->insert($table, $data); $data = array('module_id' => 2, 'name' => 'search_adapter_settings', 'type' => 0, 'value' => 'a:5:{s:7:"Default";a:0:{}s:6:"Google";a:0:{}s:5:"Mysql";a:0:{}s:6:"Lucene";a:0:{}s:5:"Sphinx";a:0:{}}'); $adapter->insert($table, $data); return 'Foresmo installed! Click <a href="/">here</a> to check it out! Also, don\'t forget to change the permissions of the config back to read only.'; }
/** * * Fetches config file values. * * Note that this method is overloaded by the variable type of $spec ... * * * `null|false` (or empty) -- This will not load any new configuration * values; you will get only the default [[Solar_Config::$_store]] array values * defined in the Solar class. * * * `string` -- The string is treated as a path to a Solar.config.php * file; the return value from that file will be used for [[Solar_Config::$_store]]. * * * `array` -- This will use the passed array for the [[Solar_Config::$_store]] * values. * * * `object` -- The passed object will be cast as an array, and those * values will be used for [[Solar_Config::$_store]]. * * @param mixed $spec A config specification. * * @return array A config array. * */ public static function fetch($spec = null) { // load the config file values. // use alternate config source if one is given. if (is_array($spec) || is_object($spec)) { $config = (array) $spec; } elseif (is_string($spec)) { // merge from array file return $config = (array) Solar_File::load($spec); } else { // no added config $config = array(); } return $config; }