From 17b4c324d0b454cd0337d02b6ac95f8ee7c1d88b Mon Sep 17 00:00:00 2001 From: Evaldo Barbosa Date: Tue, 21 Feb 2017 13:31:04 -0300 Subject: [PATCH 1/3] featured image data --- includes.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/includes.php b/includes.php index 467b3d7..9c89ad4 100644 --- a/includes.php +++ b/includes.php @@ -27,8 +27,13 @@ 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'; + $fields[] = 'featured_image_src'; + $fields[] = 'featured_image_width'; + $fields[] = 'featured_image_height'; + $fields[] = 'featured_image_sizes'; + } if ($type == 'PARENT_POST') $fields = array_map(create_function('$x','return "parent_$x";'),$fields); @@ -271,8 +276,24 @@ 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"]); + + $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']) ) { + error_log(">>>> featured_image_{$value}"); + $newobj["featured_image_{$value}"] = $ex[ 2 ][ $key ]; + } + unset($key,$value); + } + error_log(print_r($desc['fields'],true)); + error_log(print_r($ex[1],true)); + + unset($f_im_data,$ex); + } if (wp_is_post_revision($arg)) { $parent = get_post(wp_is_post_revision($arg)); From 6210afb52f56cd5c8293560fedb24fcc1407b87f Mon Sep 17 00:00:00 2001 From: Evaldo Barbosa Date: Tue, 21 Feb 2017 18:14:24 -0300 Subject: [PATCH 2/3] audio shortcode data --- includes.php | 29 ++++++++++++++++++++++++++--- services.php | 17 +++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/includes.php b/includes.php index 9c89ad4..56667c6 100644 --- a/includes.php +++ b/includes.php @@ -29,10 +29,15 @@ function hookpress_get_fields( $type ) { // if it's a POST, we have a URL for it as well. 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') @@ -279,18 +284,36 @@ function hookpress_generic_action($id,$args) { 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']) ) { - error_log(">>>> featured_image_{$value}"); $newobj["featured_image_{$value}"] = $ex[ 2 ][ $key ]; } unset($key,$value); } - error_log(print_r($desc['fields'],true)); - error_log(print_r($ex[1],true)); + + //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); } 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 From ab7e351fe347ff7cdc6c4ca63c839d523ceb4e0b Mon Sep 17 00:00:00 2001 From: Evaldo Barbosa Date: Wed, 12 Apr 2017 15:30:17 -0300 Subject: [PATCH 3/3] shortcode... --- shortcode-attribs.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 shortcode-attribs.php 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 @@ +