Example #1
0
function Streams_after_Q_image_save($params)
{
    $user = Users::loggedInUser(true);
    $path = $subpath = $data = $save = null;
    extract($params, EXTR_OVERWRITE);
    if (isset(Users::$cache['iconUrlWasChanged']) and Users::$cache['iconUrlWasChanged'] === false) {
        // the logged-in user's icon was changed without the url changing
        $stream = Streams::fetchOne($user->id, $user->id, "Streams/user/icon");
    } else {
        if (!empty(Streams::$cache['canWriteToStream'])) {
            // some stream's icon was being changed
            $stream = Streams::$cache['canWriteToStream'];
        }
    }
    if (empty($stream)) {
        return;
    }
    $url = $data[''];
    $stream->icon = Q_Valid::url($url) ? $url : Q_Request::baseUrl() . '/' . $url;
    $sizes = array();
    foreach ($save as $k => $v) {
        $sizes[] = "{$k}";
    }
    sort($sizes);
    $stream->setAttribute('sizes', $sizes);
    if (empty(Streams::$beingSavedQuery)) {
        $stream->changed($user->id);
    } else {
        $stream->save();
    }
}
Example #2
0
function Streams_after_Q_file_save($params)
{
    $user = Users::loggedInUser(true);
    $path = $subpath = $name = $writePath = $data = $tailUrl = null;
    extract($params, EXTR_OVERWRITE);
    if (!empty(Streams::$cache['canWriteToStream'])) {
        // some stream's associated file was being changed
        $stream = Streams::$cache['canWriteToStream'];
    }
    if (empty($stream)) {
        return;
    }
    $filesize = filesize($writePath . DS . $name);
    $url = $tailUrl;
    $url = Q_Valid::url($url) ? $url : Q_Request::baseUrl() . '/' . $url;
    $prevUrl = $stream->getAttribute('file.url');
    $stream->setAttribute('file.url', $url);
    $stream->setAttribute('file.size', $filesize);
    // set the title and icon every time a new file is uploaded
    $stream->title = $name;
    $parts = explode('.', $name);
    $urlPrefix = Q_Request::baseUrl() . '/plugins/Streams/img/icons/files';
    $dirname = STREAMS_PLUGIN_FILES_DIR . DS . 'Streams' . DS . 'icons' . DS . 'files';
    $extension = end($parts);
    $stream->icon = file_exists($dirname . DS . $extension) ? "{$urlPrefix}/{$extension}" : "{$urlPrefix}/_blank";
    if (empty(Streams::$beingSavedQuery)) {
        $stream->changed($user->id);
    } else {
        $stream->save();
    }
}
Example #3
0
function Streams_after_Q_file_save($params)
{
    $path = $subpath = $name = $writePath = $data = $tailUrl = $size = $audio = null;
    extract($params, EXTR_OVERWRITE);
    if (!empty(Streams::$cache['canWriteToStream'])) {
        // some stream's associated file was being changed
        $stream = Streams::$cache['canWriteToStream'];
    }
    if (empty($stream)) {
        return;
    }
    $url = Q_Valid::url($tailUrl) ? $tailUrl : '{{baseUrl}}/' . $tailUrl;
    $stream->setAttribute('Q.file.url', $url);
    $stream->setAttribute('Q.file.size', $size);
    if ($audio) {
        include_once Q_CLASSES_DIR . DS . 'Audio' . DS . 'getid3' . DS . 'getid3.php';
        $getID3 = new getID3();
        $meta = $getID3->analyze($writePath . $name);
        $bitrate = $meta['audio']['bitrate'];
        $bits = $size * 8;
        $duration = $bits / $bitrate;
        $stream->setAttribute('Q.audio.bitrate', $bitrate);
        $stream->setAttribute('Q.audio.duration', $duration);
    }
    if (Streams_Stream::getConfigField($stream->type, 'updateTitle', false)) {
        // set the title every time a new file is uploaded
        $stream->title = $name;
    }
    if (Streams_Stream::getConfigField($stream->type, 'updateIcon', false)) {
        // set the icon every time a new file is uploaded
        $parts = explode('.', $name);
        $urlPrefix = Q_Request::baseUrl() . '/plugins/Streams/img/icons/files';
        $dirname = STREAMS_PLUGIN_FILES_DIR . DS . 'Streams' . DS . 'icons' . DS . 'files';
        $extension = end($parts);
        $stream->icon = file_exists($dirname . DS . $extension) ? "{$urlPrefix}/{$extension}" : "{$urlPrefix}/_blank";
    }
    if (empty(Streams::$beingSavedQuery)) {
        $stream->changed();
    } else {
        $stream->save();
    }
}
Example #4
0
 /**
  * Get the url of a user's icon
  * @param {string} [$icon] The contents of a user row's icon field
  * @param {string} [$basename=""] The last part after the slash, such as "50.png"
  * @return {string} The stream's icon url
  */
 static function iconUrl($icon, $basename = null)
 {
     if (empty($icon)) {
         return null;
     }
     $url = Q::interpolate($icon, array('baseUrl' => Q_Request::baseUrl()));
     $url = Q_Valid::url($url) ? $url : "plugins/Users/img/icons/{$url}";
     if ($basename) {
         $url .= "/{$basename}";
     }
     return Q_Html::themedUrl($url);
 }
Example #5
0
 /**
  * Returns what the local filename of a local URL would typically be without any routing.
  * If not found under docroot, also checks various aliases.
  * @method filenamefromUrl
  * @static
  * @param {string} $url The url to translate, whether local or an absolute url beginning with the base URL
  * @return {string} The complete filename of the file or directory.
  *  It may not point to an actual file or directory, so use file_exists() or realpath()
  */
 static function filenamefromUrl($url)
 {
     if (Q_Valid::url($url)) {
         // This is an absolute URL. Get only the part after the base URL
         // Run it through proxies first
         $url = self::proxyDestination($url);
         $local_url = Q_Request::tail($url);
         if (!isset($local_url)) {
             return null;
         }
     } else {
         $local_url = $url;
     }
     $parts = explode('?', $local_url);
     $local_url = $parts[0];
     if ($local_url == '' || $local_url[0] != '/') {
         $local_url = '/' . $local_url;
     }
     // Try various aliases first
     $aliases = Q_Config::get('Q', 'aliases', array());
     foreach ($aliases as $alias => $path) {
         $alias_len = strlen($alias);
         if (substr($local_url, 0, $alias_len) == $alias) {
             return $path . substr($local_url, $alias_len);
         }
     }
     // Otherwise, we should use the document root.
     $docroot_dir = self::documentRoot();
     return $docroot_dir . $local_url;
 }
Example #6
0
 /**
  * Get the url of the stream's icon
  * @param {string} [$basename=""] The last part after the slash, such as "50.png"
  * @return {string} The stream's icon url
  */
 function iconUrl($basename = null)
 {
     if (empty($this->icon)) {
         return null;
     }
     $url = Q::interpolate($this->icon, array('baseUrl' => Q_Request::baseUrl()));
     $url = Q_Valid::url($url) ? $url : "plugins/Streams/img/icons/{$url}";
     if ($basename) {
         if (strpos($basename, '.') === false) {
             $basename = "{$basename}.png";
         }
         $url .= "/{$basename}";
     }
     return Q_Html::themedUrl($url);
 }
Example #7
0
 /**
  * Returns a <style> tag with the content of all the stylesheets included inline
  * @method stylesheetsInline
  * @static
  * @param {array} [$styles=array()] If not empty, this associative array contains styles which will be
  * included at the end of the generated <style> tag.
  * @param {string} [$slotName=null] If provided, returns only the stylesheets added while filling this slot.
  * @return {string} the style tags and their contents inline
  */
 static function stylesheetsInline($styles = array(), $slotName = null)
 {
     if (empty(self::$stylesheets)) {
         return '';
     }
     $sheets = self::stylesheetsArray($slotName, false);
     $sheets_for_slots = array();
     if (!empty($sheets)) {
         foreach ($sheets as $stylesheet) {
             $href = '';
             $media = 'screen, print';
             $type = 'text/css';
             extract($stylesheet, EXTR_IF_EXISTS);
             $ob = new Q_OutputBuffer();
             if (Q_Valid::url($href)) {
                 try {
                     include $href;
                 } catch (Exception $e) {
                 }
             } else {
                 list($href, $filename) = Q_Html::themedUrlAndFilename($href);
                 try {
                     Q::includeFile($filename);
                 } catch (Exception $e) {
                 }
             }
             $sheets_for_slots[$stylesheet['slot']][] = "\n/* Included inline from {$href} */\n" . $ob->getClean();
         }
     }
     $parts = array();
     foreach ($sheets_for_slots as $slot => $texts) {
         $parts[] = Q_Html::tag('style', array('data-slot' => $slot), implode("\n\n", $texts));
     }
     return implode("", $parts);
 }
Example #8
0
 /**
  * Gets the url and filename of a themed file
  * @method themedUrlAndFilename
  * @static
  * @param {string} $filePath  Basically the subpath of the file underneath the web or theme directory
  * @param {boolean} [$ignoreEnvironment=false] If true, doesn't apply environment transformations
  * @return {array} A two-element array containing the url and filename
  */
 static function themedUrlAndFilename($filePath, $ignoreEnvironment = false)
 {
     /**
      * @event Q/themedUrlAndFilename {before}
      * @param {string} file_path
      * @return {array}
      */
     $result = Q::event('Q/themedUrlAndFilename', compact('file_path'), 'before');
     if ($result) {
         return $result;
     }
     if (!$ignoreEnvironment and $environment = Q_Config::get('Q', 'environment', false)) {
         if ($info = Q_Config::get('Q', 'environments', $environment, false)) {
             if (!empty($info['files'][$filePath])) {
                 $filePath = $info['files'][$filePath];
             }
         }
     }
     $filename = false;
     if (Q_Valid::url($filePath)) {
         $url = $filePath;
     } else {
         $theme = Q_Uri::url(self::themeUrl());
         $themes = self::$themes;
         $c = count($themes);
         if ($c > 1) {
             // At least two theme URLs have been loaded
             // Do the cascade
             for ($i = $c - 1; $i >= 0; --$i) {
                 try {
                     $filename = Q_Uri::filenameFromUrl($themes[$i] . '/' . $filePath);
                 } catch (Exception $e) {
                     continue;
                 }
                 if ($filename and file_exists($filename)) {
                     $theme = $themes[$i];
                     break;
                 }
             }
         }
         $url = $theme . '/' . $filePath;
     }
     if (empty($filename)) {
         try {
             $filename = Q_Uri::filenameFromUrl($url);
         } catch (Exception $e) {
             $filename = null;
         }
     }
     $url = Q_Uri::cachedUrl($url);
     return array($url, $filename);
 }
Example #9
0
 /**
  * Get the url of a user's icon
  * @param {string} [$icon] The contents of a user row's icon field
  * @param {string} [$basename=""] The last part after the slash, such as "50.png"
  * @return {string} The stream's icon url
  */
 static function iconUrl($icon, $basename = null)
 {
     if (empty($icon)) {
         return null;
     }
     $url = Q_Valid::url($icon) ? $icon : "plugins/Users/img/icons/{$icon}";
     if ($basename) {
         $url .= "/{$basename}";
     }
     return Q_Html::themedUrl($url);
 }
Example #10
0
 /**
  * Get the url of the stream's icon
  * @param {string} [$basename=""] The last part after the slash, such as "50.png"
  * @return {string} The stream's icon url
  */
 function iconUrl($basename = null)
 {
     if (empty($this->icon)) {
         return null;
     }
     $url = Q_Valid::url($this->icon) ? $this->icon : "plugins/Streams/img/icons/{$this->icon}";
     if ($basename) {
         if (strpos($basename, '.') === false) {
             $basename = "{$basename}.png";
         }
         $url .= "/{$basename}";
     }
     return Q_Html::themedUrl($url);
 }