当前位置: 首页>>代码示例>>PHP>>正文


PHP Kohana::user_agent方法代码示例

本文整理汇总了PHP中Kohana::user_agent方法的典型用法代码示例。如果您正苦于以下问题:PHP Kohana::user_agent方法的具体用法?PHP Kohana::user_agent怎么用?PHP Kohana::user_agent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Kohana的用法示例。


在下文中一共展示了Kohana::user_agent方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct($use_cache = FALSE, $cache_lifetime = NULL)
 {
     $this->use_cache = $use_cache;
     $this->cache_lifetime = $cache_lifetime;
     $this->cache = new Cache();
     $this->setReturnTransfer(TRUE);
     $this->setUserAgent(Kohana::user_agent() or TRUE);
 }
开发者ID:uxturtle,项目名称:core-module,代码行数:8,代码来源:Rest.php

示例2: force

 /**
  * Force a download of a file to the user's browser. This function is
  * binary-safe and will work with any MIME type that Kohana is aware of.
  *
  * @param   string  a file path or file name
  * @param   mixed   data to be sent if the filename does not exist
  * @param   string  suggested filename to display in the download
  * @return  void
  */
 public static function force($filename = NULL, $data = NULL, $nicename = NULL)
 {
     if (empty($filename)) {
         return FALSE;
     }
     if (is_file($filename)) {
         // Get the real path
         $filepath = str_replace('\\', '/', realpath($filename));
         // Set filesize
         $filesize = filesize($filepath);
         // Get filename
         $filename = substr(strrchr('/' . $filepath, '/'), 1);
         // Get extension
         $extension = strtolower(substr(strrchr($filepath, '.'), 1));
     } else {
         // Get filesize
         $filesize = strlen($data);
         // Make sure the filename does not have directory info
         $filename = substr(strrchr('/' . $filename, '/'), 1);
         // Get extension
         $extension = strtolower(substr(strrchr($filename, '.'), 1));
     }
     // Get the mime type of the file
     $mime = Kohana::config('mimes.' . $extension);
     if (empty($mime)) {
         // Set a default mime if none was found
         $mime = array('application/octet-stream');
     }
     // Generate the server headers
     header('Content-Type: ' . $mime[0]);
     header('Content-Disposition: attachment; filename="' . (empty($nicename) ? $filename : $nicename) . '"');
     header('Content-Transfer-Encoding: binary');
     header('Content-Length: ' . sprintf('%d', $filesize));
     // More caching prevention
     header('Expires: 0');
     if (Kohana::user_agent('browser') === 'Internet Explorer') {
         // Send IE headers
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header('Pragma: public');
     } else {
         // Send normal headers
         header('Pragma: no-cache');
     }
     // Clear the output buffer
     Kohana::close_buffers(FALSE);
     if (isset($filepath)) {
         // Open the file
         $handle = fopen($filepath, 'rb');
         // Send the file data
         fpassthru($handle);
         // Close the file
         fclose($handle);
     } else {
         // Send the file data
         echo $data;
     }
 }
开发者ID:nebogeo,项目名称:borrowed-scenery,代码行数:66,代码来源:download.php

示例3: add_view

 /**
  * Allows a model to be loaded by filename.
  */
 public function add_view($type, $id)
 {
     $this->item_type = $type;
     $this->item_id = $id;
     $this->ip = Input::instance()->ip_address();
     $this->referrer = request::referrer();
     $this->user_agent = Kohana::user_agent();
     $this->save();
 }
开发者ID:sydlawrence,项目名称:SocialFeed,代码行数:12,代码来源:zest_statistic.php

示例4: check_spam

 public static function check_spam()
 {
     $comment = array('comment_type' => 'comment', 'comment_author' => Event::$data->author, 'comment_author_email' => Event::$data->email, 'comment_author_url' => Event::$data->url, 'comment_content' => Event::$data->content, 'referrer' => request::referrer(), 'user_ip' => Event::$data->ip, 'user_agent' => Kohana::user_agent(), 'blog' => url::base(TRUE, 'http'));
     $result = self::send_request('comment', $comment);
     if ($result === 'true') {
         Event::$data->approved = 'no';
         Event::$data->save();
     }
 }
开发者ID:googlecode-mirror,项目名称:s7ncms,代码行数:9,代码来源:akismet.php

