public function get_index($items)
 {
     if (PerchUtil::count($items) && PerchUtil::count($this->tags)) {
         $index = array();
         foreach ($this->tags as $Tag) {
             $FieldType = PerchFieldTypes::get($Tag->type(), false, $Tag);
             foreach ($items as $item) {
                 foreach ($item as $key => $val) {
                     if ($key == $Tag->id()) {
                         $field_index = $FieldType->get_index($val);
                         if (PerchUtil::count($field_index)) {
                             foreach ($field_index as $field_index_item) {
                                 if ($key == $field_index_item['key']) {
                                     $indexing_key = $this->id() . '.' . $key;
                                 } else {
                                     $indexing_key = $this->id() . '.' . $key . '.' . $field_index_item['key'];
                                 }
                                 $index[] = array('key' => $indexing_key, 'value' => $field_index_item['value']);
                             }
                         }
                     }
                 }
             }
         }
         return $index;
     }
     return false;
 }
示例#2
0
 /*
 if (isset($_POST['image_remove']) && $_POST['image_remove']=='1') {
     $Asset->delete();
     PerchUtil::redirect()
 }
 */
 $created = false;
 $postvars = array('resourceTitle', 'resourceInLibrary', 'resourceBucket');
 $data = $Form->receive($postvars);
 if (isset($data['resourceBucket'])) {
     $FieldTag->set('bucket', $data['resourceBucket']);
 }
 if (!isset($data['resourceInLibrary'])) {
     $data['resourceInLibrary'] = 0;
 }
 $FieldType = PerchFieldTypes::get($FieldTag->type(), $Form, $FieldTag);
 $var = $FieldType->get_raw();
 if (PerchUtil::count($var)) {
     $Resources = new PerchResources();
     $ids = $Resources->get_logged_ids();
     $assetID = array_shift($ids);
     $Asset = $Assets->find($assetID);
     $created = true;
 }
 if ($Asset) {
     if ($data['resourceInLibrary'] == '1') {
         $Asset->mark_as_library();
     }
     $Asset->update($data);
     $Asset->reindex();
     // Tags
示例#3
0
     }
     $Tag->set('sharpen', $sharpen);
     $density = 1;
     if (isset($_POST['density'])) {
         $density = (int) $_POST['density'];
     }
     $Tag->set('density', $density);
 }
 $Assets = new PerchAssets_Assets();
 $message = false;
 $assetID = false;
 $Asset = false;
 $Form = new PerchForm('edit');
 $Resources = new PerchResources();
 $data = array();
 $FieldType = PerchFieldTypes::get($Tag->type(), $Form, $Tag, array($Tag), 'markitup');
 $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 {
示例#4
0
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();
                PerchSession::set('resourceIDs', $logged_ids);
            } else {
                $logged_ids = PerchSession::get('resourceIDs');
            }
            foreach ($ids as $assetID) {
         if (isset($item[$col['id']])) {
             $title = $item[$col['id']];
         } else {
             if ($first) {
                 if (isset($item['_title'])) {
                     $title = $item['_title'];
                 } else {
                     $title = PerchLang::get('Item') . ' ' . $i;
                 }
             } else {
                 $title = '-';
             }
         }
     }
     if ($col['Tag']) {
         $FieldType = PerchFieldTypes::get($col['Tag']->type(), false, $col['Tag']);
         $title = $FieldType->render_admin_listing($title);
         if ($col['Tag']->format()) {
             $title = $Template->format_value($col['Tag'], $title);
         }
     }
     if ($first && trim($title) == '') {
         $title = '#' . $item['_id'];
     }
     echo $title;
     if ($first) {
         echo '</a>';
     }
     echo '</td>';
     $first = false;
 }
