Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions qa-embed-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ function option_default($option) {
return 64;
case 'embed_mp3_player_code':
return '<object type="application/x-shockwave-flash" data="http://flash-mp3-player.net/medias/player_mp3_mini.swf" width="200" height="20"><param name="movie" value="http://flash-mp3-player.net/medias/player_mp3_mini.swf" /><param name="bgcolor" value="#000000" /><param name="FlashVars" value="mp3=$1" /></object>';
case 'embed_pdf_from_blob':
return 1;
default:
return null;
}
Expand Down Expand Up @@ -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')) {
Expand All @@ -61,7 +64,6 @@ function admin_form(&$qa_content)

// Create the form for display


$fields = array();

$fields[] = array(
Expand Down Expand Up @@ -96,16 +98,16 @@ function admin_form(&$qa_content)
);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just some indent fixes

$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',
Expand Down Expand Up @@ -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,

Expand Down
72 changes: 72 additions & 0 deletions qa-embed-layer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The 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];
}

}