/**
  * 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');
             }
         }
     }
 }
 /**
  * Echo a cached fragment if found.
  *
  * @access public
  * @since  8.1
  * @uses   cnCache::get()
  *
  * @return bool
  */
 public function get()
 {
     $fragment = cnCache::get($this->key, 'transient', $this->group);
     if ($fragment !== FALSE) {
         echo $fragment;
         return TRUE;
     } else {
         ob_start();
         return FALSE;
     }
 }
 /**
  * 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;
     }
 }
Exemple #4
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;
 }
    /**
     * 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;
    }