public static function cge_image_list($params, $smarty)
 {
     $config = CmsApp::get_instance()->GetConfig();
     $dir = '';
     $maxdepth = -1;
     $pattern = array('*.jpg', '*.jpeg', '*.bmp', '*.gif', '*.png', '*.ico');
     $excludes = array('_*', '.??*');
     $absolute = FALSE;
     $thumbs = FALSE;
     $options = FALSE;
     $selected = null;
     $novalue = '';
     // handle the dir param
     if (isset($params['dir'])) {
         $tmp = trim($params['dir']);
         $tmp2 = cms_join_path($config['uploads_path'], $tmp);
         if (is_dir($tmp2)) {
             $dir = $tmp;
         }
     }
     // handle the extensions param
     if (isset($params['extensions'])) {
         $tmp = trim($params['extensions']);
         $pattern = explode('||', $tmp);
     }
     if (isset($params['thumbs'])) {
         $thumbs = cms_to_bool($params['thumbs']);
     }
     // handle the excludes param
     if (isset($params['excludes'])) {
         $tmp = trim($params['excludes']);
         $excludes = array_merge($excludes, explode('||', $tmp));
     }
     // handle the maxdepth param
     if (isset($params['maxdepth'])) {
         $tmp = (int) $params['excludes'];
         if ($tmp > 0) {
             $maxdepth = $tmp;
         }
     }
     if (isset($params['absolute'])) {
         $absolute = cms_to_bool($params['absolute']);
     }
     // handle the options param
     if (isset($params['options'])) {
         $options = cms_to_bool($params['options']);
     }
     // handle the selected param
     if (isset($params['selected'])) {
         $options = TRUE;
         $selected = trim($params['selected']);
     }
     // handle the 'novalue' param
     if (isset($params['novalue'])) {
         $novalue = trim($params['novalue']);
     }
     if (!$thumbs) {
         $excludes[] = 'thumb_*';
     }
     if ($dir != '') {
         $dir = trim($dir, '/');
         $dir = cms_join_path($config['uploads_path'], $dir);
     } else {
         $dir = $config['uploads_path'];
     }
     if (!is_dir($dir)) {
         return;
     }
     $files = cge_dir::recursive_glob($dir, $pattern, 'FILES', $excludes, $maxdepth);
     if (!is_array($files) || count($files) == 0) {
         return;
     }
     $out = array();
     foreach ($files as $one) {
         if ($absolute) {
             $out[$one] = $one;
         } else {
             $one = substr($one, strlen($dir));
             if (startswith($one, '/')) {
                 $one = substr($one, 1);
             }
             $out[$one] = $one;
         }
     }
     if ($options) {
         $tmp = $out;
         $out = '';
         if ($novalue != '') {
             $out .= "<option value=\"\">" . $novalue . "</option>";
         }
         foreach ($tmp as $k => $v) {
             if ($k == $selected) {
                 $out .= "<option selected=\"selected\" value=\"{$k}\">{$v}</option>";
             } else {
                 $out .= "<option value=\"{$k}\">{$v}</option>";
             }
         }
     }
     if (isset($params['assign'])) {
         $smarty->assign(trim($params['assign']), $out);
         return;
     }
     return $out;
 }
Ejemplo n.º 2
0
             for ($i = 0; $i < count($dbr); $i++) {
                 $tmp2[$dbr[$i]['company_name']] = $dbr[$i]['id'];
             }
             $obj->field = $this->CreateInputDropdown($id, 'cal_field_' . $obj->safename, $tmp2, -1, $field_value);
         }
         break;
     case 4:
         // file attachment
         $obj->field = null;
         $dir = $this->GetPreference('uploaddirectory', $config['uploads_path']);
         $pattern = explode(',', $this->GetPreference('uploadfiletypes', 'jpg,jpeg,gif,png'));
         $excludes = array('_*', '.??*');
         foreach ($pattern as &$one) {
             $one = '*.' . $one;
         }
         $files = cge_dir::recursive_glob($dir, $pattern, 'FILES', $excludes);
         if (!is_array($files) || count($files) == 0) {
             continue;
         }
         $out = array($this->Lang('none') => -1);
         foreach ($files as $one) {
             $one = substr($one, strlen($dir));
             if (startswith($one, '/')) {
                 $one = substr($one, 1);
             }
             $out[$one] = $one;
         }
         $obj->field = $this->CreateInputDropdown($id, 'cal_field_' . $obj->safename, $out, -1, $field_value);
         break;
 }
 $tmp[$obj->safename] = $obj;