本文整理汇总了PHP中generate_page_type_patterns函数的典型用法代码示例。如果您正苦于以下问题:PHP generate_page_type_patterns函数的具体用法?PHP generate_page_type_patterns怎么用?PHP generate_page_type_patterns使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了generate_page_type_patterns函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_block_at_end_of_default_region
public function add_block_at_end_of_default_region($blockname)
{
$defaulregion = $this->get_default_region();
$lastcurrentblock = end($this->birecordsbyregion[$defaulregion]);
if ($lastcurrentblock) {
$weight = $lastcurrentblock->weight + 1;
} else {
$weight = 0;
}
if ($this->page->subpage) {
$subpage = $this->page->subpage;
} else {
$subpage = null;
}
// Special case. Course view page type include the course format, but we
// want to add the block non-format-specifically.
$pagetypepattern = $this->page->pagetype;
if (strpos($pagetypepattern, 'course-view') === 0) {
$pagetypepattern = 'course-view-*';
}
// We should end using this for ALL the blocks, making always the 1st option
// the default one to be used. Until then, this is one hack to avoid the
// 'pagetypewarning' message on blocks initial edition (MDL-27829) caused by
// non-existing $pagetypepattern set. This way at least we guarantee one "valid"
// (the FIRST $pagetypepattern will be set)
// We are applying it to all blocks created in mod pages for now and only if the
// default pagetype is not one of the available options
if (preg_match('/^mod-.*-/', $pagetypepattern)) {
$pagetypelist = generate_page_type_patterns($this->page->pagetype, null, $this->page->context);
// Only go for the first if the pagetype is not a valid option
if (is_array($pagetypelist) && !array_key_exists($pagetypepattern, $pagetypelist)) {
$pagetypepattern = key($pagetypelist);
}
}
// Surely other pages like course-report will need this too, they just are not important
// enough now. This will be decided in the coming days. (MDL-27829, MDL-28150)
$this->add_block($blockname, $defaulregion, $weight, false, $pagetypepattern, $subpage);
}
示例2: process_url_delete
/**
* Handle deleting a block.
* @return boolean true if anything was done. False if not.
*/
public function process_url_delete()
{
global $CFG, $PAGE, $OUTPUT;
$blockid = optional_param('bui_deleteid', null, PARAM_INT);
$confirmdelete = optional_param('bui_confirm', null, PARAM_INT);
if (!$blockid) {
return false;
}
require_sesskey();
$block = $this->page->blocks->find_instance($blockid);
if (!$this->user_can_delete_block($block)) {
throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('deleteablock'));
}
if (!$confirmdelete) {
$deletepage = new moodle_page();
$deletepage->set_pagelayout('admin');
$deletepage->set_course($this->page->course);
$deletepage->set_context($this->page->context);
if ($this->page->cm) {
$deletepage->set_cm($this->page->cm);
}
$deleteurlbase = str_replace($CFG->wwwroot . '/', '/', $this->page->url->out_omit_querystring());
$deleteurlparams = $this->page->url->params();
$deletepage->set_url($deleteurlbase, $deleteurlparams);
$deletepage->set_block_actions_done();
// At this point we are either going to redirect, or display the form, so
// overwrite global $PAGE ready for this. (Formslib refers to it.)
$PAGE = $deletepage;
//some functions like MoodleQuickForm::addHelpButton use $OUTPUT so we need to replace that too
$output = $deletepage->get_renderer('core');
$OUTPUT = $output;
$site = get_site();
$blocktitle = $block->get_title();
$strdeletecheck = get_string('deletecheck', 'block', $blocktitle);
$message = get_string('deleteblockcheck', 'block', $blocktitle);
// If the block is being shown in sub contexts display a warning.
if ($block->instance->showinsubcontexts == 1) {
$parentcontext = context::instance_by_id($block->instance->parentcontextid);
$systemcontext = context_system::instance();
$messagestring = new stdClass();
$messagestring->location = $parentcontext->get_context_name();
// Checking for blocks that may have visibility on the front page and pages added on that.
if ($parentcontext->id != $systemcontext->id && is_inside_frontpage($parentcontext)) {
$messagestring->pagetype = get_string('showonfrontpageandsubs', 'block');
} else {
$pagetypes = generate_page_type_patterns($this->page->pagetype, $parentcontext);
$messagestring->pagetype = $block->instance->pagetypepattern;
if (isset($pagetypes[$block->instance->pagetypepattern])) {
$messagestring->pagetype = $pagetypes[$block->instance->pagetypepattern];
}
}
$message = get_string('deleteblockwarning', 'block', $messagestring);
}
$PAGE->navbar->add($strdeletecheck);
$PAGE->set_title($blocktitle . ': ' . $strdeletecheck);
$PAGE->set_heading($site->fullname);
echo $OUTPUT->header();
$confirmurl = new moodle_url($deletepage->url, array('sesskey' => sesskey(), 'bui_deleteid' => $block->instance->id, 'bui_confirm' => 1));
$cancelurl = new moodle_url($deletepage->url);
$yesbutton = new single_button($confirmurl, get_string('yes'));
$nobutton = new single_button($cancelurl, get_string('no'));
echo $OUTPUT->confirm($message, $yesbutton, $nobutton);
echo $OUTPUT->footer();
// Make sure that nothing else happens after we have displayed this form.
exit;
} else {
blocks_delete_instance($block->instance);
// bui_deleteid and bui_confirm should not be in the PAGE url.
$this->page->ensure_param_not_in_url('bui_deleteid');
$this->page->ensure_param_not_in_url('bui_confirm');
return true;
}
}
示例3: definition
function definition()
{
$mform =& $this->_form;
// First show fields specific to this type of block.
$this->specific_definition($mform);
// Then show the fields about where this block appears.
$mform->addElement('header', 'whereheader', get_string('wherethisblockappears', 'block'));
// If the current weight of the block is out-of-range, add that option in.
$blockweight = $this->block->instance->weight;
$weightoptions = array();
if ($blockweight < -block_manager::MAX_WEIGHT) {
$weightoptions[$blockweight] = $blockweight;
}
for ($i = -block_manager::MAX_WEIGHT; $i <= block_manager::MAX_WEIGHT; $i++) {
$weightoptions[$i] = $i;
}
if ($blockweight > block_manager::MAX_WEIGHT) {
$weightoptions[$blockweight] = $blockweight;
}
$first = reset($weightoptions);
$weightoptions[$first] = get_string('bracketfirst', 'block', $first);
$last = end($weightoptions);
$weightoptions[$last] = get_string('bracketlast', 'block', $last);
$regionoptions = $this->page->theme->get_all_block_regions();
foreach ($this->page->blocks->get_regions() as $region) {
// Make sure to add all custom regions of this particular page too.
if (!isset($regionoptions[$region])) {
$regionoptions[$region] = $region;
}
}
$parentcontext = context::instance_by_id($this->block->instance->parentcontextid);
$mform->addElement('hidden', 'bui_parentcontextid', $parentcontext->id);
$mform->setType('bui_parentcontextid', PARAM_INT);
$mform->addElement('static', 'bui_homecontext', get_string('createdat', 'block'), $parentcontext->get_context_name());
$mform->addHelpButton('bui_homecontext', 'createdat', 'block');
// For pre-calculated (fixed) pagetype lists
$pagetypelist = array();
// parse pagetype patterns
$bits = explode('-', $this->page->pagetype);
// First of all, check if we are editing blocks @ front-page or no and
// make some dark magic if so (MDL-30340) because each page context
// implies one (and only one) harcoded page-type that will be set later
// when processing the form data at {@link block_manager::process_url_edit()}
// There are some conditions to check related to contexts
$ctxconditions = $this->page->context->contextlevel == CONTEXT_COURSE && $this->page->context->instanceid == get_site()->id;
// And also some pagetype conditions
$pageconditions = isset($bits[0]) && isset($bits[1]) && $bits[0] == 'site' && $bits[1] == 'index';
// So now we can be 100% sure if edition is happening at frontpage
$editingatfrontpage = $ctxconditions && $pageconditions;
// Let the form to know about that, can be useful later
$mform->addElement('hidden', 'bui_editingatfrontpage', (int) $editingatfrontpage);
$mform->setType('bui_editingatfrontpage', PARAM_INT);
// Front page, show the page-contexts element and set $pagetypelist to 'any page' (*)
// as unique option. Processign the form will do any change if needed
if ($editingatfrontpage) {
$contextoptions = array();
$contextoptions[BUI_CONTEXTS_FRONTPAGE_ONLY] = get_string('showonfrontpageonly', 'block');
$contextoptions[BUI_CONTEXTS_FRONTPAGE_SUBS] = get_string('showonfrontpageandsubs', 'block');
$contextoptions[BUI_CONTEXTS_ENTIRE_SITE] = get_string('showonentiresite', 'block');
$mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions);
$mform->addHelpButton('bui_contexts', 'contexts', 'block');
$pagetypelist['*'] = '*';
// This is not going to be shown ever, it's an unique option
// Any other system context block, hide the page-contexts element,
// it's always system-wide BUI_CONTEXTS_ENTIRE_SITE
} else {
if ($parentcontext->contextlevel == CONTEXT_SYSTEM) {
$mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_ENTIRE_SITE);
} else {
if ($parentcontext->contextlevel == CONTEXT_COURSE) {
// 0 means display on current context only, not child contexts
// but if course managers select mod-* as pagetype patterns, block system will overwrite this option
// to 1 (display on current context and child contexts)
$mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_CURRENT);
} else {
if ($parentcontext->contextlevel == CONTEXT_MODULE or $parentcontext->contextlevel == CONTEXT_USER) {
// module context doesn't have child contexts, so display in current context only
$mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_CURRENT);
} else {
$parentcontextname = $parentcontext->get_context_name();
$contextoptions[BUI_CONTEXTS_CURRENT] = get_string('showoncontextonly', 'block', $parentcontextname);
$contextoptions[BUI_CONTEXTS_CURRENT_SUBS] = get_string('showoncontextandsubs', 'block', $parentcontextname);
$mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions);
}
}
}
}
$mform->setType('bui_contexts', PARAM_INT);
// Generate pagetype patterns by callbacks if necessary (has not been set specifically)
if (empty($pagetypelist)) {
$pagetypelist = generate_page_type_patterns($this->page->pagetype, $parentcontext, $this->page->context);
$displaypagetypewarning = false;
if (!array_key_exists($this->block->instance->pagetypepattern, $pagetypelist)) {
// Pushing block's existing page type pattern
$pagetypestringname = 'page-' . str_replace('*', 'x', $this->block->instance->pagetypepattern);
if (get_string_manager()->string_exists($pagetypestringname, 'pagetype')) {
$pagetypelist[$this->block->instance->pagetypepattern] = get_string($pagetypestringname, 'pagetype');
} else {
//as a last resort we could put the page type pattern in the select box
//however this causes mod-data-view to be added if the only option available is mod-data-*
//.........这里部分代码省略.........
示例4: definition
function definition()
{
$mform =& $this->_form;
// First show fields specific to this type of block.
$this->specific_definition($mform);
// Then show the fields about where this block appears.
$mform->addElement('header', 'whereheader', get_string('wherethisblockappears', 'block'));
// If the current weight of the block is out-of-range, add that option in.
$blockweight = $this->block->instance->weight;
$weightoptions = array();
if ($blockweight < -block_manager::MAX_WEIGHT) {
$weightoptions[$blockweight] = $blockweight;
}
for ($i = -block_manager::MAX_WEIGHT; $i <= block_manager::MAX_WEIGHT; $i++) {
$weightoptions[$i] = $i;
}
if ($blockweight > block_manager::MAX_WEIGHT) {
$weightoptions[$blockweight] = $blockweight;
}
$first = reset($weightoptions);
$weightoptions[$first] = get_string('bracketfirst', 'block', $first);
$last = end($weightoptions);
$weightoptions[$last] = get_string('bracketlast', 'block', $last);
$regionoptions = $this->page->theme->get_all_block_regions();
$parentcontext = get_context_instance_by_id($this->block->instance->parentcontextid);
$mform->addElement('hidden', 'bui_parentcontextid', $parentcontext->id);
$mform->addElement('static', 'bui_homecontext', get_string('createdat', 'block'), print_context_name($parentcontext));
$mform->addHelpButton('bui_homecontext', 'createdat', 'block');
// parse pagetype patterns
$bits = explode('-', $this->page->pagetype);
$contextoptions = array();
if ($parentcontext->contextlevel == CONTEXT_COURSE && $parentcontext->instanceid == SITEID || $parentcontext->contextlevel == CONTEXT_SYSTEM) {
// Home page
if ($bits[0] == 'tag' || $bits[0] == 'admin') {
// tag and admin pages always use system context
// the contexts options don't make differences, so we use
// page type patterns only
$mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_ENTIRE_SITE);
} else {
$contextoptions[BUI_CONTEXTS_FRONTPAGE_ONLY] = get_string('showonfrontpageonly', 'block');
$contextoptions[BUI_CONTEXTS_FRONTPAGE_SUBS] = get_string('showonfrontpageandsubs', 'block');
$contextoptions[BUI_CONTEXTS_ENTIRE_SITE] = get_string('showonentiresite', 'block');
$mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions);
$mform->addHelpButton('bui_contexts', 'contexts', 'block');
}
} else {
if ($parentcontext->contextlevel == CONTEXT_COURSE) {
// 0 means display on current context only, not child contexts
// but if course managers select mod-* as pagetype patterns, block system will overwrite this option
// to 1 (display on current context and child contexts)
$mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_CURRENT);
} else {
if ($parentcontext->contextlevel == CONTEXT_MODULE or $parentcontext->contextlevel == CONTEXT_USER) {
// module context doesn't have child contexts, so display in current context only
$mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_CURRENT);
} else {
$parentcontextname = print_context_name($parentcontext);
$contextoptions[BUI_CONTEXTS_CURRENT] = get_string('showoncontextonly', 'block', $parentcontextname);
$contextoptions[BUI_CONTEXTS_CURRENT_SUBS] = get_string('showoncontextandsubs', 'block', $parentcontextname);
$mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions);
}
}
}
$displaypagetypewarning = false;
if ($this->page->pagetype == 'site-index') {
// No need for pagetype list on home page
$pagetypelist = array('*' => get_string('page-x', 'pagetype'));
} else {
// Generate pagetype patterns by callbacks
$pagetypelist = generate_page_type_patterns($this->page->pagetype, $parentcontext, $this->page->context);
if (!array_key_exists($this->block->instance->pagetypepattern, $pagetypelist)) {
// Pushing block's existing page type pattern
$pagetypestringname = 'page-' . str_replace('*', 'x', $this->block->instance->pagetypepattern);
if (get_string_manager()->string_exists($pagetypestringname, 'pagetype')) {
$pagetypelist[$this->block->instance->pagetypepattern] = get_string($pagetypestringname, 'pagetype');
} else {
//as a last resort we could put the page type pattern in the select box
//however this causes mod-data-view to be added if the only option available is mod-data-*
// so we are just showing a warning to users about their prev setting being reset
$displaypagetypewarning = true;
}
}
}
// hide page type pattern select box if there is only one choice
if (count($pagetypelist) > 1) {
if ($displaypagetypewarning) {
$mform->addElement('static', 'pagetypewarning', '', get_string('pagetypewarning', 'block'));
}
$mform->addElement('select', 'bui_pagetypepattern', get_string('restrictpagetypes', 'block'), $pagetypelist);
} else {
$value = array_pop(array_keys($pagetypelist));
$mform->addElement('hidden', 'bui_pagetypepattern', $value);
}
if ($this->page->subpage) {
if ($parentcontext->contextlevel == CONTEXT_USER) {
$mform->addElement('hidden', 'bui_subpagepattern', '%@NULL@%');
} else {
$subpageoptions = array('%@NULL@%' => get_string('anypagematchingtheabove', 'block'), $this->page->subpage => get_string('thisspecificpage', 'block', $this->page->subpage));
$mform->addElement('select', 'bui_subpagepattern', get_string('subpages', 'block'), $subpageoptions);
}
//.........这里部分代码省略.........