定制 luperi/page-annotator-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

luperi/page-annotator-bundle

Composer 安装命令:

composer require luperi/page-annotator-bundle

包简介

Bundle to annotate html pages, developed for annotatorjs

README 文档

README

Installation

Step 1: Download the bundle

Add this snippet of code in composer.json:

"require": {
    // ...
    
    "luperi/page-annotator-bundle": "dev-master"
}

Step 2: Enable the bundle

Register the bundle in app/AppKernel.php:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...

        new Luperi\PageAnnotatorBundle\PageAnnotatorBundle(),
    );
}

Step 3: Composer update

Open a console window, enter into the project directory and run the following code:

    php composer.phar update

If you get memory errors, try increasing it with this code:

    php -dmemory_limit=1G composer.phar update

Step 4: Database connection parameters

Edit app/config/config.yml adding the following lines:

# Doctrine Configuration
doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver:   %database_driver%
                host:     %database_host%
                port:     %database_port%
                dbname:   %database_name%
                user:     %database_user%
                password: %database_password%
                charset:  UTF8
            annotation:
                driver:   %database_driver%
                host:     %database_host%
                port:     %database_port%
                dbname:   annotations_DB
                user:     %database_user%
                password: %database_password%
                charset:  UTF8

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        default_entity_manager: default
        entity_managers:
            default:
                // ...
            annotation:
                connection: annotation
                mappings:
                    PageAnnotatorBundle:
                        type: annotation

Step 5: Database creation

Open a console window, enter into the project directory and run the following code:

    php app/console doctrine:database:create --connection=annotation

Step 6: Database table creation

Open a console window, enter into the project directory and run the following code:

    php app/console doctrine:schema:update --force --em=annotation

Utilization

In your html page import the libraries by adding these lines:

    <script type="text/javascript" src="http://assets.annotateit.org/annotator/v1.2.10/annotator-full.min.js"></script>
    <script type="text/javascript" src="{{ path("page_annotator_library_js") }}"></script>

And the style:

    <link rel="stylesheet" href="http://assets.annotateit.org/annotator/v1.2.10/annotator.min.css">

Example with standard annotator

N.B.: the two following examples use twig to resolve the routes

<html>    
    <head>
        <script type="text/javascript" src="http://assets.annotateit.org/annotator/v1.2.10/annotator-full.min.js"></script>
        <script type="text/javascript" src="{{ path("page_annotator_library_js") }}"></script>
        <link rel="stylesheet" href="http://assets.annotateit.org/annotator/v1.2.10/annotator.min.css">
        
        <script>
        $(function(){
            // Add store plugin
            $('#container').annotator()
                            .annotator('addPlugin', 'Store',
                                    {
                                        prefix: '',

                                        annotationData: {
                                            'uri': '<your_url>'
                                        },

                                        loadFromSearch:
                                        {
                                            'limit': 0,
                                            'uri' : '<your_url>'
                                        },

                                        urls: {
                                            // These are the default URLs.
                                            create:  '{{ path("page_annotator_save") }}',
                                            update:  '{{ path("page_annotator_save") }}',
                                            destroy: '{{ path("page_annotator_delete") }}',
                                            search:  '{{ path("page_annotator_search", { 'uri' : '<your_url>' }) }}'
                                        }
                                    });

            // Set Annotator Language, for example Italian
            setAnnotatorLanguage("it");
        });
        </script>
    </head>
        <body>
            <div id='container'>
                Here there is the text that must be annotated.
            </div>
        </body>
</html>

Example with fixed values

If you want to annotate with prefixed values instead of free comments, yuo have to modify your code in this way:

<html>    
    <head>
        <script type="text/javascript" src="http://assets.annotateit.org/annotator/v1.2.10/annotator-full.min.js"></script>
        <script type="text/javascript" src="{{ path("page_annotator_library_js") }}"></script>
        <link rel="stylesheet" href="http://assets.annotateit.org/annotator/v1.2.10/annotator.min.css">
        
        <script>
        $(function(){
            // Init plugins
            Annotator.Plugin.SavingAnnotation = (function() {

                function SavingAnnotation(element, options) {
                    this.element = element;
                    this.options = options;
                }

                SavingAnnotation.prototype.pluginInit = function() {
                    this.annotator
                            .subscribe("beforeAnnotationCreated", function (annotation) {
                                console.info("The annotation: %o is going to be created!", annotation);
                                setAnnotatorFixedValueSelector("null");
                            })
                            .subscribe("annotationCreated", function (annotation) {
                                console.info("The annotation: %o has just been created!", annotation)
                                annotation.text = annotationCommentValue;
                            })
                            .subscribe("annotationEditorShown", function (editor, annotation) {
                                console.info("The annotation: %o is going to be updated!", annotation);
                                setAnnotatorFixedValueSelector(annotation.text);
                            })
                            .subscribe("annotationUpdated", function (annotation) {
                                console.info("The annotation: %o has just been updated!", annotation);
                                annotation.text = annotationCommentValue;
                            })
                };
                return SavingAnnotation;
            })();

            // Add all necessary plugins
            $('#container').annotator()
                            .annotator('addPlugin', 'SavingAnnotation')
                            .annotator('addPlugin', 'Tags')
                            .annotator('addPlugin', 'Store',
                                    {
                                        prefix: '',

                                        annotationData: {
                                            'uri': '<your_url>'
                                        },

                                        loadFromSearch:
                                        {
                                            'limit': 0,
                                            'uri' : '<your_url>'
                                        },

                                        urls: {
                                            // These are the default URLs.
                                            create:  '{{ path("page_annotator_save") }}',
                                            update:  '{{ path("page_annotator_save") }}',
                                            destroy: '{{ path("page_annotator_delete") }}',
                                            search:  '{{ path("page_annotator_search", { 'uri' : '<your_url>' }) }}'
                                        }
                                    });


            // Set Annotator Language, for example Italian
            setAnnotatorLanguage("it");

            // Set fixed values
            var values = ["Tag1", "Tag2", "Tag3"];
            annotateWithFixedValues(values);
        });
        </script>
    </head>
        <body>
            <div id='container'>
                Here there is the text that must be annotated.
            </div>
        </body>
</html>

Supported Languages

  • Italian -> "it"
  • Spanish -> "es"
  • French -> "fr"
  • German -> "de"

Other available actions

You can easily delete all annotation in two ways. If you want to delete all the annotations saved in the DB:

    deleteAllAnnotations();

Instead, if you want to delete only the annotations about a specific url, you can do this:

    deleteAllAnnotationsByUrl("<your_url>");

In your PHP code, yuo can manage annotations as entity object in this way:

    use Luperi\PageAnnotatorBundle\Controller\AnnotationController;
    
    class YourClassController extends Controller
    {
        public function YourAction()
        {
            $annotations = AnnotationController::getAll();
    
            return $this->render('YourBundle:YourClass:Your.html.twig', ['annotations' => $annotations]);
        }
    
    }

See PageAnnotatorBundle/Entity/Annotation.php for available methods

License

This bundle is released under the MIT license. See the complete license in the bundle:

Resources/meta/LICENSE

luperi/page-annotator-bundle 适用场景与选型建议

luperi/page-annotator-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 115 次下载、GitHub Stars 达 10, 最近一次更新时间为 2015 年 03 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「html」 「annotator」 「annotatorjs」 「annotate」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 luperi/page-annotator-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 luperi/page-annotator-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 luperi/page-annotator-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 115
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-03-25