示例5: setup

 public function setup()
 {
     Input::instance()->ip_address = "1.1.1.1";
     Kohana::$user_agent = "Akismet_Helper_Test";
     $root = ORM::factory("item", 1);
     $this->_comment = comment::create($root, user::guest(), "This is a comment", "John Doe", "john@gallery2.org", "http://gallery2.org");
     foreach ($this->_comment->list_fields("comments") as $name => $field) {
         if (strpos($name, "server_") === 0) {
             $this->_comment->{$name} = substr($name, strlen("server_"));
         }
     }
     $this->_comment->save();
     module::set_var("akismet", "api_key", "TEST_KEY");
 }
开发者ID:xafr,项目名称:gallery3,代码行数:14,代码来源:Akismet_Helper_Test.php

示例6: browser_language

 public static function browser_language()
 {
     if (language::$browser_language === NULL) {
         language::$browser_language = '';
         $browser_languages = Kohana::user_agent('languages');
         foreach ($browser_languages as $language) {
             if (strlen($language) == 2 and array_key_exists($language, language::$available_languages)) {
                 language::$browser_language = strtolower($language);
                 break;
             }
         }
     }
     return language::$browser_language;
 }
开发者ID:googlecode-mirror,项目名称:s7ncms,代码行数:14,代码来源:language.php

示例7: fancyupload_modify_session_config

function fancyupload_modify_session_config()
{
    if (stripos(Kohana::user_agent(), 'Shockwave Flash') !== FALSE) {
        // Check that the session isn't attempting to validate the user agent
        $validate = Kohana::config('session.validate');
        $key = array_search('user_agent', $validate);
        if ($key !== FALSE) {
            unset($validate[$key]);
            Kohana::config('session.validate', $validate);
        }
        // Ensure that the session key won't be regenerated
        Kohana::config_set('session.regenerate', 0);
    }
}
开发者ID:evansd-archive,项目名称:kohana-module--fancyupload,代码行数:14,代码来源:fancyupload_modify_session_config.php

示例8: setup

 /**
  * Sets up the PHP environment. Adds error/exception handling, output
  * buffering, and adds an auto-loading method for loading classes.
  *
  * This method is run immediately when this file is loaded, and is
  * benchmarked as environment_setup.
  *
  * For security, this function also destroys the $_REQUEST global variable.
  * Using the proper global (GET, POST, COOKIE, etc) is inherently more secure.
  * The recommended way to fetch a global variable is using the Input library.
  * @see http://www.php.net/globals
  *
  * @return  void
  */
 public static function setup()
 {
     static $run;
     // This function can only be run once
     if ($run === TRUE) {
         return;
     }
     // Start the environment setup benchmark
     Benchmark::start(SYSTEM_BENCHMARK . '_environment_setup');
     // Define Kohana error constant
     define('E_KOHANA', 42);
     // Define 404 error constant
     define('E_PAGE_NOT_FOUND', 43);
     // Define database error constant
     define('E_DATABASE_ERROR', 44);
     if (self::$cache_lifetime = self::config('core.internal_cache')) {
         // Load cached configuration and language files
         self::$internal_cache['configuration'] = self::cache('configuration', self::$cache_lifetime);
         self::$internal_cache['language'] = self::cache('language', self::$cache_lifetime);
         // Load cached file paths
         self::$internal_cache['find_file_paths'] = self::cache('find_file_paths', self::$cache_lifetime);
         // Enable cache saving
         Event::add('system.shutdown', array(__CLASS__, 'internal_cache_save'));
     }
     // Disable notices and "strict" errors
     $ER = error_reporting(~E_NOTICE & ~E_STRICT);
     // Set the user agent
     self::$user_agent = trim($_SERVER['HTTP_USER_AGENT']);
     if (function_exists('date_default_timezone_set')) {
         $timezone = self::config('locale.timezone');
         // Set default timezone, due to increased validation of date settings
         // which cause massive amounts of E_NOTICEs to be generated in PHP 5.2+
         date_default_timezone_set(empty($timezone) ? 'UTC' : $timezone);
     }
     // Restore error reporting
     error_reporting($ER);
     // Start output buffering
     ob_start(array(__CLASS__, 'output_buffer'));
     // Save buffering level
     self::$buffer_level = ob_get_level();
     // Set autoloader
     spl_autoload_register(array('Kohana', 'auto_load'));
     // Set error handler
     set_error_handler(array('Kohana', 'exception_handler'));
     // Set exception handler
     set_exception_handler(array('Kohana', 'exception_handler'));
     // Send default text/html UTF-8 header
     header('Content-Type: text/html; charset=UTF-8');
     // Load locales
     $locales = self::config('locale.language');
     // Make first locale UTF-8
     $locales[0] .= '.UTF-8';
     // Set locale information
     self::$locale = setlocale(LC_ALL, $locales);
     if (self::$configuration['core']['log_threshold'] > 0) {
         // Set the log directory
         self::log_directory(self::$configuration['core']['log_directory']);
         // Enable log writing at shutdown
         register_shutdown_function(array(__CLASS__, 'log_save'));
     }
     // Enable Kohana routing
     Event::add('system.routing', array('Router', 'find_uri'));
     Event::add('system.routing', array('Router', 'setup'));
     // Enable Kohana controller initialization
     Event::add('system.execute', array('Kohana', 'instance'));
     // Enable Kohana 404 pages
     Event::add('system.404', array('Kohana', 'show_404'));
     // Enable Kohana output handling
     Event::add('system.shutdown', array('Kohana', 'shutdown'));
     if (self::config('core.enable_hooks') === TRUE) {
         // Find all the hook files
         $hooks = self::list_files('hooks', TRUE);
         foreach ($hooks as $file) {
             // Load the hook
             include $file;
         }
     }
     // Setup is complete, prevent it from being run again
     $run = TRUE;
     // Stop the environment setup routine
     Benchmark::stop(SYSTEM_BENCHMARK . '_environment_setup');
 }
