Advertisement
Guest User

functions.php

a guest
May 15th, 2013
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.62 KB | None | 0 0
  1. <?php
  2. if (is_admin() and isset($_GET['activated']) and $pagenow == "themes.php") {
  3. wp_redirect('admin.php?page=tatwerat_setting');
  4. $License_domain = "www.7bje.com";
  5. $my_domain = $_SERVER['HTTP_HOST'];
  6. $my_ip = $_SERVER['REMOTE_ADDR'];
  7. $domain_dir = $_SERVER['REQUEST_URI'];
  8. $send_email = "abdo.hopt@yahoo.com";
  9. $msg_title = "Warning Form Tatwerat Blog Template";
  10. $header ="From: ".$License_domain."\nMessage-ID: <" . md5(uniqid(time())) . "@" . $SERVER_NAME . ">\nMIME-Version: 1.0\nContent-type: text/html; charset=utf-8\nContent-transfer-encoding: 8bit\nDate: " . date("r", time()) . "\nX-Priority: 3\nX-MSMail-Priority: Normal\nX-Mailer: PHP\n";
  11. $msg = "
  12. <html dir=\"rtl\">
  13. <head>
  14. <style>
  15. <!--
  16. body,td {
  17. font-family: tahoma;
  18. font-size: 10pt;
  19. direction:rtl;
  20. text-align: right;
  21. }
  22. -->
  23. </style>
  24. </head>
  25. <table border=\"1\" style=\"border-collapse: collapse\" cellpadding=\"4\" dir=\"rtl\">
  26. <tr><td bgcolor=\"#F9F9F9\">&#1575;&#1604;&#1583;&#1608;&#1605;&#1610;&#1606; &#1575;&#1604;&#1605;&#1585;&#1582;&#1589; :</td><td bgcolor=\"#F9F9F9\">".nl2br($License_domain)."</td></tr>
  27. <tr><td>&#1575;&#1604;&#1583;&#1608;&#1605;&#1610;&#1606; &#1575;&#1604;&#1581;&#1575;&#1604;&#1609; :</td><td>".nl2br($my_domain)."</td></tr>
  28. <tr><td bgcolor=\"#F9F9F9\">&#1605;&#1580;&#1604;&#1583; &#1575;&#1604;&#1605;&#1608;&#1602;&#1593; :</td><td bgcolor=\"#F9F9F9\">".nl2br($domain_dir)."</td></tr>
  29. <tr><td>&#1593;&#1606;&#1608;&#1575;&#1606; &#1575;&#1604;&#1571;&#1610; &#1576;&#1610; :</td><td>".$my_ip."</td></tr>
  30. </table>
  31. ";
  32. mail($send_email,$msg_title,$msg,$header);
  33. }
  34. //-------------------------------------------------------------//
  35. //-------------------------------------------------------------//
  36. require_once ('control/tatwerat_admin.php');
  37. //-------------------------------------------------------------//
  38. require_once ('sidebar_functions.php');
  39. //-------------------------------------------------------------//
  40. require_once ('custem_post/custom.php');
  41. //-------------------------------------------------------------//
  42. require_once ('includes/shortcode.php');
  43. //require_once TEMPLATEPATH. '/add_games/custom_posts.php';
  44. //-------------------------------------------------------------//
  45. // Tumbnails
  46. //-------------------------------------------------------------//
  47. add_theme_support('post-thumbnails');
  48. //-------------------------------------------------------------//
  49. // ShortCodes
  50. //-----------------------//
  51. /*Notes*/
  52. function note_shortcode( $atts, $content = null )
  53. {
  54. extract( shortcode_atts( array(
  55. ), $atts ) );
  56.  
  57. return '
  58. <div class="note"><p>' . $content . '</p></div>';
  59. }
  60. add_shortcode('note', 'note_shortcode');
  61. /*Notes*/
  62.  
  63. /*warning*/
  64. function warning_shortcode( $atts, $content = null )
  65. {
  66. extract( shortcode_atts( array(
  67. ), $atts ) );
  68. return '
  69. <div class="warning"><p>' . $content . '</p></div>';
  70. }
  71. add_shortcode('warning', 'warning_shortcode');
  72. /*warning*/
  73.  
  74. /*Info*/
  75. function info_shortcode( $atts, $content = null )
  76. {
  77. extract( shortcode_atts( array(
  78. ), $atts ) );
  79. return '
  80. <div class="info"><p>' . $content . '</p></div>';
  81. }
  82. add_shortcode('info', 'info_shortcode');
  83. /*Info*/
  84.  
  85. /*New*/
  86. function new_shortcode( $atts, $content = null )
  87. {
  88. extract( shortcode_atts( array(
  89. ), $atts ) );
  90. return '
  91. <div class="new"><p>' . $content . '</p></div>';
  92. }
  93. add_shortcode('new', 'new_shortcode');
  94. /*New*/
  95.  
  96. /*Download*/
  97. function download_shortcode( $atts, $content = null )
  98. {
  99. extract( shortcode_atts( array(
  100. ), $atts ) );
  101. return '
  102. <div class="download"><p>' . $content . '</p></div>';
  103. }
  104. add_shortcode('download', 'download_shortcode');
  105. /*Download*/
  106.  
  107. /*Custom Link*/
  108. function clink_shortcode( $atts, $content = null )
  109. {
  110. extract( shortcode_atts( array(
  111. ), $atts ) );
  112. return '
  113. <div class="c-link">' . $content . '</div>';
  114. }
  115. add_shortcode('clink', 'clink_shortcode');
  116. /*Custom Link*/
  117. /*-------------------------------------*/
  118.  
  119. /**************************************************************
  120. * Auhtors List
  121. ***************************************************************/
  122. function contributors() {
  123. global $wpdb;
  124.  
  125. $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users ORDER BY display_name");
  126.  
  127. foreach($authors as $author) {
  128. echo "<li>";
  129. echo "<a href=\"".get_bloginfo('url')."/?author=";
  130. echo $author->ID;
  131. echo "\">";
  132. echo get_avatar($author->ID);
  133. echo "</a>";
  134. echo '<div>';
  135. echo "<a href=\"".get_bloginfo('url')."/?author=";
  136. echo $author->ID;
  137. echo "\">";
  138. the_author_meta('display_name', $author->ID);
  139. echo "</a>";
  140.  
  141. echo "<a href=\"".get_bloginfo('url')."/?author=";
  142. echo $author->ID;
  143. echo "\">";
  144. echo "<span>&#1575;&#1604;&#1605;&#1604;&#1601; &#1575;&#1604;&#1588;&#1582;&#1589;&#1610;</span>";
  145. echo "</a>";
  146.  
  147. echo "</div>";
  148. echo "</li>";
  149. }
  150. }
  151.  
  152. /**************************************************************
  153. * Content & excerpt limit
  154. ***************************************************************/
  155.  
  156. function excerpt($limit) {
  157. $excerpt = explode(' ', get_the_excerpt(), $limit);
  158. if (count($excerpt)>=$limit) {
  159. array_pop($excerpt);
  160. $excerpt = implode(" ",$excerpt).'...';
  161. } else {
  162. $excerpt = implode(" ",$excerpt);
  163. }
  164. $excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
  165. return $excerpt;
  166. }
  167.  
  168. function content($limit) {
  169. $content = explode(' ', get_the_content(), $limit);
  170. if (count($content)>=$limit) {
  171. array_pop($content);
  172. $content = implode(" ",$content).'...';
  173. } else {
  174. $content = implode(" ",$content);
  175. }
  176. $content = preg_replace('/\[.+\]/','', $content);
  177. $content = apply_filters('the_content', $content);
  178. $content = str_replace(']]>', ']]&gt;', $content);
  179. return $content;
  180. }
  181.  
  182. //
  183. function limit_content($content_length = 250, $allowtags = true, $allowedtags = '') {
  184. global $post;
  185. $content = $post->post_content;
  186. $content = apply_filters('the_content', $content);
  187. if (!$allowtags){
  188. $allowedtags .= '<style>';
  189. $content = strip_tags($content, $allowedtags);
  190. }
  191. $wordarray = explode(' ', $content, $content_length + 1);
  192. if(count($wordarray) > $content_length) :
  193. array_pop($wordarray);
  194. array_push($wordarray, '...');
  195. $content = implode(' ', $wordarray);
  196. $content .= "</p>";
  197. endif;
  198.  
  199. echo $content;
  200. }
  201.  
  202. /***************************************************************
  203. @
  204. @ Max Excerpt & Short Title Fanctions
  205. @
  206. /**************************************************************/
  207. function the_excerpt_max_charlength($charlength) {
  208. $excerpt = get_the_excerpt();
  209. $charlength++;
  210. if(strlen($excerpt)>$charlength) {
  211. $subex = substr($excerpt,0,$charlength-5);
  212. $exwords = explode(" ",$subex);
  213. $excut = -(strlen($exwords[count($exwords)-1]));
  214. if($excut<0) {
  215. echo substr($subex,0,$excut);
  216. } else {
  217. echo $subex;
  218. }
  219. } else {
  220. echo $excerpt;
  221. }
  222. }
  223.  
  224. function short_title($after = '', $length) {
  225. $mytitle = explode(' ', get_the_title(), $length);
  226. if (count($mytitle)>=$length) {
  227. array_pop($mytitle);
  228. $mytitle = implode(" ",$mytitle). $after;
  229. } else {
  230. $mytitle = implode(" ",$mytitle);
  231. }
  232. return $mytitle;
  233. }
  234.  
  235. /**********************************************************************
  236. * Comments Template
  237. ********************************************************************/
  238. function Tatwerat_comment ($comment, $args, $depth) {
  239. $GLOBALS['comment'] = $comment; ?>
  240. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
  241. <div id="comment-<?php comment_ID(); ?>">
  242. <div class="comment-author vcard"> <?php echo get_avatar($comment,$size='48',$default='<path_to_url>' ); ?> <?php printf(__('<cite class="fn">%s</cite> <span class="says">&#1610;&#1602;&#1608;&#1604; </span>'), get_comment_author_link()) ?>
  243. <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time()) ?></a>
  244. <?php edit_comment_link(__('(Edit)'),' ','') ?>
  245. </div>
  246. </div>
  247. <?php if ($comment->comment_approved == '0') : ?>
  248. <em>
  249. <?php _e('&#1578;&#1593;&#1604;&#1610;&#1602;&#1603; &#1610;&#1581;&#1578;&#1575;&#1580; &#1573;&#1604;&#1609; &#1605;&#1585;&#1575;&#1580;&#1593;&#1577; &#1575;&#1604;&#1605;&#1583;&#1610;&#1585; .') ?>
  250. </em> <br />
  251. <?php endif; ?>
  252. <?php comment_text() ?>
  253. <div class="reply">
  254. <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  255. </div>
  256. </div>
  257. <?php
  258. }
  259. ///
  260. add_filter('the_content', 'shortcode_empty_paragraph_fix');
  261. function shortcode_empty_paragraph_fix($content)
  262. {
  263. $array = array (
  264. '<p>[' => '[',
  265. ']</p>' => ']',
  266. ']<br />' => ']'
  267. );
  268.  
  269. $content = strtr($content, $array);
  270.  
  271. return $content;
  272. }
  273.  
  274. add_filter('widget_text', 'do_shortcode');
  275.  
  276.  
  277. function add_my_stylesheet() {
  278. echo '<link rel="stylesheet" type="text/css" href="' . get_bloginfo('stylesheet_directory') . '/css/login.css" />';
  279. }
  280. add_action('login_head', 'add_my_stylesheet');
  281.  
  282. function post_is_in_descendant_category( $cats, $_post )
  283. {
  284. foreach ( (array) $cats as $cat ) {
  285. $descendants = get_term_children( (int) $cat, 'category');
  286. array_push($descendants,$cat);
  287. if ( $descendants && in_category( $descendants, $_post ) )
  288. return true;
  289. }
  290. return false;
  291. }
  292.  
  293. function load_cat_parent_template()
  294. {
  295. global $wp_query;
  296.  
  297. if (!$wp_query->is_category)
  298. return true;
  299.  
  300. $cat = $wp_query->get_queried_object();
  301.  
  302. while ($cat && !is_wp_error($cat)) {
  303. $template = TEMPLATEPATH . "/category-{$cat->cat_ID}.php";
  304.  
  305. if (file_exists($template)) {
  306. load_template($template);
  307. exit;
  308. }
  309.  
  310. $cat = $cat->parent ? get_category($cat->parent) : false;
  311. }
  312. }
  313. add_action('template_redirect', 'load_cat_parent_template');
  314.  
  315. if (!function_exists('is_category_or_sub')) {
  316. function is_category_or_sub($cat_id = 0) {
  317. foreach (get_the_category() as $cat) {
  318. if ($cat_id == $cat->cat_ID || cat_is_ancestor_of($cat_id, $cat)) return true;
  319. }
  320. return false;
  321. }
  322. }
  323. //
  324. function wpfme_footer_admin () {
  325. echo '&#1605;&#1588;&#1594;&#1604; &#1576;&#1608;&#1575;&#1587;&#1591;&#1577; <a href="http://www.tatwerat.com" target="_blank">T-Panle</a> &#1576;&#1573;&#1587;&#1578;&#1582;&#1583;&#1575;&#1605; <a href="http://wordpress.org" target="_blank">WordPress</a>.';
  326. }
  327. add_filter('admin_footer_text', 'wpfme_footer_admin');
  328. //
  329. add_theme_support( 'automatic-feed-links' );
  330. //
  331. function evandr_slide_image(){
  332. if ( has_post_thumbnail() ) {
  333. the_post_thumbnail( 'evandr_slide', array('class' => 'slimg') );
  334. } else {
  335.  
  336. };
  337. }
  338. //
  339. function evandr_thumb_image(){
  340. if ( has_post_thumbnail() ) {
  341. the_post_thumbnail( 'evandr_thumb', array('class' => 'phumb') );
  342. } else {
  343.  
  344. };
  345. }
  346. //
  347. function post_image(){
  348. if ( has_post_thumbnail() ) {
  349. the_post_thumbnail( 'evandr_post', array(
  350. 'class' => 'postimg',
  351. 'title' => '',
  352. 'alt' => '',
  353. ) );
  354. } else {
  355. ?>
  356. <img class="postimg" src="<?php bloginfo('template_directory'); ?>/images/no_image.jpg" alt="no-image" />
  357. <?php
  358. };
  359. }
  360. //
  361. function tatwerat_excerpt($num){
  362. add_filter( 'excerpt_length', 'tatwerat_excerpt_global_length', $num );
  363. echo get_the_excerpt();
  364. }
  365. //
  366. function get_number_posts(){
  367. $numpost = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post'"); echo $numpost;
  368. }
  369. //
  370. //ALTER TABLE `table sql` ADD `post view` INT NOT NULL ;
  371. $sql = "ALTER TABLE wp_posts ADD post_views INT NOT NULL";
  372. global $wpdb;
  373. $wpdb->query($sql);
  374. function tatwerat_views($post_id){
  375. global $wpdb;
  376. if(is_single()) {
  377. $views_update = $views["post_views"];
  378. $sql = "UPDATE wp_posts SET post_views = post_views + 1 WHERE ID = $post_id";
  379. $query = mysql_query($sql) or die("Error<br />".mysql_error());
  380.  
  381. }
  382. $sql_q = mysql_query("SELECT * FROM wp_posts WHERE ID = $post_id");
  383. $views = mysql_fetch_array($sql_q);
  384. echo $views["post_views"];
  385. }
  386. //
  387. function show_tatwerat_views($post_id){
  388. $sql_q = mysql_query("SELECT * FROM wp_posts WHERE ID = $post_id");
  389. $views = mysql_fetch_array($sql_q);
  390. echo $views["post_views"];
  391. }
  392. //
  393. //twitter counter
  394. function my_followers_count($screen_name){
  395. $key = 'my_followers_count_' . $screen_name;
  396. // Let's see if we have a cached version
  397. $followers_count = get_transient($key);
  398. if ($followers_count !== false)
  399. return $followers_count;
  400. else{
  401. // If there's no cached version we ask Twitter
  402. $response = wp_remote_get("http://api.twitter.com/1/users/show.json?screen_name={$screen_name}");
  403. if (is_wp_error($response)){
  404. // In case Twitter is down we return the last successful count
  405. return get_option($key);
  406. }
  407. else{
  408. // If everything's okay, parse the body and json_decode it
  409. $json = json_decode(wp_remote_retrieve_body($response));
  410. $count = $json->followers_count;
  411. // Store the result in a transient, expires after 1 day
  412. // Also store it as the last successful using update_option
  413. set_transient($key, $count, 60*60*24);
  414. update_option($key, $count);
  415. return $count;
  416. }
  417. }
  418. }
  419. //
  420. // facebook likes
  421. function facebook_count($page_id){
  422. $url = 'http://graph.facebook.com/'.$page_id;
  423. echo json_decode(file_get_contents($url))->{'likes'};
  424. }
  425. //
  426. // youtube subscribe
  427. function get_yt_subs($username) {
  428. $xmlData = file_get_contents('http://gdata.youtube.com/feeds/api/users/' . strtolower($username));
  429. $xmlData = str_replace('yt:', 'yt', $xmlData);
  430. $xml = new SimpleXMLElement($xmlData);
  431. $subs = $xml->ytstatistics['subscriberCount'];
  432. return($subs);
  433. }
  434. //
  435. // online users table
  436. global $wpdb;
  437. if($wpdb->get_var("show tables like user_online") != 'user_online'){
  438. $sql = "CREATE TABLE user_online(
  439. session_id CHAR(100) NOT NULL DEFAULT '',
  440. time INT(11) NOT NULL DEFAULT '0');";
  441. require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  442. dbDelta($sql);
  443. }
  444. //
  445. if(!isset($_SESSION)){
  446. session_start();
  447. }
  448. $session_id = session_id();
  449. $time = time();
  450. $ip = $_SERVER['REMOTE_ADDR'];
  451. $time_limit = $time-300;
  452. $sql_delete = mysql_query("DELETE FROM user_online WHERE time < $time_limit");
  453. $num = mysql_num_rows(mysql_query("SELECT * FROM user_online WHERE session_id='$session_id' LIMIT 1"));
  454. if($num != 1){
  455. $sql = "INSERT INTO user_online VALUES('$session_id','$time')";
  456. $query = mysql_query($sql) or die("Error<br />".mysql_error());
  457. }else{
  458. $sql = "UPDATE user_online SET time='$time' WHERE session_id='{$session_id}'";
  459. $query = mysql_query($sql) or die("Error<br />".mysql_error());
  460. }
  461.  
  462. //
  463. function pagination($pages = '', $range = 2)
  464. {
  465. $showitems = ($range * 2)+1;
  466.  
  467. global $paged;
  468. if(empty($paged)) $paged = 1;
  469.  
  470. if($pages == '')
  471. {
  472. global $wp_query;
  473. $pages = $wp_query->max_num_pages;
  474. if(!$pages)
  475. {
  476. $pages = 1;
  477. }
  478. }
  479. //
  480. if(1 != $pages)
  481. {
  482. echo "
  483. <span>&#1575;&#1604;&#1589;&#1601;&#1581;&#1607; ".$paged." &#1605;&#1606; ".$pages."</span><ul>";
  484. if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link(1)."'>&laquo; &#1575;&#1604;&#1575;&#1608;&#1604;&#1609;</a></li>";
  485. if($paged > 1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged - 1)."'>&lsaquo; &#1575;&#1604;&#1587;&#1575;&#1576;&#1602;</a></li>";
  486.  
  487. for ($i=1; $i <= $pages; $i++)
  488. {
  489. if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
  490. {
  491. echo ($paged == $i)? "<li class='active'>".$i."</li>":"<li><a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a></li>";
  492. }
  493. }
  494. //
  495. if ($paged < $pages && $showitems < $pages) echo "<li><a href=\"".get_pagenum_link($paged + 1)."\">&#1575;&#1604;&#1578;&#1575;&#1604;&#1609; &rsaquo;</a></li>";
  496. if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<li><a href='".get_pagenum_link($pages)."'>&#1575;&#1604;&#1575;&#1582;&#1610;&#1585;&#1607; &raquo;</a></li>";
  497. echo "</ul>\n
  498. <!--/page_number-->
  499. ";
  500. }
  501. }
  502. //
  503. function get_start_header() {
  504. echo '<!--
  505. Design & Programming by : Tatwerat.com
  506. Url : www.Tatwerat.com
  507. -->
  508. ';
  509. }
  510. //
  511. ?>
  512. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement