예제 #1
0
    $do_list_collapse = false;
    $show_shared = false;
}
if (isset($_GET['template']) && $_GET['template'] != '') {
    $filter = 'template';
    $do_regions = true;
    $do_list_collapse = false;
    $show_shared = true;
    $template_to_filter = urldecode($_GET['template']);
}
// Get pages
if ($do_list_collapse) {
    $expand_list = array(0);
    // get the existing expand list
    if (PerchSession::is_set('content_expand_list')) {
        $expand_list = PerchSession::get('content_expand_list');
    }
    // find any new actions
    if (isset($_GET['ex']) && $_GET['ex'] != '') {
        // expand
        $actionID = (int) $_GET['ex'];
        $current_index = array_search($actionID, $expand_list);
        if ($current_index === false) {
            $expand_list[] = $actionID;
        }
    }
    if (isset($_GET['cl']) && $_GET['cl'] != '') {
        // close
        $actionID = (int) $_GET['cl'];
        $current_index = array_search($actionID, $expand_list);
        if ($current_index !== false) {
예제 #2
0
        }
        if (PerchUtil::count($msgs)) {
            foreach ($msgs as $msg) {
                echo '<li class="failure icon"><strong>Error:</strong> ' . PerchUtil::html($msg) . '</li>';
            }
        }
        if ($db_fail || PerchUtil::count($msgs)) {
            echo '<li class="failure icon">Creating database tables&hellip; <strong>Unable to create database tables.</strong></li>';
            echo '</ul>';
            echo '<p>The most likely cause is that your database access details aren\'t quite right. Please double check them. Note that some hosting control panel software (like cPanel) will prefix the database name with your account name. So if you created a new database called <code>' . PERCH_DB_DATABASE . '</code> the full name could be something like <code>accountname_' . PERCH_DB_DATABASE . '</code>.</p>';
            echo '<p>If you\'re still have trouble, it\'s possible that the MySQL user hasn\'t got enough access rights to create tables. Change this, if you can, <a href="index.php?install=1">then reload this page</a>.</p>';
            echo '<p>Still no success? <a href="https://grabaperch.com/support">Drop us a line</a> and we\'ll see if we can help.</p>';
        } else {
            echo '<li class="success icon">Creating database tables&hellip; done.</li>';
            $Users = new PerchUsers();
            $data = PerchSession::get('user');
            $data['userMasterAdmin'] = '1';
            $data['roleID'] = '2';
            $data['userCreated'] = date('Y-m-d H:i:s');
            if ($Users->no_master_admin_exists()) {
                $Users->create($data, false);
                echo '<li class="success icon">Setting up initial user account&hellip; done.</li>';
            } else {
                echo '<li class="success icon">Setting up initial user account&hellip; user already exists.</li>';
            }
            ?>
                <li class="success icon"><strong>Setup complete.</strong></li>
            </ul>

                <h2>Next steps</h2>
예제 #3
0
 $var = $FieldType->get_raw();
 if (PerchUtil::count($var)) {
     $ids = $Resources->get_logged_ids();
     $Resources->mark_group_as_library($ids);
     $assetID = $ids[0];
     $Asset = $Assets->find($assetID);
     if (isset($_POST['miu_image_upload_title']) && $_POST['miu_image_upload_title'] != '') {
         $Asset->update(array('resourceTitle' => $_POST['miu_image_upload_title']));
     }
     $Asset->reindex();
     if (PerchUtil::count($ids)) {
         if (!PerchSession::is_set('resourceIDs')) {
             $logged_ids = array();
             PerchSession::set('resourceIDs', $logged_ids);
         } else {
             $logged_ids = PerchSession::get('resourceIDs');
         }
         foreach ($ids as $assetID) {
             if (!in_array($assetID, $logged_ids)) {
                 $logged_ids[] = $assetID;
             }
         }
         PerchSession::set('resourceIDs', $logged_ids);
     }
     if ($is_image) {
         $result = $Assets->get_resize_profile($Asset->id(), $width, $height, $crop ? '1' : '0', false, $density);
         if ($result) {
             echo $result['web_path'];
         } else {
             echo $Asset->web_path();
         }
 public function recover()
 {
     if (PerchSession::is_set('userID')) {
         $sql = 'SELECT u.*, r.* FROM ' . $this->table . ' u, ' . PERCH_DB_PREFIX . 'user_roles r
                     WHERE u.roleID=r.roleID AND u.userEnabled=1 AND u.userID=' . $this->db->pdb((int) PerchSession::get('userID')) . ' AND u.userHash=' . $this->db->pdb(PerchSession::get('userHash')) . '
                     LIMIT 1';
         $result = $this->db->get_row($sql);
         if (is_array($result)) {
             $this->set_details($result);
             $data = array();
             $data['userHash'] = md5(uniqid());
             $this->update($data);
             $this->result['userHash'] = $data['userHash'];
             $this->set_details($result);
             PerchSession::set('userHash', $data['userHash']);
             $this->logged_in = true;
             $this->_load_privileges();
             return true;
         }
     }
     $this->logged_in = false;
     $this->privileges = array();
     return false;
 }
 public function submit($id, $value, $class = false, $translate = true, $use_button = false)
 {
     $Perch = PerchAdmin::fetch();
     if ($this->display_only) {
         if ($this->allow_edits) {
             $segments = str_replace('/editform=' . $this->name, '', split('/', $Perch->get_page(true)));
             $segments[] = 'editform=' . $this->name;
             $url = implode('/', $segments);
             $url = str_replace('//', '/', $url);
             return '<a href="' . $url . '" class="button" id="' . $this->html($id, true) . '">Edit</a>';
         }
         return '';
     }
     if ($translate) {
         $value = PerchLang::get($value);
     }
     if ($use_button) {
         $s = '<button type="submit" name="' . $this->html($id, true) . '" id="' . $this->html($id, true) . '" value="' . $this->html($value, true) . '" class="' . $this->html($class, true) . '"><span></span>' . $this->html($value, true) . '</button>';
     } else {
         $s = '<input type="submit" name="' . $this->html($id, true) . '" id="' . $this->html($id, true) . '" value="' . $this->html($value, true) . '" class="' . $this->html($class, true) . '" />';
     }
     $s .= '<input type="hidden" name="formaction" value="' . $this->html($this->name, true) . '" />';
     $s .= '<input type="hidden" name="token" value="' . $this->html(PerchSession::get('csrf_token'), true) . '" />';
     return $s;
 }
예제 #6
0
파일: upload.php 프로젝트: pete-naish/4hair
    Then store the file name in the session for future chunks to reference.
*/
if ($chunk === 0) {
    if (file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName)) {
        $ext = strrpos($fileName, '.');
        $fileName_a = substr($fileName, 0, $ext);
        $fileName_b = strtolower(substr($fileName, $ext));
        $count = 1;
        while (file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName_a . '-' . $count . $fileName_b)) {
            $count++;
        }
        $fileName = $fileName_a . '-' . $count . $fileName_b;
    }
    PerchSession::set($originalFileName, $fileName);
} else {
    $fileName = PerchSession::get($originalFileName);
}
// add a _uploading_ prefix while we're uploading. We'll remove it later.
$fileName = '_uploading_' . $fileName;
// Look for the content type header
if (isset($_SERVER["HTTP_CONTENT_TYPE"])) {
    $contentType = $_SERVER["HTTP_CONTENT_TYPE"];
}
if (isset($_SERVER["CONTENT_TYPE"])) {
    $contentType = $_SERVER["CONTENT_TYPE"];
}
// Handle non multipart uploads older WebKit versions didn't support multipart in HTML5
if (strpos($contentType, "multipart") !== false) {
    if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
        // Open temp file
        $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
 public function get_raw($post = false, $Item = false)
 {
     $store = array();
     $Perch = Perch::fetch();
     $Bucket = PerchResourceBuckets::get($this->Tag->bucket());
     $image_folder_writable = $Bucket->ready_to_write();
     $item_id = $this->Tag->input_id();
     $asset_reference_used = false;
     $target = false;
     $filesize = false;
     if (!class_exists('PerchAssets_Assets', false)) {
         include_once PERCH_CORE . '/apps/assets/PerchAssets_Assets.class.php';
         include_once PERCH_CORE . '/apps/assets/PerchAssets_Asset.class.php';
     }
     $Assets = new PerchAssets_Assets();
     $AssetMeta = false;
     // Asset ID?
     if (isset($post[$this->Tag->id() . '_assetID']) && $post[$this->Tag->id() . '_assetID'] != '') {
         $new_assetID = $post[$this->Tag->id() . '_assetID'];
         $Asset = $Assets->find($new_assetID);
         if (is_object($Asset)) {
             $target = $Asset->file_path();
             $filename = $Asset->resourceFile();
             $store['assetID'] = $Asset->id();
             $store['title'] = $Asset->resourceTitle();
             $store['_default'] = $Asset->web_path();
             $store['bucket'] = $Asset->resourceBucket();
             if ($store['bucket'] != $Bucket->get_name()) {
                 $Bucket = PerchResourceBuckets::get($store['bucket']);
             }
             $asset_reference_used = true;
         }
     }
     if ($image_folder_writable && isset($_FILES[$item_id]) && (int) $_FILES[$item_id]['size'] > 0) {
         if (!isset(self::$file_paths[$this->Tag->id()])) {
             // We do this before writing to the bucket, as it performs better for remote buckets.
             $AssetMeta = $Assets->get_meta_data($_FILES[$item_id]['tmp_name'], $_FILES[$item_id]['name']);
             $result = $Bucket->write_file($_FILES[$item_id]['tmp_name'], $_FILES[$item_id]['name']);
             $target = $result['path'];
             $filename = $result['name'];
             $filesize = (int) $_FILES[$item_id]['size'];
             $store['_default'] = rtrim($Bucket->get_web_path(), '/') . '/' . $filename;
             // fire events
             if ($this->Tag->type() == 'image') {
                 $PerchImage = new PerchImage();
                 $profile = $PerchImage->get_resize_profile($target);
                 $profile['original'] = true;
                 $Perch->event('assets.upload_image', new PerchAssetFile($profile));
             }
         }
     }
     if ($target && $filename && is_file($target)) {
         self::$file_paths[$this->Tag->id()] = $target;
         $store['path'] = $filename;
         $store['size'] = $filesize ?: filesize($target);
         $store['bucket'] = $Bucket->get_name();
         // Is this an SVG?
         $svg = false;
         $size = getimagesize($target);
         if (PerchUtil::count($size)) {
             $store['w'] = $size[0];
             $store['h'] = $size[1];
             if (isset($size['mime'])) {
                 $store['mime'] = $size['mime'];
             }
         } else {
             $PerchImage = new PerchImage();
             if ($PerchImage->is_webp($target)) {
                 $store['mime'] = 'image/webp';
             } elseif ($PerchImage->is_svg($target)) {
                 $svg = true;
                 $size = $PerchImage->get_svg_size($target);
                 if (PerchUtil::count($size)) {
                     $store['w'] = $size['w'];
                     $store['h'] = $size['h'];
                     if (isset($size['mime'])) {
                         $store['mime'] = $size['mime'];
                     }
                 }
             } else {
                 // It's not an image (according to getimagesize) and not an SVG.
                 if ($this->Tag->detect_type()) {
                     // if we have permission to guess, our guess is that it's a file.
                     PerchUtil::debug('Guessing file', 'error');
                     $this->Tag->set('type', 'file');
                 }
                 $store['mime'] = PerchUtil::get_mime_type($target);
             }
         }
         // thumbnail
         if ($this->Tag->type() == 'image') {
             $PerchImage = new PerchImage();
             $PerchImage->set_density(2);
             $result = false;
             if ($asset_reference_used) {
                 $result = $Assets->get_resize_profile($store['assetID'], 150, 150, false, 'thumb', $PerchImage->get_density());
             }
             if (!$result) {
                 $result = $PerchImage->resize_image($target, 150, 150, false, 'thumb');
             }
             if (is_array($result)) {
                 //PerchUtil::debug($result, 'notice');
                 if (!isset($store['sizes'])) {
                     $store['sizes'] = array();
                 }
                 $variant_key = 'thumb';
                 $tmp = array();
                 $tmp['w'] = $result['w'];
                 $tmp['h'] = $result['h'];
                 $tmp['target_w'] = 150;
                 $tmp['target_h'] = 150;
                 $tmp['density'] = 2;
                 $tmp['path'] = $result['file_name'];
                 $tmp['size'] = filesize($result['file_path']);
                 $tmp['mime'] = isset($result['mime']) ? $result['mime'] : '';
                 if ($result && isset($result['_resourceID'])) {
                     $tmp['assetID'] = $result['_resourceID'];
                 }
                 $store['sizes'][$variant_key] = $tmp;
             }
             unset($result);
             unset($PerchImage);
         }
         if ($this->Tag->type() == 'file') {
             $PerchImage = new PerchImage();
             $PerchImage->set_density(2);
             $result = $PerchImage->thumbnail_file($target, 150, 150, false);
             if (is_array($result)) {
                 if (!isset($store['sizes'])) {
                     $store['sizes'] = array();
                 }
                 $variant_key = 'thumb';
                 $tmp = array();
                 $tmp['w'] = $result['w'];
                 $tmp['h'] = $result['h'];
                 $tmp['target_w'] = 150;
                 $tmp['target_h'] = 150;
                 $tmp['density'] = 2;
                 $tmp['path'] = $result['file_name'];
                 $tmp['size'] = filesize($result['file_path']);
                 $tmp['mime'] = isset($result['mime']) ? $result['mime'] : '';
                 if ($result && isset($result['_resourceID'])) {
                     $tmp['assetID'] = $result['_resourceID'];
                 }
                 $store['sizes'][$variant_key] = $tmp;
             }
             unset($result);
             unset($PerchImage);
         }
     }
     // Loop through all tags with this ID, get their dimensions and resize the images.
     $all_tags = $this->get_sibling_tags();
     if (PerchUtil::count($all_tags)) {
         foreach ($all_tags as $Tag) {
             if ($Tag->id() == $this->Tag->id()) {
                 // This is either this tag, or another tag in the template with the same ID.
                 if ($Tag->type() == 'image' && ($Tag->width() || $Tag->height()) && isset(self::$file_paths[$Tag->id()])) {
                     $variant_key = 'w' . $Tag->width() . 'h' . $Tag->height() . 'c' . ($Tag->crop() ? '1' : '0') . ($Tag->density() ? '@' . $Tag->density() . 'x' : '');
                     if (!isset($store['sizes'][$variant_key])) {
                         $PerchImage = new PerchImage();
                         if ($Tag->quality()) {
                             $PerchImage->set_quality($Tag->quality());
                         }
                         if ($Tag->is_set('sharpen')) {
                             $PerchImage->set_sharpening($Tag->sharpen());
                         }
                         if ($Tag->density()) {
                             $PerchImage->set_density($Tag->density());
                         }
                         $result = false;
                         if ($asset_reference_used) {
                             $result = $Assets->get_resize_profile($store['assetID'], $Tag->width(), $Tag->height(), $Tag->crop(), false, $PerchImage->get_density());
                         }
                         if (!$result) {
                             $result = $PerchImage->resize_image(self::$file_paths[$Tag->id()], $Tag->width(), $Tag->height(), $Tag->crop());
                         }
                         if (is_array($result)) {
                             if (!isset($store['sizes'])) {
                                 $store['sizes'] = array();
                             }
                             $tmp = array();
                             $tmp['w'] = $result['w'];
                             $tmp['h'] = $result['h'];
                             $tmp['target_w'] = $Tag->width();
                             $tmp['target_h'] = $Tag->height();
                             $tmp['crop'] = $Tag->crop();
                             $tmp['density'] = $Tag->density() ? $Tag->density() : '1';
                             $tmp['path'] = $result['file_name'];
                             $tmp['size'] = filesize($result['file_path']);
                             $tmp['mime'] = isset($result['mime']) ? $result['mime'] : '';
                             if ($result && isset($result['_resourceID'])) {
                                 $tmp['assetID'] = $result['_resourceID'];
                             }
                             $store['sizes'][$variant_key] = $tmp;
                             unset($tmp);
                         }
                         unset($result);
                         unset($PerchImage);
                     }
                 }
             }
         }
     }
     if (isset($_POST[$item_id . '_remove'])) {
         $store = array();
     }
     // If a file isn't uploaded...
     if (!$asset_reference_used && (!isset($_FILES[$item_id]) || (int) $_FILES[$item_id]['size'] == 0)) {
         // If remove is checked, remove it.
         if (isset($_POST[$item_id . '_remove'])) {
             $store = array();
         } else {
             // Else get the previous data and reuse it.
             if (is_object($Item)) {
                 $json = PerchUtil::json_safe_decode($Item->itemJSON(), true);
                 if (PerchUtil::count($json) && $this->Tag->in_repeater() && $this->Tag->tag_context()) {
                     $waypoints = preg_split('/_([0-9]+)_/', $this->Tag->tag_context(), null, PREG_SPLIT_DELIM_CAPTURE);
                     if (PerchUtil::count($waypoints) > 0) {
                         $subject = $json;
                         foreach ($waypoints as $waypoint) {
                             if (isset($subject[$waypoint])) {
                                 $subject = $subject[$waypoint];
                             } else {
                                 $subject = false;
                             }
                             $store = $subject;
                         }
                     }
                 }
                 if (PerchUtil::count($json) && isset($json[$this->Tag->id()])) {
                     $store = $json[$this->Tag->id()];
                 }
             } else {
                 if (is_array($Item)) {
                     $json = $Item;
                     if (PerchUtil::count($json) && isset($json[$this->Tag->id()])) {
                         $store = $json[$this->Tag->id()];
                     }
                 }
             }
         }
     }
     // log resources
     if (PerchUtil::count($store) && isset($store['path'])) {
         $Resources = new PerchResources();
         // Main image
         $parentID = $Resources->log($this->app_id, $store['bucket'], $store['path'], 0, 'orig', false, $store, $AssetMeta);
         // variants
         if (isset($store['sizes']) && PerchUtil::count($store['sizes'])) {
             foreach ($store['sizes'] as $key => $size) {
                 $Resources->log($this->app_id, $store['bucket'], $size['path'], $parentID, $key, false, $size, $AssetMeta);
             }
         }
         // Additional IDs from the session
         if (PerchSession::is_set('resourceIDs')) {
             $ids = PerchSession::get('resourceIDs');
             if (is_array($ids) && PerchUtil::count($ids)) {
                 $Resources->log_extra_ids($ids);
             }
             PerchSession::delete('resourceIDs');
         }
     }
     self::$file_paths = array();
     // Check it's not an empty array
     if (is_array($store) && count($store) === 0) {
         return null;
     }
     return $store;
 }