web/wp-content/themes/selecta/ocmx/ocmx-functions.php
changeset 1 0d28b7c10758
equal deleted inserted replaced
0:0d9a58d2c515 1:0d28b7c10758
       
     1 <?php
       
     2 // The OCMX custom options form
       
     3 function ocmx_header(){
       
     4 ?>   
       
     5 		<script src="<?php bloginfo('template_directory'); ?>/ocmx/scripts/jquery.js"></script>
       
     6     	<script src="<?php bloginfo('template_directory'); ?>/ocmx/scripts/ocmx_jquery.js"></script>
       
     7         <script src="<?php bloginfo('template_directory'); ?>/ocmx/scripts/multifile.js"></script>
       
     8 	    <link href="<?php bloginfo('template_directory'); ?>/ocmx/ocmx_styles.css" rel="stylesheet" type="text/css" />
       
     9 		<div id="template-directory" style="display: none;"><?php bloginfo("template_directory"); ?></div>
       
    10 		<div id="wp-url" style="display: none;"><?php bloginfo("wpurl"); ?></div>
       
    11 <?php
       
    12 };
       
    13 global $themename, $options;
       
    14 
       
    15 if($_POST["save_options"]) :
       
    16 		global $wpdb;
       
    17 		//Clear our preset options, because we're gonna add news ones.
       
    18 		wp_cache_flush(); 
       
    19 		if($_POST["general_options"]) :
       
    20 			if(isset($_COOKIE["ocmx_theme_style"])){setcookie ("ocmx_theme_style", "", time() - 3600, COOKIEPATH, COOKIE_DOMAIN);}
       
    21 			echo $_COOKIE["ocmx_theme_style"];	
       
    22 			$clear_menu = $wpdb->query("DELETE FROM $wpdb->options
       
    23 			WHERE `option_name` LIKE 'ocmx_main_%'
       
    24 			OR `option_name` LIKE 'ocmx_maincategory_%'
       
    25 			OR `option_name` LIKE 'ocmx_menu_page%'
       
    26 			OR `option_name` LIKE 'ocmx_subpage_%'
       
    27 			OR `option_name` = 'ocmx_gallery_page'
       
    28 			OR `option_name` = 'ocmx_archives_page'");
       
    29 		endif;
       
    30 		while (list($key,$value) = each($_POST)){
       
    31 			if (substr($key, 0, 4) == "ocmx") :
       
    32 				wp_cache_flush(); 
       
    33 				$clear_options = $wpdb->query("DELETE FROM $wpdb->options WHERE `option_name` = '".$key."'");
       
    34 				if(!get_option($key)):					
       
    35 					add_option($key, $value);						
       
    36 				else :						
       
    37 					update_option($key, $value);
       
    38 				endif;
       
    39 				
       
    40 			endif;					
       
    41 		}
       
    42 		update_option("posts_per_page", get_option("ocmx_home_page_posts"));
       
    43 		if(!$_POST["ocmx_gallery_update"]) :
       
    44 			while (list($key,$value) = each($_FILES)){
       
    45 				$image_name = strtolower($_FILES[$key]["name"]);
       
    46 				if($image_name !== "") :
       
    47 					$final_upload = ABSPATH."wp-content/uploads/".$image_name;
       
    48 					if(move_uploaded_file($_FILES[$key]["tmp_name"], $final_upload) === true) :
       
    49 						$test = move_uploaded_file($_FILES[$key]["tmp_name"], $final_upload);
       
    50 					else :
       
    51 						$test = "0";
       
    52 					endif;
       
    53 					if($test !== "0") :
       
    54 						if(!get_option($key)):
       
    55 							add_option($key, $image_name);						
       
    56 						else :						
       
    57 							update_option($key, $image_name);
       
    58 						endif;
       
    59 					endif;
       
    60 				endif;
       
    61 			}
       
    62 	endif;
       
    63 endif;
       
    64 function ocmx_save_resample($upload_image, $new_image, $mime_type, $resize_type, $resize_height, $resize_width, $resize_percent, $image_width, $image_height)
       
    65 	{
       
    66 		global $upload_image, $new_image, $mime_type, $resize_type, $resize_height, $resize_width, $resize_percent, $image_width, $image_height;
       
    67 		
       
    68 		if($resize_type == "w" && ($resize_width < $image_width)) :
       
    69 			if($resize_width !== "0") :
       
    70 				$new_width = $resize_width;
       
    71 			else :
       
    72 				$new_width = $resize_height;
       
    73 			endif;
       
    74 			$new_height = ($image_height*($resize_width/$image_width));
       
    75 		elseif($resize_type == "h" && ($resize_height < $image_height)) :
       
    76 			if($resize_height !== "0") :
       
    77 				$new_height = $resize_height;
       
    78 			else :
       
    79 				$new_height = $resize_width;
       
    80 			endif;
       
    81 			$new_width = ($image_width*($resize_height/$image_height));
       
    82 		elseif($resize_type == "p") :
       
    83 			/*  Set Resize Percentage */
       
    84 			$resize_percent = ($resize_percent);
       
    85 			$new_width = ($image_width*$resize_percent);
       
    86 			$new_height = ($image_height*$resize_percent);
       
    87 		else :
       
    88 			$new_width = ($image_width);
       
    89 			$new_height = ($image_height);
       
    90 		endif;
       
    91 		
       
    92 		// Creat Canvas
       
    93 		$canvas = imagecreatetruecolor($new_width, $new_height);
       
    94 		
       
    95 		// Resample
       
    96 		if(imagecopyresampled($canvas, $new_image, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height) === true) :
       
    97 				// Save		
       
    98 			if($mime_type == "gif") :
       
    99 				imagegif($canvas, $upload_image, 100);
       
   100 			elseif($mime_type == "jpg") :	
       
   101 				imagejpeg($canvas, $upload_image, 100);
       
   102 			elseif($mime_type == "png") :
       
   103 				imagepng($canvas, $upload_image);
       
   104 			endif;				
       
   105 		endif;
       
   106 		
       
   107 	}
       
   108 function ocmx_commentmeta_update($cid)//, $comment_twitter, $comment_subscribe, $comment_author_email
       
   109 	{
       
   110 		global $wpdb;
       
   111 		$commentId = (int) $cid;
       
   112 		$comment_table = $wpdb->prefix . "ocmx_comment_meta";
       
   113 		if($_POST['twitter'] == "undefined" && $_POST['twitter'] == "Twitter Name") :
       
   114 			$use_twitter = "";
       
   115 		else :
       
   116 			$use_twitter = $_POST['twitter'];
       
   117 		endif;
       
   118 		
       
   119 		if($_POST['email_subscribe'] == "true") :
       
   120 			$subscribe_me = 1;
       
   121 		else :
       
   122 			$subscribe_me = 0;
       
   123 		endif;
       
   124 		
       
   125 		$meta_update = $wpdb->query
       
   126 			($wpdb->prepare
       
   127 				("INSERT INTO $comment_table
       
   128 					(commentId, twitter, email_subscribe)
       
   129 				VALUES
       
   130 					(%d, %s, %s);", 
       
   131         		$cid, $use_twitter, $subscribe_me)
       
   132 			);
       
   133 		ocmx_comment_email($cid);
       
   134 	}	
       
   135 function ocmx_comment_email($cid)//, $comment_twitter, $comment_subscribe, $comment_author_email
       
   136 	{
       
   137 		global $wpdb;
       
   138 		$commentId = (int) $cid;
       
   139 		$comment_table = $wpdb->prefix . "ocmx_comment_meta";
       
   140 		
       
   141 		$comment = $wpdb->get_row("SELECT $wpdb->comments.*,  $comment_table.* FROM $wpdb->comments INNER JOIN $comment_table ON $wpdb->comments.comment_ID = $comment_table.commentId WHERE $wpdb->comments.comment_ID='".$cid."'");
       
   142 		$post_details = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='".$comment->comment_post_ID."' LIMIT 1");		
       
   143 		
       
   144 		$fetch_subscribers = $wpdb->get_results("SELECT $wpdb->comments.*,  $comment_table.*
       
   145 		FROM $wpdb->comments INNER JOIN $comment_table
       
   146 		ON $wpdb->comments.comment_ID = $comment_table.commentId
       
   147 		WHERE $wpdb->comments.comment_post_ID = '".$comment->comment_post_ID."'
       
   148 		AND $comment_table.email_subscribe = '1'
       
   149 		GROUP BY $wpdb->comments.comment_author_email");
       
   150 		
       
   151 		foreach($fetch_subscribers as $subscriber) :
       
   152 			$to = $subscriber->comment_author_email;
       
   153 			$headers  = "From: \"".get_bloginfo("name")."\" Comments";
       
   154 			$headers .= "MIME-Version: 1.0\n";
       
   155 			$headers .= "Content-type: text/html; charset=iso-8859-1 \r\n";
       
   156 			$body = "<style>body{margin: 20px;font-size: 9pt;font-family: Arial, Helvetica, sans-serif;color: ##333333;background-color: ##ffffff;}.articles_item{padding-bottom: 10px; border-bottom: 1px solid black; margin-bottom: 10px;}</style>";
       
   157 			$body .=  "<h4>".$post->post_title."</h4>";
       
   158 			$body .=  "<p><strong>".$comment->comment_author."</strong> has commented on <strong>". $post_details->post_title."</strong></p>";
       
   159 			$body .=  "<p><strong>Link:</strong> <a href=\"".$comment->comment_author."\">".$comment->comment_author_url."</a></p>";
       
   160 			$body .=  "<p><strong>Twitter Name:</strong> <a href=\"http://twitter.com/".$comment->twitter."\">".$comment->twitter."</a></p>";
       
   161 			$body .=  "<p><strong>Comment:</strong></p>";
       
   162 			$body .=  "<div class=\"articles_item\">";
       
   163 			$body .=  "<p>".$comment->comment_content."</p>";
       
   164 			$body .=  "</div>";  
       
   165 			$body .=  "<p>Go go straight to the post <a href=\"".get_permalink($comment->comment_post_ID)."#comments\">".get_permalink($comment->comment_post_ID)."</a>.</p>";
       
   166 			$body .=  "<p>Unsubscribe from this comment feed <a href=\"".get_option("template_directory")."/unsubscribe.php?comment=".$cid."\">".get_permalink($comment->comment_post_ID)."</a>.</p>";
       
   167 			wp_mail($to, $subject, $body, $headers);
       
   168 		endforeach;
       
   169 	}
       
   170 function ocmx_unsubscribe($comment_id)//, $comment_twitter, $comment_subscribe, $comment_author_email
       
   171 	{
       
   172 		global $wpdb, $comment_id, $the_post;
       
   173 		$comment_id = $_GET["comment"];	
       
   174 		$comment_table = $wpdb->prefix . "ocmx_comment_meta";	
       
   175 		$the_comment = get_comment($comment_id);	
       
   176 		
       
   177 		$subscriber_email = $the_comment->comment_author_email;
       
   178 		
       
   179 		$post_id = $the_comment->comment_post_ID;
       
   180 		$the_post = get_post($the_comment->comment_post_ID);
       
   181 		
       
   182 		$comment_args = array("post_id" => $post_id);
       
   183 		
       
   184 		$post_comments = get_comments($comment_args);
       
   185 		
       
   186 		foreach($post_comments as $this_comment) :
       
   187 			if($subscriber_email == $this_comment->comment_author_email)
       
   188 			$wpdb->update($comment_table , array( 'email_subscribe' => '0'), array( 'commentId' => $this_comment->comment_ID ), array( '%d' ), array( '%d' ) );
       
   189 		endforeach;
       
   190 	}
       
   191 
       
   192 ?>