/**
  * Callback to delete the term meta when when a term is deleted.
  *
  * @access private
  * @since  8.2
  * @static
  *
  * @param int    $term          Term ID.
  * @param int    $tt_id         Term taxonomy ID.
  * @param string $taxonomy      Taxonomy slug.
  * @param mixed  $deleted_term  Copy of the already-deleted term, in the form specified
  *                              by the parent function. WP_Error otherwise.
  */
 public static function deleteTermMeta($term, $tt_id, $taxonomy, $deleted_term)
 {
     if (!is_wp_error($deleted_term)) {
         $meta = cnMeta::get('term', $term);
         if (!empty($meta)) {
             foreach ($meta as $key => $value) {
                 cnMeta::delete('term', $term, $key);
             }
         }
     }
 }
 /**
  * Return the `meta_key` of a term
  *
  * @access public
  * @since  8.5.2
  *
  * @param int $term_id
  *
  * @return array|bool|string
  */
 public function get($term_id = 0)
 {
     return cnMeta::get('term', $term_id, $this->meta_key, TRUE);
 }
 /**
  * Add, update or delete the meta of the specified entry ID.
  *
  * @access public
  * @since 0.8
  * @param  string $action The action to be performed.
  * @param  int    $id     The entry ID.
  * @param  array  $meta   [optional] An array of meta data the action is to be performed on.
  *
  * @return array          The meta IDs of the meta data the action was performed on.
  */
 public static function meta($action, $id, $meta = array())
 {
     $metaIDs = array();
     switch ($action) {
         case 'add':
             foreach ($meta as $row) {
                 $metaIDs[] = cnMeta::add('entry', $id, $row['key'], $row['value']);
             }
             break;
         case 'update':
             foreach ($meta as $metaID => $row) {
                 cnMeta::update('entry', $id, $row['key'], $row['value']);
                 $metaIDs[] = $metaID;
             }
             break;
         case 'delete':
             if (empty($meta)) {
                 $meta = cnMeta::get('entry', $id);
             }
             if ($meta) {
                 foreach ($meta as $key => $value) {
                     cnMeta::delete('entry', $id, $key);
                     $metaIDs[] = $key;
                 }
             }
             break;
     }
     return $metaIDs;
 }
 /**
  * Write the CSV rows for the current step.
  *
  * @access public
  * @since  8.5.1
  */
 public function writeRows()
 {
     $results = $this->getData();
     $rows = '';
     if (!empty($results)) {
         // Go through each entry...
         foreach ($results as $entry) {
             $fieldCount = count($this->fields);
             $row = '';
             // ...and go through each cell the user wants to export, and match it with the cell in the entry...
             for ($i = 0; $i < $fieldCount; $i++) {
                 // ...then find out if it's a breakout cell and process it properly...
                 switch ($this->fields[$i]['type']) {
                     case 1:
                         // Export a standard breakout; just list them all in the order requested...
                         $row .= $this->exportBreakoutCell($this->fields[$i], $entry->id);
                         break;
                     case 2:
                         // Process category table and list all categories in a single cell...
                         $terms = array();
                         $results = $this->getTerms($entry->id, 'category');
                         foreach ($results as $term) {
                             $terms[] = $term->name;
                         }
                         $row .= $this->escapeAndQuote(implode(',', $terms)) . ',';
                         break;
                     case 3:
                         $count = $this->getTermCount('category');
                         $terms = array();
                         // Process the category table by breaking them out in separate cells,
                         // Prepare an empty frame of the category cells...
                         for ($j = 0; $j < $count + 1; $j++) {
                             // Make an array filled with empty cells
                             $terms[$j] = '"",';
                         }
                         // Now start filling in the empty cells with data...
                         $row = $this->getTerms($entry->id, 'category');
                         $j = 0;
                         foreach ($row as $result) {
                             $terms[$j] = $this->escapeAndQuote($result->name) . ',';
                             $j++;
                         }
                         $row .= implode('', $terms);
                         break;
                     case 4:
                         // Export breakout data from the serialized option cell.
                         $row .= $this->exportBreakoutOptionsCell($this->fields[$i], $entry);
                         break;
                     case 5:
                         $data = '';
                         $meta = cnMeta::get('entry', $entry->id, $this->fields[$i]['field'], TRUE);
                         if (!empty($meta)) {
                             $data = cnFormatting::maybeJSONencode($meta);
                         }
                         $row .= $this->escapeAndQuote($data) . ',';
                         break;
                     case 6:
                         $terms = array();
                         $parent = $this->fields[$i]['child_of'];
                         $results = $this->getTerms($entry->id, 'category');
                         foreach ($results as $term) {
                             $terms[] = $parent . ':' . $term->term_id;
                             if (cnTerm::isAncestorOf($parent, $term->term_id, 'category')) {
                                 $terms[] = $term->name;
                             }
                         }
                         $row .= $this->escapeAndQuote(implode(',', $terms)) . ',';
                         break;
                     default:
                         // If no breakout type is defined, only display the cell data...
                         $row .= $this->escapeAndQuote($entry->{$this->fields[$i]['field']}) . ',';
                         break;
                 }
             }
             // Trim the trailing comma and space, then add newline.
             $rows .= rtrim($row, ',') . "\r\n";
         }
         // Now write the data...
         $this->write($rows);
         return $rows;
     }
     return FALSE;
 }
 /**
  * Returns the entry meta data.
  *
  * @access public
  * @since  unknown
  *
  * @uses   wp_parse_args()
  * @uses   cnMeta::get()
  *
  * @param array $atts {
  *     Optional. An array of arguments.
  *
  * @type string $key       Metadata key. If not specified, retrieve all metadata for the specified object.
  * @type bool   $single    Default is FALSE. If TRUE, return only the first value of the specified meta_key.
  *                         This parameter has no effect if $key is not specified.
  * }
  *
  * @return mixed array|bool|string Array of the entry meta data.
  *                                 String if $single is set to TRUE.
  *                                 FALSE on failure.
  */
 public function getMeta($atts = array())
 {
     $defaults = array('key' => '', 'single' => FALSE);
     $atts = wp_parse_args($atts, $defaults);
     return cnMeta::get('entry', $this->getId(), $atts['key'], $atts['single']);
 }
Example #6
0
 /**
  * Load data from connections for the doubles team.
  */
 protected function load()
 {
     if ($this->cnData === null) {
         global $connections;
         $cnRetrieve = $connections->retrieve;
         $ret = $cnRetrieve->entries(array('family_name' => $this->familyName, 'allow_public_override' => true, 'private_override' => true));
         if (count($ret) == 1) {
             $this->cnData = $ret[0];
             $this->cnMeta = array();
             $allMeta = cnMeta::get('entry', $this->cnData->id);
             if (is_array($allMeta)) {
                 foreach ($allMeta as $key => $values) {
                     $this->cnMeta[$key] = $values[0];
                 }
             }
         } else {
             $this->cnData = new StdClass();
             $this->cnMeta = array();
         }
     }
 }