Example #1
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;
 }
Example #2
0
 /**
  * remove the entire cache in the cache folder
  *
  * @access public
  * @return TRUE on success, FALSE on failure
  */
 function expungeCache()
 {
     // the only places we can write to in bitweaver are temp and storage
     $subdir = str_replace(STORAGE_PKG_PATH, "", $this->mFolder);
     if (strpos($this->mFolder, STORAGE_PKG_PATH) === 0 && $subdir != "users" && $subdir != "common" || strpos($this->mFolder, TEMP_PKG_PATH) === 0) {
         $ret = unlink_r($this->mFolder);
         if (!is_dir($this->mFolder)) {
             mkdir_p($this->mFolder);
         }
     }
     return $ret;
 }
Example #3
0
function board_sync_run($pLog = FALSE)
{
    global $gBitUser, $gBitSystem;
    $gBitUser->setPermissionOverride('p_users_bypass_captcha', TRUE);
    $connectionString = '{' . $gBitSystem->getConfig('boards_sync_mail_server', 'imap') . ':' . $gBitSystem->getConfig('boards_sync_mail_port', '993') . '/' . $gBitSystem->getConfig('boards_sync_mail_protocol', 'imap') . '/ssl/novalidate-cert}';
    // Can we open the mailbox?
    if ($mbox = imap_open($connectionString, $gBitSystem->getConfig('boards_sync_user'), $gBitSystem->getConfig('boards_sync_password'))) {
        $MC = imap_check($mbox);
        // Fetch an overview for all messages in INBOX of mailbox has messages
        if ($MC->Nmsgs) {
            //	  print($MC->Nmsgs);
            $result = imap_fetch_overview($mbox, "1:{$MC->Nmsgs}", 0);
            if ($messageNumbers = imap_sort($mbox, SORTDATE, 0)) {
                foreach ($messageNumbers as $msgNum) {
                    if ($pLog) {
                        print "Processing Msg#: " . $msgNum . "\n";
                    }
                    $deleteMsg = FALSE;
                    $header = imap_headerinfo($mbox, $msgNum);
                    // Is this a moderation message?
                    if (preg_match('/.*? post from .*? requires approval/', $header->subject)) {
                        if ($pLog) {
                            print "Is Moderation Request.\n";
                        }
                        // moderated messages nest the orginal message in another part
                        // php imap functions dont give us easy access to part header info, so...
                        // to easily get to the headers of those message we open the part as a new imap stream
                        // fetch the original message
                        $body = imap_fetchbody($mbox, $msgNum, 2);
                        // add a spoof time marker to the first line to make imap_open happy
                        $body = "From dummy@localhost  Sat Jan  1 00:00:00 1970\n" . $body;
                        // write the org msg to a temp file
                        $filename = 'orginal_email.eml';
                        srand(time());
                        $filestore = TEMP_PKG_PATH . BOARDS_PKG_NAME . '/boardsync/' . rand(999, 999999999) . '/' . $filename;
                        mkdir_p(dirname($filestore));
                        $fp = fopen($filestore, "w+");
                        fwrite($fp, $body);
                        fclose($fp);
                        // open the temp file as an imap stream so we can use imap_headerinfo() to parse the org msg header
                        $mbox2 = imap_open($filestore, "", "");
                        $msgHeader = imap_headerinfo($mbox2, 1);
                        // moderation validation is also in a part, extract it
                        $replyBody = imap_fetchbody($mbox, $msgNum, 3);
                        $replyHeaders = board_sync_raw_headers($replyBody);
                        $approveSubj = board_sync_get_header('Subject', $replyHeaders);
                        $confirmCode = substr($approveSubj, strlen('confirm '));
                        if ($pLog) {
                            print "Confirm code: " . $confirmCode . "\n";
                        }
                        $deliveredTo = board_sync_delivered_to($replyHeaders);
                        $deleteMsg = board_sync_process_message($mbox, $msgNum, $msgHeader, imap_fetchstructure($mbox, $msgNum, 2), $confirmCode, $pLog, $deliveredTo);
                        // Is this a reminder message that we just skip?
                    } elseif (preg_match('/[0-9]+ .*? moderator request.* waiting/', $header->subject)) {
                        if ($pLog) {
                            print "Deleting reminder.\n";
                        }
                        $deleteMsg = TRUE;
                    } elseif (preg_match('/Welcome to the .* mailing list/', $header->subject)) {
                        if ($pLog) {
                            print "Deleting welcome message.\n";
                        }
                        $deleteMsg = TRUE;
                    } else {
                        // imap_headerinfo acts retarded on these emails and improperly parses the header unless we call fetchstructure first - so do it.
                        // note this problem does not occure above when parsing the temp email in a moderated msg - god damn spooky
                        $msgStructure = imap_fetchstructure($mbox, $msgNum);
                        $msgHeader = imap_headerinfo($mbox, $msgNum);
                        // With multiple To: recipients it is often handy to know who the message is "Delivered-To" by the MTA
                        $raw_headers = imap_fetchheader($mbox, $msgNum);
                        $deliveredTo = board_sync_delivered_to($raw_headers);
                        $deleteMsg = board_sync_process_message($mbox, $msgNum, $msgHeader, $msgStructure, FALSE, $pLog, $deliveredTo);
                        //					vd($deleteMsg);
                    }
                    if ($deleteMsg && empty($gDebug) && empty($gArgs['test'])) {
                        //					vd("DELETE!");
                        if ($pLog) {
                            print "Deleted msg {$msgNum}\n";
                        }
                        imap_delete($mbox, $msgNum);
                    }
                }
            }
        }
        // final cleanup
        imap_expunge($mbox);
        imap_close($mbox);
        // clear everything we've written to the temp directory
        $dir = TEMP_PKG_PATH . BOARDS_PKG_NAME . '/boardsync';
        if (is_dir($dir) && strpos($dir, BIT_ROOT_PATH) === 0) {
            if (!unlink_r($dir)) {
                bit_error_log("Failed to clear directory: " . $dir . " in boards package mailinglist synchronization.");
            }
        }
    } else {
        bit_error_log(__FILE__ . " failed imap_open {$connectionString} " . imap_last_error());
    }
}
Example #4
0
$diskUsage = array('templates_c' => array('path' => TEMP_PKG_PATH . 'templates_c', 'title' => tra('Templates')), 'lang' => array('path' => TEMP_PKG_PATH . 'lang', 'title' => tra('Language Files')), 'shoutbox' => array('path' => TEMP_PKG_PATH . 'shoutbox', 'title' => tra('Shoutbox')), 'modules' => array('path' => TEMP_PKG_PATH . 'modules/cache', 'title' => tra('Modules'), 'subdir' => $bitdomain), 'cache' => array('path' => TEMP_PKG_PATH . 'cache', 'title' => tra('System Cache'), 'subdir' => $bitdomain), 'icons' => array('path' => TEMP_PKG_PATH . 'themes/biticon', 'title' => tra('Icons')), 'liberty_cache' => array('path' => TEMP_PKG_PATH . 'liberty/cache', 'title' => tra('Liberty Cache')), 'format_help' => array('path' => TEMP_PKG_PATH . 'liberty/help', 'title' => tra('Format Help')), 'nexus' => array('path' => TEMP_PKG_PATH . 'nexus', 'title' => tra('Nexus Menus')), 'rss' => array('path' => TEMP_PKG_PATH . 'rss', 'title' => tra('RSS Feed Cache')), 'javascript' => array('path' => STORAGE_PKG_PATH . 'themes', 'title' => tra('Javascript and CSS files')));
/* make sure we only display paths that exist
foreach( $diskUsage as $key => $item ) {
	if( !is_dir( $item['path'] )) {
		unset( $diskUsage[$key] );
	}
}*/
if (!empty($_GET['pruned'])) {
    $feedback['success'] = tra('The cache was successfully cleared.');
}
if (!empty($_GET['prune'])) {
    foreach ($diskUsage as $key => $item) {
        if ($_GET['prune'] == $key || $_GET['prune'] == 'all') {
            $dir = $item['path'] . (!empty($item['subdir']) ? '/' . $item['subdir'] : '');
            if (is_dir($dir) && strpos($item['path'], BIT_ROOT_PATH) === 0) {
                if (unlink_r($dir)) {
                    $reload = TRUE;
                } else {
                    $feedback['error'] = tra('There was a problem clearing out the cache.');
                }
            }
        }
    }
    // nexus needs to rewrite the cache right away to avoid errors
    if ($gBitSystem->isPackageActive('nexus') && ($_GET['prune'] == 'all' || $_GET['prune'] == 'nexus')) {
        require_once NEXUS_PKG_PATH . 'Nexus.php';
        $nexus = new Nexus();
        $nexus->rewriteMenuCache();
    }
    // depending on what we've just nuked, we need to reload the page
    if (!empty($reload)) {
Example #5
0
 /**
  * Delete liberty cache
  *
  * @param array $pContentId
  * @access public
  * @return TRUE on success, FALSE on failure
  */
 function expungeCache()
 {
     global $gBitSystem;
     $ret = FALSE;
     if ($gBitSystem->isFeatureActive('liberty_cache')) {
         $cacheDir = LibertyContent::getCacheBasePath();
         // make sure that we're in the temp dir at least
         if (strstr($cacheDir, str_replace('//', '/', TEMP_PKG_PATH))) {
             unlink_r($cacheDir);
             // make sure we have a usable cache directory to work with
             $ret = is_dir($cacheDir) || mkdir_p($cacheDir);
         }
     }
     return $ret;
 }
Example #6
0
$styleLayouts = $gBitThemes->getStyleLayouts();
$gBitSmarty->assign_by_ref("styleLayouts", $styleLayouts);
if (!empty($_REQUEST["site_style_layout"])) {
    $gBitSystem->storeConfig('site_style_layout', $_REQUEST["site_style_layout"] != 'remove' ? $_REQUEST["site_style_layout"] : NULL, THEMES_PKG_NAME);
}
// load cascader
$gCascader = new Cascader($_REQUEST);
if (!$gCascader->load()) {
    $feedback['error'] = $gCascader->mErrors;
}
// Make sure gCascader is avalable in the templates
$gBitSmarty->assign_by_ref('gCascader', $gCascader);
// Process form requests
// Remove all scheme files
if (!empty($_REQUEST['clear_all_styles'])) {
    unlink_r(LibertyAttachable::getStoragePath());
    $gBitSystem->storeConfig('cascader_style', NULL);
}
// create a css file based on the user specifications
if (!empty($_REQUEST['create_style'])) {
    $cascaderCss = $gCascader->createHeader();
    $cascaderCss .= $gCascader->createCss($_REQUEST['cascader']);
    if ($cssUrl = $gCascader->writeCss($cascaderCss)) {
        $feedback['success'] = tra("The css file was stored to") . ": " . $cssUrl;
    } else {
        $feedback['error'] = tra("There was a problem storing your custom css file.");
    }
    $gBitSystem->storeConfig('cascader_style', $cssUrl);
}
// apply an existing style
if (!empty($_REQUEST['apply_style'])) {
Example #7
0
 function prepareVersionForInstall($pPackagerId = NULL, $pIgnoreVersion = FALSE)
 {
     if (@BitBase::verifyId($pPackagerId)) {
         $this->mPackagerId = $pPackagerId;
     }
     if ($this->isValid(TRUE)) {
         if ($this->fetchRemotePackage()) {
             // shorthand
             $installPath = $this->getInstallPath($this->mInfo['package']);
             $backup = $this->getStoragePath('backups') . $this->mInfo['package'] . '-' . $this->getVersionFromFile($installPath . 'admin/schema_inc.php') . '-' . mktime();
             if ($pIgnoreVersion || $this->versionCompare($this->getVersionFromFile($installPath . 'admin/schema_inc.php'), $this->mInfo) === -1) {
                 // only continue if file is present and valid
                 if ($this->isDownloaded()) {
                     // extract archive
                     $fileHash = array('tmp_name' => $this->getPackageFilepath(), 'type' => 'application/zip', 'name' => 'temp.zip');
                     if ($ext = liberty_process_archive($fileHash)) {
                         if (is_dir($extracted = $ext . '/' . $this->mInfo['package'])) {
                             if (is_dir($installPath)) {
                                 // NOTE: this step is silenced - we display an error message if this has failed
                                 if (@rename($installPath, $backup)) {
                                     if (!rename($extracted, $installPath)) {
                                         $this->mErrors['move'] = tra('There was a problem moving the extracted package to its new position.');
                                     }
                                 } else {
                                     $this->mErrors['backup'] = tra('There was a problem moving the original package to the backup location.');
                                 }
                             } else {
                                 if (!rename($extracted, $installPath)) {
                                     $this->mErrors['move'] = tra('There was a problem moving the extracted package to its new position.');
                                 }
                             }
                             // remove unnecessary files
                             unlink_r($ext);
                         } else {
                             $this->mErrors['extract'] = tra('There was a problem extracting the downloaded package.');
                         }
                     }
                 } else {
                     $this->mErrors['filecheck'] = tra('The file could not be located on your server.');
                 }
             } else {
                 $this->mErrors['version'] = tra('The version of <code>' . $installPath . 'admin/schema_inc.php</code> is either higher or equal to the version you wish to install. Only upgrades are possible.');
             }
         }
         if (empty($this->mErrors) && $this->versionCompare($this->getVersionFromFile($installPath . 'admin/schema_inc.php'), $this->mInfo) !== 0) {
             $this->mErrors['final_version'] = tra('Despite a successful download and extraction, there is a problem with the reported version of the package.');
         }
     }
     return count($this->mErrors) == 0;
 }
Example #8
0
 /**
  * recursively remove any unwanted debris from the uploaded package
  * 
  * @param array $pDir 
  * @access public
  * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
  */
 function unlinkDebris($pDir)
 {
     if (is_dir($pDir) && ($handle = opendir($pDir))) {
         // fix dir if no trailing slash
         if (!preg_match("!/\$!", $pDir)) {
             $pDir .= '/';
         }
         while (FALSE !== ($file = readdir($handle))) {
             if ($file != '.' && $file != '..') {
                 if (preg_match("/^CVS\$/", $file)) {
                     unlink_r($pDir . $file);
                 } elseif (preg_match("!^\\..*\\.swp\$!", $file)) {
                     unlink($pDir . $file);
                 } elseif (is_dir($file)) {
                     $this->unlinkDebris($pDir . $file);
                 }
             }
         }
     }
 }
Example #9
0
     // Save any changes the user made to their CSS
     $fp = fopen($customCSSFile, "w");
     if (!$fp) {
         $gBitSmarty->assign('msg', tra("You dont have permission to write the style sheet"));
         $gBitSystem->display('error.tpl', NULL, array('display_mode' => 'display'));
         die;
     }
     fwrite($fp, $_REQUEST["textData"]);
     fclose($fp);
     $successMsg[] = "CSS Updated and Saved";
 } elseif (isset($_REQUEST["fCancelCSS"]) && $_REQUEST['fCancelCSS']) {
     // Cancel (e.g. do nothing)
     $successMsg[] = "Changes have been cancelled";
 } elseif (isset($_REQUEST['fResetCSS'])) {
     // Reset CSS (e.g. copy an existing style as a base for their custom style)
     unlink_r($customCSSPath);
     mkdir_p($customCSSPath . '/images');
     $resetStyle = $_REQUEST['resetStyle'];
     $cssData = $csslib->load_css2_file(THEMES_PKG_PATH . "styles/{$resetStyle}/{$resetStyle}.css");
     if (file_exists($customCSSPath . '/images')) {
         $gBitThemes->expunge_dir($customCSSPath . '/images/');
     } else {
         mkdir_p($customCSSPath);
     }
     if (file_exists(THEMES_PKG_PATH . "styles/{$resetStyle}/images")) {
         //clean out any old junk
         copy_dirs(THEMES_PKG_PATH . "styles/{$resetStyle}/images", $customCSSPath . '/images/');
     }
     $fp = fopen($customCSSFile, "w");
     if (!$fp) {
         $gBitSmarty->assign('msg', tra("You dont have permission to write the style sheet"));
Example #10
0
 /**
  * expunge a gallery
  *
  * @param array $pParamHash
  * @access public
  * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
  */
 function expunge($pForceDeleteItems = FALSE)
 {
     $ret = FALSE;
     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();
         $tree = $struct->getSubTree($this->mStructureId);
         // include the current id as well - needed when there are no sub-galleries
         $galleryContentIds[] = $this->mContentId;
         foreach ($tree as $node) {
             $galleryContentIds[] = $node['content_id'];
         }
         $galleryContentIds = array_unique($galleryContentIds);
         // Create Item Object
         require_once TREASURY_PKG_PATH . 'TreasuryItem.php';
         $itemObject = new TreasuryItem();
         // Go through all galleries we want to remove
         foreach ($galleryContentIds as $gid) {
             // make sure the gallery is fully loaded
             $this->mContentId = $gid;
             $this->load();
             $itemContentIds = $this->mDb->getCol("SELECT `item_content_id` FROM `" . BIT_DB_PREFIX . "treasury_map` WHERE `gallery_content_id`=?", array($gid));
             $itemContentIds = array_unique($itemContentIds);
             // Delete items in galleries
             foreach ($itemContentIds as $iid) {
                 if ($pForceDeleteItems) {
                     // Remove item even if it exists in other galleries
                     $count = 1;
                 } else {
                     // Only delete item if it doesn't exist in other galleries
                     $count = $this->mDb->getOne("SELECT COUNT( `item_content_id` ) FROM `" . BIT_DB_PREFIX . "treasury_map` WHERE `item_content_id`=?", array($iid));
                 }
                 // Only delete item if it doesn't exist in other galleries
                 if ($count == 1) {
                     $itemObject->mContentId = $iid;
                     $itemObject->load();
                     if (!$itemObject->expunge()) {
                         $this->mErrors['expunge'][] = $itemObject->mErrors;
                     }
                 }
             }
             // Next, we remove any icons if they exist
             if ($thumbdir = $this->getGalleryThumbBaseUrl()) {
                 @unlink_r(BIT_ROOT_PATH . $thumbdir);
             }
             // Now that all the items are gone, we can start nuking gallery entries
             // remove gallery preferences
             $query = "DELETE FROM `" . BIT_DB_PREFIX . "liberty_content_prefs` WHERE `content_id`=?";
             $result = $this->mDb->query($query, array($this->mContentId));
             // Remove map entries
             $sql = "DELETE FROM `" . BIT_DB_PREFIX . "treasury_map` WHERE `gallery_content_id`=?";
             $rs = $this->mDb->query($sql, array($gid));
             // Remove gallery entry
             $sql = "DELETE FROM `" . BIT_DB_PREFIX . "treasury_gallery` WHERE `content_id`=?";
             $rs = $this->mDb->query($sql, array($gid));
             // Let liberty remove all the content entries for this gallery
             if (!LibertyContent::expunge()) {
                 $errors = TRUE;
             }
             // Finally nuke the structure in liberty_structures
             $struct->removeStructureNode($this->mStructureId, FALSE);
         }
         if (empty($errors)) {
             $this->mDb->CompleteTrans();
             $ret = TRUE;
         } else {
             $this->mDb->RollbackTrans();
             $ret = FALSE;
         }
     }
     return $ret;
 }
Example #11
0
function bit_files_expunge($pStorageId)
{
    global $gBitUser, $gBitSystem;
    $ret = FALSE;
    if (is_numeric($pStorageId)) {
        $sql = "SELECT * FROM `" . BIT_DB_PREFIX . "liberty_attachments` la\n\t\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_files` lf ON (lf.`file_id`=la.`foreign_id`)\n\t\t\t\tWHERE la.`attachment_id` = ?";
        if ($row = $gBitSystem->mDb->getRow($sql, array($pStorageId))) {
            $sourceFile = liberty_mime_get_source_file($row);
            if ($gBitUser->isAdmin() || $gBitUser->mUserId == $row['user_id']) {
                if (file_exists($sourceFile)) {
                    // make sure this is a valid storage directory before removing it
                    if (preg_match('!/users/\\d+/\\d+/\\w+/\\d+/.+!', $sourceFile)) {
                        unlink_r(dirname($sourceFile));
                    } else {
                        unlink($sourceFile);
                    }
                }
                $query = "DELETE FROM `" . BIT_DB_PREFIX . "liberty_files` WHERE `file_id` = ?";
                $gBitSystem->mDb->query($query, array($row['foreign_id']));
                $ret = TRUE;
            }
        }
    }
    return $ret;
}
Example #12
0
        if ($handle = fopen($tempfile, 'w')) {
            fwrite($handle, $content);
            fclose($handle);
            $pp['write']['result'] = 'ok';
            // extract archive
            $fileHash = array('tmp_name' => $tempfile, 'type' => 'application/zip', 'name' => 'temp.zip');
            if ($extracted = liberty_process_archive($fileHash)) {
                if (is_file($extracted . "/test.txt")) {
                    $pp['extract']['result'] = 'ok';
                    $dummyfile = BIT_ROOT_PATH . "___bitdummy.txt";
                    if (@rename($extracted . "/test.txt", $dummyfile)) {
                        $pp['replace']['result'] = 'ok';
                        unlink($dummyfile);
                    }
                }
                unlink_r($extracted);
            }
            // remove the testfile
            unlink($tempfile);
        }
    }
    // move
    if (@rename($testdir, $backup)) {
        rename($backup, $testdir);
        $pp['move']['result'] = 'ok';
    }
    // we are ready to advance a stage if the user wants to
    $gBitSmarty->assign('next_step', $step + 1);
    $app = "_done";
} else {
    $gBitSmarty->assign('next_step', $step);
Example #13
0
/**
 * All the files that have been extracted so far need to be processed and moved around
 * 
 * @param array $pStoreRow 
 * @access public
 * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
 */
function treasury_theme_process_extracted_files($pStoreRow)
{
    // if this is a theme, we need to convert the preview image into thumbnails
    if (!empty($pStoreRow['thumb'])) {
        $pStoreRow['thumb']['source_file'] = $pStoreRow['thumb']['tmp_name'];
        $pStoreRow['thumb']['dest_branch'] = $pStoreRow['upload']['dest_branch'];
        $pStoreRow['thumb']['dest_base_name'] = $pStoreRow['thumb']['name'];
        liberty_generate_thumbnails($pStoreRow['thumb']);
    }
    // if we have screenshots we better do something with them
    if (!empty($pStoreRow['screenshots'])) {
        foreach ($pStoreRow['screenshots'] as $key => $sshot) {
            $resizeFunc = liberty_get_function('resize');
            $sshot['source_file'] = $sshot['tmp_name'];
            $sshot['dest_base_name'] = $sshot['name'];
            $sshot['dest_branch'] = $pStoreRow['upload']['dest_branch'];
            $sshot['max_width'] = 400;
            $sshot['max_height'] = 300;
            $sshot['medium_thumb_path'] = BIT_ROOT_PATH . $resizeFunc($sshot);
        }
    }
    // if we have icons, we should place them somewhere that we can display them
    if (!empty($pStoreRow['icons'])) {
        @mkdir(BIT_ROOT_PATH . $pStoreRow['upload']['dest_branch'] . 'icons');
        foreach ($pStoreRow['icons'] as $icon) {
            $dest = BIT_ROOT_PATH . $pStoreRow['upload']['dest_branch'] . 'icons/' . basename($icon);
            if ($icon != $dest) {
                rename($icon, $dest);
            }
        }
    }
    // now that all is done, we can remove temporarily extracted files
    if (!empty($pStoreRow['ext_path'])) {
        unlink_r($pStoreRow['ext_path']);
    }
}
Example #14
0
/**
 * recursively remove files and directories
 *
 * @param string $pPath directory we want to remove
 * @param boolean $pFollowLinks follow symlinks or not
 * @access public
 * @return TRUE on success, FALSE on failure
 */
function unlink_r($pPath, $pFollowLinks = FALSE)
{
    if (!empty($pPath) && is_dir($pPath)) {
        if ($dir = opendir($pPath)) {
            while (FALSE !== ($entry = readdir($dir))) {
                if (is_file("{$pPath}/{$entry}") || !$pFollowLinks && is_link("{$pPath}/{$entry}")) {
                    unlink("{$pPath}/{$entry}");
                } elseif (is_dir("{$pPath}/{$entry}") && $entry != '.' && $entry != '..') {
                    unlink_r("{$pPath}/{$entry}");
                }
            }
            closedir($dir);
        }
        return @rmdir($pPath);
    }
}
Example #15
0
 /**
  * clearCache 
  * 
  * @access public
  * @return void
  */
 function clearCache()
 {
     unlink_r(TEMP_PKG_PATH . "lang/");
     unlink_r(TEMP_PKG_PATH . "templates_c/");
 }
Example #16
0
/**
 * Recursively builds a tree where each directory represents a gallery, and files are assumed to be images.
 */
function fisheye_process_directory($pDestinationDir, &$pParentGallery, $pRoot = FALSE)
{
    global $gBitSystem, $gBitUser;
    $errors = array();
    if ($archiveDir = opendir($pDestinationDir)) {
        $order = 100;
        while ($fileName = readdir($archiveDir)) {
            $sortedNames[] = $fileName;
        }
        sort($sortedNames);
        foreach ($sortedNames as $fileName) {
            if ($fileName == 'Thumbs.db') {
                unlink("{$pDestinationDir}/{$fileName}");
            }
            if (!preg_match('/^\\./', $fileName) && $fileName != 'Thumbs.db') {
                $mimeResults = $gBitSystem->verifyFileExtension($pDestinationDir . '/' . $fileName);
                $scanFile = array('type' => $mimeResults[1], 'name' => $fileName, 'size' => filesize("{$pDestinationDir}/{$fileName}"), 'tmp_name' => "{$pDestinationDir}/{$fileName}");
                if (!empty($_REQUEST['resize']) && is_numeric($_REQUEST['resize'])) {
                    $scanFile['max_height'] = $scanFile['max_width'] = $_REQUEST['resize'];
                }
                if (is_dir($pDestinationDir . '/' . $fileName)) {
                    if ($fileName == '__MACOSX') {
                        // Mac OS resources file
                        unlink_r($pDestinationDir . '/' . $fileName);
                    } else {
                        // We found a new Gallery!
                        $newGallery = new FisheyeGallery();
                        $galleryHash = array('title' => str_replace('_', ' ', $fileName));
                        if ($newGallery->store($galleryHash)) {
                            if ($pRoot) {
                                $newGallery->addToGalleries($_REQUEST['gallery_additions']);
                            }
                            if (is_object($pParentGallery)) {
                                $pParentGallery->addItem($newGallery->mContentId, $order);
                            }
                            //recurse down in!
                            $errors = array_merge($errors, fisheye_process_archive($scanFile, $newGallery));
                        } else {
                            $errors = array_merge($errors, array_values($newGallery->mErrors));
                        }
                    }
                } elseif (preg_match('/.+\\/*zip*/', $scanFile['type'])) {
                    //recurse down in!
                    $errors = array_merge($errors, fisheye_process_archive($scanFile, $pParentGallery));
                } elseif (fisheye_verify_upload_item($scanFile)) {
                    $newImage = new FisheyeImage();
                    $imageHash = array('_files_override' => array($scanFile));
                    if ($newImage->store($imageHash)) {
                        if ($pRoot) {
                            $newImage->addToGalleries($_REQUEST['gallery_additions']);
                        }
                        if (!is_object($pParentGallery)) {
                            global $gBitUser;
                            $pParentGallery = new FisheyeGallery(fisheye_get_default_gallery_id($gBitUser->mUserId, $gBitUser->getDisplayName() . "'s Gallery"));
                            $pParentGallery->load();
                        }
                        $pParentGallery->addItem($newImage->mContentId);
                    } else {
                        $errors = array_merge($errors, array_values($newImage->mErrors));
                    }
                } elseif (is_file($scanFile['tmp_name'])) {
                    // unknown file type, let's be tidy and clean it up
                    unlink($scanFile['tmp_name']);
                }
                $order += 10;
            }
        }
        if (!is_windows()) {
            unlink_r($pDestinationDir);
        }
    }
    return $errors;
}