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


PHP Okapi::get_var_dir方法代码示例

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


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

示例1: set

 /**
  * Note, there is no $timeout (time to live) parameter. Currently,
  * OKAPI will delete every old file after certain amount of time.
  * See CacheCleanupCronJob for details.
  */
 public static function set($key, $value)
 {
     $filename = Okapi::get_var_dir() . "/okapi_filecache_" . md5($key);
     file_put_contents($filename, $value);
     return $filename;
 }
开发者ID:Slini11,项目名称:okapi,代码行数:11,代码来源:core.php

示例2: execute

 public function execute()
 {
     # Delete all expired elements.
     Db::execute("\n            delete from okapi_cache\n            where expires < now()\n        ");
     # Update the "score" stats.
     $multiplier = 0.9;
     # Every hour, all scores are multiplied by this.
     $limit = 0.01;
     # When a score reaches this limit, the entry is deleted.
     # Every time the entry is read, its score is incread by 1. If an entry
     # is saved, but never read, it will be deleted after log(L,M) hours
     # (log(0.01, 0.9) = 43h). If an entry is read 1000000 times and then
     # never read anymore, it will be deleted after log(1000000/L, 1/M)
     # hours (log(1000000/0.01, 1/0.9) = 174h = 7 days).
     Db::execute("\n            update okapi_cache\n            set score = score * '" . mysql_real_escape_string($multiplier) . "'\n            where score is not null\n        ");
     Db::execute("\n            update\n                okapi_cache c,\n                (\n                    select cache_key, count(*) as count\n                    from okapi_cache_reads\n                    group by cache_key\n                ) cr\n            set c.score = c.score + cr.count\n            where\n                c.`key` = cr.cache_key\n                and c.score is not null\n        ");
     Db::execute("truncate okapi_cache_reads");
     # Delete elements with the lowest score. Entries which have been set
     # but never read will be removed after 36 hours (0.9^36 < 0.02 < 0.9^35).
     Db::execute("\n            delete from okapi_cache\n            where\n                score is not null\n                and score < '" . mysql_real_escape_string($limit) . "'\n        ");
     Db::query("optimize table okapi_cache");
     # FileCache does not have an expiry date. We will delete all files older
     # than 24 hours.
     $dir = Okapi::get_var_dir();
     if ($dh = opendir($dir)) {
         while (($file = readdir($dh)) !== false) {
             if (strpos($file, "okapi_filecache_") === 0) {
                 if (filemtime("{$dir}/{$file}") < time() - 86400) {
                     unlink("{$dir}/{$file}");
                 }
             }
         }
         closedir($dh);
     }
 }
开发者ID:4Vs,项目名称:oc-server3,代码行数:35,代码来源:cronjobs.php

示例3: _call


