<commit_before><?php

// Page access controller library

//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
  header("Location: ../index.php");
  die;
}


class TikiAccessLib extends TikiLib {

    function TikiAccessLib() {
    }

    // check that the user is admin or has admin permissions
    function check_admin($user,$feature_name="") {
        global $smarty, $tiki_p_admin;
        require_once ('tiki-setup.php');
        // first check that user is logged in
        $this->check_user($user);
        if (($user != 'admin') && ($tiki_p_admin != 'y')) {
            $msg = tra("You do not have permission to use this feature");
            if ($feature_name) {
                $msg = $msg . ": " . $feature_name;
            }
            $smarty->assign('msg', $msg);
            $smarty->display("error.tpl");
            die;
        }
    }

    function check_user($user) {
        global $smarty, $feature_usability;
        require_once ('tiki-setup.php');
        if (!$user) {
            $title = tra("You are not logged in");
            if (isset( $feature_usability ) && $feature_usability == 'y' ) {
                $this->display_error('',$title,'402');
            } else {
                $smarty->assign('msg', $title);
                $smarty->display("error.tpl");
            }
            die;
        }
    }

    function check_page($user='y', $features=array(), $permissions=array(), $permission_name='') {
        global $smarty;
        require_once ('tiki-setup.php');
        if( $features ) {
            $this->check_feature($features);
        }
        $this->check_user($user);
        if( $permissions ) {
            $this->check_permission($permissions, $permission_name);
        }
    }

    function check_feature($features, $feature_name="") {
        global $smarty;
        require_once ('tiki-setup.php');
	if ( ! is_array($features) ) { $features = array($features); }
        foreach ($features as $feature) {
            global $$feature;
            if ($$feature != 'y') {
                if ($feature_name == '') { $feature_name = $feature; }
                $smarty->assign('msg', tra("This feature is disabled").": ". $feature_name);
                $smarty->display("error.tpl");
                die;
            }
        }
    }

    function check_permission($permissions, $permission_name='') {
        global $smarty;
        require_once ('tiki-setup.php');
        if ( ! is_array($permissions) ) { $permissions = array($permissions); }
        foreach ($permissions as $permission) {
            global $$permission;
            if ($$permission != 'y') {
                if (!$permission_name) { $permission_name = $permission; }
                $smarty->assign('msg', tra("You do not have permission to use this feature").": ". $permission_name);
                $smarty->display("error.tpl");
                die;
            }
        }
    }

    // check permission, where the permission is normally unset
    function check_permission_unset($permissions, $permission_name) {
        global $smarty;
        require_once ('tiki-setup.php');
        foreach ($permissions as $permission) {
            global $$permission;
            if ((isset($$permission) && $$permission == 'n')) {
                $smarty->assign('msg', tra("Permission denied").": ". $permission_name);
                $smarty->display("error.tpl");
                die;
            }
        }
    }

    // check page exists
   function check_page_exists($page) {
        global $smarty;                 
        require_once ('tiki-setup.php');
        if (!$tikilib->page_exists($page)) {
            $smarty->assign('msg', tra("Page cannot be found"));

            $smarty->display("error.tpl");
            die;
        }
    }

    /**
     *  Check whether script was called directly or included
     *  err and die if called directly
     *  Typical usage: $access->check_script($_SERVER["SCRIPT_NAME"],basename(__FILE__));
     */
    function check_script($scriptname, $page) {
      global $smarty, $feature_usability;
      if (strpos($scriptname,$page) !== FALSE) {
        if( !isset($feature_usability) || $feature_usability == 'n' ) {
          $msg = tra("This script cannot be called directly");                
          $this->display_error($page, $msg);
        } else { 
          $msg = tra("Page") . " '".$page."' ".tra("cannot be found");
          $this->display_error($page, $msg, "404");
        }
      }
    }

    // you must call ask_ticket('error') before calling this
    function display_error($page, $errortitle="", $errortype="") {
        global $smarty, $wikilib;
        require_once ('tiki-setup.php');
        include_once('lib/wiki/wikilib.php');
        if ( !isset($errortitle) ) {
            $errortitle = tra('unknown error');
        }
        // Display the template
        $smarty->assign('msg', $errortitle);<commit_msg>When calling a not to be called directly script, if feature_redirect_on_error is active, then redirect to the Tiki HomePage as per Admin->General.<commit_after><?php

// Page access controller library

//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
  header("Location: ../index.php");
  die;
}


class TikiAccessLib extends TikiLib {

    function TikiAccessLib() {
    }

