diff --git a/qa-embed-admin.php b/qa-embed-admin.php index 1cac958..e9e156c 100644 --- a/qa-embed-admin.php +++ b/qa-embed-admin.php @@ -16,6 +16,8 @@ function option_default($option) { return 64; case 'embed_mp3_player_code': return ''; + case 'embed_pdf_from_blob': + return 1; default: return null; } @@ -45,6 +47,7 @@ function admin_form(&$qa_content) qa_opt('embed_enable_mp3',(bool)qa_post_text('embed_enable_mp3')); qa_opt('embed_enable_gmap',(bool)qa_post_text('embed_enable_gmap')); qa_opt('embed_mp3_player_code', qa_post_text('embed_mp3_player_code')); + qa_opt('embed_pdf_from_blob', (bool)qa_post_text('embed_pdf_from_blob')); $ok = qa_lang('admin/options_saved'); } else if (qa_clicked('embed_reset')) { @@ -61,7 +64,6 @@ function admin_form(&$qa_content) // Create the form for display - $fields = array(); $fields[] = array( @@ -96,16 +98,16 @@ function admin_form(&$qa_content) ); $fields[] = array( - 'label' => 'Image width', - 'type' => 'number', - 'value' => qa_opt('embed_image_width'), - 'tags' => 'NAME="embed_image_width"', + 'label' => 'Image width', + 'type' => 'number', + 'value' => qa_opt('embed_image_width'), + 'tags' => 'NAME="embed_image_width"', ); $fields[] = array( - 'label' => 'Image height', - 'type' => 'number', - 'value' => qa_opt('embed_image_height'), - 'tags' => 'NAME="embed_image_height"', + 'label' => 'Image height', + 'type' => 'number', + 'value' => qa_opt('embed_image_height'), + 'tags' => 'NAME="embed_image_height"', ); $fields[] = array( 'label' => 'Enable thickbox image effect', @@ -137,27 +139,32 @@ function admin_form(&$qa_content) 'type' => 'blank', ); - $fields[] = array( 'label' => 'Enable Google maps embedding', 'tags' => 'NAME="embed_enable_gmap"', 'value' => qa_opt('embed_enable_gmap'), 'type' => 'checkbox', ); - $fields[] = array( - 'label' => 'Map width', - 'type' => 'number', - 'value' => qa_opt('embed_gmap_width'), - 'tags' => 'NAME="embed_gmap_width"', - ); + 'label' => 'Map width', + 'type' => 'number', + 'value' => qa_opt('embed_gmap_width'), + 'tags' => 'NAME="embed_gmap_width"', + ); $fields[] = array( - 'label' => 'Map height', - 'type' => 'number', - 'value' => qa_opt('embed_gmap_height'), - 'tags' => 'NAME="embed_gmap_height"', + 'label' => 'Map height', + 'type' => 'number', + 'value' => qa_opt('embed_gmap_height'), + 'tags' => 'NAME="embed_gmap_height"', ); + $fields[] = array( + 'label' => 'Embed PDFs that were uploaded', + 'tags' => 'NAME="embed_pdf_from_blob"', + 'value' => qa_opt('embed_pdf_from_blob'), + 'type' => 'checkbox', + ); + return array( 'ok' => ($ok && !isset($error)) ? $ok : null, diff --git a/qa-embed-layer.php b/qa-embed-layer.php index 7f67c00..f1682ec 100644 --- a/qa-embed-layer.php +++ b/qa-embed-layer.php @@ -110,7 +110,79 @@ function embed_replace($text) { $text = preg_replace('/(?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 + $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 .= ' +
'.$lang_downloadpdf.' '.$pdfname.'
'; + } + } + } + } + } + } 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]; + } + }