if($j>$start&µtime(true)-$began>8)break;
try{$r=tlm_mcp_write_apply_item($plan['items'][$j]);}catch(Throwable $e){$r=['id'=>$plan['items'][$j]['id'],'estado'=>'error','detalle'=>'Revisar estado real; puede haber cambios parciales.'];}
$r['posicion']=$j;$r['fecha']=gmdate('c');$plan['recibos'][]=$r;
if(!update_option($key,$plan,false))throw new RuntimeException('Recibo no guardado; consultar estado y reanudar con la misma huella.');
}
return tlm_mcp_write_status($plan,$start);
}catch(Throwable $e){return ['success'=>false,'error'=>$e instanceof RuntimeException?$e->getMessage():'Operación interrumpida. Consultar estado antes de repetir.'];}
finally{if($lock!==null)$wpdb->get_var($wpdb->prepare('SELECT RELEASE_LOCK(%s)',$lock));}
}
add_action('init',function(){add_filter('mwai_mcp_tools','tlm_mcp_write_tools',20);add_filter('mwai_mcp_callback','tlm_mcp_write_dispatch',20,4);},20);
// Draft creation only. No publication, pricing, download paths or file uploads.
function tlm_mcp03_tools($tools){
$s=['type'=>'string'];$i=['type'=>'integer'];$ids=['type'=>'array','items'=>$i];
$props=['clave_origen'=>$s,'titulo'=>$s,'autor'=>$s,'sinopsis'=>$s,'descripcion'=>$s,'categorias'=>$ids,'etiquetas'=>$ids,'seo_titulo'=>$s,'seo_descripcion'=>$s,'seo_palabra_clave'=>$s,'portada_id'=>$i,'derechos_confirmados'=>['type'=>'boolean'],'referencia_derechos'=>$s];
$specs=[
['tlm_borradores_simular','Simula 1–1000 nuevas fichas. Requiere derechos acreditados, clave estable de origen, título, autor, sinopsis y categorías. Bloquea coincidencias de título incluso con autor distinto para revisión. No crea productos.',['lote'=>$s,'libros'=>['type'=>'array','items'=>['type'=>'object','properties'=>$props,'required'=>['clave_origen','titulo','autor','sinopsis','categorias','derechos_confirmados','referencia_derechos'],'additionalProperties'=>false]]],['lote','libros'],false],
['tlm_borradores_aplicar','Crea hasta 20 borradores de un plan validado; revalida duplicados, guarda recibos y permite reanudar. No publica ni vincula PDF ni precios.',['lote'=>$s,'huella'=>$s,'bloque'=>$i],['lote','huella'],false],
['tlm_borradores_estado','Consulta estado y recibos de creación de un lote propio.',['lote'=>$s,'offset'=>$i],['lote'],true]];
foreach($specs as [$name,$description,$p,$required,$ro])$tools[]=['name'=>$name,'description'=>$description,'category'=>'TuLibroMex Lotes','inputSchema'=>['type'=>'object','properties'=>$p,'required'=>$required,'additionalProperties'=>false],'annotations'=>['readOnlyHint'=>$ro,'destructiveHint'=>false,'idempotentHint'=>true,'openWorldHint'=>false]];
return $tools;
}
function tlm_mcp03_text($x,$max,$required=true){
if(!is_string($x)||strlen($x)>$max||($required&&trim($x)==='')||wp_strip_all_tags($x)!==$x||preg_match('/[\x00-\x08\x0B\x0C\x0E-\x1F]/',$x))throw new RuntimeException('Texto inválido, vacío o demasiado largo.');
return trim($x);
}
function tlm_mcp03_item($x){
if(!is_array($x)||array_diff(array_keys($x),['clave_origen','titulo','autor','sinopsis','descripcion','categorias','etiquetas','seo_titulo','seo_descripcion','seo_palabra_clave','portada_id','derechos_confirmados','referencia_derechos']))throw new RuntimeException('Campo no permitido.');
if(($x['derechos_confirmados']??null)!==true)throw new RuntimeException('Derechos no confirmados.');
$origin=tlm_mcp03_text($x['clave_origen']??null,200);$title=tlm_mcp03_text($x['titulo']??null,350);$author=tlm_mcp03_text($x['autor']??null,200);
$cats=tlm_mcp_write_ids($x['categorias']??null,'product_cat');if(!$cats||in_array(280,$cats,true))throw new RuntimeException('Categorías editoriales requeridas.');
$tags=tlm_mcp_write_ids($x['etiquetas']??[],'product_tag');$cover=$x['portada_id']??0;
if(!is_int($cover)||$cover<0||($cover&&(!wp_attachment_is_image($cover)||!current_user_can('edit_post',$cover))))throw new RuntimeException('Portada no es una imagen autorizada.');
$nt=tlm_mcp_norm($title);$na=tlm_mcp_norm($author);if(!$nt||!$na)throw new RuntimeException('Identidad bibliográfica inválida.');
$full=$title.' de '.$author;$slug=substr(sanitize_title($full),0,145).'-'.substr(hash('sha256',$nt.'|'.$na),0,16);
$p=['titulo'=>$title,'autor'=>$author,'titulo_producto'=>$full,'slug'=>$slug,'origen'=>hash('sha256',$origin),'sinopsis'=>tlm_mcp03_text($x['sinopsis']??null,12000),'descripcion'=>tlm_mcp03_text($x['descripcion']??'',24000,false),'categorias'=>$cats,'etiquetas'=>$tags,'portada_id'=>$cover,'derechos_ref'=>tlm_mcp03_text($x['referencia_derechos']??null,500),'seo'=>[]];
foreach(['seo_titulo'=>'rank_math_title','seo_descripcion'=>'rank_math_description','seo_palabra_clave'=>'rank_math_focus_keyword'] as $k=>$meta)if(isset($x[$k]))$p['seo'][$meta]=tlm_mcp03_text($x[$k],1000);
$p['fingerprint']=hash('sha256',wp_json_encode($p));return $p;
}
function tlm_mcp03_catalog(){
$all=[];$after=0;$until=tlm_mcp_upper();do{$rows=tlm_mcp_rows($after,$until,5000);foreach($rows as $r){$all[]=$r;$after=(int)$r[0];}if(count($all)>100000)throw new RuntimeException('Catálogo supera límite de seguridad.');}while(count($rows)===5000);return tlm_mcp_index($all);
}
function tlm_mcp03_existing($p){
global $wpdb;
// Include trash and other statuses for source and slug collision checks.
$q=$wpdb->prepare("SELECT DISTINCT p.ID FROM {$wpdb->posts} p LEFT JOIN {$wpdb->postmeta} m ON p.ID=m.post_id AND m.meta_key=%s WHERE p.post_type='product' AND (p.post_name=%s OR m.meta_value=%s) LIMIT 3",'_tlm_mcp03_origen',$p['slug'],$p['origen']);
$rows=$wpdb->get_results($q,ARRAY_N);if(!is_array($rows)||$wpdb->last_error)throw new RuntimeException('No se pudo verificar origen o slug.');return array_map(fn($r)=>(int)$r[0],$rows);
}
function tlm_mcp03_collision($p,$index,$except=0){
// Any exact title hit (including a homonym) requires human review. Full title checked as well.
foreach([tlm_mcp_norm($p['titulo']),tlm_mcp_norm($p['titulo_producto'])] as $k)foreach($index[$k]??[] as [$r,$a])if((int)$r[0]!==$except)return true;
return false;
}
function tlm_mcp03_verify($id,$p){
$post=get_post($id);if(!$post||$post->post_type!=='product'||$post->post_status!=='draft'||$post->post_title!==$p['titulo_producto']||$post->post_name!==$p['slug']||$post->post_excerpt!==$p['sinopsis']||$post->post_content!==$p['descripcion'])return false;
if(get_post_meta($id,'_tlm_mcp03_origen',true)!==$p['origen']||get_post_meta($id,'_tlm_mcp03_huella',true)!==$p['fingerprint']||get_post_meta($id,'_tlm_mcp03_derechos_ref',true)!==$p['derechos_ref'])return false;
foreach(['product_cat'=>'categorias','product_tag'=>'etiquetas'] as $tax=>$k)if(tlm_mcp_write_current($id,$tax)!==$p[$k])return false;
foreach($p['seo'] as $k=>$v)if(tlm_mcp_write_current($id,$k)!==$v)return false;
return (int)get_post_thumbnail_id($id)===$p['portada_id'];
}
function tlm_mcp03_create($p,$index){
$found=tlm_mcp03_existing($p);
if($found){$id=$found[0];if(count($found)===1&¤t_user_can('edit_post',$id)&&tlm_mcp03_verify($id,$p))return ['id'=>$id,'estado'=>'ya_aplicado','detalle'=>'Borrador recuperado sin duplicar.'];return ['id'=>$id,'estado'=>'conflicto','detalle'=>'Origen o slug existente; revisar borrador parcial o registro anterior.'];}
if(tlm_mcp03_collision($p,$index))return ['id'=>0,'estado'=>'conflicto','detalle'=>'Coincidencia de título en catálogo; no se creó producto.'];
foreach(['product_cat'=>'categorias','product_tag'=>'etiquetas'] as $tax=>$k)tlm_mcp_write_ids($p[$k],$tax);
if($p['portada_id']&&(!wp_attachment_is_image($p['portada_id'])||!current_user_can('edit_post',$p['portada_id'])))throw new RuntimeException('Portada ya no disponible.');
$meta=['_tlm_mcp03_origen'=>$p['origen'],'_tlm_mcp03_huella'=>$p['fingerprint'],'_tlm_mcp03_derechos_ref'=>$p['derechos_ref'],'_tlm_mcp03_pendiente_archivo'=>'1']+$p['seo'];
$id=wp_insert_post(wp_slash(['post_type'=>'product','post_status'=>'draft','post_title'=>$p['titulo_producto'],'post_name'=>$p['slug'],'post_excerpt'=>$p['sinopsis'],'post_content'=>$p['descripcion'],'meta_input'=>$meta]),true);
if(is_wp_error($id)||!$id)throw new RuntimeException('Error al crear borrador.');$id=(int)$id;
// Verify status before term or cover writes. An unexpected partial creation is never published or deleted automatically.
$post=get_post($id);if(!$post||$post->post_status!=='draft'||$post->post_type!=='product')return ['id'=>$id,'estado'=>'error','detalle'=>'Estado inesperado; revisar manualmente.'];
foreach(['product_cat'=>'categorias','product_tag'=>'etiquetas'] as $tax=>$k){$r=wp_set_object_terms($id,$p[$k],$tax,false);if(is_wp_error($r))return ['id'=>$id,'estado'=>'error','detalle'=>'Borrador parcial; revisar términos.'];}
if($p['portada_id'])set_post_thumbnail($id,$p['portada_id']);
if(!tlm_mcp03_verify($id,$p))return ['id'=>$id,'estado'=>'error','detalle'=>'Borrador parcial; lectura posterior no coincide.'];
return ['id'=>$id,'estado'=>'verificado','detalle'=>'Borrador creado; archivo protegido pendiente.'];
}
function tlm_mcp03_dispatch($result,$tool,$args,$unused){
if(!in_array($tool,['tlm_borradores_simular','tlm_borradores_aplicar','tlm_borradores_estado'],true))return $result;
if(!is_user_logged_in()||!current_user_can('manage_woocommerce')||!current_user_can('edit_products'))return ['success'=>false,'error'=>'Permisos insuficientes.'];
global $wpdb;$lock=null;
try{
$key=str_replace('tlm_mcp02_','tlm_mcp03_',tlm_mcp_write_key($args['lote']??null));$plan=get_option($key,false);
if($tool==='tlm_borradores_estado')return $plan?tlm_mcp_write_status($plan,(int)($args['offset']??0)):['success'=>false,'error'=>'Lote no existe.'];
if($tool==='tlm_borradores_simular'){
$items=$args['libros']??null;if(!is_array($items)||count($items)<1||count($items)>1000||strlen(wp_json_encode($items)?:'')>2000000)throw new RuntimeException('Enviar 1–1000 libros, máximo 2 MB.');
$hash=hash('sha256',wp_json_encode($items));if($plan){if($plan['entrada_hash']!==$hash)throw new RuntimeException('Clave ya utilizada con otros datos.');return tlm_mcp_write_status($plan);}
$index=tlm_mcp03_catalog();$validated=[];$errors=[];$seen=[];$origins=[];
foreach(array_values($items) as $pos=>$x){try{$p=tlm_mcp03_item($x);$t=tlm_mcp_norm($p['titulo']);if(isset($seen[$t])||isset($origins[$p['origen']]))throw new RuntimeException('Título u origen repetido en lote.');$seen[$t]=true;$origins[$p['origen']]=true;if(tlm_mcp03_existing($p)||tlm_mcp03_collision($p,$index))throw new RuntimeException('Coincidencia de título, slug u origen; revisión requerida.');$validated[]=$p;}catch(Throwable $e){$errors[]=['posicion'=>$pos,'error'=>$e->getMessage()];}}
if($errors)return ['success'=>false,'total'=>count($items),'validos'=>count($validated),'errores'=>count($errors),'detalle'=>array_slice($errors,0,100),'productos_creados'=>0,'nota'=>'No se guardó plan parcial.'];
$plan=['lote'=>$args['lote'],'entrada_hash'=>$hash,'huella'=>hash('sha256',wp_json_encode($validated)),'items'=>$validated,'recibos'=>[],'creado'=>time()];if(!add_option($key,$plan,'',false))throw new RuntimeException('No se pudo guardar plan; consultar estado.');return tlm_mcp_write_status($plan)+['productos_creados'=>0,'simulado'=>true];
}
if(!$plan||!is_string($args['huella']??null)||!hash_equals($plan['huella'],$args['huella']))throw new RuntimeException('Plan inexistente o huella incorrecta.');
$lock='tlm02_'.substr(hash('sha256',$wpdb->options),0,50);if((string)$wpdb->get_var($wpdb->prepare('SELECT GET_LOCK(%s, 0)',$lock))!=='1'){$lock=null;throw new RuntimeException('Otra escritura activa o bloqueo SQL no disponible.');}
wp_cache_delete($key,'options');$plan=get_option($key,false);if(!$plan||!hash_equals($plan['huella'],$args['huella']))throw new RuntimeException('Plan no disponible tras bloqueo.');
$start=count($plan['recibos']);$end=min(count($plan['items']),$start+tlm_mcp_limit($args['bloque']??20,20));$began=microtime(true);$index=$start<$end?tlm_mcp03_catalog():[];
for($j=$start;$j<$end;$j++){
if($j>$start&µtime(true)-$began>8)break;$p=$plan['items'][$j];
try{$r=tlm_mcp03_create($p,$index);}catch(Throwable $e){$r=['id'=>0,'estado'=>'error','detalle'=>'Revisar estado real; puede existir un borrador parcial.'];}
if(in_array($r['estado'],['verificado','ya_aplicado'],true)){$row=[$r['id'],$p['titulo_producto'],$p['slug'],'draft'];foreach(tlm_mcp_index([$row]) as $k=>$v)$index[$k]=array_merge($index[$k]??[],$v);}
$r['posicion']=$j;$r['fecha']=gmdate('c');$plan['recibos'][]=$r;if(!update_option($key,$plan,false))throw new RuntimeException('Recibo no guardado; consultar estado y reanudar con la misma huella.');
}
return tlm_mcp_write_status($plan,$start);
}catch(Throwable $e){return ['success'=>false,'error'=>$e instanceof RuntimeException?$e->getMessage():'Operación interrumpida. Consultar estado antes de repetir.'];}
finally{if($lock!==null)$wpdb->get_var($wpdb->prepare('SELECT RELEASE_LOCK(%s)',$lock));}
}
add_action('init',function(){add_filter('mwai_mcp_tools','tlm_mcp03_tools',30);add_filter('mwai_mcp_callback','tlm_mcp03_dispatch',30,4);},30);
Afirmaciones: Cómo usar afirmaciones para cambiar tu vida de Louise L. Hay - Tu Libro Mex
Ir al contenido
Afirmaciones: Cómo usar afirmaciones para cambiar tu vida de Louise L. Hay to Pinterest (opens in a new window)
Atención: lunes a sábado, 9:00 a 21:00 · hora del centro de México.
Las afirmaciones positivas son una fuente inmensa de poder personal. Mediante ellas podemos cambiar y mejorar cualquier aspecto de nuestra vida. Cada pensamiento y palabra que pronunciamos es una afirmación. Incluso las conversaciones que sostenemos con nosotros mismos, nuestro diálogo interno, son una cadena de afirmaciones positivas o negativas. Nuestras creencias no son más que patrones habituales de pensamiento aprendidos durante la niñez. Y aunque muchas nos benefician otras pueden limitar nuestra habilidad para crear las cosas que realmente queremos en la vida. Tenemos que reaprender a pensar y hablar de forma positiva para vencer el hábito arraigado de la negatividad. Los principios propuestos por Louise L. Hay, aplicables a temas como la salud, el perdón, la prosperidad, la creatividad, las relaciones, el éxito profesional y la autoestima, te permitirán disfrutar de la vida maravillosa que mereces.
Después de confirmar tu pago, coordinamos el envío del archivo por WhatsApp. Al contactarnos, indícanos el título del libro y comparte tu comprobante de pago.
¿Qué hago si tengo problemas con el archivo?
Escríbenos por WhatsApp con el título del libro y una descripción del problema para que podamos revisarlo contigo.
Solo los usuarios registrados que hayan comprado este producto pueden hacer una valoración.
Una selección para seguir leyendo
Elige los libros que quieras añadir a tu carrito.
LH
Acerca del autor
Louise L. Hay
Escritora vinculada al desarrollo personal y fundadora de la editorial Hay House. Su bibliografía incluye You Can Heal Your Life y obras centradas en afirmaciones, autoestima y su filosofía de autoayuda.
Valoraciones
No hay valoraciones aún.