//.........这里部分代码省略.........
         # If we're here, then we also know that the "Needs maintenance" log type is supported
         # by this OC site. However, it's a separate log type, so we might have to submit
         # two log types together:
         if ($logtype == 'Comment') {
             # If user submits a "Comment", we'll just change its type to "Needs maintenance".
             # Only one log entry will be issued.
             $logtype = 'Needs maintenance';
             $second_logtype = null;
             $second_formatted_comment = null;
         } elseif ($logtype == 'Found it') {
             # If "Found it", then we'll issue two log entries: one "Found it" with the
             # original comment, and second one "Needs maintenance" with empty comment.
             $second_logtype = 'Needs maintenance';
             $second_formatted_comment = "";
         } elseif ($logtype == "Didn't find it") {
             # If "Didn't find it", then we'll issue two log entries, but this time
             # we'll do this the other way around. The first "Didn't find it" entry
             # will have an empty comment. We will move the comment to the second
             # "Needs maintenance" log entry. (It's okay for this behavior to change
             # in the future, but it seems natural to me.)
             $second_logtype = 'Needs maintenance';
             $second_formatted_comment = $formatted_comment;
             $formatted_comment = "";
         } else {
             if ($logtype == 'Will attend' || $logtype == 'Attended') {
                 # OC branches which know maintenance logs do not allow them on event caches.
                 throw new CannotPublishException(_("Event caches cannot \"need maintenance\"."));
             } else {
                 throw new Exception();
             }
         }
     } else {
         # User didn't check the "Needs maintenance" flag OR "Needs maintenance" log type
         # isn't supported by this server.
         $second_logtype = null;
         $second_formatted_comment = null;
     }
     # Finally! Insert the rows into the log entries table. Update
     # cache stats and user stats.
     $log_uuid = self::insert_log_row($request->consumer->key, $cache['internal_id'], $user['internal_id'], $logtype, $when, $formatted_comment, $value_for_text_html_field);
     self::increment_cache_stats($cache['internal_id'], $when, $logtype);
     self::increment_user_stats($user['internal_id'], $logtype);
     if ($second_logtype != null) {
         # Reminder: This will never be called while SUPPORTS_LOGTYPE_NEEDS_MAINTENANCE is off.
         self::insert_log_row($request->consumer->key, $cache['internal_id'], $user['internal_id'], $second_logtype, $when + 1, $second_formatted_comment, $value_for_text_html_field);
         self::increment_cache_stats($cache['internal_id'], $when + 1, $second_logtype);
         self::increment_user_stats($user['internal_id'], $second_logtype);
     }
     # Save the rating.
     if ($rating) {
         # This code will be called for OCPL branch only. Earlier, we made sure,
         # to set $rating to null, if we're running on OCDE.
         # OCPL has a little strange way of storing cumulative rating. Instead
         # of storing the sum of all ratings, OCPL stores the computed average
         # and update it using multiple floating-point operations. Moreover,
         # the "score" field in the database is on the -3..3 scale (NOT 1..5),
         # and the translation made at retrieval time is DIFFERENT than the
         # one made here (both of them are non-linear). Also, once submitted,
         # the rating can never be changed. It surely feels quite inconsistent,
         # but presumably has some deep logic into it. See also here (Polish):
         # http://wiki.opencaching.pl/index.php/Oceny_skrzynek
         switch ($rating) {
             case 1:
                 $db_score = -2.0;
                 break;
             case 2:
                 $db_score = -0.5;
                 break;
             case 3:
                 $db_score = 0.7;
                 break;
             case 4:
                 $db_score = 1.7;
                 break;
             case 5:
                 $db_score = 3.0;
                 break;
             default:
                 throw new Exception();
         }
         Db::execute("\n                update caches\n                set\n                    score = (score*votes + '" . mysql_real_escape_string($db_score) . "')/(votes + 1),\n                    votes = votes + 1\n                where cache_id = '" . mysql_real_escape_string($cache['internal_id']) . "'\n            ");
         Db::execute("\n                insert into scores (user_id, cache_id, score)\n                values (\n                    '" . mysql_real_escape_string($user['internal_id']) . "',\n                    '" . mysql_real_escape_string($cache['internal_id']) . "',\n                    '" . mysql_real_escape_string($db_score) . "'\n                );\n            ");
     }
     # Save recommendation.
     if ($recommend) {
         if (Db::field_exists('cache_rating', 'rating_date')) {
             Db::execute("\n                    insert into cache_rating (user_id, cache_id, rating_date)\n                    values (\n                        '" . mysql_real_escape_string($user['internal_id']) . "',\n                        '" . mysql_real_escape_string($cache['internal_id']) . "',\n                        from_unixtime('" . mysql_real_escape_string($when) . "')\n                    );\n                ");
         } else {
             Db::execute("\n                    insert into cache_rating (user_id, cache_id)\n                    values (\n                        '" . mysql_real_escape_string($user['internal_id']) . "',\n                        '" . mysql_real_escape_string($cache['internal_id']) . "'\n                    );\n                ");
         }
     }
     # We need to delete the copy of stats-picture for this user. Otherwise,
     # the legacy OC code won't detect that the picture needs to be refreshed.
     $filepath = Okapi::get_var_dir() . '/images/statpics/statpic' . $user['internal_id'] . '.jpg';
     if (file_exists($filepath)) {
         unlink($filepath);
     }
     # Success. Return the uuid.
     return $log_uuid;
 }
开发者ID:4Vs,项目名称:oc-server3,代码行数:101,代码来源:submit.php

