/wp-content/plugins/utilities.php
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
- <?php
- /*
- Plugin Name: Utilities
- Version: 0.1 Beta
- Plugin URI: http://www.maxvillegas.com
- Author: Max Villegas
- Author URI: http://www.maxvillegas.com
- Description: Coleccion de funciones menores
- */
- $ruta_new = split($_SERVER["SERVER_NAME"],get_bloginfo("home"));
- $ruta = $ruta_new[1]."/";
- function mvc($mvc){
- global $ruta;
- $uri = $_SERVER["REQUEST_URI"];
- $rest = substr($uri, -1);
- $uri = $rest=="/"?$uri:$uri."/";
- if ($ruta!="/"){ $uri = split($ruta, $uri); $uri = $uri[1]; }
- else { $uri = substr($uri,1); }
- $url = split('/', $uri);
- return $url[$mvc];
- }
- function idioma(){
- global $ruta;
- $in = split($ruta,$_SERVER["REQUEST_URI"]);
- if(stristr($ruta,'en/')){
- $url=split('en/',$ruta);
- $url=$url[0].$in[1];
- }
- else {
- $url=$ruta.'en/'.$in[1];
- }
- return $url;
- }
- function is_active() {
- global $ruta;
- $uri=$_SERVER["REQUEST_URI"];
- $rest = substr($uri, -1);
- $uri=$rest=="/"?$uri:$uri."/";
- if ($ruta!=""){$uri = split($ruta, $uri);$uri = $uri[1];}
- $url = split('/', $uri);
- $url=is_single()?$url[1]:$url[1];
- return $url;
- }
-
- function is_activePage() {
- global $ruta;
- $uri=$_SERVER["REQUEST_URI"];
- $rest = substr($uri, -1);
- $uri=$rest=="/"?$uri:$uri."/";
- if ($ruta!=""){$uri = split($ruta, $uri);$uri = $uri[1];}
- $url = split('/', $uri);
- $url=is_single()?$url[2]:$url[2];
- return $url;
- }
-
- function is_activePageSub() {
- global $ruta;
- $uri=$_SERVER["REQUEST_URI"];
- $rest = substr($uri, -1);
- $uri=$rest=="/"?$uri:$uri."/";
- if ($ruta!=""){$uri = split($ruta, $uri);$uri = $uri[1];}
- $url = split('/', $uri);
- $url=is_single()?$url[3]:$url[4];
- return $url;
- }
- function cortar($str,$n){
- if(strlen($str)>$n){
- $out = substr(strip_tags($str),0,$n);
- $out = explode(" ",$out);
- array_pop($out);
- $out = implode(" ",$out)." ...";
- }
- else{
- $out = $str;
- }
- return $out;
- }
- function url_wp($url){
- global $q_config;
- $server = $_SERVER["SERVER_NAME"];
- $default = get_option("qtranslate_default_language");
- $lenguajes = get_option("qtranslate_enabled_languages");
- foreach($lenguajes as $leng){
- if(eregi("/".strtolower($leng)."/",$url)){
- $urlfinal = eregi_replace("/".strtolower($leng)."/","/".strtolower($leng)."/#/",$url);
- }
- if(!eregi("/".strtolower($leng)."/",$url)){
- $urlfinal = eregi_replace($server,$server."/#",$url);
- }
- }
- return $urlfinal;
- }
- function mostrar_lenguajes(){
- global $q_config;
- $lenguajes = get_option("qtranslate_language_names");
- $disponibles = get_option("qtranslate_enabled_languages");
- $activo = detectar_leng();
- $uri = $_SERVER['REDIRECT_URL'];
- $urihome = $_SERVER['REQUEST_URI'];
- $blogurl = str_replace("http://".$_SERVER["SERVER_NAME"],"",get_bloginfo("home"))."/";
- foreach($lenguajes as $key=>$value){
- foreach($disponibles as $disponible){
- if($key==$disponible){
- if($_GET["s"]){
- // idioma -> por defecto
- if($key==$q_config["default_language"]){
- $url = $urihome;
- }
- // idioma -> idioma
- else{
- $url = eregi_replace("/\?s=","/".$key."/?s=",$urihome);
- }
- }
- else{
- // por defecto -> idioma
- if($q_config["default_language"] == $activo && $key!=$q_config["default_language"]){
- if($urihome==$blogurl) $url = eregi_replace($blogurl,$blogurl.$key."/",$urihome);
- else $url = eregi_replace($blogurl,$blogurl.$key."/",$uri);
- }
- // idioma -> por defecto
- else if(!eregi("/".strtolower($key)."/",$uri) && $key==$q_config["default_language"]){
- $url = eregi_replace("/".$activo."/","/",$uri);
- }
- // idioma -> idioma
- else{
- $url = eregi_replace("/".$activo."/","/".$key."/",$uri);
- }
- }
- if($key != $activo) $out .= '<a id="force_language" href="'.str_replace("&","&",$url).'" title="Switch to '.$value.'" rel="Help">'.$value.'</a>'."\n";
- }
- }
- }
- return $out;
- }
- function lang_ie(){
- if(stristr($_SERVER["HTTP_USER_AGENT"], "MSIE 6")){
- echo "\n\t\t\t\t".'<a href="#" class="menuIE"><span>Language</span>';
- echo '<table><tr><td><ul>';
- echo mostrar_lenguajes();
- echo '</ul></td></tr></table></a>';
- } else {
- echo '<ul>';
- echo mostrar_lenguajes();
- echo '</ul>';
- }
- }
- function obtener_imagen($id){
- global $wpdb;
- 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')");
- }
- function obtener_imagendest($id){
- global $wpdb;
- 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')");
- }
- function id_family($page_id) {
- global $wpdb;
- return $parent = $wpdb->get_var("SELECT post_parent FROM $wpdb->posts WHERE post_type='page' AND ID = '$page_id'");
- }
- function obtener_imagen_clientes($id){
- global $wpdb;
- $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')");
- foreach ($imagenes as $imagen) {
- $out .= '<li>
- <img class="logo" src="'.$imagen->guid.'" alt="'.$imagen->post_title.'" />
- </li>';
- }
- return $out;
- }
- function ficha_equipo($id){
- global $wpdb;
- $posts = get_posts('post_type=page&post_parent='.$id.'&orderby=menu_order&numberposts=30&order=ASC');
-
- foreach ($posts as $post){
- $out .= '<li class="grid_6">
- <img class="img" src="'.obtener_imagen($post->ID).'" alt="'.$post->post_title.'" />
- <div class="text">
- <h3>'.$post->post_title.'</h3>
- '.$post->post_content.'
- </div>
- </li>';
- }
- return $out;
-
- }
- function ficha_libros($id){
- global $wpdb;
- $posts = get_posts('post_type=page&post_parent='.$id.'&orderby=menu_order&numberposts=30&order=ASC');
- foreach ($posts as $post){
- $out .= '<li class="grid_6">
- <img class="img" src="'.obtener_imagen($post->ID).'" alt="'.$post->post_title.'" />
- <div class="text">
- <h3>'.$post->post_title.'</h3>
- '.$post->post_content.'
- </div>
- </li>';
- }
- return $out;
- }
- /*
- $date = datetime mysql
- */
- function flitrar_fecha($date, $formato, $separador){
- list($fecha, $hora) = split (' ', $date);
- if ($formato == "fecha"){
- $fecha = split ("-", $fecha);
- return $fecha[2] . $separador . $fecha[1] . $separador . $fecha[0];
- }
- if ($formato == "hora"){
- return $hora;
- }
- if ($formato == "fechahora"){
-
- $fecha = split ("-", $fecha);
- return $fecha[2] . $separador . $fecha[1] . $separador . $fecha[0] . " " . $hora;
- }
- }
- function last_comments(){
- global $wpdb;
- $args = array(
- 'post_type' => 'post',
- 'numberposts' => -1,
- 'post_status' => "publish",
- 'post_parent' => null
- );
- $posts = get_posts($args);
- foreach ($posts as $post) {
- $out .= '<li class="cf">
- <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>
- <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>
- </li>';
- }
- return $out;
- }
- function obtener_archivos(){
- global $wpdb, $post;
- $args = array(
- 'post_type' => 'attachment',
- 'numberposts' => -1,
- 'post_status' => null,
- 'post_parent' => $post->ID
- );
- $attachments = get_posts($args);
-
- if ($attachments) {
- foreach ($attachments as $attachment) {
-
- $out .= '<li class="cf">
- <div class="meta">
- <img src="'.get_bloginfo("stylesheet_directory").'/images/auxi/file.png" alt="" />
- <p>Subido el <span>'. flitrar_fecha($attachment->post_date, "fecha", "/").'</span></p>
- </div>
- <div class="cuerpo">
- <h3>'.apply_filters('the_title', $attachment->post_title).'</h3>
- <p>'. apply_filters('post_content', $attachment->post_content).'</p>
- <a href="'.apply_filters('guid', $attachment->guid).'" title="'.apply_filters('the_title', $attachment->post_title).'" class="down">Descargar »</a>
- </div>
- </li>';
- }
- return $out;
- }
- }
- function get_the_pdf($id){
- global $wpdb, $post;
- $args = array(
- 'post_type' => 'attachment',
- 'post_mime_type' => 'application/pdf',
- 'numberposts' => 1,
- 'post_status' => null,
- 'post_parent' => $id
- );
- $attachments = get_posts($args);
- if ($attachments) {
- foreach ($attachments as $attachment) {
- $out = apply_filters('guid', $attachment->guid);
- }
- return $out;
- }
- }
- function the_pdf(){
- print get_the_pdf($id);
- }
- ?>