Changeset 3447566
- Timestamp:
- 01/27/2026 07:26:28 AM (3 weeks ago)
- Location:
- wp-facturaone/trunk
- Files:
-
- 3 edited
-
FONE_index.php (modified) (1 diff)
-
update_images.php (modified) (3 diffs)
-
wp-facturaone.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-facturaone/trunk/FONE_index.php
r3447004 r3447566 660 660 </p> 661 661 <div style="margin-top:30px; margin-bottom:30px; text-align:left; max-width:100%;"> 662 <iframe width=" 760" height="515"662 <iframe width="640" height="360" 663 663 style="max-width:100%;" 664 664 src="https://www.youtube.com/embed/DacGO1XAFQ4" -
wp-facturaone/trunk/update_images.php
r3392499 r3447566 19 19 20 20 if (isset($_POST['action']) && ($_POST['action']=='start' || $_POST['action']=='startall' )){ 21 if ($_POST['action']=='startall'){$sobreescribe=1;}else{$sobreescribe=0;}21 $sobreescribe = ($_POST['action'] === 'startall') ? 1 : 0; 22 22 //genera proceso sobre todas las db 23 23 $pagePath = explode('/wp-content/', dirname(__FILE__)); … … 121 121 $baseurlfact=trim($arrayvariables[4]); 122 122 $urlimage=trim($arrayvariables[5]); 123 $sobreescribe=trim($arrayvariables[6]); 124 if ($sobreescribe==1){$sobreescribe=true;}else{$sobreescribe=false;} 123 $sobreescribe = ((int)($arrayvariables[6] ?? 0) === 1); 125 124 126 125 if ($idproducto!='' && $urlimage!=''){ … … 137 136 $baseurlfact=trim($arrayvariables[4]); 138 137 $urlimage=trim($arrayvariables[5]); 139 $sobreescribe=trim($arrayvariables[6]); 140 if ($sobreescribe==1){$sobreescribe=true;}else{$sobreescribe=false;} 138 $sobreescribe = ((int)($arrayvariables[6] ?? 0) === 1); 141 139 142 140 if ($item_lookup_id!='' && $urlimage!=''){ -
wp-facturaone/trunk/wp-facturaone.php
r3447004 r3447566 4 4 Plugin URI: https://www.facturaone.com/ 5 5 Description: La forma más fácil de trabajar con tu tienda online desde nuestro ERP FacturaONE. 6 Version: 4.6 86 Version: 4.69 7 7 Author: FacturaONE 8 8 Author URI: https://www.facturaone.com/ … … 1259 1259 1260 1260 function FONE_subeimagen($baseurlfact,$item_lookup_id,$urlimage,$item_name,$item_txt_alternativo,$borragaleriaimag,$sobreescribe){ 1261 $mod_wordpress = get_option('mod_wordpress'); 1262 if($mod_wordpress>0){ 1263 $urlimage=trim($urlimage); 1264 $item_lookup_id=trim($item_lookup_id); 1265 $_product_id = fone_get_product_id_by_idfactura($item_lookup_id); 1266 if ($_product_id>0 && $sobreescribe==true){ 1267 //elimina siempre variaciones anteriores 1268 //FONE_delete_product_image_variaciones($_product_id); 1269 FONE_delete_product_images($_product_id, $borragaleriaimag); 1270 } 1271 // sube imagenes 1272 if ($urlimage != '' && $item_lookup_id != '' && $_product_id > 0) { 1273 // userdb cache 1274 $userdb = get_option('FacturaONE_userdb'); 1275 if ($userdb == '') { 1276 $userdb = gzuncompress(base64_decode(FONE_url_get_contents('userdb'))); 1277 update_option('FacturaONE_userdb', $userdb); 1278 } 1279 $urlssl = (get_option('FacturaONE_conexionSSL') == '1') ? 'https' : 'http'; 1280 $userdb = (int)$userdb; 1281 $token = FONE_get_externalpics_token($userdb); 1282 $fileurl = ''; 1283 if ($token !== '') { 1284 $fileurl = $urlssl.'://app.ifactura.es/externalpics/index.php' 1285 .'?i='.(int)$item_lookup_id 1286 .'&d='.(int)$userdb 1287 .'&f=1&s='.$token 1288 .'&time='.time(); 1289 if (preg_match('~^https?://~i', $urlimage)) { 1290 // URL externa: fuerza descarga/actualiza cache en el ERP y devuelve FULL 1291 $fileurl .= '&n='.base64_encode($urlimage); 1292 } 1293 if (trim($item_txt_alternativo) == '') { 1294 $item_txt_alternativo = str_replace(['_','-'], ' ', $item_name); 1295 } 1296 1297 if ($sobreescribe || !wp_get_attachment_image_src(get_post_thumbnail_id($_product_id), 'single-post-thumbnail')) { 1298 FONE_uploadMedia($fileurl, $_product_id, $item_name, $item_lookup_id, $item_txt_alternativo, $sobreescribe); 1299 } 1300 } 1301 } 1302 }//fin mod_wordpress 1303 } 1261 $mod_wordpress = (int) get_option('mod_wordpress'); 1262 if ($mod_wordpress <= 0) return; 1263 1264 $sobreescribe = ($sobreescribe === true || (int)$sobreescribe === 1); 1265 1266 $urlimage = trim((string)$urlimage); 1267 $item_lookup_id = trim((string)$item_lookup_id); 1268 1269 $_product_id = (int) fone_get_product_id_by_idfactura($item_lookup_id); 1270 if ($_product_id <= 0 || $urlimage === '' || $item_lookup_id === '') return; 1271 1272 // Si NO sobrescribe y ya hay imagen destacada, no hagas nada (salida rápida) 1273 if ($sobreescribe === false && (int) get_post_thumbnail_id($_product_id) > 0) { 1274 return; 1275 } 1276 1277 // Si sobrescribe, borra antes 1278 if ($sobreescribe === true) { 1279 FONE_delete_product_images($_product_id, $borragaleriaimag); 1280 } 1281 1282 // userdb cache 1283 $userdb = get_option('FacturaONE_userdb'); 1284 if ($userdb == '') { 1285 $userdb = gzuncompress(base64_decode(FONE_url_get_contents('userdb'))); 1286 update_option('FacturaONE_userdb', $userdb); 1287 } 1288 1289 $urlssl = (get_option('FacturaONE_conexionSSL') == '1') ? 'https' : 'http'; 1290 $userdb = (int)$userdb; 1291 $token = FONE_get_externalpics_token($userdb); 1292 if ($token === '') return; 1293 1294 $fileurl = $urlssl.'://app.ifactura.es/externalpics/index.php' 1295 .'?i='.(int)$item_lookup_id 1296 .'&d='.(int)$userdb 1297 .'&f=1&s='.$token 1298 .'&time='.time(); 1299 1300 if (preg_match('~^https?://~i', $urlimage)) { 1301 $fileurl .= '&n='.base64_encode($urlimage); 1302 } 1303 1304 if (trim((string)$item_txt_alternativo) === '') { 1305 $item_txt_alternativo = str_replace(['_','-'], ' ', (string)$item_name); 1306 } 1307 1308 FONE_uploadMedia($fileurl, $_product_id, $item_name, $item_lookup_id, $item_txt_alternativo, $sobreescribe); 1309 } 1310 1304 1311 1305 1312 function FONE_subeimagen_variacion($baseurlfact, $hijo_item_lookup_id, $urlimage, $pic_item_name_variacion, $pic_item_txt_alternativo_variacion, $sobreescribe){ 1306 $mod_wordpress = get_option('mod_wordpress'); 1307 if ($mod_wordpress > 0) { 1308 1309 $urlimage = trim((string)$urlimage); 1310 $hijo_item_lookup_id = trim((string)$hijo_item_lookup_id); 1311 1312 // sube imagenes 1313 if ($urlimage !== '' && $hijo_item_lookup_id !== '') { 1314 1315 $variation_id = fone_get_variation_id_by_idfactura($hijo_item_lookup_id); 1316 if ($variation_id > 0) { 1317 1318 if ($sobreescribe == true) { 1319 // elimina imagen destacada actual de la variación (si existe) 1320 $variation = new WC_Product_Variation($variation_id); 1321 if ($variation) { 1322 $featured_image_id = (int)$variation->get_image_id(); 1323 if ($featured_image_id > 0) { 1324 wp_delete_post($featured_image_id, true); 1325 } 1326 // Limpia referencia en Woo (evita que quede un ID huérfano) 1327 $variation->set_image_id(0); 1328 $variation->save(); 1329 } 1330 } 1331 1332 // userdb cache 1333 $userdb = (string) get_option('FacturaONE_userdb'); 1334 if ($userdb === '') { 1335 $resultado = FONE_url_get_contents('userdb'); 1336 $userdb = gzuncompress(base64_decode($resultado)); 1337 update_option('FacturaONE_userdb', $userdb); 1338 } 1339 1340 $urlssl = (get_option('FacturaONE_conexionSSL') == '1') ? 'https' : 'http'; 1341 $userdb_int = (int)$userdb; 1342 1343 $token = FONE_get_externalpics_token($userdb_int); 1344 if ($token === '') return; 1345 1346 // URL nueva (index.php protegido por token) 1347 $fileurl = $urlssl.'://app.ifactura.es/externalpics/index.php' 1348 .'?i='.(int)$hijo_item_lookup_id 1349 .'&d='.(int)$userdb_int 1350 .'&f=1&s='.$token 1351 .'&time='.time(); 1352 // Si es URL externa, forzamos descarga/cache en el ERP 1353 if (preg_match('~^https?://~i', $urlimage)) { 1354 $fileurl .= '&n=' . base64_encode($urlimage); 1355 } 1356 1357 if (trim((string)$pic_item_txt_alternativo_variacion) === '') { 1358 $pic_item_txt_alternativo_variacion = str_replace(['_','-'], ' ', (string)$pic_item_name_variacion); 1359 } 1360 1361 if ($sobreescribe == true) { 1362 FONE_uploadMedia($fileurl, $variation_id, $pic_item_name_variacion, $hijo_item_lookup_id, $pic_item_txt_alternativo_variacion, $sobreescribe); 1363 } else { 1364 if ((int)get_post_thumbnail_id($variation_id) === 0) { 1365 FONE_uploadMedia($fileurl, $variation_id, $pic_item_name_variacion, $hijo_item_lookup_id, $pic_item_txt_alternativo_variacion, $sobreescribe); 1366 } 1367 } 1368 } 1369 } 1370 } 1371 } 1313 $mod_wordpress = (int) get_option('mod_wordpress'); 1314 if ($mod_wordpress <= 0) return; 1315 1316 $sobreescribe = ($sobreescribe === true || (int)$sobreescribe === 1); 1317 1318 $urlimage = trim((string)$urlimage); 1319 $hijo_item_lookup_id = trim((string)$hijo_item_lookup_id); 1320 if ($urlimage === '' || $hijo_item_lookup_id === '') return; 1321 1322 $variation_id = (int) fone_get_variation_id_by_idfactura($hijo_item_lookup_id); 1323 if ($variation_id <= 0) return; 1324 1325 $variation = new WC_Product_Variation($variation_id); 1326 if (!$variation) return; 1327 1328 // Si NO sobrescribe y ya hay imagen en la variación, no hagas nada 1329 if ($sobreescribe === false && (int)$variation->get_image_id() > 0) { 1330 return; 1331 } 1332 1333 // Si sobrescribe, borra imagen actual 1334 if ($sobreescribe === true) { 1335 $featured_image_id = (int)$variation->get_image_id(); 1336 if ($featured_image_id > 0) wp_delete_post($featured_image_id, true); 1337 $variation->set_image_id(0); 1338 $variation->save(); 1339 } 1340 1341 // userdb cache 1342 $userdb = (string) get_option('FacturaONE_userdb'); 1343 if ($userdb === '') { 1344 $resultado = FONE_url_get_contents('userdb'); 1345 $userdb = gzuncompress(base64_decode($resultado)); 1346 update_option('FacturaONE_userdb', $userdb); 1347 } 1348 1349 $urlssl = (get_option('FacturaONE_conexionSSL') == '1') ? 'https' : 'http'; 1350 $userdb_int = (int)$userdb; 1351 1352 $token = FONE_get_externalpics_token($userdb_int); 1353 if ($token === '') return; 1354 1355 $fileurl = $urlssl.'://app.ifactura.es/externalpics/index.php' 1356 .'?i='.(int)$hijo_item_lookup_id 1357 .'&d='.(int)$userdb_int 1358 .'&f=1&s='.$token 1359 .'&time='.time(); 1360 1361 if (preg_match('~^https?://~i', $urlimage)) { 1362 $fileurl .= '&n=' . base64_encode($urlimage); 1363 } 1364 1365 if (trim((string)$pic_item_txt_alternativo_variacion) === '') { 1366 $pic_item_txt_alternativo_variacion = str_replace(['_','-'], ' ', (string)$pic_item_name_variacion); 1367 } 1368 1369 FONE_uploadMedia($fileurl, $variation_id, $pic_item_name_variacion, $hijo_item_lookup_id, $pic_item_txt_alternativo_variacion, $sobreescribe); 1370 } 1371 1372 1372 function FONE_uploadMedia($image_url,$post_id,$item_name,$item_lookup_id,$item_txt_alternativo, $sobreescribe=false){ 1373 1373 require_once(ABSPATH . 'wp-admin/includes/media.php'); … … 1406 1406 if ($item_txt_alternativo !== '') {update_post_meta($thumb_id, '_wp_attachment_image_alt', $item_txt_alternativo);} 1407 1407 set_post_thumbnail($post_id, $thumb_id); 1408 @unlink($image_tmp); 1409 return true; 1408 1410 } 1409 1411 }
Note: See TracChangeset
for help on using the changeset viewer.