Пример #1
0
 public function load()
 {
     if (empty($this->includeHandler)) {
         new EaseWarning(__('Bad ressource file', 'ease'), sprintf(__('The ressource %s, which you are trying to include into your theme, can not be handeled correctly.', 'ease'), '<i>' . EaseHelper::getFilename($this->path) . '</i>'));
         return;
     }
     call_user_func($this->includeHandler, (!empty($this->scope) ? $this->scope : EaseSettings::get('theme', 'slug')) . (!empty($this->id) ? '-' . $this->id : ''), $this->path, $this->dependencies);
 }
Пример #2
0
 private function appendEaseSettings()
 {
     $this->addSettingSection("ease", "ease Framework", sprintf(__("This theme is empowered by <b>ease %s</b>, a powerful framework making theme development more flexible and themes easier to upgrade. Ease adds this section automatically to your theme customizer.", EaseSettings::get('ease', 'textDomain')), EASE_VERSION), 200);
     $this->addSetting("ease-updatenotify", "ease", __("Update-Notification", EaseSettings::get('ease', 'textDomain')), __("Should ease automatically check for updates of itself and notify you when you are using an old version? Usually, best practice is to let the theme author update ease through updating the whole theme, but in case of unmaintained themes you can manually upgrade your \"core\"-subfolder in your theme folder.", EaseSettings::get('ease', 'textDomain')), "boolean", "true");
 }
