Skip to content

Instantly share code, notes, and snippets.

@freayd
Last active October 12, 2017 05:48
Show Gist options
  • Save freayd/5169440 to your computer and use it in GitHub Desktop.
Save freayd/5169440 to your computer and use it in GitHub Desktop.
NextGEN Gallery image source for Wysija Newsletters WordPress plugin

This feature is really important for me, that's why I developed it. I share this bunch of code in the hope that it will be useful, but without any warranty.

How to

Add the code between "Add this code - begin" and "Add this code - end" in the corresponding files.

Tested with

  • WordPress 3.5.1
  • NextGEN Gallery 1.9.12
  • Wysija Newsletters 2.3.4 and 2.3.5

Please note

  • In the controller campaigns.php, I commented $this->jsTrans['deleteimg'] because I don't know why is it used for.

Published

$this->iframeTabs['special_wysija_browse']=__('Newsletter Images',WYSIJA);
$this->iframeTabs['special_wordp_browse']=__('WordPress Posts\' Images',WYSIJA);
/* Add this code - begin */
if (is_plugin_active('nextgen-gallery/nggallery.php'))
$this->iframeTabs['special_ngg_browse']=__('NextGEN Gallery', 'nggallery');
/* Add this code - end */
function special_wysija_browse() {
}
function special_wordp_browse() {
}
/* Add this code - begin */
function special_ngg_browse() {
$this->_wysija_subaction();
// TODO $this->jsTrans['deleteimg']=__('???',WYSIJA);
return wp_iframe( array($this->viewObj,'popup_ngg_browse'), array() );
}
/* Add this code - end */
/* Add this code - begin */
.media-ngg-browse #media-items{width:100%;height:340px;margin:0 0 10px 0}
/* Add this code - end */
.popup_content.media-browse,.popup_content.media-wp-browse,.popup_content.media-wp-upload/* Add this code - begin */,.popup_content.media-ngg-browse/* Add this code - end */{width:715px}
function popup_wysija_browse($errors){
}
/* Add this code - begin */
function popup_ngg_browse($errors){
echo $this->messages(true);
?><div id="overlay"><img id="loader" src="<?php echo WYSIJA_URL ?>img/wpspin_light.gif" /></div>
<div class="popup_content media-ngg-browse">
<?php
global $redir_tab, $type;
$redir_tab = 'ngg_browse';
media_upload_header();
?>
<form enctype="multipart/form-data" method="post" action="" class="media-upload-form validate" id="ngg-browse-form">
<?php
$secure=array('action'=>"medias");
$this->secure($secure); ?>
<div id="media-items" class="clearfix"><?php echo $this->_get_ngg_media_items(); ?></div>
</form>
<?php $this->_alt_close(); ?>
</div>
<?php
}
function _get_ngg_media_items() {
$output = '';
global $nggdb;
$galleryId = isset( $_POST['galleryId'] ) ? intval($_POST['galleryId']) : null;
$galleryList = $nggdb->find_all_galleries();
if (! is_array($galleryList) || empty($galleryList))
return "<em>".__('No galleries have been yet created.', 'nggallery')."</em>";
// Display gallery selector
$output .= '<div class="clearfix">';
$output .= '<select name="galleryId">';
foreach($galleryList as $gallery) {
$selected = ($gallery->gid == $galleryId )? ' selected="selected"' : "";
$output .= '<option value="'.$gallery->gid.'"'.$selected.' >'.$gallery->title.'</option>'."\n";
}
$output .= '</select>';
$output .= '<input type="submit" value="'.esc_attr( __('Select &#187;','nggallery') ).'" class="button-secondary" />';
$output .= '</div>';
// Display image selector
if ($galleryId != null) {
$gallery = $nggdb->find_gallery($galleryId);
$selectedImages=$this->_getSelectedImages();
foreach ( $nggdb->get_gallery($galleryId) as $image ) {
$id = 'ngg-'.$image->pid;
$thumbURL = $image->thumbURL;
$imageURL = $image->imageURL;
$alt = $image->alttext;
$width = $image->meta_data['width'];
$height = $image->meta_data['height'];
// Use http scheme instead of https in case admin is forced to https but website isn't using https
if (defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN && ! preg_match('@^https\://@i', home_url())) {
$thumbURL = preg_replace('@^(http)s(\://)@i', '${1}${2}', $thumbURL);
$imageURL = preg_replace('@^(http)s(\://)@i', '${1}${2}', $imageURL);
}
$classname="";
if(isset($selectedImages["wp-".$id])) $classname=" selected ";
$output.='<div class="wysija-thumb'.$classname.'">';
$output .= '<img title="'.$alt.'" alt="'.$alt.'" src="'.$thumbURL.'" class="thumbnail" />';
$output.='<span class="identifier">'.$id.'</span>
<span class="width">'.$width.'</span>
<span class="height">'.$height.'</span>
<span class="url">'.$imageURL.'</span>
<span class="thumb_url">'.$thumbURL.'</span></div>';
}
}
return $output;
}
/* Add this code - end */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment