예제 #1
0
function perch_forms_form_handler($SubmittedForm)
{
    if ($SubmittedForm->validate()) {
        $API = new PerchAPI(1.0, 'perch_forms');
        $Forms = new PerchForms_Forms($API);
        $formKey = $SubmittedForm->id;
        $Form = $Forms->find_by_key($formKey);
        if (!is_object($Form)) {
            $data = array();
            $data['formKey'] = $formKey;
            $data['formTemplate'] = $SubmittedForm->templatePath;
            $data['formOptions'] = PerchUtil::json_safe_encode(array('store' => true));
            $attrs = $SubmittedForm->get_form_attributes();
            if ($attrs->label()) {
                $data['formTitle'] = $attrs->label();
            } else {
                $data['formTitle'] = PerchUtil::filename($formKey, false);
            }
            $Form = $Forms->create($data);
        }
        if (is_object($Form)) {
            $Form->process_response($SubmittedForm);
        }
    }
    $Perch = Perch::fetch();
    PerchUtil::debug($Perch->get_form_errors($SubmittedForm->formID));
}
 public function display_name()
 {
     $out = '';
     if (strpos($this->templatePath(), '/') !== false) {
         $segments = explode('/', $this->templatePath());
         array_pop($segments);
         $out .= PerchUtil::filename(implode('/', $segments)) . ' → ';
     }
     $out .= $this->templateTitle();
     return $out;
 }
 /**
  * Find a page based on its path, or create a new one. Used by the Upgrade app.
  * @param  string $path A root-relative site path
  * @return object       Instance of Page class.
  */
 public function find_or_create($path)
 {
     $Page = $this->find_by_path($path);
     if (is_object($Page)) {
         return $Page;
     }
     $data = array();
     $data['pagePath'] = $path;
     $data['pageTitle'] = PerchUtil::filename($path, false, false);
     $data['pageNavText'] = $data['pageTitle'];
     $data['pageNew'] = 1;
     $data['pageDepth'] = 0;
     $data['pageModified'] = date('Y-m-d H:i:s');
     $data['pageAttributes'] = '';
     $Page = $this->create($data);
     $Perch = Perch::fetch();
     $Perch->event('page.create', $Page);
     $this->order_new_pages();
     return $this->find($Page->id());
 }
