Пример #1
0
 function head_title()
 {
     if (qa_opt('buddypress_integration_enable') && qa_opt('buddypress_display_names') && $this->template == 'user' && @$this->content['title']) {
         $rest = str_replace('^', '(\\S+)', qa_lang_html('profile/user_x'));
         $handle = preg_replace('|' . $rest . '|', '$1', $this->content['title']);
         $name = bp_core_get_user_displayname($handle);
         if ($name) {
             $this->content['title'] = qa_lang_html_sub('profile/user_x', $name) . ' (@' . $handle . ')';
             if (isset($this->content['form_activity'])) {
                 $this->content['form_activity']['title'] = qa_lang_html_sub('profile/activity_by_x', $name);
             }
         }
     }
     qa_html_theme_base::head_title();
 }
Пример #2
0
 function head_title()
 {
     // Title Customization Options
     $title = '';
     switch ($this->template) {
         case 'qa':
             $title_template = qa_opt('useo_title_qa');
             if (!empty($title_template)) {
                 $search = array('%site-title%');
                 $replace = array(qa_opt('site_title'));
                 $title = str_replace($search, $replace, $title_template);
             }
             break;
         case 'question':
             $category_name = '';
             if (isset($this->content["categoryids"]) && !empty($this->content["categoryids"])) {
                 $category_name = $this->content["q_view"]["raw"]["categoryname"];
             }
             if (empty($this->meta_title)) {
                 // title customization
                 $title_template = qa_opt('useo_title_qa_item');
                 if (!empty($title_template)) {
                     $search = array('%site-title%', '%question-title%', '%category-name%');
                     $replace = array(qa_opt('site_title'), @$this->content['q_view']['raw']['title'], $category_name);
                     $title = str_replace($search, $replace, $title_template);
                 }
             } else {
                 // meta editor
                 $title = $this->meta_title;
             }
             break;
         case 'questions':
             $category_name = '';
             if (count(explode('/', $this->request)) > 1) {
                 $category_name = $this->content["q_list"]["qs"][0]["raw"]["categoryname"];
             }
             $sort = qa_get('sort');
             if (empty($sort)) {
                 $title_template = qa_opt('useo_title_recent');
                 if (!empty($title_template)) {
                     $search = array('%site-title%', '%recent-qs-title%', '%category-name%');
                     $replace = array(qa_opt('site_title'), qa_lang_html('main/recent_qs_title'), $category_name);
                     $title = str_replace($search, $replace, $title_template);
                 }
             } elseif ($sort == 'hot') {
                 $title_template = qa_opt('useo_title_hot');
                 if (!empty($title_template)) {
                     $search = array('%site-title%', '%hot-qs-title%');
                     $replace = array(qa_opt('site_title'), qa_lang_html('main/hot_qs_title'));
                     $title = str_replace($search, $replace, $title_template);
                 }
             } elseif ($sort == 'votes') {
                 $title_template = qa_opt('useo_title_voted');
                 if (!empty($title_template)) {
                     $search = array('%site-title%', '%voted-qs-title%');
                     $replace = array(qa_opt('site_title'), qa_lang_html('main/voted_qs_title'));
                     $title = str_replace($search, $replace, $title_template);
                 }
             } elseif ($sort == 'answers') {
                 $title_template = qa_opt('useo_title_answered');
                 if (!empty($title_template)) {
                     $search = array('%site-title%', '%answered-qs-title%');
                     $replace = array(qa_opt('site_title'), qa_lang_html('main/answered_qs_title'));
                     $title = str_replace($search, $replace, $title_template);
                 }
             } elseif ($sort == 'views') {
                 $title_template = qa_opt('useo_title_viewed');
                 if (!empty($title_template)) {
                     $search = array('%site-title%', '%viewed-qs-title%');
                     $replace = array(qa_opt('site_title'), qa_lang_html('main/viewed_qs_title'));
                     $title = str_replace($search, $replace, $title_template);
                 }
             }
         case 'unanswered':
             $sort = qa_get('by');
             $category_name = '';
             if (count(explode('/', $this->request)) > 1) {
                 $category_name = $this->content["q_list"]["qs"][0]["raw"]["categoryname"];
             }
             if (empty($sort)) {
                 $title_template = qa_opt('useo_title_unanswered');
                 if (!empty($title_template)) {
                     $search = array('%site-title%', '%unanswered-qs-title%', '%category-name%');
                     $replace = array(qa_opt('site_title'), qa_lang_html('main/unanswered_qs_title'), $category_name);
                     $title = str_replace($search, $replace, $title_template);
                 }
             } elseif ($sort == 'selected') {
                 $title_template = qa_opt('useo_title_unselected');
                 if (!empty($title_template)) {
                     $search = array('%site-title%', '%unselected-qs-title%');
                     $replace = array(qa_opt('site_title'), qa_lang_html('main/unselected_qs_title'));
                     $title = str_replace($search, $replace, $title_template);
                 }
             } elseif ($sort == 'upvotes') {
                 $title_template = qa_opt('useo_title_unupvoted');
                 if (!empty($title_template)) {
                     $search = array('%site-title%', '%unupvoteda-qs-title%');
                     $replace = array(qa_opt('site_title'), qa_lang_html('main/unupvoteda_qs_title'));
                     $title = str_replace($search, $replace, $title_template);
                 }
             }
             break;
         case 'activity':
             $title_template = qa_opt('useo_title_activity');
             if (!empty($title_template)) {
                 $category_name = '';
                 if (count(explode('/', $this->request)) > 1) {
                     $category_name = $this->content["q_list"]["qs"][0]["raw"]["categoryname"];
                 }
                 $search = array('%site-title%', '%recent-activity-title%', '%category-name%');
                 $replace = array(qa_opt('site_title'), qa_lang_html('main/recent_activity_title'), $category_name);
                 $title = str_replace($search, $replace, $title_template);
             }
             break;
         case 'ask':
             $title_template = qa_opt('useo_title_ask');
             if (!empty($title_template)) {
                 $search = array('%site-title%', '%ask-title%');
                 $replace = array(qa_opt('site_title'), qa_lang_html('question/ask_title'));
                 $title = str_replace($search, $replace, $title_template);
             }
             break;
         case 'categories':
             $title_template = qa_opt('useo_title_categories');
             if (!empty($title_template)) {
                 $search = array('%site-title%', '%browse-categories%');
                 $replace = array(qa_opt('site_title'), qa_lang_html('misc/browse_categories'));
                 $title = str_replace($search, $replace, $title_template);
             }
             break;
         case 'tags':
             $title_template = qa_opt('useo_title_tags');
             if (!empty($title_template)) {
                 $search = array('%site-title%', '%popular-tags%');
                 $replace = array(qa_opt('site_title'), qa_lang_html('main/popular_tags'));
                 $title = str_replace($search, $replace, $title_template);
             }
             break;
         case 'tag':
             $title_template = qa_opt('useo_title_tag');
             if (!empty($title_template)) {
                 $req = explode('/', $this->request);
                 $tag = $req[1];
                 $search = array('%site-title%', '%questions-tagged-x%', '%current-tag%');
                 $replace = array(qa_opt('site_title'), qa_lang_html_sub('main/questions_tagged_x', qa_html($tag)), $tag);
                 $title = str_replace($search, $replace, $title_template);
             }
             break;
         case 'search':
             $title_template = qa_opt('useo_title_search');
             if (!empty($title_template)) {
                 $term = qa_get('q');
                 $search = array('%site-title%', '%results-for-x%', '%current-term%');
                 $replace = array(qa_opt('site_title'), qa_lang_html_sub('main/results_for_x', qa_html($term)), $term);
                 $title = str_replace($search, $replace, $title_template);
             }
             break;
         case 'users':
             $title_template = qa_opt('useo_title_users');
             if (!empty($title_template)) {
                 $search = array('%site-title%', '%highest-users%');
                 $replace = array(qa_opt('site_title'), qa_lang_html('main/highest_users'));
                 $title = str_replace($search, $replace, $title_template);
             }
             break;
         case 'user':
             $title_template = qa_opt('useo_title_user');
             if (!empty($title_template)) {
                 $req = explode('/', $this->request);
                 $user = $req[1];
                 $search = array('%site-title%', '%user-x%', '%current-user%');
                 $replace = array(qa_opt('site_title'), qa_lang_html_sub('main/results_for_x', qa_html($user)), $user);
                 $title = str_replace($search, $replace, $title_template);
             }
             break;
     }
     if (empty($title)) {
         qa_html_theme_base::head_title();
     } else {
         $this->output('<title>' . $title . '</title>');
     }
     // Page Meta Tags
     $noindex = qa_opt('useo_access_noindex');
     $nofollow = qa_opt('useo_access_nofollow');
     if ($noindex and $nofollow) {
         $this->output('<meta name="robots" content="noindex, nofollow" />');
     } elseif ($noindex) {
         $this->output('<meta name="robots" content="noindex" />');
     } else {
         // if page is not already noindex, check if it needs to be noindex. also add nofollow if necessary
         $status = 1;
         // content is long enough
         if ($this->template == 'question' and qa_opt('useo_access_length_enable') and (int) qa_opt('useo_access_length') > 0) {
             $status = 0;
             $minimum_words = (int) qa_opt('useo_access_length');
             $word_count = str_word_count($this->content['q_view']['raw']['title']) + str_word_count($this->content['q_view']['raw']['content']);
             if ($word_count >= $minimum_words) {
                 $status = 1;
             } else {
                 foreach ($this->content['q_view']['c_list']['cs'] as $comment) {
                     $word_count += str_word_count($comment['raw']['content']);
                 }
                 if ($word_count >= $minimum_words) {
                     $status = 1;
                 } else {
                     foreach ($this->content['a_list']['as'] as $answer) {
                         $word_count += str_word_count($answer['raw']['content']);
                     }
                     if ($word_count >= $minimum_words) {
                         $status = 1;
                     } else {
                         foreach ($this->content['a_list']['as'] as $answer) {
                             foreach ($answer['c_list']['cs'] as $comment) {
                                 $word_count += str_word_count($comment['raw']['content']);
                             }
                         }
                         if ($word_count >= $minimum_words) {
                             $status = 1;
                         }
                     }
                 }
             }
         }
         if ($nofollow && $status == 1) {
             $this->output('<meta name="robots" content="nofollow" />');
         } elseif ($nofollow && $status == 0) {
             $this->output('<meta name="robots" content="noindex, nofollow" />');
         } elseif ($status == 0) {
             $this->output('<meta name="robots" content="noindex" />');
         }
     }
     // Question Meta tags
     if ($this->template == 'question') {
         // setup custom meta keyword
         if (!empty($this->meta_keywords)) {
             $this->content['keywords'] = $this->meta_keywords;
         }
         // setup custom meta description
         if (!empty($this->meta_description)) {
             $this->content['description'] = $this->meta_description;
         } elseif (qa_opt('useo_meta_desc_ans_enable')) {
             $lenght = (int) qa_opt('useo_meta_desc_length');
             if ($lenght <= 0) {
                 $lenght = 160;
             }
             $text = '';
             if ($this->content['q_view']['raw']['acount'] > 0 and qa_opt('useo_meta_desc_ans_enable')) {
                 // get Selected Answer's content
                 if (isset($this->content["q_view"]["raw"]["selchildid"]) and qa_opt('useo_meta_desc_sel_ans_enable')) {
                     foreach ($this->content['a_list']['as'] as $answer) {
                         if ($answer['raw']['isselected']) {
                             $text = $answer['raw']['content'];
                         }
                     }
                 } else {
                     // get most voted Answer's content
                     $max_vote = 0;
                     // don't use answers with negative votes.
                     foreach ($this->content['a_list']['as'] as $answer) {
                         if ($answer['raw']['netvotes'] > $max_vote) {
                             $text = $answer['raw']['content'];
                             $max_vote = $answer['raw']['netvotes'];
                         }
                     }
                 }
             }
             if (!empty($text)) {
                 $excerpt = useo_get_excerpt($text, 0, $lenght);
                 $this->content['description'] = $excerpt;
             }
         }
         // Meta Tags and social meta tags
         if ($this->template == 'question') {
             if (qa_opt('useo_social_enable_editor')) {
                 foreach ($this->metas as $key => $value) {
                     if (isset($this->social_metas[$key])) {
                         $this->output('<meta ' . $value['type'] . ' content="' . $this->social_metas[$key] . '" />');
                     } else {
                         $this->output('<meta ' . $value['type'] . ($value['content'] ? ' content="' . $value['content'] . '"' : '') . ' /> ');
                     }
                 }
             } elseif (qa_opt('useo_social_og_enable_auto')) {
                 foreach ($this->metas as $key => $value) {
                     $this->output('<meta ' . $value['type'] . ($value['content'] ? ' content="' . $value['content'] . '"' : '') . ' /> ');
                 }
             }
         }
     }
 }