示例#6
0
    }
    $Tag->set('sharpen', $sharpen);
    $density = 1;
    if (isset($_POST['density']) && $_POST['density'] != '') {
        $density = (int) $_POST['density'];
    }
    $Tag->set('density', $density);
}
$Assets = new PerchAssets_Assets();
$message = false;
$assetID = false;
$Asset = false;
$Form = new PerchForm('edit');
$Resources = new PerchResources();
$data = array();
$FieldType = PerchFieldTypes::get($Tag->type(), $Form, $Tag, array($Tag));
$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);
    $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) {
 /**
  * Add the content of this region into the content index
  * @param  boolean $item_id [description]
  * @param  boolean $rev [description]
  * @return [type]       [description]
  */
 public function index($rev = false)
 {
     if ($rev === false) {
         $rev = $this->regionLatestRev();
     }
     $Items = new PerchContent_Items();
     // clear out old items
     $sql = 'DELETE FROM ' . PERCH_DB_PREFIX . 'content_index 
             WHERE regionID=' . $this->db->pdb((int) $this->id()) . ' AND itemRev<' . $this->db->pdb((int) $Items->get_oldest_rev($this->id()));
     $this->db->execute($sql);
     $items = $Items->get_for_region($this->id(), $rev);
     if (PerchUtil::count($items)) {
         $sql = 'DELETE FROM ' . PERCH_DB_PREFIX . 'content_index 
                 WHERE regionID=' . $this->db->pdb((int) $this->id()) . ' AND itemRev=' . $this->db->pdb((int) $rev);
         $this->db->execute($sql);
         $Template = new PerchTemplate('content/' . $this->regionTemplate(), 'content');
         $tags = $Template->find_all_tags_and_repeaters('content');
         $tag_index = array();
         if (PerchUtil::count($tags)) {
             foreach ($tags as $Tag) {
                 if (!isset($tag_index[$Tag->id()])) {
                     $tag_index[$Tag->id()] = $Tag;
                 }
             }
         }
         foreach ($items as $Item) {
             $fields = PerchUtil::json_safe_decode($Item->itemJSON(), true);
             $sql = 'INSERT INTO ' . PERCH_DB_PREFIX . 'content_index (itemID, regionID, pageID, itemRev, indexKey, indexValue) VALUES ';
             $values = array();
             $id_set = false;
             if (PerchUtil::count($fields)) {
                 foreach ($fields as $key => $value) {
                     if (isset($tag_index[$key])) {
                         $tag = $tag_index[$key];
                         if ($tag->no_index()) {
                             continue;
                         }
                         if ($tag->type() == 'PerchRepeater') {
                             $index_value = $tag->get_index($value);
                         } else {
                             $FieldType = PerchFieldTypes::get($tag->type(), false, $tag);
                             $index_value = $FieldType->get_index($value);
                         }
                         if (is_array($index_value)) {
                             foreach ($index_value as $index_item) {
                                 $data = array();
                                 $data['itemID'] = (int) $Item->itemID();
                                 $data['regionID'] = (int) $this->id();
                                 $data['pageID'] = (int) $Item->pageID();
                                 $data['itemRev'] = (int) $Item->itemRev();
                                 $data['indexKey'] = $this->db->pdb(substr($index_item['key'], 0, 64));
                                 $data['indexValue'] = $this->db->pdb(substr($index_item['value'], 0, 255));
                                 $values[] = '(' . implode(',', $data) . ')';
                                 if ($index_item['key'] == '_id') {
                                     $id_set = true;
                                 }
                             }
                         }
                     }
                 }
             }
             // _id
             if (!$id_set) {
                 $data = array();
                 $data['itemID'] = (int) $Item->itemID();
                 $data['regionID'] = (int) $this->id();
                 $data['pageID'] = (int) $Item->pageID();
                 $data['itemRev'] = (int) $Item->itemRev();
                 $data['indexKey'] = $this->db->pdb('_id');
                 $data['indexValue'] = (int) $Item->itemID();
                 $values[] = '(' . implode(',', $data) . ')';
             }
             // natural order
             $data = array();
             $data['itemID'] = (int) $Item->itemID();
             $data['regionID'] = (int) $this->id();
             $data['pageID'] = (int) $Item->pageID();
             $data['itemRev'] = (int) $Item->itemRev();
             $data['indexKey'] = $this->db->pdb('_order');
             $data['indexValue'] = $this->db->pdb($Item->itemOrder());
             $values[] = '(' . implode(',', $data) . ')';
             $sql .= implode(',', $values);
             $this->db->execute($sql);
         }
     }
     // optimize index
     $sql = 'OPTIMIZE TABLE ' . PERCH_DB_PREFIX . 'content_index';
     $this->db->get_row($sql);
     $Perch = Perch::fetch();
     $Perch->event('region.index', $this);
 }
 public function old_receive_from_template_fields($Template, $previous_values, $perch_only = true, $fixed_fields = false, $include_repeaters = true)
 {
     if ($include_repeaters) {
         $tags = $Template->find_all_tags_and_repeaters();
     } else {
         $tags = $Template->find_all_tags();
     }
     $Form = $this;
     $form_vars = array();
     if (is_array($tags)) {
         $seen_tags = array();
         if ($perch_only) {
             $postitems = $Form->find_items('perch_');
             $seen_tags = array_keys($_POST);
             //if (!$postitems) $postitems = array();
             //$postitems = array_merge($_POST, $postitems);
             if (!$postitems) {
                 $postitems = $_POST;
             }
         } else {
             $postitems = $_POST;
         }
         foreach ($tags as $tag) {
             $item_id = 'perch_' . $tag->id();
             $tag->set('input_id', $item_id);
             if (!in_array($tag->id(), $seen_tags)) {
                 $var = false;
                 $FieldType = PerchFieldTypes::get($tag->type(), $Form, $tag, $tags, $this->app_id);
                 $var = $FieldType->get_raw($postitems, $previous_values);
                 if (true || $var) {
                     $form_vars[$tag->id()] = $var;
                     // title
                     if ($tag->title()) {
                         $title_var = $var;
                         if (is_array($var) && isset($var['_title'])) {
                             $title_var = $var['_title'];
                         }
                         if (isset($forms_vars[$i])) {
                             if (isset($form_vars[$i]['_title'])) {
                                 $form_vars[$i]['_title'] .= ' ' . $title_var;
                                 $processed_vars[$i]['_title'] = ' ' . $title_var;
                             } else {
                                 $form_vars[$i]['_title'] = $title_var;
                                 $processed_vars[$i]['_title'] = $title_var;
                             }
                         }
                     }
                 }
                 $seen_tags[] = $tag->id();
             }
         }
     }
     return $form_vars;
 }
 public function replace_content_tags($namespace, $content_vars, $contents)
 {
     if (is_array($content_vars)) {
         // Find all matching tags
         $s = '#<perch:' . $namespace . '[^>]*/>#';
         $count = preg_match_all($s, $contents, $matches, PREG_SET_ORDER);
         if ($count) {
             foreach ($matches as $match) {
                 $match = $match[0];
                 $tag = new PerchXMLTag($match);
                 if ($tag->suppress) {
                     $contents = str_replace($match, '', $contents);
                 } else {
                     if (isset($content_vars[$tag->id])) {
                         $value = $content_vars[$tag->id];
                     } else {
                         $replacement = '';
                         if ($tag->else()) {
                             $replacement = $tag->else();
                         }
                         $contents = str_replace($match, $replacement, $contents);
                         continue;
                     }
                     $field_is_markup = false;
                     if ($tag->type) {
                         $FieldType = PerchFieldTypes::get($tag->type, false, $tag);
                         $modified_value = $FieldType->get_processed($value);
                         $field_is_markup = $FieldType->processed_output_is_markup;
                     } else {
                         $modified_value = $value;
                     }
                     // check for 'rewrite' attribute
                     if ($tag->rewrite) {
                         $modified_value = $this->_rewrite($tag, $modified_value);
                     }
                     // check for 'format' attribute
                     if ($tag->format) {
                         $modified_value = $this->_format($tag, $modified_value);
                     }
                     // check for 'replace' strings
                     if ($tag->replace) {
                         $pairs = explode(',', $tag->replace);
                         if (PerchUtil::count($pairs)) {
                             foreach ($pairs as $pair) {
                                 $pairparts = explode('|', $pair);
                                 if (isset($pairparts[0]) && isset($pairparts[1])) {
                                     $modified_value = str_replace(trim($pairparts[0]), trim($pairparts[1]), $modified_value);
                                 }
                             }
                         }
                     }
                     // Urlify
                     if ($tag->urlify) {
                         $modified_value = PerchUtil::urlify($modified_value);
                     }
                     // Trim by chars
                     if ($tag->chars) {
                         if (strlen($modified_value) > (int) $tag->chars) {
                             $modified_value = PerchUtil::excerpt_char($modified_value, (int) $tag->chars, false, true, $tag->append);
                         }
                     }
                     // Trim by words
                     if ($tag->words) {
                         $modified_value = PerchUtil::excerpt($modified_value, (int) $tag->words, false, true, $tag->append);
                     }
                     // Hash
                     if ($tag->hash == 'md5') {
                         $modified_value = md5($modified_value);
                     }
                     // check that what we've got isn't an array. If it is, try your best to get a good string.
                     if (is_array($modified_value)) {
                         if (isset($modified_value['_default'])) {
                             $modified_value = (string) $modified_value['_default'];
                         } else {
                             if (isset($modified_value['processed'])) {
                                 $modified_value = (string) $modified_value['processed'];
                             } else {
                                 $modified_value = (string) array_shift($modified_value);
                             }
                         }
                     }
                     // Strip tags
                     if ($tag->striptags) {
                         $modified_value = strip_tags($modified_value);
                     }
                     // Append
                     if (!$tag->words && !$tag->chars && $tag->append) {
                         $modified_value .= $tag->append;
                     }
                     // URL Encode
                     if ($tag->urlencode) {
                         $modified_value = rawurlencode($modified_value);
                     }
                     // Escape quotes
                     if ($tag->escape) {
                         $modified_value = PerchUtil::html($modified_value, true, false);
                         $field_is_markup = true;
                     }
                     // check encoding
                     if ($this->autoencode && !$field_is_markup) {
                         if (!$tag->textile && !$tag->markdown) {
                             if ((!$tag->is_set('encode') || $tag->encode == true) && (!$tag->is_set('html') || $tag->html == false)) {
                                 $modified_value = PerchUtil::html($modified_value);
                             }
                         }
                     }
                     // JSON encoding
                     if ($tag->jsonencode) {
                         $modified_value = json_encode($modified_value);
                     }
                     $contents = str_replace($match, $modified_value, $contents);
                 }
             }
         }
     }
     return $contents;
 }
示例#10
0
 public function index($Template = null)
 {
     if (!$this->index_table) {
         return;
     }
     $table = PERCH_DB_PREFIX . $this->index_table;
     // clear out old items
     $sql = 'DELETE FROM ' . $table . ' WHERE itemKey=' . $this->db->pdb($this->pk) . ' AND itemID=' . $this->db->pdb($this->id());
     $this->db->execute($sql);
     $tags = $Template->find_all_tags_and_repeaters($Template->namespace);
     $tag_index = array();
     if (PerchUtil::count($tags)) {
         foreach ($tags as $Tag) {
             if (!isset($tag_index[$Tag->id()])) {
                 $tag_index[$Tag->id()] = $Tag;
             }
         }
     }
     $fields = $this->to_array(array_keys($tag_index));
     $sql = 'INSERT INTO ' . $table . ' (itemKey, itemID, indexKey, indexValue) VALUES ';
     $values = array();
     $id_set = false;
     if (PerchUtil::count($fields)) {
         foreach ($fields as $key => $value) {
             if (strpos($key, 'DynamicFields') !== false || substr($key, 0, 6) == 'perch_' || strpos($key, 'JSON') !== false) {
                 continue;
             }
             if (isset($tag_index[$key])) {
                 $tag = $tag_index[$key];
             } else {
                 $tag = new PerchXMLTag('<perch:x type="text" id="' . $key . '" />');
             }
             if ($tag->type() == 'PerchRepeater') {
                 $index_value = $tag->get_index($value);
             } else {
                 $FieldType = PerchFieldTypes::get($tag->type(), false, $tag);
                 $index_value = $FieldType->get_index($value);
             }
             if (is_array($index_value)) {
                 foreach ($index_value as $index_item) {
                     $data = array();
                     $data['itemKey'] = $this->db->pdb($this->pk);
                     $data['itemID'] = $this->pk_is_int ? (int) $this->id() : $this->db->pdb($this->id());
                     $data['indexKey'] = $this->db->pdb(substr($index_item['key'], 0, 64));
                     $data['indexValue'] = $this->db->pdb(substr($index_item['value'], 0, 255));
                     $values[] = '(' . implode(',', $data) . ')';
                     if ($index_item['key'] == '_id') {
                         $id_set = true;
                     }
                 }
             }
         }
     }
     // _id
     if (!$id_set) {
         $data = array();
         $data['itemKey'] = $this->db->pdb($this->pk);
         $data['itemID'] = $this->pk_is_int ? (int) $this->id() : $this->db->pdb($this->id());
         $data['indexKey'] = $this->db->pdb('_id');
         $data['indexValue'] = $this->pk_is_int ? (int) $this->id() : $this->db->pdb($this->id());
         $values[] = '(' . implode(',', $data) . ')';
     }
     $sql .= implode(',', $values);
     $this->db->execute($sql);
     // optimize index
     $sql = 'OPTIMIZE TABLE ' . $table;
     $this->db->get_row($sql);
     if ($this->event_prefix && !$this->suppress_events) {
         $Perch = Perch::fetch();
         $Perch->event($this->event_prefix . '.index', $this);
     }
     return true;
 }
示例#11
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();
}
#PerchUtil::debug('Image folder writable? ' . $image_folder_writable);
$details = $Settings->get_as_array();
 public static function display_item_fields($tags, $id, $item, $Page, $Form, $Template, $blocks_link_builder = array('PerchContent_Util', 'get_block_link'), $seen_tags = array())
 {
     //PerchUtil::debug($tags, 'success');
     //$seen_tags = array();
     if (!PerchUtil::count($tags)) {
         return;
     }
     foreach ($tags as $tag) {
         if ($id === null) {
             $item_id = 'perch_' . $tag->id();
             $tag->set('input_id', $item_id);
             $tag->set('post_prefix', 'perch_');
         } else {
             $item_id = 'perch_' . $id . '_' . $tag->id();
             $tag->set('input_id', $item_id);
             $tag->set('post_prefix', 'perch_' . $id . '_');
         }
         if (is_object($Page)) {
             $tag->set('page_id', $Page->id());
         }
         if (!in_array($tag->id(), $seen_tags) && $tag->type() != 'hidden' && $tag->type() != 'editcontrol' && substr($tag->id(), 0, 7) != 'parent.') {
             if ($tag->type() == 'slug' && !$tag->editable()) {
                 continue;
             }
             if (!PERCH_RUNWAY && $tag->runway()) {
                 continue;
             }
             //PerchUtil::debug($tag->type(), 'success');
             if ($tag->type() == 'PerchRepeater') {
                 $repeater_id = $id . '_' . $tag->id();
                 if ($tag->divider_before()) {
                     echo '<h2 class="divider">' . PerchUtil::html($tag->divider_before()) . '</h2>';
                 }
                 if ($tag->notes_before()) {
                     echo '<p class="formnotes">' . PerchUtil::html($tag->notes_before()) . '</p>';
                 }
                 echo '<h3 class="label repeater-heading">' . $tag->label() . '</h3>';
                 echo '<div class="repeater" data-prefix="perch_' . PerchUtil::html($repeater_id) . '"';
                 if ($tag->max()) {
                     echo ' data-max="' . PerchUtil::html($tag->max()) . '"';
                 }
                 echo '>';
                 echo '<div class="repeated">';
                 $repeater_i = 0;
                 if (isset($item[$tag->id()]) && is_array($item[$tag->id()])) {
                     $subitems = $item[$tag->id()];
                     if (isset($_POST['perch_' . $repeater_id . '_count']) && (int) $_POST['perch_' . $repeater_id . '_count'] > 0) {
                         $submitted_count = (int) $_POST['perch_' . $repeater_id . '_count'];
                         if (PerchUtil::count($subitems) < $submitted_count) {
                             for ($i = PerchUtil::count($subitems); $i < $submitted_count; $i++) {
                                 $subitems[] = array();
                             }
                         }
                     }
                     foreach ($subitems as $subitem) {
                         $edit_prefix = 'perch_' . $repeater_id . '_' . $repeater_i . '_';
                         foreach ($subitem as $key => $val) {
                             $subitem[$edit_prefix . $key] = $val;
                         }
                         echo '<div class="repeated-item">';
                         echo '<div class="index"><span>' . ($repeater_i + 1) . '</span><span class="icon"></span></div>';
                         echo '<div class="repeated-fields">';
                         PerchContent_Util::display_item_fields($tag->tags, $repeater_id . '_' . $repeater_i, $subitem, $Page, $Form, $Template);
                         echo '<input type="hidden" name="perch_' . ($repeater_id . '_' . $repeater_i) . '_present" class="present" value="1" />';
                         echo '<input type="hidden" name="perch_' . ($repeater_id . '_' . $repeater_i) . '_prevpos" value="' . $repeater_i . '" />';
                         echo '</div>';
                         echo '<div class="rm"></div>';
                         echo '</div>';
                         $repeater_i++;
                     }
                 }
                 $spare = true;
                 if ($tag->max() && $repeater_i - 1 >= (int) $tag->max()) {
                     $spare = false;
                 }
                 if ($spare) {
                     // And one spare
                     echo '<div class="repeated-item spare">';
                     echo '<div class="index icon"><span>' . ($repeater_i + 1) . '</span><span class="icon"></span></div>';
                     echo '<div class="repeated-fields">';
                     PerchContent_Util::display_item_fields($tag->tags, $repeater_id . '_' . $repeater_i, array(), $Page, $Form, $Template);
                     echo '<input type="hidden" name="perch_' . ($repeater_id . '_' . $repeater_i) . '_present" class="present" value="1" />';
                     echo '</div>';
                     echo '<div class="rm"></div>';
                     echo '</div>';
                     echo '</div>';
                     // .repeated
                     // footer
                     echo '<div class="repeater-footer">';
                     echo '<input type="hidden" name="perch_' . $repeater_id . '_count" value="0" class="count" />';
                     echo '</div>';
                 }
                 echo '</div>';
                 if ($tag->divider_after()) {
                     echo '<h2 class="divider">' . PerchUtil::html($tag->divider_after()) . '</h2>';
                 }
             } elseif ($tag->type() == 'PerchBlocks') {
                 if ($tag->divider_before()) {
                     echo '<h2 class="divider">' . PerchUtil::html($tag->divider_before()) . '</h2>';
                 }
                 if ($tag->notes_before()) {
                     echo '<p class="formnotes">' . PerchUtil::html($tag->notes_before()) . '</p>';
                 }
                 echo PerchContent_Util::display_blocks($tags, $id, $item, $Page, $Form, $Template, $blocks_link_builder);
                 if ($tag->divider_after()) {
                     echo '<h2 class="divider">' . PerchUtil::html($tag->divider_after()) . '</h2>';
                 }
             } else {
                 if ($tag->divider_before()) {
                     echo '<h2 class="divider">' . PerchUtil::html($tag->divider_before()) . '</h2>';
                 }
                 if ($tag->notes_before()) {
                     echo '<p class="formnotes">' . PerchUtil::html($tag->notes_before()) . '</p>';
                 }
                 echo '<div class="field ' . $Form->error($item_id, false) . '">';
                 echo '<div class="fieldtbl">';
                 $label_text = PerchUtil::html($tag->label());
                 if ($tag->type() == 'textarea') {
                     if (PerchUtil::bool_val($tag->textile()) == true) {
                         $label_text .= ' <span><a href="' . PERCH_LOGINPATH . '/core/help/textile" class="assist">Textile</a></span>';
                     }
                     if (PerchUtil::bool_val($tag->markdown()) == true) {
                         $label_text .= ' <span><a href="' . PERCH_LOGINPATH . '/core/help/markdown" class="assist">Markdown</a></span>';
                     }
                 }
                 $Form->disable_html_encoding();
                 echo '<div class="fieldlbl">' . $Form->label($item_id, $label_text, '', false, false) . '</div>';
                 $Form->enable_html_encoding();
                 $FieldType = PerchFieldTypes::get($tag->type(), $Form, $tag, false, $Form->app_id);
                 echo '<div class="field-wrap">';
                 echo $FieldType->render_inputs($item);
                 if ($tag->help()) {
                     echo $Form->translated_hint($tag->help());
                 }
                 echo '</div>';
                 echo '</div>';
                 echo '</div>';
                 if ($tag->divider_after()) {
                     echo '<h2 class="divider">' . PerchUtil::html($tag->divider_after()) . '</h2>';
                 }
             }
             $seen_tags[] = $tag->id();
         } else {
             if (!in_array($tag->id(), $seen_tags) && $tag->edit_control()) {
                 // Hidden fields for editing purposes.
                 $FieldType = PerchFieldTypes::get('editcontrol', $Form, $tag, false, $Form->app_id);
                 echo $FieldType->render_inputs($item);
                 $seen_tags[] = $tag->id();
             }
         }
     }
 }
