Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

featured image data #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
17 changes: 17 additions & 0 deletions services.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
15 changes: 15 additions & 0 deletions shortcode-attribs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
define("INCL",realpath(__DIR__ . "/../../../wp-includes"));

require INCL . "/shortcodes.php";

require "services.php";

$newobj = [];
$newobj["post_content"] = 'di daskda dasjkhdas [audio ogg="http://localhost:9000/wp-content/uploads/2017/02/316829__lalks__ferambie.ogg" teste="abc" xxx][/audio] [biskit kkk="isisis"]dasdasd';

$ex = hookpress_get_shortcode_attribs($newobj["post_content"],'audio');
$ex = hookpress_parse_attribs( $ex );

print_r($ex);
echo "\n";