PageRenderTime 46ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/site/pie-wp-theme/carrington-core/utility.php

http://github.com/lojjic/PIE
PHP | 821 lines | 721 code | 58 blank | 42 comment | 161 complexity | 430fb76833d3e5982e7b895577c7b03c MD5 | raw file
  1. <?php
  2. // This file is part of the Carrington Theme Framework for WordPress
  3. // http://carringtontheme.com
  4. //
  5. // Copyright (c) 2008-2010 Crowd Favorite, Ltd. All rights reserved.
  6. // http://crowdfavorite.com
  7. //
  8. // Released under the GPL license
  9. // http://www.opensource.org/licenses/gpl-license.php
  10. //
  11. // **********************************************************************
  12. // This program is distributed in the hope that it will be useful, but
  13. // WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. // **********************************************************************
  16. if (__FILE__ == $_SERVER['SCRIPT_FILENAME']) { die(); }
  17. function cfct_die($str = '') {
  18. if (!empty($str)) {
  19. if (file_exists(CFCT_PATH.'error/exit.php')) {
  20. include(CFCT_PATH.'error/exit.php');
  21. die();
  22. }
  23. else {
  24. wp_die($str);
  25. }
  26. }
  27. }
  28. function cfct_banner($str = '') {
  29. if (!empty($str)) {
  30. if (file_exists(CFCT_PATH.'misc/banner.php')) {
  31. include(CFCT_PATH.'misc/banner.php');
  32. }
  33. else {
  34. echo '<!-- '.$str.' -->';
  35. }
  36. }
  37. }
  38. function cfct_get_option($name) {
  39. $defaults = array(
  40. 'cfct_credit' => 'yes',
  41. 'cfct_lightbox' => 'yes',
  42. 'cfct_header_image' => 0,
  43. );
  44. $defaults = apply_filters('cfct_option_defaults', $defaults);
  45. $value = get_option($name);
  46. if ($value == '' && isset($defaults[$name])) {
  47. $value = $defaults[$name];
  48. }
  49. return $value;
  50. }
  51. function cfct_load_plugins() {
  52. $files = cfct_files(CFCT_PATH.'plugins');
  53. if (count($files)) {
  54. foreach ($files as $file) {
  55. if (file_exists(CFCT_PATH.'plugins/'.$file)) {
  56. include_once(CFCT_PATH.'plugins/'.$file);
  57. }
  58. // child theme support
  59. if (file_exists(STYLESHEETPATH.'/plugins/'.$file)) {
  60. include_once(STYLESHEETPATH.'/plugins/'.$file);
  61. }
  62. }
  63. }
  64. }
  65. function cfct_default_file($dir) {
  66. $fancy = $dir.'-default.php';
  67. file_exists(CFCT_PATH.$dir.'/'.$fancy) ? $default = $fancy : $default = 'default.php';
  68. return $default;
  69. }
  70. function cfct_context() {
  71. $context = 'home';
  72. if (is_home()) {
  73. $context = 'home';
  74. }
  75. else if (is_page()) {
  76. $context = 'page';
  77. }
  78. else if (is_single()) {
  79. $context = 'single';
  80. }
  81. else if (is_category()) {
  82. $context = 'category';
  83. }
  84. else if (is_tag()) {
  85. $context = 'tag';
  86. }
  87. else if (is_author()) {
  88. $context = 'author';
  89. }
  90. else if (is_archive()) {
  91. // possible future abstraction for:
  92. // is_month()
  93. // is_year()
  94. // is_day()
  95. $context = 'archive';
  96. }
  97. else if (is_search()) {
  98. $context = 'search';
  99. }
  100. else if (is_404()) {
  101. $context = '404';
  102. }
  103. return apply_filters('cfct_context', $context);
  104. }
  105. /**
  106. * @param $template = folder name of file
  107. * @param $type = file name of file
  108. * @param $keys = keys that could be used for additional filename params
  109. * returns false if file does not exist
  110. *
  111. */
  112. function cfct_filename($dir, $type = 'default', $keys = array()) {
  113. switch ($type) {
  114. case 'author':
  115. if (count($keys)) {
  116. $file = 'author-'.$keys[0];
  117. }
  118. else {
  119. $file = 'author';
  120. }
  121. break;
  122. case 'category':
  123. if (count($keys)) {
  124. $file = 'cat-'.$keys[0];
  125. }
  126. else {
  127. $file = 'category';
  128. }
  129. break;
  130. case 'tag':
  131. if (count($keys)) {
  132. $file = 'tag-'.$keys[0];
  133. }
  134. else {
  135. $file = 'tag';
  136. }
  137. break;
  138. case 'meta':
  139. if (count($keys)) {
  140. foreach ($keys as $k => $v) {
  141. if (!empty($v)) {
  142. $file = 'meta-'.$k.'-'.$v;
  143. }
  144. else {
  145. $file = 'meta-'.$k;
  146. }
  147. break;
  148. }
  149. }
  150. break;
  151. case 'user':
  152. if (count($keys)) {
  153. $file = 'user-'.$keys[0];
  154. }
  155. break;
  156. case 'role':
  157. if (count($keys)) {
  158. $file = 'role-'.$keys[0];
  159. }
  160. break;
  161. case 'parent':
  162. if (count($keys)) {
  163. $file = 'parent-'.$keys[0];
  164. }
  165. break;
  166. default:
  167. // handles page, etc.
  168. $file = $type;
  169. }
  170. // fallback for category, author, tag, etc.
  171. // child theme path
  172. $path = STYLESHEETPATH.'/'.$dir.'/'.$file.'.php';
  173. // check for child theme first
  174. if (!file_exists($path)) {
  175. // use parent theme if no child theme file found
  176. $path = CFCT_PATH.$dir.'/'.$file.'.php';
  177. }
  178. if (!file_exists($path)) {
  179. switch ($type) {
  180. case 'author':
  181. case 'category':
  182. case 'tag':
  183. // child theme path
  184. $path = STYLESHEETPATH.'/'.$dir.'/archive.php';
  185. if (!file_exists($path)) {
  186. // use parent theme if no child theme file found
  187. $path = CFCT_PATH.$dir.'/archive.php';
  188. }
  189. }
  190. }
  191. $default = CFCT_PATH.$dir.'/'.cfct_default_file($dir);
  192. if (file_exists($path)) {
  193. $path = $path;
  194. }
  195. else if (file_exists($default)) {
  196. $path = $default;
  197. }
  198. else {
  199. $path = false;
  200. }
  201. return apply_filters('cfct_filename', $path);
  202. }
  203. function cfct_template($dir, $keys = array()) {
  204. $context = cfct_context();
  205. $file = cfct_filename($dir, $context, $keys);
  206. if ($file) {
  207. include($file);
  208. }
  209. else {
  210. cfct_die('Error loading '.$dir.' '.__LINE__);
  211. }
  212. }
  213. function cfct_template_file($dir, $file, $data = null) {
  214. $path = '';
  215. if (!empty($file)) {
  216. $file = basename($file, '.php');
  217. // child theme support
  218. $path = STYLESHEETPATH.'/'.$dir.'/'.$file.'.php';
  219. if (!file_exists($path)) {
  220. $path = CFCT_PATH.$dir.'/'.$file.'.php';
  221. }
  222. }
  223. if (file_exists($path)) {
  224. include($path);
  225. }
  226. else {
  227. cfct_die('Error loading '.$file.' '.__LINE__);
  228. }
  229. }
  230. function cfct_choose_general_template($dir) {
  231. $exec_order = array(
  232. 'author',
  233. 'role',
  234. 'category',
  235. 'tag',
  236. 'single',
  237. 'default'
  238. );
  239. $exec_order = apply_filters('cfct_general_match_order', $exec_order);
  240. $files = cfct_files(CFCT_PATH.$dir);
  241. foreach ($exec_order as $func_name) {
  242. if (!function_exists($func_name)) {
  243. $func_name = 'cfct_choose_general_template_'.$func_name;
  244. }
  245. if (function_exists($func_name)) {
  246. $filename = $func_name($dir, $files);
  247. if ($filename != false) {
  248. break;
  249. }
  250. }
  251. }
  252. return apply_filters('cfct_choose_general_template', $filename, $dir);
  253. }
  254. function cfct_choose_general_template_author($dir, $files) {
  255. $files = cfct_author_templates($dir, $files);
  256. if (count($files)) {
  257. $username = get_query_var('author_name');
  258. if (empty($username)) {
  259. $user = new WP_User(get_query_var('author'));
  260. $username = $user->user_login;
  261. }
  262. $filename = 'author-'.$username.'.php';
  263. if (in_array($filename, $files)) {
  264. $keys = array($username);
  265. return cfct_filename($dir, 'author', $keys);
  266. }
  267. }
  268. return false;
  269. }
  270. function cfct_choose_general_template_category($dir, $files) {
  271. $files = cfct_cat_templates($dir, $files);
  272. if (count($files)) {
  273. global $cat;
  274. $slug = cfct_cat_id_to_slug($cat);
  275. if (in_array('cat-'.$slug.'.php', $files)) {
  276. $keys = array($slug);
  277. return cfct_filename($dir, 'category', $keys);
  278. }
  279. }
  280. return false;
  281. }
  282. function cfct_choose_general_template_tag($dir, $files) {
  283. $files = cfct_tag_templates($dir, $files);
  284. if (count($files)) {
  285. $tag = get_query_var('tag');
  286. if (in_array('tag-'.$tag.'.php', $files)) {
  287. $keys = array($tag);
  288. return cfct_filename($dir, 'tag', $keys);
  289. }
  290. }
  291. return false;
  292. }
  293. function cfct_choose_general_template_role($dir, $files) {
  294. $files = cfct_role_templates($dir, $files);
  295. if (count($files)) {
  296. $username = get_query_var('author_name');
  297. $user = new WP_User(cfct_username_to_id($username));
  298. if (!empty($user->user_login)) {
  299. if (count($user->roles)) {
  300. foreach ($user->roles as $role) {
  301. $role_file = 'role-'.$role.'.php';
  302. if (in_array($role_file, $files)) {
  303. return $role_file;
  304. }
  305. }
  306. }
  307. }
  308. }
  309. return false;
  310. }
  311. function cfct_choose_general_template_single($dir, $files) {
  312. if (cfct_context() == 'single') {
  313. $files = cfct_single_templates($dir, $files);
  314. if (count($files)) {
  315. // check to see if we're in the loop.
  316. global $post;
  317. $orig_post = $post;
  318. while (have_posts()) {
  319. the_post();
  320. $filename = cfct_choose_single_template($files, 'single-*');
  321. if (!$filename) {
  322. if (file_exists(CFCT_PATH.$dir.'/single.php')) {
  323. $filename = 'single.php';
  324. }
  325. }
  326. }
  327. rewind_posts();
  328. $post = $orig_post;
  329. return $filename;
  330. }
  331. }
  332. return false;
  333. }
  334. function cfct_choose_general_template_default($dir, $files) {
  335. $context = cfct_context();
  336. return cfct_filename($dir, $context);
  337. }
  338. function cfct_choose_single_template($files = array(), $filter = '*') {
  339. // must be called within the_loop - cfct_choose_general_template_single() approximates a loop for this reason.
  340. $exec_order = array(
  341. 'author',
  342. 'meta',
  343. 'category',
  344. 'type',
  345. 'role',
  346. 'tag',
  347. 'parent', // for pages
  348. );
  349. $exec_order = apply_filters('cfct_single_match_order', $exec_order);
  350. $filename = false;
  351. foreach ($exec_order as $func_name) {
  352. if (!function_exists($func_name)) {
  353. $func_name = 'cfct_choose_single_template_'.$func_name;
  354. }
  355. if (function_exists($func_name)) {
  356. $filename = $func_name($dir, $files, $filter);
  357. if ($filename != false) {
  358. break;
  359. }
  360. }
  361. }
  362. return apply_filters('cfct_choose_single_template', $filename);
  363. }
  364. function cfct_choose_single_template_type($dir, $files, $filter) {
  365. $type_files = cfct_type_templates('', $files);
  366. if (count($type_files)) {
  367. global $post;
  368. $file = cfct_filename_filter('type-'.$post->post_type.'.php', $filter);
  369. if (in_array($file, $type_files)) {
  370. return $file;
  371. }
  372. }
  373. return false;
  374. }
  375. function cfct_choose_single_template_author($dir, $files, $filter) {
  376. $author_files = cfct_author_templates('', $files);
  377. if (count($author_files)) {
  378. $author = get_the_author_login();
  379. $file = cfct_filename_filter('author-'.$author.'.php', $filter);
  380. if (in_array($file, $author_files)) {
  381. return $file;
  382. }
  383. }
  384. return false;
  385. }
  386. function cfct_choose_single_template_meta($dir, $files, $filter) {
  387. global $post;
  388. $meta_files = cfct_meta_templates('', $files);
  389. if (count($meta_files)) {
  390. $meta = get_post_custom($post->ID);
  391. if (count($meta)) {
  392. // check key, value matches first
  393. foreach ($meta as $k => $v) {
  394. $val = $v[0];
  395. $file = cfct_filename_filter('meta-'.$k.'-'.$val.'.php', $filter);
  396. if (in_array($file, $meta_files)) {
  397. return $file;
  398. }
  399. }
  400. // check key matches only
  401. if (!$filename) {
  402. foreach ($meta as $k => $v) {
  403. $file = cfct_filename_filter('meta-'.$k.'.php', $filter);
  404. if (in_array($file, $meta_files)) {
  405. return $file;
  406. }
  407. }
  408. }
  409. }
  410. }
  411. return false;
  412. }
  413. function cfct_choose_single_template_category($dir, $files, $filter) {
  414. $cat_files = cfct_cat_templates($type, $files);
  415. if (count($cat_files)) {
  416. foreach ($cat_files as $file) {
  417. $file = cfct_filename_filter($file, $filter);
  418. $cat_id = cfct_cat_filename_to_id($file);
  419. if (in_category($cat_id)) {
  420. return $file;
  421. }
  422. }
  423. }
  424. return false;
  425. }
  426. function cfct_choose_single_template_role($dir, $files, $filter) {
  427. $role_files = cfct_role_templates($type, $files);
  428. if (count($role_files)) {
  429. $user = new WP_User(get_the_author_meta('ID'));
  430. if (count($user->roles)) {
  431. foreach ($role_files as $file) {
  432. $file = cfct_filename_filter($file, $filter);
  433. foreach ($user->roles as $role) {
  434. if (cfct_role_filename_to_name($file) == $role) {
  435. return $file;
  436. }
  437. }
  438. }
  439. }
  440. }
  441. return false;
  442. }
  443. function cfct_choose_single_template_tag($dir, $files, $filter) {
  444. global $post;
  445. $tag_files = cfct_tag_templates($type, $files);
  446. if (count($tag_files)) {
  447. $tags = get_the_tags($post->ID);
  448. if (is_array($tags) && count($tags)) {
  449. foreach ($tag_files as $file) {
  450. $file = cfct_filename_filter($file, $filter);
  451. foreach ($tags as $tag) {
  452. if ($tag->slug == cfct_tag_filename_to_name($file)) {
  453. return $file;
  454. }
  455. }
  456. }
  457. }
  458. }
  459. return false;
  460. }
  461. function cfct_choose_single_template_parent($dir, $files, $filter) {
  462. global $post;
  463. $parent_files = cfct_parent_templates($type, $files);
  464. if (count($parent_files) && $post->post_parent > 0) {
  465. $parent = cfct_post_id_to_slug($post->post_parent);
  466. $file = cfct_filename_filter('parent-'.$parent.'.php', $filter);
  467. if (in_array($file, $parent_files)) {
  468. return $file;
  469. }
  470. }
  471. return false;
  472. }
  473. function cfct_choose_content_template($type = 'content') {
  474. $files = cfct_files(CFCT_PATH.$type);
  475. $filename = cfct_choose_single_template($files);
  476. if (!$filename && cfct_context() == 'page' && file_exists(CFCT_PATH.$type.'/page.php')) {
  477. $filename = 'page.php';
  478. }
  479. if (!$filename) {
  480. $filename = cfct_default_file($type);
  481. }
  482. return apply_filters('cfct_choose_content_template', $filename, $type);
  483. }
  484. function cfct_choose_comment_template() {
  485. $exec_order = array(
  486. 'ping',
  487. 'author',
  488. 'user',
  489. 'meta',
  490. 'role',
  491. 'default',
  492. );
  493. $exec_order = apply_filters('cfct_comment_match_order', $exec_order);
  494. $files = cfct_files(CFCT_PATH.'comment');
  495. foreach ($exec_order as $func_name) {
  496. if (!function_exists($func_name)) {
  497. $func_name = 'cfct_choose_comment_template_'.$func_name;
  498. }
  499. if (function_exists($func_name)) {
  500. $filename = $func_name($files);
  501. if ($filename != false) {
  502. break;
  503. }
  504. }
  505. }
  506. return apply_filters('cfct_choose_comment_template', $filename);
  507. }
  508. function cfct_choose_comment_template_ping($files) {
  509. global $comment;
  510. if (in_array('ping.php', $files)) {
  511. switch ($comment->comment_type) {
  512. case 'pingback':
  513. case 'trackback':
  514. return 'ping';
  515. break;
  516. }
  517. }
  518. return false;
  519. }
  520. function cfct_choose_comment_template_meta($files) {
  521. global $comment;
  522. $meta_files = cfct_meta_templates('', $files);
  523. if (count($meta_files)) {
  524. $meta = get_metadata('comment', $comment->comment_ID);
  525. if (count($meta)) {
  526. // check key, value matches first
  527. foreach ($meta as $k => $v) {
  528. $val = $v[0];
  529. $file = 'meta-'.$k.'-'.$val.'.php';
  530. if (in_array($file, $meta_files)) {
  531. return $file;
  532. }
  533. }
  534. // check key matches only
  535. if (!$filename) {
  536. foreach ($meta as $k => $v) {
  537. $file = 'meta-'.$k.'.php';
  538. if (in_array($file, $meta_files)) {
  539. return $file;
  540. }
  541. }
  542. }
  543. }
  544. }
  545. return false;
  546. }
  547. function cfct_choose_comment_template_author($files) {
  548. global $post, $comment;
  549. if (!empty($comment->user_id) && $comment->user_id == $post->post_author && in_array('author.php', $files)) {
  550. return 'author';
  551. }
  552. return false;
  553. }
  554. function cfct_choose_comment_template_user($files) {
  555. global $comment;
  556. $files = cfct_comment_templates('user', $files);
  557. if (count($files) && !empty($comment->user_id)) {
  558. $user = new WP_User($comment->user_id);
  559. if (!empty($user->user_login)) {
  560. $user_file = 'user-'.$user->user_login.'.php';
  561. if (in_array($user_file, $files)) {
  562. return $user_file;
  563. }
  564. }
  565. }
  566. return false;
  567. }
  568. function cfct_choose_comment_template_role($files) {
  569. global $comment;
  570. $files = cfct_comment_templates('role', $files);
  571. if (count($files) && !empty($comment->user_id)) {
  572. $user = new WP_User($comment->user_id);
  573. if (!empty($user->user_login)) {
  574. if (count($user->roles)) {
  575. foreach ($user->roles as $role) {
  576. $role_file = 'role-'.$role.'.php';
  577. if (in_array($role_file, $files)) {
  578. return $role_file;
  579. }
  580. }
  581. }
  582. }
  583. }
  584. return false;
  585. }
  586. function cfct_choose_comment_template_default($files) {
  587. return cfct_default_file('comment');
  588. }
  589. function cfct_filename_filter($filename, $filter) {
  590. // check for filter already appended
  591. if (substr($filename, 0, strlen($filter) - 1) == str_replace('*', '', $filter)) {
  592. return $filename;
  593. }
  594. return str_replace('*', $filename, $filter);
  595. }
  596. function cfct_files($path) {
  597. $files = apply_filters('cfct_files_'.$path, false);
  598. if ($files) {
  599. return $files;
  600. }
  601. $files = wp_cache_get('cfct_files_'.$path, 'cfct');
  602. if ($files) {
  603. return $files;
  604. }
  605. $files = array();
  606. $paths = array($path);
  607. if (STYLESHEETPATH.'/' != CFCT_PATH) {
  608. // load child theme files
  609. $paths[] = STYLESHEETPATH.'/'.str_replace(CFCT_PATH, '', $path);
  610. }
  611. foreach ($paths as $path) {
  612. if (is_dir($path) && $handle = opendir($path)) {
  613. while (false !== ($file = readdir($handle))) {
  614. $path = trailingslashit($path);
  615. if (is_file($path.$file) && strtolower(substr($file, -4, 4)) == ".php") {
  616. $files[] = $file;
  617. }
  618. }
  619. closedir($handle);
  620. }
  621. }
  622. $files = array_unique($files);
  623. wp_cache_set('cfct_files_'.$path, $files, 'cfct', 3600);
  624. return $files;
  625. }
  626. function cfct_filter_files($files = array(), $prefix = '') {
  627. $matches = array();
  628. if (count($files)) {
  629. foreach ($files as $file) {
  630. if (strpos($file, $prefix) !== false) {
  631. $matches[] = $file;
  632. }
  633. }
  634. }
  635. return $matches;
  636. }
  637. function cfct_meta_templates($dir, $files = null) {
  638. if (is_null($files)) {
  639. $files = cfct_files(CFCT_PATH.$dir);
  640. }
  641. $matches = cfct_filter_files($files, 'meta-');
  642. return apply_filters('cfct_meta_templates', $matches);
  643. }
  644. function cfct_cat_templates($dir, $files = null) {
  645. if (is_null($files)) {
  646. $files = cfct_files(CFCT_PATH.$dir);
  647. }
  648. $matches = cfct_filter_files($files, 'cat-');
  649. return apply_filters('cfct_cat_templates', $matches);
  650. }
  651. function cfct_tag_templates($dir, $files = null) {
  652. if (is_null($files)) {
  653. $files = cfct_files(CFCT_PATH.$dir);
  654. }
  655. $matches = cfct_filter_files($files, 'tag-');
  656. return apply_filters('cfct_tag_templates', $matches);
  657. }
  658. function cfct_author_templates($dir, $files = null) {
  659. if (is_null($files)) {
  660. $files = cfct_files(CFCT_PATH.$dir);
  661. }
  662. $matches = cfct_filter_files($files, 'author-');
  663. return apply_filters('cfct_author_templates', $matches);
  664. }
  665. function cfct_type_templates($dir, $files = null) {
  666. if (is_null($files)) {
  667. $files = cfct_files(CFCT_PATH.$dir);
  668. }
  669. $matches = cfct_filter_files($files, 'type-');
  670. return apply_filters('cfct_type_templates', $matches);
  671. }
  672. function cfct_role_templates($dir, $files = null) {
  673. if (is_null($files)) {
  674. $files = cfct_files(CFCT_PATH.$dir);
  675. }
  676. $matches = cfct_filter_files($files, 'role-');
  677. return apply_filters('cfct_role_templates', $matches);
  678. }
  679. function cfct_parent_templates($dir, $files = null) {
  680. if (is_null($files)) {
  681. $files = cfct_files(CFCT_PATH.$dir);
  682. }
  683. $matches = cfct_filter_files($files, 'parent-');
  684. return apply_filters('cfct_parent_templates', $matches);
  685. }
  686. function cfct_single_templates($dir, $files = null) {
  687. if (is_null($files)) {
  688. $files = cfct_files(CFCT_PATH.$dir);
  689. }
  690. $matches = cfct_filter_files($files, 'single');
  691. return apply_filters('cfct_single_templates', $matches);
  692. }
  693. function cfct_comment_templates($type, $files = false) {
  694. if (!$files) {
  695. $files = cfct_files(CFCT_PATH.'comment');
  696. }
  697. $matches = array();
  698. switch ($type) {
  699. case 'user':
  700. $matches = cfct_filter_files($files, 'user-');
  701. break;
  702. case 'role':
  703. $matches = cfct_filter_files($files, 'role-');
  704. break;
  705. }
  706. return apply_filters('cfct_comment_templates', $matches);
  707. }
  708. function cfct_cat_filename_to_id($file) {
  709. $cat = cfct_cat_filename_to_slug($file);
  710. $cat = get_category_by_slug($cat);
  711. return $cat->cat_ID;
  712. }
  713. function cfct_cat_filename_to_name($file) {
  714. $cat = cfct_cat_filename_to_slug($file);
  715. $cat = get_category_by_slug($cat);
  716. return $cat->name;
  717. }
  718. function cfct_cat_filename_to_slug($file) {
  719. return str_replace(array('single-cat-', 'cat-', '.php'), '', $file);
  720. }
  721. function cfct_cat_id_to_slug($id) {
  722. $cat = &get_category($id);
  723. return $cat->slug;
  724. }
  725. function cfct_username_to_id($username) {
  726. return get_profile('ID', $username);
  727. }
  728. function cfct_tag_filename_to_name($file) {
  729. return str_replace(array('single-tag-', 'tag-', '.php'), '', $file);
  730. }
  731. function cfct_author_filename_to_name($file) {
  732. return str_replace(array('single-author-', 'author-', '.php'), '', $file);
  733. }
  734. function cfct_role_filename_to_name($file) {
  735. return str_replace(array('single-role-', 'role-', '.php'), '', $file);
  736. }
  737. function cfct_post_id_to_slug($id) {
  738. $post = get_post($id);
  739. return $post->post_name;
  740. }
  741. function cfct_basic_content_formatting($str) {
  742. $str = wptexturize($str);
  743. $str = convert_smilies($str);
  744. $str = convert_chars($str);
  745. $str = wpautop($str);
  746. return $str;
  747. }
  748. function cfct_leading_dir($path) {
  749. $val = array(
  750. 'dir' => '',
  751. 'file' => ''
  752. );
  753. if (strpos($path, '/') !== false) {
  754. $parts = explode('/', $path);
  755. $val['file'] = $parts[count($parts) - 1];
  756. $val['dir'] = implode('/', array_slice($parts, 0, count($parts) - 1));
  757. }
  758. else {
  759. $val['file'] = $path;
  760. }
  761. return $val;
  762. }
  763. ?>