function _uploads_AdminDoDeleteCategory(&$module, $category_id)
{
    // get the category details
    $category = $module->_getUploadCategoryDetails($category_id);
    if (!$category) {
        return $module->Lang('error_categorynotfound');
    }
    // get the files from the category
    $query = 'SELECT upload_id FROM ' . cms_db_prefix() . 'module_uploads 
             WHERE upload_category_id = ?';
    $db =& $module->GetDb();
    $tmp = $db->GetOne($query, array($category_id));
    if ($tmp) {
        return $module->Lang('error_categorynotempty');
    }
    $dir = $module->_categoryPath($category['upload_category_path']);
    cge_dir::recursive_rmdir($dir);
    if (file_exists($dir)) {
        return $module->Lang('error_delete', $dir);
    }
    // delete the category from the db
    $db =& $module->GetDb();
    $query = "DELETE FROM " . cms_db_prefix() . "module_uploads_categories WHERE upload_category_id = ?";
    $dbresult = $db->Execute($query, array($category_id));
    // send an event
    $parms[] = array();
    $parms['name'] = $category['upload_category_name'];
    $parms['path'] = $category['upload_category_path'];
    $module->SendEvent('OnDeleteCategory', $parms);
    // and we're done
    return FALSE;
}
 // check if the directory is already in use
 $query = "SELECT upload_category_id from " . cms_db_prefix() . "module_uploads_categories WHERE upload_category_path = ?";
 $dbresult = $db->Execute($query, array($params['input_categorypath']));
 if ($dbresult->FetchRow()) {
     $this->smarty->assign('error', "1");
     $this->smarty->assign('message', $this->Lang("error_pathinuse"));
     $error = true;
 } else {
     // Create the directory if it doesn't exist
     $do_scan = false;
     $dir = $this->_categoryPath($params['input_categorypath']);
     if (file_exists($dir)) {
         $do_scan = true;
     } else {
         // create the directory
         $result = cge_dir::mkdirr($dir);
         if ($result === FALSE) {
             $this->smarty->assign('error', "1");
             $this->smarty->assign('message', $this->Lang("error_categoryexists") . ': ' . $dir);
             $error = true;
         }
         // create an index.html file (empty)
         if ($this->GetPreference('create_dummy_index_html')) {
             touch($dir . DIRECTORY_SEPARATOR . "index.html");
         }
     }
     if (!$error) {
         $groups = null;
         if (isset($params['input_grouplist'])) {
             $groups = implode(',', $params['input_grouplist']);
         }
for ($i = 1; $i < 72; $i++) {
    $opts[$i] = $i;
}
$smarty->assign('input_textsize', $this->CreateInputDropdown($id, 'watermark_textsize', $opts, -1, $this->GetPreference('watermark_textsize', 12)));
$smarty->assign('input_textangle', $this->CreateInputText($id, 'watermark_angle', $this->GetPreference('watermark_textangle', '0'), 3, 3));
// font list
$list = array();
$dir1 = dirname(__FILE__) . '/fonts';
$list1 = cge_dir::file_list_regexp($dir1, '[Tt][Tt][Ff]$');
foreach ($list1 as $one) {
    $list[$one] = $dir1 . '/' . $one;
}
// todo, make this configurable
$config = cms_config::get_instance();
$dir2 = $config['uploads_path'];
$list2 = cge_dir::file_list_regexp($dir2, '[Tt][Tt][Ff]$');
if (!empty($list2)) {
    foreach ($list2 as $one) {
        $list[$one] = $dir2 . '/' . $one;
    }
}
$smarty->assign('input_font', $this->CreateInputDropdown($id, 'watermark_font', $list, -1, $this->GetPreference('watermark_font')));
$smarty->assign('input_textcolor', $this->CreateColorDropdown($id, 'watermark_textcolor', $this->GetPreference('watermark_textcolor', '#00FFFF')));
$smarty->assign('input_bgcolor', $this->CreateColorDropdown($id, 'watermark_bgcolor', $this->GetPreference('watermark_bgcolor', '#FFFFFF')));
$smarty->assign('input_transparent', $this->CreateInputYesNoDropdown($id, 'watermark_transparent', $this->GetPreference('watermark_transparent', 1)));
$smarty->assign('input_image', $this->CreateFileDropdown($id, 'watermark_file', $this->GetPreference('watermark_file'), '', 'jpg,jpeg,png,gif', '1'));
$nums = array();
for ($i = 100; $i > 0; $i--) {
    $nums[$i] = $i;
}
$smarty->assign('input_translucency', $this->CreateInputDropdown($id, 'watermark_translucency', $nums, -1, $this->GetPreference('watermark_translucency', 100)));
Ejemplo n.º 4
0
 /**
  * A convenience function to create a list of filenames in a specified directory.
  *
  * @deprecated
  * @param string $id The module action id
  * @param string $name the name for the dropdown.
  * @param string $selectedfile The initial value for the dropdown (an image filename)
  * @param string $dir The path (relative to the uploads path) to the directory to pull images from.  If not specified, the image uploads path will be used.
  * @param string $extensions A comma separated list of filename extensions to include in the list.  If not specified the module preference will be used.
  * @param bool   $allownone Allow no files to be selected.
  * @param bool   $allowmultiple To allow selecting multiple files.
  * @param int    $size The size of the dropdown.
  * @return string.
  */
 function CreateFileDropdown($id, $name, $selectedfile = '', $dir = '', $extensions = '', $allownone = '', $allowmultiple = false, $size = 3)
 {
     $config = cms_config::get_instance();
     if ($dir == '') {
         $dir = $config['uploads_path'];
     } else {
         while (startswith($dir, '/') && $dir != '') {
             $dir = substr($dir, 1);
         }
         $dir = $config['uploads_path'] . $dir;
     }
     if ($extensions == '') {
         $extensions = $this->GetPreference('fileextensions', '');
     }
     $tmp = cge_dir::get_file_list($dir, $extensions);
     $tmp2 = array();
     if (!empty($allownone)) {
         $cge = \cms_utils::get_module(MOD_CGEXTENSIONS);
         $tmp2[$cge->Lang('none')] = '';
     }
     $filelist = array_merge($tmp2, $tmp);
     if ($allowmultiple) {
         if (!endswith($name, '[]')) {
             $name .= '[]';
         }
         return $this->CreateInputSelectList($id, $name, $filelist, array(), $size);
     }
     return $this->CreateInputDropdown($id, $name, $filelist, -1, $selectedfile);
 }
 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;
 }
            $n_removed = $this->clear_cached_files();
            $this->SetMessage($this->Lang('msg_cachecleaned', $n_removed));
            audit('', $this->GetName(), $n_removed . ' files cleaned from cache directory');
        } else {
            if (isset($params['clear_all'])) {
                // just nuke the cache directory completely.
                $cache_path = $this->GetPreference('cache_path', cms_join_path('uploads', '_' . $this->GetName()));
                $dir = $cache_path;
                if (!startswith($dir, '/')) {
                    $dir = $config['root_path'] . '/' . $cache_path;
                }
                $p1 = realpath($dir);
                $p2 = realpath($config['root_path']);
                if (!startswith($p1, $p2) || $p1 == $p2) {
                    throw new Exception($this->Lang('error_cachepath_invalid'));
                }
                cge_dir::recursive_rmdir($dir);
                mkdir($dir);
                @touch($dir . '/index.html');
                $this->SetMessage($this->Lang('msg_cacheremoved'));
                audit('', $this->GetName(), 'All cached files removed');
            }
        }
    }
} catch (Exception $e) {
    $this->SetError($e->getMessage());
}
$this->RedirectToTab($id);
#
# EOF
#
Ejemplo n.º 7
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;
 function CreateFileDropdown($id, $name, $selectedfile = '', $dir = '', $extensions = '', $allownone = '', $allowmultiple = false, $size = 3)
 {
     $config = cmsms()->GetConfig();
     if ($dir == '') {
         $dir = $config['uploads_path'];
     }
     if ($extensions == '') {
         $extensions = $this->GetPreference('fileextensions', '');
     }
     $tmp = cge_dir::get_file_list($dir, $extensions);
     $tmp2 = array();
     if (!empty($allownone)) {
         $tmp2[$this->Lang('none')] = '';
     }
     $filelist = array_merge($tmp2, $tmp);
     if ($allowmultiple) {
         if (!endswith($name, '[]')) {
             $name .= '[]';
         }
         return $this->CreateInputSelectList($id, $name, $filelist, array(), $size);
     }
     return $this->CreateInputDropdown($id, $name, $filelist, -1, $selectedfile);
 }