Executed for single-blog sites
@internal
776396
protected function init_as_singlesite() {
		$this->admin_email = get_bloginfo('admin_email');
		$this->name = get_bloginfo('name');
		$this->title = $this->name;
		$this->description = get_bloginfo('description');
		$this->theme = new Theme();
		$this->multisite = false;
	}
171936
public function run()
    {
        $writer = $this->app->make(SitemapWriter::class);
        if (method_exists($this, 'canIncludePageInSitemap')) {
            // Add support for deprecated custom canIncludePageInSitemap
            $pageListGenerator = $this->app->make(DeprecatedPageListGenerator::class);
            $pageListGenerator->setDeprecatedChecker(function ($page, $instances) {
                return $this->canIncludePageInSitemap($page, $instances);
            });
            $writer->getSitemapGenerator()->setPageListGenerator($pageListGenerator);
        }
        $generator = $writer->getSitemapGenerator();
        if ($generator->getSiteCanonicalUrl() === '') {
            $request = $this->app->make(Request::class);
            if (!$request->getHost()) {
                throw new UserMessageException(t('Canonical URL is not set and there is no HTTP request to retrieve the site URL from.'));
            }
            $generator->setCustomSiteCanonicalUrl($request->getSchemeAndHttpHost());
        }
        $numPages = 0;
        $writer->generate(function (SitemapElement $data) use (&$numPages) {
            if ($data instanceof SitemapPage) {
                ++$numPages;
            }
        });
        $sitemapUrl = $writer->getSitemapUrl();
        if ($sitemapUrl === '') {
            $openLink = '';
        } else {
            $openLink = sprintf('<a href="%s" target="_blank">', h($sitemapUrl));
        }

        return t2(
            /*i18n: %2$s and %3$s contains HTML markup, %1$d is the number of pages */
            'The %2$ssitemap%3$s has been generated (%1$d page)',
            'The %2$ssitemap%3$s has been generated (%1$d pages)',
            $numPages,
            $openLink,
            $openLink === '' ? '' : '</a>'
        );
    }
432499
static function instance( $id, $secondary_id, $network_level_or_blog_id = false ) {
            $key = $id . ':' . $secondary_id;

            if ( is_multisite() ) {
                if ( true === $network_level_or_blog_id ) {
                    $key .= ':ms';
                } else if ( is_numeric( $network_level_or_blog_id ) && $network_level_or_blog_id > 0 ) {
                    $key .= ":{$network_level_or_blog_id}";
                } else {
                    $network_level_or_blog_id = get_current_blog_id();

                    $key .= ":{$network_level_or_blog_id}";
                }
            }

			if ( ! isset( self::$_instances[ $key ] ) ) {
				self::$_instances[ $key ] = new FS_Key_Value_Storage( $id, $secondary_id, $network_level_or_blog_id );
			}

			return self::$_instances[ $key ];
		}
1242340
function _delete_site( $store = true, $blog_id = null ) {
            return self::_delete_site_by_slug( $this->_slug, $this->_module_type, $store, $blog_id );
        }
988325
def index():
    """"""
    posts = Post.query.order_by(Post.created.desc()).all()
    return render_template("blog/index.html", posts=posts)
