<commit_before><?php

/**
 * Extension for the DataObject object to add subsites support
 *
 * All objects are visible on main site by default, except if HideOnMainSite is checked
 * Please note this applies to ModelAdmin as well (you need to filter things if you want
 * to display only records in the main site)
 *
 * @author lekoala
 */
class SubsiteDataObject extends DataExtension
{
    private static $_accessible_sites_map_cache = null;
    private static $db = array(
        'HideOnMainSite' => 'Boolean',
    );
    private static $has_one                     = array(
        'Subsite' => 'Subsite',
    );

    function isMainDataObject()
    {
        if ($this->owner->SubsiteID == 0) return true;
        return false;
    }

    function canView($member = null)
    {
        if ($this->canEdit($member)) {
            return true;
        }
    }

    /**
     * Update any requests to limit the results to the current site
     */
    function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null)
    {
        $ctrl = null;
        if (Controller::has_curr()) {
            $ctrl = Controller::curr();
        }

        if (Subsite::$disable_subsite_filter) return;
        if ($dataQuery->getQueryParam('Subsite.filter') === false) return;
        if ($ctrl && get_class(Controller::curr()) == 'Security') return;

        // Don't run on delete queries, since they are always tied to
        // a specific ID.
        if ($query->getDelete()) return;

        // If you're querying by ID, ignore the sub-site - this is a bit ugly...
        // if(!$query->where || (strpos($query->where[0], ".\"ID\" = ") === false && strpos($query->where[0], ".`ID` = ") === false && strpos($query->where[0], ".ID = ") === false && strpos($query->where[0], "ID = ") !== 0)) {
        if (!$query->filtersOnID()) {

            if (Subsite::$force_subsite) $subsiteID = Subsite::$force_subsite;
            else {
                /* if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID;
                  else */$subsiteID = (int) Subsite::currentSubsiteID();
            }

            $froms     = $query->getFrom();
            $froms     = array_keys($froms);
            $tableName = array_shift($froms);

            if ($subsiteID != 0) {
                $query->addWhere("\"$tableName\".\"SubsiteID\" IN ($subsiteID) AND \"$tableName\".\"HideOnMainSite\" = 0");
            }
        }
    }

    function onBeforeWrite()
    {
        if (!$this->owner->ID && !$this->owner->SubsiteID)
                $this->owner->SubsiteID = Subsite::currentSubsiteID();

        parent::onBeforeWrite();
    }

    static function accessible_sites_map($refresh = false)
    {
        if (!$refresh && self::$_accessible_sites_map_cache) {
            return self::$_accessible_sites_map_cache;
        }
        $subsites    = Subsite::accessible_sites("CMS_ACCESS_CMSMain");
        $subsitesMap = array();
        if ($subsites && $subsites->Count()) {<commit_msg>fix hide on main site<commit_after><?php

/**
 * Extension for the DataObject object to add subsites support
 *
 * All objects are visible on main site by default, except if HideOnMainSite is checked
 * Please note this applies to ModelAdmin as well (you need to filter things if you want
 * to display only records in the main site)
 *
 * @author lekoala
 */
class SubsiteDataObject extends DataExtension
{
    private static $_accessible_sites_map_cache = null;
    private static $db = array(
        'HideOnMainSite' => 'Boolean',
    );
    private static $has_one                     = array(
        'Subsite' => 'Subsite',
    );

    function isMainDataObject()
    {
        if ($this->owner->SubsiteID == 0) return true;
        return false;
    }

    function canView($member = null)
    {
        if ($this->canEdit($member)) {
            return true;
        }
    }

    /**
     * Update any requests to limit the results to the current site
     */
    function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null)
    {
        $ctrl = null;
        if (Controller::has_curr()) {
            $ctrl = Controller::curr();
        }

        if (Subsite::$disable_subsite_filter) return;
        if ($dataQuery->getQueryParam('Subsite.filter') === false) return;
        if ($ctrl && get_class(Controller::curr()) == 'Security') return;

        // Don't run on delete queries, since they are always tied to
        // a specific ID.
        if ($query->getDelete()) return;

        // If you're querying by ID, ignore the sub-site - this is a bit ugly...
        // if(!$query->where || (strpos($query->where[0], ".\"ID\" = ") === false && strpos($query->where[0], ".`ID` = ") === false && strpos($query->where[0], ".ID = ") === false && strpos($query->where[0], "ID = ") !== 0)) {
        if (!$query->filtersOnID()) {

            if (Subsite::$force_subsite) $subsiteID = Subsite::$force_subsite;
            else {
                /* if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID;
                  else */$subsiteID = (int) Subsite::currentSubsiteID();
            }

            $froms     = $query->getFrom();
            $froms     = array_keys($froms);
            $tableName = array_shift($froms);

            if ($subsiteID != 0) {
                $query->addWhere("\"$tableName\".\"SubsiteID\" IN ($subsiteID)");
            }
            else {
                $query->addWhere("\"$tableName\".\"HideOnMainSite\" = 0");
            }
        }
    }

    function onBeforeWrite()
    {
        if (!$this->owner->ID && !$this->owner->SubsiteID)
                $this->owner->SubsiteID = Subsite::currentSubsiteID();

        parent::onBeforeWrite();
    }

    static function accessible_sites_map($refresh = false)
    {
        if (!$refresh && self::$_accessible_sites_map_cache) {
            return self::$_accessible_sites_map_cache;
        }
        $subsites    = Subsite::accessible_sites("CMS_ACCESS_CMSMain");
        $subsitesMap = array();
        if ($subsites && $subsites->Count()) {
{'fraction_non_alphanumeric': 0.15019762845849802, 'fraction_numerical': 0.002635046113306983, 'mean_word_length': 2.2475935828877005, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 50, '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': '2329458', 'n_tokens_mistral': 1804, 'n_tokens_neox': 1735, 'n_words': 440}