nggGallery

Main PHP class for the WordPress plugin NextGEN Gallery.

Defined (1)

The class is defined in the following location(s).

/products/photocrati_nextgen/modules/ngglegacy/lib/core.php  
  1. class nggGallery { 
  2.  
  3. /** 
  4. * Show a error messages 
  5. */ 
  6. static function show_error($message) { 
  7. echo '<div class="wrap"><h2></h2><div class="error" id="error"><p>' . $message . '</p></div></div>' . "\n"; 
  8.  
  9. /** 
  10. * Show a system messages 
  11. */ 
  12. static function show_message($message, $message_id=NULL) { 
  13. echo '<div class="wrap"><h2></h2><div class="updated fade '.$message_id.'" id="message"><p>' . $message . '</p></div></div>' . "\n"; 
  14.  
  15. /** 
  16. * nggGallery::get_option() - get the options and overwrite them with custom meta settings 
  17. * @param string $key 
  18. * @return array $options 
  19. */ 
  20. static function get_option($key) { 
  21. global $post; 
  22.  
  23. // get first the options from the database 
  24. $options = get_option($key); 
  25.  
  26. if ( $post == null ) 
  27. return $options; 
  28.  
  29. // Get all key/value data for the current post. 
  30. $meta_array = get_post_custom(); 
  31.  
  32. // Ensure that this is a array 
  33. if ( !is_array($meta_array) ) 
  34. $meta_array = array($meta_array); 
  35.  
  36. // assign meta key to db setting key 
  37. $meta_tags = array( 
  38. 'string' => array( 
  39. 'ngg_gal_ShowOrder' => 'galShowOrder',  
  40. 'ngg_gal_Sort' => 'galSort',  
  41. 'ngg_gal_SortDirection' => 'galSortDir',  
  42. 'ngg_gal_ShowDescription' => 'galShowDesc',  
  43. 'ngg_ir_Audio' => 'irAudio',  
  44. 'ngg_ir_Overstretch' => 'irOverstretch',  
  45. 'ngg_ir_Transition' => 'irTransition',  
  46. 'ngg_ir_Backcolor' => 'irBackcolor',  
  47. 'ngg_ir_Frontcolor' => 'irFrontcolor',  
  48. 'ngg_ir_Lightcolor' => 'irLightcolor',  
  49. 'ngg_slideshowFX' => 'slideFx',  
  50. ),  
  51.  
  52. 'int' => array( 
  53. 'ngg_gal_Images' => 'galImages',  
  54. 'ngg_gal_Columns' => 'galColumns',  
  55. 'ngg_paged_Galleries' => 'galPagedGalleries',  
  56. 'ngg_ir_Width' => 'irWidth',  
  57. 'ngg_ir_Height' => 'irHeight',  
  58. 'ngg_ir_Rotatetime' => 'irRotatetime' 
  59. ),  
  60.  
  61. 'bool' => array( 
  62. 'ngg_gal_ShowSlide' => 'galShowSlide',  
  63. 'ngg_gal_ImageBrowser' => 'galImgBrowser',  
  64. 'ngg_gal_HideImages' => 'galHiddenImg',  
  65. 'ngg_ir_Shuffle' => 'irShuffle',  
  66. 'ngg_ir_LinkFromDisplay' => 'irLinkfromdisplay',  
  67. 'ngg_ir_ShowNavigation' => 'irShownavigation',  
  68. 'ngg_ir_ShowWatermark' => 'irWatermark',  
  69. 'ngg_ir_Kenburns' => 'irKenburns' 
  70. ); 
  71.  
  72. foreach ($meta_tags as $typ => $meta_keys) { 
  73. foreach ($meta_keys as $key => $db_value) { 
  74. // if the kex exist overwrite it with the custom field 
  75. if (array_key_exists($key, $meta_array)) { 
  76. switch ($typ) { 
  77. case 'string': 
  78. $options[$db_value] = (string) esc_attr($meta_array[$key][0]); 
  79. break; 
  80. case 'int': 
  81. $options[$db_value] = (int) $meta_array[$key][0]; 
  82. break; 
  83. case 'bool': 
  84. $options[$db_value] = (bool) $meta_array[$key][0]; 
  85. break; 
  86.  
  87. return $options; 
  88.  
  89. /** 
  90. * Renders a section of user display code. The code is first checked for in the current theme display directory 
  91. * before defaulting to the plugin 
  92. * Call the function : nggGallery::render ('template_name', array ('var1' => $var1, 'var2' => $var2)); 
  93. * @autor John Godley 
  94. * @param string $template_name Name of the template file (without extension) 
  95. * @param string $vars Array of variable name=>value that is available to the display code (optional) 
  96. * @param bool $callback In case we check we didn't find template we tested it one time more (optional) 
  97. * @return void 
  98. **/ 
  99. static function render($template_name, $vars = array (), $callback = false) 
  100. $vars['template'] = $template_name; 
  101. echo C_Displayed_Gallery_Renderer::get_instance()->display_images($vars); 
  102.  
  103.  
  104.  
  105. /** 
  106. * Captures an section of user display code. 
  107. * @autor John Godley 
  108. * @param string $template_name Name of the template file (without extension) 
  109. * @param string $vars Array of variable name=>value that is available to the display code (optional) 
  110. * @deprecated Use C_Displayed_Gallery_Renderer class 
  111. * @return void 
  112. **/ 
  113. static function capture ($template_name, $vars = array ()) 
  114. $vars['template'] = $template_name; 
  115. return C_Displayed_Gallery_Renderer::get_instance()->display_images($vars); 
  116.  
  117. /** 
  118. * nggGallery::graphic_library() - switch between GD and ImageMagick 
  119. * @return path to the selected library 
  120. */ 
  121. static function graphic_library() { 
  122.  
  123. $ngg_options = get_option('ngg_options'); 
  124.  
  125. if ( $ngg_options['graphicLibrary'] == 'im') 
  126. return NGGALLERY_ABSPATH . '/lib/imagemagick.inc.php'; 
  127. else 
  128. return NGGALLERY_ABSPATH . '/lib/gd.thumbnail.inc.php'; 
  129.  
  130.  
  131. /** 
  132. * Support for i18n with wpml, polyglot or qtrans 
  133. * @param string $in 
  134. * @param string $name (optional) required for wpml to determine the type of translation 
  135. * @return string $in localized 
  136. */ 
  137. static function i18n($in, $name = null) { 
  138.  
  139. if ( function_exists( 'langswitch_filter_langs_with_message' ) ) 
  140. $in = langswitch_filter_langs_with_message($in); 
  141.  
  142. if ( function_exists( 'polyglot_filter' )) 
  143. $in = polyglot_filter($in); 
  144.  
  145. if ( function_exists( 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage' )) 
  146. $in = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($in); 
  147.  
  148. if (is_string($name) && !empty($name) && function_exists('icl_translate')) 
  149. $in = icl_translate('plugin_ngg', $name, $in, true); 
  150.  
  151. $in = apply_filters('localization', $in); 
  152.  
  153. return $in; 
  154.  
  155. /** 
  156. * Check the memory_limit and calculate a recommended memory size 
  157. * @since V1.2.0 
  158. * @return string message about recommended image size 
  159. */ 
  160. static function check_memory_limit() { 
  161.  
  162. if ( (function_exists('memory_get_usage')) && (ini_get('memory_limit')) ) { 
  163.  
  164. // get memory limit 
  165. $memory_limit = ini_get('memory_limit'); 
  166. if ($memory_limit != '') 
  167. $memory_limit = substr($memory_limit, 0, -1) * 1024 * 1024; 
  168.  
  169. // calculate the free memory 
  170. $freeMemory = $memory_limit - memory_get_usage(); 
  171.  
  172. // build the test sizes 
  173. $sizes = array(); 
  174. $sizes[] = array ( 'width' => 800, 'height' => 600); 
  175. $sizes[] = array ( 'width' => 1024, 'height' => 768); 
  176. $sizes[] = array ( 'width' => 1280, 'height' => 960); // 1MP 
  177. $sizes[] = array ( 'width' => 1600, 'height' => 1200); // 2MP 
  178. $sizes[] = array ( 'width' => 2016, 'height' => 1512); // 3MP 
  179. $sizes[] = array ( 'width' => 2272, 'height' => 1704); // 4MP 
  180. $sizes[] = array ( 'width' => 2560, 'height' => 1920); // 5MP 
  181.  
  182. // test the classic sizes 
  183. foreach ($sizes as $size) { 
  184. // very, very rough estimation 
  185. if ($freeMemory < round( $size['width'] * $size['height'] * 5.09 )) { 
  186. $result = sprintf( __( 'Note : Based on your server memory limit you should not upload larger images then <strong>%d x %d</strong> pixel', 'nggallery' ), $size['width'], $size['height']); 
  187. return $result; 
  188. return; 
  189.  
  190. /** 
  191. * Check for extended capabilites. Must previously registers with add_ngg_capabilites() 
  192. * @since 1.5.0 
  193. * @param string $capability 
  194. * @return bool $result of capability check 
  195. */ 
  196. static function current_user_can( $capability ) { 
  197.  
  198. global $_ngg_capabilites; 
  199.  
  200. if ( is_array($_ngg_capabilites) ) 
  201. if ( in_array($capability , $_ngg_capabilites) ) 
  202. return current_user_can( $capability ); 
  203.  
  204. return true; 
  205.  
  206. /** 
  207. * Show NextGEN Version in header 
  208. * @since 1.9.0 
  209. * @return void 
  210. */ 
  211. static function nextgen_version() { 
  212. global $ngg; 
  213. echo apply_filters('show_nextgen_version', '<!-- <meta name="NextGEN" version="'. $ngg->version . '" /> -->' . "\n");