示例4: generate_fulldump

 /**
  * Generate a new fulldump file and put it into the OKAPI cache table.
  * Return the cache key.
  */
 public static function generate_fulldump()
 {
     # First we will create temporary files, then compress them in the end.
     $revision = self::get_revision();
     $generated_at = date('c', time());
     $dir = Okapi::get_var_dir() . "/okapi-db-dump";
     $i = 1;
     $json_files = array();
     # Cleanup (from a previous, possibly unsuccessful, execution)
     shell_exec("rm -f {$dir}/*");
     shell_exec("rmdir {$dir}");
     shell_exec("mkdir {$dir}");
     shell_exec("chmod 777 {$dir}");
     # Geocaches
     $cache_codes = Db::select_column("select wp_oc from caches");
     $cache_code_groups = Okapi::make_groups($cache_codes, self::$chunk_size);
     unset($cache_codes);
     foreach ($cache_code_groups as $cache_codes) {
         $basename = "part" . str_pad($i, 5, "0", STR_PAD_LEFT);
         $json_files[] = $basename . ".json";
         $entries = self::generate_changelog_entries('services/caches/geocaches', 'geocache', 'cache_codes', 'code', $cache_codes, self::$logged_cache_fields, true, false);
         $filtered = array();
         foreach ($entries as $entry) {
             if ($entry['change_type'] == 'replace') {
                 $filtered[] = $entry;
             }
         }
         unset($entries);
         file_put_contents("{$dir}/{$basename}.json", json_encode($filtered));
         unset($filtered);
         $i++;
     }
     unset($cache_code_groups);
     # Log entries. We cannot load all the uuids at one time, this would take
     # too much memory. Hence the offset/limit loop.
     $offset = 0;
     while (true) {
         $log_uuids = Db::select_column("\n                select uuid\n                from cache_logs\n                where " . (Settings::get('OC_BRANCH') == 'oc.pl' ? "deleted = 0" : "true") . "\n                order by uuid\n                limit {$offset}, 10000\n            ");
         if (count($log_uuids) == 0) {
             break;
         }
         $offset += 10000;
         $log_uuid_groups = Okapi::make_groups($log_uuids, 500);
         unset($log_uuids);
         foreach ($log_uuid_groups as $log_uuids) {
             $basename = "part" . str_pad($i, 5, "0", STR_PAD_LEFT);
             $json_files[] = $basename . ".json";
             $entries = self::generate_changelog_entries('services/logs/entries', 'log', 'log_uuids', 'uuid', $log_uuids, self::$logged_log_entry_fields, true, false);
             $filtered = array();
             foreach ($entries as $entry) {
                 if ($entry['change_type'] == 'replace') {
                     $filtered[] = $entry;
                 }
             }
             unset($entries);
             file_put_contents("{$dir}/{$basename}.json", json_encode($filtered));
             unset($filtered);
             $i++;
         }
     }
     # Package data.
     $metadata = array('revision' => $revision, 'data_files' => $json_files, 'meta' => array('site_name' => Okapi::get_normalized_site_name(), 'okapi_version_number' => Okapi::$version_number, 'okapi_revision' => Okapi::$version_number, 'okapi_git_revision' => Okapi::$git_revision, 'generated_at' => $generated_at));
     file_put_contents("{$dir}/index.json", json_encode($metadata));
     # Compute uncompressed size.
     $size = filesize("{$dir}/index.json");
     foreach ($json_files as $filename) {
         $size += filesize("{$dir}/{$filename}");
     }
     # Create JSON archive. We use tar options: -j for bzip2, -z for gzip
     # (bzip2 is MUCH slower).
     $use_bzip2 = true;
     $dumpfilename = "okapi-dump.tar." . ($use_bzip2 ? "bz2" : "gz");
     shell_exec("tar --directory {$dir} -c" . ($use_bzip2 ? "j" : "z") . "f {$dir}/{$dumpfilename} index.json " . implode(" ", $json_files) . " 2>&1");
     # Delete temporary files.
     shell_exec("rm -f {$dir}/*.json");
     # Move the archive one directory upwards, replacing the previous one.
     # Remove the temporary directory.
     shell_exec("mv -f {$dir}/{$dumpfilename} " . Okapi::get_var_dir());
     shell_exec("rmdir {$dir}");
     # Update the database info.
     $metadata['meta']['filepath'] = Okapi::get_var_dir() . '/' . $dumpfilename;
     $metadata['meta']['content_type'] = $use_bzip2 ? "application/octet-stream" : "application/x-gzip";
     $metadata['meta']['public_filename'] = 'okapi-dump-r' . $metadata['revision'] . '.tar.' . ($use_bzip2 ? "bz2" : "gz");
     $metadata['meta']['uncompressed_size'] = $size;
     $metadata['meta']['compressed_size'] = filesize($metadata['meta']['filepath']);
     Cache::set("last_fulldump", $metadata, 10 * 86400);
 }
开发者ID:PaulinaKowalczuk,项目名称:oc-server3,代码行数:91,代码来源:replicate_common.inc.php

示例5: _call


