Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Sat, Aug 16, 5:15 PM

in-portal

Index: branches/unlabeled/unlabeled-1.5.2/core/kernel/utility/formatters/upload_formatter.php
===================================================================
--- branches/unlabeled/unlabeled-1.5.2/core/kernel/utility/formatters/upload_formatter.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.5.2/core/kernel/utility/formatters/upload_formatter.php (revision 8098)
@@ -0,0 +1,178 @@
+<?php
+
+class kUploadFormatter extends kFormatter
+{
+ var $DestinationPath;
+ var $FullPath;
+
+ function kUploadFormatter()
+ {
+ if ($this->DestinationPath)
+ {
+ $this->FullPath = FULL_PATH.$this->DestinationPath;
+ }
+ parent::kBase();
+ }
+
+
+//function Parse($value, $options, &$errors)
+ function Parse($value, $field_name, &$object)
+ {
+ $ret = '';
+ $options = $object->GetFieldOptions($field_name);
+
+ if(getArrayValue($options, 'upload_dir'))
+ {
+ $this->DestinationPath = $options['upload_dir'];
+ $this->FullPath = FULL_PATH.$this->DestinationPath;
+ }
+
+ if (getArrayValue($value, 'upload') && getArrayValue($value, 'error') == UPLOAD_ERR_NO_FILE) {
+ // file was not uploaded this time, but was uploaded before, then use previously uploaded file (from db)
+ return getArrayValue($value, 'upload');
+ }
+
+ if ( is_array($value) && $value['size'] )
+ {
+ if ( is_array($value) && $value['error'] === UPLOAD_ERR_OK )
+ {
+ if ( getArrayValue($options, 'allowed_types') && !in_array($value['type'], $options['allowed_types']) )
+ {
+ $object->FieldErrors[$field_name]['pseudo'] = 'bad_file_format';
+ }
+ elseif ( $value['size'] > ($options['max_size'] ? $options['max_size'] : MAX_UPLOAD_SIZE) )
+ {
+ $object->FieldErrors[$field_name]['pseudo'] = 'bad_file_size';
+ }
+ elseif ( !is_writable($this->FullPath) )
+ {
+ $object->FieldErrors[$field_name]['pseudo'] = 'cant_save_file';
+ }
+ else
+ {
+ $real_name = $this->ValidateFileName($this->FullPath, $value['name']);
+ $file_name = $this->FullPath.$real_name;
+ if ( !move_uploaded_file($value['tmp_name'], $file_name) )
+ {
+ $object->FieldErrors[$field_name]['pseudo'] = 'cant_save_file';
+ }
+ else
+ {
+ @chmod($file_name, 0666);
+ if(getArrayValue($options, 'size_field'))
+ {
+ $object->SetDBField($options['size_field'], $value['size']);
+ }
+ if(getArrayValue($options, 'orig_name_field'))
+ {
+ $object->SetDBField($options['orig_name_field'], $value['name']);
+ }
+ if(getArrayValue($options, 'content_type_field'))
+ {
+ $object->SetDBField($options['content_type_field'], $value['type']);
+ }
+ $ret = getArrayValue($options, 'upload_dir') ? $real_name : $this->DestinationPath.$real_name;
+
+ // delete previous file, when new file is uploaded under same field
+ /*$previous_file = isset($value['upload']) ? $value['upload'] : false;
+ if ($previous_file && file_exists($this->FullPath.$previous_file)) {
+ unlink($this->FullPath.$previous_file);
+ }*/
+ }
+ }
+ }
+ else
+ {
+ $object->FieldErrors[$field_name]['pseudo'] = 'cant_save_file';
+ }
+ }
+ else
+ {
+ if(getArrayValue($options, 'required'))
+ {
+ $object->FieldErrors[$field_name]['pseudo'] = 'required';
+ }
+ }
+
+ if ($value['error'] && !( $value['error'] == UPLOAD_ERR_NO_FILE ) && !$object->FieldErrors[$field_name]['pseudo'])
+ {
+ $object->FieldErrors[$field_name]['pseudo'] = 'cant_save_file';
+ }
+
+ return $ret;
+ }
+
+ function Format($value, $field_name, &$object, $format=null)
+ {
+ if ( is_null($value) ) return '';
+
+ $options = $object->GetFieldOptions($field_name);
+ if ( isset($format) ) $options['format'] = $format;
+ $tc_value = $this->TypeCast($value, $options);
+ if( ($tc_value === false) || ($tc_value != $value) ) return $value; // for leaving badly formatted date on the form
+
+ return $this->GetFormatted($tc_value, $options);
+ }
+
+ function GetFormatted($tc_value, &$options)
+ {
+ if (isset($options['format'])) {
+ switch ($options['format']) {
+ case 'full_url':
+ $upload_dir = isset($options['upload_dir']) ? $options['upload_dir'] : $this->DestinationPath;
+ return rtrim($this->Application->BaseURL(), '/').$upload_dir.$tc_value;
+ break;
+
+ default:
+ return sprintf($options['format'], $tc_value);
+ break;
+ }
+ }
+
+ return $tc_value;
+ }
+
+ function ValidateFileName($path, $name)
+ {
+ $parts = pathinfo($name);
+ $ext = '.'.$parts['extension'];
+ $filename = substr($parts['basename'], 0, -strlen($ext));
+ $new_name = $filename.$ext;
+ while ( file_exists($path.'/'.$new_name) )
+ {
+ if ( preg_match('/('.preg_quote($filename, '/').'_)([0-9]*)('.preg_quote($ext, '/').')/', $new_name, $regs) ) {
+ $new_name = $regs[1].($regs[2]+1).$regs[3];
+ }
+ else {
+ $new_name = $filename.'_1'.$ext;
+ }
+ }
+ return $new_name;
+ }
+
+}
+
+class kPictureFormatter extends kUploadFormatter
+{
+
+ function kPictureFormatter()
+ {
+ $this->NakeLookupPath = IMAGES_PATH;
+ $this->DestinationPath = IMAGES_PENDING_PATH;
+ parent::kUploadFormatter();
+ }
+
+ function GetFormatted($tc_value, &$options)
+ {
+ if (isset($options['format']) && ($options['format'] == 'img_size')) {
+ $upload_dir = isset($options['upload_dir']) ? $options['upload_dir'] : $this->DestinationPath;
+ $img_path = FULL_PATH.'/'.$upload_dir.$tc_value;
+
+ $image_info = @getimagesize($img_path);
+ return ' width="'.$image_info[0].'" height="'.$image_info[1].'"';
+ }
+
+ return parent::GetFormatted($tc_value, $options);
+ }
+
+}
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.5.2/core/kernel/utility/formatters/upload_formatter.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.5
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.5.2/core/admin_templates/tree.tpl
===================================================================
--- branches/unlabeled/unlabeled-1.5.2/core/admin_templates/tree.tpl (nonexistent)
+++ branches/unlabeled/unlabeled-1.5.2/core/admin_templates/tree.tpl (revision 8098)
@@ -0,0 +1,125 @@
+<inp2:m_Set skip_last_template="1"/>
+<inp2:m_include t="incs/header" nobody="yes" noform="yes"/>
+
+<inp2:m_NoDebug/>
+
+<body style="margin: 0px; height: 100%" bgcolor="#DCEBF6">
+<inp2:m_RenderElement name="kernel_form"/>
+<script type="text/javascript">
+ function credits(url)
+ {
+ var width = 200;
+ var height = 200;
+ var screen_x = (screen.availWidth-width)/2;
+ var screen_y = (screen.availHeight-height)/2;
+ window.open(url, 'credits', 'width=280,height=520,left='+screen_x+',top='+screen_y);
+ }
+</script>
+
+<script src="js/ajax.js"></script>
+<script src="js/tree.js"></script>
+
+<style type="text/css">
+ .tree_head.td, .tree_head, .tree_head:hover {
+ font-weight: bold;
+ font-size: 10px;
+ color: #FFFFFF;
+ font-family: Verdana, Arial;
+ text-decoration: none;
+ }
+
+ .tree {
+ padding: 0px;
+ border: none;
+ border-collapse: collapse;
+ }
+
+ .tree tr td {
+ padding: 0px;
+ margin: 0px;
+ font-family: helvetica, arial, verdana,;
+ font-size: 11px;
+ white-space: nowrap;
+ }
+
+ .tree tr td a {
+ font-size: 11px;
+ color: #000000;
+ font-family: Helvetica, Arial, Verdana;
+ text-decoration: none;
+ }
+
+ .tree tr td a:hover {
+ color: #009FF0;
+ }
+</style>
+
+<table style="height: 100%; width: 100%; border-collapse: collapse;" border="0">
+ <tr style="background: #5291DE url(img/menu_bar.gif) repeat-x left bottom;" class="tree_head">
+ <td align="left" width="80%" height="21">
+ &nbsp;<a class="tree_head" href="javascript:credits('<inp2:m_Link index_file="help/credits.php" destform="popup"/>');">In-Portal v <inp2:adm_ModuleVersion module="In-Portal"/></a>
+ </td>
+ <td align="right" width="20%">
+ <select name="language" style="width: 62px; border: 0px; background-color: #FFFFFF; font-size: 9px; color: black;" onchange="submit_event('lang', 'OnChangeLanguage', 'index');">
+ <inp2:m_DefineElement name="lang_elem">
+ <option value="<inp2:Field name="LanguageId"/>" <inp2:m_if check="SelectedLanguage">selected="selected"</inp2:m_if> ><inp2:Field name="PackName"/></option>
+ </inp2:m_DefineElement>
+ <inp2:lang_ListLanguages render_as="lang_elem" row_start_render_as="html:" row_end_render_as="html:"/>
+ </select>
+ </td>
+ </tr>
+
+ <tr>
+ <td colspan="2" style="vertical-align: top; padding: 5px;">
+ <inp2:m_DefineElement name="xml_node" icon_module="">
+ <inp2:m_if check="m_ParamEquals" param="children_count" value="0">
+ <item href="<inp2:m_param name="section_url"/>" priority="<inp2:m_param name="priority"/>" onclick="<inp2:m_param name="onclick"/>" icon="<inp2:$SectionPrefix_ModulePath module="$icon_module"/>img/icons/icon24_<inp2:m_param name="icon"/>.gif"><inp2:m_phrase name="$label" escape="1"/></item>
+ <inp2:m_else/>
+ <folder href="<inp2:m_param name="section_url"/>" priority="<inp2:m_param name="priority"/>" onclick="<inp2:m_param name="onclick"/>" name="<inp2:m_phrase name="$label" escape="1"/>" icon="<inp2:$SectionPrefix_ModulePath module="$icon_module"/>img/icons/icon24_<inp2:m_param name="icon"/>.gif" load_url="<inp2:m_param name="late_load"/>"><inp2:adm_PrintSections render_as="xml_node" section_name="$section_name"/></folder>
+ </inp2:m_if>
+ </inp2:m_DefineElement>
+
+ <table class="tree">
+ <tbody id="tree">
+ </tbody>
+ </table>
+ <script type="text/javascript">
+ var TREE_ICONS_PATH = 'img/tree';
+ var TREE_SHOW_PRIORITY = <inp2:m_if check="adm_ConstOn" name="DBG_SHOW_TREE_PRIORITY" debug_mode="1">1<inp2:m_else/>0</inp2:m_if>;
+ <inp2:m_DefineElement name="root_node">
+ var the_tree = new TreeFolder('tree', '<inp2:m_param name="label"/>', '<inp2:m_param name="section_url"/>', '<inp2:$SectionPrefix_ModulePath module="$icon_module"/>img/icons/icon24_<inp2:m_param name="icon"/>.gif', null, null, '<inp2:m_param name="priority"/>');
+ </inp2:m_DefineElement>
+ <inp2:adm_PrintSection render_as="root_node" section_name="in-portal:root"/>
+ the_tree.AddFromXML('<tree><inp2:adm_PrintSections render_as="xml_node" section_name="in-portal:root"/></tree>');
+ </script>
+ </td>
+ </tr>
+</table>
+
+<inp2:m_include t="incs/footer"/>
+
+<script type="text/javascript">
+ // when changing language submit is made to frameset, not the current frame
+ var $kf = document.getElementById($form_name);
+ $kf.target = 'main_frame';
+
+ function checkCatalog($cat_id) {
+ var $ret = checkEditMode();
+ var $right_frame = getFrame('main');
+ if ($ret && $right_frame.$is_catalog) {
+ $right_frame.$Catalog.go_to_cat($cat_id);
+ return 1; // this opens folder, but disables click
+ }
+ return $ret;
+ }
+
+ function checkEditMode()
+ {
+ var $phrase = "<inp2:adm_TreeEditWarrning label="la_EditingInProgress" escape="1"/>";
+ if (getFrame('main').$edit_mode) {
+ return confirm($phrase) ? true : false;
+ }
+
+ return true;
+ }
+</script>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.5.2/core/admin_templates/tree.tpl
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.5
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

Event Timeline