Status
Not open for further replies.

NightLightW

Active Member
173
2011
23
0
Hello,
I`m using
Display PDF using Thickbox in a WordPress plugin. Plugin work great until you put three pdf file in one page and then will show you only one(first pdf file link - this mean when you click on other link you will se only the first pdf document other is not showed). So i found this code to show multiple pdf`s
Code:
function ilc_pdfbox_thecontent ($content){
    global $post;
    global $pdfbox_width;
    global $pdfbox_height;
 
    $pdfbox_height_plus = $pdfbox_height + 15;
    $pdfbox_height += 35;
 
    $pattern = "/<a>]*).(pdf)('|\")(.*?)>(.*?)/i";
    $replacement = '<a href="#TB_inline?height='.$pdfbox_height.'&width='.$pdfbox_width.'&inlineId=ilc_pdfbox_##" rel="nofollow">Launch PDF file.</a>
        ';
    preg_match_all($pattern,$content,$matches);
    foreach($matches[0] as $k=>$v){
        $new_v = preg_replace($pattern, $replacement, $v);
        $new_v = preg_replace("!##!", $k, $new_v);
        $content = preg_replace("!".preg_quote($v)."!", $new_v, $content);
    }
    return $content;
}
then i click update. and i have this error on my screen
4062484744.png


here is orginal code
Code:
function ilc_pdfbox_thecontent ($content){
    global $post;
    global $pdfbox_width;
    global $pdfbox_height;
    
    $pdfbox_height_plus = $pdfbox_height + 15;
    $pdfbox_height += 35;
    
    $pattern = "/<a(.*?)href=('|\")([^>]*).(pdf)('|\")(.*?)>(.*?)<\/a>/i";
    $replacement = '<a href="#TB_inline?height='.$pdfbox_height.'&width='.$pdfbox_width.'&inlineId=ilc_pdfbox_content" class="thickbox pdfbox">Launch PDF file.</a>
        <div id="ilc_pdfbox_content" style="display:none;"><iframe class="ilc_pdfbox_iframe" src="$3.$4" style="height:'.$pdfbox_height_plus.'px;"></iframe></div>';
    $content = preg_replace($pattern, $replacement, $content);
    //}
    return $content;
}
 
Last edited:
4 comments
There seems to be an error in the $pattern, the default pattern would also work fine to match hrefs ending with .pdf so
PHP:
function ilc_pdfbox_thecontent ($content){
    global $post;
    global $pdfbox_width;
    global $pdfbox_height;
 
    $pdfbox_height_plus = $pdfbox_height + 15;
    $pdfbox_height += 35;
 
    $pattern = "/<a(.*?)href=('|\")([^>]*).(pdf)('|\")(.*?)>(.*?)<\/a>/i";
    $replacement = '<a href="#TB_inline?height='.$pdfbox_height.'&width='.$pdfbox_width.'&inlineId=ilc_pdfbox_##" rel="nofollow">Launch PDF file.</a>';
    preg_match_all($pattern,$content,$matches);
    foreach($matches[0] as $k=>$v){
        $new_v = preg_replace($pattern, $replacement, $v);
        $new_v = preg_replace("!##!", $k, $new_v);
        $content = preg_replace("!".preg_quote($v)."!", $new_v, $content);
    }
    return $content;
}
 
i change the code with your code soft2050 - thanks for help :D
and i try to open...only url made changes and no open pdf box
toII6.jpg

gioa1.jpg

i dont know what to do why is this problem....
 
OK. I found the solution for my problem using other plugin.
Lightbox Plus is really good plugin. You can use for gallery and also if you check

5155725653.png

you will have other options like

3786617767.png



to show pdf doc i use this link

Using Secondary Lightbox for External Content

Code:
<h4 style="text-align: center;">♦ Електрични апарати и уреди ←→

 <a [SIZE=4][COLOR=Red]class="lbpModal"[/COLOR][/SIZE] title="Електрични апарати и уреди" 

 href="http://www.matura.gov.mk/data_files/state_graduate/mk/0638_Elektricni%20aparati%20i%20uredi.pdf">

Here put name to be hyper link</a></h4>
and here is what is showing on the screen

you need only in hyper link to put class="IbpModal" - and you can have how much you want pdf doc.

aMOHO.jpg

this is really cool

if you have any question about this you can ask me :)
 
Status
Not open for further replies.
Back
Top