예제 #4
0
 public function log($app = 'content', $bucket = 'default', $file, $parentID = 0, $resource_key = '', $library_resource = false, $details = false, $AssetMeta = false)
 {
     if (isset($details['assetID'])) {
         $newID = $details['assetID'];
     } else {
         $data = array('resourceApp' => $app, 'resourceBucket' => $bucket, 'resourceFile' => $file, 'resourceKey' => $resource_key, 'resourceParentID' => $parentID, 'resourceType' => $this->_get_type($file), 'resourceCreated' => date('Y-m-d H:i:s'), 'resourceInLibrary' => $library_resource ? '1' : '0');
         if (PerchUtil::count($details)) {
             foreach ($details as $key => $val) {
                 switch ($key) {
                     case 'w':
                         $data['resourceWidth'] = $val;
                         break;
                     case 'h':
                         $data['resourceHeight'] = $val;
                         break;
                     case 'target_w':
                         $data['resourceTargetWidth'] = $val;
                         break;
                     case 'target_h':
                         $data['resourceTargetHeight'] = $val;
                         break;
                     case 'crop':
                         $data['resourceCrop'] = $val ? '1' : '0';
                         break;
                     case 'density':
                         $data['resourceDensity'] = $val;
                         break;
                     case 'size':
                         $data['resourceFileSize'] = $val;
                         break;
                     case 'mime':
                         $data['resourceMimeType'] = $val;
                         break;
                     case 'title':
                         $data['resourceTitle'] = $val;
                         break;
                 }
             }
         }
         if (!isset($data['resourceTitle'])) {
             if ($AssetMeta) {
                 $data['resourceTitle'] = $AssetMeta->get_title();
             } else {
                 $data['resourceTitle'] = PerchUtil::filename(PerchUtil::strip_file_extension($data['resourceFile']), false);
             }
         }
         $newID = $this->db->insert($this->table, $data, true);
         if ($newID == '0') {
             $sql = 'SELECT resourceID FROM ' . $this->table . ' WHERE resourceBucket=' . $this->db->pdb($bucket) . ' AND resourceFile=' . $this->db->pdb($file) . ' LIMIT 1';
             $newID = $this->db->get_value($sql);
         }
         // Tags
         if ($AssetMeta) {
             $tags = $AssetMeta->get_tags();
             if (PerchUtil::count($tags)) {
                 if (!class_exists('PerchAssets_Tags', false)) {
                     include_once PERCH_CORE . '/apps/assets/PerchAssets_Tags.class.php';
                     include_once PERCH_CORE . '/apps/assets/PerchAssets_Tag.class.php';
                 }
                 $Tags = new PerchAssets_Tags();
                 $Tags->assign_tag_array($newID, $tags, true);
             }
         }
     }
     PerchResources::$logged[] = $newID;
     return $newID;
 }
 public function get_meta_data($file_path, $name)
 {
     if (!class_exists('PerchAssets_MetaData')) {
         include_once __DIR__ . '/PerchAssets_MetaData.class.php';
     }
     $MetaData = new PerchAssets_MetaData();
     if (is_callable('iptcparse') && is_callable('getimagesize')) {
         $info = array();
         getimagesize($file_path);
         // once
         getimagesize($file_path, $info);
         // twice for luck (aka bugs);
         if (isset($info['APP13'])) {
             $iptc = iptcparse($info['APP13']);
             $MetaData->store_iptc($iptc);
         }
     }
     if (!$MetaData->get_title()) {
         $title = PerchUtil::filename(PerchUtil::strip_file_extension($name), false);
         $MetaData->set_title($title);
     }
     return $MetaData;
 }
예제 #6
0
if ($message) {
    echo $message;
}
$template_help_html = $Template->find_help();
if ($template_help_html) {
    echo $HTML->heading2('Help');
    echo '<div id="template-help">' . $template_help_html . '</div>';
}
echo $HTML->heading2('Blog details');
echo $Form->form_start();
echo $Form->text_field('blogTitle', 'Title', isset($details['blogTitle']) ? $details['blogTitle'] : '');
$opts = array();
if (PerchUtil::count($category_sets)) {
    foreach ($category_sets as $Set) {
        $opts[] = array('value' => $Set->setSlug(), 'label' => $Set->setTitle());
    }
}
echo $Form->select_field('setSlug', 'Category set', $opts, isset($details['setSlug']) ? $details['setSlug'] : '');
$opts = array();
$Util = new PerchBlog_Util($API);
$templates = $Util->find_templates();
if (PerchUtil::count($templates)) {
    foreach ($templates as $template) {
        $opts[] = array('value' => $template, 'label' => PerchUtil::filename($template, true));
    }
}
echo $Form->select_field('postTemplate', 'Default master template', $opts, isset($details['postTemplate']) ? $details['postTemplate'] : 'post.html');
echo $Form->fields_from_template($Template, $details, $Blogs->static_fields);
echo $Form->submit_field('btnSubmit', 'Save', $API->app_path() . '/blogs/');
echo $Form->form_end();
echo $HTML->main_panel_end();
예제 #7
0
                <th><?php 
    echo PerchLang::get('Template');
    ?>
