PageRenderTime 60ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/utilities.php

https://bitbucket.org/serumax/saieh
PHP | 316 lines | 259 code | 41 blank | 16 comment | 33 complexity | c59f147a097a5f64b6ae5c56acf8cb58 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-3.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. /*
  3. Plugin Name: Utilities
  4. Version: 0.1 Beta
  5. Plugin URI: http://www.maxvillegas.com
  6. Author: Max Villegas
  7. Author URI: http://www.maxvillegas.com
  8. Description: Coleccion de funciones menores
  9. */
  10. $ruta_new = split($_SERVER["SERVER_NAME"],get_bloginfo("home"));
  11. $ruta = $ruta_new[1]."/";
  12. function mvc($mvc){
  13. global $ruta;
  14. $uri = $_SERVER["REQUEST_URI"];
  15. $rest = substr($uri, -1);
  16. $uri = $rest=="/"?$uri:$uri."/";
  17. if ($ruta!="/"){ $uri = split($ruta, $uri); $uri = $uri[1]; }
  18. else { $uri = substr($uri,1); }
  19. $url = split('/', $uri);
  20. return $url[$mvc];
  21. }
  22. function idioma(){
  23. global $ruta;
  24. $in = split($ruta,$_SERVER["REQUEST_URI"]);
  25. if(stristr($ruta,'en/')){
  26. $url=split('en/',$ruta);
  27. $url=$url[0].$in[1];
  28. }
  29. else {
  30. $url=$ruta.'en/'.$in[1];
  31. }
  32. return $url;
  33. }
  34. function is_active() {
  35. global $ruta;
  36. $uri=$_SERVER["REQUEST_URI"];
  37. $rest = substr($uri, -1);
  38. $uri=$rest=="/"?$uri:$uri."/";
  39. if ($ruta!=""){$uri = split($ruta, $uri);$uri = $uri[1];}
  40. $url = split('/', $uri);
  41. $url=is_single()?$url[1]:$url[1];
  42. return $url;
  43. }
  44. function is_activePage() {
  45. global $ruta;
  46. $uri=$_SERVER["REQUEST_URI"];
  47. $rest = substr($uri, -1);
  48. $uri=$rest=="/"?$uri:$uri."/";
  49. if ($ruta!=""){$uri = split($ruta, $uri);$uri = $uri[1];}
  50. $url = split('/', $uri);
  51. $url=is_single()?$url[2]:$url[2];
  52. return $url;
  53. }
  54. function is_activePageSub() {
  55. global $ruta;
  56. $uri=$_SERVER["REQUEST_URI"];
  57. $rest = substr($uri, -1);
  58. $uri=$rest=="/"?$uri:$uri."/";
  59. if ($ruta!=""){$uri = split($ruta, $uri);$uri = $uri[1];}
  60. $url = split('/', $uri);
  61. $url=is_single()?$url[3]:$url[4];
  62. return $url;
  63. }
  64. function cortar($str,$n){
  65. if(strlen($str)>$n){
  66. $out = substr(strip_tags($str),0,$n);
  67. $out = explode(" ",$out);
  68. array_pop($out);
  69. $out = implode(" ",$out)." ...";
  70. }
  71. else{
  72. $out = $str;
  73. }
  74. return $out;
  75. }
  76. function url_wp($url){
  77. global $q_config;
  78. $server = $_SERVER["SERVER_NAME"];
  79. $default = get_option("qtranslate_default_language");
  80. $lenguajes = get_option("qtranslate_enabled_languages");
  81. foreach($lenguajes as $leng){
  82. if(eregi("/".strtolower($leng)."/",$url)){
  83. $urlfinal = eregi_replace("/".strtolower($leng)."/","/".strtolower($leng)."/#/",$url);
  84. }
  85. if(!eregi("/".strtolower($leng)."/",$url)){
  86. $urlfinal = eregi_replace($server,$server."/#",$url);
  87. }
  88. }
  89. return $urlfinal;
  90. }
  91. function mostrar_lenguajes(){
  92. global $q_config;
  93. $lenguajes = get_option("qtranslate_language_names");
  94. $disponibles = get_option("qtranslate_enabled_languages");
  95. $activo = detectar_leng();
  96. $uri = $_SERVER['REDIRECT_URL'];
  97. $urihome = $_SERVER['REQUEST_URI'];
  98. $blogurl = str_replace("http://".$_SERVER["SERVER_NAME"],"",get_bloginfo("home"))."/";
  99. foreach($lenguajes as $key=>$value){
  100. foreach($disponibles as $disponible){
  101. if($key==$disponible){
  102. if($_GET["s"]){
  103. // idioma -> por defecto
  104. if($key==$q_config["default_language"]){
  105. $url = $urihome;
  106. }
  107. // idioma -> idioma
  108. else{
  109. $url = eregi_replace("/\?s=","/".$key."/?s=",$urihome);
  110. }
  111. }
  112. else{
  113. // por defecto -> idioma
  114. if($q_config["default_language"] == $activo && $key!=$q_config["default_language"]){
  115. if($urihome==$blogurl) $url = eregi_replace($blogurl,$blogurl.$key."/",$urihome);
  116. else $url = eregi_replace($blogurl,$blogurl.$key."/",$uri);
  117. }
  118. // idioma -> por defecto
  119. else if(!eregi("/".strtolower($key)."/",$uri) && $key==$q_config["default_language"]){
  120. $url = eregi_replace("/".$activo."/","/",$uri);
  121. }
  122. // idioma -> idioma
  123. else{
  124. $url = eregi_replace("/".$activo."/","/".$key."/",$uri);
  125. }
  126. }
  127. if($key != $activo) $out .= '<a id="force_language" href="'.str_replace("&","&amp;",$url).'" title="Switch to '.$value.'" rel="Help">'.$value.'</a>'."\n";
  128. }
  129. }
  130. }
  131. return $out;
  132. }
  133. function lang_ie(){
  134. if(stristr($_SERVER["HTTP_USER_AGENT"], "MSIE 6")){
  135. echo "\n\t\t\t\t".'<a href="#" class="menuIE"><span>Language</span>';
  136. echo '<table><tr><td><ul>';
  137. echo mostrar_lenguajes();
  138. echo '</ul></td></tr></table></a>';
  139. } else {
  140. echo '<ul>';
  141. echo mostrar_lenguajes();
  142. echo '</ul>';
  143. }
  144. }
  145. function obtener_imagen($id){
  146. global $wpdb;
  147. return $wpdb->get_var("SELECT guid FROM $wpdb->posts WHERE post_parent = $id AND post_type = 'attachment' AND post_status='inherit' AND post_mime_type IN ('image/gif','image/jpg','image/jpeg','image/png')");
  148. }
  149. function obtener_imagendest($id){
  150. global $wpdb;
  151. return $wpdb->get_var("SELECT guid FROM $wpdb->posts WHERE post_parent = $id AND post_type = 'attachment' AND post_status='inherit' AND post_mime_type IN ('image/gif','image/jpg','image/jpeg','image/png')");
  152. }
  153. function id_family($page_id) {
  154. global $wpdb;
  155. return $parent = $wpdb->get_var("SELECT post_parent FROM $wpdb->posts WHERE post_type='page' AND ID = '$page_id'");
  156. }
  157. function obtener_imagen_clientes($id){
  158. global $wpdb;
  159. $imagenes = $wpdb->get_results("SELECT guid, post_title FROM $wpdb->posts WHERE post_parent = $id AND post_type = 'attachment' AND post_status='inherit' AND post_mime_type IN ('image/gif','image/jpg','image/jpeg','image/png')");
  160. foreach ($imagenes as $imagen) {
  161. $out .= '<li>
  162. <img class="logo" src="'.$imagen->guid.'" alt="'.$imagen->post_title.'" />
  163. </li>';
  164. }
  165. return $out;
  166. }
  167. function ficha_equipo($id){
  168. global $wpdb;
  169. $posts = get_posts('post_type=page&post_parent='.$id.'&orderby=menu_order&numberposts=30&order=ASC');
  170. foreach ($posts as $post){
  171. $out .= '<li class="grid_6">
  172. <img class="img" src="'.obtener_imagen($post->ID).'" alt="'.$post->post_title.'" />
  173. <div class="text">
  174. <h3>'.$post->post_title.'</h3>
  175. '.$post->post_content.'
  176. </div>
  177. </li>';
  178. }
  179. return $out;
  180. }
  181. function ficha_libros($id){
  182. global $wpdb;
  183. $posts = get_posts('post_type=page&post_parent='.$id.'&orderby=menu_order&numberposts=30&order=ASC');
  184. foreach ($posts as $post){
  185. $out .= '<li class="grid_6">
  186. <img class="img" src="'.obtener_imagen($post->ID).'" alt="'.$post->post_title.'" />
  187. <div class="text">
  188. <h3>'.$post->post_title.'</h3>
  189. '.$post->post_content.'
  190. </div>
  191. </li>';
  192. }
  193. return $out;
  194. }
  195. /*
  196. $date = datetime mysql
  197. */
  198. function flitrar_fecha($date, $formato, $separador){
  199. list($fecha, $hora) = split (' ', $date);
  200. if ($formato == "fecha"){
  201. $fecha = split ("-", $fecha);
  202. return $fecha[2] . $separador . $fecha[1] . $separador . $fecha[0];
  203. }
  204. if ($formato == "hora"){
  205. return $hora;
  206. }
  207. if ($formato == "fechahora"){
  208. $fecha = split ("-", $fecha);
  209. return $fecha[2] . $separador . $fecha[1] . $separador . $fecha[0] . " " . $hora;
  210. }
  211. }
  212. function last_comments(){
  213. global $wpdb;
  214. $args = array(
  215. 'post_type' => 'post',
  216. 'numberposts' => -1,
  217. 'post_status' => "publish",
  218. 'post_parent' => null
  219. );
  220. $posts = get_posts($args);
  221. foreach ($posts as $post) {
  222. $out .= '<li class="cf">
  223. <a href="'.apply_filters('guid', $post->guid).'" title="'.apply_filters('the_title', $post->post_title).'" ><img src="'.obtener_imagen($post->ID, get_post_meta($post->ID, 'autoria', true)).'" alt="'. get_post_meta($post->ID, 'autoria', true) . '" /></a>
  224. <p><a href="'.apply_filters('guid', $post->guid).'" title="'.apply_filters('the_title', $post->post_title).'" class="down"><strong>'.apply_filters('the_title', $post->post_title).'</strong></a></p>
  225. </li>';
  226. }
  227. return $out;
  228. }
  229. function obtener_archivos(){
  230. global $wpdb, $post;
  231. $args = array(
  232. 'post_type' => 'attachment',
  233. 'numberposts' => -1,
  234. 'post_status' => null,
  235. 'post_parent' => $post->ID
  236. );
  237. $attachments = get_posts($args);
  238. if ($attachments) {
  239. foreach ($attachments as $attachment) {
  240. $out .= '<li class="cf">
  241. <div class="meta">
  242. <img src="'.get_bloginfo("stylesheet_directory").'/images/auxi/file.png" alt="" />
  243. <p>Subido el <span>'. flitrar_fecha($attachment->post_date, "fecha", "/").'</span></p>
  244. </div>
  245. <div class="cuerpo">
  246. <h3>'.apply_filters('the_title', $attachment->post_title).'</h3>
  247. <p>'. apply_filters('post_content', $attachment->post_content).'</p>
  248. <a href="'.apply_filters('guid', $attachment->guid).'" title="'.apply_filters('the_title', $attachment->post_title).'" class="down">Descargar &raquo;</a>
  249. </div>
  250. </li>';
  251. }
  252. return $out;
  253. }
  254. }
  255. function get_the_pdf($id){
  256. global $wpdb, $post;
  257. $args = array(
  258. 'post_type' => 'attachment',
  259. 'post_mime_type' => 'application/pdf',
  260. 'numberposts' => 1,
  261. 'post_status' => null,
  262. 'post_parent' => $id
  263. );
  264. $attachments = get_posts($args);
  265. if ($attachments) {
  266. foreach ($attachments as $attachment) {
  267. $out = apply_filters('guid', $attachment->guid);
  268. }
  269. return $out;
  270. }
  271. }
  272. function the_pdf(){
  273. print get_the_pdf($id);
  274. }
  275. ?>