534942
public function index() {
        
        $tree = Globals::getTree();
        Theme::theme(new AdministrationTheme)->init($tree);
        $controller = new PageController();
        $controller
            ->restrictAccess(Auth::isAdmin())
            ->setPageTitle($this->module->getTitle());
			
		$token = $this->module->getSetting('MAJ_AT_FORCE_EXEC_TOKEN');
		if(is_null($token)) {
			$token = Functions::generateRandomToken();
			$this->module->setSetting('PAT_FORCE_EXEC_TOKEN', $token);
		}
        
        $data = new ViewBag();
        $data->set('title', $controller->getPageTitle());
        
        $table_id = 'table-admintasks-' . Uuid::uuid4();
        $data->set('table_id', $table_id);
		
		$data->set('trigger_url_root', WT_BASE_URL.'module.php?mod='.$this->module->getName().'&mod_action=Task@trigger');
		$token = $this->module->getSetting('MAJ_AT_FORCE_EXEC_TOKEN');
		if(is_null($token)) {
			$token = Functions::generateRandomToken();
			$this->module->setSetting('MAJ_AT_FORCE_EXEC_TOKEN', $token);
		}
		$data->set('trigger_token', $token);
		
		$this->provider->getInstalledTasks();
		
		$controller
            ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)
            ->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL)
            ->addInlineJavascript('
                //Datatable initialisation
				jQuery.fn.dataTableExt.oSort["unicode-asc"  ]=function(a,b) {return a.replace(/<[^<]*>/, "").localeCompare(b.replace(/<[^<]*>/, ""))};
				jQuery.fn.dataTableExt.oSort["unicode-desc" ]=function(a,b) {return b.replace(/<[^<]*>/, "").localeCompare(a.replace(/<[^<]*>/, ""))};
				jQuery.fn.dataTableExt.oSort["num-html-asc" ]=function(a,b) {a=parseFloat(a.replace(/<[^<]*>/, "")); b=parseFloat(b.replace(/<[^<]*>/, "")); return (a<b) ? -1 : (a>b ? 1 : 0);};
				jQuery.fn.dataTableExt.oSort["num-html-desc"]=function(a,b) {a=parseFloat(a.replace(/<[^<]*>/, "")); b=parseFloat(b.replace(/<[^<]*>/, "")); return (a>b) ? -1 : (a<b ? 1 : 0);};
	
				var adminTasksTable = jQuery("#'.$table_id.'").DataTable({
					'.I18N::datatablesI18N().',			
					sorting: [[3, "asc"]],
					pageLength: 10,
                    processing: true,
                    serverSide : true,
					ajax : {
						url : "module.php?mod='.$this->module->getName().'&mod_action=AdminConfig@jsonTasksList&ged='. $tree->getNameUrl().'",
                        type : "POST"
					},
                    columns: [
						/* 0 Edit		 	*/ { sortable: false, className: "text-center"},
                        /* 1 task_name      */ { visible: false },
						/* 2 Enabled 		*/ { sortable: false, className: "text-center"  },
						/* 3 Task Title		*/ null,
						/* 4 Last Run		*/ null,
						/* 5 Last status 	*/ { className: "text-center" },
						/* 6 Frequency      */ { sortable: false, className: "text-center" },
						/* 7 Nb Occcurrences*/ { sortable: false, className: "text-center" },
						/* 8 Is Running    	*/ { sortable: false, className: "text-center" },					
						/* 9 Run task		*/ { sortable: false, className: "text-center" }
					],
				});
                
                ')
                ->addInlineJavascript('					
					function generate_force_token() {
						jQuery("#bt_genforcetoken").attr("disabled", "disabled");
						jQuery("#bt_tokentext").empty().html("<i class=\"fa fa-spinner fa-pulse fa-fw\"></i>");
						jQuery("#token_url").load(
							"module.php?mod='.$this->module->getName().'&mod_action=AdminConfig@generateToken",
							function() {
								jQuery("#bt_genforcetoken").removeAttr("disabled");
								jQuery("#bt_tokentext").empty().html("'.I18N::translate('Regenerate token').'");
                                adminTasksTable.ajax.reload();
							}
						);
					}
				
                    function set_admintask_status(task, status) {
                		jQuery.ajax({
                            url: "module.php", 
                            type: "GET",
                            data: {
                			    mod: "' . $this->module->getName() .'",
                                mod_action:  "Task@setStatus",
                			    task: task,
                                status: status
                            },
                            error: function(result, stat, error) {
                                var err = typeof result.responseJSON === "undefined" ? error : result.responseJSON.error;
                                alert("' . I18N::translate('An error occured while editing this task:') . '" + err);
                            },
                            complete: function(result, stat) {
                                adminTasksTable.ajax.reload(null, false);
                            }                            
                		});
                    } 
                    
                    function run_admintask(taskname) {
                        jQuery("#bt_runtask_" + taskname).attr("disabled", "disabled");
				        jQuery("#bt_runtasktext_" + taskname).empty().html("<i class=\"fa fa-cog fa-spin fa-fw\"></i><span class=\"sr-only\">'.I18N::translate('Running').'</span>");
				        jQuery("#bt_runtasktext_" + taskname).load(
					       "module.php?mod='.$this->module->getName().'&mod_action=Task@trigger&force='.$token.'&task=" + taskname,
        					function() {
        						jQuery("#bt_runtasktext_" + taskname).empty().html("<i class=\"fa fa-check\"></i>'.I18N::translate('Done').'");
        						adminTasksTable.ajax.reload();
        					}
				        );
                    
                    } 
                ');
        
        ViewFactory::make('AdminConfig', $this, $controller, $data)->render();
    }
739838
public function index()
    {
        //  If already logged out just send them silently on their way
        if (!isLoggedIn()) {
            redirect('/');
        }

        // --------------------------------------------------------------------------

        //  Generate an event for this log in
        create_event('did_log_out');

        // --------------------------------------------------------------------------

        //  Log social media out
        $oSocial = Factory::service('SocialSignOn', 'nails/module-auth');
        $oSocial->logout();

        // --------------------------------------------------------------------------

        //  Log user out
        $oAuthModel = Factory::model('Auth', 'nails/module-auth');
        $oAuthModel->logout();

        // --------------------------------------------------------------------------

        redirect();
    }
773661
public function index()
    {
        //  Page data
        $this->data['page']->title = 'Blog &rsaquo; Tags';

        // --------------------------------------------------------------------------

        $data                  = array();
        $data['include_count'] = true;
        $data['where']         = array();
        $data['where'][]       = array('column' => 'blog_id', 'value' => $this->blog->id);

        $this->data['tags'] = $this->blog_tag_model->getAll(null, null, $data);

        // --------------------------------------------------------------------------

        Helper::loadView('index');
    }
1093913
public static function bootstrap() {
        global $PAGE;

        if (!isloggedin() || isguestuser()) {
            return;
        }

        if (in_array($PAGE->pagelayout, ['maintenance', 'print', 'redirect'])) {
            // Do not try to show user tours inside iframe, in maintenance mode,
            // when printing, or during redirects.
            return;
        }

        if (self::$bootstrapped) {
            return;
        }
        self::$bootstrapped = true;

        if ($tour = manager::get_current_tour()) {
            $PAGE->requires->js_call_amd('tool_usertours/usertours', 'init', [
                    $tour->get_id(),
                    $tour->should_show_for_user(),
                    $PAGE->context->id,
                ]);
        }
    }
874127
public function execute() {
        global $CFG;

        // Run stats as at the end because they are known to take very long time on large sites.
        if (!empty($CFG->enablestats) and empty($CFG->disablestatsprocessing)) {
            require_once($CFG->dirroot.'/lib/statslib.php');
            // Process configured number of days as max (defaulting to 31).
            $maxdays = empty($CFG->statsruntimedays) ? 31 : abs($CFG->statsruntimedays);
            if (stats_cron_daily($maxdays)) {
                if (stats_cron_weekly()) {
                    if (stats_cron_monthly()) {
                        stats_clean_old();
                    }
                }
            }
            \core_php_time_limit::raise();
        }
    }
1354570
protected function execute()
    {
        $ips = $this->user->posts()->whereNotNull('ip_address')->lists('ip_address');

        $this->report['locations'] = "Ip's used: ".count($ips);
        $this->report['related'] = [];

        User::whereHas('posts', function ($q) use ($ips) {
            $q->whereIn('ip_address', $ips);
        })
            ->where('id', '!=', $this->user->id)
            ->chunk(10, function ($users) {
                foreach ($users as $user) {
                    $this->report['related'][] = $user->toJson();
                }
            });
    }
163465
public function edit()
    {
        if (!userHasPermission('admin:blog:tag:' . $this->blog->id . ':edit')) {

            unauthorised();
        }

        // --------------------------------------------------------------------------

        $this->data['tag'] = $this->blog_tag_model->getById($this->uri->segment(6));

        if (empty($this->data['tag'])) {

            show404();
        }

        // --------------------------------------------------------------------------

        if ($this->input->post()) {

            $oFormValidation = Factory::service('FormValidation');

            $oFormValidation->set_rules('label', '', 'required');
            $oFormValidation->set_rules('description', '', '');
            $oFormValidation->set_rules('seo_title', '', 'max_length[150]');
            $oFormValidation->set_rules('seo_description', '', 'max_length[300]');
            $oFormValidation->set_rules('seo_keywords', '', 'max_length[150]');

            $oFormValidation->set_message('required', lang('fv_required'));
            $oFormValidation->set_message('max_length', lang('fv_max_length'));

            if ($oFormValidation->run()) {

                $aUpdateData                    = array();
                $aUpdateData['label']           = $this->input->post('label');
                $aUpdateData['description']     = $this->input->post('description');
                $aUpdateData['seo_title']       = $this->input->post('seo_title');
                $aUpdateData['seo_description'] = $this->input->post('seo_description');
                $aUpdateData['seo_keywords']    = $this->input->post('seo_keywords');

                if ($this->blog_tag_model->update($this->data['tag']->id, $aUpdateData)) {

                    $this->session->set_flashdata('success', 'Tag saved successfully.');
                    redirect('admin/blog/tag/index/' . $this->blog->id . $this->isModal);

                } else {

                    $this->data['error']  = 'There was a problem saving the Tag. ';
                    $this->data['error'] .= $this->blog_tag_model->lastError();
                }

            } else {

                $this->data['error'] = lang('fv_there_were_errors');
            }
        }

        // --------------------------------------------------------------------------

        //  Page data
        $this->data['page']->title = 'Blog &rsaquo; Catrgories &rsaquo; Edit &rsaquo; ' . $this->data['tag']->label;

        // --------------------------------------------------------------------------

        //  Fetch data
        $this->data['tags'] = $this->blog_tag_model->getAll();

        // --------------------------------------------------------------------------

        //  Load views
        Helper::loadView('edit');
    }
1358954
private function _store_site( $store = true, $network_level_or_blog_id = null, FS_Site $site = null ) {
            $this->_logger->entrance();

            if ( empty( $this->_site->id ) ) {
                $this->_logger->error( "Empty install ID, can't store site." );

                return;
            }

            $site_clone     = is_object( $site ) ? $site : $this->_site;
            $encrypted_site = clone $site_clone;

            $sites = self::get_all_sites( $this->_module_type, $network_level_or_blog_id );

            $prev_stored_user_id = $this->_storage->get( 'prev_user_id', false, $network_level_or_blog_id );

            if ( empty( $prev_stored_user_id ) &&
                 $this->_user->id != $this->_site->user_id
            ) {
                /**
                 * Store the current user ID as the previous user ID so that the previous user can be used
                 * as the install's owner while the new owner's details are not yet available.
                 *
                 * This will be executed only in the `replica` site. For example, there are 2 sites, namely `original`
                 * and `replica`, then an ownership change was initiated and completed in the `original`, the `replica`
                 * will be using the previous user until it is updated again (e.g.: until the next clone of `original`
                 * into `replica`.
                 *
                 * @author Leo Fajardo (@leorw)
                 */
                $this->_storage->store( 'prev_user_id', $sites[ $this->_slug ]->user_id, $network_level_or_blog_id );
            }

            $sites[ $this->_slug ] = $encrypted_site;

            $this->set_account_option( 'sites', $sites, $store, $network_level_or_blog_id );
        }
1091201
protected function applySiteConditions()
    {
        if ($this->site !== null) {
            $this->andWhere(Db::parseParam('siteId', $this->parseSiteValue($this->site)));
        } else {
            $this->andWhere(Db::parseParam('siteId', Craft::$app->getSites()->currentSite->id));
        }
    }
830864
function _processPages(siteDesc, prefix) {
    if (siteDesc.pages !== undefined && siteDesc.pages !== null) {
        //console.log('pages', siteDesc.pages, 'prefix', prefix);

        for (let i in siteDesc.pages) {
            _processElement(siteDesc.pages[i], prefix);
        }
    }
}
846407
protected function setupCurrentSite()
    {
        /** @var wpdb $wpdb */
        global $current_site, $wpdb;

        $current_site = new \stdClass;

        if (!empty($wpdb->get_results("SHOW TABLES LIKE '{$wpdb->prefix}blogs'"))) {
            $query = "SELECT domain, path  FROM {$wpdb->prefix}blogs WHERE blog_id = 1 AND site_id = 1";
            $data                    = $wpdb->get_row($query);
            $current_site->domain    = $data->domain;
            $current_site->path      = $data->path;
            $current_site->site_name = ucfirst($data->domain);
        } else {
            $site_url = $wpdb->get_var("SELECT option_value FROM {$wpdb->options} WHERE option_name = 'siteurl'");
            if (!empty($site_url)) {
                $current_site->domain = parse_url($site_url, PHP_URL_HOST);
                if ($port = parse_url($site_url, PHP_URL_PORT)) {
                    $current_site->domain .= ":{$port}";
                }
            } else {
                $current_site->domain = $this->config['domain'];
            }
            $current_site->path = '/';
        }
        $current_site->site_name = ucfirst($current_site->domain);
        $current_site->id        = 1;
    }
671018
static function getFirst( $return_post_id = false, $admin_mode = false ) {

		global $blog_id;

		$book_structure = static::getBookStructure();
		$order = $book_structure['__order'];
		$pos = array_keys( $order );

		reset( $pos );
		while ( $first_id = current( $pos ) ) {
			if ( $admin_mode ) {
				if ( current_user_can( 'edit_post', $first_id ) ) {
					break;
				} else {
					next( $pos );
				}
			} else {
				if ( in_array( $order[ $first_id ]['post_status'], [ 'publish', 'web-only' ], true ) ) {
					break;
				} elseif ( current_user_can_for_blog( $blog_id, 'read_private_posts' ) ) {
					break;
				} elseif ( get_option( 'permissive_private_content' ) && current_user_can_for_blog( $blog_id, 'read' ) ) {
					break;
				} else {
					next( $pos );
				}
			}
		}

		if ( $return_post_id ) {
			return (int) $first_id;
		} else {
			return ( empty( $first_id ) ) ? '/' : get_permalink( $first_id );
		}

	}