本文整理汇总了PHP中t2函数的典型用法代码示例。如果您正苦于以下问题:PHP t2函数的具体用法?PHP t2怎么用?PHP t2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了t2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
static function get($block_id, $theme)
{
$block = "";
switch ($block_id) {
case "random_image":
// The random_query approach is flawed and doesn't always return a
// result when there actually is one. Retry a *few* times.
// @todo Consider another fallback if further optimizations are necessary.
$image_count = module::get_var("image_block", "image_count");
$items = array();
for ($i = 0; $i < $image_count; $i++) {
$attempts = 0;
$item = null;
do {
$item = item::random_query()->where("type", "!=", "album")->find_all(1)->current();
} while (!$item && $attempts++ < 3);
if ($item) {
$items[] = $item;
}
}
if ($items) {
$block = new Block();
$block->css_id = "g-image-block";
$block->title = t2("Random image", "Random images", $image_count);
$block->content = new View("image_block_block.html");
$block->content->items = $items;
}
break;
}
return $block;
}
示例2: delete
public function delete($ptID = false)
{
$pagetype = PageType::getByID($ptID);
if (!is_object($pagetype)) {
$this->error->add(t('Invalid page type object.'));
}
$cmp = new \Permissions($pagetype);
if (!$cmp->canDeletePageType()) {
$this->error->add(t('You do not have access to delete this page type.'));
}
$count = $pagetype->getPageTypeUsageCount();
if ($count > 0) {
$this->error->add(t2(
'This page type is in use on %d page.',
'This page type is in use on %d pages.', $count));
}
if (!$this->token->validate('delete_page_type')) {
$this->error->add(t($this->token->getErrorMessage()));
}
if (!$this->error->has()) {
$pagetype->delete();
$this->redirect('/dashboard/pages/types', 'page_type_deleted');
}
$this->view();
}
示例3: rescan
public function rescan() {
$files = $this->getRequestFiles('canEditFileContents');
$r = new FileEditResponse();
$r->setFiles($files);
$successMessage = '';
$errorMessage = '';
$successCount = 0;
foreach($files as $f) {
try {
$fv = $f->getApprovedVersion();
$resp = $fv->refreshAttributes();
switch ($resp) {
case \Concrete\Core\File\Importer::E_FILE_INVALID:
$errorMessage .= t('File %s could not be found.', $fv->getFilename()) . '<br/>';
break;
default:
$successCount++;
$successMessage = t2('%s file rescanned successfully.', '%s files rescanned successfully.',
$successCount);
break;
}
} catch(\Concrete\Flysystem\FileNotFoundException $e) {
$errorMessage .= t('File %s could not be found.', $fv->getFilename()) . '<br/>';
}
}
if ($errorMessage && !$successMessage) {
$e = new \Concrete\Core\Error\Error;
$e->add($errorMessage);
$r->setError($e);
} else {
$r->setMessage($errorMessage . $successMessage);
}
$r->outputJSON();
}
示例4: rescan_locale
public function rescan_locale()
{
if ($this->token->validate('rescan_locale')) {
$u = new \User();
if ($u->isSuperUser()) {
\Core::make('cache/request')->disable();
$section = Section::getByID($_REQUEST['locale']);
$target = new MultilingualProcessorTarget($section);
$processor = new Processor($target);
if ($_POST['process']) {
foreach ($processor->receive() as $task) {
$processor->execute($task);
}
$obj = new \stdClass();
$obj->totalItems = $processor->getTotalTasks();
echo json_encode($obj);
exit;
} else {
$processor->process();
}
$totalItems = $processor->getTotalTasks();
\View::element('progress_bar', array('totalItems' => $totalItems, 'totalItemsSummary' => t2("%d task", "%d tasks", $totalItems)));
exit;
}
}
}
示例5: update_index
static function update_index($task)
{
try {
$completed = $task->get("completed", 0);
$start = microtime(true);
foreach (ORM::factory("item")->join("exif_records", "items.id", "exif_records.item_id", "left")->where("type", "photo")->open_paren()->where("exif_records.item_id", null)->orwhere("exif_records.dirty", 1)->close_paren()->find_all() as $item) {
if (microtime(true) - $start > 1.5) {
break;
}
$completed++;
exif::extract($item);
}
list($remaining, $total, $percent) = exif::stats();
$task->set("completed", $completed);
if ($remaining == 0 || !($remaining + $completed)) {
$task->done = true;
$task->state = "success";
site_status::clear("exif_index_out_of_date");
$task->percent_complete = 100;
} else {
$task->percent_complete = round(100 * $completed / ($remaining + $completed));
}
$task->status = t2("one record updated, index is %percent% up-to-date", "%count records updated, index is %percent% up-to-date", $completed, array("percent" => $percent));
} catch (Exception $e) {
$task->done = true;
$task->state = "error";
$task->status = $e->getMessage();
$task->log($e->__toString());
}
}
示例6: fix_internet_addresses
static function fix_internet_addresses($task)
{
$start = microtime(true);
$total = $task->get("total");
if (empty($total)) {
$task->set("total", $total = db::build()->count_records("items"));
$task->set("last_id", 0);
$task->set("completed", 0);
}
$last_id = $task->get("last_id");
$completed = $task->get("completed");
foreach (ORM::factory("item")->where("id", ">", $last_id)->find_all(100) as $item) {
$item->slug = item::convert_filename_to_slug($item->slug);
$item->save();
$last_id = $item->id;
$completed++;
if ($completed == $total || microtime(true) - $start > 1.5) {
break;
}
}
$task->set("completed", $completed);
$task->set("last_id", $last_id);
if ($total == $completed) {
$task->done = true;
$task->state = "success";
$task->percent_complete = 100;
db::build()->update("items")->set("relative_path_cache", null)->set("relative_url_cache", null)->execute();
} else {
$task->percent_complete = round(100 * $completed / $total);
}
$task->status = t2("One row updated", "%count / %total rows updated", $completed, array("total" => $total));
}
示例7: run
public function run()
{
Cache::disableCache();
Loader::library('database_indexed_search');
$is = new IndexedSearch();
if ($_GET['force'] == 1) {
Loader::model('attribute/categories/collection');
Loader::model('attribute/categories/file');
Loader::model('attribute/categories/user');
$attributes = CollectionAttributeKey::getList();
$attributes = array_merge($attributes, FileAttributeKey::getList());
$attributes = array_merge($attributes, UserAttributeKey::getList());
foreach ($attributes as $ak) {
$ak->updateSearchIndex();
}
$result = $is->reindexAll(true);
} else {
$result = $is->reindexAll();
}
if ($result->count == 0) {
return t('Indexing complete. Index is up to date');
} else {
if ($result->count == $is->searchBatchSize) {
return t('Index partially updated. %s pages indexed (maximum number.) Re-run this job to continue this process.', $result->count);
} else {
return t('Index updated.') . ' ' . t2('%d page required reindexing.', '%d pages required reindexing.', $result->count, $result->count);
}
}
}
示例8: update_index
static function update_index($task)
{
try {
$completed = $task->get("completed", 0);
$start = microtime(true);
foreach (ORM::factory("item")->join("exif_records", "items.id", "exif_records.item_id", "left")->where("type", "=", "photo")->and_open()->where("exif_records.item_id", "IS", null)->or_where("exif_records.dirty", "=", 1)->close()->find_all() as $item) {
// The query above can take a long time, so start the timer after its done
// to give ourselves a little time to actually process rows.
if (!isset($start)) {
$start = microtime(true);
}
exif::extract($item);
$completed++;
if (microtime(true) - $start > 1.5) {
break;
}
}
list($remaining, $total, $percent) = exif::stats();
$task->set("completed", $completed);
if ($remaining == 0 || !($remaining + $completed)) {
$task->done = true;
$task->state = "success";
site_status::clear("exif_index_out_of_date");
$task->percent_complete = 100;
} else {
$task->percent_complete = round(100 * $completed / ($remaining + $completed));
}
$task->status = t2("one record updated, index is %percent% up-to-date", "%count records updated, index is %percent% up-to-date", $completed, array("percent" => $percent));
} catch (Exception $e) {
$task->done = true;
$task->state = "error";
$task->status = $e->getMessage();
$task->log((string) $e);
}
}
示例9: rebuild_dirty_images
/**
* Task that rebuilds all dirty images.
* @param Task_Model the task
*/
static function rebuild_dirty_images($task)
{
$result = graphics::find_dirty_images_query();
$remaining = $result->count();
$completed = $task->get("completed", 0);
$i = 0;
foreach ($result as $row) {
$item = ORM::factory("item", $row->id);
if ($item->loaded) {
graphics::generate($item);
}
$completed++;
$remaining--;
if (++$i == 2) {
break;
}
}
$task->status = t2("Updated: 1 image. Total: %total_count.", "Updated: %count images. Total: %total_count.", $completed, array("total_count" => $remaining + $completed));
if ($completed + $remaining > 0) {
$task->percent_complete = (int) (100 * $completed / ($completed + $remaining));
} else {
$task->percent_complete = 100;
}
$task->set("completed", $completed);
if ($remaining == 0) {
$task->done = true;
$task->state = "success";
site_status::clear("graphics_dirty");
}
}
示例10: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$db = \Database::connection();
$em = $db->getEntityManager();
$cacheDriver = $em->getConfiguration()->getMetadataCacheImpl();
$cacheDriver->flushAll();
$tool = new \Doctrine\ORM\Tools\SchemaTool($em);
$schemas = [];
/**
* @var $sm MySqlSchemaManager
*/
$sm = $db->getSchemaManager();
$dbSchema = $sm->createSchema();
// core xml tables
$schemas[] = Schema::getCoreXMLSchema();
// core entities
$sm = new DatabaseStructureManager($em);
$entities = $sm->getMetadatas();
$schemas[] = $tool->getSchemaFromMetadata($entities);
// core, application and package block types
$env = Environment::get();
$list = new BlockTypeList();
$list->includeInternalBlockTypes();
foreach ($list->get() as $bt) {
$r = $env->getRecord(DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . '/' . FILENAME_BLOCK_DB, $bt->getPackageHandle());
if ($r->exists()) {
$parser = Schema::getSchemaParser(simplexml_load_file($r->file));
$parser->setIgnoreExistingTables(false);
$schemas[] = $parser->parse($db);
}
}
// packages
$packages = Package::getInstalledList();
foreach ($packages as $pkg) {
$xmlFile = $pkg->getPackagePath() . '/' . FILENAME_BLOCK_DB;
if (file_exists($xmlFile)) {
$parser = Schema::getSchemaParser(simplexml_load_file($xmlFile));
$parser->setIgnoreExistingTables(false);
$schemas[] = $parser->parse($db);
}
}
// Finalize output.
$comparator = new \Doctrine\DBAL\Schema\Comparator();
$saveQueries = array();
foreach ($schemas as $schema) {
$schemaDiff = $comparator->compare($dbSchema, $schema);
$saveQueries = array_merge($saveQueries, $schemaDiff->toSaveSql($db->getDatabasePlatform()));
}
$saveQueries = $this->filterQueries($saveQueries);
if (count($saveQueries)) {
$output->writeln(t2('%s query found', '%s queries found', count($saveQueries)));
$i = 1;
foreach ($saveQueries as $query) {
$output->writeln(sprintf('%s: %s', $i, $query));
$i++;
}
} else {
$output->writeln(t('No differences found between schema and database.'));
}
}
示例11: run
public function run()
{
$cfg = new Config();
$pNum = (int) $cfg->get('OLD_VERSION_JOB_PAGE_NUM');
$pNum = $pNum < 0 ? 1 : $pNum + 1;
$pl = new PageList();
$pl->setItemsPerPage(3);
/* probably want to keep a record of pages that have been gone through
* so you don't start from the beginning each time..
*/
$pages = $pl->getPage($pNum);
if (!count($pages)) {
$cfg->save('OLD_VERSION_JOB_PAGE_NUM', 0);
return t("All pages have been processed, starting from beginning on next run.");
}
$versionCount = 0;
$pagesAffected = array();
foreach ($pages as $page) {
if ($page instanceof Page) {
$pvl = new VersionList($page);
$pagesAffected[] = $page->getCollectionID();
foreach (array_slice(array_reverse($pvl->getVersionListArray()), 10) as $v) {
if ($v instanceof CollectionVersion && !$v->isApproved() && !$v->isMostRecent()) {
@$v->delete();
$versionCount++;
}
}
}
}
$pageCount = count($pagesAffected);
$cfg->save('OLD_VERSION_JOB_PAGE_NUM', $pNum);
//i18n: %1$d is the number of versions deleted, %2$d is the number of affected pages, %3$d is the number of times that the Remove Old Page Versions job has been executed.
return t2('%1$d versions deleted from %2$d page (%3$d)', '%1$d versions deleted from %2$d pages (%3$s)', $pageCount, $versionCount, $pageCount, implode(',', $pagesAffected));
}
示例12: available_tasks
static function available_tasks()
{
$q = emboss::find_dirty();
$n = $q->count();
$description = $n == 0 ? t('All photo overlays are up to date') : t2('one Photo needs its emboss overlay updated', "{$n} Photos need their emboss overlay updated", $n);
$tasks[] = Task_Definition::factory()->callback('emboss_task::update_overlays')->name(t('Update photo embossing'))->description($description)->severity($n > 0 ? log::WARNING : log::SUCCESS);
return $tasks;
}
示例13: clean_up_tags
/**
* Fix up tag counts and delete any tags that have no associated items.
* @param Task_Model the task
*/
static function clean_up_tags($task)
{
$errors = array();
try {
$start = microtime(true);
$last_tag_id = $task->get("last_tag_id", null);
$current = 0;
$total = 0;
switch ($task->get("mode", "init")) {
case "init":
$task->set("total", ORM::factory("tag")->count_all());
$task->set("mode", "clean_up_tags");
$task->set("completed", 0);
$task->set("last_tag_id", 0);
case "clean_up_tags":
$completed = $task->get("completed");
$total = $task->get("total");
$last_tag_id = $task->get("last_tag_id");
$tags = ORM::factory("tag")->where("id", ">", $last_tag_id)->find_all(25);
Kohana_Log::add("error", print_r(Database::instance()->last_query(), 1));
while ($current < $total && microtime(true) - $start < 1 && ($tag = $tags->current())) {
$last_tag_id = $tag->id;
$real_count = $tag->items_count();
if ($tag->count != $real_count) {
$tag->count = $real_count;
if ($tag->count) {
$task->log("Fixing count for tag {$tag->name} (id: {$tag->id}, new count: {$tag->count})");
$tag->save();
} else {
$task->log("Deleting empty tag {$tag->name} ({$tag->id})");
$tag->delete();
}
}
$completed++;
$tags->next();
}
$task->percent_complete = $completed / $total * 100;
$task->set("completed", $completed);
$task->set("last_tag_id", $last_tag_id);
}
$task->status = t2("Examined %count tag", "Examined %count tags", $completed);
if ($completed == $total) {
$task->done = true;
$task->state = "success";
$task->percent_complete = 100;
}
} catch (Exception $e) {
Kohana_Log::add("error", (string) $e);
$task->done = true;
$task->state = "error";
$task->status = $e->getMessage();
$errors[] = (string) $e;
}
if ($errors) {
$task->log($errors);
}
}
示例14: status
public function status($success_count, $error_count)
{
if ($error_count) {
// The "errors" won't be properly pluralized :-/
print t2("Uploaded %count photo (%error errors)", "Uploaded %count photos (%error errors)", (int) $success_count, array("error" => (int) $error_count));
} else {
print t2("Uploaded %count photo", "Uploaded %count photos", $success_count);
}
}
示例15: rescan_locale
public function rescan_locale()
{
if ($this->token->validate('rescan_locale')) {
$u = new \User();
if ($u->isSuperUser()) {
\Core::make('cache/request')->disable();
$section = Section::getByID($_REQUEST['locale']);
$target = new MultilingualProcessorTarget($section);
$processor = new Processor($target);
if ($_POST['process']) {
foreach ($processor->receive() as $task) {
$processor->execute($task);
}
$obj = new \stdClass();
$obj->totalItems = $processor->getTotalTasks();
print json_encode($obj);
exit;
} else {
$processor->process();
}
$totalItems = $processor->getTotalTasks();
\View::element('progress_bar', array('totalItems' => $totalItems, 'totalItemsSummary' => t2("%d task", "%d tasks", $totalItems)));
/*
$q = Queue::get('rescan_multilingual_section');
if ($_POST['process']) {
$obj = new \stdClass;
$messages = $q->receive(\Config::get('concrete.limits.copy_pages'));
foreach($messages as $key => $p) {
// delete the page here
$page = unserialize($p->body);
$oc = \Page::getByID($page['cID']);
$q->deleteMessage($p);
}
$obj->totalItems = $q->count();
print json_encode($obj);
if ($q->count() == 0) {
$q->deleteQueue('rescan_multilingual_section');
}
exit;
} else if ($q->count() == 0) {
$oc = Section::getByID($_REQUEST['locale']);
if (is_object($oc) && !$oc->isError()) {
$oc->queueForDeletionRequest($q, false);
}
}
$totalItems = $q->count();
\View::element('progress_bar', array('totalItems' => $totalItems, 'totalItemsSummary' => t2("%d page", "%d pages", $totalItems)));
*/
exit;
}
}
}