From 8b86caddf491fca58a066eafbb9a81032565a4a3 Mon Sep 17 00:00:00 2001 From: CaMer0n Date: Sun, 19 Aug 2012 02:33:43 +0000 Subject: [PATCH] MediaCategories added to plugin.xml spec. and install/uninstall routine. Paste fixes for wysiwyg. Custom-Page issue corrected. admin-ui enhanced for images categories. --- e107_admin/cpage.php | 14 ++++++- e107_admin/image.php | 67 +++++++++++++++++++++++++----- e107_admin/update_routines.php | 18 ++++---- e107_handlers/application.php | 5 ++- e107_handlers/form_handler.php | 4 +- e107_handlers/media_class.php | 36 ++++++++++++++-- e107_handlers/plugin_class.php | 71 +++++++++++++++++++++++++++++++- e107_plugins/gallery/plugin.xml | 3 ++ e107_plugins/tinymce/wysiwyg.php | 4 -- 9 files changed, 188 insertions(+), 34 deletions(-) diff --git a/e107_admin/cpage.php b/e107_admin/cpage.php index 1bea2d79c..97a46988a 100644 --- a/e107_admin/cpage.php +++ b/e107_admin/cpage.php @@ -782,14 +782,26 @@ class page_admin_ui extends e_admin_ui if(!$type && (!$page_title || !$page_sef)) { e107::getMessage()->addError(CUSLAN_34, 'default', true); + + + e107::getRedirect()->redirect(e_ADMIN_ABS.'cpage.php'); } - if(!$type && $sql->db_Count('page', '(page_id)', ($mode ? "page_id<>{$mode} AND " : '')."page_sef!='{$page_sef}'")) + // FIXME Causes false positives on Update.. - what is trying to be achieved with this check? + /* + if(!$type && $sql->db_Count('page', '(page_id)', ($mode ? "page_id != {$mode} AND " : '')."page_sef != '{$page_sef}'")) { e107::getMessage()->addError(CUSLAN_34, 'default', true); + + e107::getMessage()->addDebug("type=".$type, 'default', true); + e107::getMessage()->addDebug("page_title=".$page_title, 'default', true); + e107::getMessage()->addDebug("page_sef=".$page_sef, 'default', true); + e107::getMessage()->addDebug("Mode=".$mode, 'default', true); + e107::getRedirect()->redirect(e_ADMIN_ABS.'cpage.php'); } + */ if($type && empty($_POST['menu_name'])) { diff --git a/e107_admin/image.php b/e107_admin/image.php index 8666dee96..bcdacc50d 100644 --- a/e107_admin/image.php +++ b/e107_admin/image.php @@ -145,39 +145,54 @@ class media_cat_ui extends e_admin_ui protected $batchDelete = false; public $ownerCount = array(); - // protected $listQry = "SELECT * FROM #faq_info"; // without any Order or Limit. + // protected $listQry = "SELECT * FROM #core_media_cat"; // without any Order or Limit. + protected $listOrder = 'media_cat_owner asc'; + // protected $editQry = "SELECT * FROM #faq_info WHERE faq_info_id = {ID}"; protected $fields = array( //'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'), - 'media_cat_id' => array('title'=> LAN_ID, 'type' => 'number', 'width' =>'5%', 'forced'=> TRUE, 'readonly'=>TRUE), + 'media_cat_id' => array('title'=> LAN_ID, 'type' => 'number', 'width' =>'5%', 'nolist'=>true, 'forced'=> TRUE, 'readonly'=>TRUE), 'media_cat_image' => array('title'=> LAN_IMAGE, 'type' => 'image', 'data' => 'str', 'width' => '100px', 'thclass' => 'center', 'class'=>'center', 'readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60','readonly'=>FALSE, 'batch' => FALSE, 'filter'=>FALSE), - 'media_cat_owner' => array('title'=> "Owner", 'type' => 'dropdown', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>FALSE), + 'media_cat_owner' => array('title'=> "Owner", 'type' => 'dropdown', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>FALSE), 'media_cat_category' => array('title'=> LAN_CATEGORY, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>TRUE), 'media_cat_title' => array('title'=> LAN_TITLE, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>FALSE), 'media_cat_diz' => array('title'=> LAN_DESCRIPTION, 'type' => 'bbarea', 'width' => '30%', 'readParms' => 'expand=...&truncate=150&bb=1','readonly'=>FALSE), // Display name 'media_cat_class' => array('title'=> LAN_VISIBILITY, 'type' => 'userclass', 'width' => 'auto', 'data' => 'int'), 'media_cat_order' => array('title'=> LAN_ORDER, 'type' => 'text', 'width' => '5%', 'thclass' => 'right', 'class'=> 'right' ), - 'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'width' => '10%', 'forced'=>TRUE, 'thclass' => 'center last', 'class' => 'center') + 'options' => array('title'=> LAN_OPTIONS, 'type' => 'method', 'noedit'=>true, 'width' => '10%', 'forced'=>TRUE, 'thclass' => 'center last', 'class' => 'center') ); function init() { - $this->fields['media_cat_owner']['writeParms'] = array( + + $restricted = array( "_common" => "_common", "_icon" => "_icon", "news" => "news", "page" => "page", - "gallery" => "gallery", - "download" => "download" - + "download" => "download" ); + if($_GET['action'] == 'list') + { + $this->fields['media_cat_owner']['writeParms'] = $restricted; + } + $sql = e107::getDb(); + + $sql->db_Select_gen("SELECT media_cat_owner, count(media_cat_id) as number FROM `#core_media_cat` GROUP BY media_cat_owner"); while($row = $sql->db_Fetch()) { - $this->ownerCount[$row['media_cat_owner']] = $row['number']; + $this->ownerCount[$row['media_cat_owner']] = $row['number']; + $own = $row['media_cat_owner']; + if(!in_array($own,$restricted)) + { + + $this->fields['media_cat_owner']['writeParms'][$own] = $own; + + } } } @@ -212,7 +227,37 @@ class media_cat_ui extends e_admin_ui class media_cat_form_ui extends e_admin_form_ui { + protected $restrictedOwners = array( + '_common', + 'news', + 'page', + 'download', + '_icon' + ); + + + function options($parms, $value, $id) + { + if($_GET['action'] == 'create' || $_GET['action'] == 'edit') + { + return; + } + + $owner = $this->getController()->getListModel()->get('media_cat_owner'); + if(!in_array($owner,$this->restrictedOwners)) + { + return $this->renderValue('options',$value,'',$id); + } + + + + + // $save = ($_GET['bbcode']!='file') ? "e-dialog-save" : ""; + // e-dialog-close + + + } } @@ -1379,13 +1424,13 @@ class media_admin_ui extends e_admin_ui $mes->addWarning($f['fname']." couldn't be renamed. Check file perms."); } - + $large = e107::getParser()->thumbUrl($f['path'].$f['fname'], 'w=800', true); $text .= " ".$frm->checkbox("batch_selected[".$c."]",$f['fname'])." ".$this->preview($f)." - ".$f['fname']." + ".$f['fname']." ".$frm->text('batch_import_name['.$c.']', ($_POST['batch_import_name'][$c] ? $_POST['batch_import_name'][$c] : $default['title']))." diff --git a/e107_admin/update_routines.php b/e107_admin/update_routines.php index 07d30caed..d9fc63aaf 100644 --- a/e107_admin/update_routines.php +++ b/e107_admin/update_routines.php @@ -1117,14 +1117,14 @@ function update_706_to_800($type='') e107::getMessage()->addDebug("core-media-cat `media_cat_nick` field removed."); } - $query = "INSERT INTO `".MPREFIX."core_media_cat` (`media_cat_id`, `media_cat_owner`, `media_cat_category`, `media_cat_title`, `media_cat_diz`, `media_cat_class`, `media_cat_image`, `media_cat_order`) VALUES - (0, 'gallery', 'gallery_1', 'Gallery 1', 'Visible to the public at /gallery.php', 0, '', 0); - "; - - if(mysql_query($query)) - { - e107::getMessage()->addDebug("Added core-media-cat Gallery."); - } + // $query = "INSERT INTO `".MPREFIX."core_media_cat` (`media_cat_id`, `media_cat_owner`, `media_cat_category`, `media_cat_title`, `media_cat_diz`, `media_cat_class`, `media_cat_image`, `media_cat_order`) VALUES + // (0, 'gallery', 'gallery_1', 'Gallery 1', 'Visible to the public at /gallery.php', 0, '', 0); + /// "; + // + // if(mysql_query($query)) + // { + // e107::getMessage()->addDebug("Added core-media-cat Gallery."); + // } } } @@ -1183,7 +1183,7 @@ function update_706_to_800($type='') mysql_query("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'download', 'download_thumb', 'Download Thumbnails', '', 253, '', 0);"); mysql_query("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'download', 'download_file', 'Download Files', '', 253, '', 0);"); - mysql_query("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'gallery', 'gallery_1', 'Gallery', 'Visible to the public at /gallery.php', 0, '', 0);"); + // mysql_query("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'gallery', 'gallery_1', 'Gallery', 'Visible to the public at /gallery.php', 0, '', 0);"); mysql_query("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'news', 'news_thumb', 'News Thumbnails (Legacy)', 'Legacy news thumbnails. ', 253, '', 1);"); diff --git a/e107_handlers/application.php b/e107_handlers/application.php index abfd9e4ff..8cb99575b 100644 --- a/e107_handlers/application.php +++ b/e107_handlers/application.php @@ -891,7 +891,10 @@ class eRouter public static function clearCache() { - @unlink(e_CACHE_URL.'config.php'); + if(file_exists(e_CACHE_URL.'config.php')) + { + @unlink(e_CACHE_URL.'config.php'); + } } /** diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index 75c4e710b..059c78be4 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -2083,13 +2083,13 @@ class e_form case 'image': //TODO - thumb, image list shortcode, js tooltip... $label = varset($parms['label'], 'LAN_EDIT'); unset($parms['label']); - $ret = $this->imagepicker($key, $value, defset($label, $label), vartrue($parms['__options'])); + $ret = $this->imagepicker($key, $value, defset($label, $label), $parms); break; case 'file': //TODO - thumb, image list shortcode, js tooltip... $label = varset($parms['label'], 'LAN_EDIT'); unset($parms['label']); - $ret = $this->filepicker($key, $value, defset($label, $label), vartrue($parms['__options'])); + $ret = $this->filepicker($key, $value, defset($label, $label), $parms); break; case 'icon': diff --git a/e107_handlers/media_class.php b/e107_handlers/media_class.php index 30ea16d12..d1ad9e489 100644 --- a/e107_handlers/media_class.php +++ b/e107_handlers/media_class.php @@ -203,17 +203,20 @@ class e_media * Create media category. * 'class' data is optional, 'id' key is ignored * - * @param array $data associative array, db keys should be passed without the leading 'media_cat_' e.g. 'class', 'nick', etc. + * @param array $data associative array, db keys should be passed without the leading 'media_cat_' e.g. 'class', 'type', etc. * @return integer last inserted ID or false on error */ - public function createCategory($data) + public function createCategory($datas) { - foreach ($data as $k => $v) + foreach ($datas as $k => $v) { $data['media_cat_'.$k] = $v; } $data['media_cat_id'] = 0; - if(!isset($data['media_cat_class']) || '' === $data['media_cat_class']) $data['media_cat_class'] = defset('e_UC_MEMBER', 253); + if(!isset($data['media_cat_class']) || '' === $data['media_cat_class']) + { + $data['media_cat_class'] = defset('e_UC_MEMBER', 253); + } return e107::getDb()->db_Insert('core_media_cat', $data); } @@ -237,6 +240,31 @@ class e_media // TODO } + public function deleteAllCategories($owner='') + { + if($owner == '') + { + return; + } + + $sql = e107::getDb(); + + $sql->db_Select('core_media_cat',"media_cat_category", "media_cat_owner = '".$owner."' "); + while($row = $sql->db_Fetch()) + { + $categories[] = "'".$row['media_cat_category']."'"; + } + + if($sql->db_Delete('core_media_cat', "media_cat_owner = '".$owner."' ")) + { + //TODO retrieve all category names for owner, and reset all media categories to _common. + return TRUE; + // return $sql->db_Update('core_media', "media_category = '_common_image' WHERE media_category IN (".implode(",",$categories).")"); + } + + return FALSE; + } + /** * Return an Array of Media Categories */ diff --git a/e107_handlers/plugin_class.php b/e107_handlers/plugin_class.php index 5a944c18d..59474de7a 100644 --- a/e107_handlers/plugin_class.php +++ b/e107_handlers/plugin_class.php @@ -54,7 +54,8 @@ class e107plugin 'e_cron', 'e_mailout', 'e_sitelink', - 'e_tohtml' + 'e_tohtml', + 'e_featurebox' ); // List of all plugin variables which need to be checked - install required if one or more set and non-empty @@ -1293,6 +1294,11 @@ class e107plugin { $this->XmlBBcodes($function, $plug_vars); } + + if (varset($plug_vars['mediaCategories'])) + { + $this->XmlMediaCategories($function, $plug_vars); + } $this->manage_icons($this->plugFolder, $function); @@ -1499,7 +1505,7 @@ class e107plugin { $status = ($this->manage_link('add', $url, $linkName, $perm)) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; - $mes->add("Adding Link: {$linkName} with url [{$url}] and perm {$perm} ", $status); + $mes->add("Adding Link: {$linkName} with url [{$url}] and perm {$perm} ", $status); //TODO LAN } if ($function == 'upgrade' && $remove) //remove inactive links on upgrade @@ -1539,6 +1545,67 @@ class e107plugin } } } + + // Only 1 category per file-type allowed. ie. 1 for images, 1 for files. + function XmlMediaCategories($function, $tag) + { + $mes = e107::getMessage(); + // print_a($tag); + + $folder = $tag['folder']; + $prevType = ""; + + + //print_a($tag); + switch ($function) + { + case 'install': + $c = 1; + foreach($tag['mediaCategories']['category'] as $v) + { + $type = $v['@attributes']['type']; + + if($type != 'image' && $type !='file') + { + continue; + } + + if($c == 3 || ($prevType == $type)) + { + $mes->addDebug("Only 2 Media Categories are permitted during install. One for images and one for files."); + break; + } + + $prevType = $type; + + $data['owner'] = $folder; + $data['category'] = $folder."_".$c; + $data['title'] = $v['@value']; + // $data['type'] = $v['@attributes']['type']; //TODO + $data['class'] = 253; + $status = e107::getMedia()->createCategory($data) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; + $mes->add("Adding Media Category: {$data['category']}", $status); + + $c++; + } + + break; + + case 'uninstall': // Probably best to leave well alone + $status = e107::getMedia()->deleteAllCategories($folder)? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; + $mes->add("Deleting All Media Categories owned by : {$folder}", $status); + break; + + + } + + + } + + + + + /** diff --git a/e107_plugins/gallery/plugin.xml b/e107_plugins/gallery/plugin.xml index 9a3733a7d..5b5373006 100644 --- a/e107_plugins/gallery/plugin.xml +++ b/e107_plugins/gallery/plugin.xml @@ -15,6 +15,9 @@ + + Gallery 1 + 800 800 diff --git a/e107_plugins/tinymce/wysiwyg.php b/e107_plugins/tinymce/wysiwyg.php index 70d03eea5..373ae5836 100644 --- a/e107_plugins/tinymce/wysiwyg.php +++ b/e107_plugins/tinymce/wysiwyg.php @@ -313,14 +313,10 @@ class wysiwyg ); } - if(ADMIN) { $this->config['external_link_list_url'] = e_PLUGIN_ABS."tiny_mce/filelist.php"; } - - - }