PageRenderTime 54ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/wp-content/plugins/all-in-one-seo-pack/aioseop.class.php

https://bitbucket.org/dkrzos/phc
PHP | 2446 lines | 2075 code | 222 blank | 149 comment | 317 complexity | 100cbdf00b00a925969b06ccee77ec11 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. class All_in_One_SEO_Pack {
  3. var $version = "1.6.15.2";
  4. /** Max numbers of chars in auto-generated description */
  5. var $maximum_description_length = 160;
  6. /** Minimum number of chars an excerpt should be so that it can be used
  7. * as description. Touch only if you know what you're doing
  8. */
  9. var $minimum_description_length = 1;
  10. var $ob_start_detected = false;
  11. var $title_start = -1;
  12. var $title_end = -1;
  13. /** The title before rewriting */
  14. var $orig_title = '';
  15. /** Temp filename for the latest version. */
  16. // var $upgrade_filename = 'temp.zip';
  17. /** Where to extract the downloaded newest version. */
  18. // var $upgrade_folder;
  19. /** Any error in upgrading. */
  20. // var $upgrade_error;
  21. /** Which zip to download in order to upgrade .*/
  22. // var $upgrade_url = 'http://downloads.wordpress.org/plugin/all-in-one-seo-pack.zip';
  23. /** Filename of log file. */
  24. var $log_file;
  25. /** Flag whether there should be logging. */
  26. var $do_log;
  27. var $wp_version;
  28. var $aioseop_op;
  29. //var $aioseop_options = get_option('aioseop_options');
  30. function All_in_One_SEO_Pack() {
  31. global $wp_version;
  32. global $aioseop_options;
  33. $this->wp_version = $wp_version;
  34. $this->log_file = dirname(__FILE__) . '/all_in_one_seo_pack.log';
  35. if ($aioseop_options['aiosp_do_log']) {
  36. $this->do_log = true;
  37. } else {
  38. $this->do_log = false;
  39. }
  40. // $this->upgrade_filename = dirname(__FILE__) . '/' . $this->upgrade_filename;
  41. // $this->upgrade_folder = dirname(__FILE__);
  42. }
  43. /*** Case conversion; handle non UTF-8 encodings and fallback ***/
  44. function convert_case( $str, $mode = 'upper' ) {
  45. static $charset = null;
  46. if ($charset == null) $charset = get_bloginfo( 'charset' );
  47. if ( $charset == 'UTF-8' ) {
  48. global $UTF8_TABLES;
  49. include_once( 'aioseop_utility.php' );
  50. }
  51. if ( $charset == 'UTF-8' && is_array($UTF8_TABLES) ) {
  52. if ( $mode == 'upper' ) return strtr( $str, $UTF8_TABLES['strtoupper'] );
  53. if ( $mode == 'lower' ) return strtr( $str, $UTF8_TABLES['strtolower'] );
  54. return $str;
  55. } else {
  56. if ( $mode == 'upper' && function_exists( 'mb_strtoupper' ) ) {
  57. return mb_strtoupper( $str, $charset );
  58. } elseif ( $mode == 'lower' && function_exists( 'mb_strtolower' ) ) {
  59. return mb_strtolower( $str, $charset );
  60. } else {
  61. if ( $mode == 'upper' ) return strtoupper( $str );
  62. if ( $mode == 'lower' ) return strtolower( $str );
  63. return $str;
  64. }
  65. }
  66. }
  67. /**
  68. * Convert a string to lower case
  69. * Compatible with mb_strtolower(), an UTF-8 friendly replacement for strtolower()
  70. */
  71. function strtolower( $str ) {
  72. return $this->convert_case( $str, 'lower' );
  73. }
  74. /**
  75. * Convert a string to upper case
  76. * Compatible with mb_strtoupper(), an UTF-8 friendly replacement for strtoupper()
  77. */
  78. function strtoupper( $str ) {
  79. return $this->convert_case( $str, 'upper' );
  80. }
  81. function template_redirect() {
  82. global $wp_query;
  83. global $aioseop_options;
  84. $post = $wp_query->get_queried_object();
  85. if( $this->aioseop_mrt_exclude_this_page()){
  86. return;
  87. }
  88. if (is_feed()) {
  89. return;
  90. }
  91. if (is_single() || is_page()) {
  92. $aiosp_disable = htmlspecialchars(stripcslashes(get_post_meta($post->ID, '_aioseop_disable', true)));
  93. if ($aiosp_disable) {
  94. return;
  95. }
  96. }
  97. if ($aioseop_options['aiosp_rewrite_titles']) {
  98. ob_start(array($this, 'output_callback_for_title'));
  99. }
  100. }
  101. function aioseop_mrt_exclude_this_page(){
  102. global $aioseop_options;
  103. $currenturl = trim($_SERVER['REQUEST_URI'],'/');
  104. /* echo "<br /><br />";
  105. echo $aioseop_options['aiosp_ex_pages'];
  106. echo "<br /><br />";
  107. */
  108. if ( !isset( $aioseop_options['aiosp_ex_pages'] ) ) $aioseop_options['aiosp_ex_pages'] = '';
  109. $excludedstuff = explode(',',$aioseop_options['aiosp_ex_pages']);
  110. foreach($excludedstuff as $exedd){
  111. //echo $exedd;
  112. $exedd = trim($exedd);
  113. if($exedd){
  114. if(stristr($currenturl, $exedd)){
  115. return true;
  116. }
  117. }
  118. }
  119. return false;
  120. }
  121. function output_callback_for_title($content) {
  122. return $this->rewrite_title($content);
  123. }
  124. //
  125. //CHECK IF ARRAY EXISTS IN DB, IF SO, GET ARRAY, ADD EVERYTHING, CHECK FOR ISSET?
  126. //
  127. function init() {
  128. if ( !defined('WP_PLUGIN_DIR') ) {
  129. load_plugin_textdomain('all_in_one_seo_pack', str_replace( ABSPATH, '', dirname(__FILE__)));
  130. } else {
  131. load_plugin_textdomain('all_in_one_seo_pack', false, dirname(plugin_basename(__FILE__)));
  132. }
  133. /*
  134. if (function_exists('load_plugin_textdomain')) {
  135. load_plugin_textdomain('all_in_one_seo_pack', WP_PLUGIN_DIR . '/all-in-one-seo-pack');
  136. }
  137. */
  138. }
  139. function is_static_front_page() {
  140. global $wp_query;
  141. global $aioseop_options;
  142. $post = $wp_query->get_queried_object();
  143. return get_option('show_on_front') == 'page' && is_page() && $post->ID == get_option('page_on_front');
  144. }
  145. function is_static_posts_page() {
  146. global $wp_query;
  147. $post = $wp_query->get_queried_object();
  148. return get_option('show_on_front') == 'page' && is_home() && $post->ID == get_option('page_for_posts');
  149. }
  150. function get_base() {
  151. return '/'.end(explode('/', str_replace(array('\\','/all_in_one_seo_pack.php'),array('/',''),__FILE__)));
  152. }
  153. function seo_mrt_admin_head() {
  154. $home = get_settings('siteurl');
  155. $stylesheet = AIOSEOP_PLUGIN_URL . 'style.css';
  156. echo '<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />';
  157. }
  158. function wp_head() {
  159. if (is_feed()) {
  160. return;
  161. }
  162. global $wp_query;
  163. global $aioseop_options;
  164. $post = $wp_query->get_queried_object();
  165. $meta_string = null;
  166. if($this->is_static_posts_page()){
  167. $title = strip_tags( apply_filters( 'single_post_title', $post->post_title ) );
  168. }
  169. //echo("wp_head() " . wp_title('', false) . " is_home() => " . is_home() . ", is_page() => " . is_page() . ", is_single() => " . is_single() . ", is_static_front_page() => " . $this->is_static_front_page() . ", is_static_posts_page() => " . $this->is_static_posts_page());
  170. if (is_single() || is_page()) {
  171. $aiosp_disable = htmlspecialchars(stripcslashes(get_post_meta($post->ID, '_aioseop_disable', true)));
  172. if ($aiosp_disable) {
  173. return;
  174. }
  175. }
  176. if( $this->aioseop_mrt_exclude_this_page()==TRUE ){
  177. return;
  178. }
  179. if ($aioseop_options['aiosp_rewrite_titles']) {
  180. // make the title rewrite as short as possible
  181. if (function_exists('ob_list_handlers')) {
  182. $active_handlers = ob_list_handlers();
  183. } else {
  184. $active_handlers = array();
  185. }
  186. if (sizeof($active_handlers) > 0 &&
  187. strtolower($active_handlers[sizeof($active_handlers) - 1]) ==
  188. strtolower('All_in_One_SEO_Pack::output_callback_for_title')) {
  189. ob_end_flush();
  190. } else {
  191. $this->log("another plugin interfering?");
  192. // if we get here there *could* be trouble with another plugin :(
  193. $this->ob_start_detected = true;
  194. if (function_exists('ob_list_handlers')) {
  195. foreach (ob_list_handlers() as $handler) {
  196. $this->log("detected output handler $handler");
  197. }
  198. }
  199. }
  200. }
  201. echo "\n<!-- All in One SEO Pack $this->version by Michael Torbert of Semper Fi Web Design";
  202. if ($this->ob_start_detected) {
  203. echo "ob_start_detected ";
  204. }
  205. echo "[$this->title_start,$this->title_end] ";
  206. echo "-->\n";
  207. $is_front_page = ( ( is_home() && $aioseop_options['aiosp_home_keywords'] && !$this->is_static_posts_page() ) || $this->is_static_front_page() );
  208. if ( $is_front_page ) {
  209. $keywords = trim($this->internationalize($aioseop_options['aiosp_home_keywords']));
  210. } elseif($this->is_static_posts_page() && !$aioseop_options['aiosp_dynamic_postspage_keywords']){ // and if option = use page set keywords instead of keywords from recent posts
  211. //$keywords = "posts keyyysss" . stripcslashes(get_post_meta($post->ID,'keywords',true));
  212. $keywords = stripcslashes($this->internationalize(get_post_meta($post->ID, "_aioseop_keywords", true)));
  213. // $keywords = $this->get_unique_keywords($keywords);
  214. } else {
  215. $keywords = $this->get_all_keywords();
  216. }
  217. if (is_single() || is_page() || $this->is_static_posts_page()) {
  218. if ($this->is_static_front_page()) {
  219. $description = trim(stripcslashes($this->internationalize($aioseop_options['aiosp_home_description'])));
  220. } else {
  221. $description = $this->get_post_description($post);
  222. $description = apply_filters('aioseop_description',$description);
  223. }
  224. } else if (is_home()) {
  225. $description = trim(stripcslashes($this->internationalize($aioseop_options['aiosp_home_description'])));
  226. } else if (is_category()) {
  227. $description = $this->internationalize(category_description());
  228. }
  229. if (isset($description) && (strlen($description) > $this->minimum_description_length) && !(is_home() && is_paged())) {
  230. $description = trim(strip_tags($description));
  231. $description = str_replace('"', '', $description);
  232. // replace newlines on mac / windows?
  233. $description = str_replace("\r\n", ' ', $description);
  234. // maybe linux uses this alone
  235. $description = str_replace("\n", ' ', $description);
  236. if (isset($meta_string)) {
  237. //$meta_string .= "\n";
  238. } else {
  239. $meta_string = '';
  240. }
  241. // description format
  242. $description_format = $aioseop_options['aiosp_description_format'];
  243. if (!isset($description_format) || empty($description_format)) {
  244. $description_format = "%description%";
  245. }
  246. $description = str_replace('%description%', apply_filters('aioseop_description_override', $description), $description_format);
  247. $description = str_replace('%blog_title%', get_bloginfo('name'), $description);
  248. $description = str_replace('%blog_description%', get_bloginfo('description'), $description);
  249. $description = str_replace('%wp_title%', $this->get_original_title(), $description);
  250. //$description = html_entity_decode($description, ENT_COMPAT, get_bloginfo('charset'));
  251. if($aioseop_options['aiosp_can'] && is_attachment()){
  252. $url = $this->aiosp_mrt_get_url($wp_query);
  253. if ($url) {
  254. preg_match_all('/(\d+)/', $url, $matches);
  255. if (is_array($matches)){
  256. $uniqueDesc = join('',$matches[0]);
  257. }
  258. }
  259. $description .= ' ' . $uniqueDesc;
  260. }
  261. $meta_string .= sprintf("<meta name=\"description\" content=\"%s\" />", $description);
  262. }
  263. $keywords = apply_filters('aioseop_keywords',$keywords);
  264. if (isset ($keywords) && !empty($keywords) && !(is_home() && is_paged())) {
  265. if (isset($meta_string)) {
  266. $meta_string .= "\n";
  267. }
  268. $keywords = str_replace('"','',$keywords);
  269. $meta_string .= sprintf("<meta name=\"keywords\" content=\"%s\" />", $keywords);
  270. }
  271. $is_tag = is_tag();
  272. if ((is_category() && $aioseop_options['aiosp_category_noindex']) || (!is_category() && is_archive() &&!$is_tag && $aioseop_options['aiosp_archive_noindex']) || ($aioseop_options['aiosp_tags_noindex'] && $is_tag)) {
  273. if (isset($meta_string)) {
  274. $meta_string .= "\n";
  275. }
  276. $meta_string .= '<meta name="robots" content="noindex,follow" />';
  277. }
  278. $page_meta = stripcslashes($aioseop_options['aiosp_page_meta_tags']);
  279. $post_meta = stripcslashes($aioseop_options['aiosp_post_meta_tags']);
  280. $home_meta = stripcslashes($aioseop_options['aiosp_home_meta_tags']);
  281. $front_meta = stripcslashes($aioseop_options['aiosp_front_meta_tags']);
  282. if ( is_page() && isset( $page_meta ) && !empty( $page_meta ) && ( !$is_front_page || empty( $front_meta ) ) ) {
  283. if ( isset( $meta_string ) ) $meta_string .= "\n";
  284. $meta_string .= $page_meta;
  285. }
  286. if (is_single() && isset($post_meta) && !empty($post_meta)) {
  287. if (isset($meta_string)) {
  288. $meta_string .= "\n";
  289. }
  290. $meta_string .= "$post_meta";
  291. }
  292. if ( !empty( $post ) && isset( $post->post_author ) )
  293. $googleplus = get_the_author_meta( 'googleplus', $post->post_author );
  294. if ( empty( $googleplus ) && !empty( $aioseop_options['aiosp_google_publisher'] ) )
  295. $googleplus = $aioseop_options['aiosp_google_publisher'];
  296. if ( is_singular() && ( $googleplus ) ) {
  297. $meta_string = '<link rel="author" href="' . $googleplus . '" />' . "\n" . $meta_string;
  298. } else if ( !is_home() && !empty( $aioseop_options['aiosp_google_publisher'] ) ) {
  299. $meta_string = '<link rel="author" href="' . $aioseop_options['aiosp_google_publisher'] . '" />' . "\n" . $meta_string;
  300. }
  301. if ( is_home() && !empty( $aioseop_options['aiosp_google_publisher'] ) )
  302. $meta_string = '<link rel="publisher" href="' . $aioseop_options['aiosp_google_publisher'] . '" />' . "\n" . $meta_string;
  303. if ( $is_front_page && !empty( $front_meta ) ) {
  304. if ( isset( $meta_string ) ) $meta_string .= "\n";
  305. $meta_string .= $front_meta;
  306. } else {
  307. if ( is_home() && !empty( $home_meta ) ) {
  308. if ( isset( $meta_string ) ) $meta_string .= "\n";
  309. $meta_string .= $home_meta;
  310. }
  311. }
  312. if ($meta_string != null) {
  313. echo "$meta_string\n";
  314. }
  315. if($aioseop_options['aiosp_can']){
  316. $url = $this->aiosp_mrt_get_url($wp_query);
  317. if ($url) {
  318. $url = apply_filters('aioseop_canonical_url',$url);
  319. echo "".'<link rel="canonical" href="'.$url.'" />'."\n";
  320. }
  321. }
  322. echo "<!-- /all in one seo pack -->\n";
  323. }
  324. function aiosp_google_analytics(){
  325. global $aioseop_options;
  326. ?>
  327. <script type="text/javascript">
  328. var _gaq = _gaq || [];
  329. _gaq.push(['_setAccount', '<?php echo $aioseop_options['aiosp_google_analytics_id']; ?>']);
  330. <?php if ( !empty( $aioseop_options['aiosp_ga_domain'] ) ) {
  331. ?> _gaq.push(['_setDomainName', '<?php echo $aioseop_options['aiosp_ga_domain']; ?>']);
  332. <?php
  333. }
  334. ?>
  335. _gaq.push(['_trackPageview']);
  336. (function() {
  337. var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  338. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  339. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  340. })();
  341. </script>
  342. <?php
  343. if ($aioseop_options['aiosp_ga_track_outbound_links']) {
  344. ?>
  345. <script type="text/javascript">
  346. function recordOutboundLink(link, category, action) {
  347. _gat._getTrackerByName()._trackEvent(category, action);
  348. if ( link.target == '_blank' ) return true;
  349. setTimeout('document.location = "' + link.href + '"', 100);
  350. return false;
  351. }
  352. /* use regular Javascript for this */
  353. function getAttr(ele, attr) {
  354. var result = (ele.getAttribute && ele.getAttribute(attr)) || null;
  355. if( !result ) {
  356. var attrs = ele.attributes;
  357. var length = attrs.length;
  358. for(var i = 0; i < length; i++)
  359. if(attr[i].nodeName === attr) result = attr[i].nodeValue;
  360. }
  361. return result;
  362. }
  363. window.onload = function () {
  364. var links = document.getElementsByTagName('a');
  365. for (var x=0; x < links.length; x++) {
  366. if (typeof links[x] == 'undefined') continue;
  367. if (typeof links[x].onclick != 'undefined') continue;
  368. links[x].onclick = function () {
  369. var mydomain = new RegExp(document.domain, 'i');
  370. href = getAttr(this, 'href');
  371. if(href && href.toLowerCase().indexOf('http') === 0 && !mydomain.test(href)) {
  372. recordOutboundLink(this, 'Outbound Links', href);
  373. }
  374. }
  375. }
  376. };
  377. </script>
  378. <?php
  379. }}
  380. // Thank you, Yoast de Valk, for much of this code.
  381. function aiosp_mrt_get_url($query) {
  382. global $aioseop_options;
  383. if ($query->is_404 || $query->is_search) {
  384. return false;
  385. }
  386. $haspost = count($query->posts) > 0;
  387. $has_ut = function_exists('user_trailingslashit');
  388. if (get_query_var('m')) {
  389. $m = preg_replace('/[^0-9]/', '', get_query_var('m'));
  390. switch (strlen($m)) {
  391. case 4:
  392. $link = get_year_link($m);
  393. break;
  394. case 6:
  395. $link = get_month_link(substr($m, 0, 4), substr($m, 4, 2));
  396. break;
  397. case 8:
  398. $link = get_day_link(substr($m, 0, 4), substr($m, 4, 2), substr($m, 6, 2));
  399. break;
  400. default:
  401. return false;
  402. }
  403. } elseif (($query->is_single || $query->is_page) && $haspost) {
  404. $post = $query->posts[0];
  405. $link = get_permalink($post->ID);
  406. $link = $this->yoast_get_paged($link);
  407. } elseif (($query->is_single || $query->is_page) && $haspost) {
  408. $post = $query->posts[0];
  409. $link = get_permalink($post->ID);
  410. $link = $this->yoast_get_paged($link);
  411. } elseif ($query->is_author && $haspost) {
  412. global $wp_version;
  413. if ($wp_version >= '2') {
  414. $author = get_userdata(get_query_var('author'));
  415. if ($author === false)
  416. return false;
  417. $link = get_author_link(false, $author->ID, $author->user_nicename);
  418. } else {
  419. global $cache_userdata;
  420. $userid = get_query_var('author');
  421. $link = get_author_link(false, $userid, $cache_userdata[$userid]->user_nicename);
  422. }
  423. } elseif ($query->is_category && $haspost) {
  424. $link = get_category_link(get_query_var('cat'));
  425. $link = $this->yoast_get_paged($link);
  426. } else if ($query->is_tag && $haspost) {
  427. $tag = get_term_by('slug',get_query_var('tag'),'post_tag');
  428. if (!empty($tag->term_id)) {
  429. $link = get_tag_link($tag->term_id);
  430. }
  431. $link = $this->yoast_get_paged($link);
  432. } elseif ($query->is_day && $haspost) {
  433. $link = get_day_link(get_query_var('year'),
  434. get_query_var('monthnum'),
  435. get_query_var('day'));
  436. } elseif ($query->is_month && $haspost) {
  437. $link = get_month_link(get_query_var('year'),
  438. get_query_var('monthnum'));
  439. } elseif ($query->is_year && $haspost) {
  440. $link = get_year_link(get_query_var('year'));
  441. } elseif ($query->is_home) {
  442. if ((get_option('show_on_front') == 'page') &&
  443. ($pageid = get_option('page_for_posts'))) {
  444. $link = get_permalink($pageid);
  445. $link = $this->yoast_get_paged($link);
  446. $link = trailingslashit($link);
  447. } else {
  448. if ( function_exists( 'icl_get_home_url' ) ) {
  449. $link = icl_get_home_url();
  450. } else {
  451. $link = get_option( 'home' );
  452. }
  453. $link = $this->yoast_get_paged($link);
  454. $link = trailingslashit($link);
  455. }
  456. } elseif ($query->is_tax && $haspost ) {
  457. $taxonomy = get_query_var( 'taxonomy' );
  458. $term = get_query_var( 'term' );
  459. $link = get_term_link( $term, $taxonomy );
  460. $link = $this->yoast_get_paged( $link );
  461. } elseif ( $query->is_archive && function_exists( 'get_post_type_archive_link' ) && ( $post_type = get_query_var( 'post_type' ) ) ) {
  462. $link = get_post_type_archive_link( $post_type );
  463. } else {
  464. return false;
  465. }
  466. return $link;
  467. }
  468. function yoast_get_paged($link) {
  469. $page = get_query_var('paged');
  470. if ($page && $page > 1) {
  471. $link = trailingslashit($link) ."page/". "$page";
  472. if ($has_ut) {
  473. $link = user_trailingslashit($link, 'paged');
  474. } else {
  475. $link .= '/';
  476. }
  477. }
  478. return $link;
  479. }
  480. function get_post_description($post) {
  481. global $aioseop_options;
  482. $description = trim(stripcslashes($this->internationalize(get_post_meta($post->ID, "_aioseop_description", true))));
  483. if (!$description) {
  484. $description = $this->trim_excerpt_without_filters_full_length($this->internationalize($post->post_excerpt));
  485. if (!$description && $aioseop_options["aiosp_generate_descriptions"]) {
  486. $description = $this->trim_excerpt_without_filters($this->internationalize($post->post_content));
  487. }
  488. }
  489. // "internal whitespace trim"
  490. $description = preg_replace("/\s\s+/u", " ", $description);
  491. return $description;
  492. }
  493. function replace_title($content, $title) {
  494. $title = trim(strip_tags($title));
  495. $title_tag_start = "<title>";
  496. $title_tag_end = "</title>";
  497. $len_start = strlen($title_tag_start);
  498. $len_end = strlen($title_tag_end);
  499. $title = stripcslashes(trim($title));
  500. $start = strpos($content, $title_tag_start);
  501. $end = strpos($content, $title_tag_end);
  502. $this->title_start = $start;
  503. $this->title_end = $end;
  504. $this->orig_title = $title;
  505. if ($start && $end) {
  506. $header = substr($content, 0, $start + $len_start) . $title . substr($content, $end);
  507. } else {
  508. // this breaks some sitemap plugins (like wpg2)
  509. //$header = $content . "<title>$title</title>";
  510. $header = $content;
  511. }
  512. return $header;
  513. }
  514. function internationalize($in) {
  515. if (function_exists('langswitch_filter_langs_with_message')) {
  516. $in = langswitch_filter_langs_with_message($in);
  517. }
  518. if (function_exists('polyglot_filter')) {
  519. $in = polyglot_filter($in);
  520. }
  521. if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) {
  522. $in = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($in);
  523. }
  524. $in = apply_filters('localization', $in);
  525. return $in;
  526. }
  527. /** @return The original title as delivered by WP (well, in most cases) */
  528. function get_original_title() {
  529. global $wp_query;
  530. global $aioseop_options;
  531. if (!$wp_query) {
  532. return null;
  533. }
  534. $post = $wp_query->get_queried_object();
  535. // the_search_query() is not suitable, it cannot just return
  536. global $s;
  537. $title = null;
  538. if (is_home()) {
  539. $title = get_option('blogname');
  540. } else if (is_single()) {
  541. $title = $this->internationalize(wp_title('', false));
  542. } else if (is_search() && isset($s) && !empty($s)) {
  543. $search = esc_attr(stripcslashes($s));
  544. $search = $this->capitalize($search);
  545. $title = $search;
  546. } else if (is_category() && !is_feed()) {
  547. $category_description = $this->internationalize(category_description());
  548. $category_name = ucwords($this->internationalize(single_cat_title('', false)));
  549. $title = $category_name;
  550. } else if (is_page()) {
  551. $title = $this->internationalize(wp_title('', false));
  552. } else if (is_tag()) {
  553. global $utw;
  554. if ($utw) {
  555. $tags = $utw->GetCurrentTagSet();
  556. $tag = $tags[0]->tag;
  557. $tag = str_replace('-', ' ', $tag);
  558. } else {
  559. // wordpress > 2.3
  560. $tag = $this->internationalize(wp_title('', false));
  561. }
  562. if ($tag) {
  563. $title = $tag;
  564. }
  565. } else if (is_archive()) {
  566. $title = $this->internationalize(wp_title('', false));
  567. } else if (is_404()) {
  568. $title_format = $aioseop_options['aiosp_404_title_format'];
  569. $new_title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
  570. $new_title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $new_title);
  571. $new_title = str_replace('%request_url%', $_SERVER['REQUEST_URI'], $new_title);
  572. $new_title = str_replace('%request_words%', $this->request_as_words($_SERVER['REQUEST_URI']), $new_title);
  573. $title = $new_title;
  574. }
  575. return trim($title);
  576. }
  577. function paged_title($title) {
  578. // the page number if paged
  579. global $paged;
  580. global $aioseop_options;
  581. // simple tagging support
  582. global $STagging;
  583. if (is_paged() || (isset($STagging) && $STagging->is_tag_view() && $paged)) {
  584. $part = $this->internationalize($aioseop_options['aiosp_paged_format']);
  585. if (isset($part) || !empty($part)) {
  586. $part = " " . trim($part);
  587. $part = str_replace('%page%', $paged, $part);
  588. $this->log("paged_title() [$title] [$part]");
  589. $title .= $part;
  590. }
  591. }
  592. return $title;
  593. }
  594. function rewrite_title($header) {
  595. global $aioseop_options;
  596. global $wp_query;
  597. if (!$wp_query) {
  598. $header .= "<!-- no wp_query found! -->\n";
  599. return $header;
  600. }
  601. $post = $wp_query->get_queried_object();
  602. // the_search_query() is not suitable, it cannot just return
  603. global $s;
  604. global $STagging;
  605. if (is_home() && !$this->is_static_posts_page()) {
  606. $title = $this->internationalize($aioseop_options['aiosp_home_title']);
  607. if (empty($title)) {
  608. $title = $this->internationalize(get_option('blogname'));
  609. }
  610. $title = $this->paged_title($title);
  611. $header = $this->replace_title($header, $title);
  612. } else if (is_attachment()) {
  613. $title = get_the_title($post->post_parent).' '.$post->post_title.' – '.get_option('blogname');
  614. $header = $this->replace_title($header,$title);
  615. } else if (is_single()) {
  616. // we're not in the loop :(
  617. $authordata = get_userdata($post->post_author);
  618. $categories = get_the_category();
  619. $category = '';
  620. if (count($categories) > 0) {
  621. $category = $categories[0]->cat_name;
  622. }
  623. $title = $this->internationalize(get_post_meta($post->ID, "_aioseop_title", true));
  624. if (!$title) {
  625. $title = $this->internationalize(get_post_meta($post->ID, "title_tag", true));
  626. if (!$title) {
  627. $title = $this->internationalize(wp_title('', false));
  628. }
  629. }
  630. $title_format = $aioseop_options['aiosp_post_title_format'];
  631. /*
  632. $new_title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
  633. $new_title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $new_title);
  634. $new_title = str_replace('%post_title%', $title, $new_title);
  635. $new_title = str_replace('%category%', $category, $new_title);
  636. $new_title = str_replace('%category_title%', $category, $new_title);
  637. $new_title = str_replace('%post_author_login%', $authordata->user_login, $new_title);
  638. $new_title = str_replace('%post_author_nicename%', $authordata->user_nicename, $new_title);
  639. $new_title = str_replace('%post_author_firstname%', ucwords($authordata->first_name), $new_title);
  640. $new_title = str_replace('%post_author_lastname%', ucwords($authordata->last_name), $new_title);
  641. */
  642. $r_title = array('%blog_title%','%blog_description%','%post_title%','%category%','%category_title%','%post_author_login%','%post_author_nicename%','%post_author_firstname%','%post_author_lastname%');
  643. $d_title = array($this->internationalize(get_bloginfo('name')),$this->internationalize(get_bloginfo('description')),$title, $category, $category, $authordata->user_login, $authordata->user_nicename, ucwords($authordata->first_name), ucwords($authordata->last_name));
  644. $title = trim(str_replace($r_title, $d_title, $title_format));
  645. // $title = $new_title;
  646. // $title = trim($title);
  647. $title = apply_filters('aioseop_title_single',$title);
  648. $header = $this->replace_title($header, $title);
  649. } else if (is_search() && isset($s) && !empty($s)) {
  650. $search = esc_attr(stripcslashes($s));
  651. $search = $this->capitalize($search);
  652. $title_format = $aioseop_options['aiosp_search_title_format'];
  653. $title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
  654. $title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $title);
  655. $title = str_replace('%search%', $search, $title);
  656. $header = $this->replace_title($header, $title);
  657. } else if (is_category() && !is_feed()) {
  658. $category_description = $this->internationalize(category_description());
  659. if($aioseop_options['aiosp_cap_cats']){
  660. $category_name = ucwords($this->internationalize(single_cat_title('', false)));
  661. }else{
  662. $category_name = $this->internationalize(single_cat_title('', false));
  663. }
  664. //$category_name = ucwords($this->internationalize(single_cat_title('', false)));
  665. $title_format = $aioseop_options['aiosp_category_title_format'];
  666. $title = str_replace('%category_title%', $category_name, $title_format);
  667. $title = str_replace('%category_description%', $category_description, $title);
  668. $title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title);
  669. $title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $title);
  670. $title = $this->paged_title($title);
  671. $header = $this->replace_title($header, $title);
  672. } else if (is_page() || $this->is_static_posts_page()) {
  673. // we're not in the loop :(
  674. $authordata = get_userdata($post->post_author);
  675. if ($this->is_static_front_page()) {
  676. if ($this->internationalize($aioseop_options['aiosp_home_title'])) {
  677. //home title filter
  678. $home_title = $this->internationalize($aioseop_options['aiosp_home_title']);
  679. $home_title = apply_filters('aioseop_home_page_title',$home_title);
  680. $header = $this->replace_title($header, $home_title);
  681. }
  682. } else {
  683. $title = $this->internationalize(get_post_meta($post->ID, "_aioseop_title", true));
  684. if (!$title) {
  685. $title = $this->internationalize(wp_title('', false));
  686. }
  687. $title_format = $aioseop_options['aiosp_page_title_format'];
  688. $new_title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
  689. $new_title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $new_title);
  690. $new_title = str_replace('%page_title%', $title, $new_title);
  691. $new_title = str_replace('%page_author_login%', $authordata->user_login, $new_title);
  692. $new_title = str_replace('%page_author_nicename%', $authordata->user_nicename, $new_title);
  693. $new_title = str_replace('%page_author_firstname%', ucwords($authordata->first_name), $new_title);
  694. $new_title = str_replace('%page_author_lastname%', ucwords($authordata->last_name), $new_title);
  695. $title = trim($new_title);
  696. $title = $this->paged_title($title);
  697. $title = apply_filters('aioseop_title_page',$title);
  698. $header = $this->replace_title($header, $title);
  699. }
  700. } else if (is_tag()) {
  701. global $utw;
  702. if ($utw) {
  703. $tags = $utw->GetCurrentTagSet();
  704. $tag = $tags[0]->tag;
  705. $tag = str_replace('-', ' ', $tag);
  706. } else {
  707. // wordpress > 2.3
  708. $tag = $this->internationalize(wp_title('', false));
  709. }
  710. if ($tag) {
  711. $tag = $this->capitalize($tag);
  712. $title_format = $aioseop_options['aiosp_tag_title_format'];
  713. $title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
  714. $title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $title);
  715. $title = str_replace('%tag%', $tag, $title);
  716. $title = $this->paged_title($title);
  717. $header = $this->replace_title($header, $title);
  718. }
  719. } else if (isset($STagging) && $STagging->is_tag_view()) { // simple tagging support
  720. $tag = $STagging->search_tag;
  721. if ($tag) {
  722. $tag = $this->capitalize($tag);
  723. $title_format = $aioseop_options['aiosp_tag_title_format'];
  724. $title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
  725. $title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $title);
  726. $title = str_replace('%tag%', $tag, $title);
  727. $title = $this->paged_title($title);
  728. $header = $this->replace_title($header, $title);
  729. }
  730. } else if (is_archive()) {
  731. $date = $this->internationalize(wp_title('', false));
  732. $title_format = $aioseop_options['aiosp_archive_title_format'];
  733. $new_title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
  734. $new_title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $new_title);
  735. $new_title = str_replace('%date%', $date, $new_title);
  736. $title = trim($new_title);
  737. $title = $this->paged_title($title);
  738. $header = $this->replace_title($header, $title);
  739. } else if (is_404()) {
  740. $title_format = $aioseop_options['aiosp_404_title_format'];
  741. $new_title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
  742. $new_title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $new_title);
  743. $new_title = str_replace('%request_url%', $_SERVER['REQUEST_URI'], $new_title);
  744. $new_title = str_replace('%request_words%', $this->request_as_words($_SERVER['REQUEST_URI']), $new_title);
  745. $new_title = str_replace('%404_title%', $this->internationalize(wp_title('', false)), $new_title);
  746. $header = $this->replace_title($header, $new_title);
  747. }
  748. return $header;
  749. }
  750. /**
  751. * @return User-readable nice words for a given request.
  752. */
  753. function request_as_words($request) {
  754. $request = htmlspecialchars($request);
  755. $request = str_replace('.html', ' ', $request);
  756. $request = str_replace('.htm', ' ', $request);
  757. $request = str_replace('.', ' ', $request);
  758. $request = str_replace('/', ' ', $request);
  759. $request_a = explode(' ', $request);
  760. $request_new = array();
  761. foreach ($request_a as $token) {
  762. $request_new[] = ucwords(trim($token));
  763. }
  764. $request = implode(' ', $request_new);
  765. return $request;
  766. }
  767. function capitalize($s) {
  768. $s = trim($s);
  769. $tokens = explode(' ', $s);
  770. while (list($key, $val) = each($tokens)) {
  771. $tokens[$key] = trim($tokens[$key]);
  772. $tokens[$key] = strtoupper(substr($tokens[$key], 0, 1)) . substr($tokens[$key], 1);
  773. }
  774. $s = implode(' ', $tokens);
  775. return $s;
  776. }
  777. function trim_excerpt_without_filters($text) {
  778. $text = str_replace(']]>', ']]&gt;', $text);
  779. $text = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $text );
  780. $text = strip_tags($text);
  781. $max = $this->maximum_description_length;
  782. if ($max < strlen($text)) {
  783. while($text[$max] != ' ' && $max > $this->minimum_description_length) {
  784. $max--;
  785. }
  786. }
  787. $text = substr($text, 0, $max);
  788. return trim(stripcslashes($text));
  789. }
  790. function trim_excerpt_without_filters_full_length($text) {
  791. $text = str_replace(']]>', ']]&gt;', $text);
  792. $text = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $text );
  793. $text = strip_tags($text);
  794. return trim(stripcslashes($text));
  795. }
  796. /**
  797. * @return comma-separated list of unique keywords
  798. */
  799. function get_all_keywords() {
  800. global $posts;
  801. global $aioseop_options;
  802. if (is_404()) {
  803. return null;
  804. }
  805. // if we are on synthetic pages
  806. if (!is_home() && !is_page() && !is_single() &&!$this->is_static_front_page() && !$this->is_static_posts_page()) {
  807. return null;
  808. }
  809. $keywords = array();
  810. if (is_array($posts)) {
  811. foreach ($posts as $post) {
  812. if ($post) {
  813. // custom field keywords
  814. $keywords_a = $keywords_i = null;
  815. $description_a = $description_i = null;
  816. $id = (is_attachment())?($post->post_parent):($post->ID); // if attachment then use parent post id
  817. $keywords_i = stripcslashes($this->internationalize(get_post_meta($id, "_aioseop_keywords", true)));
  818. //$id = $post->ID;
  819. //$keywords_i = stripcslashes($this->internationalize(get_post_meta($post->ID, "_aioseop_keywords", true)));
  820. $keywords_i = str_replace('"', '', $keywords_i);
  821. if (isset($keywords_i) && !empty($keywords_i)) {
  822. $traverse = explode(',', $keywords_i);
  823. foreach ($traverse as $keyword) {
  824. $keywords[] = $keyword;
  825. }
  826. }
  827. // WP 2.3 tags
  828. if ($aioseop_options['aiosp_use_tags_as_keywords']){
  829. if (function_exists('get_the_tags')) {
  830. //$tags = get_the_tags($post->ID);
  831. $tags = get_the_tags($id);
  832. if ($tags && is_array($tags)) {
  833. foreach ($tags as $tag) {
  834. $keywords[] = $this->internationalize($tag->name);
  835. }
  836. }
  837. }
  838. }
  839. // Ultimate Tag Warrior integration
  840. global $utw;
  841. if ($utw) {
  842. $tags = $utw->GetTagsForPost($post);
  843. if (is_array($tags)) {
  844. foreach ($tags as $tag) {
  845. $tag = $tag->tag;
  846. $tag = str_replace('_',' ', $tag);
  847. $tag = str_replace('-',' ',$tag);
  848. $tag = stripcslashes($tag);
  849. $keywords[] = $tag;
  850. }
  851. }
  852. }
  853. // autometa
  854. $autometa = stripcslashes(get_post_meta($id, 'autometa', true));
  855. //$autometa = stripcslashes(get_post_meta($post->ID, "autometa", true));
  856. if (isset($autometa) && !empty($autometa)) {
  857. $autometa_array = explode(' ', $autometa);
  858. foreach ($autometa_array as $e) {
  859. $keywords[] = $e;
  860. }
  861. }
  862. if ($aioseop_options['aiosp_use_categories'] && !is_page()) {
  863. $categories = get_the_category($id);
  864. //$categories = get_the_category($post->ID);
  865. foreach ($categories as $category) {
  866. $keywords[] = $this->internationalize($category->cat_name);
  867. }
  868. }
  869. }
  870. }
  871. }
  872. return $this->get_unique_keywords($keywords);
  873. }
  874. function get_meta_keywords() {
  875. global $posts;
  876. $keywords = array();
  877. if (is_array($posts)) {
  878. foreach ($posts as $post) {
  879. if ($post) {
  880. // custom field keywords
  881. $keywords_a = $keywords_i = null;
  882. $description_a = $description_i = null;
  883. $id = $post->ID;
  884. $keywords_i = stripcslashes(get_post_meta($post->ID, "_aioseop_keywords", true));
  885. $keywords_i = str_replace('"', '', $keywords_i);
  886. if (isset($keywords_i) && !empty($keywords_i)) {
  887. $keywords[] = $keywords_i;
  888. }
  889. }
  890. }
  891. }
  892. return $this->get_unique_keywords($keywords);
  893. }
  894. function get_unique_keywords($keywords) {
  895. $small_keywords = array();
  896. foreach ($keywords as $word) {
  897. if (function_exists('mb_strtolower'))
  898. $small_keywords[] = mb_strtolower($word, get_bloginfo('charset'));
  899. else
  900. $small_keywords[] = $this->strtolower($word);
  901. }
  902. $keywords_ar = array_unique($small_keywords);
  903. return implode(',', $keywords_ar);
  904. }
  905. function get_url($url) {
  906. if (function_exists('file_get_contents')) {
  907. $file = file_get_contents($url);
  908. } else {
  909. $curl = curl_init($url);
  910. curl_setopt($curl, CURLOPT_HEADER, 0);
  911. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  912. $file = curl_exec($curl);
  913. curl_close($curl);
  914. }
  915. return $file;
  916. }
  917. function log($message) {
  918. if ($this->do_log) {
  919. error_log(date('Y-m-d H:i:s') . " " . $message . "\n", 3, $this->log_file);
  920. }
  921. }
  922. function download_newest_version() {
  923. $success = true;
  924. $file_content = $this->get_url($this->upgrade_url);
  925. if ($file_content === false) {
  926. $this->upgrade_error = sprintf(__("Could not download distribution (%s)"), $this->upgrade_url);
  927. $success = false;
  928. } else if (strlen($file_content) < 100) {
  929. $this->upgrade_error = sprintf(__("Could not download distribution (%s): %s"), $this->upgrade_url, $file_content);
  930. $success = false;
  931. } else {
  932. $this->log(sprintf("filesize of download ZIP: %d", strlen($file_content)));
  933. $fh = @fopen($this->upgrade_filename, 'w');
  934. $this->log("fh is $fh");
  935. if (!$fh) {
  936. $this->upgrade_error = sprintf(__("Could not open %s for writing"), $this->upgrade_filename);
  937. $this->upgrade_error .= "<br />";
  938. $this->upgrade_error .= sprintf(__("Please make sure %s is writable"), $this->upgrade_folder);
  939. $success = false;
  940. } else {
  941. $bytes_written = @fwrite($fh, $file_content);
  942. $this->log("wrote $bytes_written bytes");
  943. if (!$bytes_written) {
  944. $this->upgrade_error = sprintf(__("Could not write to %s"), $this->upgrade_filename);
  945. $success = false;
  946. }
  947. }
  948. if ($success) {
  949. fclose($fh);
  950. }
  951. }
  952. return $success;
  953. }
  954. function install_newest_version() {
  955. $success = $this->download_newest_version();
  956. if ($success) {
  957. $success = $this->extract_plugin();
  958. unlink($this->upgrade_filename);
  959. }
  960. return $success;
  961. }
  962. function extract_plugin() {
  963. if (!class_exists('PclZip')) {
  964. require_once ('pclzip.lib.php');
  965. }
  966. $archive = new PclZip($this->upgrade_filename);
  967. $files = $archive->extract(PCLZIP_OPT_STOP_ON_ERROR, PCLZIP_OPT_REPLACE_NEWER, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_PATH, $this->upgrade_folder);
  968. $this->log("files is $files");
  969. if (is_array($files)) {
  970. $num_extracted = sizeof($files);
  971. $this->log("extracted $num_extracted files to $this->upgrade_folder");
  972. $this->log(print_r($files, true));
  973. return true;
  974. } else {
  975. $this->upgrade_error = $archive->errorInfo();
  976. return false;
  977. }
  978. }
  979. /** crude approximization of whether current user is an admin */
  980. function is_admin() {
  981. return current_user_can('level_8');
  982. }
  983. function is_directory_writable($directory) {
  984. $filename = $directory . '/' . 'tmp_file_' . time();
  985. $fh = @fopen($filename, 'w');
  986. if (!$fh) {
  987. return false;
  988. }
  989. $written = fwrite($fh, "test");
  990. fclose($fh);
  991. unlink($filename);
  992. if ($written) {
  993. return true;
  994. } else {
  995. return false;
  996. }
  997. }
  998. function is_upgrade_directory_writable() {
  999. //return $this->is_directory_writable($this->upgrade_folder);
  1000. // let's assume it is
  1001. return true;
  1002. }
  1003. function post_meta_tags($id) {
  1004. $awmp_edit = $_POST["aiosp_edit"];
  1005. $nonce = $_POST['nonce-aioseop-edit'];
  1006. // if (!wp_verify_nonce($nonce, 'edit-aioseop-nonce')) die ( 'Security Check - If you receive this in error, log out and back in to WordPress');
  1007. if (isset($awmp_edit) && !empty($awmp_edit) && wp_verify_nonce($nonce, 'edit-aioseop-nonce')) {
  1008. foreach (Array('keywords', 'description', 'title', 'meta', 'disable', 'titleatr', 'menulabel', 'togglekeywords') as $f) {
  1009. $field = "aiosp_$f";
  1010. if ( isset( $_POST[$field] ) ) $$field = $_POST[$field];
  1011. }
  1012. if ( isset( $aiosp_keywords ) ) $keywords = $aiosp_keywords;
  1013. if ( isset( $aiosp_description ) ) $description = $aiosp_description;
  1014. if ( isset( $aiosp_title ) ) $title = $aiosp_title;
  1015. delete_post_meta($id, '_aioseop_keywords');
  1016. delete_post_meta($id, '_aioseop_description');
  1017. delete_post_meta($id, '_aioseop_title');
  1018. delete_post_meta($id, '_aioseop_titleatr');
  1019. delete_post_meta($id, '_aioseop_menulabel');
  1020. if ($this->is_admin()) {
  1021. delete_post_meta($id, '_aioseop_disable');
  1022. }
  1023. //delete_post_meta($id, 'aiosp_meta');
  1024. if (isset($keywords) && !empty($keywords)) {
  1025. add_post_meta($id, '_aioseop_keywords', $keywords);
  1026. }
  1027. if (isset($description) && !empty($description)) {
  1028. add_post_meta($id, '_aioseop_description', $description);
  1029. }
  1030. if (isset($title) && !empty($title)) {
  1031. add_post_meta($id, '_aioseop_title', $title);
  1032. }
  1033. if (isset($aiosp_titleatr) && !empty($aiosp_titleatr)) {
  1034. add_post_meta($id, '_aioseop_titleatr', $aiosp_titleatr);
  1035. }
  1036. if (isset($aiosp_menulabel) && !empty($aiosp_menulabel)) {
  1037. add_post_meta($id, '_aioseop_menulabel', $aiosp_menulabel);
  1038. }
  1039. if (isset($aiosp_disable) && !empty($aiosp_disable) && $this->is_admin()) {
  1040. add_post_meta($id, '_aioseop_disable', $aiosp_disable);
  1041. }
  1042. /*
  1043. if (isset($aiosp_meta) && !empty($aiosp_meta)) {
  1044. add_post_meta($id, 'aiosp_meta', $aiosp_meta);
  1045. }
  1046. */
  1047. }
  1048. }
  1049. function edit_category($id) {
  1050. global $wpdb;
  1051. $id = $wpdb->escape($id);
  1052. $awmp_edit = $_POST["aiosp_edit"];
  1053. if (isset($awmp_edit) && !empty($awmp_edit)) {
  1054. $keywords = $wpdb->escape($_POST["aiosp_keywords"]);
  1055. $title = $wpdb->escape($_POST["aiosp_title"]);
  1056. $old_category = $wpdb->get_row("select * from $this->table_categories where category_id=$id", OBJECT);
  1057. if ($old_category) {
  1058. $wpdb->query($wpdb->prepare("update $this->table_categories
  1059. set meta_title='$title', meta_keywords='$keywords'
  1060. where category_id=$id"));
  1061. } else {
  1062. $wpdb->query($wpdb->prepare("insert into $this->table_categories(meta_title, meta_keywords, category_id)
  1063. values ('$title', '$keywords', $id"));
  1064. }
  1065. //$wpdb->query($wpdb->prepare("insert into $this->table_categories"))
  1066. /*
  1067. delete_post_meta($id, 'keywords');
  1068. delete_post_meta($id, 'description');
  1069. delete_post_meta($id, 'title');
  1070. if (isset($keywords) && !empty($keywords)) {
  1071. add_post_meta($id, 'keywords', $keywords);
  1072. }
  1073. if (isset($description) && !empty($description)) {
  1074. add_post_meta($id, 'description', $description);
  1075. }
  1076. if (isset($title) && !empty($title)) {
  1077. add_post_meta($id, 'title', $title);
  1078. }
  1079. */
  1080. }
  1081. }
  1082. /**
  1083. * @deprecated This was for the feature of dedicated meta tags for categories which never went mainstream.
  1084. */
  1085. function edit_category_form() {
  1086. global $post;
  1087. $keywords = stripcslashes(get_post_meta($post->ID, '_aioseop_keywords', true));
  1088. $title = stripcslashes(get_post_meta($post->ID, '_aioseop_title', true));
  1089. $description = stripcslashes(get_post_meta($post->ID, '_aioseop_description', true));
  1090. ?>
  1091. <input value="aiosp_edit" type="hidden" name="aiosp_edit" />
  1092. <table class="editform" width="100%" cellspacing="2" cellpadding="5">
  1093. <tr>
  1094. <th width="33%" scope="row" valign="top">
  1095. <a href="http://wp.uberdose.com/2007/03/24/all-in-one-seo-pack/"><?php _e('All in One SEO Pack', 'all_in_one_seo_pack') ?></a>
  1096. </th>
  1097. </tr>
  1098. <tr>
  1099. <th width="33%" scope="row" valign="top"><label for="aiosp_title"><?php _e('Title:', 'all_in_one_seo_pack') ?></label></th>
  1100. <td><input value="<?php echo $title ?>" type="text" name="aiosp_title" size="70"/></td>
  1101. </tr>
  1102. <tr>
  1103. <th width="33%" scope="row" valign="top"><label for="aiosp_keywords"><?php _e('Keywords (comma separated):', 'all_in_one_seo_pack') ?></label></th>
  1104. <td><input value="<?php echo $keywords ?>" type="text" name="aiosp_keywords" size="70"/></td>
  1105. </tr>
  1106. </table>
  1107. <?php
  1108. }
  1109. function add_meta_tags_textinput() {
  1110. global $post;
  1111. $post_id = $post;
  1112. if (is_object($post_id)) {
  1113. $post_id = $post_id->ID;
  1114. }
  1115. $keywords = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_keywords', true)));
  1116. $title = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_title', true)));
  1117. $description = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_description', true)));
  1118. $aiosp_meta = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_meta', true)));
  1119. $aiosp_disable = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_disable', true)));
  1120. $aiosp_titleatr = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_titleatr', true)));
  1121. $aiosp_menulabel = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_menulabel', true)));
  1122. ?>
  1123. <SCRIPT LANGUAGE="JavaScript">
  1124. <!-- Begin
  1125. function countChars(field,cntfield) {
  1126. cntfield.value = field.value.length;
  1127. }
  1128. // End -->
  1129. </script>
  1130. <div id="postaiosp" class="postbox closed">
  1131. <h3><?php _e('All in One SEO Pack', 'all_in_one_seo_pack') ?></h3>
  1132. <div class="inside">
  1133. <div id="postaiosp">
  1134. <a target="__blank" href="http://semperfiwebdesign.com/portfolio/wordpress/wordpress-plugins/all-in-one-seo-pack/"><?php _e('Click here for Support', 'all_in_one_seo_pack') ?></a>
  1135. <input value="aiosp_edit" type="hidden" name="aiosp_edit" />
  1136. <table style="margin-bottom:40px">
  1137. <tr>
  1138. <th style="text-align:left;" colspan="2">
  1139. </th>
  1140. </tr>
  1141. <tr>
  1142. <th scope="row" style="text-align:right;"><?php _e('Title:', 'all_in_one_seo_pack') ?></th>
  1143. <td><input value="<?php echo $title ?>" type="text" name="aiosp_title" size="62"/></td>
  1144. </tr>
  1145. <tr>
  1146. <th scope="row" style="text-align:right;"><?php _e('Description:', 'all_in_one_seo_pack') ?></th>
  1147. <td><textarea name="aiosp_description" rows="1" cols="60" onKeyDown="countChars(document.post.aiosp_description,document.post.length1)" onKeyUp="countChars(document.post.aiosp_description,document.post.length1)"><?php echo $description ?>
  1148. </textarea><br />
  1149. <input readonly type="text" name="length1" size="3" maxlength="3" value="<?php echo strlen($description);?>" />
  1150. <?php _e(' characters. Most search engines use a maximum of 160 chars for the description.', 'all_in_one_seo_pack') ?>
  1151. </td>
  1152. </tr>
  1153. <tr>
  1154. <th scope="row" style="text-align:right;"><?php _e('Keywords (comma separated):', 'all_in_one_seo_pack') ?></th>
  1155. <td><input value="<?php echo $keywords ?>" type="text" name="aiosp_keywords" size="62"/></td>
  1156. </tr>
  1157. <input type="hidden" name="nonce-aioseop-edit" value="<?php echo wp_create_nonce('edit-aioseop-nonce'); ?>" />
  1158. <?php if ($this->is_admin()) { ?>
  1159. <tr>
  1160. <th scope="row" style="text-align:right; vertical-align:top;">
  1161. <?php _e('Disable on this page/post:', 'all_in_one_seo_pack')?>
  1162. </th>
  1163. <td>
  1164. <input type="checkbox" name="aiosp_disable" <?php if ($aiosp_disable) echo "checked=\"1\""; ?>/>
  1165. </td>
  1166. </tr>
  1167. <tr>
  1168. <th scope="row" style="text-align:right;"><?php _e('Title Attribute:', 'all_in_one_seo_pack') ?></th>
  1169. <td><input value="<?php echo $aiosp_titleatr ?>" type="text" name="aiosp_titleatr" size="62"/></td>
  1170. </tr>
  1171. <tr>
  1172. <th scope="row" style="text-align:right;"><?php _e('M…

Large files files are truncated, but you can click here to view the full file