开发者ID:nanangsyaifudin,项目名称:HAC-2012,代码行数:96,代码来源:Kohana.php

示例9: download

 /**
  * Download a file to the user's browser. This function is
  * binary-safe and will work with any MIME type that Kohana is aware of.
  *
  * @param   string  a file path or file name, or data
  * @param   string  suggested filename to display in the download
  * @return  void
  */
 public static function download($filedata, $filename = NULL)
 {
     // file
     if (is_file($filedata)) {
         $filepath = str_replace('\\', '/', realpath($filedata));
         $filesize = filesize($filepath);
         $filename = substr(strrchr('/' . $filepath, '/'), 1);
         // Make sure the filename does not have directory info
         $extension = strtolower(substr(strrchr($filepath, '.'), 1));
     } else {
         $filesize = strlen($filedata);
         $extension = strtolower(substr(strrchr($filename, '.'), 1));
     }
     // Mimetype
     $mimes = Kohana::config('mimes.' . $extension);
     $mime = $mimes[0];
     if (empty($mime)) {
         $mime = array('application/octet-stream');
     }
     // headers
     // Generate the server headers
     header('Content-Type: ' . $mime[0]);
     header('Content-Disposition: attachment; filename="' . (empty($nicename) ? $filename : $nicename) . '"');
     header('Content-Transfer-Encoding: binary');
     header('Content-Length: ' . sprintf('%d', $filesize));
     // More caching prevention
     header('Expires: 0');
     if (Kohana::user_agent('browser') === 'Internet Explorer') {
         // Send IE headers
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header('Pragma: public');
     } else {
         // Send normal headers
         header('Pragma: no-cache');
     }
     // output
     if (isset($filepath)) {
         $handle = fopen($filepath, 'rb');
         fpassthru($handle);
         fclose($handle);
     } else {
         echo $filedata;
     }
 }
开发者ID:riartem,项目名称:kohana-update,代码行数:52,代码来源:Filesystem.php

示例10: add_stat

 public static function add_stat($type, $id)
 {
     if (Kohana::user_agent('is_browser')) {
         ORM::factory('statistic')->add_view($type, $id);
     }
 }
开发者ID:sydlawrence,项目名称:SocialFeed,代码行数:6,代码来源:zest.php

示例11: user_agent

 /**
  * Demonstrates the User_Agent library.
  */
 function user_agent()
 {
     foreach (array('agent', 'browser', 'version') as $key) {
         echo $key . ': ' . Kohana::user_agent($key) . '<br/>' . "\n";
     }
     echo "<br/><br/>\n";
     echo 'done in {execution_time} seconds';
 }
开发者ID:AsteriaGamer,项目名称:steamdriven-kohana,代码行数:11,代码来源:examples.php

示例12: teardown

 public function teardown()
 {
     Input::instance()->ip_address = $this->_ip_address;
     Kohana::$user_agent = $this->_user_agent;
 }
