diff --git a/includes.php b/includes.php index 467b3d7..56667c6 100644 --- a/includes.php +++ b/includes.php @@ -27,8 +27,18 @@ function hookpress_get_fields( $type ) { } // if it's a POST, we have a URL for it as well. - if ($type == 'POST' || $type == 'PARENT_POST') + if ($type == 'POST' || $type == 'PARENT_POST') { $fields[] = 'post_url'; + } + + if ( in_array($type, ['POST','PARENT_POST','ATTACHMENT']) ) { + $fields[] = 'featured_image_src'; + $fields[] = 'featured_image_width'; + $fields[] = 'featured_image_height'; + $fields[] = 'featured_image_sizes'; + $fields[] = 'audio_shortcode_src'; + $fields[] = 'audio_shortcode_type'; + } if ($type == 'PARENT_POST') $fields = array_map(create_function('$x','return "parent_$x";'),$fields); @@ -271,8 +281,42 @@ function hookpress_generic_action($id,$args) { case 'ATTACHMENT': $newobj = get_post($arg,ARRAY_A); - if ($arg_names[$i] == 'POST') + if ($arg_names[$i] == 'POST') { $newobj["post_url"] = get_permalink($newobj["ID"]); + + //Getting attached image data + $f_im_data = get_the_post_thumbnail($newobj["ID"]); + $ex = []; + preg_match_all("/([a-z]+)=\"([a-z0-9A-Z_\-\.\/:]+)\"/", $f_im_data, $ex); + foreach ($ex[1] as $key => $value) { + if ( array_search("featured_image_{$value}",$desc['fields']) ) { + $newobj["featured_image_{$value}"] = $ex[ 2 ][ $key ]; + } + unset($key,$value); + } + + //Getting audio shortcode data + $ex = hookpress_get_shortcode_attribs($newobj["post_content"],'audio'); + $ex = hookpress_parse_attribs( $ex ); + foreach ($ex as $key => $value) { + switch ($key) { + case 'src': + case 'ogg': + case 'mp3': + case 'wav': + if ( array_search("audio_shortcode_src",$desc['fields']) ) { + $newobj["audio_shortcode_src"] = $value; + } + if ( array_search("audio_shortcode_type",$desc['fields']) ) { + $newobj["audio_shortcode_type"] = $key; + } + break; + } + unset($key,$value); + } + + unset($f_im_data,$ex); + } if (wp_is_post_revision($arg)) { $parent = get_post(wp_is_post_revision($arg)); diff --git a/services.php b/services.php index 8f6b9c0..de89810 100644 --- a/services.php +++ b/services.php @@ -135,3 +135,20 @@ function hookpress_ajax_get_hooks() { } exit; } + +function hookpress_get_shortcode_attribs($post_content, $tag) +{ + $ex = []; + + preg_match("/\[{$tag}(.*)\]\[\/{$tag}\]/", $post_content, $ex); + + return $ex[0]; +} + +function hookpress_parse_attribs($content) +{ + $output = []; + preg_match_all("/([a-z]+)=\"([a-z0-9A-Z_\-\.\/:]+)\"/", $content, $output); + + return array_combine($output[1], $output[2]); +} \ No newline at end of file diff --git a/shortcode-attribs.php b/shortcode-attribs.php new file mode 100644 index 0000000..b811960 --- /dev/null +++ b/shortcode-attribs.php @@ -0,0 +1,15 @@ +