/**
  * AJAX callback to revoke the secret URL for the system info.
  *
  * @access private
  * @since  8.3
  * @static
  */
 public static function revokeSystemInfoURL()
 {
     if (!check_ajax_referer('revoke_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'));
     }
     cnCache::clear('system_info_remote_token', 'option-cache');
     wp_send_json_success(__('Secret URL has been revoked.', 'connections'));
 }
Beispiel #2
0
 /**
  * Clear a fragment cache object or object group.
  *
  * @access public
  * @since  8.1.6
  * @static
  * @param  mixed  $key   bool | string The cache key to clear. When set to TRUE, clear a fragment cache group.
  * @param  string $group The cache group to clear
  * @return void
  */
 public static function clear($key, $group = '')
 {
     if (TRUE !== $key) {
         cnCache::clear($key, 'transient', self::PREFIX);
     } else {
         $group_key = empty($group) ? self::PREFIX : $group;
         cnCache::clear(TRUE, 'transient', $group_key);
     }
 }
 /**
  * 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');
             }
         }
     }
 }
 /**
  * Download the CSV file.
  *
  * @access public
  * @since  8.5
  *
  * @uses   cnCSV_Export::headers()
  * @uses   cnCSV_Batch_Export::fileContents()
  */
 public function download()
 {
     // Clear the fields and types query caches.
     cnCache::clear(TRUE, 'transient', 'cn-csv');
     $this->headers();
     $file = $this->fileContents();
     @unlink($this->file);
     echo $file;
     die;
 }
 /**
  * The template_redirect action callback used to "remotely" display the system info.
  *
  * @access private
  * @since  8.3
  * @static
  *
  * @uses   cnCache::get()
  * @uses   cnSystem_Info::display()
  */
 public static function view()
 {
     if (!isset($_GET['cn-system-info']) || empty($_GET['cn-system-info'])) {
         return;
     }
     $queryValue = $_GET['cn-system-info'];
     $token = cnCache::get('system_info_remote_token', 'option-cache');
     if ($queryValue == $token) {
         /** WordPress Plugin Administration API */
         require_once ABSPATH . 'wp-admin/includes/plugin.php';
         require_once ABSPATH . 'wp-admin/includes/update.php';
         echo '<pre>';
         self::display();
         echo '</pre>';
         exit;
     } else {
         wp_redirect(home_url());
         exit;
     }
 }