开发者ID:xafr,项目名称:gallery3,代码行数:5,代码来源:Comment_Helper_Test.php

示例13: array

 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
 */
// If var/database.php doesn't exist, then we assume that the Gallery is not properly installed
// and send users to the installer.
if (!file_exists(VARPATH . "database.php")) {
    url::redirect(url::abs_file("installer"));
}
Event::add("system.ready", array("I18n", "instance"));
Event::add("system.ready", array("module", "load_modules"));
Event::add("system.ready", array("gallery", "ready"));
Event::add("system.post_routing", array("url", "parse_url"));
Event::add("system.post_routing", array("gallery", "maintenance_mode"));
Event::add("system.shutdown", array("gallery", "shutdown"));
// @todo once we convert to Kohana 2.4 this doesn't have to be here
set_error_handler(array("gallery_error", "error_handler"));
// Override the cookie if we have a session id in the URL.
// @todo This should probably be an event callback
$input = Input::instance();
if ($g3sid = $input->post("g3sid", $input->get("g3sid"))) {
    $_COOKIE["g3sid"] = $g3sid;
}
if ($user_agent = $input->post("user_agent", $input->get("user_agent"))) {
    Kohana::$user_agent = $user_agent;
}
开发者ID:ChrisRut,项目名称:gallery3,代码行数:31,代码来源:init_gallery.php

示例14: user_agent

 /**
  * Retrieves current user agent information:
  * keys:  browser, version, platform, mobile, robot, referrer, languages, charsets
  * tests: is_browser, is_mobile, is_robot, accept_lang, accept_charset
  *
  * @param   string   key or test name
  * @param   string   used with "accept" tests: user_agent(accept_lang, en)
  * @return  array    languages and charsets
  * @return  string   all other keys
  * @return  boolean  all tests
  */
 public static function user_agent($key = 'agent', $compare = NULL)
 {
     static $info;
     // Return the raw string
     if ($key === 'agent') {
         return Kohana::$user_agent;
     }
     if ($info === NULL) {
         // Parse the user agent and extract basic information
         $agents = Kohana::config('user_agents');
         foreach ($agents as $type => $data) {
             foreach ($data as $agent => $name) {
                 if (stripos(Kohana::$user_agent, $agent) !== FALSE) {
                     if ($type === 'browser' and preg_match('|' . preg_quote($agent) . '[^0-9.]*+([0-9.][0-9.a-z]*)|i', Kohana::$user_agent, $match)) {
                         // Set the browser version
                         $info['version'] = $match[1];
                     }
                     // Set the agent name
                     $info[$type] = $name;
                     break;
                 }
             }
         }
     }
     if (empty($info[$key])) {
         switch ($key) {
             case 'is_robot':
             case 'is_browser':
             case 'is_mobile':
                 // A boolean result
                 $return = !empty($info[substr($key, 3)]);
                 break;
             case 'languages':
                 $return = array();
                 if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                     if (preg_match_all('/[-a-z]{2,}/', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE'])), $matches)) {
                         // Found a result
                         $return = $matches[0];
                     }
                 }
                 break;
             case 'charsets':
                 $return = array();
                 if (!empty($_SERVER['HTTP_ACCEPT_CHARSET'])) {
                     if (preg_match_all('/[-a-z0-9]{2,}/', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET'])), $matches)) {
                         // Found a result
                         $return = $matches[0];
                     }
                 }
                 break;
             case 'referrer':
                 if (!empty($_SERVER['HTTP_REFERER'])) {
                     // Found a result
                     $return = trim($_SERVER['HTTP_REFERER']);
                 }
                 break;
         }
         // Cache the return value
         isset($return) and $info[$key] = $return;
     }
     if (!empty($compare)) {
         // The comparison must always be lowercase
         $compare = strtolower($compare);
         switch ($key) {
             case 'accept_lang':
                 // Check if the lange is accepted
                 return in_array($compare, Kohana::user_agent('languages'));
                 break;
             case 'accept_charset':
                 // Check if the charset is accepted
                 return in_array($compare, Kohana::user_agent('charsets'));
                 break;
             default:
                 // Invalid comparison
                 return FALSE;
                 break;
         }
     }
     // Return the key, if set
     return isset($info[$key]) ? $info[$key] : NULL;
 }
开发者ID:sydlawrence,项目名称:SocialFeed,代码行数:92,代码来源:Kohana.php


注:本文中的Kohana::user_agent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。