public function __construct() { // Set the request data $this->request = ($_SERVER['REQUEST_METHOD'] == 'POST') ? $_POST : $_GET; // Load the API configuration file Kohana::config_load('api'); // Get the IP Address of the client submitting the API request // Check if the IP is from a shared internet connection if ( ! empty($_SERVER['HTTP_CLIENT_IP'])) { $this->request_ip_address = $_SERVER['HTTP_CLIENT_IP']; } // Check if the IP address is passed from a proxy server such as Nginx elseif ( ! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $this->request_ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $this->request_ip_address = $_SERVER['REMOTE_ADDR']; } // Unpack the URL parameters $this->api_parameters = serialize(array_keys($this->request)); // Instantiate the database $this->db = new Database(); }
/** * constructor; set up listeners * * @author Andy Bennett */ public function __construct() { $this->init(); Kohana::config_load('steamauth'); $this->conf = Kohana::config('steamauth.steamauth'); Event::add('steamauth.login_success', array('steamauth_listeners', 'login_success')); Event::add('steamauth.logged_in', array('steamauth_listeners', 'logged_in')); Event::add('steamauth.show_login_form', array('steamauth_listeners', 'login_form')); Event::add('steamauth.logged_out', array('steamauth_listeners', 'logged_out')); Event::add('steamform_auth_register.complete', array('steamauth_listeners', 'register_complete')); Event::add('steamform_auth_register.complete', array('auth_email_events', 'register_complete_email')); Event::add('steamform_auth_register.show_form', array('steamauth_listeners', 'register_show_form')); Event::add('steamform_auth_profile.complete', array('steamauth_listeners', 'profile_complete')); Event::add('steamform_auth_profile.show_form', array('steamauth_listeners', 'profile_show_form')); Event::add('steamauth.change_credential_form', array('steamauth_listeners', 'change_credential_form')); Event::add('steamauth.change_credential_email', array('auth_email_events', 'change_credential_email')); Event::add('steamauth.change_credential_success', array('steamauth_listeners', 'change_credential_success')); Event::add('steamauth.forgotten_credential_form', array('steamauth_listeners', 'forgotten_credential_form')); Event::add('steamauth.forgotten_credential_email', array('auth_email_events', 'forgotten_credential_email')); Event::add('steamauth.forgotten_credential_sent', array('steamauth_listeners', 'forgotten_credential_sent')); Event::add('steamauth.forgotten_identity_form', array('steamauth_listeners', 'forgotten_identity_form')); Event::add('steamauth.forgotten_identity_email', array('auth_email_events', 'forgotten_identity_email')); Event::add('steamauth.forgotten_identity_sent', array('steamauth_listeners', 'forgotten_identity_sent')); Event::add('steamauth.activated', array('auth_email_events', 'activation_email')); Event::add('steamauth.activated', array('steamauth_listeners', 'activation_complete')); Event::add('steamauth.activation_error', array('steamauth_listeners', 'activation_error')); Event::add('steamauth.forgotten_credential_reset_email', array('auth_email_events', 'forgotten_credential_reset_email')); Event::add('steamauth.forgotten_credential_reset', array('steamauth_listeners', 'forgotten_credential_reset')); Event::add('steamauth.forgotten_credential_reset_error', array('steamauth_listeners', 'forgotten_credential_reset_error')); // Singleton instance self::$instance = $this; }
public function __construct($options = array()) { $default = array("width" => "100", "height" => "100", "images" => array(), "class" => "square_thumb", "view" => null, "thickbox" => true); $config = Kohana::config_load('zest'); $config = arr::overwrite($default, $config['gallery']); $this->config = arr::overwrite($config, $options); }
public function render($options = null) { if (!$options) { $config = Kohana::config_load('zest'); $options = $config['comment']; } $array = array("date_format" => 'D jS M Y', "image" => array(50, 50), "html" => '{AVATAR}{DATE} by {AUTHOR}<br/><p>{TEXT}</p><a href="{DELETE_LINK}" title="delete comment"></a><div class="spacer"> </div>', "default_image" => 'http://' . $_SERVER['HTTP_HOST'] . '/zest/images/user_icon.gif', "template" => ''); $array = arr::overwrite($array, $options); if (isset($array['template']) && $array['template'] != "") { $html = zest::template_to_html('snippets/' . $array['template']); } else { $html = $array['html']; } $html = str_replace('{DATE}', date($array['date_format'], strtotime($this->date)), $html); $html = str_replace('{AVATAR}', gravatar::render($this->email, $array['image'][0], $array['default_image']), $html); if ($this->fl_deleted == 1) { $html = str_replace('{TEXT}', '<i>This comment has been deleted.</i>', $html); } else { $html = str_replace('{TEXT}', $this->title, $html); } $html = str_replace('{AUTHOR}', $this->display_name, $html); if ($this->can_modify()) { $html = str_replace('{DELETE_LINK}', $this->delete_url(), $html); } return $html; }
/** * Returns the formatted html * * html example * e.g <h1>{TITLE}</h1><h2>{DATE}</h2><h3>by {AUTHOR}</h3>{IMAGE}{TEXT}<div class="spacer"> </div> * * @param array $options Options for the rendering array('count', 'date_format','image' = array($width,$height), 'word_count', 'html') * @return string $html Formatted HTML */ public function render_summary($options = null, $feedpost_options = null) { $array = array('per_page' => 5, 'pagination' => 'classic', 'template' => 'feed', 'html' => '{FEEDPOSTS}{PAGINATION}'); if (!$options) { $config = Kohana::config_load('zest'); $options = $config['feed.summary']; } $array = arr::overwrite($array, $options); $uri = uri::instance(); $page = $uri->segment('page', 1); $feedposts = ""; $posts = $this->get_posts($array['per_page'], ($page - 1) * $array['per_page']); foreach ($posts as $post) { $feedposts .= $post->render_summary($feedpost_options); } $pagination = new Pagination(array('uri_segment' => 'page', 'total_items' => count($this->get_posts()), 'items_per_page' => $array['per_page'], 'style' => $array['pagination'])); if ($array['template'] != '') { $html = zest::template_to_html('snippets/' . $array['template']); } else { $html = $array['html']; } $html = str_replace("{RSS_LINK}", $this->get_rss(), $html); $html = str_replace("{FEEDPOSTS}", $feedposts, $html); $html = str_replace("{PAGINATION}", $pagination, $html); $html = str_replace("{FEED_LINK}", $this->get_url(), $html); return $html; }
public function __construct($options = array()) { $default = array("width" => 900, "height" => 150, "view" => "includes/banner", "images" => array()); $config = Kohana::config_load('zest'); $config = arr::overwrite($default, $config['banner']); $this->config = arr::overwrite($config, $options); }
public function __construct() { // Set the request data $this->request = $_SERVER['REQUEST_METHOD'] == 'POST' ? $_POST : $_GET; // Load the API configuration file Kohana::config_load('api'); }
public function __construct() { $this->zest = new Zest_admin(); parent::__construct(); $this->config = Kohana::config_load('zest'); $this->__setup(); if (request::is_ajax()) { $this->auto_render = FALSE; Event::add('system.post_controller', array($this, '_json_render')); } }
public function __construct($config = array()) { // Check for GD library before doing anything if (extension_loaded('gd')) { $config += Kohana::config_load('dynamicimage'); $this->config = $config; // Check for a filename and check it is a file if ($this->config['filename'] && is_file($this->config['filename'])) { // Set filename $this->filename = $this->config['filename']; $this->gd_data = getimagesize($this->filename); $this->gd_image_out = FALSE; // Get filesize $this->filesize = filesize($this->filename); // Get the Mimetype $this->mime_type = $this->gd_data['mime']; // Get dimensions $this->width = $this->gd_data[0]; $this->height = $this->gd_data[1]; $this->background_colour = $this->config['background']; $this->maintain_transparency = $this->config['maintain_transparency']; // Setup GD object switch ($this->gd_data['mime']) { // If image is PNG, load PNG file case "image/png": $this->gd_image = imagecreatefrompng($this->filename); break; // If image is JPG, load JPG file // If image is JPG, load JPG file case "image/jpg": $this->gd_image = imagecreatefromjpeg($this->filename); break; // If image is GIF, load GIF file // If image is GIF, load GIF file case "image/gif": $this->gd_image = imagecreatefromgif($this->filename); break; // Otherwise image is not supported in this version (more to follow) // Otherwise image is not supported in this version (more to follow) default: throw new Kohana_Exception("DynamicImage.__construct() Filetype {$this->mime_type} not supported yet."); return; } $this->print_image($this->config['width'], $this->config['height'], $this->config['maintain_ratio'], $this->config['format']); } else { // Otherwise die horribly return FALSE; } } else { // Die informing user of lack of extentions throw new Kohana_Exception('GD Library not installed'); return; } }
/** * Instantiate the class and setup connection parameters. * * @param $BasecampUrl * Your Basecamp Url. Should begin with http or https * @param $username * Your Basecamp username. * @param $password * Your Basecamp password. */ public function __construct($username = null, $password = null, $basecampUserId = null, $BasecampUrl = null) { $config = Kohana::config_load('basecamp'); $this->config = $config; $BasecampUrl = $config['basecamp.url']; $this->setBasecampUrl($BasecampUrl); $this->setUsername($username); $this->setPassword($password); $this->setAuthorId($basecampUserId); $this->setCategoryId($config['basecamp.categoryID']); $this->setProjectId($config['basecamp.projectID']); }
public function __construct() { parent::__construct(); Kohana::config_load('workermgmt'); $this->profiler = IN_DEV_MODE ? new Profiler() : null; $requested_area = strtolower(Router::$controller . "::" . Router::$method); if (!in_array($requested_area, $this->non_authed_areas)) { // run authentication if (!Bugzilla::instance(Kohana::config('workermgmt'))->authenticated()) { url::redirect('login'); } } }
public function __construct() { // Set the request data $this->request = ($_SERVER['REQUEST_METHOD'] == 'POST') ? $_POST : $_GET; // Load the API configuration file Kohana::config_load('api'); // Get the IP Address of the client submitting the API request $this->request_ip_address = $_SERVER['REMOTE_ADDR']; // Unpack the URL parameters $this->api_parameters = serialize(array_keys($this->request)); // Instantiate the database $this->db = new Database(); }
public function __construct() { // AJAX requests don't need an outer template if (request::is_ajax()) { $this->template = 'templates/blank'; } parent::__construct(); // assign view array with system information // $this->template->system = Kohana::config_load('version'); $this->db = Database::instance(); $this->auth = new Auth(); $this->session = new Session(); if ($this->auth->logged_in()) { $this->template->menu = self::get_menu(); } $title = kohana::config('indicia.warehouse_title'); $this->template->warehouseTitle = $title ? $title : 'Indicia Warehouse'; }
public function save() { // This array maps the telephony returns to the telephony file $telephonyOptions = array('cfg_root' => rtrim($this->session->get('installer.ast_root'), '/'), 'AmiHost' => $this->session->get('installer.ami_host'), 'AmiPort' => $this->session->get('installer.ami_port'), 'AmiUser' => $this->session->get('installer.ami_user'), 'AmiPass' => $this->session->get('installer.ami_pass')); if (!is_dir($telephonyOptions['cfg_root'])) { message::set('Unable to access directory <pre>' . $telephonyOptions['cfg_root'] . '</pre>'); return false; } // Write $telephonyOptions to asterisk.php if (!Installer_Controller::updateConfig($telephonyOptions, 'asterisk')) { return false; } // Set the driver name in telephony.php if (!Installer_Controller::updateConfig(array('driver' => 'Asterisk'), 'telephony')) { return false; } // Reload the new asterisk options Kohana::config_clear('asterisk'); Kohana::config_load('asterisk'); $this->session->set('installer.default_packages', kohana::config('asterisk.default_packages')); return true; }
public function __construct() { // Set the request data $this->request = $_SERVER['REQUEST_METHOD'] == 'POST' ? $_POST : $_GET; // Reset the session - API should be stateless $_SESSION = array(); // Especially reset auth Session::instance()->set(Kohana::config('auth.session_key'), null); // Load the API configuration file Kohana::config_load('api'); // Get the IP Address of the client submitting the API request // Check if the IP is from a shared internet connection if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $this->request_ip_address = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $this->request_ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $this->request_ip_address = $_SERVER['REMOTE_ADDR']; } // Unpack the URL parameters $this->api_parameters = serialize(array_keys($this->request)); // Instantiate the database $this->db = new Database(); }
/** * insert values in the system table * * @return bool */ public function insertSystemInfo() { $version = Kohana::config_load('version'); // Note the version is set to 0.1, since this is the initially installed db version which will immediately be updated. if (false === pg_query($this->dbconn, "INSERT INTO \"system\"\n (\"version\", \"name\", \"repository\", \"release_date\")\n VALUES\n ('0.1',\n 'Indicia',\n '{$version['repository']}',\n '{$version['release_date']}')")) { return pg_last_error($this->dbconn); } return true; }
/** * Load the active modules. This is called at bootstrap time. */ static function load_modules() { // Reload module list from the config file since we'll do a refresh after calling install() $core = Kohana::config_load("core"); $kohana_modules = $core["modules"]; self::$module_names = array(); self::$modules = array(); // This is one of the first database operations that we'll do, so it may fail if there's no // install yet. Try to handle this situation gracefully expecting that the scaffolding will // Do The Right Thing. // Reverting from installer stage 1. // @todo get rid of this extra error checking when we have an installer. set_error_handler(array("module", "dummy_error_handler")); try { $modules = ORM::factory("module")->find_all(); } catch (Exception $e) { return; } try { foreach ($modules as $module) { self::$module_names[$module->name] = $module->name; self::$modules[$module->name] = $module; $kohana_modules[] = MODPATH . $module->name; } Kohana::config_set("core.modules", $kohana_modules); } catch (Exception $e) { self::$module_names = array(); self::$modules = array(); } self::event("gallery_ready"); }
public function render($options = null) { if (!$options) { $config = Kohana::config_load('zest'); $options = $config['feedpost.full']; } $array = array("date_format" => 'D jS M Y', "image" => array(250, 250), "image_class" => "", "html" => '<h1>{TITLE}</h1><h2>{DATE}</h2><h3>by {AUTHOR}</h3>{IMAGE}{TEXT}<div class="spacer"> </div>', "template" => '', "word_limit" => 0); $array = arr::overwrite($array, $options); if (isset($array['template']) && $array['template'] != "") { $html = zest::template_to_html('snippets/' . $array['template']); } else { $html = $array['html']; } $html = str_replace('{TITLE}', $this->title, $html); $html = str_replace('{DATE}', date($array['date_format'], strtotime($this->date)), $html); if ($this->media_id > 0) { $html = str_replace('{IMAGE}', $this->media->render_cropped($array['image'][0], $array['image'][1], $array['image_class']), $html); } else { $html = str_replace('{IMAGE}', '', $html); } if (isset($array['word_limit']) && $array['word_limit'] > 0) { $html = str_replace('{TEXT}', text::limit_words(strip_tags($this->text), $array['word_limit']), $html); } else { $html = str_replace('{TEXT}', $this->text, $html); $html = str_replace('{ADD_THIS}', zest::add_this($this->get_url(), $this->title), $html); } $html = str_replace('{LINK}', $this->get_url(), $html); $html = str_replace('{FEED_LINK}', $this->feed->get_url(), $html); $html = str_replace('{FEED_TITLE}', $this->feed->title, $html); $html = str_replace('{AUTHOR}', $this->user->username, $html); if ($this->feed->has_comments()) { $html = str_replace('{COMMENT_FORM}', $this->comment_form(), $html); $comments = $this->get_comments(); $comments_html = "<a name='comments'></a>"; foreach ($comments as $c) { $comments_html .= $c->render(); } if ($comments_html == "") { $comments_html = "<p>No comments have yet been posted. Be the first!</p>"; } $html = str_replace('{COMMENTS}', $comments_html, $html); $com_count = count($comments); switch ($com_count) { case 0: $str = '0 comments'; break; case 1: $str = '1 comment'; break; default: $str = $com_count . ' comments'; break; } $html = str_replace('{COMMENT_COUNT}', $str, $html); } else { $html = str_replace('{COMMENT_FORM}', '', $html); $html = str_replace('{COMMENTS}', '', $html); $html = str_replace('{COMMENT_COUNT}', '', $html); } return $html; }
public function save() { if (!class_exists('DOMDocument')) { message::set('This driver requires ' . html::anchor('http://us3.php.net/manual/en/class.domdocument.php', 'DOMDocument', array('target' => '_new')) . ' to be installed and active'); return false; } // This array maps the telephony returns to the telephony file $telephonyOptions = array('cfg_root' => rtrim($this->session->get('installer.cfg_root'), '/'), 'audio_root' => rtrim($this->session->get('installer.audio_root'), '/'), 'ESLHost' => $this->session->get('installer.esl_host'), 'ESLPort' => $this->session->get('installer.esl_port'), 'ESLAuth' => $this->session->get('installer.esl_auth')); if (!is_dir($telephonyOptions['cfg_root'])) { message::set('Unable to access directory <pre>' . $telephonyOptions['cfg_root'] . '</pre>'); return false; } if (!is_dir($telephonyOptions['audio_root'])) { message::set('Unable to access directory <pre>' . $telephonyOptions['audio_root'] . '</pre>'); return false; } // Write $telephonyOptions to freeswitch.php if (!Installer_Controller::updateConfig($telephonyOptions, 'freeswitch')) { return false; } // Set the driver name in telephony.php if (!Installer_Controller::updateConfig(array('driver' => 'FreeSwitch'), 'telephony')) { return false; } // Reload the new telephony options so we can use the filemap Kohana::config_clear('freeswitch'); Kohana::config_load('freeswitch'); $filemaps = Kohana::config('freeswitch.filemap'); $notWritable = array(); foreach ($filemaps as $filemap) { if (!filesystem::is_writable($filemap['filename'])) { $notWritable[] = $filemap['filename']; } } if (!empty($notWritable)) { $notWritable = array_unique($notWritable); if (empty($this->template->error)) { message::set('Ensure the web server has write permission on these files, and SELINUX allows this action.' . '<div class="write_help">Unable to write to the following file(s):</div>' . '<div>' . arr::arrayToUL($notWritable, array(), array('class' => 'error_details', 'style' => 'text-align:left;')) . '</div>'); } return false; } // Make sure that if the user changed the directory and any conflicts were found that the user // knows these will be deleted $existingProfiles = glob(rtrim($telephonyOptions['cfg_root'], '/') . '/sip_profiles/*.xml', GLOB_MARK); $oldXmlFiles = array(); foreach ($filemaps as $filemap) { if (file_exists($filemap['filename'])) { $oldXmlFiles[] = $filemap['filename']; } } $conflictXmlFiles = $this->session->get('installer.conflictXmlFiles'); foreach (array_unique(array_merge($existingProfiles, $oldXmlFiles)) as $existingFile) { if (!in_array($existingFile, $conflictXmlFiles)) { message::set('Conflicting configuration files will be permanently erased if you continue!'); message::set('Click continue again to proceed...', 'alert'); // This session var lets the user continue the second time around (after the warning) $this->session->set('installer.confirm_delete', true); return false; } } // If there are conflictXmlFile in the session then the user has seen this list // so they SHOULD be aware we are about to delete them... should $conflictXmlFiles = $this->session->get('installer.conflictXmlFiles'); if (!empty($conflictXmlFiles) && is_array($conflictXmlFiles)) { $confirmDelete = $this->session->get('installer.confirm_delete', false); if (empty($confirmDelete)) { message::set('Conflicting configuration files will be permanently erased if you continue!'); message::set('Click continue again to proceed...', 'alert'); // This session var lets the user continue the second time around (after the warning) $this->session->set('installer.confirm_delete', true); return false; } foreach ($conflictXmlFiles as $conflictXmlFile) { if (!filesystem::delete($conflictXmlFile)) { Kohana::log('error', 'Unable to unlink ' . $conflictXmlFile); $unlinkErrors[] = $conflictXmlFile; } } } // If there are files that could not be deleted, inform the user if (!empty($unlinkErrors)) { message::set('Manually remove these files or change the file permissions.' . '<div class="write_help">Unable to delete incompatible file(s):</div>' . '<div>' . arr::arrayToUL($unlinkErrors, array(), array('class' => 'error_details', 'style' => 'text-align:left;')) . '</div>'); return false; } $this->session->set('installer.default_packages', kohana::config('freeswitch.default_packages')); return true; }
public function message_opt_friend_apply($data, $message_id, $mini) { $location = ''; $sex = 0; $together_count = 0; $same_friend = array(); $result = $this->getNoticeInfo(array('id' => $message_id, 'authorid' => $this->uid), true); if ($result) { $tmp = $result['body'] ? json_decode($result['body'], true) : array("explain" => ""); //取得共同好友 $friendModel = new Friend_Model(); $ffids = $friendModel->getAllFriendIDs($result['authorid'], false); $mfids = $friendModel->getAllFriendIDs($this->uid, false); $together = array_intersect($ffids, $mfids); $data = sns::getuser($result['authorid']); $tmp['reside'] = ''; if ($data['resideprovince'] || $data['residecity']) { $config = Kohana::config_load('cityarray'); //加载城市数组 $province = isset($data['resideprovince']) ? isset($config['province'][$data['resideprovince']]) ? $config['province'][$data['resideprovince']] : '' : ""; $city = isset($data['residecity']) ? isset($config['city'][$data['residecity']]) ? $config['city'][$data['residecity']] : '' : ""; $location = $province . " " . $city; } $sex = $data['sex'] == 1 ? "男" : "女"; $tmp['fid'] = $result['authorid']; $tmp['explain'] = $tmp['explain'] ? str::unhtmlspecialchars($tmp['explain']) : ''; unset($data, $ffids, $mfids, $config); $str = ""; $urlpre = url::base(); $avatar = sns::getavatar($result['authorid']); if (!empty($together)) { $together_count = count($together); $i = 0; foreach ($together as $val) { $item = array(); $item['id'] = $val; $item['name'] = sns::getrealname($val); $same_friend[] = $item; if (9 < ++$i) { break; } } } } return array('location' => $location, 'sex' => $sex, 'together_count' => $together_count, 'together' => $same_friend); }
public function index() { // 1. get limit // 2. set filename // 3. ditect cache // 4.1. has cache -> return file // 4.2. no cache -> get data from sql, and write in view Kohana::config_load('kml'); // 1. $limit = 0; if (isset($_GET['l']) AND !empty($_GET['l'])) { $limit = (int) $_GET['l']; } $category_id = 0; if (isset($_GET['cat']) AND !empty($_GET['cat'])) { $category_id = (int) $_GET['cat']; } // cron on? $cron_flag = false; if (isset($_GET['cron']) AND !empty($_GET['cron'])) { $cron_flag = true; $limit = 0; // execute cron with no limit. } if ($limit == 0 && $cron_flag == false) { url::redirect(Kohana::config("kml.cdn_kml_url")); } // 2. $kml_filename = "latest.kml"; // filename for exported KML file $kmz_filename = "latest.kmz"; // filename for exported KMZ file if ($limit != 0) { $kml_filename = $kml_filename . "_" . strval($limit); $kmz_filename = $kmz_filename . "_" . strval($limit); } $kmlFileName = Kohana::config('upload.directory', TRUE) . $kml_filename; // internal path to KML file in uploads directory $kmzFileName = Kohana::config('upload.directory', TRUE) . $kmz_filename; // internal path to KMZ file in uploads directory // 3. //=== Caching Options == $cache_secs = 120; // seconds during which to serve cached file, after which re-generate on next request $cache_on = true; // true = cache file, false = debug mode: file is re-generated on each request $use_cache = false; if (file_exists($kmzFileName) && (time() - filemtime($kmzFileName) < $cache_secs) && $cache_on) { $use_cache = true; } // 4. if ($use_cache) { // 4.1 $incidents = NULL; $categories = NULL; } else { // 4.2 if ($limit != 0) { // If so, Get all incidents upto limit $incidents = ORM::factory('incident') ->where('incident_active', '1') ->orderby('incident_date', 'desc') ->limit($limit) ->find_all(); } else { // Otherwise, Get all incidents (no limit) $incidents = ORM::factory('incident') ->where('incident_active', '1') ->orderby('incident_date', 'desc') ->find_all(); } // Get all Categories... $categories = array(); if ($category_id == 0) { $categories = ORM::factory('category') ->where('category_visible', '1') ->find_all(); } else { $categories = ORM::factory('category') ->where('id', $category_id) ->where('category_visible', '1') ->find_all(); } } //header("Content-Type: application/vnd.google-earth.kml+xml"); header("Content-Type: application/vnd.google-earth.kmz"); //header("Content-Disposition: attachment; filename=".time().".kml"); //header("Content-Disposition: attachment; filename=ushahidi_link.kml"); header("Content-Disposition: attachment; filename=".time().".kmz"); header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); header("Cache-Control: cache, must-revalidate"); header("Pragma: public"); $view = new View("kml"); $view->kml_name = htmlspecialchars(Kohana::config('settings.site_name')); $view->kml_tagline = htmlspecialchars(Kohana::config('settings.site_tagline')); $view->items = $incidents; $view->categories = $categories; // move from view $view->kml_filename = $kml_filename; $view->kmz_filename = $kmz_filename; $view->kmlFileName = $kmlFileName; $view->kmzFileName = $kmzFileName; // set use cache $view->use_cache = $use_cache; // set cron flag $view->cron_flag = $cron_flag; $view->render(TRUE); }
function Index() { if (!TEST_MODE) { print Kohana::show_404(); } // Jump through some hoops to satisfy the way that we check for the site_domain in // config.php. We structure this such that the code in config will leave us with a // site_domain of "." (for historical reasons) // @todo: for tests, we should force the site_domain to something like example.com $_SERVER["SCRIPT_FILENAME"] = "index.php"; $_SERVER["SCRIPT_NAME"] = "./index.php"; $original_config = DOCROOT . "var/database.php"; $test_config = VARPATH . "database.php"; if (!file_exists($original_config)) { print "Please copy kohana/config/database.php to {$original_config}.\n"; return; } else { copy($original_config, $test_config); $db_config = Kohana::config('database'); if (empty($db_config['unit_test'])) { $default = $db_config['default']; $conn = $default['connection']; Kohana::config_set('database.unit_test.benchmark', $default['benchmark']); Kohana::config_set('database.unit_test.persistent', $default['persistent']); Kohana::config_set('database.unit_test.connection.type', $conn['type']); Kohana::config_set('database.unit_test.connection.user', $conn['user']); Kohana::config_set('database.unit_test.connection.pass', $conn['pass']); Kohana::config_set('database.unit_test.connection.host', $conn['host']); Kohana::config_set('database.unit_test.connection.port', $conn['port']); Kohana::config_set('database.unit_test.connection.socket', $conn['socket']); Kohana::config_set('database.unit_test.connection.database', "{$conn['database']}_test"); Kohana::config_set('database.unit_test.character_set', $default['character_set']); Kohana::config_set('database.unit_test.table_prefix', $default['table_prefix']); Kohana::config_set('database.unit_test.object', $default['object']); Kohana::config_set('database.unit_test.cache', $default['cache']); Kohana::config_set('database.unit_test.escape', $default['escape']); $db_config = Kohana::config('database'); } if ($db_config['default']['connection']['database'] == $db_config['unit_test']['connection']['database']) { print "Don't use the default database for your unit tests or you'll lose all your data.\n"; return; } try { $db = Database::instance('unit_test'); $db->connect(); // Make this the default database for the rest of this run Database::$instances = array('default' => $db); } catch (Exception $e) { print "{$e->getMessage()}\n"; return; } } try { // Find all tests, excluding sample tests that come with the unit_test module. foreach (glob(MODPATH . "*/tests") as $path) { if ($path != MODPATH . "unit_test/tests") { $paths[] = $path; } } Kohana::config_set('unit_test.paths', $paths); // Clean out the database if ($tables = $db->list_tables()) { foreach ($db->list_tables() as $table) { $db->query("DROP TABLE {$table}"); } } // Clean out the filesystem @system("rm -rf test/var"); @mkdir('test/var/logs', 0777, true); // Reset our caches module::$modules = array(); module::$active = array(); module::$var_cache = array(); $db->clear_cache(); // Rest the cascading class path Kohana::config_set("core", Kohana::config_load("core")); // Install all modules // Force gallery and user to be installed first to resolve dependencies. gallery_installer::install(true); module::load_modules(); module::install("user"); module::activate("user"); $modules = array(); foreach (glob(MODPATH . "*/helpers/*_installer.php") as $file) { $module_name = basename(dirname(dirname($file))); if (in_array($module_name, array("gallery", "user"))) { continue; } module::install($module_name); module::activate($module_name); } // Trigger late-binding install actions (defined in gallery_event::user_login) graphics::choose_default_toolkit(); $filter = count($_SERVER["argv"]) > 2 ? $_SERVER["argv"][2] : null; print new Unit_Test($modules, $filter); } catch (Exception $e) { print "Exception: {$e->getMessage()}\n"; print $e->getTraceAsString() . "\n"; } }
/** * 过滤输入、创建群联系人对象 * @param array $data 联系人信息 * @return Group_Contact $contact */ public function array_to_Group_contact($data) { $contact = new Group_Contact(); $location_model = Location_Model::instance(); $bjx_arr = Kohana::config_load('bjx'); foreach ($data as $type => $value) { switch ($type) { case 'tels': if (!empty($value)) { $values = $tmp = array(); foreach ($value as $val) { if (!in_array(trim($val['value']), $tmp)) { $tmp[] = trim($val['value']); $values[] = array('value' => trim($val['value']), 'type' => $val['type'], 'city' => $location_model->get_tel_location(trim($val['value'])), 'pref' => !empty($val['pref']) ? (int) $val['pref'] : 0); } } call_user_func(array($contact, 'set_' . $type), $values); } break; case 'ims': if (!empty($value)) { $values = $tmp = $protocols = array(); foreach ($value as $val) { $val['protocol'] = strtolower($val['protocol']); $keys = array_keys($tmp, trim($val['value'])); $key = isset($keys[0]) ? $keys[0] : -1; if ($key < 0 or $protocols[$key] != $val['protocol']) { $tmp[] = trim($val['value']); $protocols[] = $val['protocol']; $values[] = array('value' => trim($val['value']), 'protocol' => $val['protocol'], 'type' => $val['type']); } } call_user_func(array($contact, 'set_' . $type), $values); } break; case 'addresses': if (!empty($value)) { $values = $tmp = array(); $t = ''; foreach ($value as $val) { $t = trim($val['country']) . '|' . trim($val['region']) . '|' . trim($val['city']) . '|' . trim($val['street']) . '|' . trim($val['postal']); if (!in_array($t, $tmp)) { $values[] = array('country' => trim($val['country']), 'region' => trim($val['region']), 'city' => trim($val['city']), 'street' => trim($val['street']), 'postal' => trim($val['postal']), 'type' => $val['type']); $tmp[] = $t; } } call_user_func(array($contact, 'set_' . $type), $values); } break; case 'emails': case 'urls': case 'events': case 'relations': if (!empty($value)) { $values = $tmp = array(); foreach ($value as $val) { if (!in_array(trim($val['value']), $tmp)) { $tmp[] = trim($val['value']); $values[] = array('value' => trim($val['value']), 'type' => $val['type']); } } call_user_func(array($contact, 'set_' . $type), $values); } break; case 'birthday': $contactModel = Contact_Model::instance(); call_user_func(array($contact, 'set_' . $type), !empty($value) ? $contactModel->_filter_birthday($value) : ''); break; case 'id': break; default: call_user_func(array($contact, 'set_' . $type), !empty($value) ? $value : ''); break; } } $formatted_name = $this->name_to_formatted_name($data['family_name'], $data['given_name']); //拼接后的全名为空,并且输入的全名不是空的,把全名拆分设置 if (empty($formatted_name) and !empty($data['formatted_name'])) { $name = $this->formatted_name_to_name($data['formatted_name']); $contact->set_given_name($name['given_name']); $contact->set_family_name($name['family_name']); } else { $fn = $formatted_name; } if (!empty($fn)) { require_once Kohana::find_file('vendor', 'pinyin/c2p'); $phonetic = getPinYin($fn, false, ' '); $tmp = explode(' ', $phonetic); $sort = ''; if (is_array($tmp)) { foreach ($tmp as $t) { $sort .= isset($t[0]) ? $t[0] : ''; } } $t = ord($sort[0]); if (empty($sort) or $t < 97 or $t > 122) { $sort = '#'; } $sort = substr($sort, 0, 20); $contact->set_formatted_name($fn); $contact->set_phonetic(implode('', $tmp)); $contact->set_sort($sort); } else { $contact->set_formatted_name(''); $contact->set_phonetic(''); $contact->set_sort('#'); } return $contact; }
/** * Load the active modules. This is called at bootstrap time. */ static function load_modules() { // Reload module list from the config file since we'll do a refresh after calling install() $core = Kohana::config_load("core"); $kohana_modules = $core["modules"]; $modules = ORM::factory("module")->find_all(); self::$modules = array(); self::$active = array(); foreach ($modules as $module) { self::$modules[$module->name] = $module; if ($module->active) { self::$active[] = $module; } $kohana_modules[] = MODPATH . $module->name; // @todo: force 'gallery' to be at the end } Kohana::config_set("core.modules", $kohana_modules); }
public function __construct($config = array()) { $this->config = arr::overwrite(Kohana::config_load('url_shortner'), $config); }