Beispiel #1
0
 public static function getTimestamp()
 {
     static $timestamp = null;
     if ($timestamp === null) {
         $timestamp = Other::getPlugin('Version');
     }
     return $timestamp;
 }
Beispiel #2
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;
 }
Beispiel #3
0
 public function filterWpDropdownUsers($html)
 {
     if (Other::getCurrentScreen()->base !== 'edit') {
         return $html;
     }
     ?>
     <select style="display:none;" class="authors poiauthor-author-id" name="post_author"></select>
     <?php 
 }
Beispiel #4
0
 public static function getPagesCount($comments)
 {
     if (class_exists(InnThemeComment::class) && method_exists(InnThemeComment::class, 'getPagesCount')) {
         return InnThemeComment::getPagesCount($comments);
     }
     static $count = null;
     if ($count === null) {
         $count = \get_comment_pages_count($comments, Other::getOption('comments_per_page'), Other::getOption('thread_comments'));
     }
     return $count;
 }
Beispiel #5
0
    public static function pageOptsList($addonID, $optID)
    {
        static $pages = null;
        if ($pages === null) {
            $pages = \get_pages();
        }
        $opt = Other::getOpts($addonID);
        $selectedPageID = isset($opt[$optID]) ? (int) $opt[$optID] : null;
        ?>
        <select name="<?php 
        echo $addonID;
        ?>
[<?php 
        echo $optID;
        ?>
]" id="<?php 
        echo $addonID;
        ?>
-<?php 
        echo $optID;
        ?>
">
            <option value="-1"><?php 
        echo L10n::__('Select page');
        ?>
</option>
            <?php 
        foreach ($pages as $page) {
            if ($selectedPageID == $page->ID) {
                $selected = ' selected ';
            } else {
                $selected = null;
            }
            ?>
                <option value="<?php 
            echo $page->ID;
            ?>
" <?php 
            echo $selected;
            ?>
><?php 
            echo Post::getTheTitle($page->ID);
            ?>
</option>
                <?php 
        }
        ?>
        </select>
        <?php 
    }
Beispiel #6
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;
 }
Beispiel #7
0
 public static function getPermalink($postID, $leavename = false)
 {
     static $cache = [];
     if (isset($cache[$postID])) {
         return $cache[$postID];
     }
     global $post;
     if (!isset($post->ID) || $post->ID != $postID) {
         $p = static::getPost($postID);
     } else {
         $p = $post;
     }
     $rewritecode = ['%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', $leavename ? '' : '%postname%', '%post_id%', '%category%', '%author%', $leavename ? '' : '%pagename%'];
     if ($p->post_type == 'page') {
         return Url::esc(\get_page_link($p, $leavename));
     } elseif ($p->post_type == 'attachment') {
         return Url::esc(\get_attachment_link($p, $leavename));
     } elseif (in_array($p->post_type, \get_post_types(['_builtin' => false]))) {
         return Url::esc(\get_post_permalink($p, $leavename));
     }
     $permalink = Other::getOption('permalink_structure');
     $permalink = \apply_filters('pre_post_link', $permalink, $p, $leavename);
     if ('' != $permalink && !in_array($p->post_status, ['draft', 'pending', 'auto-draft', 'future'])) {
         $unixtime = strtotime($p->post_date);
         $category = '';
         if (strpos($permalink, '%category%') !== false) {
             $cats = Category::getTheCategory($p->ID);
             if ($cats) {
                 usort($cats, '_usort_terms_by_ID');
                 // order by ID
                 /**
                  * Filter the category that gets used in the %category% permalink token.
                  *
                  * @since 3.5.0
                  *
                  * @param stdClass $cat  The category to use InnStudio\PoiAuthor\in the permalink.
                  * @param array    $cats Array of all categories associated with the post.
                  * @param WP_Post  $post The post in question.
                  */
                 $category_object = \apply_filters('post_link_category', $cats[0], $cats, $p);
                 $category_object = \get_term($category_object, 'category');
                 $category = $category_object->slug;
                 if ($parent = $category_object->parent) {
                     $category = \get_category_parents($parent, false, '/', true) . $category;
                 }
             }
             // show default category in permalinks, without
             // having to assign it explicitly
             if (empty($category)) {
                 $default_category = \get_term(Other::getOption('default_category'), 'category');
                 $category = \is_wp_error($default_category) ? '' : $default_category->slug;
             }
         }
         $author = '';
         if (strpos($permalink, '%author%') !== false) {
             $authordata = User::getUserdata($p->post_author);
             $author = $authordata->user_nicename;
         }
         $date = explode(" ", date('Y m d H i s', $unixtime));
         $rewritereplace = array($date[0], $date[1], $date[2], $date[3], $date[4], $date[5], $p->post_name, $p->ID, $category, $author, $p->post_name);
         $permalink = Url::getHome(str_replace($rewritecode, $rewritereplace, $permalink));
         $permalink = \user_trailingslashit($permalink, 'single');
     } else {
         // if they're not using the fancy permalink option
         $permalink = Url::getHome() . '?p=' . $p->ID;
     }
     /**
      * Filter the permalink for a post.
      *
      * Only applies to posts with post_type of 'post'.
      *
      * @since 1.5.0
      *
      * @param string  $permalink The post's permalink.
      * @param WP_Post $post      The post in question.
      * @param bool    $leavename Whether to keep the post name.
      */
     $cache[$postID] = Url::esc(\apply_filters('post_link', $permalink, $p, $leavename));
     unset($p);
     return $cache[$postID];
 }
Beispiel #8
0
 public static function getHumanDate($timestamp)
 {
     $text = '';
     $t = Other::getCurrentTime('timestamp') - $timestamp;
     switch ($t) {
         /**
          * in 1 minu, just now
          */
         case $t < 60:
             $text = L10n::__('Just');
             break;
             /**
              * in 1 hours, 60 * 60 = 3600
              */
         /**
          * in 1 hours, 60 * 60 = 3600
          */
         case $t < 3600:
             $text = sprintf(L10n::__('%dmin ago'), floor($t / 60));
             break;
             /**
              * in 1 day, 60 * 60 * 24 = 86400
              */
         /**
          * in 1 day, 60 * 60 * 24 = 86400
          */
         case $t < 86400:
             $text = sprintf(L10n::__('%dh ago'), floor($t / 3600));
             break;
             /**
              * in 1 month, 60 * 60 * 24 * 30 = 2592000
              */
         /**
          * in 1 month, 60 * 60 * 24 * 30 = 2592000
          */
         case $t < 2592000:
             $text = sprintf(L10n::__('%dd ago'), floor($t / 86400));
             break;
             /**
              * in 1 year, 60 * 60 * 24 * 30 * 12 = 31104000
              */
         /**
          * in 1 year, 60 * 60 * 24 * 30 * 12 = 31104000
          */
         case $t < 31104000:
             $text = sprintf(L10n::__('%dm ago'), floor($t / 2592000));
             break;
             /**
              * in 100 year 60 * 60 * 24 * 30 * 12 * 100 = 3110400000
              */
         /**
          * in 100 year 60 * 60 * 24 * 30 * 12 * 100 = 3110400000
          */
         case $t < 3110400000:
             $text = sprintf(L10n::__('%dy ago'), floor($t / 31104000));
             break;
             /**
              * dislay date
              */
         /**
          * dislay date
          */
         default:
             $text = date(L10n::__('M j, Y'), $timestamp);
     }
     return $text;
 }