Programmation
Replace WordPress default media icon with preview image
by Jean-Marc Amiaud le 05 Mar 2011, catégorie Programmation, WordPress
Media library in WordPress display thumbnail of the pictures but only generic icon for all other type.
It’s possible to change generics icons (eg. by video preview image) with pair of filter :
[code lang= »csharp »]
add_filter(‘wp_mime_type_icon’, ‘my_plugin_video_icon’, 10, 3);
add_filter(‘icon_dir’, ‘wp_plugin_video_icon_dir’);
function my_plugin_video_icon($icon, $mime, $post_id)
{
if(preg_match("/^video/",$mime))
{
// – Find your icon for the specified post
// – Save the repository of your icon as global
global $_current_video_icon_dir;
$_current_video_icon_dir = dirname(ABSPATH . substr($new_icon, strpos($new_icon, "wp-content")));
// – Return your icon path
return $new_icon;
}
}
function my_plugin_video_icon_dir($dir)
{
global $_current_video_icon_dir;
if(!empty($_current_video_icon_dir))
{
$var = $_current_video_icon_dir;
$_current_video_icon_dir = null;
return $var;
}
return $dir;
}
[/code]
Handle unload event with jQuery
by Jean-Marc Amiaud le 23 Déc 2010, catégorie jQuery, Programmation
After a lot of research over internet, to know how it’s possible to handle unload event with jQuery, I have found the solution ! But I’ve seen lot of error… the reason of my post.
The unload event is fired by window element and NOT by the document element !
So you have to handle the event from window element like this :
jQuery(window).unload(function() { alert(‘Window unload event is fired !’); });
That’s all !
Getting the absolute path in ASP.NET
by Jean-Marc Amiaud le 30 Nov 2010, catégorie ASP.NET
After too much case of context, i´ve wrote a simple but powerfull function to get the absolute path in ASP.NET.
[code lang= »csharp »]
public static string GetAbsoluteUrl(string relativeUrl)
{
return String.Format("{0}://{1}{2}{3}",
HttpContext.Current.Request.IsSecureConnection ? "https" : "http",
HttpContext.Current.Request.Url.Host,
HttpContext.Current.Request.Url.IsDefaultPort ? "" : ":" + HttpContext.Current.Request.Url.Port,
VirtualPathUtility.ToAbsolute(relativeUrl, HttpRuntime.AppDomainAppVirtualPath));
}
[/code]
Upload a binary file through an ASP.NET 2.0 WebService
by Jean-Marc Amiaud le 10 Nov 2010, catégorie ASP.NET, Programmation
It’s possible to upload a large binary file through an ASP.NET 2.0 WebService.
- Declare a service method that take a byte array in argument.
- Change the maximum http request size allowed by IIS.
- Change the maximum http request size allowed by ASP.NET
Service Method
[code lang= »csharp »]
[WebMethod]
public bool FileUpload (string name, int type, byte[] data)
{
}
[/code]
IIS Configuration
For IIS 6.0, you have to change the metabase.xml file located in C:\Windows\System32\Inetsrv.
Find and set the key AspMaxRequestEntityAllowed with the appropriate value.
ASP.NET Configuration (web.config)
Open the web.config file of your WebService project.
Define the httpRuntime subsection of system.web section like this :
[code lang= »xml »]
<httpRuntime enable="true" maxRequestLength="1073741824" />
[/code]
Warning : The maxRequestLength must to be in Ko.