Esempio n. 1
0
 public function backendEnqueueScripts()
 {
     $js = [Functions::buildActionName('backend') => ['url' => Url::getJsUrl('backend')]];
     foreach ($js as $k => $v) {
         \wp_enqueue_script($k, $v['url'], isset($v['deps']) ? $v['deps'] : [], $this->getVersion($v));
     }
 }
Esempio n. 2
0
 public function frontendEnqueueCss()
 {
     $css = [Functions::buildActionName('awesome') => ['deps' => [], 'url' => $this->getAwesomeURL(), 'version' => null], Functions::buildActionName('frontend') => ['deps' => [Functions::buildActionName('awesome')], 'url' => Url::getCssUrl('frontend')]];
     foreach ($css as $k => $v) {
         \wp_enqueue_style($k, $v['url'], isset($v['deps']) ? $v['deps'] : [], $this->getVersion($v));
     }
 }
Esempio n. 3
0
 protected function getConf()
 {
     $conf = ['ID' => Core::ID, 'ajaxURL' => Url::getAjax(), 'lang' => ['loading' => L10n::__('Loading, please wait...'), 'error' => L10n::__('Sorry, server is busy now, can not respond your request, please try again later.'), 'close' => L10n::__('Close'), 'ok' => L10n::__('OK')]];
     if (Condition::isAdmin()) {
         $conf['_nonce'] = Security::createNonce();
     }
     return \apply_filters(Functions::buildActionName('dynamicConf'), $conf);
 }
Esempio n. 4
0
 public function dynamicConfAdmin(array $conf)
 {
     if (Other::getCurrentScreen()->base !== 'post') {
         return $conf;
     }
     global $post;
     $conf[static::getOptID()] = ['id' => Functions::buildActionName(static::getOptID()), 'lang' => ['typeAuthorNameForSearch' => L10n::__('Type author name for search'), 'authorId' => L10n::__('Author ID')], 'postId' => $post->ID, 'authorId' => $post->post_author, 'authorName' => User::getTheAuthorMeta('display_name', $post->post_author)];
     return $conf;
 }
Esempio n. 5
0
 private function ajaxGetUser()
 {
     $userId = filter_input(INPUT_GET, 'userId', FILTER_VALIDATE_INT);
     if (!$userId) {
         return;
     }
     $user = User::getUserBy('id', $userId);
     if (!$user) {
         return;
     }
     Functions::jsonOutput(['status' => 'success', 'user' => ['name' => User::getTheAuthorMeta('display_name', $user->ID)]], true);
 }
Esempio n. 6
0
 public static function getAjax($action = null, array $args = [])
 {
     $url = static::getAdmin('admin-ajax.php');
     if (!$action) {
         return $url;
     }
     $action = Functions::buildActionName($action);
     if (empty($args)) {
         return "{$url}?action={$action}";
     }
     return "{$url}?action={$action}&" . http_build_query($args);
 }
Esempio n. 7
0
 protected static function _saveOpts()
 {
     if (empty(static::$opts)) {
         static::$opts = static::getOpts();
     }
     if (isset($_POST['restore'])) {
         static::$opts = [];
         \delete_option(Core::ID);
     } else {
         static::$opts = \apply_filters(Functions::buildActionName('addonSaveOpts'), []);
         Other::updateOption(Core::ID, static::$opts);
     }
     return static::$opts;
 }
Esempio n. 8
0
 public static function getUserMeta(...$args)
 {
     if (class_exists(InnThemeUser::class) && method_exists(InnThemeUser::class, 'getUserMeta')) {
         return call_user_func_array([InnThemeUser::class, 'getUserMeta'], $args);
     }
     if (isset($args[3]) && $args[3]) {
         unset($args[3]);
         return Functions::metaToJson(call_user_func_array('\\get_user_meta', $args));
     }
     static $cache = [];
     $cacheID = md5(json_encode($args));
     if (!isset($cache[$cacheID])) {
         $cache[$cacheID] = Functions::metaToJson(call_user_func_array('\\get_user_meta', $args));
     }
     return $cache[$cacheID];
 }
