public final function from_url($url)
 {
     if (bp_links_is_url_valid($url)) {
         $this->data()->url = $url;
         $page_parser = BP_Links_Embed_Page_Parser::GetInstance();
         if ($page_parser->from_url($url)) {
             $this->parser = $page_parser;
             return $this->find_elements();
         }
     }
     return false;
 }
Пример #2
0
function bp_get_links_auto_embed_panel_content($embed_service = null)
{
    if (!$embed_service instanceof BP_Links_Embed_Service) {
        return null;
    }
    // no js html or selected image index by default
    $js_html = null;
    $image_idx = null;
    $image_selected_idx = null;
    $image_selection_count = 0;
    $image_selection_diplay = null;
    // multiple images to select from?
    if ($embed_service instanceof BP_Links_Embed_Has_Selectable_Image && count($embed_service->image_selection()) >= 1) {
        // body of javascript array
        $js_array = array();
        // user selected image index
        $image_idx = isset($_POST['link-url-embed-thidx']) ? $_POST['link-url-embed-thidx'] : $embed_service->image_get_selected();
        // selected image index from data storage
        $image_selected_idx = $embed_service->image_get_selected();
        // count of images in selection
        $image_selection_count = count($embed_service->image_selection());
        foreach ($embed_service->image_selection() as $idx => $url) {
            if (is_int($idx)) {
                $js_array[] = sprintf('[%d,"%s"]', $idx, $url);
            } else {
                $js_array[] = sprintf('["%s","%s"]', $idx, $url);
            }
        }
        $js_html = sprintf('<script type="text/javascript">
						jQuery(document).ready( function() {
							jQuery("div#link-url-embed-thpick").data("images", [ %1$s ] );
							jQuery("div#link-url-embed-thpick").data("images_idx", %2$s );
							return;
						});
					</script>%3$s', join(",", $js_array), is_null($image_idx) ? 'null' : $image_idx, PHP_EOL);
    } else {
        // don't display the thumb picker
        $image_selection_diplay = ' style="display: none;"';
    }
    // determine output thumb url
    $service_thumb_url = $embed_service->image_thumb_url();
    if (!empty($service_thumb_url) && bp_links_is_url_valid($service_thumb_url)) {
        $thumb_url = $service_thumb_url;
    } else {
        // service or owner chose not to have a thumb
        $thumb_url = bp_links_default_avatar_uri();
    }
    return $js_html . sprintf('<label style="clear: right;">
				%1$s %3$s
			</label>
			<div id="link-url-embed-content">
				<div id="link-url-embed-avatar">
					<img src="%4$s" class="avatar-current" alt="%5$s">
					<div id="link-url-embed-thpick"%12$s>
						<a href="#thprev" id="thprev">&lt;</a>
						<span id="thcurrent">%13$d</span>/<span id="thcount">%14$d</span> %15$s
						<a href="#thnext" id="thnext">&gt;</a>
						<div id="thnone">
							<input type="checkbox" name="link-url-embed-thskip" id="link-url-embed-thskip" value="1"%16$s /> %17$s
						</div>
					</div>
				</div>
				<a href="%7$s" target="_blank">%6$s</a>
				<p>%8$s</p>
				<div id="link-url-embed-options">
					<label for="link-url-embed-edit-text"><input type="checkbox" name="link-url-embed-edit-text" id="link-url-embed-edit-text" value="1"%9$s /> %2$s</label>
					<input type="hidden" name="link-url-embed-data" id="link-url-embed-data" value="%10$s" />
					<input type="hidden" name="link-url-embed-thidx" id="link-url-embed-thidx" value="%11$s" />
				</div>
			</div>', __('Rich Media Detected:', 'buddypress-links'), __('Edit Name and Description', 'buddypress-links'), esc_html($embed_service->service_name()), esc_url($thumb_url), esc_attr($embed_service->title()), esc_html($embed_service->title()), esc_url($embed_service->url()), esc_html($embed_service->description()), !empty($_POST['link-url-embed-edit-text']) ? ' checked="checked"' : null, $embed_service->export_data(), $image_selected_idx, $image_selection_diplay, $image_idx + 1, $image_selection_count, __('Thumbs', 'buddypress-links'), is_null($image_idx) ? ' checked="checked"' : null, __('No Thumbnail', 'buddypress-links'));
}
Пример #3
0
function bp_links_auto_embed_panel_content($embed_service = null)
{
    if (!$embed_service instanceof BP_Links_Embed_Service) {
        return;
    }
    // no selected image index by default
    $image_idx = null;
    $image_selected_idx = null;
    $image_selection_count = 0;
    $image_selection_diplay = null;
    // multiple images to select from?
    if ($embed_service instanceof BP_Links_Embed_Has_Selectable_Image && count($embed_service->image_selection()) >= 1) {
        // body of javascript array
        $js_array = array();
        // user selected image index
        $image_idx = isset($_POST['link-url-embed-thidx']) ? $_POST['link-url-embed-thidx'] : $embed_service->image_get_selected();
        // selected image index from data storage
        $image_selected_idx = $embed_service->image_get_selected();
        // count of images in selection
        $image_selection_count = count($embed_service->image_selection());
        foreach ($embed_service->image_selection() as $idx => $url) {
            if (is_int($idx)) {
                $js_array[] = sprintf('[%d,"%s"]', $idx, $url);
            } else {
                $js_array[] = sprintf('["%s","%s"]', $idx, $url);
            }
        }
        // js syntax strings
        $image_js_img = join(",", $js_array);
        $image_js_img_idx = is_null($image_idx) ? 'null' : $image_idx;
        // render js element
        ?>
		<script type="text/javascript">
			jQuery(document).ready( function() {
				jQuery("div#link-url-embed-thpick").data("images", [ <?php 
        echo $image_js_img;
        ?>
 ] );
				jQuery("div#link-url-embed-thpick").data("images_idx", <?php 
        echo $image_js_img_idx;
        ?>
 );
				return;
			});
		</script><?php 
    } else {
        // don't display the thumb picker
        $image_selection_diplay = ' style="display: none;"';
    }
    // determine output thumb url
    $service_thumb_url = $embed_service->image_thumb_url();
    if (!empty($service_thumb_url) && bp_links_is_url_valid($service_thumb_url)) {
        $thumb_url = $service_thumb_url;
    } else {
        // service or owner chose not to have a thumb
        $thumb_url = bp_links_default_avatar_uri();
    }
    // checkiness vars
    $checked_edit = !empty($_POST['link-url-embed-edit-text']) ? ' checked="checked"' : null;
    $checked_thumb = is_null($image_idx) ? ' checked="checked"' : null;
    // render the html
    ?>
	<label style="clear: right;">
		<?php 
    _e('Rich Media Detected:', 'buddypress-links');
    ?>
		<?php 
    echo esc_html($embed_service->service_name());
    ?>
	</label>
	<div id="link-url-embed-content">
		<div id="link-url-embed-avatar">
			<img src="<?php 
    echo esc_url($thumb_url);
    ?>
" class="avatar-current" alt="<?php 
    echo esc_attr($embed_service->title());
    ?>
">
			<div id="link-url-embed-thpick"<?php 
    echo $image_selection_diplay;
    ?>
>
				<a href="#thprev" id="thprev">&lt;</a>
				<span id="thcurrent"><?php 
    echo $image_idx + 1;
    ?>
</span>/<span id="thcount"><?php 
    echo $image_selection_count;
    ?>
</span> <?php 
    _e('Thumbs', 'buddypress-links');
    ?>
				<a href="#thnext" id="thnext">&gt;</a>
				<div id="thnone">
					<input type="checkbox" name="link-url-embed-thskip" id="link-url-embed-thskip" value="1"<?php 
    echo $checked_thumb;
    ?>
> <?php 
    _e('No Thumbnail', 'buddypress-links');
    ?>
				</div>
			</div>
		</div>
		<a href="<?php 
    echo esc_url($embed_service->url());
    ?>
" target="_blank"><?php 
    echo esc_html($embed_service->title());
    ?>
</a>
		<p><?php 
    echo esc_html($embed_service->description());
    ?>
</p>
		<div id="link-url-embed-options">
			<label for="link-url-embed-edit-text">
				<input type="checkbox" name="link-url-embed-edit-text" id="link-url-embed-edit-text" value="1"<?php 
    echo $checked_edit;
    ?>
>
				<?php 
    _e('Edit Name and Description', 'buddypress-links');
    ?>
			</label>
			<input type="hidden" name="link-url-embed-data" id="link-url-embed-data" value="<?php 
    echo $embed_service->export_data();
    ?>
">
			<input type="hidden" name="link-url-embed-thidx" id="link-url-embed-thidx" value="<?php 
    echo esc_attr($image_selected_idx);
    ?>
">
		</div>
	</div><?php 
}
 /**
  * Return an array of all img elements in the DOM with their src, height and width
  *
  * @param integer $min_pixels At least one dimension must be this many pixels
  * @param integer $max_pixels Both dimensions must be less than this many pixels
  * @param integer $max_ratio Longer dimension must be no more than N times longer than the shorter dimension
  * @param integer $limit Maximum number of images to return
  * @return array|false
  */
 public final function images($min_pixels, $max_pixels, $max_ratio, $limit, $strict = false)
 {
     // try to find some images
     $nodes_img = $this->dom->getElementsByTagName('img');
     // if we found at least one image, sort through them
     if ($nodes_img->length >= 1) {
         $img_array = array();
         foreach ($nodes_img as $node_img) {
             $src = null;
             $width = null;
             $height = null;
             // check for required attributes
             if ($node_img->hasAttribute('src')) {
                 $src = $this->deep_clean_string($node_img->getAttribute('src'));
             } else {
                 continue;
             }
             if ($node_img->hasAttribute('width')) {
                 $width = (int) $node_img->getAttribute('width');
             } elseif ($strict) {
                 continue;
             }
             if ($node_img->hasAttribute('height')) {
                 $height = (int) $node_img->getAttribute('height');
             } elseif ($strict) {
                 continue;
             }
             // validate the attributes we found
             if (bp_links_is_url_valid($src)) {
                 // if we have a width AND height set, check image size and ratio
                 if ($width && $height && !$this->check_image_size($width, $height, $min_pixels, $max_pixels, $max_ratio)) {
                     continue;
                 }
                 // append to return array
                 $img_array[] = array('src' => $src, 'height' => $height, 'width' => $width);
             }
             // break out of loop if we have reached limit threshold
             if (count($img_array) >= $limit) {
                 break;
             }
         }
         // if we found at least one image, return the array
         if (count($img_array) >= 1) {
             return $img_array;
         }
     }
     // no images found
     return null;
 }
Пример #5
0
/**
 * Validate new/udpate link form data and format errors
 */
function bp_links_validate_create_form_input($link = null)
{
    $message_required = __('Please fill in all of the required fields', 'buddypress-links');
    // init return data array
    $return_data = array();
    // link category
    if (!empty($_POST['link-category'])) {
        $bp_new_link_category = stripslashes($_POST['link-category']);
        $return_data['link-category'] = $bp_new_link_category;
    } else {
        bp_core_add_message($message_required, 'error');
        return false;
    }
    // link url
    if (!empty($_POST['link-url'])) {
        $bp_new_link_url = rtrim(trim(stripslashes($_POST['link-url'])), '/');
        if (strlen($bp_new_link_url) > BP_LINKS_MAX_CHARACTERS_URL) {
            bp_core_add_message(sprintf(__('Link URL must be %1$d characters or less, please make corrections and re-submit.', 'buddypress-links'), BP_LINKS_MAX_CHARACTERS_URL), 'error');
            return false;
        } elseif (bp_links_is_url_valid($bp_new_link_url) !== true) {
            bp_core_add_message(__('The URL you entered is not valid.', 'buddypress-links'), 'error');
            return false;
        } elseif (false === BP_LINKS_CREATE_DUPE_URL && (false === $link instanceof BP_Links_Link || $bp_new_link_url != $link->url)) {
            // check for dupeness
            if (bp_links_check_link_url_exists($bp_new_link_url)) {
                bp_core_add_message(__('The URL you entered already exists.', 'buddypress-links'), 'error');
                return false;
            }
        }
        $return_data['link-url'] = $bp_new_link_url;
    } else {
        bp_core_add_message($message_required, 'error');
        return false;
    }
    // link name
    if (!empty($_POST['link-name'])) {
        $bp_new_link_name = trim(stripslashes($_POST['link-name']));
        if (function_exists('mb_strlen') && mb_strlen($bp_new_link_name) > BP_LINKS_MAX_CHARACTERS_NAME || strlen($bp_new_link_name) > BP_LINKS_MAX_CHARACTERS_NAME) {
            bp_core_add_message(sprintf(__('Link Name must be %1$d characters or less, please make corrections and re-submit.', 'buddypress-links'), BP_LINKS_MAX_CHARACTERS_NAME), 'error');
            return false;
        }
        $return_data['link-name'] = $bp_new_link_name;
    } else {
        bp_core_add_message($message_required, 'error');
        return false;
    }
    // link description
    if (!empty($_POST['link-desc'])) {
        $bp_new_link_description = trim(stripslashes($_POST['link-desc']));
        if (function_exists('mb_strlen') && mb_strlen($bp_new_link_description) > BP_LINKS_MAX_CHARACTERS_DESCRIPTION || strlen($bp_new_link_description) > BP_LINKS_MAX_CHARACTERS_DESCRIPTION) {
            bp_core_add_message(sprintf(__('Link Description must be %1$d characters or less, please make corrections and re-submit.', 'buddypress-links'), BP_LINKS_MAX_CHARACTERS_DESCRIPTION), 'error');
            return false;
        }
        $return_data['link-desc'] = $bp_new_link_description;
    } elseif (true == BP_LINKS_IS_REQUIRED_DESCRIPTION) {
        bp_core_add_message($message_required, 'error');
        return false;
    }
    // link status
    if (bp_links_is_valid_status($_POST['link-status'])) {
        $return_data['link-status'] = (int) $_POST['link-status'];
    } else {
        $return_data['link-status'] = null;
    }
    // link url embed service (optional)
    if (!empty($_POST['link-url-embed-data'])) {
        $return_data['link-url-embed-data'] = trim($_POST['link-url-embed-data']);
    } else {
        $return_data['link-url-embed-data'] = null;
    }
    // link url embed service selected image index (optional)
    if (isset($_POST['link-url-embed-thidx'])) {
        $return_data['link-url-embed-thidx'] = trim($_POST['link-url-embed-thidx']);
    } else {
        $return_data['link-url-embed-thidx'] = null;
    }
    // link group association (optional)
    if (isset($_POST['link-group-id'])) {
        $return_data['link-group-id'] = (int) $_POST['link-group-id'];
    } else {
        $return_data['link-group-id'] = null;
    }
    // process meta data
    if (isset($_POST['link-meta'])) {
        $return_data['link-meta'] = apply_filters('bp_links_validate_create_form_input_meta', $_POST['link-meta'], $link);
    } else {
        $return_data['link-meta'] = array();
    }
    return apply_filters('bp_links_validate_create_form_input', $return_data, $link);
}