Beispiel #6
0
    /**
     * Callback to display the remote URL for the system info.
     *
     * @access public
     * @since  8.3
     * @static
     *
     * @uses   home_url()
     * @uses   _e()
     * @uses   esc_url()
     * @uses   wp_create_nonce()
     */
    public static function systemInfoRemote()
    {
        $token = cnCache::get('system_info_remote_token', 'option-cache');
        $url = $token ? home_url() . '/?cn-system-info=' . $token : '';
        ?>

		<div class="postbox">
			<h3><span><?php 
        _e('Remote Viewing', 'connections');
        ?>
</span></h3>

			<div class="inside">

				<div id="cn-remote-response"></div>

				<p>
					<?php 
        _e('Create a secret URL that support can use to remotely view your system information. The secret URL will expire after 72 hours and can be revoked at any time.', 'connections');
        ?>
				</p>

				<p>
					<input type="text" readonly="readonly" id="system-info-url" class="regular-text"
					       onclick="this.focus();this.select()" value="<?php 
        echo esc_url($url ? $url : '');
        ?>
"
					       title="<?php 
        _e('To copy the URL, click then press Ctrl + C (PC) or Cmd + C (Mac).', 'connections');
        ?>
"/>&nbsp;&nbsp;<a class="button-secondary" href="<?php 
        echo esc_url($url ? $url : '#');
        ?>
" target="_blank"
					                              id="system-info-url-text-link" style="display: <?php 
        echo $url ? 'display-inline' : 'none';
        ?>
"><?php 
        _e('Test', 'connections');
        ?>
</a>
				</p>

				<p class="submit">
					<input type="submit" onClick="return false;" class="button-secondary" name="generate-url"
					       value="<?php 
        _e('Generate URL', 'connections');
        ?>
"
					       data-nonce="<?php 
        echo wp_create_nonce('generate_remote_system_info_url');
        ?>
"/>
					<input type="submit" onClick="return false;" class="button-secondary" name="revoke-url"
					       value="<?php 
        _e('Revoke URL', 'connections');
        ?>
"
					       data-nonce="<?php 
        echo wp_create_nonce('revoke_remote_system_info_url');
        ?>
"/>
				</p>

			</div><!-- .inside -->
		</div><!-- .postbox -->

		<?php 
    }
 /**
  * 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;
 }
 /**
  * Purge entry related caches when an entry is added/edited.
  *
  * @access public
  * @since  8.1
  *
  * @uses   cnCache::clear()
  *
  * @return void
  */
 public static function clearCache()
 {
     cnCache::clear(TRUE, 'transient', 'cn_category');
     cnCache::clear(TRUE, 'transient', 'cn_relative');
     /**
      * Action fired after entry related caches are cleared.
      *
      * The `cn_process_cache-entry` action is deprecated since 8.2.5 and should not be used.
      *
      * @since 8.2.5
      */
     do_action('cn_clean_entry_cache');
     do_action('cn_process_cache-entry');
 }
 /**
  * Will remove all of the term ids from the cache.
  *
  * NOTE: This is the Connections equivalent of @see clean_term_cache() in WordPress core ../wp-includes/taxonomy.php
  *
  * @access public
  * @since  8.1.6
  * @static
  *
  * @global $wpdb
  *
  * @uses   wpdb::get_results()
  * @uses   wp_cache_delete()
  * @uses   delete_option()
  * @uses   cnTerm::get_hierarchy()
  * @uses   do_action()
  * @uses   wp_cache_set()
  *
  * @param int|array $ids            Single or list of Term IDs
  * @param string    $taxonomy       Can be empty and will assume tt_ids, else will use for context.
  * @param bool      $clean_taxonomy Whether to clean taxonomy wide caches (true), or just individual term object caches (false). Default is true.
  */
 public static function cleanCache($ids, $taxonomy = '', $clean_taxonomy = TRUE)
 {
     /** @var $wpdb wpdb */
     global $wpdb;
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     $taxonomies = array();
     // If no taxonomy, assume tt_ids.
     if (empty($taxonomy)) {
         $tt_ids = array_map('intval', $ids);
         $tt_ids = implode(', ', $tt_ids);
         $terms = $wpdb->get_results("SELECT term_id, taxonomy FROM " . CN_TERM_TAXONOMY_TABLE . " WHERE term_taxonomy_id IN ({$tt_ids})");
         $ids = array();
         foreach ((array) $terms as $term) {
             $taxonomies[] = $term->taxonomy;
             $ids[] = $term->term_id;
             wp_cache_delete($term->term_id, 'cn_' . $term->taxonomy);
         }
         $taxonomies = array_unique($taxonomies);
     } else {
         $taxonomies = array($taxonomy);
         foreach ($taxonomies as $taxonomy) {
             foreach ($ids as $id) {
                 wp_cache_delete($id, 'cn_' . $taxonomy);
             }
         }
     }
     foreach ($taxonomies as $taxonomy) {
         if ($clean_taxonomy) {
             wp_cache_delete('all_ids', 'cn_' . $taxonomy);
             wp_cache_delete('get', 'cn_' . $taxonomy);
             delete_option("cn_{$taxonomy}_children");
             // Regenerate {$taxonomy}_children
             self::get_hierarchy($taxonomy);
         }
         /**
          * Fires once after each taxonomy's term cache has been cleaned.
          *
          * @since 8.1.6
          *
          * @param array  $ids      An array of term IDs.
          * @param string $taxonomy Taxonomy slug.
          */
         do_action('cn_clean_term_cache', $ids, $taxonomy);
     }
     wp_cache_set('last_changed', microtime(), 'cn_terms');
     // Clear any transients/cache fragments that were set.
     cnCache::clear(TRUE, 'transient', "cn_{$taxonomy}");
 }
    /**
     * 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;
    }