-
Notifications
You must be signed in to change notification settings - Fork 20
Added PDF embed #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
q2apro
wants to merge
1
commit into
NoahY:master
Choose a base branch
from
q2apro:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,7 +110,79 @@ function embed_replace($text) { | |
| $text = preg_replace('/(?<![\'"=])'.$r[0].'/i',$r[1],$text); | ||
| } | ||
| } | ||
|
|
||
| /* Files that were uploaded to q2a get a URL like: ./?qa=blob&qa_blobid=14985201715764609123 | ||
| * The regex-checks above cannot find the filetype as it is not specified in the URL. | ||
| * However, we can extract the blobid and request the filetype from the DB, | ||
| * according to the filetype we can set the correct html embed tags. | ||
| * Filetype of interest: PDF | ||
| * Note: The PDF-embed is added to the end of the post. | ||
| * by q2apro.com | ||
| */ | ||
|
|
||
| /* Important: With q2a v1.6.3 and lower, the qa-include/qa-blob.php must be changed | ||
| * to achieve correct serving of the PDF file. | ||
| * See here for details: http://www.question2answer.org/qa/33645/ | ||
| * Probably this will be solved with q2a v1.7 | ||
| */ | ||
|
|
||
|
|
||
| if(qa_opt('embed_pdf_from_blob')) { | ||
| // do we have a bloburl in the post text | ||
| if(strpos($text,'qa_blobid=') !== false) { | ||
| $allBlobURLs = array(); | ||
|
|
||
| // get all URLs | ||
| $urls = $this->q2apro_getUrlsFromString($text); | ||
| foreach($urls as $urln) { | ||
| if(strpos($urln,'qa_blobid=') !== false) { | ||
| // found blobid add link to array | ||
| $allBlobURLs[] = $urln; | ||
| } | ||
| } | ||
|
|
||
| // @NoahY: for later language file needed | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not know if the admin interface should become multilingual? Specified the two variables just in case. |
||
| $lang_nopdfplugin = 'Your browser does not have a PDF plugin installed.'; | ||
| $lang_downloadpdf = 'Download the PDF:'; | ||
|
|
||
| // we found blobURLs | ||
| if(count($allBlobURLs)>0) { | ||
| // remove duplicates from array and go over all items | ||
| foreach(array_unique($allBlobURLs) as $blobURL) { | ||
| // extract the blobid from the blobURL | ||
| $urlArray = explode('=',$blobURL); | ||
| $blobid = $urlArray[sizeof($urlArray)-1]; | ||
|
|
||
| if($blobid!='') { | ||
| // query the filetype | ||
| $blobFF = qa_db_read_one_assoc( qa_db_query_sub('SELECT format,filename FROM `^blobs` | ||
| WHERE blobid = # | ||
| ', $blobid), true ); | ||
| if(isset($blobFF['format']) && $blobFF['format']=='pdf') { | ||
| $pdfname = $blobFF['filename']; | ||
| if(is_null($pdfname)) { | ||
| $pdfname = 'Document'; | ||
| } | ||
| // we have a pdf, add embed to the end of the post | ||
| $text .= '<object data="'.$blobURL.'" type="application/pdf" style="width:100%;height:600px;border:1px solid #DDD;"> | ||
| <embed src="'.$blobURL.'" /> | ||
| <p>'.$lang_nopdfplugin.'</p> | ||
| </object> | ||
| <p style="margin:10px 0 50px 0;">'.$lang_downloadpdf.' <a href="'.$blobURL.'">'.$pdfname.'</a></p>'; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return $text; | ||
| } | ||
|
|
||
| function q2apro_getUrlsFromString($string) { | ||
| $regex = '/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i'; | ||
| preg_match_all($regex, $string, $matches); | ||
| return $matches[0]; | ||
| } | ||
|
|
||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just some indent fixes