</th>
                <th class="action last"></th>
            </tr>
        </thead>
        <tbody>
        <?php 
    if (PerchUtil::count($contentItems) > 0) {
        $prev = false;
        $prev_url = false;
        $level = 0;
        foreach ($contentItems as $item) {
            echo '<tr class="' . PerchUtil::flip('odd') . '">';
            echo '<td class="level' . $level . ' page"><span>' . PerchUtil::html(PerchUtil::filename($item->Alias(), false)) . '</span></td>';
            echo '<td>' . PerchUtil::html($item->Location()) . '</td>';
            echo '<td>' . PerchUtil::html($PerchPage->template_display_name($item->Template())) . '</td>';
            echo '<td>';
            if ($CurrentUser->userRole() == 'Admin' || $CurrentUser->userRole() == 'Editor' && $Settings->get('editorMayDeleteRegions')->settingValue()) {
                echo '<a href="delete?id=' . PerchUtil::html($item->id()) . '" class="delete">' . PerchLang::get('Delete') . '</a>';
            } else {
                echo '&nbsp;';
            }
            echo '</td>';
            echo '</tr>';
        }
    }
    ?>
        </tbody>
		<tfoot>
예제 #8
0
 /**
  * Find the page by its path, or create it if it's new.
  *
  * @param string $path 
  * @return void
  * @author Drew McLellan
  */
 private function _find_or_create_page($path)
 {
     if ($path == '*') {
         return 1;
     }
     if ($this->pageID) {
         return $this->pageID;
     }
     $db = PerchDB::fetch();
     $table = PERCH_DB_PREFIX . 'pages';
     $sql = 'SELECT pageID FROM ' . $table . ' WHERE pagePath=' . $db->pdb($path) . ' LIMIT 1';
     $pageID = $db->get_value($sql);
     if ($pageID) {
         $this->pageID = $pageID;
         return $pageID;
     }
     $data = array();
     $data['pagePath'] = $path;
     $data['pageTitle'] = PerchUtil::filename($path, false, false);
     $data['pageNavText'] = $data['pageTitle'];
     $data['pageNew'] = 1;
     $data['pageDepth'] = 0;
     $data['pageModified'] = date('Y-m-d H:i:s');
     $data['pageAttributes'] = '';
     //return $db->insert($table, $data);
     $cols = array();
     $vals = array();
     foreach ($data as $key => $value) {
         $cols[] = $key;
         $vals[] = $db->pdb($value) . ' AS ' . $key;
     }
     $sql = 'INSERT INTO ' . $table . '(' . implode(',', $cols) . ') 
             SELECT ' . implode(',', $vals) . ' 
             FROM (SELECT 1) AS ptable
             WHERE (
                     SELECT COUNT(*) 
                     FROM ' . $table . ' 
                     WHERE pagePath=' . $db->pdb($data['pagePath']) . '
                     )=0
             LIMIT 1';
     return $db->execute($sql);
 }
