/**
  * Set the URL to create a screenshot of.
  *
  * @access public
  * @since  8.2.5
  *
  * @param string $url
  */
 public function setURL($url)
 {
     // If the http protocol is not part of the url, add it.
     $this->url = cnURL::prefix($url);
 }
예제 #2
0
 /**
  * Get the template author's URL.
  *
  * @access public
  * @since  0.7.6
  *
  * @return string
  */
 public function getAuthorURL()
 {
     return cnURL::prefix($this->authorURL);
 }
 /**
  * Caches the links for use and preps for saving and updating.
  *
  * @todo Validate as valid web addresses.
  *
  * @access  public
  * @since   0.7.3
  *
  * @param   array $links {
  *     Optional. An array of arguments.
  *
  *     @type int    $id         The unique link ID as queried from the DB.
  *     @type mixed  $preferred  The array key of the link to be set as the preferred link.
  *                              Default: ''
  *     @type string $type       The link type.
  *                              Default: @todo Should have a default if one is not supplied.
  *                              Accepts: The array keys returned from @see cnOptions::getDefaultLinkValues()
  *     @type string $title      The link text (also used for the link title attribute).
  *                              Default: ''
  *     @type string $url        The link URL.
  *     @type string $target     The link target attribute.
  *                              Default: same
  *                              Accepts: new|same
  *     @type bool   $follow     Whether or not the link should be followed.
  *                              Default: nofollow
  *                              Accepts: dofollow | nofollow
  *     @type string $visibility The visibility status of the link.
  *                              Default: public
  *                              Accepts: public|private|unlisted
  *     @type mixed  $image      The array key of the link to be assigned to the entry image.
  *                              Default: ''
  *     @type mixed  $logo       The array key of the link to be assigned to the entry logo.
  *                              Default: ''
  * }
  *
  * @return void
  */
 public function setLinks($links)
 {
     $userPreferred = NULL;
     $validFields = array('id' => NULL, 'preferred' => NULL, 'type' => NULL, 'title' => NULL, 'url' => NULL, 'target' => NULL, 'follow' => NULL, 'visibility' => NULL);
     if (!empty($links)) {
         $order = 0;
         $preferred = '';
         $image = '';
         $logo = '';
         if (isset($links['preferred'])) {
             $preferred = $links['preferred'];
             unset($links['preferred']);
         }
         if (isset($links['image'])) {
             $image = $links['image'];
             unset($links['image']);
         }
         if (isset($links['logo'])) {
             $logo = $links['logo'];
             unset($links['logo']);
         }
         foreach ($links as $key => $link) {
             // First validate the supplied data.
             $link = cnSanitize::args($link, $validFields);
             // If the URL is empty, no need to save it.
             if (0 == strlen($link['url'])) {
                 unset($links[$key]);
                 continue;
             }
             // If the http protocol is not part of the url, add it.
             $links[$key]['url'] = cnURL::prefix($link['url']);
             // Sanitize the URL.
             $links[$key]['url'] = cnSanitize::field('url', $links[$key]['url'], 'db');
             // Store the order attribute as supplied in the addresses array.
             $links[$key]['order'] = $order;
             // Convert the do/nofollow string to an (int) so it is saved properly in the db
             $links[$key]['follow'] = 'dofollow' == $link['follow'] ? 1 : 0;
             $links[$key]['preferred'] = !empty($preferred) && $preferred == $key ? TRUE : FALSE;
             $links[$key]['image'] = !empty($image) && $image == $key ? TRUE : FALSE;
             $links[$key]['logo'] = !empty($logo) && $logo == $key ? TRUE : FALSE;
             /*
              * If the user set a preferred link, save the $key value.
              * This is going to be needed because if a link that the user
              * does not have permission to edit is set to preferred, that link
              * will have preference.
              */
             if ($links[$key]['preferred']) {
                 $userPreferred = $key;
             }
             if ($links[$key]['image']) {
                 $userImage = $key;
             }
             if ($links[$key]['logo']) {
                 $userLogo = $key;
             }
             $order++;
         }
     }
     /*
      * Before storing the data, add back into the array from the cache the networks
      * the user may not have had permission to edit so the cache stays current.
      */
     $cached = unserialize($this->links);
     if (!empty($cached)) {
         foreach ($cached as $link) {
             /*
              * // START -- Compatibility for previous versions.
              */
             if (!isset($link['visibility']) || empty($link['visibility'])) {
                 $link['visibility'] = 'public';
             }
             /*
              * // END -- Compatibility for previous versions.
              */
             /** This filter is documented in ../includes/entry/class.entry-data.php */
             $link = apply_filters('cn_link-pre_setup', $link);
             // Add back to the data array the networks that user does not have permission to view and edit.
             if (!cnValidate::userPermitted($link['visibility'])) {
                 $links[] = $link;
                 // If the network is preferred, it takes precedence, so the user's choice is overridden.
                 if (isset($userPreferred) && !empty($preferred) && $link['preferred']) {
                     $links[$userPreferred]['preferred'] = FALSE;
                     // Throw the user a message so they know why their choice was overridden.
                     cnMessage::set('error', 'entry_preferred_overridden_link');
                 }
                 // If the link is already assigned to an image, it takes precedence, so the user's choice is overridden.
                 if (isset($userImage) && !empty($image) && $link['image']) {
                     $links[$userImage]['image'] = FALSE;
                     // @todo Create error message for the user.
                 }
                 // If the link is already assigned to an image, it takes precedence, so the user's choice is overridden.
                 if (isset($userLogo) && !empty($logo) && $link['logo']) {
                     $links[$userLogo]['logo'] = FALSE;
                     // @todo Create error message for the user.
                 }
             }
         }
     }
     $this->links = !empty($links) ? serialize($links) : '';
     //print_r($links); die;
 }