| 1 | <?php |
|---|
| 2 | class RCCWP_Post |
|---|
| 3 | { |
|---|
| 4 | function save_files() |
|---|
| 5 | { |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | ### IF NOT CALLED FROM A CWP PAGE, IGNORE IT ### |
|---|
| 9 | |
|---|
| 10 | if( ! isset( $_REQUEST['rc_cwp_meta_files'] ) ) |
|---|
| 11 | { |
|---|
| 12 | return; |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | ### IF NO NEW FILES ARE GIVEN, USE THE OLD FILES ### |
|---|
| 18 | |
|---|
| 19 | if( count( $_FILES ) < 1 && isset( $_REQUEST['rc_cwp_meta_files'] ) ) |
|---|
| 20 | { |
|---|
| 21 | foreach( $_REQUEST['rc_cwp_meta_files'] as $meta_name ) |
|---|
| 22 | { |
|---|
| 23 | $_POST[$meta_name] = $_REQUEST[ $meta_name . '_last' ]; |
|---|
| 24 | } |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | ### DEAL WITH SPECIFIED FILES ### |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | foreach( $_FILES as $meta_name => $file ) |
|---|
| 33 | { |
|---|
| 34 | $upload_filepath = $_POST[$meta_name . '_filepath']; |
|---|
| 35 | if ($upload_filepath != ""){ |
|---|
| 36 | $oldfilename = $upload_filepath; |
|---|
| 37 | $path = get_bloginfo('url') . '/wp-content/plugins/fresh-page/files/'; |
|---|
| 38 | |
|---|
| 39 | $filename = time().substr($oldfilename, 10); |
|---|
| 40 | //rename the file to avoid image caching |
|---|
| 41 | rename(dirname(__FILE__) . '/files/'.$oldfilename, dirname(__FILE__) . '/files/'.$filename); |
|---|
| 42 | $_POST[$meta_name] = $path . $filename; |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | } |
|---|
| 46 | else{ |
|---|
| 47 | $_POST[$meta_name] = $_POST[$meta_name . '_last']; |
|---|
| 48 | continue; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | /*if( file_exists( $file['tmp_name'] ) ) |
|---|
| 52 | { |
|---|
| 53 | //Old Upload code: |
|---|
| 54 | $filename = time() . $file['name']; |
|---|
| 55 | |
|---|
| 56 | $path = get_bloginfo('url') . '/wp-content/plugins/fresh-page/files/'; |
|---|
| 57 | |
|---|
| 58 | $_POST[$meta_name] = $path . $filename; |
|---|
| 59 | |
|---|
| 60 | move_uploaded_file( $file['tmp_name'], dirname(__FILE__) . '/files/' . $filename ); |
|---|
| 61 | */ |
|---|
| 62 | |
|---|
| 63 | /*else // try to get web file |
|---|
| 64 | { |
|---|
| 65 | $url = $_REQUEST[$meta_name . '_url']; |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | if ($fp_source = @fopen($url, 'rb')) { |
|---|
| 69 | //Get target filename |
|---|
| 70 | $exploded_url = explode( '.', $url ); |
|---|
| 71 | |
|---|
| 72 | $ext = array_pop( $exploded_url ); |
|---|
| 73 | |
|---|
| 74 | $filename = time() . '_' . str_replace( 'rc_cwp_meta_', '', $meta_name ) . '.' . $ext; |
|---|
| 75 | |
|---|
| 76 | $path = get_bloginfo('url') . '/wp-content/plugins/fresh-page/files/'; |
|---|
| 77 | |
|---|
| 78 | $_POST[$meta_name] = $path . $filename; |
|---|
| 79 | |
|---|
| 80 | $directory = dirname(__FILE__) . '/files/'; |
|---|
| 81 | |
|---|
| 82 | $fp_dest = @fopen($directory . $filename,"wb"); |
|---|
| 83 | if ($fp_dest == false) return; |
|---|
| 84 | |
|---|
| 85 | while(!feof($fp_source)) { |
|---|
| 86 | set_time_limit(30); |
|---|
| 87 | |
|---|
| 88 | if (connection_status()!=0) return; |
|---|
| 89 | |
|---|
| 90 | $readData = fread($fp_source, 1024*8); |
|---|
| 91 | if ($readData == false) return; |
|---|
| 92 | |
|---|
| 93 | if (fwrite($fp_dest,$readData) == false) return; |
|---|
| 94 | |
|---|
| 95 | } |
|---|
| 96 | if (fclose($fp_source) == false) return; |
|---|
| 97 | if (fclose($fp_dest) == false) return; |
|---|
| 98 | } |
|---|
| 99 | else{ |
|---|
| 100 | $_POST[$meta_name] = $_POST[$meta_name . '_last']; |
|---|
| 101 | continue; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | if( ! $file_string = file_get_contents( $url ) ) // if we fail to get web file, use old value |
|---|
| 108 | { |
|---|
| 109 | $_POST[$meta_name] = $_POST[$meta_name . '_last']; |
|---|
| 110 | |
|---|
| 111 | continue; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | $exploded_url = explode( '.', $url ); |
|---|
| 115 | |
|---|
| 116 | $ext = array_pop( $exploded_url ); |
|---|
| 117 | |
|---|
| 118 | $filename = time() . '_' . str_replace( 'rc_cwp_meta_', '', $meta_name ) . '.' . $ext; |
|---|
| 119 | |
|---|
| 120 | $path = get_bloginfo('url') . '/wp-content/plugins/fresh-page/files/'; |
|---|
| 121 | |
|---|
| 122 | $_POST[$meta_name] = $path . $filename; |
|---|
| 123 | |
|---|
| 124 | $directory = dirname(__FILE__) . '/files/'; |
|---|
| 125 | |
|---|
| 126 | file_put_contents( $directory . $filename, $file_string ); |
|---|
| 127 | }*/ |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | ### ADD THUMBNAILER PATH AND PARAMS TO THE PHOTO FILE NAME ### |
|---|
| 133 | |
|---|
| 134 | if( isset( $_REQUEST['rc_cwp_meta_photos'] ) ) |
|---|
| 135 | { |
|---|
| 136 | foreach( $_REQUEST['rc_cwp_meta_photos'] as $meta_name ) |
|---|
| 137 | { |
|---|
| 138 | // if photo is new, add thumbnailer path |
|---|
| 139 | |
|---|
| 140 | if( $_POST[ $meta_name ] != $_POST[ $meta_name . '_last' ] ) |
|---|
| 141 | { |
|---|
| 142 | $path = get_bloginfo('url') . '/wp-content/plugins/fresh-page/phpThumb.php?src='; |
|---|
| 143 | $_POST[ $meta_name ] = $path . $_POST[ $meta_name ]; |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | // if photo is new, add params |
|---|
| 148 | |
|---|
| 149 | if( isset( $_REQUEST[ $meta_name . '_params' ] ) && $_REQUEST[ $meta_name . '_params' ] ) |
|---|
| 150 | { |
|---|
| 151 | if( ! strpos( $_POST[$meta_name], $_REQUEST[ $meta_name . '_params' ] ) ) |
|---|
| 152 | { |
|---|
| 153 | $_POST[$meta_name] .= $_REQUEST[$meta_name . '_params']; |
|---|
| 154 | } |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | function GetCustomWritePanel() |
|---|
| 162 | { |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | if (isset($_GET['post'])) |
|---|
| 166 | { |
|---|
| 167 | |
|---|
| 168 | $customWritePanelId = get_post_meta((int)$_GET['post'], RC_CWP_POST_WRITE_PANEL_ID_META_KEY, true); |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | if (empty($customWritePanelId)) |
|---|
| 172 | { |
|---|
| 173 | $customWritePanelId = (int)$_REQUEST['custom-write-panel-id']; |
|---|
| 174 | } |
|---|
| 175 | } |
|---|
| 176 | else if (isset($_REQUEST['custom-write-panel-id'])) |
|---|
| 177 | { |
|---|
| 178 | $customWritePanelId = (int)$_REQUEST['custom-write-panel-id']; |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | if (isset($customWritePanelId)) |
|---|
| 182 | { |
|---|
| 183 | include_once('RCCWP_Application.php'); |
|---|
| 184 | $customWritePanel = RCCWP_Application::GetCustomWritePanels($customWritePanelId); |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | return $customWritePanel; |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | function SetCustomWritePanel($postId) |
|---|
| 191 | { |
|---|
| 192 | |
|---|
| 193 | if(!wp_verify_nonce($_REQUEST['rc-custom-write-panel-verify-key'], 'rc-custom-write-panel')) |
|---|
| 194 | return $postId; |
|---|
| 195 | |
|---|
| 196 | if (!current_user_can('edit_post', $postId)) |
|---|
| 197 | return $postId; |
|---|
| 198 | |
|---|
| 199 | $customWritePanelId = $_POST['rc-cwp-custom-write-panel-id']; |
|---|
| 200 | if (isset($customWritePanelId)) |
|---|
| 201 | { |
|---|
| 202 | if (!empty($customWritePanelId)) |
|---|
| 203 | { |
|---|
| 204 | |
|---|
| 205 | if (!update_post_meta($postId, RC_CWP_POST_WRITE_PANEL_ID_META_KEY, $customWritePanelId)) |
|---|
| 206 | { |
|---|
| 207 | |
|---|
| 208 | add_post_meta($postId, RC_CWP_POST_WRITE_PANEL_ID_META_KEY, $customWritePanelId); |
|---|
| 209 | } |
|---|
| 210 | } |
|---|
| 211 | else |
|---|
| 212 | { |
|---|
| 213 | delete_post_meta($postId, RC_CWP_POST_WRITE_PANEL_ID_META_KEY); |
|---|
| 214 | } |
|---|
| 215 | } |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | function SetMetaValue($postId) |
|---|
| 219 | { |
|---|
| 220 | global $wpdb; |
|---|
| 221 | |
|---|
| 222 | if(!wp_verify_nonce($_REQUEST['rc-custom-write-panel-verify-key'], 'rc-custom-write-panel')) |
|---|
| 223 | return $postId; |
|---|
| 224 | |
|---|
| 225 | if (!current_user_can('edit_post', $postId)) |
|---|
| 226 | return $postId; |
|---|
| 227 | |
|---|
| 228 | $customWritePanelId = $_POST['rc-cwp-custom-write-panel-id']; |
|---|
| 229 | if (isset($customWritePanelId)) |
|---|
| 230 | { |
|---|
| 231 | if (!empty($customWritePanelId)) |
|---|
| 232 | { |
|---|
| 233 | $customFieldCount = count($customFieldKeys); |
|---|
| 234 | $customFieldKeys = (array)$_POST['rc_cwp_meta_keys']; |
|---|
| 235 | foreach ($customFieldKeys as $key) |
|---|
| 236 | { |
|---|
| 237 | $rawCustomFieldName = $key; |
|---|
| 238 | |
|---|
| 239 | if (isset($rawCustomFieldName)) |
|---|
| 240 | { |
|---|
| 241 | if (!empty($rawCustomFieldName)) |
|---|
| 242 | { |
|---|
| 243 | $customFieldName = $wpdb->escape(stripslashes(trim(RC_Format::GetFieldName($rawCustomFieldName)))); |
|---|
| 244 | |
|---|
| 245 | $customFieldValue = $_POST[$rawCustomFieldName]; |
|---|
| 246 | $audioExt = substr($customFieldValue, -4); |
|---|
| 247 | |
|---|
| 248 | /*if($audioExt == '.mp3' || $audioExt == '.MP3' || $audioExt == '.avg' || $audioExt == '.AVG' || $audioExt == 'mpeg' || $audioExt == 'MPEG') |
|---|
| 249 | { |
|---|
| 250 | $customFieldValue = "\<div style=\'padding-top:3px;\'\>\<object classid=\'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\' codebase='\http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\' width=\'95%\' height=\'20\' wmode=\'transparent\' \>\<param name=\'movie\' value=\'http://www.freshoutmedia.com/singlemp3player.swf?file=".$customFieldValue."\' wmode=\'transparent\' /\>\<param name=\'quality\' value=\'high\' wmode=\'transparent\' /\>\<embed src=\'http://www.freshoutmedia.com/singlemp3player.swf?file=".$customFieldValue."' width=\'50\%\' height=\'20\' quality=\'high\' pluginspage=\'http://www.macromedia.com/go/getflashplayer\' type=\'application/x-shockwave-flash\' wmode=\'transparent\' \>\</embed\>\</object\>\</div\>"; |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | if(!(strpos($customFieldValue, 'phpThumb.php') === FALSE)) |
|---|
| 254 | { |
|---|
| 255 | $_POST['rc_cwp_meta_Image_url']; |
|---|
| 256 | |
|---|
| 257 | if((strpos($customFieldValue, 'img src') === FALSE)) |
|---|
| 258 | { |
|---|
| 259 | $cssClass = $wpdb->get_results("SELECT CSS FROM wp_rc_cwp_panel_custom_field WHERE panel_id='".$_POST['rc-cwp-custom-write-panel-id']."' and name='".$customFieldName."'"); |
|---|
| 260 | |
|---|
| 261 | $customFieldValue = "\<img src=\'".$customFieldValue."\' class=\"".$cssClass[0]->CSS."\" \/\>"; |
|---|
| 262 | //$customFieldValue = "\<img src=\'".$customFieldValue."\' \/\>"; |
|---|
| 263 | } |
|---|
| 264 | }*/ |
|---|
| 265 | |
|---|
| 266 | delete_post_meta($postId, $customFieldName); |
|---|
| 267 | if (is_array($customFieldValue)) |
|---|
| 268 | { |
|---|
| 269 | foreach ($customFieldValue as $value) |
|---|
| 270 | { |
|---|
| 271 | $value = stripslashes(trim($value)); |
|---|
| 272 | add_post_meta($postId, $customFieldName, $value); |
|---|
| 273 | } |
|---|
| 274 | } |
|---|
| 275 | else |
|---|
| 276 | { |
|---|
| 277 | $value = stripslashes(trim($customFieldValue)); |
|---|
| 278 | add_post_meta($postId, $customFieldName, $value); |
|---|
| 279 | } |
|---|
| 280 | } |
|---|
| 281 | else |
|---|
| 282 | { |
|---|
| 283 | delete_post_meta($postId, $customFieldName); |
|---|
| 284 | } |
|---|
| 285 | } |
|---|
| 286 | } |
|---|
| 287 | } |
|---|
| 288 | else |
|---|
| 289 | { |
|---|
| 290 | |
|---|
| 291 | } |
|---|
| 292 | } |
|---|
| 293 | } |
|---|
| 294 | } |
|---|
| 295 | ?> |
|---|