/** * AJAX callback to create a secret URL for the system info. * * @access private * @since 8.3 * @static */ public static function generateSystemInfoURL() { if (!check_ajax_referer('generate_remote_system_info_url', FALSE, FALSE)) { wp_send_json_error(__('Invalid AJAX action or nonce validation failed.', 'connections')); } if (!current_user_can('manage_options')) { wp_send_json_error(__('You do not have sufficient permissions to perform this action.', 'connections')); } /** @todo need to check the $token is not WP_Error. */ $token = cnString::random(32); $expires = apply_filters('cn_system_info_remote_token_expire', DAY_IN_SECONDS * 3); cnCache::set('system_info_remote_token', $token, $expires, 'option-cache'); $url = home_url() . '/?cn-system-info=' . $token; wp_send_json_success(array('url' => $url, 'message' => __('Secret URL has been created.', 'connections'))); }
/** * The callback ran in the async request to do the face detection. * * @access private * @since 1.0 * @static * @param array $atts The associative array that is passed to an instance of cnImage::get() when processing an immage. * @param string $source The image URL or absolute path. NOTE: The onl valid pathhs will be: WP_CONTENT/UPLOADS or STYLESHEETPATH * @param string $return What to return, @see cnImage::get() * * @return void */ public static function detect($atts, $source, $return) { if (!is_wp_error($info = cnImage::info($source))) { $name = $info['basename']; $cache = cnCache::get('face_detect', 'option-cache', 'cnfc'); $image = $cache != FALSE ? json_decode($cache, TRUE) : array(); if ($image == FALSE || (!isset($image[$name]) || $image[$name]['modified'] != $info['modified'])) { if (!class_exists('svay\\FaceDetector')) { include_once CNFD_PATH . 'vendor/facedetector/FaceDetector.php'; } $detect = new svay\FaceDetector(); $detect->faceDetect($info['path']); $coord = $detect->getFace(); if (!is_null($coord)) { $atts['crop_focus'] = array(($coord['x'] + $coord['w'] / 2) / $info[0], $coord['y'] / $info[1]); } $image[$name]['path'] = $info['path']; $image[$name]['modified'] = $info['modified']; $image[$name]['mime'] = $info['mime']; $image[$name]['width'] = $info[0]; $image[$name]['height'] = $info[1]; $image[$name]['face'] = $coord; $image[$name]['crop_focus'] = $atts['crop_focus']; if (!is_wp_error($result = cnImage::get($source, $atts))) { cnCache::set('face_detect', json_encode($image), YEAR_IN_SECONDS, 'option-cache', 'cnfc'); } } } }
/** * Callback to render the 'family' entry type part of the 'Name' metabox. * Called from self::name() * * @access private * @since 0.8 * * @param cnEntry $entry An instance of the cnEntry object. * @param array $atts The metabox attributes array set in self::register(). Passed from self::name(). * * @return void */ public static function family($entry, $atts) { // Grab an instance of the Connections object. $instance = Connections_Directory(); $html = ''; $id = $entry->getId(); $ckey = $entry->getId() ? 'relative_select_entry_' . $id : 'relative_select_user_' . $instance->currentUser->getID(); if (FALSE !== ($cache = cnCache::get($ckey, 'transient'))) { echo $cache; return; } // Retrieve all the entries of the "individual" entry type that the user is permitted to view and is approved. $individuals = cnRetrieve::individuals(); // Get the core entry relations. $options = $instance->options->getDefaultFamilyRelationValues(); $html .= '<div class="cn-metabox" id="cn-metabox-section-family">'; // --> Start template for Family <-- \\ $html .= '<textarea id="cn-relation-template" style="display: none">'; $html .= cnHTML::select(array('class' => 'family-member-name', 'id' => 'family_member[::FIELD::][entry_id]', 'default' => __('Select Entry', 'connections'), 'options' => $individuals, 'enhanced' => TRUE, 'return' => TRUE)); $html .= cnHTML::select(array('class' => 'family-member-relation', 'id' => 'family_member[::FIELD::][relation]', 'default' => __('Select Relation', 'connections'), 'options' => $options, 'enhanced' => TRUE, 'return' => TRUE)); $html .= '</textarea>'; // --> End template for Family <-- \\ $html .= '<label for="family_name">' . __('Family Name', 'connections') . ':</label>'; $html .= '<input type="text" name="family_name" value="' . $entry->getFamilyName() . '" />'; $html .= '<ul id="cn-relations">'; if ($relations = $entry->getFamilyMembers()) { foreach ($relations as $relationData) { $token = str_replace('-', '', cnUtility::getUUID()); if (array_key_exists($relationData['entry_id'], $individuals)) { $html .= '<li id="relation-row-' . $token . '" class="cn-relation"><i class="fa fa-sort"></i> '; $html .= cnHTML::select(array('class' => 'family-member-name', 'id' => 'family_member[' . $token . '][entry_id]', 'default' => __('Select Entry', 'connections'), 'options' => $individuals, 'enhanced' => TRUE, 'return' => TRUE), $relationData['entry_id']); $html .= cnHTML::select(array('class' => 'family-member-relation', 'id' => 'family_member[' . $token . '][relation]', 'default' => __('Select Relation', 'connections'), 'options' => $options, 'enhanced' => TRUE, 'return' => TRUE), $relationData['relation']); $html .= '<a href="#" class="cn-remove cn-button button cn-button-warning" data-type="relation" data-token="' . $token . '">' . __('Remove', 'connections') . '</a>'; $html .= '</li>'; } } } $html .= '</ul>'; $html .= '<p class="add"><a id="add-relation" class="button">' . __('Add Relation', 'connections') . '</a></p>'; $html .= '</div>'; cnCache::set($ckey, $html, YEAR_IN_SECONDS, 'transient'); echo $html; }
/** * Save fragment in the cache. * * @access public * @since 8.1 * @uses cnCache::set() * * @param null $ttl The number of seconds the fragment should live. Defaults to WEEK_IN_SECONDS. * * @return void */ public function save($ttl = NULL) { $ttl = is_null($ttl) ? $this->ttl : $ttl; cnCache::set($this->key, ob_get_flush(), $ttl, 'transient', $this->group); }
/** * Returns the largest number of terms associated to a single entry. * * @access private * @since 8.5.1 * * @param string $taxonomy The taxonomy to retrieve the count for. * * @return int */ private function getTermCount($taxonomy) { /** @var wpdb $wpdb */ global $wpdb; $result = cnCache::get('max-term-count', 'transient', 'cn-csv'); if (FALSE === $result) { $sql = $wpdb->prepare('SELECT COUNT(*) AS total FROM ' . CN_TERMS_TABLE . ' AS t INNER JOIN ' . CN_TERM_TAXONOMY_TABLE . ' AS tt ON t.term_id = tt.term_id INNER JOIN ' . CN_TERM_RELATIONSHIP_TABLE . ' AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = %s GROUP BY tr.entry_id ORDER BY COUNT(*) DESC LIMIT 1', $taxonomy); $result = $wpdb->get_results($sql); cnCache::set('max-term-count', $result, DAY_IN_SECONDS, 'transient', 'cn-csv'); } return $result[0]->total ? $result[0]->total : 0; }