PageRenderTime 30ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/magic-fields/RCCWP_CustomWritePanel.php

https://gitlab.com/endomorphosis/reservationtelco
PHP | 685 lines | 444 code | 98 blank | 143 comment | 48 complexity | 4458dd9cb003e74a4d7e12d24deaa94c MD5 | raw file
  1. <?php
  2. /**
  3. * In this Class can be found it the methods for work with Write Panels.
  4. */
  5. class RCCWP_CustomWritePanel
  6. {
  7. /**
  8. * Get all Write Panels.
  9. *
  10. * @return array of objects containing all write panels. Each object contains
  11. * id, name, description, display_order, capability_name, type, always_show
  12. */
  13. function GetCustomWritePanels() {
  14. global $wpdb;
  15. $sql = "SELECT id, name, description, display_order, capability_name, type, single FROM " . MF_TABLE_PANELS;
  16. $sql .= " ORDER BY display_order ASC";
  17. $results = $wpdb->get_results($sql);
  18. if (!isset($results))
  19. $results = array();
  20. return $results;
  21. }
  22. /**
  23. * Assign a specified write panel to a role.
  24. *
  25. * @param integer $customWritePanelId panel id
  26. * @param string $roleName role name (see roles in wordpress)
  27. */
  28. function AssignToRole($customWritePanelId, $roleName) {
  29. $customWritePanel = RCCWP_CustomWritePanel::Get($customWritePanelId);
  30. $capabilityName = $customWritePanel->capability_name;
  31. $role = get_role($roleName);
  32. $role->add_cap($capabilityName);
  33. }
  34. /**
  35. * Create a new write panel.
  36. *
  37. * @param string $name write panel name
  38. * @param string $description write panel description
  39. * @param array $standardFields a list of standard fields ids that are to be displayed in
  40. * in the panel. Use $STANDARD_FIELDS defined in RCCWP_Constant.php
  41. * @param array $categories array of category ids that are checked by default when the user
  42. * opens Write tab for that panel.
  43. * @param integer $display_order the order of the panel in Magic Fields > Write Panels tab
  44. * @param string $type 'post' or 'page'
  45. * @param boolean $createDefaultGroup indicates whether to create a default group.
  46. * @return the id of the write panel
  47. */
  48. function Create($name, $description = '', $standardFields = array(), $categories = array(), $display_order = 1, $type = FALSE, $createDefaultGroup=true,$single_post = 0, $default_theme_page = NULL, $default_parent_page = NULL) {
  49. include_once('RC_Format.php');
  50. global $wpdb;
  51. $capabilityName = RCCWP_CustomWritePanel::GetCapabilityName($name);
  52. if (!$type) $type = $_POST['radPostPage'];
  53. $sql = sprintf(
  54. "INSERT INTO " . MF_TABLE_PANELS .
  55. " (name, description, display_order, capability_name, type,single)" .
  56. " values" .
  57. " (%s, %s, %d, %s, %s,%d)",
  58. RC_Format::TextToSql($name),
  59. RC_Format::TextToSql($description),
  60. $display_order,
  61. RC_Format::TextToSql($capabilityName),
  62. RC_Format::TextToSql($type),
  63. $single_post
  64. );
  65. $wpdb->query($sql);
  66. $customWritePanelId = $wpdb->insert_id;
  67. if (!isset($categories))
  68. $categories = array();
  69. foreach ($categories as $cat_id)
  70. {
  71. $sql = sprintf(
  72. "INSERT INTO " . MF_TABLE_PANEL_CATEGORY .
  73. " (panel_id, cat_id)" .
  74. " values (%d, %d)",
  75. $customWritePanelId,
  76. $cat_id
  77. );
  78. $wpdb->query($sql);
  79. }
  80. if (!isset($standardFields))
  81. $standardFields = array();
  82. foreach ($standardFields as $standard_field_id)
  83. {
  84. $sql = sprintf(
  85. "INSERT INTO " . MF_TABLE_PANEL_STANDARD_FIELD .
  86. " (panel_id, standard_field_id)" .
  87. " values (%d, %d)",
  88. $customWritePanelId,
  89. $standard_field_id
  90. );
  91. $wpdb->query($sql);
  92. }
  93. // Create default group
  94. if ($createDefaultGroup){
  95. include_once('RCCWP_CustomGroup.php');
  96. RCCWP_CustomGroup::Create($customWritePanelId, '__default', false, false);
  97. }
  98. if($default_theme_page){
  99. $theme_key="t_".$name;
  100. $sql = "INSERT INTO ". $wpdb->postmeta .
  101. " (meta_key, meta_value) ".
  102. " VALUES ('".$theme_key."', '".$default_theme_page."')";
  103. $wpdb->query($sql);
  104. }
  105. if($default_parent_page && $default_parent_page >= 0){
  106. $parent_key="p_".$name;
  107. $sql = "INSERT INTO ". $wpdb->postmeta .
  108. " (meta_key, meta_value) ".
  109. " VALUES ('".$parent_key."', '".$default_parent_page."')";
  110. $wpdb->query($sql);
  111. }
  112. RCCWP_CustomWritePanel::AssignToRole($customWritePanelId, 'administrator');
  113. return $customWritePanelId;
  114. }
  115. /**
  116. * Delete a write panel without deleting its modules
  117. *
  118. * @param integer $customWritePanelId write panel id
  119. */
  120. function Delete($customWritePanelId = null) {
  121. if (isset($customWritePanelId)) {
  122. global $wpdb;
  123. $customWritePanel = RCCWP_CustomWritePanel::Get($customWritePanelId);
  124. $sql = sprintf(
  125. "DELETE FROM " . MF_TABLE_PANELS .
  126. " WHERE id = %d",
  127. $customWritePanel->id
  128. );
  129. $wpdb->query($sql);
  130. $sql = sprintf(
  131. "DELETE FROM " . MF_TABLE_PANEL_CATEGORY .
  132. " WHERE panel_id = %d",
  133. $customWritePanel->id
  134. );
  135. $wpdb->query($sql);
  136. $sql = sprintf(
  137. "DELETE FROM " . MF_TABLE_PANEL_STANDARD_FIELD .
  138. " WHERE panel_id = %d",
  139. $customWritePanelId
  140. );
  141. $wpdb->query($sql);
  142. }
  143. }
  144. /**
  145. * Get the properties of a write panel
  146. *
  147. * @param unknown_type $customWritePanelId
  148. * @return an object containing the properties of the write panel which are
  149. * id, name, description, display_order, capability_name, type
  150. */
  151. function Get($customWritePanelId) {
  152. global $wpdb;
  153. $sql = "SELECT id, name, description, display_order, capability_name, type,single FROM " . MF_TABLE_PANELS .
  154. " WHERE id = " . (int)$customWritePanelId;
  155. $results = $wpdb->get_row($sql);
  156. return $results;
  157. }
  158. /**
  159. * Gets a write panel id based on write panel name.
  160. *
  161. * @param string $name
  162. * @return the write panel id
  163. */
  164. function GetIdByName($name) {
  165. global $wpdb;
  166. return $wpdb->get_var("SELECT id FROM ".MF_TABLE_PANELS." WHERE name='".$name."'");
  167. }
  168. /**
  169. * Get the properties of a write panel
  170. *
  171. * @param unknown_type $customWritePanelId
  172. * @return an object containing the properties of the write panel which are
  173. * id, name, description, display_order, capability_name, type
  174. */
  175. function GetThemePage($customWritePanelName) {
  176. global $wpdb;
  177. $sql = "SELECT meta_value FROM " . $wpdb->postmeta .
  178. " WHERE meta_key = 't_".$customWritePanelName."' AND post_id = 0" ;
  179. $results = $wpdb->get_row($sql);
  180. if($results) return $results->meta_value;
  181. return false;
  182. }
  183. /**
  184. * Get the properties of a write panel
  185. *
  186. * @param unknown_type $customWritePanelId
  187. * @return an object containing the properties of the write panel which are
  188. * id, name, description, display_order, capability_name, type
  189. */
  190. function GetParentPage($customWritePanelName) {
  191. global $wpdb;
  192. $sql = "SELECT meta_value FROM " . $wpdb->postmeta .
  193. " WHERE meta_key = 'p_".$customWritePanelName."' AND post_id = 0" ;
  194. $results = $wpdb->get_row($sql);
  195. if($results) return $results->meta_value;
  196. return FALSE;
  197. }
  198. /**
  199. * Get a list of the ids of the categories assigned to a write panel
  200. *
  201. * @param integer $customWritePanelId write panel id
  202. * @return array of ids
  203. */
  204. function GetAssignedCategoryIds($customWritePanelId) {
  205. $results = RCCWP_CustomWritePanel::GetAssignedCategories($customWritePanelId);
  206. $ids = array();
  207. foreach ($results as $r)
  208. {
  209. $ids[] = $r->cat_id;
  210. }
  211. return $ids;
  212. }
  213. /**
  214. * Get a list of categories assigned to a write panel
  215. *
  216. * @param integer $customWritePanelId write panel id
  217. * @return array of objects, each object contains cat_id and cat_name
  218. */
  219. function GetAssignedCategories($customWritePanelId) {
  220. global $wpdb;
  221. if( $wpdb->terms != '' )
  222. {
  223. $sql = "SELECT rc.cat_id, wp.name AS cat_name FROM " .
  224. MF_TABLE_PANEL_CATEGORY . "
  225. rc JOIN $wpdb->terms wp ON rc.cat_ID = wp.term_id" . "
  226. WHERE panel_id = " . $customWritePanelId;
  227. }
  228. else
  229. {
  230. $sql = "SELECT rc.cat_id, cat_name FROM " .
  231. MF_TABLE_PANEL_CATEGORY . "
  232. rc JOIN $wpdb->categories wp ON rc.cat_ID = wp.cat_ID
  233. WHERE panel_id = " . $customWritePanelId;
  234. }
  235. $results = $wpdb->get_results($sql);
  236. if (!isset($results))
  237. $results = array();
  238. return $results;
  239. }
  240. /**
  241. * Create a capability name for a write panel given its name. This function is
  242. * copied from WP's sanitize_title_with_dashes($title) (formatting.php)
  243. *
  244. * @param string $customWritePanelName panel name
  245. * @return string capability name
  246. */
  247. function GetCapabilityName($customWritePanelName) {
  248. // copied from WP's sanitize_title_with_dashes($title) (formatting.php)
  249. $capabilityName = strip_tags($customWritePanelName);
  250. // Preserve escaped octets.
  251. $capabilityName = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $capabilityName);
  252. // Remove percent signs that are not part of an octet.
  253. $capabilityName = str_replace('%', '', $capabilityName);
  254. // Restore octets.
  255. $capabilityName = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $capabilityName);
  256. $capabilityName = remove_accents($capabilityName);
  257. if (seems_utf8($capabilityName))
  258. {
  259. if (function_exists('mb_strtolower'))
  260. {
  261. $capabilityName = mb_strtolower($capabilityName, 'UTF-8');
  262. }
  263. $capabilityName = utf8_uri_encode($capabilityName, 200);
  264. }
  265. $capabilityName = strtolower($capabilityName);
  266. $capabilityName = preg_replace('/&.+?;/', '', $capabilityName); // kill entities
  267. $capabilityName = preg_replace('/[^%a-z0-9 _-]/', '', $capabilityName);
  268. $capabilityName = preg_replace('/\s+/', '_', $capabilityName);
  269. $capabilityName = preg_replace('|-+|', '_', $capabilityName);
  270. $capabilityName = trim($capabilityName, '_');
  271. return $capabilityName;
  272. }
  273. /**
  274. * Get a list of the standard fields of a the write panel
  275. *
  276. * @param integer $customWritePanelId panel id
  277. * @return array of ids of the standard fields (see $STANDARD_FIELDS defined in RCCWP_Constant.php)
  278. */
  279. function GetStandardFields($customWritePanelId)
  280. {
  281. global $wpdb;
  282. $sql = "SELECT standard_field_id FROM " . MF_TABLE_PANEL_STANDARD_FIELD .
  283. " WHERE panel_id = " . $customWritePanelId;
  284. $results = $wpdb->get_col($sql);
  285. if (!isset($results))
  286. $results = array();
  287. return $results;
  288. }
  289. /**
  290. * Updates the properties of a write panel
  291. *
  292. * @param integer $customWritePanelId panel id
  293. * @param string $name write panel name
  294. * @param string $description write panel description
  295. * @param array $standardFields a list of standard fields ids that are to be displayed in
  296. * in the panel. Use $STANDARD_FIELDS defined in RCCWP_Constant.php
  297. * @param array $categories array of category ids that are checked by default when the user
  298. * opens Write tab for that panel.
  299. * @param integer $display_order the order of the panel in Magic Fields > Write Panels tab
  300. * @param string $type 'post' or 'page'
  301. */
  302. function Update($customWritePanelId, $name, $description = '', $standardFields = array(), $categories = array(), $display_order = 1, $type = FALSE, $createDefaultGroup=true,$single_post = 0, $default_theme_page = NULL, $default_parent_page = NULL)
  303. {
  304. include_once('RC_Format.php');
  305. global $wpdb;
  306. $capabilityName = RCCWP_CustomWritePanel::GetCapabilityName($name);
  307. $sql = sprintf(
  308. "UPDATE " . MF_TABLE_PANELS .
  309. " SET name = %s" .
  310. " , description = %s" .
  311. " , display_order = %d" .
  312. " , capability_name = %s" .
  313. " , type = %s" .
  314. " , single = %s" .
  315. " where id = %d",
  316. RC_Format::TextToSql($name),
  317. RC_Format::TextToSql($description),
  318. $display_order,
  319. RC_Format::TextToSql($capabilityName),
  320. RC_Format::TextToSql($_POST['radPostPage']),
  321. $single_post,
  322. $customWritePanelId );
  323. $wpdb->query($sql);
  324. if (!isset($categories) || empty($categories))
  325. {
  326. $sql = sprintf(
  327. "DELETE FROM " . MF_TABLE_PANEL_CATEGORY .
  328. " WHERE panel_id = %d",
  329. $customWritePanelId
  330. );
  331. $wpdb->query($sql);
  332. }
  333. else
  334. {
  335. $currentCategoryIds = array();
  336. $currentCategoryIds = RCCWP_CustomWritePanel::GetAssignedCategoryIds($customWritePanelId);
  337. $keepCategoryIds = array_intersect($currentCategoryIds, $categories);
  338. $deleteCategoryIds = array_diff($currentCategoryIds, $keepCategoryIds);
  339. $insertCategoryIds = array_diff($categories, $keepCategoryIds);
  340. foreach ($insertCategoryIds as $cat_id)
  341. {
  342. $sql = sprintf(
  343. "INSERT INTO " . MF_TABLE_PANEL_CATEGORY .
  344. " (panel_id, cat_id)" .
  345. " values (%d, %d)",
  346. $customWritePanelId,
  347. $cat_id
  348. );
  349. $wpdb->query($sql);
  350. }
  351. if (!empty($deleteCategoryIds))
  352. {
  353. $sql = sprintf(
  354. "DELETE FROM " . MF_TABLE_PANEL_CATEGORY .
  355. " WHERE panel_id = %d" .
  356. " AND cat_id IN (%s)",
  357. $customWritePanelId,
  358. implode(',', $deleteCategoryIds)
  359. );
  360. $wpdb->query($sql);
  361. }
  362. }
  363. if (!isset($standardFields) || empty($standardFields))
  364. {
  365. $sql = sprintf(
  366. "DELETE FROM " . MF_TABLE_PANEL_STANDARD_FIELD .
  367. " WHERE panel_id = %d",
  368. $customWritePanelId
  369. );
  370. $wpdb->query($sql);
  371. }
  372. else
  373. {
  374. $currentStandardFieldIds = array();
  375. $currentStandardFieldIds = RCCWP_CustomWritePanel::GetStandardFields($customWritePanelId);
  376. $keepStandardFieldIds = array_intersect($currentStandardFieldIds, $standardFields);
  377. $deleteStandardFieldIds = array_diff($currentStandardFieldIds, $keepStandardFieldIds);
  378. $insertStandardFieldIds = array_diff($standardFields, $keepStandardFieldIds);
  379. foreach ($insertStandardFieldIds as $standard_field_id)
  380. {
  381. $sql = sprintf(
  382. "INSERT INTO " . MF_TABLE_PANEL_STANDARD_FIELD .
  383. " (panel_id, standard_field_id)" .
  384. " values (%d, %d)",
  385. $customWritePanelId,
  386. $standard_field_id
  387. );
  388. $wpdb->query($sql);
  389. }
  390. if (!empty($deleteStandardFieldIds))
  391. {
  392. $sql = sprintf(
  393. "DELETE FROM " . MF_TABLE_PANEL_STANDARD_FIELD .
  394. " WHERE panel_id = %d" .
  395. " AND standard_field_id IN (%s)",
  396. $customWritePanelId,
  397. implode(',', $deleteStandardFieldIds)
  398. );
  399. $wpdb->query($sql);
  400. }
  401. }
  402. if($default_theme_page){
  403. $theme_key="t_".$name;
  404. //check if exist template in postmeta
  405. $check_template ="SELECT meta_id FROM ".$wpdb->postmeta." WHERE meta_key='".$theme_key."' ";
  406. $query_template= $wpdb->query($check_template);
  407. if($query_template){
  408. $sql = "UPDATE ". $wpdb->postmeta .
  409. " SET meta_value = '".$default_theme_page."' ".
  410. " WHERE meta_key = '".$theme_key."' AND post_id = '0' ";
  411. }else{
  412. $sql = "INSERT INTO ". $wpdb->postmeta .
  413. " (meta_key, meta_value) ".
  414. " VALUES ('".$theme_key."', '".$default_theme_page."')";
  415. }
  416. $wpdb->query($sql);
  417. }
  418. if($default_parent_page && $default_parent_page >= 0){
  419. $parent_key="p_".$name;
  420. //check if exist parent in postmeta
  421. $check_parent ="SELECT meta_id FROM ".$wpdb->postmeta." WHERE meta_key='".$parent_key."' ";
  422. $query_parent = $wpdb->query($check_parent);
  423. if($query_parent){
  424. $sql = "UPDATE ". $wpdb->postmeta .
  425. " SET meta_value = '".$default_parent_page."' ".
  426. " WHERE meta_key = '".$parent_key."' AND post_id = '0' ";
  427. }else{
  428. $sql = "INSERT INTO ". $wpdb->postmeta .
  429. " (meta_key, meta_value) ".
  430. " VALUES ('".$parent_key."', '".$default_parent_page."')";
  431. }
  432. $wpdb->query($sql);
  433. }elseif($default_parent_page == -1){
  434. delete_post_meta(0, "p_".$name);
  435. }
  436. }
  437. /**
  438. * Retrieves the groups of a module
  439. *
  440. * @param integer $customWriteModuleId module id
  441. * @return array of objects representing basic information of the group,
  442. * each object contains id, name and module_id
  443. */
  444. function GetCustomGroups($customWritePanelId)
  445. {
  446. global $wpdb;
  447. $sql = "SELECT * FROM " . MF_TABLE_PANEL_GROUPS .
  448. " WHERE panel_id = " . $customWritePanelId .
  449. " ORDER BY name";
  450. $results =$wpdb->get_results($sql);
  451. if (!isset($results))
  452. $results = array();
  453. return $results;
  454. }
  455. /**
  456. * Import a write panel given the file path.
  457. * @param string $panelFilePath the full path of the panel file
  458. * @param string $writePanelName the write panel name, if this value if false, the function will
  459. * use the pnl filename as the write panel name. The default value is false
  460. * @param boolean $overwrite whether to overwrite existing panels with the same name
  461. * @return the panel id, or false in case of error.
  462. */
  463. function Import($panelFilePath, $writePanelName = false, $overwrite = false){
  464. global $wpdb;
  465. include_once('RCCWP_CustomGroup.php');
  466. include_once('RCCWP_CustomField.php');
  467. include_once('RCCWP_Application.php');
  468. if (!$writePanelName)
  469. //use filename
  470. $writePanelName = basename($panelFilePath, ".pnl");
  471. if ($writePanelName == '') return false;
  472. $writePanelID = RCCWP_CustomWritePanel::GetIdByName($writePanelName);
  473. if ($writePanelID && !$overwrite) {
  474. // Append a number if the panel already exists,
  475. $i = 2;
  476. $temp_name = $writePanelName . "_1";
  477. while (RCCWP_CustomWritePanel::GetIdByName($temp_name)){
  478. $temp_name = $writePanelName. "_" . $i++;
  479. }
  480. $writePanelName = $temp_name;
  481. }
  482. // Unserialize file
  483. $imported_data = unserialize(file_get_contents($panelFilePath));
  484. $types_results = RCCWP_CustomField::GetCustomFieldTypes();
  485. $types = array();
  486. foreach($types_results as $types_result){
  487. $types[$types_result->name] = $types_result->id;
  488. }
  489. // Prepare categories list
  490. $assignedCategories = array();
  491. if(is_array($imported_data['panel']->assignedCategories)){
  492. foreach($imported_data['panel']->assignedCategories as $cat_name){
  493. $assignedCategories[] = wp_create_category($cat_name);
  494. }
  495. }
  496. //Create write panel
  497. if($writePanelID && $overwrite) {
  498. RCCWP_CustomWritePanel::Update($existingPanelId, $writePanelName, $imported_data['panel']->description, $imported_data['panel']->standardFieldsIDs, $assignedCategories,$imported_data['panel']->display_order, $imported_data['panel']->type, false,$imported_data['panel']->single,$imported_data['panel']->theme, $imported_data['panel']->parent_page);
  499. foreach (RCCWP_CustomWritePanel::GetCustomGroups($writePanelID) as $group) {
  500. RCCWP_CustomGroup::Delete($group->id);
  501. }
  502. } else {
  503. $writePanelID = RCCWP_CustomWritePanel::Create($writePanelName, $imported_data['panel']->description, $imported_data['panel']->standardFieldsIDs, $assignedCategories,$imported_data['panel']->display_order, $imported_data['panel']->type, false,$imported_data['panel']->single,$imported_data['panel']->theme, $imported_data['panel']->parent_page);
  504. }
  505. if(is_array($imported_data['fields'])){
  506. foreach($imported_data['fields'] as $groupName => $group){
  507. // For backward compatability
  508. if (!isset($group->fields)) {
  509. $newGroup->fields = $group;
  510. $group = $newGroup;
  511. }
  512. // Import group
  513. $groupID = RCCWP_CustomGroup::Create($writePanelID, $groupName, $group->duplicate, $group->at_right);
  514. // Import group fields
  515. foreach ($group->fields as $field){
  516. $fieldOptions = @implode("\n", $field->options);
  517. $fieldDefault = @implode("\n", $field->default_value);
  518. if ($field->type == "Related Type") {
  519. $field->properties["panel_id"] = RCCWP_CustomWritePanel::GetIdByName($field->properties["panel_name"]);
  520. unset($field->properties["panel_name"]);
  521. }
  522. RCCWP_CustomField::Create($groupID, $field->name, $field->description, $field->display_order, $field->required_field, $types[$field->type], $fieldOptions, $fieldDefault, $field->properties, $field->duplicate,$field->help_text);
  523. }
  524. }
  525. }
  526. return $writePanelID;
  527. }
  528. /**
  529. * Export a write panel to file
  530. *
  531. * @param integer $panelID
  532. * @param string $exportedFilename the full path of the file to which the panel will be exported
  533. */
  534. function Export($panelID, $exportedFilename){
  535. include_once('RCCWP_CustomGroup.php');
  536. include_once('RCCWP_CustomField.php');
  537. $exported_data = array();
  538. $writePanel = RCCWP_CustomWritePanel::Get($panelID);
  539. $writePanel->standardFieldsIDs = RCCWP_CustomWritePanel::GetStandardFields($panelID);
  540. $writePanel->assignedCategories = array();
  541. $writePanel->theme = RCCWP_CustomWritePanel::GetThemePage($writePanel->name);
  542. $writePanel->parent_page = RCCWP_CustomWritePanel::GetParentPage($writePanel->name);
  543. $assignedCategories = RCCWP_CustomWritePanel::GetAssignedCategories($panelID);
  544. foreach($assignedCategories as $assignedCategory){
  545. $writePanel->assignedCategories[] = $assignedCategory->cat_name;
  546. }
  547. $moduleGroups = RCCWP_CustomWritePanel::GetCustomGroups($panelID);
  548. foreach( $moduleGroups as $moduleGroup){
  549. $fields = RCCWP_CustomGroup::GetCustomFields($moduleGroup->id);
  550. foreach ($fields as $field) {
  551. if ($field->type == "Related Type") {
  552. $tmp = RCCWP_CustomWritePanel::Get($field->properties["panel_id"]);
  553. $field->properties["panel_name"] = $tmp->name;
  554. unset($field->properties["panel_id"]);
  555. }
  556. }
  557. $groupFields[$moduleGroup->name]->fields = $fields;
  558. $groupFields[$moduleGroup->name]->duplicate = $moduleGroup->duplicate;
  559. $groupFields[$moduleGroup->name]->at_right = $moduleGroup->at_right;
  560. }
  561. $exported_data['panel'] = $writePanel;
  562. $exported_data['fields'] = $groupFields;
  563. $handle = fopen($exportedFilename, "w");
  564. $result = fwrite($handle, serialize($exported_data));
  565. @fclose($handle);
  566. }
  567. /**
  568. * Return the name of the write panel giving the post_id
  569. *
  570. * @param integer $post_id
  571. * @return string
  572. */
  573. function GetWritePanelName($post_id){
  574. global $wpdb;
  575. if ($the_post = wp_is_post_revision($post_id)){
  576. $post_id = $the_post;
  577. }
  578. //getting the panel id
  579. $panel_id = $wpdb->get_var("SELECT meta_value FROM $wpdb->postmeta WHERE post_id = {$post_id} AND meta_key = '_mf_write_panel_id'");
  580. if(empty($panel_id)){
  581. return false;
  582. }
  583. //Getting the write panel name using the id
  584. $properties = RCCWP_CustomWritePanel::Get($panel_id);
  585. return $properties->name;
  586. }
  587. }