Ejemplo n.º 1
0
<?php

$FieldTag = new PerchXMLTag('<perch:content id="image" type="image" disable-asset-panel="true" app-mode="true" detect-type="true" />');
$FieldTag->set('input_id', 'image');
$Assets = new PerchAssets_Assets();
$Tags = new PerchAssets_Tags();
$Form = new PerchForm('edit');
$message = false;
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
    $assetID = (int) $_GET['id'];
    $Asset = $Assets->find($assetID);
    if ($Asset) {
        if (!$Asset->is_image()) {
            $FieldTag->set('type', 'file');
        }
    }
} else {
    if (!$CurrentUser->has_priv('assets.create')) {
        PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/assets/');
    }
    $assetID = false;
    $Asset = false;
}
$Form = new PerchForm('edit');
$req = array();
$req['resourceTitle'] = "Required";
$Form->set_required($req);
if ($Form->posted() && $Form->validate()) {
    /*
    if (isset($_POST['image_remove']) && $_POST['image_remove']=='1') {
        $Asset->delete();
Ejemplo n.º 2
0
<?php

require '../../../../../core/inc/api.php';
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';
}
if (PerchUtil::count($_FILES)) {
    $Tag = new PerchXMLTag('<perch:content id="miu_image_upload_image" disable-asset-panel="true" detect-type="true" />');
    $Tag->set('input_id', 'miu_image_upload_image');
    $API = new PerchAPI(1.0, 'miu_image_upload');
    if ($_POST['image'] == 'false') {
        $is_image = false;
        $Tag->set('type', 'file');
    } else {
        $is_image = true;
        $Tag->set('type', 'image');
    }
    /* -------- GET THE RESOURCE BUCKET TO USE ---------- */
    $bucket_name = 'default';
    if (isset($_POST['bucket']) && $_POST['bucket'] != '') {
        $bucket_name = $_POST['bucket'];
    }
    $Tag->set('bucket', $bucket_name);
    if ($is_image) {
        $width = false;
        if (isset($_POST['width'])) {
            $width = (int) $_POST['width'];
        }
        $Tag->set('width', $width);
        $height = false;
Ejemplo n.º 3
0
<?php

header('Content-Type: application/json');
$FieldTag = new PerchXMLTag('<perch:content id="file" type="image" disable-asset-panel="true" detect-type="true" accept="all" />');
$FieldTag->set('input_id', 'file');
if (isset($_POST['bucket']) && !empty($_POST['bucket'])) {
    $FieldTag->set('bucket', $_POST['bucket']);
}
if (!$CurrentUser->has_priv('assets.create')) {
    die;
}
$Assets = new PerchAssets_Assets();
$message = false;
$assetID = false;
$Asset = false;
$Form = new PerchForm('edit');
if (PerchUtil::count($_FILES)) {
    //PerchUtil::debug($_FILES);
    $Resources = new PerchResources();
    $data = array();
    $FieldType = PerchFieldTypes::get($FieldTag->type(), $Form, $FieldTag, null, 'assets');
    $var = $FieldType->get_raw();
    if (PerchUtil::count($var)) {
        $ids = $Resources->get_logged_ids();
        $assetID = $ids[0];
        $Asset = $Assets->find($assetID);
        $Asset->reindex();
        //PerchUtil::debug($ids);
        if (PerchUtil::count($ids)) {
            if (!PerchSession::is_set('resourceIDs')) {
                $logged_ids = array();
Ejemplo n.º 4
0
 public function find_all_tags_and_repeaters($type = 'content', $contents = false)
 {
     $template = $this->template;
     $path = $this->file;
     if ($contents === false) {
         $contents = $this->load();
     }
     $untouched_content = $contents;
     $out = array();
     // Excluded tags are discarded
     $tag_pairs_to_exclude = array();
     $tag_pairs_with_empty_openers = array('blocks');
     //	List of tags to process. Blocks needs to come before others, as blocks can contain e.g. repeaters.
     $tag_pairs_to_process = array('blocks', 'repeater');
     if (PERCH_RUNWAY) {
         $tag_pairs_to_process[] = 'related';
     }
     // Add excluded tags so they can be discarded.
     $tag_pairs_to_process = array_merge($tag_pairs_to_process, $tag_pairs_to_exclude);
     foreach ($tag_pairs_to_process as $tag_type) {
         // parse out tag pairs
         $empty_opener = in_array($tag_type, $tag_pairs_with_empty_openers);
         $close_tag = '</perch:' . $tag_type . '>';
         $close_tag_len = mb_strlen($close_tag);
         $open_tag = '<perch:' . $tag_type . ($empty_opener ? '' : ' ');
         $order = 1;
         // escape hatch
         $i = 0;
         $max_loops = 100;
         // loop through while we have closing tags
         while ($close_pos = mb_strpos($contents, $close_tag)) {
             // we always have to go from the start, as the string length changes,
             // but stop at the closing tag
             $chunk = mb_substr($contents, 0, $close_pos);
             // search from the back of the chunk for the opening tag
             $open_pos = mb_strrpos($chunk, $open_tag);
             // get the pair html chunk
             $len = $close_pos + $close_tag_len - $open_pos;
             $pair_html = mb_substr($contents, $open_pos, $len);
             // find the opening tag - it's right at the start
             $opening_tag_end_pos = mb_strpos($pair_html, '>') + 1;
             $opening_tag = mb_substr($pair_html, 0, $opening_tag_end_pos);
             // condition contents
             $condition_contents = mb_substr($pair_html, $opening_tag_end_pos, 0 - $close_tag_len);
             // Do the business
             $OpeningTag = new PerchXMLTag($opening_tag);
             $tmp = array();
             if ($tag_type == 'repeater') {
                 $Repeater = new PerchRepeater($OpeningTag->attributes);
                 $Repeater->set('id', $OpeningTag->id());
                 //$Repeater->tags = $this->find_all_tags($type, $condition_contents);
                 $Repeater->tags = $this->find_all_tags_and_repeaters($type, $condition_contents);
                 $tmp['tag'] = $Repeater;
             } elseif ($tag_type == 'blocks') {
                 $OpeningTag->set('id', '_blocks');
                 $OpeningTag->set('type', 'PerchBlocks');
                 $tmp['tag'] = $OpeningTag;
             } else {
                 $tmp['tag'] = $OpeningTag;
             }
             // Set the order
             if ($OpeningTag->order()) {
                 $tmp['order'] = (int) $OpeningTag->order();
             } else {
                 $tmp['order'] = strpos($untouched_content, $opening_tag);
             }
             // If the tag isn't one to strip/exclude, add it to the list.
             if (!in_array($tag_type, $tag_pairs_to_exclude)) {
                 $out[] = $tmp;
             }
             // Remove the pair so we can parse the next one
             $contents = str_replace($pair_html, '', $contents);
             // escape hatch counter
             $i++;
             if ($i > $max_loops) {
                 return $contents;
             }
         }
     }
     $s = '/<perch:(' . $type . '|categories)[^>]*>/';
     $count = preg_match_all($s, $contents, $matches);
     if ($count > 0) {
         $i = 100;
         if (is_array($matches[0])) {
             foreach ($matches[0] as $match) {
                 $tmp = array();
                 $tmp['tag'] = new PerchXMLTag($match);
                 if (!in_array('categories', $this->disabled_features)) {
                     if ($tmp['tag']->tag_name() == 'perch:categories') {
                         $tmp['tag']->set('type', 'category');
                     }
                 }
                 if ($tmp['tag']->tag_name() == 'perch:related') {
                     $tmp['tag']->set('type', 'related');
                 }
                 if ($tmp['tag']->type() != 'repeater') {
                     if ($tmp['tag']->order()) {
                         $tmp['order'] = (int) $tmp['tag']->order();
                     } else {
                         $tmp['order'] = strpos($untouched_content, $match);
                         #PerchUtil::debug('Setting order to: '.$tmp['order']);
                         $i++;
                     }
                     $out[] = $tmp;
                 }
             }
         }
     }
     if (PerchUtil::count($out)) {
         // sort tags using 'order' attribute
         $out = PerchUtil::array_sort($out, 'order');
         $final = array();
         foreach ($out as $tag) {
             $final[] = $tag['tag'];
         }
         return $final;
     }
     return false;
 }
Ejemplo n.º 5
0
        }
    }
    if (isset($_POST['logo_remove']) && $_POST['logo_remove'] == '1') {
        $data['logoPath'] = '';
    }
    foreach ($data as $key => $value) {
        $Settings->set($key, $value);
    }
    $Lang = PerchLang::fetch();
    $Lang->reload();
    $Alert->set('success', PerchLang::get("Your settings have been updated."));
    // image upload
    if (isset($_FILES['customlogo']) && (int) $_FILES['customlogo']['size'] > 0) {
        // new
        $FieldTag = new PerchXMLTag('<perch:content id="customlogo" type="image" disable-asset-panel="true" detect-type="true" accept="webimage" />');
        $FieldTag->set('input_id', 'customlogo');
        $Assets = new PerchAssets_Assets();
        $Resources = new PerchResources();
        $FieldType = PerchFieldTypes::get($FieldTag->type(), $Form, $FieldTag, false, 'system');
        $var = $FieldType->get_raw();
        if (PerchUtil::count($var)) {
            $ids = $Resources->get_logged_ids();
            $assetID = $ids[0];
            $Asset = $Assets->find($assetID);
            $Asset->reindex();
            $Asset->mark_as_library();
            $Settings->set('logoPath', $Asset->web_path());
        }
    }
    $Settings->reload();
}
Ejemplo n.º 6
0
<?php

# include the API
include '../../../../../core/inc/api.php';
# include Assets
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';
}
/* -------- SET UP TEMPLATE TAG ---------- */
$Tag = new PerchXMLTag('<perch:content id="file" disable-asset-panel="true" detect-type="true" />');
$Tag->set('input_id', 'file');
$API = new PerchAPI(1.0, 'redactorjs');
if (isset($_GET['filetype']) && $_GET['filetype'] == 'image') {
    $is_image = true;
    $Tag->set('type', 'image');
} else {
    $is_image = false;
    $Tag->set('type', 'file');
}
/* -------- GET THE RESOURCE BUCKET TO USE ---------- */
$bucket_name = 'default';
if (isset($_POST['bucket']) && $_POST['bucket'] != '') {
    $bucket_name = $_POST['bucket'];
}
if ($is_image) {
    $width = 800;
    if (isset($_POST['width']) && $_POST['width'] != '') {
        $width = (int) $_POST['width'];
    }
    $Tag->set('width', $width);