Plugin Directory

Changeset 1132529


Ignore:
Timestamp:
04/11/2015 05:24:16 AM (11 years ago)
Author:
guavaworks
Message:

1.2 - add sanitation - code updates

Location:
angularjs-for-wp/trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • angularjs-for-wp/trunk/angularjs-templates/post-content.html

    r932250 r1132529  
    33-->
    44
    5 <div ng-bind-html="post.content_raw | unsafe"></div>
     5<div ng-bind-html="content | unsafe"></div>
  • angularjs-for-wp/trunk/includes/contentFilter.php

    r1105778 r1132529  
    44    global $post;
    55   
    6     $content = '<div ng-app="wpAngularPlugin">'.$content.'</div>';
    7    
    86    $meta = get_post_meta($post->ID, 'angularjsLoad', true);
    97    $meta = intval($meta);
    108
    119    if($meta){
    12         $content = '<ng-post-content id="'.$post->ID.'"></ng-post-content>';
     10        $content = '<div ng-app="wpAngularPlugin"><ng-post-content id="'.$post->ID.'" content="'.$content.'"></ng-post-content></div>';
     11    } else {
     12        $content = '<div ng-app="wpAngularPlugin">'.$content.'</div>';
    1313    }
    1414
  • angularjs-for-wp/trunk/js/angular-app.js

    r1105778 r1132529  
    1 var angular_app = angular.module('wpAngularPlugin', []);
     1var angular_app = angular.module('wpAngularPlugin', ['ngSanitize']);
    22
    33angular_app.filter('unsafe', function($sce) {
    44    return function(val) {
    5         return $sce.trustAsHtml(val);
     5        if( $sce.trustAsHtml(val) )
     6            return $sce.trustAsHtml(val).toString();
    67    };
    78});
     
    1213    });
    1314});
     15
     16angular_app.directive('ngRender', ['$compile', function ($compile) {
     17    return {
     18      restrict: 'E',
     19      scope: {
     20        html: '='
     21      },
     22      link: function postLink(scope, element, attrs) {
     23
     24          function appendHtml() {
     25              if(scope.html) {
     26                  var newElement = angular.element(scope.html);
     27                  $compile(newElement)(scope);
     28                  element.append(newElement);
     29              }
     30          }
     31
     32          scope.$watch(function() { return scope.html }, appendHtml);
     33      }
     34    };
     35  }]);
  • angularjs-for-wp/trunk/js/angular-posts-directives.js

    r1105778 r1132529  
    1313            search: '@search',
    1414            postType: '@postType',
    15             perPage: '@perPage'
     15            perPage: '@perPage',
     16            page: '@page'
    1617        },
    1718        controller: ['$scope', '$http', function($scope, $http) {
    18             $scope.getPosts = function(filters, postType){
     19            $scope.getPosts = function(filters, postType, page){
    1920                $scope.baseURL = wpAngularVars.base + '/posts?';
    2021
     
    2526                }
    2627                if(postType){
    27                     $scope.baseURL = $scope.baseURL + 'type[]=' + postType;
     28                    $scope.baseURL = $scope.baseURL + '&type[]=' + postType;
    2829                }
     30                if(page){
     31                        $scope.baseURL = $scope.baseURL + '&page=' + page;
     32                }
    2933                $http.get($scope.baseURL).then(function(res){
    3034                    $scope.postsD = res.data;
     
    4549            if($scope.search) { $scope.filters.push({'filter': 's', 'value': $scope.search}); }
    4650            if($scope.perPage) { $scope.filters.push({'filter': 'posts_per_page', 'value': $scope.perPage}); }
    47             if($scope.page) { $scope.filters.push({'filter': 'posts_per_page', 'value': $scope.page}); }
    48                    
     51            if($scope.page) { $scope.filters.push({'filter': 'posts_per_page', 'value': $scope.page}); }   
     52           
    4953            $scope.getPosts($scope.filters, $scope.postType);
    5054        },
     
    7983        restrict: 'E',
    8084        scope: {
    81             id: '='
     85            id: '=',
     86            content: '@'
    8287        },
    83         controller: ['$scope', '$http', function($scope, $http) {
    84             $scope.getPost = function(id) {
    85             $http.get(wpAngularVars.base + '/posts/' + id + '?context=edit&_wp_json_nonce=' + wpAngularVars.nonce).then(function(res){
    86                 $scope.post = res.data;
    87             });
    88         }
    89     }],
    90     link: function($scope, $elm, attrs, ctrl){
    91         $scope.getPost($scope.id);
    92     },
    9388        template: '<div class="ngSingleWrapper"><ng-include src="\''+wpAngularVars.template_directory.post_content+'\'"></ng-include></div>'
    9489    }
    9590}]);
     91
    9692
    9793angular_app.directive('ngNewPost', ['$http', '$rootScope', function($http, $rootScope){
  • angularjs-for-wp/trunk/plugin.php

    r1105778 r1132529  
    2626        // Angular Core
    2727        wp_enqueue_script('angular-core', plugin_dir_url( __FILE__ ).'js/angular.min.js', array('jquery'), null, false);
     28        wp_enqueue_script('angular-sanitize', plugin_dir_url( __FILE__ ).'js/angular-sanitize.min.js', array('jquery'), null, false);
    2829        wp_enqueue_script('angular-app', plugin_dir_url( __FILE__ ).'js/angular-app.js', array('jquery'), null, false);
    2930
  • angularjs-for-wp/trunk/readme.txt

    r1105778 r1132529  
    1515AngularJS for WordPress was created to help anyone leverage the power of AngularJS and easily add it into their own theme. 
    1616 
    17 AngularJS is a client-side template framework that lets you extend HTML vocabulary for your applications. It has a markup more similar to what HTML used to be. HTML its not a dynamic language
    18 by itself, with AngularJS it is.
     17AngularJS is a client-side template framework that lets you extend HTML vocabulary for your applications. It has a markup more similar to what HTML used to be. HTML its not a dynamic language by itself, with AngularJS it is.
    1918 
    2019AngularJS for WordPress includes several directives (html elements) that will help you easily add in a block for a single post/page or a list. More directives will be added in.
     
    2322 
    2423For even easier use for specific pages a new post meta box has been added. If selected the AngularJS directive will take over loading the content of the page client-side. This feature uses the post-content.html template.
    25  
     24
    2625View [documentation](http://www.roysivan.com/angularjs-for-wordpress) for how to utilize the directives and shortcodes
    27 
    2826
    2927== Installation ==
     
    6765* Added Taxonomy and post type to new post creation
    6866
    69 =1.1.2=
     67= 1.2 =
    7068* Fix for new post template [fixing issue](https://wordpress.org/support/topic/template-override-for-new-posthtml-appears-to-not-be-working?replies=2#post-6635530)
    71  
    72  =1.2=
    73  * No more global Angular App - redefined app to be more modular friendly
Note: See TracChangeset for help on using the changeset viewer.