Changeset 1288206
- Timestamp:
- 11/17/2015 07:42:05 PM (10 years ago)
- Location:
- digital-publishing/trunk
- Files:
-
- 2 added
- 7 edited
-
classes/cms-modules/wordpress/dpsfa-cms-wordpress-cpt-article.php (modified) (2 diffs)
-
classes/dpsfa-adobe.php (modified) (2 diffs)
-
classes/dpsfa-article.php (modified) (3 diffs)
-
classes/dpsfa-bundlr.php (modified) (7 diffs)
-
classes/dpsfa-settings.php (modified) (2 diffs)
-
digital-publishing-tools-for-wordpress.php (modified) (2 diffs)
-
libs/phpuri (added)
-
libs/phpuri/phpuri.php (added)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
digital-publishing/trunk/classes/cms-modules/wordpress/dpsfa-cms-wordpress-cpt-article.php
r1266814 r1288206 134 134 $data['internalKeywords'] = array_intersect_key( 135 135 $data['internalKeywords'], 136 array_unique(array_map( strtolower,$data['internalKeywords']))136 array_unique(array_map('strtolower',$data['internalKeywords'])) 137 137 ); 138 138 $data['internalKeywords'] = array_values($data['internalKeywords']); … … 143 143 $data['keywords'] = array_intersect_key( 144 144 $data['keywords'], 145 array_unique(array_map( strtolower,$data['keywords']))145 array_unique(array_map('strtolower',$data['keywords'])) 146 146 ); 147 147 $data['keywords'] = array_values($data['keywords']); -
digital-publishing/trunk/classes/dpsfa-adobe.php
r1266814 r1288206 86 86 87 87 $url = "$endpoint/publication/$publication/$entityType/$entityName"; 88 88 89 89 // EXECUTE 90 90 $curl = new Curl('PUT', $url, $headers, $this->prepEntity($entity)); 91 91 92 92 // VERIFY RESPONSE 93 93 $this->verify_response($curl, $entity); … … 829 829 $attributes = array(); 830 830 foreach(get_object_vars($entity) as $key => $value){ 831 if(in_array($key, $entity->apiAllowed ) && !empty($value)){831 if(in_array($key, $entity->apiAllowed()) && !empty($value)){ 832 832 $attributes[$key] = $value; 833 833 } -
digital-publishing/trunk/classes/dpsfa-article.php
r1266814 r1288206 20 20 public $articleText = ''; 21 21 public $isAd = FALSE; 22 public $adType = ' static';22 public $adType = ''; 23 23 public $adCategory = ''; 24 24 public $advertiser = ''; … … 51 51 $this->template = $defaultTemplate['path']; 52 52 } 53 54 if(!$this->isAd){ 55 $this->adType = null; 56 $this->advertiser = null; 57 $this->adCategory = null; 58 } 53 59 } 54 60 … … 68 74 } 69 75 70 public $apiAllowed = array( 71 'author', 72 'authorUrl', 73 'articleText', 74 'isAd', 75 'adType', 76 'adCategory', 77 'advertiser', 78 'accessState', 79 'hideFromBrowsePage', 80 'isTrustedContent', 81 'entityType', 82 'entityName', 83 'title', 84 '_links', 85 'shortTitle', 86 'abstract', 87 'shortAbstract', 88 'keywords', 89 'internalKeywords', 90 'department', 91 'category', 92 'importance', 93 'socialShareUrl', 94 'availabilityDate' 95 ); 76 public function apiAllowed(){ 77 return array( 78 'author', 79 'authorUrl', 80 'articleText', 81 'isAd', 82 'adType', 83 'adCategory', 84 'advertiser', 85 'accessState', 86 'hideFromBrowsePage', 87 'isTrustedContent', 88 'entityType', 89 'entityName', 90 'title', 91 '_links', 92 'shortTitle', 93 'abstract', 94 'shortAbstract', 95 'keywords', 96 'internalKeywords', 97 'department', 98 'category', 99 'importance', 100 'socialShareUrl', 101 'availabilityDate' 102 ); 103 } 96 104 97 105 public $internalFields = array( -
digital-publishing/trunk/classes/dpsfa-bundlr.php
r1266814 r1288206 12 12 if( $_SERVER[ 'SCRIPT_FILENAME' ] == __FILE__ ) 13 13 die( 'Access denied.' ); 14 15 14 16 15 require_once( DPSFA_DIR . '/libs/Mustache/Autoloader.php' ); … … 100 99 ob_start(); 101 100 include_once($template); 102 $output = ob_get_clean(); 103 $files = $this->get_files_from_template( $entity ); 101 ob_get_clean(); 102 $templateFiles = $this->get_files_from_template( $entity ); 103 104 /* DOWNLOAD COLLECTED FILES FROM TEMPLATE FILES */ 105 foreach($templateFiles as $file){ 106 if(is_array($file)){ 107 foreach($file as $key => $path){ 108 $files[$key] = $this->save_file(basename($key), $path); 109 } 110 }else if(is_string($file)){ 111 $files[$this->build_asset_path($file)] = $this->save_file(basename($file), $file); 112 } 113 } 104 114 105 /* COLLECTLINKED IMAGES / MEDIA / CSS / JS FILES */106 $collected = $this->get_linked_assets_from_html($html, $ template);115 /* PARSE HTML AND DOWNLOAD LINKED IMAGES / MEDIA / CSS / JS FILES */ 116 $collected = $this->get_linked_assets_from_html($html, $entity); 107 117 $files = array_merge( $files, $collected["assets"] ); 108 $files["index.html"] = $this->make_file("index", (string)$collected["html"]);118 $files["index.html"] = $this->make_file("index", $this->pretty_html( (string)$collected["html"] )); 109 119 110 120 /* VERIFY ARTICLE FILES */ … … 3174 3184 } 3175 3185 3186 /* Call filter for getting additional files from a custom template */ 3176 3187 private function get_files_from_template( $entity ){ 3177 /* Call filter for getting additional files from a custom template */3178 3188 $CMS = new CMS(); 3179 3189 $templateFiles = $CMS->get_template_files($entity); 3180 $templateFiles = is_array($templateFiles) ? $templateFiles : array(); 3181 3182 // Download files 3183 foreach($templateFiles as $key=>$file){ 3184 $templateFiles[$key] = $this->save_file(basename($key), $file); 3185 } 3186 3187 return $templateFiles; 3190 return is_array($templateFiles) ? $templateFiles : array(); 3188 3191 } 3189 3192 … … 3332 3335 private function get_html_content( $entity ){ 3333 3336 $file = tempnam(DPSFA_TMPDIR,"dps-"); 3334 $CMS = new CMS(); 3335 3337 $URL = $this->get_entity_url($entity); 3338 3339 $HTML = file_get_contents( $URL ); 3340 return str_get_html($HTML); 3341 } 3342 3343 private function get_entity_url( $entity ){ 3336 3344 // If entity is associated with a device add it to the URL for the template 3337 3345 $width = !empty($entity->device) ? $entity->device->width : ""; 3338 3346 3339 3347 // Append folioBuilder attribute in URL 3348 $CMS = new CMS(); 3340 3349 $URL = $CMS->get_entity_url($entity); 3341 3350 $URL = parse_url($URL, PHP_URL_QUERY) ? $URL . "&bundlr=true&width=$width" : $URL . "?bundlr=true&width=$width"; 3342 3351 3343 if(empty($URL)){ return ""; } 3352 return empty($URL) ? "" : $URL; 3353 } 3344 3354 3345 $HTML = file_get_contents( $URL );3346 return str_get_html($HTML);3347 }3348 3349 3355 private function pretty_html( $htmlString = "" ){ 3350 3356 // Tidy the HTML … … 3377 3383 /* ANY ASSETS FOUND WILL BE SAVED / RETURNED AS FILES */ 3378 3384 /* THE HTML WILL ALSO BE UPDATED WITH THESE NEW LINKS */ 3379 private function get_linked_assets_from_html($htmlStr, $ template) {3385 private function get_linked_assets_from_html($htmlStr, $entity) { 3380 3386 if(empty($htmlStr)){ 3381 3387 return array( … … 3388 3394 $assets = array(); 3389 3395 3396 $URL = $this->get_entity_url($entity); 3397 // TODO: ADD BUNDLE=FALSE for items you don't want the bundlr to touch 3398 3399 // update image to local assets folder 3390 3400 $images = $html->find('img'); 3391 $mediaSources = $html->find('source');3392 3393 $styles = $html->find('link');3394 $scripts = $html->find('script');3395 3396 // update image to local assets folder3397 3401 foreach($images as $image) { 3398 3402 if( isset($image->src) && pathinfo($image->src, PATHINFO_EXTENSION)){ 3399 $relative = (strpos($image->src, "//") === false) ? true : false; 3400 3401 if($relative){ 3402 $path = $this->get_asset_relative($image->src, $template); 3403 $assets[$image->src] = $this->save_file($image->src, $path); 3404 }else{ 3405 $path = $this->get_asset_path($image->src); 3406 $path = ltrim($path, '/'); 3407 $assets[$path] = $this->save_file(basename($path), $image->src); 3408 $image->src = $path; 3409 } 3403 $assetUrl = (strpos($image->src, "//") === false) ? $this->make_absolute($image->src, $URL) : $image->src; 3404 $assetPath = $this->build_asset_path($assetUrl); 3405 $assets[$assetPath] = $this->save_file(basename($assetUrl), $assetUrl); 3406 $image->src = $assetPath; 3410 3407 } 3411 3408 } 3412 3409 3413 3410 // update audio / video source to local assets folder 3411 $mediaSources = $html->find('source'); 3414 3412 foreach($mediaSources as $media) { 3415 3413 if( isset($media->src) && pathinfo($media->src, PATHINFO_EXTENSION)){ 3416 $relative = (strpos($media->src, "//") === false) ? true : false; 3417 3418 if($relative){ 3419 $path = $this->get_asset_relative($media->src, $template); 3420 $path = ltrim($path, '/'); 3421 $assets[$media->src] = $this->save_file($media->src, $path); 3422 }else{ 3423 $path = $this->get_asset_path($media->src); 3424 $path = ltrim($path, '/'); 3425 $assets[$path] = $this->save_file(basename($path), $media->src); 3426 $media->src = $path; 3427 } 3414 $assetUrl = (strpos($media->src, "//") === false) ? $this->make_absolute($media->src, $URL) : $media->src; 3415 $assetPath = $this->build_asset_path($assetUrl); 3416 $assets[$assetPath] = $this->save_file(basename($assetUrl), $assetUrl); 3417 $media->src = $assetPath; 3428 3418 } 3429 3419 } 3430 3420 3431 3421 // update css to local assets folder 3422 $styles = $html->find('link'); 3432 3423 foreach($styles as $style) { 3433 3424 if( isset($style->href) && $style->rel == 'stylesheet' && pathinfo($style->href, PATHINFO_EXTENSION)){ 3434 $relative = (strpos($style->href, "//") === false) ? true : false; 3435 3436 if($relative){ 3437 $path = $this->get_asset_relative($style->href, $template); 3438 $path = ltrim($path, '/'); 3439 $assets[$style->href] = $this->save_file($style->href, $path); 3440 }else{ 3441 $path = $this->get_asset_path($style->href); 3442 $path = ltrim($path, '/'); 3443 $assets[$path] = $this->save_file(basename($path), $style->href); 3444 $style->href = $path; 3445 } 3425 $assetUrl = (strpos($style->href, "//") === false) ? $this->make_absolute($style->href, $URL) : $style->href; 3426 $assetPath = $this->build_asset_path($assetUrl); 3427 $assets[$assetPath] = $this->save_file(basename($assetUrl), $assetUrl); 3428 $style->href = $assetPath; 3446 3429 } 3447 3430 } 3448 3431 3449 3432 // update javascript to local assets folder 3433 $scripts = $html->find('script'); 3450 3434 foreach($scripts as $script) { 3451 3435 if( isset($script->src) && pathinfo($script->src, PATHINFO_EXTENSION)){ 3452 $relative = (strpos($script->src, "//") === false) ? true : false; 3453 3454 if($relative){ 3455 $path = $this->get_asset_relative($script->src, $template); 3456 $path = ltrim($path, '/'); 3457 $assets[$script->src] = $this->save_file($script->src, $path); 3458 }else{ 3459 $path = $this->get_asset_path($script->src); 3460 $path = ltrim($path, '/'); 3461 $assets[$path] = $this->save_file(basename($path), $script->src); 3462 $script->src = $path; 3463 } 3436 $assetUrl = (strpos($script->src, "//") === false) ? $this->make_absolute($script->src, $URL) : $script->src; 3437 $assetPath = $this->build_asset_path($assetUrl); 3438 $assets[$assetPath] = $this->save_file(basename($assetUrl), $assetUrl); 3439 $script->src = $assetPath; 3464 3440 } 3465 3441 } … … 3471 3447 } 3472 3448 3473 /* HELPER TO DISECT ASSET URL */ 3474 private function get_asset_path( $url ){ 3475 $url = $this->make_absolute($url, ""); 3476 $url_parts = parse_url($url); 3477 $path = isset($url_parts["path"]) ? $url_parts["path"] : ""; 3478 return $path; 3479 } 3480 3481 private function get_asset_relative($url, $template){ 3482 $templatePath = pathinfo($template); 3483 $path = $templatePath['dirname'] . "/" . ltrim($url, '/'); 3484 return $path; 3449 private function build_asset_path( $url ){ 3450 $pathParts = parse_url($url); 3451 $hostFolder = isset($pathParts["host"]) ? preg_replace('/[^a-z0-9\.]/', '', strtolower($pathParts["host"])) : ""; 3452 return $hostFolder . $pathParts["path"]; 3485 3453 } 3486 3454 3487 // HELPER TO MAKE ABS URL 3488 private function make_absolute($url, $base) { 3489 // Return base if no url 3490 if( ! $url) return $base; 3491 3492 // Return if already absolute URL 3493 if(parse_url($url, PHP_URL_SCHEME) != '') return $url; 3494 3495 // Urls only containing query or anchor 3496 if($url[0] == '#' || $url[0] == '?') return $base.$url; 3497 3498 // Parse base URL and convert to local variables: $scheme, $host, $path 3499 extract(parse_url($base)); 3500 3501 // If no path, use / 3502 if( ! isset($path)) $path = '/'; 3503 3504 // Remove non-directory element from path 3505 $path = preg_replace('#/[^/]*$#', '', $path); 3506 3507 // Destroy path if relative url points to root 3508 if($url[0] == '/') $path = ''; 3509 3510 // Dirty absolute URL 3511 $abs = "$host$path/$url"; 3512 3513 // Replace '//' or '/./' or '/foo/../' with '/' 3514 $re = array('#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#'); 3515 for($n = 1; $n > 0; $abs = preg_replace($re, '/', $abs, -1, $n)) {} 3516 3517 // Absolute URL is ready! 3518 return $scheme.'://'.$abs; 3519 } 3455 private function make_absolute( $relative, $url ){ 3456 require_once( DPSFA_DIR . '/libs/phpuri/phpuri.php' ); 3457 return \phpUri::parse($url)->join($relative); 3458 } 3520 3459 3521 3460 } // END Bundlr -
digital-publishing/trunk/classes/dpsfa-settings.php
r1256996 r1288206 147 147 // Update user permissions 148 148 $this->update_api_permissions(); 149 $this->refresh();150 149 } 151 150 } … … 162 161 163 162 public function get_settings(){ 163 $this->update_api(); 164 164 $CMS = new CMS(); 165 165 return $CMS->get_settings(); -
digital-publishing/trunk/digital-publishing-tools-for-wordpress.php
r1266814 r1288206 4 4 * Plugin URI: http://studiomercury.github.io/digital-publishing-tools-for-wordpress 5 5 * Description: Digital Publishing Tools for WordPress is a plugin that allows anyone to create articles for Adobe's Digital Publishing Solution directly from WordPress. 6 * Version: 2.0. 96 * Version: 2.0.10 7 7 * Author: Studio Mercury 8 8 * Author URI: http://studiomercury.github.io/digital-publishing-tools-for-wordpress … … 17 17 18 18 // Generic Plugin Settings 19 define( 'DPSFA_VERSION', '2.0. 9' );19 define( 'DPSFA_VERSION', '2.0.10' ); 20 20 define( 'DPSFA_NAME', 'Digital Publishing Tools for WordPress' ); 21 21 define( 'DPSFA_SHORT_NAME', 'Digital Publishing' ); -
digital-publishing/trunk/readme.txt
r1266814 r1288206 4 4 Requires at least: 3.5 5 5 Tested up to: 4.3.1 6 Stable tag: 2.0. 96 Stable tag: 2.0.10 7 7 License: GPLv2 or later 8 8
Note: See TracChangeset
for help on using the changeset viewer.