Craft\SeomaticService::getGlobals PHP Method

getGlobals() public method

* -------------------------------------------------------------------------------- Get the seomatic globals --------------------------------------------------------------------------------
public getGlobals ( $forTemplate = "", $locale )
    public function getGlobals($forTemplate = "", $locale)
    {
        if ($this->renderedMetaVars) {
            return $this->renderedMetaVars;
        }
        if (!$locale) {
            $locale = craft()->language;
        }
        /* -- Load in our globals */
        $meta = $this->getMeta($forTemplate);
        $siteMeta = $this->getSiteMeta($locale);
        $identity = $this->getIdentity($locale);
        $social = $this->getSocial($locale);
        $creator = $this->getCreator($locale);
        /* -- Get a full qualified URL for the current request */
        $requestUrl = UrlHelper::stripQueryString(craft()->request->url);
        $meta['canonicalUrl'] = $this->getFullyQualifiedUrl($requestUrl);
        /* -- Merge the meta with the global meta */
        $globalMeta['seoTitle'] = $siteMeta['siteSeoTitle'];
        $globalMeta['seoDescription'] = $siteMeta['siteSeoDescription'];
        $globalMeta['seoKeywords'] = $siteMeta['siteSeoKeywords'];
        $globalMeta['seoImage'] = $this->getFullyQualifiedUrl($siteMeta['siteSeoImage']);
        $globalMeta['seoImageId'] = $siteMeta['siteSeoImageId'];
        $globalMeta['seoTwitterImageId'] = $siteMeta['siteSeoTwitterImageId'];
        $globalMeta['seoFacebookImageId'] = $siteMeta['siteSeoFacebookImageId'];
        $globalMeta['seoImageTransform'] = $siteMeta['siteSeoImageTransform'];
        $globalMeta['seoFacebookImageTransform'] = $siteMeta['siteSeoFacebookImageTransform'];
        $globalMeta['seoTwitterImageTransform'] = $siteMeta['siteSeoTwitterImageTransform'];
        $globalMeta['twitterCardType'] = $siteMeta['siteTwitterCardType'];
        $globalMeta['openGraphType'] = $siteMeta['siteOpenGraphType'];
        $globalMeta['robots'] = $siteMeta['siteRobots'];
        $meta = array_merge($globalMeta, $meta);
        /* -- Merge with the entry meta, if any */
        if ($this->entryMeta) {
            $meta = array_merge($meta, $this->entryMeta);
        }
        /* -- Merge with the global override config settings */
        $globalMetaOverride = craft()->config->get("globalMetaOverride", "seomatic");
        if (!empty($globalMetaOverride)) {
            $globalMetaOverride = array_filter($globalMetaOverride);
            $meta = array_merge($meta, $globalMetaOverride);
        }
        /* -- Add the helper vars */
        $helper = array();
        $this->addSocialHelpers($helper, $social, $identity);
        $this->addIdentityHelpers($helper, $identity);
        $this->addCreatorHelpers($helper, $creator);
        $this->setSocialForMeta($meta, $siteMeta, $social, $helper, $identity, $locale);
        /* -- Fill in the breadcrumbs */
        $meta['breadcrumbs'] = $this->getDefaultBreadcrumbs($meta);
        /* -- Swap in our JSON-LD objects */
        $identity = $this->getIdentityJSONLD($identity, $helper, $locale);
        $creator = $this->getCreatorJSONLD($creator, $helper, $locale);
        /* -- Handle the Main Entity of Page, if set */
        $seomaticMainEntityOfPage = "";
        $seomaticMainEntityOfPage = $this->getMainEntityOfPageJSONLD($meta, $identity, $locale, true);
        /* -- Special-case for Craft Commerce products */
        if ($this->entryMeta && isset($this->entrySeoCommerceVariants) && !empty($this->entrySeoCommerceVariants)) {
            $seomaticMainEntityOfPage = $this->getProductJSONLD($meta, $identity, $locale, true);
        }
        /* -- Get rid of variables we don't want to expose */
        unset($siteMeta['siteSeoImageId']);
        unset($siteMeta['siteSeoTwitterImageId']);
        unset($siteMeta['siteSeoFacebookImageId']);
        unset($siteMeta['siteTwitterCardType']);
        unset($siteMeta['siteOpenGraphType']);
        unset($siteMeta['siteRobotsTxt']);
        unset($siteMeta['siteSeoImageTransform']);
        unset($siteMeta['siteSeoFacebookImageTransform']);
        unset($siteMeta['siteSeoTwitterImageTransform']);
        unset($meta['seoMainEntityCategory']);
        unset($meta['seoMainEntityOfPage']);
        unset($meta['twitterCardType']);
        unset($meta['openGraphType']);
        unset($meta['seoImageId']);
        unset($meta['seoTwitterImageId']);
        unset($meta['seoFacebookImageId']);
        unset($meta['seoImageTransform']);
        unset($meta['seoFacebookImageTransform']);
        unset($meta['seoTwitterImageTransform']);
        /* -- Set some useful runtime variables, too */
        $runtimeVars = array('seomaticTemplatePath' => '');
        /* -- Return everything is an array of arrays */
        $result = array('seomaticMeta' => $meta, 'seomaticHelper' => $helper, 'seomaticSiteMeta' => $siteMeta, 'seomaticSocial' => $social, 'seomaticIdentity' => $identity, 'seomaticCreator' => $creator);
        /* -- Fill in the main entity of the page */
        if ($seomaticMainEntityOfPage) {
            $result['seomaticMainEntityOfPage'] = $seomaticMainEntityOfPage;
        }
        /* -- Return our global variables */
        $result = array_merge($result, $runtimeVars);
        return $result;
    }