Esempio n. 9
0
 public static function getThumbnailURL($postID, $size = 'thumbnail', $placeholderURL = null)
 {
     if (!$placeholderURL) {
         $placeholderURL = ImgPlaceholder::getThumbnailPlaceholderURL();
     }
     $imgURL = null;
     /** check sinapicv2 thumbnail */
     if (class_exists('\\sinapicv2\\sinapicv2')) {
         $imgURL = \sinapicv2\sinapicv2::get_post_thumbnail_url($postID, true);
     } else {
         if (\has_post_thumbnail($postID)) {
             $thumbnailID = \get_post_thumbnail_id($postID);
             $imgURL = \wp_get_attachment_image_src($thumbnailID, $size)[0];
             if ($size !== 'thumbnail') {
                 if (\wp_get_attachment_image_src($thumbnailID, 'full')[0] === $imgURL) {
                     $imgURL = \wp_get_attachment_image_src($thumbnailID, 'thumbnail')[0];
                 }
             }
         }
     }
     if (!$imgURL) {
         $post = static::getPost($postID);
         $imgURL = $post ? Functions::getImgURL($post->post_content) : false;
         unset($post);
     }
     if (!$imgURL) {
         $imgURL = $placeholderURL;
     }
     return $imgURL;
     //if (\is_ssl() && stripos($imgURL, 'https://')) {
     //}
     //return stripos(Other::getBlogInfo('home')) Url::esc($imgURL);
 }
Esempio n. 10
0
 public function confFrontend()
 {
     \wp_localize_script(Functions::buildActionName('frontend'), $this->getConfId(), $this->getConf());
 }
Esempio n. 11
0
    public function displayBackend()
    {
        ?>
        <div class="wrap <?php 
        echo Core::ID;
        ?>
-wrap">
        <form class="backend-fm <?php 
        echo Core::ID;
        ?>
-backend-fm" method="post" action="<?php 
        echo Url::getAjax(static::getOptID(), ['_nonce' => Security::createNonce()]);
        ?>
">
        <div class="tab-nav-container <?php 
        echo Core::ID;
        ?>
-tab-nav-container"></div>

        <div class="tab-body">
            <?php 
        $settings = \apply_filters(Functions::buildActionName('backendSettings'), []);
        ksort($settings);
        foreach ($settings as $legend => $setting) {
            ?>
                <fieldset>
                    <legend class="button button-primary">
                        <i class="fa fa-fw fa-<?php 
            echo $setting['icon'];
            ?>
"></i> <?php 
            echo $setting['title'];
            ?>
                    </legend>
                    <?php 
            call_user_func($setting['content']);
            ?>
                </fieldset>
            <?php 
        }
        ?>

        </div>

        <p>
            <input type="hidden" name="_nonce" value="<?php 
        echo Security::createNonce();
        ?>
">

            <button id="submit" type="submit" class="backend-submit button button-primary"><i class="fa fa-check"></i> <span class="tx"><?php 
        echo L10n::__('Save');
        ?>
</span></button>

            <label for="options-restore" class="label-options-restore" title="<?php 
        echo L10n::__('Something error with plugin? Try to restore. Be careful, plugin options will be cleared up!');
        ?>
">
                <input id="options-restore" name="restore" type="checkbox" value="1"/>
                <?php 
        echo L10n::__('Restore to default options');
        ?>
 <i class="fa fa-question-circle"></i>
            </label>
        </p>
        </form>
        </div>
        <?php 
    }
Esempio n. 12
0
 protected function setOptsSave($method = 'saveOpts')
 {
     \add_filter(Functions::buildActionName('addonSaveOpts'), function (array $opts = []) use($method) {
         $opts[static::getOptID()] = call_user_func([$this, $method]);
         return $opts;
     });
 }
Esempio n. 13
0
 public static function isOptsPage()
 {
     $page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_STRING);
     return $page === Functions::buildActionName(Options::URL_ID) && User::currentUserCan('manage_options') && static::isAdmin();
 }