Ejemplo n.º 1
0
 /**
  * Initiates class
  *
  * @access public
  * @return void
  */
 function TreasuryBase()
 {
     if (get_class($this) == 'treasurygallery') {
         parent::__construct();
     } else {
         parent::__construct();
     }
 }
Ejemplo n.º 2
0
/**
 * Store the data in the database - this function will hand off the file to the 
 * correct plugin and use that to store the data. The import plugin will not be 
 * called again by this file.
 * 
 * @param array $pStoreRow File data needed to store details in the database - sanitised and generated in the verify function
 * @access public
 * @return TRUE on success, FALSE on failure - $pStoreRow['errors'] will contain reason
 */
function mime_import_store(&$pStoreRow)
{
    global $gLibertySystem;
    $libertyMime = new LibertyMime();
    // let the correct plugin do the rest - this plugin should not be called again for this file
    $guid = $gLibertySystem->lookupMimeHandler($pStoreRow['upload']);
    if ($libertyMime->pluginStore($pStoreRow, $guid, @BitBase::verifyId($upload['attachment_id']))) {
        return TRUE;
    } else {
        $pStoreRow['errors'] = $libertyMime->mErrors;
    }
}
Ejemplo n.º 3
0
/**
 * mime_flash_store_preferences 
 * 
 * @param array $pFileHash Flash information
 * @access public
 * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
 */
function mime_flash_store_preferences(&$pFileHash)
{
    $ret = FALSE;
    if (@BitBase::verifyId($pFileHash['attachment_id'])) {
        list($pFileHash['preferences']['width'], $pFileHash['preferences']['height'], $type, $attr) = getimagesize(STORAGE_PKG_PATH . $pFileHash['upload']['dest_branch'] . $pFileHash['upload']['name']);
        // store width of video
        if (!empty($pFileHash['preferences']['width'])) {
            LibertyMime::storeAttachmentPreference($pFileHash['attachment_id'], 'width', $pFileHash['preferences']['width']);
        }
        // store height of video
        if (!empty($pFileHash['preferences']['height'])) {
            LibertyMime::storeAttachmentPreference($pFileHash['attachment_id'], 'height', $pFileHash['preferences']['height']);
        }
        $ret = TRUE;
    }
    return $ret;
}
Ejemplo n.º 4
0
 function load()
 {
     if (!empty($this->mOverlayId) || !empty($this->mContentId)) {
         $overlayKey = $this->mOverlayType . '_id';
         $lookupColumn = !empty($this->mOverlayId) ? $overlayKey : 'content_id';
         $bindVars = array();
         $selectSql = '';
         $joinSql = '';
         $whereSql = '';
         array_push($bindVars, $lookupId = @BitBase::verifyId($this->mOverlayId) ? $this->mOverlayId : $this->mContentId);
         $this->getServicesSql('content_load_sql_function', $selectSql, $joinSql, $whereSql, $bindVars);
         $query = "select ot.*, lc.*, ufm.`favorite_content_id`, ufm.`map_position`,\n\t\t\t\t\t  uue.`login` AS modifier_user, uue.`real_name` AS modifier_real_name,\n\t\t\t\t\t  uuc.`login` AS creator_user, uuc.`real_name` AS creator_real_name,\n\t\t\t\t\t  lf.storage_path AS `image_attachment_path` {$selectSql}\n\t\t\t\t\t  FROM `" . BIT_DB_PREFIX . $this->mOverlayTable . "` ot\n\t\t\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON (lc.`content_id` = ot.`content_id`) {$joinSql}\n\t\t\t\t\t\tLEFT JOIN `" . BIT_DB_PREFIX . "users_users` uue ON (uue.`user_id` = lc.`modifier_user_id`)\n\t\t\t\t\t\tLEFT JOIN `" . BIT_DB_PREFIX . "users_users` uuc ON (uuc.`user_id` = lc.`user_id`)\n\t\t\t\t\t\tLEFT JOIN `" . BIT_DB_PREFIX . "users_favorites_map` ufm ON ( lc.`content_id`=ufm.`favorite_content_id` )\n\t\t\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_attachments` la ON( la.`content_id` = lc.`content_id` AND la.`is_primary` = 'y' )\n\t\t\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_files` lf ON( lf.`file_id` = la.`foreign_id` )\n\t\t\t\t\t  WHERE ot.`{$lookupColumn}`=? {$whereSql}";
         if ($this->mInfo = $this->mDb->getRow($query, $bindVars)) {
             $this->mInfo['thumbnail_url'] = liberty_fetch_thumbnails(array("storage_path" => $this->mInfo['image_attachment_path']));
             $this->mOverlayId = $this->mInfo[$overlayKey];
             $this->mContentId = $this->mInfo['content_id'];
             $this->mInfo['raw'] = $this->mInfo['data'];
             $parseHash['data'] = $this->mInfo['data'];
             $this->prepParseFilters($parseHash);
             // @TODO this has gone through many changes and this looks a bit chaotic - might be able to simplify this
             $this->mInfo['xml_parsed_data'] = $this->parseData($parseHash, $this->mInfo['format_guid']);
             $this->mInfo['parsed_data'] = $this->parseData($parseHash, $this->mInfo['format_guid']);
             $this->mInfo['clean_data'] = $this->mInfo['parsed_data'];
             $this->mInfo['parsed_data'] = addslashes($this->mInfo['parsed_data']);
             $this->mInfo['xml_data'] = str_replace("\n", "
", $this->mInfo['data']);
             $this->mInfo['data'] = addslashes($this->mInfo['data']);
             $this->mInfo['data'] = str_replace("\n", "\\n", $this->mInfo['data']);
             // to support html in labels
             $this->mInfo['parsed_label_data'] = $this->parseData($this->mInfo['label_data'], $this->mInfo['format_guid']);
             $comment = new LibertyComment();
             $this->mInfo['num_comments'] = $comment->getNumComments($this->mInfo['content_id']);
             LibertyMime::load();
         }
     }
     return count($this->mInfo);
 }
Ejemplo n.º 5
0
 function getAvailableContentStatuses($pUserMinimum = -100, $pUserMaximum = 100)
 {
     global $gBitSystem;
     if ($gBitSystem->isFeatureActive('events_moderation')) {
         return LibertyContent::getAvailableContentStatuses(-100, 0);
     }
     return parent::getAvailableContentStatuses();
 }
Ejemplo n.º 6
0
 /**
  * getContentStatus
  *
  * @access public
  * @return an array of content_status_id, content_status_names the current
  * user can use on this content.
  *
  * NOTE: pUserMinimum and pUserMaximum are currently NOT inclusive in parent funtion, so these are one beyond the limit we desire
  */
 function getAvailableContentStatuses($pUserMinimum = -6, $pUserMaximum = 51)
 {
     global $gBitUser;
     $ret = LibertyMime::getAvailableContentStatuses($pUserMinimum, $pUserMaximum);
     // this is a little ugly as we manually trim the list to just what we need for blog posts for regular users
     if (!$gBitUser->hasPermission('p_liberty_edit_all_status')) {
         if (array_key_exists(-1, $ret)) {
             unset($ret[-1]);
         }
         if (array_key_exists(50, $ret) && $ret[50] == "Available") {
             $ret[50] = "Public";
         }
     }
     return $ret;
 }
Ejemplo n.º 7
0
 /**
  * Work out the path to the image for this article
  * @param $pTopicId id of the article we need the image path for
  * @param $pBasePathOnly bool TRUE / FALSE - specify whether you want full path or just base path
  * @return path on success, FALSE on failure
  * @access public
  **/
 public function getTopicImageBaseUrl($pTopicId = NULL)
 {
     $ret = FALSE;
     if (!@BitBase::verifyId($pTopicId) && $this->isValid()) {
         $pTopicId = $this->mTopicId;
     }
     if (@BitBase::verifyId($pTopicId)) {
         $ret = LibertyMime::getStorageUrl('topics/' . $pTopicId);
     }
     return $ret;
 }
Ejemplo n.º 8
0
if (@(!BitBase::verifyId($_REQUEST['attachment_id'])) || !($attachment = LibertyMime::getAttachment($_REQUEST['attachment_id'], $_REQUEST))) {
    $gBitSystem->fatalError(tra("The Attachment ID given is not valid"));
}
// first we need to check the permissions of the content the attachment belongs to since they inherit them
if ($gContent = LibertyBase::getLibertyObject($attachment['content_id'])) {
    $gContent->verifyViewPermission();
    if (!empty($_REQUEST['plugin_submit'])) {
        // now that we have data for a plugin, we'll simply feed it back to the update function of that plugin
        $data = !empty($_REQUEST['plugin'][$attachment['attachment_id']][$attachment['attachment_plugin_guid']]) ? $_REQUEST['plugin'][$attachment['attachment_id']][$attachment['attachment_plugin_guid']] : array();
        if ($gContent->updateAttachmentParams($attachment['attachment_id'], $attachment['attachment_plugin_guid'], $data)) {
            $feedback['success'] = tra("The data was successfully updated.");
        } else {
            $feedback['error'] = $gContent->mErrors;
        }
        // reload the attachment
        $attachment = LibertyMime::getAttachment($_REQUEST['attachment_id']);
    }
    // attachment usage filter stuff is hardcoded for now - ugly as hell but we'll survive it as long as there's no demand for more of these.
    if ($gLibertySystem->isPluginActive('filterattachment')) {
        $gBitSmarty->assign('usage', attachment_filter_get_usage($attachment['attachment_id']));
    }
    if (empty($_REQUEST['size'])) {
        $_REQUEST['size'] = 'large';
    }
    $attachment['original'] = $gContent->isOwner($attachment) || $gBitSystem->isFeatureActive('liberty_original_image');
    $gBitSmarty->assign('attachment', $attachment);
    $gBitSmarty->assign('gContent', $gContent);
    $gBitSmarty->assign('feedback', $feedback);
    // what template are we going to use to display this attachment
    $gBitSmarty->assign('view_template', $gLibertySystem->getMimeTemplate('view', $attachment['attachment_plugin_guid']));
    $gBitSmarty->assign('edit_template', $gLibertySystem->getMimeTemplate('edit', $attachment['attachment_plugin_guid']));
Ejemplo n.º 9
0
 /**
  * This function removes an overlay
  **/
 function expunge()
 {
     $ret = FALSE;
     if ($this->isValid()) {
         $overlayKey = $this->mOverlayType . '_id';
         $this->mDb->StartTrans();
         // delete all references to the overlay from the overlay keychain
         $query = "DELETE FROM `" . BIT_DB_PREFIX . $this->mOverlayKeychainTable . "` WHERE `" . $overlayKey . "` =?";
         $result = $this->mDb->query($query, array($this->mOverlayId));
         // delete the overlay record
         $query = "DELETE FROM `" . BIT_DB_PREFIX . $this->mOverlayTable . "` WHERE `content_id` = ?";
         $result = $this->mDb->query($query, array($this->mContentId));
         // delete the overlay liberty content object
         if ($ret = LibertyMime::expunge()) {
             $this->mDb->CompleteTrans();
         } else {
             $this->mDb->RollbackTrans();
         }
     }
     return $ret;
 }
Ejemplo n.º 10
0
/**
 * Convert a stored video file to flashvideo
 *
 * @param array $pParamHash
 * @access public
 * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
 */
function mime_video_converter(&$pParamHash, $pOnlyGetParameters = FALSE)
{
    global $gBitSystem;
    // video conversion can take a while
    ini_set("max_execution_time", "1800");
    $ret = FALSE;
    if (@BitBase::verifyId($pParamHash['attachment_id'])) {
        // we might have some attachment preferences set if this is an update
        LibertyMime::expungeAttachmentPreferences($pParamHash['attachment_id']);
        // these are set in the liberty plugin admin screen
        $ffmpeg = trim($gBitSystem->getConfig('ffmpeg_path', shell_exec('which ffmpeg')));
        $width = trim($gBitSystem->getConfig('mime_video_width', 320));
        $begin = date('U');
        $log = $actionLog = array();
        if (!is_executable($ffmpeg)) {
            $log['time'] = date('Y-M-d - H:i:s O');
            $log['duration'] = 0;
            $log['message'] = 'ERROR: ffmpeg does not seem to be available on your system at: ' . $ffmpeg . ' Please set the path to ffmpeg in the liberty plugin administration screen.';
            $actionLog['log_message'] = "ERROR: ffmpeg does not seem to be available on your system at: '{$ffmpeg}' Please set the path to ffmpeg in the liberty plugin administration screen.";
        } else {
            // this is the codec we'll use - currently this might be: flv, h264, h264-2pass
            $codec = $gBitSystem->getConfig("mime_video_video_codec", "flv");
            $source = STORAGE_PKG_PATH . $pParamHash['upload']['dest_branch'] . $pParamHash['upload']['name'];
            $destPath = dirname($source);
            // set some default values if ffpeg-php isn't available or fails
            $default['aspect'] = 4 / 3;
            $default['video_width'] = $width;
            $default['video_height'] = round($width / 4 * 3);
            $default['size'] = "{$default['video_width']}x{$default['video_height']}";
            $default['offset'] = '00:00:10';
            if (extension_loaded('ffmpeg')) {
                // we silence these calls since they might spew errors
                $movie = @new ffmpeg_movie($source);
                $info = array('vcodec' => @$movie->getVideoCodec(), 'duration' => round(@$movie->getDuration()), 'width' => @$movie->getFrameWidth(), 'height' => @$movie->getFrameHeight(), 'video_bitrate' => @$movie->getVideoBitRate(), 'acodec' => @$movie->getAudioCodec(), 'audio_bitrate' => @$movie->getAudioBitRate(), 'audio_samplerate' => @$movie->getAudioSampleRate());
                // make sure audio sample rate is valid
                if (!empty($info['audio_samplerate']) && !in_array($info['audio_samplerate'], array(11025, 22050, 44100))) {
                    unset($info['audio_samplerate']);
                }
            } else {
                // alternative method using ffmpeg to fetch source dimensions
                $command = "{$ffmpeg} -i " . escapeshellarg($source) . ' 2>&1';
                exec($command, $output, $status);
                if (!preg_match('/Stream #(?:[0-9\\.]+)(?:.*)\\: Video: (?P<videocodec>.*) (?P<width>[0-9]*)x(?P<height>[0-9]*)/', implode('\\n', $output), $matches)) {
                    preg_match('/Could not find codec parameters \\(Video: (?P<videocodec>.*) (?P<width>[0-9]*)x(?P<height>[0-9]*)\\)/', implode('\\n', $output), $matches);
                }
                if (!empty($matches['width']) && !empty($matches['height'])) {
                    $info['width'] = $matches['width'];
                    $info['height'] = $matches['height'];
                }
            }
            // our player supports flv and h264 so we might as well use the default
            if (!$gBitSystem->isFeatureActive('mime_video_force_encode') && !empty($info) && ($info['vcodec'] == 'h264' && (empty($info['acodec']) || $info['acodec'] == 'mpeg4aac' || $info['acodec'] == 'aac') || $info['vcodec'] == 'flv' && (empty($info['acodec']) || $info['acodec'] == 'mp3'))) {
                // work out what the target filename is
                $extension = $info['vcodec'] == "flv" ? "flv" : "mp4";
                $dest_file = $destPath . "/flick.{$extension}";
                // if the video can be processed by ffmpeg-php, width and height are greater than 1
                if (!empty($info['width']) && $info['width'] > 1) {
                    $info['aspect'] = $info['width'] / $info['height'];
                    $info['offset'] = strftime("%T", round($info['duration'] / 5 - 60 * 60));
                } else {
                    $info = $default;
                }
                // store prefs and create thumbnails
                LibertyMime::expungeMetaData($pParamHash['attachment_id']);
                LibertyMime::storeMetaData($pParamHash['attachment_id'], 'Video', $info);
                mime_video_create_thumbnail($source, $info['offset']);
                if (!is_file($dest_file) && !link($source, $dest_file)) {
                    copy($source, $dest_file);
                }
                mime_video_fix_streaming($dest_file);
                $log['message'] = 'SUCCESS: Converted to flash video';
                $actionLog['log_message'] = "Video file was successfully uploaded and thumbnails extracted.";
                $ret = TRUE;
            } else {
                // work out what the target filename is
                $extension = $codec == "flv" ? "flv" : "mp4";
                $dest_file = $destPath . "/flick.{$extension}";
                // if the video can be processed by ffmpeg-php, width and height are greater than 1
                if (!empty($info['width']) && $info['width'] > 1) {
                    // reset some values to reduce video size
                    if ($info['width'] < $width) {
                        $width = $info['width'];
                    }
                    // here we calculate the size and aspect ratio of the output video
                    $size_ratio = $width / $info['width'];
                    $info['aspect'] = $info['width'] / $info['height'];
                    $info['video_width'] = $width;
                    $info['video_height'] = round($size_ratio * $info['height']);
                    // height of video needs to be an even number
                    if ($info['video_height'] % 2) {
                        $info['video_height']++;
                    }
                    $info['size'] = "{$info['video_width']}x{$info['video_height']}";
                } else {
                    $info = $default;
                }
                // transfer settings to vars for easy manipulation for various APIs of ffmpeg
                $audio_bitrate = $gBitSystem->getConfig('mime_video_audio_bitrate', 32000) / 1000 . 'kb';
                $audio_samplerate = $gBitSystem->getConfig('mime_video_audio_samplerate', 22050);
                $video_bitrate = $gBitSystem->getConfig('mime_video_video_bitrate', 160000) / 1000 . 'kb';
                $acodec_mp3 = $gBitSystem->getConfig('ffmpeg_mp3_lib', 'libmp3lame');
                $me_param = $gBitSystem->getConfig('ffmpeg_me_method', 'me');
                if ($codec == "h264") {
                    $parameters = " -i '{$source}'" . " -acodec libfaac" . " -ab {$audio_bitrate}" . " -ar {$audio_samplerate}" . " -vcodec libx264" . " -b {$video_bitrate}" . " -bt {$video_bitrate}" . " -s " . $info['size'] . " -aspect " . $info['aspect'] . " -flags +loop -cmp +chroma -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -maxrate 10M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30" . " -partitions +parti4x4+partp8x8+partb8x8 -{$me_param} epzs -subq 5 -trellis 1" . " -y '{$dest_file}'";
                } elseif ($codec == "h264-2pass") {
                    // it is not possible to pass in the path for the x264 log file and it is always generated in the working dir.
                    $cwd = getcwd();
                    chdir(dirname($dest_file));
                    $passlogfile = dirname($dest_file) . "/ffmpeg2pass";
                    // pass 1
                    $parameters = " -i '{$source}'" . " -an" . " -pass 1" . " -passlogfile {$passlogfile}" . " -vcodec libx264" . " -b {$video_bitrate}" . " -bt {$video_bitrate}" . " -s " . $info['size'] . " -aspect " . $info['aspect'] . " -flags +loop -cmp +chroma -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bf 16 -maxrate 10M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30" . " -partitions 0 -{$me_param} epzs -subq 1 -trellis 0" . " -y '{$dest_file}'";
                    // pass 2
                    $parameters2 = " -i '{$source}'" . " -acodec libfaac" . " -ab {$audio_bitrate}" . " -ar {$audio_samplerate}" . " -pass 2" . " -passlogfile {$passlogfile}" . " -vcodec libx264" . " -b {$video_bitrate}" . " -bt {$video_bitrate}" . " -s " . $info['size'] . " -aspect " . $info['aspect'] . " -flags +loop -cmp +chroma -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4" . " -partitions +parti8x8+parti4x4+partp8x8+partp4x4+partb8x8 -flags2 +brdo+dct8x8+wpred+bpyramid+mixed_refs -{$me_param} epzs -subq 7 -trellis 1 -refs 6 -bf 16 -directpred 3 -b_strategy 1 -bidir_refine 1 -coder 1" . " -y '{$dest_file}'";
                } else {
                    $parameters = " -i '{$source}'" . " -acodec {$acodec_mp3}" . " -ab {$audio_bitrate}" . " -ar {$audio_samplerate}" . " -f flv" . " -b {$video_bitrate}" . " -bt {$video_bitrate}" . " -s " . $info['size'] . " -aspect " . $info['aspect'] . " -y '{$dest_file}'";
                }
                if ($pOnlyGetParameters) {
                    return $parameters;
                } else {
                    // we keep the output of this that we can store it to the error file if we need to do so
                    $debug = shell_exec("{$ffmpeg} {$parameters} 2>&1");
                    if (!empty($parameters2)) {
                        $debug .= shell_exec("{$ffmpeg} {$parameters2} 2>&1");
                        // change back to whence we came
                        chdir($cwd);
                    }
                }
                // make sure the conversion was successfull
                if (is_file($dest_file) && filesize($dest_file) > 48) {
                    mime_video_fix_streaming($dest_file);
                    // try to work out a reasonable timepoint where to extract a screenshot
                    if (preg_match('!Duration: ([\\d:\\.]*)!', $debug, $time)) {
                        list($h, $m, $s) = explode(':', $time[1]);
                        $seconds = round(60 * 60 * (int) $h + 60 * (int) $m + (double) $s);
                        // we need to subract one hour from our time for strftime to return the correct value
                        $info['offset'] = strftime("%T", round($seconds / 5 - 60 * 60));
                    } else {
                        $info['offset'] = "00:00:10";
                    }
                    // store some video specific settings
                    LibertyMime::expungeMetaData($pParamHash['attachment_id']);
                    LibertyMime::storeMetaData($pParamHash['attachment_id'], 'Video', $info);
                    // since the flv conversion worked, we will create a preview screenshots to show.
                    mime_video_create_thumbnail($dest_file, $info['offset']);
                    $log['message'] = 'SUCCESS: Converted to flash video';
                    $actionLog['log_message'] = "Converted to flashvideo in " . (date('U') - $begin) . " seconds";
                    $ret = TRUE;
                } else {
                    // remove unsuccessfully converted file
                    @unlink($dest_file);
                    $log['message'] = "ERROR: The video you uploaded could not be converted by ffmpeg.\nDEBUG OUTPUT:\n\n" . $debug;
                    $actionLog['log_message'] = "Video could not be converted to flashvideo. An error dump was saved to: " . $destPath . '/error';
                    // write error message to error file
                    $h = fopen($destPath . "/error", 'w');
                    fwrite($h, "{$ffmpeg} {$parameters}\n\n{$debug}");
                    fclose($h);
                }
                @unlink($destPath . '/processing');
            }
        }
        $log['time'] = date('d/M/Y:H:i:s O');
        $log['duration'] = date('U') - $begin;
        // we'll insert some info into the database for reference
        $actionLog['content_id'] = $pParamHash['content_id'];
        $actionLog['title'] = "Uploaded file: {$pParamHash['upload']['name']} [Attchment ID: {$pParamHash['attachment_id']}]";
        // if this all goes t**s up, we'll know why
        $pParamHash['log'] = $log;
        // we'll add an entry in the action logs
        LibertyContent::storeActionLogFromHash(array('action_log' => $actionLog));
        // return the log
        $pParamHash['log'] = $log;
    }
    return $ret;
}
Ejemplo n.º 11
0
 * attachment_browser
 *
 * @author   spider <*****@*****.**>
 * @version  $Revision$
 * @package  liberty
 * @subpackage functions
 */
/**
 * bit setup
 */
require_once "../kernel/setup_inc.php";
global $gBitSmarty, $gContent, $gBitUser, $gBitSystem, $gLibertySystem;
// we just want information about a single attachment
if (isset($_REQUEST['attachment_id']) && is_numeric($_REQUEST['attachment_id'])) {
    if (!$gContent) {
        $gContent = new LibertyMime();
    }
    // this is a hack to make it compatible with existing tpls for now
    $attachment = $gContent->getAttachment($_REQUEST['attachment_id']);
    $ret = array();
    $ret[$attachment['attachment_id']] = $attachment;
    $userAttachments = $ret;
    $gContent->mStorage = $userAttachments;
    $gBitSmarty->assign('gContent', $gContent);
} else {
    // we want a list of user attachments
    $listHash = $_REQUEST;
    $listHash = array('page' => @BitBase::verifyId($_REQUEST['pgnPage']) ? $_REQUEST['pgnPage'] : NULL, 'load_attached_to' => true);
    $userAttachments = $gBitUser->getUserAttachments($listHash);
    // Fake the storage assignment for edit_storage_list.tpl
    $gContent->mStorage = $userAttachments;
Ejemplo n.º 12
0
 /**
  * getContentStatus
  *
  * @access public
  * @return an array of content_status_id, content_status_names the current
  * user can use on this content.
  */
 function getAvailableContentStatuses($pUserMinimum = -100, $pUserMaximum = 100)
 {
     global $gBitUser;
     $ret = NULL;
     // return NULL for all but admins
     if ($gBitUser->hasPermission('p_liberty_edit_all_status')) {
         $ret = LibertyMime::getAvailableContentStatuses();
     }
     return $ret;
 }
Ejemplo n.º 13
0
 function __construct()
 {
     $this->mGalleryPath = '';
     parent::__construct();
 }
Ejemplo n.º 14
0
 /**
  * getMetaId
  *
  * @param string $pDescription Description of meta key. e.g.: Exif, ID3, Album, Artist
  * @param string $pTable Table data is stored in - either 'type' or 'title'
  * @access public
  * @return meta type or title id on sucess, FALSE on failure
  */
 function getMetaId($pDescription, $pTable = 'type')
 {
     global $gBitSystem;
     $ret = FALSE;
     if (!empty($pDescription) && ($pTable == 'type' || $pTable == 'title')) {
         $ret = $gBitSystem->mDb->getOne("SELECT `meta_{$pTable}_id` FROM `" . BIT_DB_PREFIX . "liberty_meta_{$pTable}s` WHERE `meta_{$pTable}` = ?", array(LibertyMime::normalizeMetaDescription($pDescription)));
     }
     return $ret;
 }
Ejemplo n.º 15
0
 /**
  * This function generates a list of records from the liberty_content database for use in a list page
  * @param $pParamHash contains an array of conditions to sort by
  * @return array of articles
  * @access public
  **/
 public function getList(&$pParamHash)
 {
     global $gBitSystem, $gBitUser, $gLibertySystem;
     if (empty($pParamHash['sort_mode'])) {
         // no idea what this is supposed to do
         //$pParamHash['sort_mode'] = $gBitSystem->isFeatureActive('articles_auto_approve') ? 'order_key_desc' : 'publish_date_desc';
         $pParamHash['sort_mode'] = 'publish_date_desc';
     }
     LibertyContent::prepGetList($pParamHash);
     $joinSql = '';
     $selectSql = '';
     $bindVars = array();
     array_push($bindVars, $this->mContentTypeGuid);
     $this->getServicesSql('content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars, NULL, $pParamHash);
     $find = $pParamHash['find'];
     if (is_array($find)) {
         // you can use an array of articles
         $whereSql .= " AND lc.`title` IN( " . implode(',', array_fill(0, count($find), '?')) . " )";
         $bindVars = array_merge($bindVars, $find);
     } elseif (is_string($find)) {
         // or a string
         $whereSql .= " AND UPPER( lc.`title` ) LIKE ? ";
         $bindVars[] = '%' . strtoupper($find) . '%';
     } elseif (@$this->verifyId($pParamHash['user_id'])) {
         // or gate on a user
         $whereSql .= " AND lc.`user_id` = ? ";
         $bindVars[] = (int) $pParamHash['user_id'];
     }
     if (@$this->verifyId($pParamHash['status_id'])) {
         $whereSql .= " AND a.`status_id` = ? ";
         $bindVars[] = $pParamHash['status_id'];
     }
     if (@$this->verifyId($pParamHash['type_id'])) {
         $whereSql .= " AND a.`article_type_id` = ? ";
         $bindVars[] = (int) $pParamHash['type_id'];
     }
     // TODO: we need to check if the article wants to be viewed before / after respective dates
     // someone better at SQL please get this working without an additional db call - xing
     $now = $gBitSystem->getUTCTime();
     if (!empty($pParamHash['show_future']) && !empty($pParamHash['show_expired']) && $gBitUser->hasPermission('p_articles_admin')) {
         // this will show all articles at once - future, current and expired
     } elseif (!empty($pParamHash['show_future']) && $gBitUser->hasPermission('p_articles_admin')) {
         // hide expired articles
         $whereSql .= " AND ( a.`expire_date` > ? OR atype.`show_post_expire` = ? ) ";
         $bindVars[] = (int) $now;
         $bindVars[] = 'y';
     } elseif (!empty($pParamHash['show_expired']) && $gBitUser->hasPermission('p_articles_admin')) {
         // hide future articles
         $whereSql .= " AND ( a.`publish_date` < ? OR atype.`show_pre_publ` = ? ) ";
         $bindVars[] = (int) $now;
         $bindVars[] = 'y';
     } elseif (!empty($pParamHash['get_future'])) {
         // show only future
         // if we're trying to view these articles, we better have the perms to do so
         if (!$gBitUser->hasPermission('p_articles_admin')) {
             return array();
         }
         $whereSql .= " AND a.`publish_date` > ?";
         $bindVars[] = (int) $now;
     } elseif (!empty($pParamHash['get_expired'])) {
         // show only expired articles
         // if we're trying to view these articles, we better have the perms to do so
         if (!$gBitUser->hasPermission('p_articles_admin')) {
             return array();
         }
         $whereSql .= " AND a.`expire_date` < ? ";
         $bindVars[] = (int) $now;
     } else {
         // hide future and expired articles - this is the default behaviour
         // we need all these AND and ORs to ensure that other conditions such as status_id are respected as well
         $whereSql .= " AND (( a.`publish_date` > a.`expire_date` ) OR (( a.`publish_date` < ? OR atype.`show_pre_publ` = ? ) AND ( a.`expire_date` > ? OR atype.`show_post_expire` = ? ))) ";
         $bindVars[] = (int) $now;
         $bindVars[] = 'y';
         $bindVars[] = (int) $now;
         $bindVars[] = 'y';
     }
     if (@$this->verifyId($pParamHash['topic_id'])) {
         $whereSql .= " AND a.`topic_id` = ? ";
         $bindVars[] = (int) $pParamHash['topic_id'];
     } elseif (!empty($pParamHash['topic'])) {
         $whereSql .= " AND UPPER( atopic.`topic_name` ) = ? ";
         $bindVars[] = strtoupper($pParamHash['topic']);
     } else {
         $whereSql .= " AND ( atopic.`active_topic` != 'n' OR atopic.`active_topic` IS NULL ) ";
         //$whereSql .= " AND atopic.`active_topic` != 'n' ";
     }
     // Oracle is very particular about naming multiple columns, so need to explicity name them ORA-00918: column ambiguously defined
     $query = "SELECT\n\t\t\t\ta.`article_id`, a.`description`, a.`author_name`, a.`publish_date`, a.`expire_date`, a.`rating`,\n\t\t\t\tatopic.`topic_id`, atopic.`topic_name`, atopic.`has_topic_image`, atopic.`active_topic`,\n\t\t\t\tastatus.`status_id`, astatus.`status_name`,\n\t\t\t\tlch.`hits`,\n\t\t\t\tatype.*, lc.*, la.`attachment_id` AS `primary_attachment_id`, lf.`file_name` AS `image_attachment_path` {$selectSql}\n\t\t\tFROM `" . BIT_DB_PREFIX . "articles` a\n\t\t\t\tINNER JOIN      `" . BIT_DB_PREFIX . "liberty_content`       lc ON( lc.`content_id`         = a.`content_id` )\n\t\t\t\tINNER JOIN      `" . BIT_DB_PREFIX . "article_status`   astatus ON( astatus.`status_id`     = a.`status_id` )\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_content_hits` lch ON( lc.`content_id`         = lch.`content_id` )\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "article_topics`    atopic ON( atopic.`topic_id`       = a.`topic_id` )\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "article_types`      atype ON( atype.`article_type_id` = a.`article_type_id` )\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_attachments`   la ON( la.`content_id`         = lc.`content_id` AND la.`is_primary` = 'y' )\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_files`         lf ON( lf.`file_id`            = la.`foreign_id` )\n\t\t\t\t{$joinSql}\n\t\t\tWHERE lc.`content_type_guid` = ? {$whereSql}\n\t\t\tORDER BY " . $this->mDb->convertSortmode($pParamHash['sort_mode']);
     $query_cant = "SELECT COUNT( * )FROM `" . BIT_DB_PREFIX . "articles` a\n\t\t\tINNER JOIN      `" . BIT_DB_PREFIX . "liberty_content`    lc ON lc.`content_id`   = a.`content_id`\n\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "article_topics` atopic ON atopic.`topic_id` = a.`topic_id` {$joinSql}\n\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "article_types`   atype ON atype.`article_type_id` = a.`article_type_id`\n\t\t\tWHERE lc.`content_type_guid` = ? {$whereSql}";
     $result = $this->mDb->query($query, $bindVars, $pParamHash['max_records'], $pParamHash['offset']);
     $ret = array();
     $comment = new LibertyComment();
     while ($res = $result->fetchRow()) {
         // get this stuff parsed
         $res = array_merge($this->parseSplit($res, $gBitSystem->getConfig('articles_description_length', 500)), $res);
         $res['thumbnail_url'] = static::getImageThumbnails($res);
         $res['num_comments'] = $comment->getNumComments($res['content_id']);
         $res['display_url'] = self::getDisplayUrlFromHash($res);
         $res['display_link'] = $this->getDisplayLink($res['title'], $res);
         // fetch the primary attachment that we can display the file on the front page if needed
         $res['primary_attachment'] = LibertyMime::loadAttachment($res['primary_attachment_id']);
         $ret[] = $res;
     }
     $pParamHash["cant"] = $this->mDb->getOne($query_cant, $bindVars);
     LibertyContent::postGetList($pParamHash);
     return $ret;
 }
Ejemplo n.º 16
0
 public static function getTitleFromHash($pParamHash = NULL, $pContentId = NULL)
 {
     $ret = NULL;
     if (@BitBase::verifyId($pContentId)) {
         global $gBitDb;
         $ret = $gBitDb->getOne("SELECT lc.`title` FROM `" . BIT_DB_PREFIX . "liberty_content` lc WHERE lc.`content_id` = ? AND lc.`content_type_guid` = ?", array($pContentId, 'bitgroup'));
     } else {
         $ret = parent::getTitle($pParamHash);
     }
     return $ret;
 }
Ejemplo n.º 17
0
 /**
  * Get the base path to where the gallery thumbnail is stored - create directory if needed
  *
  * @param numeric $pContentId Content ID of gallery in question
  * @access public
  * @return Path to thumbnail directory on success, FALSE on failure
  */
 function getGalleryThumbBaseUrl($pContentId = NULL)
 {
     $ret = FALSE;
     if (!@BitBase::verifyId($pContentId) && $this->isValid()) {
         $pContentId = $this->mContentId;
     }
     if (@BitBase::verifyId($pContentId)) {
         // getStorageBranch is a private function, so this is a no-no but necessary until LA offers something better
         $ret = LibertyMime::getStorageBranch('gallery_thumbnails/' . $pContentId, NULL, TREASURY_PKG_NAME);
     }
     return $ret;
 }
Ejemplo n.º 18
0
 /**
  * expunge 
  * 
  * @access public
  * @return boolean TRUE on success, FALSE on failure
  */
 function expunge()
 {
     $ret = FALSE;
     if ($this->isValid()) {
         $this->mDb->StartTrans();
         $attrQuery = "DELETE FROM `" . BIT_DB_PREFIX . "ticket_attributes` WHERE `ticket_id` = ?";
         $query = "DELETE FROM `" . BIT_DB_PREFIX . "tickets` WHERE `content_id` = ?";
         // first delete attributes not to violate constraints
         $attrResult = $this->mDb->query($attrQuery, array($this->mTicketId));
         $result = $this->mDb->query($query, array($this->mContentId));
         if (LibertyMime::expunge()) {
             $ret = TRUE;
             $this->mDb->CompleteTrans();
         } else {
             $this->mDb->RollbackTrans();
         }
     }
     return $ret;
 }
Ejemplo n.º 19
0
 /**
  * This function generates a list of records from the liberty_content database for use in a list page
  */
 function getList(&$pParamHash)
 {
     global $gBitSystem, $gBitUser;
     $BIT_DB_PREFIX = BIT_DB_PREFIX;
     // this makes sure parameters used later on are set
     LibertyMime::prepGetList($pParamHash);
     $selectSql = $joinSql = $whereSql = '';
     $bindVars = array();
     $pParamHash['include_comments'] = 'y';
     $this->getServicesSql('content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars, NULL, $pParamHash);
     // this will set $find, $sort_mode, $max_records and $offset
     extract($pParamHash);
     if (empty($find)) {
     } elseif (is_array($find)) {
         // you can use an array of pages
         $whereSql .= " AND flc.`title` IN( " . implode(',', array_fill(0, count($find), '?')) . " )";
         $bindVars = array_merge($bindVars, $find);
     } elseif (is_string($find)) {
         // or a string
         $bindVars[] = '%' . strtoupper($find) . '%';
         $whereSql .= " AND UPPER( lc.`title` ) LIKE ?";
     }
     // if we have the board's board_id (b) we use that, or if we have its content_id we can use that
     if (!empty($pParamHash['b']) && $this->verifyId($pParamHash['b']) || !empty($pParamHash['content_id']) && $this->verifyId($pParamHash['content_id'])) {
         $joinSql .= " INNER JOIN `{$BIT_DB_PREFIX}boards_map` map ON (map.`topic_content_id` = lcom.`root_id`)";
         $joinSql .= " INNER JOIN `{$BIT_DB_PREFIX}boards` b ON (b.`content_id` = map.`board_content_id`)";
         if (!empty($pParamHash['b'])) {
             $whereSql .= " AND b.`board_id` = ?";
             $bindVars[] = (int) $pParamHash['b'];
         } else {
             $whereSql .= " AND b.`content_id` = ?";
             $bindVars[] = (int) $pParamHash['content_id'];
         }
     }
     BitBoardTopic::loadTrack($selectSql, $joinSql);
     // use adodb's substr property
     $substr = $this->mDb->substr();
     if ($this->mDb->mType == 'firebird') {
         $substrSql = "SUBSTRING(s_lcom.`thread_forward_sequence` FROM 1 FOR 10) LIKE SUBSTRING(lcom.`thread_forward_sequence` FROM 1 FOR 10)";
     } else {
         $substrSql = "{$substr}(s_lcom.`thread_forward_sequence`, 1, 10) LIKE {$substr}(lcom.`thread_forward_sequence`, 1, 10)";
     }
     if ($gBitSystem->isFeatureActive('boards_posts_anon_moderation') && !($gBitUser->hasPermission('p_boards_update') || $gBitUser->hasPermission('p_boards_post_update'))) {
         $whereSql .= " AND ((post.`is_approved` = 1) OR (lc.`user_id` >= 0))";
     }
     if ($gBitSystem->isFeatureActive('boards_posts_anon_moderation') && ($gBitUser->hasPermission('p_boards_update') || $gBitUser->hasPermission('p_boards_post_update'))) {
         $selectSql .= ", ( SELECT COUNT(*)\n\t\t\t\t\t\t\t\tFROM `{$BIT_DB_PREFIX}liberty_comments` AS s_lcom\n\t\t\t\t\t\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` s_lc ON (s_lcom.`content_id` = s_lc.`content_id`)\n\t\t\t\t\t\t\t\t\tLEFT JOIN  `{$BIT_DB_PREFIX}boards_posts` s ON( s_lcom.`comment_id` = s.`comment_id` )\n\t\t\t\t\t\t\t\tWHERE (" . $substrSql . ") AND ((s_lc.`user_id` < 0) AND (s.`is_approved` = 0 OR s.`is_approved` IS NULL))) AS unreg";
     } else {
         $selectSql .= ", 0 AS unreg";
     }
     $sort_sql = "flc." . $this->mDb->convertSortmode($sort_mode);
     $query = "SELECT\n\t\t\t\t\t\tlc.`user_id` AS flc_user_id,\n\t\t\t\t\t\tlc.`created` AS flc_created,\n\t\t\t\t\t\tlc.`last_modified` AS flc_last_modified,\n\t\t\t\t\t\tlc.`title` AS title,\n\t\t\t\t\t\tlc.`content_id` AS flc_content_id,\n\n\t\t\t\t\t\tCOALESCE(post.`is_approved`,0) AS first_approved,\n\t\t\t\t\t\tlcom.`anon_name`,\n\n\t\t\t\t\t\tth.`parent_id` AS th_first_id,\n\t\t\t\t\t\tCOALESCE(th.`is_locked`,0) AS th_is_locked,\n\t\t\t\t\t\tCOALESCE(th.`is_moved`,0) AS th_is_moved,\n\t\t\t\t\t\tCOALESCE(th.`is_sticky`,0) AS th_is_sticky,\n\n\t\t\t\t\t\tlcom.`comment_id` AS th_thread_id,\n\t\t\t\t\t\tlcom.`root_id` AS th_root_id,\n\n\t\t\t\t\t\tlcom.`root_id` AS content_id,\n\t\t\t\t\t\tlc.`content_type_guid` AS content_type_guid,\n\t\t\t\t\t\tlc.`content_status_id` AS content_status_id,\n\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tSELECT COUNT(*)\n\t\t\t\t\t\t\tFROM `" . BIT_DB_PREFIX . "liberty_comments` s_lcom\n\t\t\t\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` s_lc ON (s_lcom.`content_id` = s_lc.`content_id`)\n\t\t\t\t\t\t\tWHERE (" . $substrSql . ")\n\t\t\t\t\t\t) AS post_count,\n\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tSELECT MAX(s_lc.created)\n\t\t\t\t\t\t\tFROM `" . BIT_DB_PREFIX . "liberty_comments` s_lcom\n\t\t\t\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` s_lc ON (s_lcom.`content_id` = s_lc.`content_id`)\n\t\t\t\t\t\t\tWHERE (" . $substrSql . ")\n\t\t\t\t\t\t) AS last_post\n\n\t\t\t\t\t\t{$selectSql}\n\t\t\t\t\t\t\tFROM `{$BIT_DB_PREFIX}liberty_comments` lcom\n\t\t\t\t\t\t\tINNER JOIN `{$BIT_DB_PREFIX}liberty_content` lc ON( lc.`content_id` = lcom.`content_id` )\n\t\t\t\t\t\t\tLEFT JOIN `{$BIT_DB_PREFIX}boards_topics` th ON (th.`parent_id`=lcom.`content_id`)\n\t\t\t\t\t\t\tLEFT JOIN `{$BIT_DB_PREFIX}boards_posts` post ON (post.`comment_id` = lcom.`comment_id`)\n\t\t\t\t\t\t\t{$joinSql}\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tlcom.`root_id`=lcom.`parent_id`\n\t\t\t\t\t\t\t{$whereSql}\n\t\t\t\t\t\tORDER BY\n\t\t\t\t\t\t\t11 DESC,\n\t\t\t\t\t\t\t10 ASC,\n\t\t\t\t\t\t\tlast_post DESC,\n\t\t\t\t\t\t\tlc.created DESC\n\t\t\t\t\t\t";
     $query_cant = "SELECT count(*)\n\t\t\t\t\t\tFROM `{$BIT_DB_PREFIX}liberty_comments` lcom\n\t\t\t\t\t\t\tINNER JOIN `{$BIT_DB_PREFIX}liberty_content` lc ON( lc.`content_id` = lcom.`content_id` )\n\t\t\t\t\t\t\tLEFT JOIN `{$BIT_DB_PREFIX}boards_topics` th ON (th.`parent_id`=lcom.`content_id`)\n\t\t\t\t\t\t\tLEFT JOIN `{$BIT_DB_PREFIX}boards_posts` post ON (post.`comment_id` = lcom.`comment_id`)\n\t\t\t\t\t\t\t{$joinSql}\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tlcom.`root_id`=lcom.`parent_id`\n\t\t\t\t\t\t\t{$whereSql}";
     $result = $this->mDb->query($query, $bindVars, $max_records, $offset);
     $ret = array();
     while ($res = $result->fetchRow()) {
         if (empty($res['anon_name'])) {
             $res['anon_name'] = "Anonymous";
         }
         if ($res['th_is_moved'] > 0) {
             $res['url'] = BOARDS_PKG_URL . "index.php?t=" . $res['th_is_moved'];
         } else {
             $res['url'] = BOARDS_PKG_URL . "index.php?t=" . $res['th_thread_id'];
         }
         $llc_data = BitBoardTopic::getLastPost($res);
         $res = array_merge($res, $llc_data);
         BitBoardTopic::track($res);
         $res['flip'] = BitBoardTopic::getFlipFlop($res);
         if (empty($res['title'])) {
             $res['title'] = "[Thread " . $res['th_thread_id'] . "]";
         }
         $ret[] = $res;
     }
     $pParamHash["cant"] = $this->mDb->getOne($query_cant, $bindVars);
     // add all pagination info to pParamHash
     LibertyMime::postGetList($pParamHash);
     return $ret;
 }
Ejemplo n.º 20
0
 /**
  * Expunge data associated with an uploaded file
  * 
  * @access public
  * @param should the attachment be expunged. Defaults to true.
  * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
  * TODO: make it possible to remove only items when they are not part of other galleries
  */
 function expunge()
 {
     if ($this->isValid()) {
         $this->mDb->StartTrans();
         // Remove map entries
         $this->expungeItemMap();
         // now we can deal with the entry in liberty_content
         if (LibertyMime::expunge()) {
             $this->mDb->CompleteTrans();
         } else {
             $this->mErrors['expunge'] = tra('The item could not be completely removed.');
             $this->mDb->RollbackTrans();
         }
     }
     if (count($this->mErrors) != 0) {
         error_log("Error deleting treasury item: " . vc($this->mErrors));
     }
     return count($this->mErrors) == 0;
 }
Ejemplo n.º 21
0
 /**
  * Expunge currently loaded pigeonhole
  * @return bool TRUE on success, FALSE if store could not occur.
  * @access public
  **/
 function expunge($pStructureId = NULL)
 {
     $ret = FALSE;
     // if we have a custom structure id we want to remove, load it
     if (@BitBase::verifyId($pStructureId)) {
         $this->mStructureId = $pStructureId;
         $this->load();
     }
     if ($this->isValid()) {
         $this->mDb->StartTrans();
         // get all items that are part of the sub tree
         require_once LIBERTY_PKG_PATH . 'LibertyStructure.php';
         $struct = new LibertyStructure();
         // include the current structure id as well
         $structureIds[] = $this->mStructureId;
         $tree = $struct->getSubTree($this->mStructureId);
         foreach ($tree as $node) {
             $structureIds[] = $node['structure_id'];
         }
         $structureIds = array_unique($structureIds);
         $where = '';
         foreach ($structureIds as $structureId) {
             $where .= (empty($where) ? " WHERE " : " OR ") . "`structure_id`=?";
         }
         $result = $this->mDb->query("SELECT `content_id` FROM `" . BIT_DB_PREFIX . "liberty_structures` {$where}", $structureIds);
         $contentIds = $result->getRows();
         foreach ($contentIds as $id) {
             // now we have the content ids - let the nuking begin
             $query = "DELETE FROM `" . BIT_DB_PREFIX . "pigeonholes` WHERE `content_id` = ?";
             $result = $this->mDb->query($query, array($id['content_id']));
             $query = "DELETE FROM `" . BIT_DB_PREFIX . "pigeonhole_members` WHERE `parent_id` = ?";
             $result = $this->mDb->query($query, array($id['content_id']));
             // remove all entries from content tables
             $this->mContentId = $id['content_id'];
             if (LibertyMime::expunge()) {
                 $ret = TRUE;
                 $this->mDb->CompleteTrans();
             } else {
                 $this->mDb->RollbackTrans();
             }
         }
         // finally nuke the structure in liberty_structures
         $struct->removeStructureNode($this->mStructureId, FALSE);
     }
     return $ret;
 }
Ejemplo n.º 22
0
 /**
  * expunge 
  * 
  * @access public
  * @return boolean TRUE on success, FALSE on failure
  */
 function expunge()
 {
     global $gBitSystem;
     $ret = FALSE;
     if ($this->isValid()) {
         $this->mDb->StartTrans();
         $query = "DELETE FROM `" . BIT_DB_PREFIX . "sample_data` WHERE `content_id` = ?";
         $result = $this->mDb->query($query, array($this->mContentId));
         if (LibertyMime::expunge()) {
             $ret = TRUE;
         }
         $this->mDb->CompleteTrans();
         // If deleting the default/home sample record then unset this.
         if ($ret && $gBitSystem->getConfig('sample_home_id') == $this->mSampleId) {
             $gBitSystem->storeConfig('sample_home_id', 0, SAMPLE_PKG_NAME);
         }
     }
     return $ret;
 }
Ejemplo n.º 23
0
 /**
  * This function removes a map entry
  **/
 function expunge()
 {
     $ret = FALSE;
     if ($this->isValid()) {
         $this->mDb->StartTrans();
         $query = "DELETE FROM `" . BIT_DB_PREFIX . "gmaps` WHERE `content_id` = ?";
         $result = $this->mDb->query($query, array($this->mContentId));
         if (LibertyMime::expunge()) {
             $ret = TRUE;
             $this->mDb->CompleteTrans();
         } else {
             $this->mDb->RollbackTrans();
         }
     }
     return $ret;
 }
Ejemplo n.º 24
0
 /**
  * Generates the URL to the bitboard page
  * @return the link to display the page.
  */
 public static function getDisplayUrlFromHash(&$pParamHash)
 {
     global $gBitSystem;
     $ret = NULL;
     if (!empty($pParamHash['comment']) && !empty($pParamHash['comment']['thread_forward_sequence'])) {
         // look up base of comment sequece which is BitBoardTopic
         $seq = explode(".", $pParamHash['comment']['thread_forward_sequence']);
         $topicRootId = (int) $seq[0];
         if (BitBase::verifyId($topicRootId)) {
             require_once BOARDS_PKG_PATH . 'BitBoardTopic.php';
             $hash = array('topic_id' => $topicRootId);
             $ret = BitBoardTopic::getDisplayUrlFromHash($hash);
             // we're out of here with our topic url
             return $ret;
         }
     }
     if (BitBase::verifyId($pParamHash['board_id'])) {
         if ($gBitSystem->isFeatureActive('pretty_urls') || $gBitSystem->isFeatureActive('pretty_urls_extended')) {
             $rewrite_tag = $gBitSystem->isFeatureActive('pretty_urls_extended') ? 'view/' : '';
             $ret = BOARDS_PKG_URL . $rewrite_tag . 'board/' . $pParamHash['board_id'];
         } else {
             $ret = BOARDS_PKG_URL . "index.php?b=" . $pParamHash['board_id'];
         }
     } else {
         $ret = parent::getDisplayUrlFromHash($pParamHash);
     }
     return $ret;
 }
Ejemplo n.º 25
0
 function mime_default_expunge($pAttachmentId)
 {
     global $gBitSystem, $gBitUser;
     $ret = FALSE;
     if (@BitBase::verifyId($pAttachmentId)) {
         if ($fileHash = LibertyMime::loadAttachment($pAttachmentId)) {
             if ($gBitUser->isAdmin() || $gBitUser->mUserId == $fileHash['user_id'] && isset($fileHash['source_file']) && !empty($fileHash['source_file'])) {
                 // make sure this is a valid storage directory before removing it
                 if (preg_match("#^" . realpath(STORAGE_PKG_PATH) . "/attachments/\\d+/\\d+/#", $fileHash['source_file']) && is_file($fileHash['source_file'])) {
                     unlink_r(dirname($fileHash['source_file']));
                 }
                 $query = "DELETE FROM `" . BIT_DB_PREFIX . "liberty_files` WHERE `file_id` = ?";
                 $gBitSystem->mDb->query($query, array($fileHash['foreign_id']));
                 $ret = TRUE;
             }
         }
     }
     return $ret;
 }
Ejemplo n.º 26
0
 /**
  * @return boolean TRUE on success, FALSE on failure
  */
 public function expunge()
 {
     global $gBitSystem;
     $ret = FALSE;
     if ($this->isValid()) {
         $this->mDb->StartTrans();
         $query = "DELETE FROM `" . $this->mFormTbl . "` WHERE (`content_id` = ?) ";
         $result = $this->mDb->query($query, array($this->mContentId));
         if (parent::expunge()) {
             $ret = TRUE;
         }
         $this->mDb->CompleteTrans();
     }
     return $ret;
 }
Ejemplo n.º 27
0
 /**
  * TODO: This code is old and is not used by any package in the bitweaver CVS anymore.
  * We will clean up this code as soon as we migrated all legacy code
  */
 function store(&$pParamHash)
 {
     //deprecated( "This method has been replaced by a method in LibertyMime. Please try to migrate your code." );
     global $gLibertySystem, $gBitSystem, $gBitUser;
     $this->mDb->StartTrans();
     if (LibertyAttachable::verify($pParamHash) && (isset($pParamHash['skip_content_store']) || LibertyContent::store($pParamHash))) {
         if (!empty($pParamHash['STORAGE']) && count($pParamHash['STORAGE'])) {
             foreach (array_keys($pParamHash['STORAGE']) as $guid) {
                 $storeRows =& $pParamHash['STORAGE'][$guid];
                 // short hand variable assignment
                 // If it is empty then nothing more to do. Avoid error in foreach.
                 if (empty($storeRows)) {
                     continue;
                 }
                 foreach ($storeRows as $key => $value) {
                     $storeRow =& $pParamHash['STORAGE'][$guid][$key];
                     $storeRow['plugin_guid'] = $guid;
                     if (!@BitBase::verifyId($pParamHash['content_id'])) {
                         $storeRow['content_id'] = NULL;
                     } else {
                         $storeRow['content_id'] = $pParamHash['content_id'];
                         // copy in content_id
                     }
                     if (!empty($pParamHash['user_id'])) {
                         $storeRow['user_id'] = $pParamHash['user_id'];
                         // copy in the user_id
                     } else {
                         $storeRow['user_id'] = $gBitUser->mUserId;
                     }
                     // do we have a verify function for this storage type, and do things verify?
                     $verifyFunc = $gLibertySystem->getPluginFunction($guid, 'verify_function');
                     if ($verifyFunc && $verifyFunc($storeRow)) {
                         // For backwards compatibility with a single upload.
                         if (@BitBase::verifyId($pParamHash['attachment_id'])) {
                             $storeRow['upload']['attachment_id'] = $storeRow['attachment_id'] = $pParamHash['attachment_id'];
                         } else {
                             if (!isset($storeRow['skip_insert'])) {
                                 if (defined('LINKED_ATTACHMENTS') && @BitBase::verifyId($pParamHash['content_id'])) {
                                     $storeRow['upload']['attachment_id'] = $storeRow['attachment_id'] = $pParamHash['content_id'];
                                 } else {
                                     $storeRow['upload']['attachment_id'] = $storeRow['attachment_id'] = defined('LINKED_ATTACHMENTS') ? $this->mDb->GenID('liberty_content_id_seq') : $this->mDb->GenID('liberty_attachments_id_seq');
                                 }
                             }
                         }
                         // if we have uploaded a file, we can take care of that generically
                         if (!empty($storeRow['upload']) && is_array($storeRow['upload']) && !empty($storeRow['upload']['size'])) {
                             if (empty($storeRow['upload']['type'])) {
                                 $ext = substr($storeRow['upload']['name'], strrpos($storeRow['upload']['name'], '.') + 1);
                                 $storeRow['upload']['type'] = $gBitSystem->lookupMimeType($ext);
                             }
                             $storeRow['upload']['dest_branch'] = $this->getStorageBranch($storeRow['attachment_id'], $storeRow['user_id'], $this->getStorageSubDirName());
                             if (!empty($pParamHash['thumbnail_sizes'])) {
                                 $storeRow['upload']['thumbnail_sizes'] = $pParamHash['thumbnail_sizes'];
                             }
                             $storagePath = liberty_process_upload($storeRow['upload']);
                             // We're gonna store to local file system & liberty_files table
                             if (empty($storagePath)) {
                                 $this->mErrors['file'] = tra("Could not store file") . ": " . $storeRow['upload']['name'] . '.';
                                 $storeRow['attachment_id'] = NULL;
                                 $storeRow['upload']['attachment_id'] = NULL;
                             } else {
                                 $storeRow['upload']['dest_file_path'] = $storagePath;
                             }
                         }
                         if (@BitBase::verifyId($storeRow['attachment_id']) && ($storeFunc = $gLibertySystem->getPluginFunction($storeRow['plugin_guid'], 'store_function'))) {
                             $this->mStorage = $storeFunc($storeRow);
                         }
                         // don't insert if we already have an entry with this attachment_id
                         if (@BitBase::verifyId($storeRow['attachment_id']) && !isset($storeRow['skip_insert']) && !LibertyMime::loadAttachment($storeRow['attachment_id'])) {
                             $sql = "INSERT INTO `" . BIT_DB_PREFIX . "liberty_attachments` ( `content_id`, `attachment_id`, `attachment_plugin_guid`, `foreign_id`, `user_id` ) VALUES ( ?, ?, ?, ?, ? )";
                             $rs = $this->mDb->query($sql, array($storeRow['content_id'], $storeRow['attachment_id'], $storeRow['plugin_guid'], (int) $storeRow['foreign_id'], $storeRow['user_id']));
                         }
                     }
                 }
             }
         }
         // set the primary attachment id
         $this->setPrimaryAttachment($pParamHash['liberty_attachments']['primary'], $pParamHash['content_id'], empty($pParamHash['liberty_attachments']['auto_primary']) || $pParamHash['liberty_attachments']['auto_primary'] ? TRUE : FALSE);
     }
     $this->mDb->CompleteTrans();
     return count($this->mErrors) == 0;
 }
Ejemplo n.º 28
0
 * Setup
 */
require_once '../kernel/setup_inc.php';
require_once LIBERTY_PKG_PATH . 'LibertyMime.php';
// fetch the attachment details
if (@(!BitBase::verifyId($_REQUEST['attachment_id'])) || !($attachment = LibertyMime::loadAttachment($_REQUEST['attachment_id'], $_REQUEST))) {
    $gBitSystem->fatalError(tra("The Attachment ID given is not valid"));
}
$gBitSmarty->assign('attachment', $attachment);
// first we need to check the permissions of the content the attachment belongs to since they inherit them
if ($gContent = LibertyBase::getLibertyObject($attachment['content_id'])) {
    $gContent->verifyViewPermission();
    $gBitSmarty->assign('gContent', $gContent);
    if ($download_function = $gLibertySystem->getPluginFunction($attachment['attachment_plugin_guid'], 'download_function', 'mime')) {
        if ($download_function($attachment)) {
            LibertyMime::addDownloadHit($attachment['attachment_id']);
            die;
        } else {
            if (!empty($attachment['errors'])) {
                $msg = '';
                foreach ($attachment['errors'] as $error) {
                    $msg .= $error . '<br />';
                }
                $gBitSystem->fatalError(tra($msg));
            } else {
                $gBitSystem->fatalError(tra('There was an undetermined problem trying to prepare the file for download.'));
            }
        }
    } else {
        $gBitSystem->fatalError(tra("No suitable download function found."));
    }
Ejemplo n.º 29
0
/**
 * liberty_magickwand_panorama_image - strictly speaking, this belongs in one of the image processing plugin files, but we'll leave it here for the moment
 *
 * @param array $pFileHash File hash - souce_file is required
 * @param array $pOptions
 * @access public
 * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
 */
function liberty_magickwand_panorama_image(&$pFileHash, $pOptions = array())
{
    $magickWand = NewMagickWand();
    $pFileHash['error'] = NULL;
    if (!empty($pFileHash['source_file']) && is_file($pFileHash['source_file'])) {
        if (!($pFileHash['error'] = liberty_magickwand_check_error(MagickReadImage($magickWand, $pFileHash['source_file']), $magickWand))) {
            // calculate border width
            $iwidth = round(MagickGetImageWidth($magickWand));
            $iheight = round(MagickGetImageHeight($magickWand));
            $aspect = $iwidth / $iheight;
            $metaHash = array('width' => $iwidth, 'height' => $iheight, 'aspect' => $aspect);
            // store original file information that we can adjust the viewer
            LibertyMime::storeMetaData($pFileHash['attachment_id'], 'PANO', $metaHash);
            // we need to pad the image if the aspect ratio is not 2:1 (give it a wee bit of leeway that we don't add annoying borders if not really needed)
            if ($aspect > 2.1 || $aspect < 1.9) {
                $bwidth = $bheight = 0;
                if ($aspect > 2) {
                    $bheight = round(($iwidth / 2 - $iheight) / 2);
                } else {
                    $bwidth = round(($iheight / 2 - $iwidth) / 2);
                }
                // if the ratio has nothing to do with a panorama image - i.e. gives us a negative number here, we won't generate a panorama image
                if ($bheight > 0) {
                    $pixelWand = NewPixelWand();
                    PixelSetColor($pixelWand, !empty($pOptions['background']) ? $pOptions['background'] : 'black');
                    if (!($pFileHash['error'] = liberty_magickwand_check_error(MagickBorderImage($magickWand, $pixelWand, $bwidth, $bheight), $magickWand))) {
                        if (!($pFileHash['error'] = liberty_magickwand_check_error(MagickWriteImage($magickWand, $pFileHash['source_file']), $magickWand))) {
                            // yay!
                        }
                    }
                    DestroyPixelWand($pixelWand);
                }
            }
        }
    }
    DestroyMagickWand($magickWand);
    return empty($pFileHash['error']);
}
Ejemplo n.º 30
0
 function getDisplayLink($pLinkText = NULL, $pMixed = NULL, $pAnchor = NULL)
 {
     $anchor = '';
     // Override default title with something comment centric
     if (empty($pLinkText)) {
         $pLinkText = tra('Comment');
     }
     if (@BitBase::verifyId($pMixed['content_id'])) {
         $anchor = "&view_comment_id=" . $pMixed['content_id'] . "#comment_{$pMixed['content_id']}";
     }
     return parent::getDisplayLink($pLinkText, $pMixed, $anchor);
 }