Пример #3
0
 public function generate()
 {
     // Selects all {{ ... }} wildcards containing more than three characters (minimum for valid expression) and saving wildcard group, if given.
     $wildcardPattern = '/(?P<complete>(?<=\\{\\{)\\{?.*?\\}?(?=\\}(?P<group>[1-9])?\\}))/';
     // Selects all [ ... ] or { ... } tags containing at least on alpha-numeric character. Also extracting defaults.
     $tagPattern = '/(?J)(?P<complete>(?<=(?P<openingcharacter>\\{))(?P<body>[a-zA-Z0-9]+)(?:=(?P<default>[a-zA-Z0-9\\s]+))?(?=\\}))|(?P<complete>(?<=(?P<openingcharacter>\\[))(?P<body>[a-zA-Z0-9]+)(?:=(?P<default>[a-zA-Z0-9\\s]+))?(?=\\]))/';
     $wildcardGroups = array();
     preg_match_all($wildcardPattern, $this->replace, $wildcards, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
     foreach ($wildcards as $wildcardId => $wildcard) {
         // Searching for tags in wildcard, adding them to wildcard array and
         // checking, if there is a primary tag.
         preg_match_all($tagPattern, $wildcards[$wildcardId]['complete'][0], $tags, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
         foreach ($tags as $tagId => $tag) {
             $tagType = $tag['openingcharacter'][0] == '{' ? 'primary' : 'optional';
             // Putting the tag in the wildcards-array
             // Muting this line, because it gives tons of notices if fields doesn't exist.
             @($wildcards[$wildcardId][$tagType][] = array('body' => $tag['body'][0], 'position' => intval($tag['complete'][1]) - 1, 'length' => strlen($tag['complete'][0]) + 2, 'default' => $tag['default'][0]));
         }
         // Cleaning the wildcards-array and calculating some values
         foreach ($wildcard as $field => $value) {
             if (is_int($field)) {
                 unset($wildcards[$wildcardId][$field]);
             }
         }
         $wildcards[$wildcardId]['position'] = intval($wildcards[$wildcardId]['complete'][1]) - 2;
         $wildcards[$wildcardId]['length'] = strlen($wildcards[$wildcardId]['complete'][0]) + @strlen($wildcards[$wildcardId]['group'][0]) + 4;
         $wildcards[$wildcardId]['complete'] = $wildcards[$wildcardId]['complete'][0];
         if (array_key_exists('group', $wildcards[$wildcardId])) {
             $groupId = intval($wildcards[$wildcardId]['group'][0]);
             $wildcards[$wildcardId]['group'] = $groupId;
             $wildcardGroups[$groupId][] = $wildcardId;
         }
     }
     // Doing some wildcard checking
     foreach ($wildcards as $wildcardId => $wildcard) {
         $warning = false;
         if (!array_key_exists('primary', $wildcard)) {
             if (!array_key_exists('group', $wildcard)) {
                 $warning = true;
             } else {
                 $warning = true;
                 foreach ($wildcardGroups[$wildcard['group']] as $wildcardId) {
                     if (array_key_exists('primary', $wildcards[$wildcardId])) {
                         $warning = false;
                     }
                 }
             }
         }
         if ($warning) {
             new EaseWarning(__('Empty wildcard in shortcode', EaseSettings::get('ease', 'textDomain')), sprintf(__('The replacement-string for your shortcode %s contains a wildcard %s with no primary tag. Without one (or more), it will never shown and is therefore useless.', EaseSettings::get('ease', 'textDomain')), '<b>[' . $this->id . ']</b>', '<b>{{' . $wildcards[$wildcardId]['complete'] . '}}</b>'));
             $wildcards[$wildcardId]['dead'] = true;
         }
     }
     $this->wildcards = $wildcards;
     $this->wildcardGroups = $wildcardGroups;
     $shortcodeFunction = function ($attributes, $content = null) {
         // Initializing output string and combined attribute array
         $output = $this->replace;
         $wildcards = $this->wildcards;
         if (!empty($attributes)) {
             foreach ($wildcards as $wildcardId => $wildcard) {
                 if (!(array_key_exists('dead', $wildcards[$wildcardId]) || array_key_exists('matched', $wildcards[$wildcardId]))) {
                     $matched = false;
                     $totalPrimaries = 0;
                     $primaries = 0;
                     if (array_key_exists('primary', $wildcard)) {
                         foreach ($wildcard['primary'] as $primary) {
                             if (array_key_exists($primary['body'], $attributes)) {
                                 $primaries++;
                             }
                             $totalPrimaries++;
                         }
                     }
                     if (array_key_exists('group', $wildcard)) {
                         foreach ($this->wildcardGroups[$wildcard['group']] as $groupWildcardId) {
                             if ($groupWildcardId != $wildcardId && array_key_exists('primary', $wildcards[$groupWildcardId])) {
                                 foreach ($wildcards[$groupWildcardId]['primary'] as $groupPrimary) {
                                     if (array_key_exists($groupPrimary['body'], $attributes)) {
                                         $primaries++;
                                     }
                                     $totalPrimaries++;
                                 }
                             }
                         }
                     }
                     $matched = $primaries == $totalPrimaries ? true : false;
                     $wildcards[$wildcardId]['matched'] = $matched;
                     if (array_key_exists('group', $wildcard)) {
                         foreach ($this->wildcardGroups[$wildcard['group']] as $groupWildcardId) {
                             $wildcards[$groupWildcardId]['matched'] = $matched;
                         }
                     }
                 }
             }
         }
         foreach (array_reverse($wildcards) as $wildcardId => $wildcard) {
             $wildcardOutput = '';
             if (!array_key_exists('dead', $wildcard) && @$wildcard['matched'] == true) {
                 $wildcardOutput = $wildcard['complete'];
                 $mergedTags = array();
                 if (array_key_exists('primary', $wildcard)) {
                     $mergedTags = array_merge($mergedTags, $wildcard['primary']);
                 }
                 if (array_key_exists('optional', $wildcard)) {
                     $mergedTags = array_merge($mergedTags, $wildcard['optional']);
                 }
                 if (!empty($mergedTags)) {
                     $tags = array();
                     foreach ($mergedTags as $tag) {
                         if (array_key_exists($tag['body'], $attributes)) {
                             $tag['default'] = $attributes[$tag['body']];
                         }
                         $tags[$tag['position']] = $tag;
                     }
                     ksort($tags);
                     $tags = array_reverse($tags);
                     foreach ($tags as $tagId => $tag) {
                         $wildcardOutput = substr($wildcardOutput, 0, $tag['position']) . $tag['default'] . substr($wildcardOutput, $tag['position'] + $tag['length']);
                     }
                 }
             }
             $output = substr($output, 0, $wildcard['position']) . $wildcardOutput . substr($output, $wildcard['position'] + $wildcard['length']);
         }
         // If child shortcodes are allowed, checking for them
         if ($this->allowChildren) {
             $content = do_shortcode($content);
         }
         // Finally, replacing the non-attributized content element (if present)
         $output = str_replace('[[[CONTENT]]]', $content, $output);
         // Returning the completly combined output string
         return $output;
     };
     add_shortcode($this->id, $shortcodeFunction);
 }