示例#1
0
 /**
  * Rewrite rules
  * @return array
  */
 public function rewrites()
 {
     global $wp_rewrite;
     global $ap_rules;
     unset($wp_rewrite->extra_permastructs['question']);
     unset($wp_rewrite->extra_permastructs['answer']);
     $base_page_id = ap_opt('base_page');
     $slug = ap_base_page_slug() . '/';
     $question_slug = ap_opt('question_page_slug');
     if (empty($question_slug)) {
         $question_slug = 'question';
     }
     $user_page = ap_opt('base_before_user_perma') ? $slug . ap_get_user_page_slug() . '/' : ap_get_user_page_slug() . '/';
     $new_rules = array($slug . 'parent/([^/]+)/?' => 'index.php?page_id=' . $base_page_id . '&parent=' . $wp_rewrite->preg_index(1), $slug . 'tag/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?page_id=' . $base_page_id . '&ap_page=tag&q_tag=' . $wp_rewrite->preg_index(1) . '&paged=' . $wp_rewrite->preg_index(2), $slug . 'tag/([^/]+)/?' => 'index.php?page_id=' . $base_page_id . '&ap_page=tag&q_tag=' . $wp_rewrite->preg_index(1), $slug . 'page/?([0-9]{1,})/?$' => 'index.php?page_id=' . $base_page_id . '&paged=' . $wp_rewrite->preg_index(1), $slug . '([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?page_id=' . $base_page_id . '&ap_page=' . $wp_rewrite->preg_index(1) . '&paged=' . $wp_rewrite->preg_index(2));
     if (!ap_opt('question_permalink_follow')) {
         $new_rules[$question_slug . '/([^/]+)/page/?([0-9]{1,})/?$'] = 'index.php?page_id=' . $base_page_id . '&question_name=' . $wp_rewrite->preg_index(1) . '&paged=' . $wp_rewrite->preg_index(2);
         $new_rules[$question_slug . '/([^/]+)/?$'] = 'index.php?page_id=' . $base_page_id . '&question_name=' . $wp_rewrite->preg_index(1);
     } else {
         $new_rules[$slug . $question_slug . '/([^/]+)/page/?([0-9]{1,})/?$'] = 'index.php?page_id=' . $base_page_id . '&question_name=' . $wp_rewrite->preg_index(1) . '&paged=' . $wp_rewrite->preg_index(2);
         $new_rules[$slug . $question_slug . '/([^/]+)/?$'] = 'index.php?page_id=' . $base_page_id . '&question_name=' . $wp_rewrite->preg_index(1);
     }
     $new_rules[$slug . $question_slug . '/([^/]+)/([^/]+)/?$'] = 'index.php?page_id=' . $base_page_id . '&question_id=' . $wp_rewrite->preg_index(1) . '&question_name=' . $wp_rewrite->preg_index(2);
     $new_rules[$user_page . '([^/]+)/([^/]+)/page/?([0-9]{1,})/?$'] = 'index.php?page_id=' . $base_page_id . '&ap_page=' . ap_get_user_page_slug() . '&ap_user='******'&user_page=' . $wp_rewrite->preg_index(2) . '&paged=' . $wp_rewrite->preg_index(3);
     $new_rules[$user_page . '([^/]+)/([^/]+)/?'] = 'index.php?page_id=' . $base_page_id . '&ap_page=' . ap_get_user_page_slug() . '&ap_user='******'&user_page=' . $wp_rewrite->preg_index(2);
     $new_rules[$user_page . '([^/]+)/?$'] = 'index.php?page_id=' . $base_page_id . '&ap_page=' . ap_get_user_page_slug() . '&ap_user='******'?$'] = 'index.php?page_id=' . $base_page_id . '&ap_page=' . ap_get_user_page_slug();
     $new_rules[$slug . 'search/([^/]+)/?'] = 'index.php?page_id=' . $base_page_id . '&ap_page=search&ap_s=' . $wp_rewrite->preg_index(1);
     $new_rules[$slug . 'ask/([^/]+)/?'] = 'index.php?page_id=' . $base_page_id . '&ap_page=ask&parent=' . $wp_rewrite->preg_index(1);
     $new_rules[$slug . '([^/]+)/?'] = 'index.php?page_id=' . $base_page_id . '&ap_page=' . $wp_rewrite->preg_index(1);
     $ap_rules = apply_filters('ap_rewrite_rules', $new_rules, $slug, $base_page_id);
     return $wp_rewrite->rules = $ap_rules + $wp_rewrite->rules;
 }
示例#2
0
/**
 * Surround mentions with anchor tag.
 * @param  string $content Post content.
 * @return string
 */
function ap_linkyfy_mentions($content)
{
    if (!ap_opt('base_before_user_perma')) {
        $base = home_url('/' . ap_get_user_page_slug() . '/');
    } else {
        $base = ap_get_link_to(ap_get_user_page_slug());
    }
    // Find mentions and wrap with anchor.
    return preg_replace('/(?:[\\s.]|^)@(\\w+)/', '<a class="ap-mention-link" href="' . $base . '$1">@$1</a> ', $content);
}
示例#3
0
/**
 * Check if current page is user page
 * @return boolean
 */
function is_ap_user()
{
    if (is_anspress() && ap_current_page() == ap_get_user_page_slug()) {
        return true;
    }
    return false;
}
示例#4
0
文件: user.php 项目: Byrlyne/anspress
/**
 * Return Link to user pages
 * @param  boolean|integer $user_id    user id
 * @param  string          $sub        page slug
 * @return string
 * @since  unknown
 */
function ap_user_link($user_id = false, $sub = false)
{
    if (false === $user_id) {
        $user_id = get_the_author_meta('ID');
    }
    if ($user_id < 1) {
        return '#AnonymousUser';
    }
    if (ap_opt('user_profile') == '') {
        return apply_filters('ap_user_custom_profile_link', $user_id, $sub);
    } elseif (function_exists('bp_core_get_userlink') && ap_opt('user_profile') == 'buddypress') {
        return bp_core_get_userlink($user_id, false, true);
    } elseif (ap_opt('user_profile') == 'userpro') {
        global $userpro;
        return $userpro->permalink($user_id);
    }
    if (0 == $user_id) {
        return false;
    }
    $user = get_user_by('id', $user_id);
    // If permalink is enabled.
    if (get_option('permalink_structure') != '') {
        if (!ap_opt('base_before_user_perma')) {
            $base = home_url('/' . ap_get_user_page_slug() . '/');
        } else {
            $base = ap_get_link_to(ap_get_user_page_slug());
        }
        if ($sub === false) {
            $link = $base . $user->user_login . '/';
        } elseif (is_array($sub)) {
            $link = $base . $user->user_login . '/';
            if (!empty($sub)) {
                foreach ($sub as $s) {
                    $link .= $s . '/';
                }
            }
        } elseif (!is_array($sub)) {
            $link = $base . $user->user_login . '/' . $sub . '/';
        }
    } else {
        if (false === $sub) {
            $sub = array('ap_page' => 'user', 'ap_user' => $user->user_login);
        } elseif (is_array($sub)) {
            $sub['ap_page'] = 'user';
            $sub['ap_user'] = $user->user_login;
        } elseif (!is_array($sub)) {
            $sub = array('ap_page' => 'user', 'ap_user' => $user->user_login, 'user_page' => $sub);
        }
        $link = ap_get_link_to($sub);
    }
    return apply_filters('ap_user_link', $link, $user_id);
}