PluginProbe
ShiftController Employee Shift Scheduling / 4.9.66
ShiftController Employee Shift Scheduling v4.9.66
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
← All changes | hc3/crud/wordpress/custompost.php +0 -186 4.9.774.9.66 View file →
@@ -402,191 +402,10 @@
402 402 return $return;
403 403 }
404 404
405 405 // CREATE
406 - public function sqlValues( array $values, $many = false )
407 - {
408 - $ret = '';
409 -
410 - // fields
411 - $fields = $many ? array_keys( current($values) ) : array_keys( $values );
412 - $ret .= '(' . join(', ', $fields) . ')';
413 -
414 - // values
415 - $arrayOfValues = $many ? $values : [ $values ];
416 -
417 - $sqlArg = array();
418 - $retValue = array();
419 - foreach( $arrayOfValues as $thisValues ){
420 - $thisSv = [];
421 - foreach( $fields as $k ){
422 - $v = $thisValues[ $k ];
423 - $isInt = is_numeric( $v ) && ( strlen($v) < 12 );
424 - $sqlArg[] = $v;
425 -
426 - if( $isInt ){
427 - $thisSv[] = '%d';
428 - // $sv[] = '%d';
429 - }
430 - else {
431 - $thisSv[] = '%s';
432 - // $sv[] = '%s';
433 - }
434 - }
435 - $retValue[] = '(' . join(', ', $thisSv) . ')';
436 - }
437 -
438 - $ret .= ' VALUES ' . join( ', ', $retValue );
439 -
440 - global $wpdb;
441 - $ret = $wpdb->prepare( $ret, $sqlArg );
442 -
443 - return $ret;
444 - }
445 -
446 - public function createDirect( $values )
447 - {
448 - $ret = $values;
449 -
450 - list( $coreValues, $metaValues ) = $this->convert_to_wp( $values );
451 -
452 - $now = time();
453 - $postDate = date( "Y-m-d H:i:s", $now );
454 - $postDateGmt = gmdate( "Y-m-d H:i:s", $now );
455 - $postAuthor = get_current_user_id();
456 -
457 - $default = array(
458 - 'post_content' => '',
459 - 'post_title' => '',
460 - 'post_excerpt' => '',
461 - 'post_password' => '',
462 - 'post_name' => '',
463 - 'to_ping' => '',
464 - 'pinged' => '',
465 - 'post_content_filtered' => '',
466 - 'guid' => '',
467 - 'post_mime_type' => '',
468 -
469 - 'post_date' => $postDate,
470 - 'post_date_gmt' => $postDateGmt,
471 - 'post_modified' => $postDate,
472 - 'post_modified_gmt' => $postDateGmt,
473 -
474 - 'post_author' => $postAuthor,
475 - 'comment_status' => 'closed',
476 - );
477 -
478 - $coreValues['post_type'] = $this->wp_type;
479 - if( ! array_key_exists('post_status', $coreValues) ){
480 - $coreValues['post_status'] = 'publish';
481 - }
482 -
483 - $coreValues += $default;
484 -
485 - global $wpdb;
486 -
487 - $tableName = $wpdb->prefix . 'posts';
488 - $sqlValues = $this->sqlValues( $coreValues );
489 - $sql = 'INSERT INTO ' . $tableName . ' ' . $sqlValues;
490 -
491 - $res = $wpdb->query( $sql );
492 -
493 - if( is_wp_error($res) ){
494 - $error = '__Database Error__' . ': ' . $res->get_error_message();
495 - throw new Exception( $error );
496 - }
497 -
498 - $id = $wpdb->insert_id;
499 - $ret['id'] = $id;
500 -
501 - // insert meta
502 - if( ! $metaValues ){
503 - return $ret;
504 - }
505 -
506 - $arrayOfMeta = array();
507 - foreach( $metaValues as $k => $v ){
508 - $arrayOfMeta[] = array(
509 - 'post_id' => $id,
510 - 'meta_key' => $k,
511 - 'meta_value' => $v
512 - );
513 - }
514 -
515 - $tableName = $wpdb->prefix . 'postmeta';
516 - $sqlValues = $this->sqlValues( $arrayOfMeta, true );
517 - $sql = 'INSERT INTO ' . $tableName . ' ' . $sqlValues;
518 -
519 - $res = $wpdb->query( $sql );
520 -
521 - if( is_wp_error($res) ){
522 - $error = '__Database Error__' . ': ' . $res->get_error_message();
523 - throw new Exception( $error );
524 - }
525 -
526 - return $ret;
527 - }
528 -
529 -/*
530 -wp_insert_post then directly meta
531 -*/
532 - public function createSemiDirect( $values )
533 - {
534 - $ret = $values;
535 -
536 - list( $coreValues, $metaValues ) = $this->convert_to_wp( $values );
537 -
538 - $coreValues['post_type'] = $this->wp_type;
539 - if( ! array_key_exists('post_status', $coreValues) ){
540 - $coreValues['post_status'] = 'publish';
541 - }
542 -
543 - $res = wp_insert_post( $coreValues, true );
544 -
545 - if( is_wp_error($res) ){
546 - $error = '__Database Error__' . ': ' . $res->get_error_message();
547 - throw new Exception( $error );
548 - }
549 -
550 - $id = $res;
551 -
552 - $ret['id'] = $id;
553 -
554 - // insert meta
555 - if( ! $metaValues ){
556 - return $ret;
557 - }
558 -
559 - $arrayOfMeta = array();
560 - foreach( $metaValues as $k => $v ){
561 - $arrayOfMeta[] = array(
562 - 'post_id' => $id,
563 - 'meta_key' => $k,
564 - 'meta_value' => $v
565 - );
566 - }
567 -
568 - global $wpdb;
569 -
570 - $tableName = $wpdb->prefix . 'postmeta';
571 - $sqlValues = $this->sqlValues( $arrayOfMeta, true );
572 - $sql = 'INSERT INTO ' . $tableName . ' ' . $sqlValues;
573 -
574 - $res = $wpdb->query( $sql );
575 -
576 - if( is_wp_error($res) ){
577 - $error = '__Database Error__' . ': ' . $res->get_error_message();
578 - throw new Exception( $error );
579 - }
580 -
581 - return $ret;
582 - }
583 -
584 406 public function create( $values )
585 407 {
586 - $ret = $this->createSemiDirect( $values );
587 - return $ret;
588 -
589 408 $return = $values;
590 409
591 410 list( $core_values, $meta_values ) = $this->convert_to_wp( $values );
592 411
@@ -614,13 +433,8 @@
614 433
615 434 // UPDATE
616 435 public function update( $id, $values )
617 436 {
618 -/* disable Aruba high speed cache plugin */
619 -if( function_exists('ahsc_set_transient') ){
620 - ahsc_set_transient( 'ahsc_is_purged', time(), MINUTE_IN_SECONDS );
621 -}
622 -
623 437 $return = TRUE;
624 438
625 439 if( ! $id ){
626 440 return;