    // check that the user is admin or has admin permissions
    function check_admin($user,$feature_name="") {
        global $smarty, $tiki_p_admin;
        require_once ('tiki-setup.php');
        // first check that user is logged in
        $this->check_user($user);
        if (($user != 'admin') && ($tiki_p_admin != 'y')) {
            $msg = tra("You do not have permission to use this feature");
            if ($feature_name) {
                $msg = $msg . ": " . $feature_name;
            }
            $smarty->assign('msg', $msg);
            $smarty->display("error.tpl");
            die;
        }
    }

    function check_user($user) {
        global $smarty, $feature_usability;
        require_once ('tiki-setup.php');
        if (!$user) {
            $title = tra("You are not logged in");
            if (isset( $feature_usability ) && $feature_usability == 'y' ) {
                $this->display_error('',$title,'402');
            } else {
                $smarty->assign('msg', $title);
                $smarty->display("error.tpl");
            }
            die;
        }
    }

    function check_page($user='y', $features=array(), $permissions=array(), $permission_name='') {
        global $smarty;
        require_once ('tiki-setup.php');
        if( $features ) {
            $this->check_feature($features);
        }
        $this->check_user($user);
        if( $permissions ) {
            $this->check_permission($permissions, $permission_name);
        }
    }

    function check_feature($features, $feature_name="") {
        global $smarty;
        require_once ('tiki-setup.php');
	if ( ! is_array($features) ) { $features = array($features); }
        foreach ($features as $feature) {
            global $$feature;
            if ($$feature != 'y') {
                if ($feature_name == '') { $feature_name = $feature; }
                $smarty->assign('msg', tra("This feature is disabled").": ". $feature_name);
                $smarty->display("error.tpl");
                die;
            }
        }
    }

    function check_permission($permissions, $permission_name='') {
        global $smarty;
        require_once ('tiki-setup.php');
        if ( ! is_array($permissions) ) { $permissions = array($permissions); }
        foreach ($permissions as $permission) {
            global $$permission;
            if ($$permission != 'y') {
                if (!$permission_name) { $permission_name = $permission; }
                $smarty->assign('msg', tra("You do not have permission to use this feature").": ". $permission_name);
                $smarty->display("error.tpl");
                die;
            }
        }
    }

    // check permission, where the permission is normally unset
    function check_permission_unset($permissions, $permission_name) {
        global $smarty;
        require_once ('tiki-setup.php');
        foreach ($permissions as $permission) {
            global $$permission;
            if ((isset($$permission) && $$permission == 'n')) {
                $smarty->assign('msg', tra("Permission denied").": ". $permission_name);
                $smarty->display("error.tpl");
                die;
            }
        }
    }

    // check page exists
   function check_page_exists($page) {
        global $smarty;                 
        require_once ('tiki-setup.php');
        if (!$tikilib->page_exists($page)) {
            $smarty->assign('msg', tra("Page cannot be found"));

            $smarty->display("error.tpl");
            die;
        }
    }

    /**
     *  Check whether script was called directly or included
     *  err and die if called directly
     *  Typical usage: $access->check_script($_SERVER["SCRIPT_NAME"],basename(__FILE__));
     * 
     *  if feature_redirect_on_error is active, then just goto the Tiki HomePage as configured
     *  in Admin->General. -- Damian
     * 
     */
    function check_script($scriptname, $page) {
      global $smarty, $feature_usability, $feature_redirect_on_error, $tikiIndex;
      if (strpos($scriptname,$page) !== FALSE) {
      	if ($feature_redirect_on_error == 'y') {
      		header ("location: $tikiIndex");
      		die;
      	} else {
        if( !isset($feature_usability) || $feature_usability == 'n' ) {
          $msg = tra("This script cannot be called directly");                
          $this->display_error($page, $msg);
        } else { 
          $msg = tra("Page") . " '".$page."' ".tra("cannot be found");
          $this->display_error($page, $msg, "404");
        }
      	}
      }
    }

    // you must call ask_ticket('error') before calling this
    function display_error($page, $errortitle="", $errortype="") {
        global $smarty, $wikilib;
        require_once ('tiki-setup.php');
        include_once('lib/wiki/wikilib.php');
        if ( !isset($errortitle) ) {
            $errortitle = tra('unknown error');
        }
        // Display the template
        $smarty->assign('msg', $errortitle);
{'fraction_non_alphanumeric': 0.15048636276940683, 'fraction_numerical': 0.0011443829868395957, 'mean_word_length': 2.046775130737943, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5870578', 'n_tokens_mistral': 3015, 'n_tokens_neox': 2962, 'n_words': 683}