示例#13
0
    $details = $Event->to_array();
    $heading1 = 'Editing an Event';
} else {
    $Event = false;
    $eventID = false;
    $details = array();
    $heading1 = 'Adding an Event';
}
$heading2 = 'Event details';
$Template = $API->get('Template');
$Template->set('events/event.html', 'events');
$Form = $API->get('Form');
$tags = $Template->find_all_tags_and_repeaters('events');
if (PerchUtil::count($tags)) {
    foreach ($tags as $Tag) {
        PerchFieldTypes::get($Tag->type(), $Form, $Tag, $tags);
    }
}
$Form->handle_empty_block_generation($Template);
$Form->require_field('eventTitle', 'Required');
$Form->require_field('eventDescRaw', 'Required');
$Form->require_field('eventDateTime_minute', 'Required');
$Form->set_required_fields_from_template($Template);
if ($Form->submitted()) {
    $postvars = array('eventTitle', 'eventDescRaw', 'cat_ids');
    $data = $Form->receive($postvars);
    $data['eventDateTime'] = $Form->get_date('eventDateTime');
    $prev = false;
    if (isset($details['eventDynamicFields'])) {
        $prev = PerchUtil::json_safe_decode($details['eventDynamicFields'], true);
    }
示例#14
0
if ($Region->regionTemplate() != '') {
    $Resources = new PerchResources();
    $Template = new PerchTemplate('content/' . $Region->regionTemplate(), 'content');
    if ($Template->status == 404) {
        $Alert->set('error', PerchLang::get('The template for this region (%s) cannot be found.', '<code>' . $Region->regionTemplate() . '</code>'));
    }
    $tags = $Template->find_all_tags_and_repeaters('content');
    //PerchUtil::debug($tags);
    $template_help_html = $Template->find_help();
    $Form = new PerchForm('edit');
    $req = array();
    // initialise field types (add head javascript)
    $all_tags = $Template->find_all_tags('content');
    if (PerchUtil::count($all_tags)) {
        foreach ($all_tags as $tag) {
            $FieldType = PerchFieldTypes::get($tag->type(), $Form, $tag, $all_tags);
        }
    }
    // Check for required content
    if (is_array($tags)) {
        foreach ($details as $item) {
            $id = $item['itemID'];
            PerchContent_Util::set_required_fields($Form, $id, $item, $tags, $Template);
        }
    }
    if ($Form->posted() && $Form->validate()) {
        // New rev
        $Region->create_new_revision();
        // Get items
        if (isset($item_id) && $item_id) {
            $items = $Region->get_items_for_updating($item_id);