예제 #9
0
}
echo $Form->fields_from_template($Template, $modified_details);
echo $HTML->heading2('Meta data');
/* ---- TAGS ---- */
echo $Form->hint('Separate with commas');
echo $Form->text_field('postTags', 'Tags', isset($details['postTags']) ? $details['postTags'] : false);
/* ---- COMMENTS ---- */
if ($CurrentUser->has_priv('perch_blog.comments.enable')) {
    echo $Form->checkbox_field('postAllowComments', 'Allow comments', '1', isset($details['postAllowComments']) ? $details['postAllowComments'] : '1');
}
/* ---- POST TEMPLATES} ---- */
if (PerchUtil::count($post_templates)) {
    $opts = array();
    $opts[] = array('label' => $Lang->get('Default'), 'value' => 'post.html');
    foreach ($post_templates as $template) {
        $opts[] = array('label' => PerchUtil::filename($template, false), 'value' => 'posts/' . $template);
    }
    echo $Form->hint('See sidebar note about post types');
    echo $Form->select_field('postTemplate', 'Post type', $opts, isset($details['postTemplate']) ? $details['postTemplate'] : 'post.html');
} else {
    echo $Form->hidden('postTemplate', isset($details['postTemplate']) ? $details['postTemplate'] : 'post.html');
}
/* ---- AUTHORS ---- */
$authors = $Authors->all();
if (PerchUtil::count($authors)) {
    $opts = array();
    foreach ($authors as $author) {
        $opts[] = array('label' => $author->authorGivenName() . ' ' . $author->authorFamilyName(), 'value' => $author->id());
    }
    echo $Form->select_field('authorID', 'Author', $opts, isset($details['authorID']) ? $details['authorID'] : $Author->id());
}
예제 #10
0
        <div class="field">
            <?php 
        $opts = array();
        $vals = explode(',', $Page->pageSubpageTemplates());
        if ($ParentPage) {
            $templates = $PageTemplates->get_filtered($ParentPage->pageSubpageTemplates());
            if ($ParentPage->pageSubpageTemplates() == '' || $ParentPage->pageSubpageTemplates() == '*') {
                $opts[] = array('label' => PerchLang::get('All'), 'value' => '*', 'class' => 'single');
            }
        } else {
            $templates = $PageTemplates->get_filtered();
            $opts[] = array('label' => PerchLang::get('All'), 'value' => '*', 'class' => 'single');
        }
        if (PerchUtil::count($templates)) {
            foreach ($templates as $Template) {
                $tmp = array('label' => PerchUtil::filename($Template->display_name()), 'value' => $Template->id());
                $opts[] = $tmp;
            }
        }
        echo $Form->checkbox_set('subpage_templates', 'May use these master pages', $opts, $vals, $class = '', $limit = false);
        ?>
        </div>

        <?php 
    }
    // runway
    ?>

        
        <?php 
    if (!PERCH_RUNWAY) {
예제 #11
0
if ($message) {
    echo $message;
}
include __DIR__ . '/_post_smartbar.php';
if ($edit_mode == 'define') {
    include 'edit.define.post.php';
} else {
    $template_help_html = $Template->find_help();
    if ($template_help_html) {
        echo $HTML->heading2('Help');
        echo '<div id="template-help">' . $template_help_html . '</div>';
    }
    if ($template == 'post.html') {
        echo $HTML->heading2('Post');
    } else {
        echo '<h2>' . $HTML->encode(PerchUtil::filename($template, false)) . '</h2>';
    }
    /* ---- FORM ---- */
    echo $Form->form_start('blog-edit', 'magnetic-save-bar');
    /* ---- FIELDS FROM TEMPLATE ---- */
    $modified_details = $details;
    if (isset($modified_details['postDescRaw'])) {
        $modified_details['postDescHTML'] = $modified_details['postDescRaw'];
    }
    echo $Form->fields_from_template($Template, $modified_details);
    /* ---- TAGS ---- */
    #echo $Form->hint('Separate with commas');
    #echo $Form->text_field('postTags', 'Tags', isset($details['postTags'])?$details['postTags']:false);
    /* ---- COMMENTS ---- */
    #if ($CurrentUser->has_priv('perch_blog.comments.enable')) {
    #    echo $Form->checkbox_field('postAllowComments', 'Allow comments', '1', isset($details['postAllowComments'])?$details['postAllowComments']:'1');
 /**
  * Attempt to construct a nice(ish) looking title from the file name
  * @return [type] [description]
  */
 public function get_title_from_filename()
 {
     $s = $this->resourceFile();
     $s = PerchUtil::strip_file_extension($s);
     return PerchUtil::filename($s, false);
 }
예제 #13
0
    ?>
</th>
                <th class="action last"></th>
            </tr>
        </thead>
        <tbody>
<?php 
    foreach ($templates as $Template) {
        ?>
            <tr>
                <td class="primary">
                    <?php 
        if (strpos($Template->templatePath(), '/') !== false) {
            $segments = explode('/', $Template->templatePath());
            array_pop($segments);
            echo PerchUtil::filename(implode('/', $segments)) . ' → ';
        }
        ?>
                    <a href="<?php 
        echo PerchUtil::html(PERCH_LOGINPATH);
        ?>
/core/apps/content/page/templates/edit/?id=<?php 
        echo PerchUtil::html(urlencode($Template->id()));
        ?>
"><?php 
        echo PerchUtil::html($Template->templateTitle());
        ?>
</a>

                </td>
                <td><?php