Changeset 19662


Ignore:
Timestamp:
Dec 30, 2012, 9:09:34 PM (8 years ago)
Author:
julien1311
Message:

more extensions supported

Location:
extensions/pdf2tab
Files:
3 added
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • extensions/pdf2tab/main.inc.php

    r19310 r19662  
    1111if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    1212
     13define('PDF2TAB_ABSOLUTE_PATH' , dirname(__FILE__).'/');
    1314define('PDF2TAB_DIR' , basename(dirname(__FILE__)));
    1415define('PDF2TAB_PATH' , PHPWG_PLUGINS_PATH.PDF2TAB_DIR.'/');
     
    1819 * +-----------------------------------------------------------------------+ */
    1920       
    20 include_once(PDF2TAB_PATH.'thumbnails.php');
    21 include_once(PDF2TAB_PATH.'picture.php');
     21include_once(PDF2TAB_PATH.'include/thumbnails.inc.php');
     22include_once(PDF2TAB_PATH.'include/picture.inc.php');
    2223?>
  • extensions/pdf2tab/picture.php

    r19332 r19662  
    11<?php
    2 add_event_handler('render_element_content','pdf2tab_add_tag_picture',EVENT_HANDLER_PRIORITY_NEUTRAL+10,2);
     2add_event_handler('render_element_content','pdf2tab_add_links_picture',EVENT_HANDLER_PRIORITY_NEUTRAL+10,2);
    33
    44load_language('plugin.lang', PDF2TAB_PATH);
    55
    6 function pdf2tab_add_tag_picture($content, $element_info) {
    7         if (strrchr($element_info['file'], ".") == ".pdf") {
    8                 preg_match('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i',$content,$match);
    9                
    10                 $content = str_replace($match[0],'<a href="'.$element_info['element_url'].'" target="_blank" title="'.l10n('Open the file in a new tab').'">'.$match[0].'</a>',$content);
     6function pdf2tab_add_links_picture($content, $element_info) {
     7        include_once('include/constants.inc.php');
     8
     9        if (in_array(strtolower(substr(strrchr($element_info['file'], "."),1)), $supported_extensions)) {
     10                $content = pdf2tab_add_link_image($content, $element_info);
     11                $content = pdf2tab_add_link_beside_image($content, $element_info);
    1112        }
    1213       
    1314        return $content;
    1415}
     16
     17function pdf2tab_add_link_image($content, $element_info) {
     18        preg_match('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i',$content,$match);
     19        $content = str_replace($match[0],'<a href="'.$element_info['element_url'].'" target="_blank" title="'.l10n('Open the file in a new tab').'">'.$match[0].'</a>',$content);
     20       
     21        return $content;
     22}
     23
     24function pdf2tab_add_link_beside_image($content, $element_info) {
     25        $content .= '<p class="imageComment"><a href="'.$element_info['element_url'].'" target="_blank" title="'.l10n('Open the file in a new tab').'">'.l10n('Open the file in a new tab').'</a>';
     26       
     27        return $content;
     28}
    1529?>
  • extensions/pdf2tab/template/thumbnails.tpl

    r19617 r19662  
     1{combine_script id="jquery" load="header"}
    12{html_head}
    23{literal}
     
    45        //Add a link to the thumbnail
    56        function pdf2tab_link() {
    6                 $("img[pdf2tab$=pdf]").closest('a').attr("target","_blank");
     7                $("img[class=thumbnail]").each(function() {
     8                        var filename_array = $(this).attr("pdf2tab").split(".");
     9                        var filename_extension = filename_array[filename_array.length-1].toLowerCase();
     10                       
    711{/literal}
    8                 $("img[pdf2tab$=pdf]").attr("title","{'Open the file in a new tab'|@translate}");
     12                        var pdf2tab_supported_extensions = new Array();
     13                        {foreach from=$pdf2tab_supported_extensions item=extension name=loop}
     14                                pdf2tab_supported_extensions[{$smarty.foreach.loop.index}] = "{$extension}";
     15                        {/foreach}
    916{literal}
    10                 $("img[pdf2tab$=pdf]").closest('a').attr("href",$("img[pdf2tab$=pdf]").attr("pdf2tab"));
     17                        if(jQuery.inArray(filename_extension, pdf2tab_supported_extensions) != -1)
     18                        {
     19                                $(this).closest('a').attr({
     20                                        target: "_blank",
     21                                        href: $(this).attr("pdf2tab")
     22                                });
     23{/literal}
     24                                $(this).attr("title","{'Open the file in a new tab'|@translate}");
     25{literal}
     26                        }                       
     27                });
    1128        }
    1229 
  • extensions/pdf2tab/thumbnails.php

    r19332 r19662  
    66function pdf2tab_thumbnails($tpl_thumbnails_var) {
    77        global $template;
    8 
     8        include_once('include/constants.inc.php');
     9       
    910        $template->set_prefilter('index_thumbnails', 'pdf2tab_add_tag_thumbnails');
    1011       
    11         $template->set_filename('pdf2tab_template_thumbnails', dirname(__FILE__).'/template/pdf2tab_thumbnails.tpl');
     12        $template->assign('pdf2tab_supported_extensions', $supported_extensions);
     13        $template->set_filename('pdf2tab_template_thumbnails', PDF2TAB_ABSOLUTE_PATH.'template/thumbnails.tpl');
    1214        $template->concat('PLUGIN_INDEX_CONTENT_END', $template->parse('pdf2tab_template_thumbnails', true));
    1315       
Note: See TracChangeset for help on using the changeset viewer.