Plugin Directory

Changeset 1288206


Ignore:
Timestamp:
11/17/2015 07:42:05 PM (10 years ago)
Author:
StudioMercury
Message:

2.0.10

Location:
digital-publishing/trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • digital-publishing/trunk/classes/cms-modules/wordpress/dpsfa-cms-wordpress-cpt-article.php

    r1266814 r1288206  
    134134                $data['internalKeywords'] = array_intersect_key(
    135135                    $data['internalKeywords'],
    136                     array_unique(array_map(strtolower,$data['internalKeywords']))
     136                    array_unique(array_map('strtolower',$data['internalKeywords']))
    137137                );
    138138                $data['internalKeywords'] = array_values($data['internalKeywords']);
     
    143143                $data['keywords'] = array_intersect_key(
    144144                    $data['keywords'],
    145                     array_unique(array_map(strtolower,$data['keywords']))
     145                    array_unique(array_map('strtolower',$data['keywords']))
    146146                );
    147147                $data['keywords'] = array_values($data['keywords']);
  • digital-publishing/trunk/classes/dpsfa-adobe.php

    r1266814 r1288206  
    8686           
    8787            $url = "$endpoint/publication/$publication/$entityType/$entityName";
    88            
     88
    8989            // EXECUTE
    9090            $curl = new Curl('PUT', $url, $headers, $this->prepEntity($entity));           
    91            
     91
    9292            // VERIFY RESPONSE
    9393            $this->verify_response($curl, $entity);
     
    829829            $attributes = array();
    830830            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)){
    832832                    $attributes[$key] = $value;
    833833                }
  • digital-publishing/trunk/classes/dpsfa-article.php

    r1266814 r1288206  
    2020        public $articleText = '';
    2121        public $isAd = FALSE;
    22         public $adType = 'static';
     22        public $adType = '';
    2323        public $adCategory = '';
    2424        public $advertiser = '';
     
    5151                $this->template = $defaultTemplate['path'];
    5252            }
     53           
     54            if(!$this->isAd){
     55                $this->adType = null;
     56                $this->advertiser = null;
     57                $this->adCategory = null;
     58            }
    5359        }
    5460       
     
    6874        }
    6975                       
    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        }
    96104       
    97105        public $internalFields = array(
  • digital-publishing/trunk/classes/dpsfa-bundlr.php

    r1266814 r1288206  
    1212if( $_SERVER[ 'SCRIPT_FILENAME' ] == __FILE__ )
    1313    die( 'Access denied.' );
    14 
    1514
    1615require_once( DPSFA_DIR . '/libs/Mustache/Autoloader.php' );
     
    10099            ob_start();
    101100            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            }
    104114
    105             /* COLLECT LINKED 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);
    107117            $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"] ));
    109119           
    110120            /* VERIFY ARTICLE FILES */
     
    31743184        }
    31753185       
     3186        /* Call filter for getting additional files from a custom template */
    31763187        private function get_files_from_template( $entity ){
    3177             /* Call filter for getting additional files from a custom template */
    31783188            $CMS = new CMS();
    31793189            $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();
    31883191        }
    31893192       
     
    33323335        private function get_html_content( $entity ){
    33333336            $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 ){         
    33363344            // If entity is associated with a device add it to the URL for the template
    33373345            $width = !empty($entity->device) ? $entity->device->width : "";
    33383346           
    33393347            // Append folioBuilder attribute in URL
     3348            $CMS = new CMS();
    33403349            $URL = $CMS->get_entity_url($entity);
    33413350            $URL = parse_url($URL, PHP_URL_QUERY) ? $URL . "&bundlr=true&width=$width" : $URL . "?bundlr=true&width=$width";
    33423351           
    3343             if(empty($URL)){ return ""; }
     3352            return empty($URL) ? "" : $URL;
     3353        }
    33443354           
    3345             $HTML = file_get_contents( $URL );
    3346             return str_get_html($HTML);
    3347         }
    3348    
    33493355        private function pretty_html( $htmlString = "" ){           
    33503356            // Tidy the HTML
     
    33773383        /* ANY ASSETS FOUND WILL BE SAVED / RETURNED AS FILES */
    33783384        /* 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) {
    33803386            if(empty($htmlStr)){
    33813387                return array(
     
    33883394            $assets = array();
    33893395           
     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
    33903400            $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 folder
    33973401            foreach($images as $image) {
    33983402                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;
    34103407                }
    34113408            }
    34123409           
    34133410            // update audio / video source to local assets folder
     3411            $mediaSources = $html->find('source');
    34143412            foreach($mediaSources as $media) {
    34153413                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;
    34283418                }
    34293419            }
    34303420           
    34313421            // update css to local assets folder
     3422            $styles = $html->find('link');
    34323423            foreach($styles as $style) {
    34333424                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;
    34463429                }
    34473430            }
    34483431   
    34493432            // update javascript to local assets folder
     3433            $scripts = $html->find('script');
    34503434            foreach($scripts as $script) {
    34513435                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;
    34643440                }
    34653441            }
     
    34713447        }
    34723448       
    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"];
    34853453        }
    34863454               
    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        }
    35203459
    35213460    } // END Bundlr
  • digital-publishing/trunk/classes/dpsfa-settings.php

    r1256996 r1288206  
    147147                // Update user permissions
    148148                $this->update_api_permissions();
    149                 $this->refresh();
    150149            }
    151150        }
     
    162161
    163162        public function get_settings(){
     163            $this->update_api();
    164164            $CMS = new CMS();
    165165            return $CMS->get_settings();
  • digital-publishing/trunk/digital-publishing-tools-for-wordpress.php

    r1266814 r1288206  
    44 *   Plugin URI: http://studiomercury.github.io/digital-publishing-tools-for-wordpress
    55 *   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.9
     6 *   Version: 2.0.10
    77 *   Author: Studio Mercury
    88 *   Author URI: http://studiomercury.github.io/digital-publishing-tools-for-wordpress
     
    1717
    1818// Generic Plugin Settings
    19 define( 'DPSFA_VERSION',                '2.0.9' );
     19define( 'DPSFA_VERSION',                '2.0.10' );
    2020define( 'DPSFA_NAME',                   'Digital Publishing Tools for WordPress' );
    2121define( 'DPSFA_SHORT_NAME',             'Digital Publishing' );
  • digital-publishing/trunk/readme.txt

    r1266814 r1288206  
    44Requires at least: 3.5
    55Tested up to: 4.3.1
    6 Stable tag: 2.0.9
     6Stable tag: 2.0.10
    77License: GPLv2 or later
    88
Note: See TracChangeset for help on using the changeset viewer.