Añadir estilos y scripts a la administración de plugins en WordPress

Cuando estamos desarrollando un plugin para WordPress y queremos que la administración del plugin tenga estilos y scripts propios, ya sea para darle cierta interactividad o diseño, o bien podremos incluir los estilos o librerías a pelo en la página del plugin, o bien podremos hacer que WordPress añada lo estilos y los scripts en el head del HTML. Para realizar esto, deberemos utilizar las acciones admin_print_styles y admin_print_scripts:

add_action('admin_print_styles', 'incluir_css');
add_action('admin_print_scripts', 'incluir_script');

function incluir_css() {
  echo '';
}

function incluir_script() {
  echo '';
}

Así de sencillo.

|

Scale-out vs Scale-up

In this post I'll cover the difference between multi-core concurrency that is often referred to as Scale-Up and distributed computing that is often referred to as Scale-Out mode.  more.. Source: Scale-out vs Scale-up (http://www.dzone.com/links/r/scaleout_vs_scaleup.html) by Nati Shalom …

Post original

|

PHPBuilder.com: Downloading and Parsing Gmail Messages in PHP

New on PHPBuilder.com today there’s a tutorial showing you how to download and parse messages from Google Mail. In their case it’s grabbing and parsing submissions from a form. Some friends of mine publish a literary journal that accepts submissions via email. At their request I wrote a script to download messages from the journal’s Gmail account a …

Post original

|

NoSQL databases: 10 Things you Should Know About Them

NoSQL databases: 10 Things you Should Know About Them: 5 pros and 5 cons by Guy Harrison: Five advantages of NoSQL Elastic scaling Big data Goodbye DBAs (see you later?) Economics Flexible data models Five challenges of NoSQL Maturity Support Analytics and business intelligence Administration Expertise A few amendments though: Elastic scaling: part …

Post original

Usar Solr desde PHP

Solr es un servidor de búsquedas basado en Lucene que nos puede venir muy bien cuando nuestro proyecto web necesite un motor de búsqueda en condiciones, siendo una alternativa a Sphinx. Aunque está basado en Java, existe una librería que permite trabajar con ella, otra posibilidad sería utilizar Zend Search, ya que usa el formato de Lucene, aunque en una versión anterior a la que utiliza Solr, por lo que nos encontramos con incompatibilidades.

El uso de la librería es bastante sencillo:

  require_once( 'Apache/Solr/Service.php' );
  
  // 
  // 
  // Try to connect to the named server, port, and url
  // 
  $solr = new Apache_Solr_Service( 'localhost', '8983', '/solr' );
  
  if ( ! $solr->ping() ) {
    echo 'Solr service not responding.';
    exit;
  }
  
  //
  //
  // Create two documents to represent two auto parts.
  // In practice, documents would likely be assembled from a 
  //   database query. 
  //
  $parts = array(
    'spark_plug' => array(
      'partno' => 1,
      'name' => 'Spark plug',
      'model' => array( 'Boxster', '924' ),
      'year' => array( 1999, 2000 ),
      'price' => 25.00,
      'inStock' => true,
    ),
    'windshield' => array(
      'partno' => 2,
      'name' => 'Windshield',
      'model' => '911',
      'year' => array( 1999, 2000 ),
      'price' => 15.00,
      'inStock' => false,
    )
  );
    
  $documents = array();
  
  foreach ( $parts as $item => $fields ) {
    $part = new Apache_Solr_Document();
    
    foreach ( $fields as $key => $value ) {
      if ( is_array( $value ) ) {
        foreach ( $value as $datum ) {
          $part->setMultiValue( $key, $datum );
        }
      }
      else {
        $part->$key = $value;
      }
    }
    
    $documents[] = $part;
  }
    
  //
  //
  // Load the documents into the index
  // 
  try {
    $solr->addDocuments( $documents );
    $solr->commit();
    $solr->optimize();
  }
  catch ( Exception $e ) {
    echo $e->getMessage();
  }
  
  //
  // 
  // Run some queries. Provide the raw path, a starting offset
  //   for result documents, and the maximum number of result
  //   documents to return. You can also use a fourth parameter
  //   to control how results are sorted and highlighted, 
  //   among other options.
  //
  $offset = 0;
  $limit = 10;
  
  $queries = array(
    'partno: 1 OR partno: 2',
    'model: Boxster',
    'name: plug'
  );

  foreach ( $queries as $query ) {
    $response = $solr->search( $query, $offset, $limit );
    
    if ( $response->getHttpStatus() == 200 ) { 
      // print_r( $response->getRawResponse() );
      
      if ( $response->response->numFound > 0 ) {
        echo "$query 
"; foreach ( $response->response->docs as $doc ) { echo "$doc->partno $doc->name
"; } echo '
'; } } else { echo $response->getHttpStatusMessage(); } }

También recomiendo que en el esquema de Solr añadamos el filtro de caracteres mapping-ISOLatin1Accent.txt, para que no tengamos problemas a la hora de buscar palabras acentuadas sin usar los acentos (cancion => canción).

Solr PHP Client

|

NoSQL Guide for Beginners

NoSQL Guide for Beginners: Alexandre Porcelli has a great post for NoSQL beginners: one of the most frequent question that people use to ask me about nosql is: what is the best nosql tool that enables me start with using my programming language (java, .net, php, python, etc..)? its almost impossible to have a quick answer ‘cos it involves many thin …

Post original

|

InfiniteGraph Use Case: Modeling Stackoverflow

InfiniteGraph Use Case: Modeling Stackoverflow: I didn’t hear much about InfiniteGraph after its 1.0 release, except this post that uses Stackoverflow data as input to demo some features of graph databases: The vertices in the graph are represented as the Users, Questions and Answers above while the edges are represented as the interactions between …

Post original

|

Picasa jQuery Plugin

A simple jQuery plugin to get albums and images from Picasa without the need for PHP, Ruby, or any other server side language. Makes it easy to create a simple, dynamic, free, client-side-only image gallery. …

Post original