//.........这里部分代码省略.........
             # If user submits a "Comment", we'll just change its type to
             # "Needs maintenance". Only one log entry will be issued.
             $logtype = 'Needs maintenance';
             $second_logtype = null;
             $second_formatted_comment = null;
         } elseif ($logtype == 'Found it') {
             # If "Found it", then we'll issue two log entries: one "Found
             # it" with the original comment, and second one "Needs
             # maintenance" with empty comment.
             $second_logtype = 'Needs maintenance';
             $second_formatted_comment = "";
         } elseif ($logtype == "Didn't find it") {
             # If "Didn't find it", then we'll issue two log entries, but this time
             # we'll do this the other way around. The first "Didn't find it" entry
             # will have an empty comment. We will move the comment to the second
             # "Needs maintenance" log entry. (It's okay for this behavior to change
             # in the future, but it seems natural to me.)
             $second_logtype = 'Needs maintenance';
             $second_formatted_comment = $formatted_comment;
             $formatted_comment = "";
         } else {
             if ($logtype == 'Will attend' || $logtype == 'Attended') {
                 # OC branches which allow maintenance logs, still don't allow them on
                 # event caches.
                 throw new CannotPublishException(_("Event caches cannot \"need maintenance\"."));
             } else {
                 throw new Exception();
             }
         }
     } else {
         # User didn't check the "Needs maintenance" flag OR "Needs maintenance"
         # log type isn't supported by this server.
         $second_logtype = null;
         $second_formatted_comment = null;
     }
     # Finally! Insert the rows into the log entries table. Update
     # cache stats and user stats.
     $log_uuids = array(self::insert_log_row($request->consumer->key, $cache['internal_id'], $user['internal_id'], $logtype, $when, $formatted_comment, $value_for_text_html_field, $needs_maintenance2));
     self::increment_cache_stats($cache['internal_id'], $when, $logtype);
     self::increment_user_stats($user['internal_id'], $logtype);
     if ($second_logtype != null) {
         # Reminder: This will only be called for OCPL branch.
         $log_uuids[] = self::insert_log_row($request->consumer->key, $cache['internal_id'], $user['internal_id'], $second_logtype, $when + 1, $second_formatted_comment, $value_for_text_html_field, 'null');
         self::increment_cache_stats($cache['internal_id'], $when + 1, $second_logtype);
         self::increment_user_stats($user['internal_id'], $second_logtype);
     }
     # Save the rating.
     if ($rating) {
         # This code will be called for OCPL branch only. Earlier, we made sure,
         # to set $rating to null, if we're running on OCDE.
         # OCPL has a little strange way of storing cumulative rating. Instead
         # of storing the sum of all ratings, OCPL stores the computed average
         # and update it using multiple floating-point operations. Moreover,
         # the "score" field in the database is on the -3..3 scale (NOT 1..5),
         # and the translation made at retrieval time is DIFFERENT than the
         # one made here (both of them are non-linear). Also, once submitted,
         # the rating can never be changed. It surely feels quite inconsistent,
         # but presumably has some deep logic into it. See also here (Polish):
         # http://wiki.opencaching.pl/index.php/Oceny_skrzynek
         switch ($rating) {
             case 1:
                 $db_score = -2.0;
                 break;
             case 2:
                 $db_score = -0.5;
                 break;
             case 3:
                 $db_score = 0.7;
                 break;
             case 4:
                 $db_score = 1.7;
                 break;
             case 5:
                 $db_score = 3.0;
                 break;
             default:
                 throw new Exception();
         }
         Db::execute("\n                update caches\n                set\n                    score = (\n                        score*votes + '" . Db::escape_string($db_score) . "'\n                    ) / (votes + 1),\n                    votes = votes + 1\n                where cache_id = '" . Db::escape_string($cache['internal_id']) . "'\n            ");
         Db::execute("\n                insert into scores (user_id, cache_id, score)\n                values (\n                    '" . Db::escape_string($user['internal_id']) . "',\n                    '" . Db::escape_string($cache['internal_id']) . "',\n                    '" . Db::escape_string($db_score) . "'\n                );\n            ");
     }
     # Save recommendation.
     if ($recommend) {
         if (Db::field_exists('cache_rating', 'rating_date')) {
             Db::execute("\n                    insert into cache_rating (user_id, cache_id, rating_date)\n                    values (\n                        '" . Db::escape_string($user['internal_id']) . "',\n                        '" . Db::escape_string($cache['internal_id']) . "',\n                        from_unixtime('" . Db::escape_string($when) . "')\n                    );\n                ");
         } else {
             Db::execute("\n                    insert into cache_rating (user_id, cache_id)\n                    values (\n                        '" . Db::escape_string($user['internal_id']) . "',\n                        '" . Db::escape_string($cache['internal_id']) . "'\n                    );\n                ");
         }
     }
     # Finalize the transaction.
     Db::execute("commit");
     # We need to delete the copy of stats-picture for this user. Otherwise,
     # the legacy OC code won't detect that the picture needs to be refreshed.
     $filepath = Okapi::get_var_dir() . '/images/statpics/statpic' . $user['internal_id'] . '.jpg';
     if (file_exists($filepath)) {
         unlink($filepath);
     }
     # Success. Return the uuids.
     return $log_uuids;
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:101,代码来源:submit.php


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