/*
rule_match_page_template

@description:
@since: 3.5.7
@created: 3/01/13
429628
function rule_match_page_template( $match, $rule, $options )
	{
		$page_template = $options['page_template'];
		if( ! $page_template )
		{
			$page_template = get_post_meta( $options['post_id'], '_wp_page_template', true );
		}
		
		
		if( ! $page_template )
		{
			$post_type = $options['post_type'];

			if( !$post_type )
			{
				$post_type = get_post_type( $options['post_id'] );
			}
			
			if( $post_type == 'page' )
			{
				$page_template = "default";
			}
		}
		
		
		
        if($rule['operator'] == "==")
        {
        	$match = ( $page_template === $rule['value'] );
        }
        elseif($rule['operator'] == "!=")
        {
        	$match = ( $page_template !== $rule['value'] );
        }
                
        return $match;

	}
1229571
private static boolean isPageInTemplateDefinition(Page page) {
    Resource resource = page.adaptTo(Resource.class);
    if (resource != null) {
      Resource parent = resource.getParent();
      if (parent != null) {
        return StringUtils.equals(NT_TEMPLATE, parent.getValueMap().get(JCR_PRIMARYTYPE, String.class));
      }
    }
    return false;
  }
953103
private boolean loadMatchRulesFromFile(String rulesUrl) {
	//load match rules from a local file
	try {
	    mCallbacks.printOutput("Loading match rules from file: " + rulesUrl);
            InputStream in = new URL(rulesUrl).openStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));

            processMatchRules(reader);
            
            return true;

	} catch (IOException e) {
	    scan.printStackTrace(e);
	} catch (NumberFormatException e) {
	    scan.printStackTrace(e);
	}
        
        return false;
    }
342864
def page_not_found(request, template_name="errors/404.html"):
    
    context = {
        "STATIC_URL": settings.STATIC_URL,
        "request_path": request.path,
    }
    t = get_template(template_name)
    return HttpResponseNotFound(t.render(context, request))
1315367
function(route, rule) {
            if (rule == null) rule = "base";
            if (_.isString(rule)) rule = Urls[rule];
            route = rule(route);
            window.location.href = route;
        }
480018
private static boolean matchWildCards(String name, String template) {
        int wildcardIndex = template.indexOf("*");
        if (wildcardIndex == -1) {
            return name.equals(template);
        }

        boolean isBeginning = true;
        String beforeWildcard;
        String afterWildcard = template;
        while (wildcardIndex != -1) {
            beforeWildcard = afterWildcard.substring(0, wildcardIndex);
            afterWildcard = afterWildcard.substring(wildcardIndex + 1);

            int beforeStartIndex = name.indexOf(beforeWildcard);
            if ((beforeStartIndex == -1) || (isBeginning && beforeStartIndex != 0)) {
                return false;
            }
            isBeginning = false;

            name = name.substring(beforeStartIndex + beforeWildcard.length());
            wildcardIndex = afterWildcard.indexOf("*");
        }

        return name.endsWith(afterWildcard);
    }
1185285
function (pageNum) {
            var textPath = util.template(config.template.html, { page: pageNum });
            return config.url + textPath + config.queryString;
        }
759391
def get_templates_per_page(self, per_page=1000, page=1, params=None):
        
        return self._get_resource_per_page(resource=TEMPLATES, per_page=per_page, page=page, params=params)
993436
function findPageForPath (pages, path) {
  for (let i = 0; i < pages.length; i++) {
    const page = pages[i]
    if (page.path.toLowerCase() === path.toLowerCase()) {
      return page
    }
  }
  return {
    path: '',
    frontmatter: {}
  }
}
1296650
def match_pagination(ref_line):
    """"""
    pattern = ur'\(?\[?(\d{1,4})\]?\)?\.?\s*$'
    re_footer = re.compile(pattern, re.UNICODE)
    match = re_footer.match(ref_line)
    if match:
        return int(match.group(1))
    return None
622904
function createTemplateMatcher (fields) {
  var length = fields.length
  var pattern = fields.reduce(function (pattern, field, i) {
    if (i === 0) {
      pattern = '^'
    }
    if (field.prefix) {
      pattern += '(' + escapeRegExp(field.prefix) + ')'
    }
    if (field.placeholder) {
      switch (field.placeholder) {
        case 'hash':
        case 'chunkhash':
          pattern += '[0-9a-fA-F]'
          pattern += field.width ? '{1,' + field.width + '}' : '+'
          break
        case 'id':
        case 'name':
        case 'file':
        case 'filebase':
          pattern += '.+?'
          break
        case 'query':
          pattern += '(?:\\?.+?)?'
          break
      }
    }
    if (i === length - 1) {
      pattern += '$'
    }

    return pattern
  }, '')

  return new RegExp(pattern)
}
894421
function (line, block) {
    if (!block.template) {
        return;
    }

    var regex = getRegExp(block.template);
    var match = regex.exec(line);
    return match ? match[1] : match;
}
1030501
public static boolean is(@NotNull Page page, @NotNull String @NotNull... templatePaths) {
    if (page == null || templatePaths == null || templatePaths.length == 0) {
      return false;
    }
    String templatePath = page.getProperties().get(NameConstants.PN_TEMPLATE, String.class);
    for (String givenTemplatePath : templatePaths) {
      if (StringUtils.equals(templatePath, givenTemplatePath)) {
        return true;
      }
    }
    return false;
  }
1073934
def page_or_find(page)
      if page.is_a?(String)
        page = Language.current.pages.find_by(page_layout: page)
      end
      if page.blank?
        warning("No Page found for #{page.inspect}")
        return
      else
        page
      end
    end
500179
function isMatchRule(req, pathname, rule) {
  if (typeof rule === 'string') {
    return pathname.indexOf(rule) > -1;
  } else if (rule instanceof RegExp) {
    return rule.test(pathname);
  } else if (typeof rule === 'function') {
    return rule(pathname, req);
  }
}
654621
function rule_match_page_type( $match, $rule, $options )
	{
		// validation
		if( !$options['post_id'] )
		{
			return false;
		}

		$post = get_post( $options['post_id'] );
		        
        if( $rule['value'] == 'front_page')
        {
        	
	        $front_page = (int) get_option('page_on_front');
	        
	        
	        if($rule['operator'] == "==")
	        {
	        	$match = ( $front_page == $post->ID );
	        }
	        elseif($rule['operator'] == "!=")
	        {
	        	$match = ( $front_page != $post->ID );
	        }
	        
        }
        elseif( $rule['value'] == 'posts_page')
        {
        
	        $posts_page = (int) get_option('page_for_posts');
	        
	        
	        if($rule['operator'] == "==")
	        {
	        	$match = ( $posts_page == $post->ID );
	        }
	        elseif($rule['operator'] == "!=")
	        {
	        	$match = ( $posts_page != $post->ID );
	        }
	        
        }
        elseif( $rule['value'] == 'top_level')
        {
        	$post_parent = $post->post_parent;
        	if( $options['page_parent'] )
        	{
	        	$post_parent = $options['page_parent'];
        	}
        	
        	
	        if($rule['operator'] == "==")
	        {
	        	$match = ( $post_parent == 0 );
	        }
	        elseif($rule['operator'] == "!=")
	        {
	        	$match = ( $post_parent != 0 );
	        }
	        
        }
        elseif( $rule['value'] == 'parent')
        {
        
        	$children = get_pages(array(
        		'post_type' => $post->post_type,
        		'child_of' =>  $post->ID,
        	));
        	
	        
	        if($rule['operator'] == "==")
	        {
	        	$match = ( count($children) > 0 );
	        }
	        elseif($rule['operator'] == "!=")
	        {
	        	$match = ( count($children) == 0 );
	        }
	        
        }
        elseif( $rule['value'] == 'child')
        {
        
        	$post_parent = $post->post_parent;
        	if( $options['page_parent'] )
        	{
	        	$post_parent = $options['page_parent'];
        	}
	        
	        
	        if($rule['operator'] == "==")
	        {
	        	$match = ( $post_parent != 0 );
	        }
	        elseif($rule['operator'] == "!=")
	        {
	        	$match = ( $post_parent == 0 );
	        }
	        
        }
        
        return $match;

	}
690266
public function errorpage($page){
		$device=BBrowserUseragent::detectDevice();
		if($device==DEVICE_TYPE_MPHONE){
			$suffix='.m';
			}
		elseif($device==DEVICE_TYPE_TABLET){
			$suffix='.m';
			}
		else{
			$suffix='.d';
			}
		if(empty($this->templatename)){
			$this->templatename='default';
			}
		$fn=BTEMPLATESPATH.$this->templatename.DIRECTORY_SEPARATOR.'#error_'.$page.$suffix.'.php';
		if(!file_exists($fn)){
			$fn=BTEMPLATESPATH.$this->templatename.DIRECTORY_SEPARATOR.'#error_'.$page.'.d.php';
			}
		if((!file_exists($fn))&&($this->templatename!='default')){
			$fn=BTEMPLATESPATH.'default'.DIRECTORY_SEPARATOR.'#error_'.$page.$suffix.'.php';
			}
		if((!file_exists($fn))&&($this->templatename!='default')){
			$fn=BTEMPLATESPATH.'default'.DIRECTORY_SEPARATOR.'#error_'.$page.'.d.php';
			}
		//Outputing the template
		if(file_exists($fn)){
			include($fn);
			}else{
			echo('<h1>404</h1>');
			}
		if(!empty($this->htmllogger)){
			BLog::addToLog('[Router]: 404 page.',LL_ERROR);
			$this->htmllogger->print_html();
			}
		return false;
		}