WordPress.org

Plugin Directory

Changeset 1557956


Ignore:
Timestamp:
12/20/16 03:52:28 (10 months ago)
Author:
_Y_Power
Message:

Added multi-language support, added Wikipedia logo for undefined search

Location:
visual-chap/trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • visual-chap/trunk/includes/js/wikipedia-visual-chap.js

    r1555186 r1557956  
    3737        results: [], 
    3838        lastPositionY: 0, 
     39        language: (document.documentElement.lang.length > 2) ? document.documentElement.lang.slice(0, 2) : document.documentElement.lang, 
    3940        // from WP options 
    4041        options: WVCWPOptions, 
    4142        wordsFilter: (WVCWPOptions.wvcWordsFilter === '') ? '' : WVCWPOptions.wvcWordsFilter.split(/[\,]+/) 
    4243    }; 
    43  
     44    console.log(wikipediaVisualChap.language); 
     45     
    4446     // FUNCTIONS  
    4547 
     
    355357        /* reset old search - comment to save results */ 
    356358        wikipediaVisualChap.results = []; 
    357         var queryString = 'https://en.wikipedia.org/w/api.php?action=query&titles=' + query + '&prop=imageinfo|pageprops|images|pageimages|pageterms|links&iiprop=url&pilimit=10&redirects=return&origin=*&ascii=&format=json&formatversion=2'; 
     359        var pageLocalLang = wikipediaVisualChap.language, 
     360            queryString = 'https://' + pageLocalLang + '.wikipedia.org/w/api.php?action=query&titles=' + query + '&prop=imageinfo|pageprops|images|pageimages|pageterms|links&iiprop=url&pilimit=10&redirects=return&origin=*&ascii=&format=json&formatversion=2'; 
    358361        jQ.ajax({ 
    359362        url: queryString, 
     
    362365        dataType: 'json', 
    363366        success: function(data){ 
    364             //console.log('First query: ', data); 
     367            console.log('First query: ', data); 
    365368            wikipediaVisualChap.results.push(data); 
    366369            /* when request has successfully pushed the result */ 
     
    370373        }, 
    371374        complete: function(){ 
    372             queryString = 'https://en.wikipedia.org/w/api.php?action=query&titles=' + wikipediaVisualChap.results[0].query.pages[0].title + '&prop=imageinfo|pageprops|images|pageimages|pageterms|links&iiprop=url&pilimit=10&redirects=return&origin=*&ascii=&format=json&formatversion=2'; 
     375            queryString = 'https://' + pageLocalLang + '.wikipedia.org/w/api.php?action=query&titles=' + wikipediaVisualChap.results[0].query.pages[0].title + '&prop=imageinfo|pageprops|images|pageimages|pageterms|links&iiprop=url&pilimit=10&redirects=return&origin=*&ascii=&format=json&formatversion=2'; 
    373376            jQ.ajax({ 
    374377            url: queryString, 
     
    377380            dataType: 'json', 
    378381            success: function(data){ 
    379                 //console.log('Second query: ', data); 
     382                console.log('Second query: ', data); 
    380383                wikipediaVisualChap.results.push(data); 
    381384                /* when request has successfully pushed the second result */ 
     
    392395                imgNames = imgNames.join('|'); 
    393396                /* ready to request imgs */ 
    394                 queryString = 'https://en.wikipedia.org/w/api.php?action=query&titles=' + imgNames + '&prop=imageinfo&iiprop=url&redirects=return&origin=*&ascii=&format=json&formatversion=2'; 
     397                queryString = 'https://' + pageLocalLang + '.wikipedia.org/w/api.php?action=query&titles=' + imgNames + '&prop=imageinfo&iiprop=url&redirects=return&origin=*&ascii=&format=json&formatversion=2'; 
    395398                jQ.ajax({ 
    396399                url: queryString, 
     
    399402                dataType: 'json', 
    400403                success: function(data){ 
    401                     //console.log('Third query: ', data); 
     404                    console.log('Third query: ', data); 
    402405                    /* assign images property to main obj */ 
    403406                    wikipediaVisualChap.images = data; 
     
    410413                    mainImg = wikipediaVisualChap.results[1].query.pages[0].pageimage; 
    411414                    for (i = 0; i < photos.length; i++){ 
    412                     var correctedTitle = photos[i].title.replace('File:', '').replace(/ /g, '_'); 
     415                    var correctedTitle; 
     416                    /* language checks */ 
     417                    // -- TO IMPROVE!!! write complete language checks 
     418                    if (wikipediaVisualChap.language === 'en' || wikipediaVisualChap.language === 'it' || wikipediaVisualChap.language === 'es' || wikipediaVisualChap.language === 'de'){ 
     419                        correctedTitle = photos[i].title.replace('File:', '').replace(/ /g, '_'); 
     420                    } 
     421                    else if (wikipediaVisualChap.language === 'fr'){ 
     422                        correctedTitle = photos[i].title.replace('Fichier:', '').replace(/ /g, '_'); 
     423                    } 
     424                    else { 
     425                        console.log('Error! No recognized language! Please visit: http://visualchap.nouveausiteweb.fr/faq/'); 
     426                        // -- TO IMPROVE!!! - easy fix for unrecognized language (fallback to standard 'File:') 
     427                        correctedTitle = photos[i].title.replace('File:', '').replace(/ /g, '_'); 
     428                    } 
     429                    //console.log(correctedTitle); 
    413430                    if (correctedTitle === mainImg){ 
    414431                        photoLink = photos[i].imageinfo[0].url; 
     
    417434                    if ( ! mainImg){ 
    418435                        var titleCheck = photos[i].title, 
     436                        thisTitle; 
     437                        /* language checks */ 
     438                        // -- TO IMPROVE!!! write complete language checks 
     439                        if (wikipediaVisualChap.language === 'en' || wikipediaVisualChap.language === 'it' || wikipediaVisualChap.language === 'es' || wikipediaVisualChap.language === 'de'){ 
    419440                        thisTitle = photos[i].title.replace('File:', ''); 
     441                        } 
     442                        else if (wikipediaVisualChap.language === 'fr'){ 
     443                        thisTitle = photos[i].title.replace('Fichier:', ''); 
     444                        } 
     445                        else { 
     446                        console.log('Error! No recognized language! Please visit: http://visualchap.nouveausiteweb.fr/faq/'); 
     447                        // -- TO IMPROVE!!! - easy fix for unrecognized language (fallback to standard 'File:') 
     448                        thisTitle = photos[i].title.replace('File:', ''); 
     449                        } 
     450                        //console.log(thisTitle); 
    420451                        if (photos[i].imageinfo && titleCheck.search(thisTitle) >= 0){ 
    421452                        photoLink = photos[i].imageinfo[0].url; 
     
    453484                    imgUpdate = ''; 
    454485                    if (wikipediaVisualChap.results[0].query.pages[0].pageid !== undefined){ 
    455                     urlUpdate = 'http://en.wikipedia.org/?curid=' + wikipediaVisualChap.results[0].query.pages[0].pageid; 
     486                    urlUpdate = 'http://' + pageLocalLang + '.wikipedia.org/?curid=' + wikipediaVisualChap.results[0].query.pages[0].pageid; 
    456487                    } 
    457488                    /* assign images */ 
     
    473504                    } 
    474505                    if (photoLink === 'Undefined' || wikipediaVisualChap.results[0].warnings) { 
    475                         photoLink = 'img/Wikipedia-logo-v2.png'; 
     506                        photoLink = wikipediaVisualChap.options.wvcPluginsURL + '/visual-chap/assets/img/Wikipedia-logo-v2.svg'; 
    476507                        jQ('div#wikipedia-visual-chap-img-loading').removeClass('wvc-loading-image-active').addClass('wvc-loading-image-standby'); 
    477508                        /* reset image loading box */ 
     
    488519                            /* if no description is found, reset img */ 
    489520                            if (descriptionUpdate == 'No description found!'){ 
    490                             jQ('img#wikipedia-visual-chap-display-image').attr('src', '../img/Wikipedia-logo-v2.png'); 
     521                            jQ('img#wikipedia-visual-chap-display-image').attr('src', wikipediaVisualChap.options.wvcPluginsURL + '/visual-chap/assets/img/Wikipedia-logo-v2.svg'); 
    491522                            } 
    492523                            /* reset image loading box */ 
     
    499530                        /* if no description is found, reset img */ 
    500531                        if (descriptionUpdate == 'No description found!'){ 
    501                             jQ('img#wikipedia-visual-chap-display-image').attr('src', '../img/Wikipedia-logo-v2.png'); 
     532                            jQ('img#wikipedia-visual-chap-display-image').attr('src', wikipediaVisualChap.options.wvcPluginsURL + '/visual-chap/assets/img/Wikipedia-logo-v2.svg'); 
    502533                        } 
    503534                        /* reset image loading box */ 
     
    509540                    } 
    510541                    else { 
    511                     photoLink = 'img/Wikipedia-logo-v2.png'; 
     542                    photoLink = wikipediaVisualChap.options.wvcPluginsURL + '/visual-chap/assets/img/Wikipedia-logo-v2.svg'; 
    512543                    jQ('img#wikipedia-visual-chap-display-image').attr('href', photoLink); 
    513544                    /* reset image loading box */ 
  • visual-chap/trunk/readme.txt

    r1555690 r1557956  
    11=== Visual Chap === 
    2 Contributors: _y_power 
     2Contributors: _Y_Power 
    33Donate link: http://visualchap.nouveausiteweb.fr/donate/ 
    4 Tags: content, wikipedia, search, jquery, ajax 
     4Tags: content, wikipedia, search, images, jquery, ajax 
    55Requires at least: 4.6 
    66Tested up to: 4.7 
    7 Stable tag: 1.0.2 
     7Stable tag: 1.0.3 
    88License: GPLv3 or later 
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html 
     
    1717Visual Chap places its discreet icon on the side of your posts content, following any scroll of your visitor's window: tapping the icon opens a panel and the words in that content will become click-able, picture-focused Wikipedia searches. It is also possible to trigger the search by selecting ( or 'highlighting') text. 
    1818 
     19[![Visual Chap clip](https://i.ytimg.com/vi/i-rc-oUZTaU/maxresdefault.jpg)](https://youtu.be/i-rc-oUZTaU "Visual Chap clip") 
     20 
    1921Features: 
    2022 
    2123* _Y_Power's FlexSearch algorithm 
    22 * words filter 
    23 * animated UI 
    24 * top margin adjustment 
    25 * colors customization 
     24* Words filter 
     25* Animated UI 
     26* Top margin adjustment 
     27* Colors customization 
    2628 
    2729Visual Chap will be **ONLY ACTIVE IN 'EMPTY' PARAGRAPHS** - which means it will bypass a particular paragraph if it finds there are already links in it. 
    2830 
    29 Find more on the [official website] : http://visualchap.nouveausiteweb.fr/ 
     31Find more on the [official website](http://visualchap.nouveausiteweb.fr/) 
    3032 
    3133Wikipedia&reg; and the Wikipedia logos are registered trademarks of the Wikimedia Foundation. 
     
    3436 
    35371. Install Visual Chap through the WordPress plugins screen directly OR upload the plugin files to the `/wp-content/plugins/visual-chap` directory. 
    36 1. Activate the plugin through the 'Plugins' screen in WordPress 
    37 1. Use the Settings->Visual Chap screen to configure the plugin 
     381. Activate the plugin through the 'Plugins' screen in WordPress. 
     391. Use the Settings->Visual Chap screen to configure the plugin. 
    3840 
    3941== Frequently Asked Questions == 
     
    4547= How about i18(internationalization)? = 
    4648 
    47 Visual Chap is only available in English, at the moment ('en' servers). 
    48 However, it is already translatable  and I'd love to make it available in other languages as well (I'm a polyglot myself) but that would require a specific search algorithm for each domain, which could be done, with some help from other developers, just by substituting the search function in the main javascript object. Please get in touch if you'd like to help out with that. 
     49Visual Chap is only been tested on English, French, Italian, Spanish and German Wikipedia API servers, at the moment. 
     50However, it is already translatable (you can translate it in your language by using the easy WordPress translating tool) and it might work well in your website language out-of-the-box: Visual Chap will automatically detect the html page language. I'd love to make a fine search available in other languages as well (I'm a polyglot myself) but that would require a specific search algorithm for each domain, which could be done, with some help from other developers, just by substituting the search function in the main javascript object. Please get in touch if you'd like to help out with that. 
    4951 
    5052= Why doesn’t it work on all my content? = 
     53 
    5154Visual Chap will be **ONLY ACTIVE IN ‘EMPTY’ PARAGRAPHS** – which means it will bypass a particular paragraph if it finds there are already links in it. 
    5255 
     
    5760== Screenshots == 
    5861 
    59 1. Visual Chap STANDBY 
    60 2. Visual Chap ACTIVE 
     621. Visual Chap on STANDBY 
     632. Visual Chap when ACTIVE 
    61643. Settings page 
    6265 
    6366== Changelog == 
     67 
     68= 1.0.3 = 
     69* Added multi-language support, added wikipedia logo for undefined image results, updated readme description 
    6470 
    6571= 1.0.2 = 
     
    6975* Fixed directory names. 
    7076 
    71 = 1.0.0 = 
    72 * First WordPress release. 
     77== Upgrade Notice == 
    7378 
    74 == Upgrade Notice == 
     79= 1.0.3 = 
     80Added multi-language support, added wikipedia logo for undefined image results, updated readme description 
    7581 
    7682= 1.0.2 = 
     
    7985= 1.0.1 = 
    8086Fixed directory names. 
    81  
    82 = 1.0.0 = 
    83 First WordPress release. 
  • visual-chap/trunk/visual-chap.php

    r1555690 r1557956  
    44   Plugin URI:  http://visualchap.nouveausiteweb.fr/ 
    55   Description: Enriches your posts by adding a quick, 'visual' Wikipedia-powered search. 
    6    Version:     1.0.2 
     6   Version:     1.0.3 
    77   Author:      _y_power 
    88   Author URI:  http://ypower.nouveausiteweb.fr/ 
     
    9595            'wvcWordsFilter' => get_option('wikipedia-visual-chap-options-words-filter', ''), 
    9696            'wvcWikiLink' => get_option('wikipedia-visual-chap-options-wiki-donate', 0), 
    97             'wvcDevLink' => get_option('wikipedia-visual-chap-options-dev', 0) 
     97            'wvcDevLink' => get_option('wikipedia-visual-chap-options-dev', 0), 
     98            'wvcPluginsURL' => plugins_url() 
    9899        ); 
    99100        // export options to JS 
Note: See TracChangeset for help on using the changeset viewer.