/** * Loads a helper * * @param string $helper * @return void * @author Armando Sosa */ function __loadHelper($helper) { $helper = underscorize($helper); require_once DUP_PATH . "/helpers/{$helper}.php"; $className = ucfirst($helper) . "Helper"; $this->__helpers[$helper] = new $className($this); }
/** * Constructor * * @author Armando Sosa */ function __construct() { $this->name = get_class($this); if (!$this->title) { $this->title = $this->name; } if (empty($this->slug)) { $this->slug = str_replace('_widget', '', underscorize($this->name)); } $widgetOptions = array('classname' => $this->slug, 'description' => $this->description); $controlOptions = array('width' => $this->width); parent::__construct($this->name, $this->title, $widgetOptions, $controlOptions); }
/** * Handles the save part of the meta boxes fields. It's hooked into the save_post action. * * @param string $postId * @return void * @author Armando Sosa */ function save($postId, $multiple = null) { $this->initMetaboxes(); if (isset($_POST['dup_meta'][$this->name])) { $meta = $_POST['dup_meta'][$this->name]; } if ($multiple) { $boxes = $multiple; } else { $boxes = $this->metaboxes; } foreach ($boxes as $id => $box) { extract($box); if (isset($meta[$id])) { if (!isset($_POST[underscorize($id) . "_wpnonce"]) || !wp_verify_nonce($_POST[underscorize($id) . "_wpnonce"], $id)) { return $postId; } $data = $meta[$id]; if ($type == "multiple") { $this->save($postId, $multiple); } // format date/time data if ($type == 'date' || $type == 'datetime' || $type == 'time') { extract($data); $data = "{$year}-{$month}-{$day}"; if (isset($hour)) { $data .= " {$hour}:{$mins}:00"; } } // let's make available a callback for the developer if (!empty($box['beforeSave']) && is_callable($box['beforeSave'])) { $data = call_user_func_array($box['beforeSave'], array($data, $id, $postId, $this)); } if (!isset($box['unique'])) { $box['unique'] = true; } $this->updateField($postId, $id, $data, $box['unique']); } } }
/** * undocumented function * * @param string $postId * @return void * @author Armando Sosa */ function save($postId) { foreach ($this->settings as $id => $settings) { $key = $settings['field']; if (isset($_POST[$key])) { if (!isset($_POST[underscorize($id) . "_wpnonce"]) || !wp_verify_nonce($_POST[underscorize($id) . "_wpnonce"], $id)) { return $postId; } if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $postId)) { return $postId; } } else { if (!current_user_can('edit_post', $postId)) { return $postId; } } $data = $_POST[$key]; // let's make available a callback for the developer if (!empty($settings['beforeSave']) && is_callable($settings['beforeSave'])) { $data = call_user_func_array($settings['beforeSave'], array($data, $key, $postId, $this)); } $this->updateField($postId, $key, $data, $settings['unique']); } // if isset $_POST[$key] } // foreach }
/** * Add theme option pages * * @return void * @author Armando Sosa */ function addPanels() { foreach ($this->panels as $panel => $options) { if (!is_string($panel)) { $panel = $options; $options = array(); } $options = array_merge($this->defaultPanelOptions, $options); $function = array(&$this, $panel); $page = add_theme_page($options['pageTitle'], $options['menuTitle'], $options['accessLevel'], underscorize($panel), $function); if (!empty($options['scripts'])) { $this->nqScript($page, $options['scripts']); } if (!empty($options['styles'])) { $this->nqStyle($page, $options['styles']); } add_action("admin_print_scripts-{$page}", array(&$this, 'injectScripts')); add_action("admin_print_styles-{$page}", array(&$this, 'injectStyles')); } }
/** * undocumented function * * @param string $key * @param string $unique * @param string $object * @return void * @author Armando Sosa */ function field($key, $unique = true, $object = null) { $key = underscorize($key); if (!$object) { global $post; } else { $post =& $object; } return get_post_meta($post->ID, $key, $unique); }
/** * * Or else ... make it work! The web application takes decision of what to do and show it to the final user. * Without this function nothing works. Here is the core of grocery CRUD project. * * @access public */ public function render() { $this->pre_render(); if ($this->state_code != 0) { $this->state_info = $this->getStateInfo(); } else { throw new Exception('The state is unknown , I don\'t know what I will do with your data!', 4); die; } switch ($this->state_code) { case 15: //success //success case 1: //list if ($this->unset_list) { throw new Exception('You don\'t have permissions for this operation', 14); die; } if ($this->theme === null) { $this->set_theme($this->default_theme); } $this->setThemeBasics(); $this->set_basic_Layout(); $state_info = $this->getStateInfo(); $this->showList(false, $state_info); break; case 2: //add if ($this->unset_add) { throw new Exception('You don\'t have permissions for this operation', 14); die; } if ($this->theme === null) { $this->set_theme($this->default_theme); } $this->setThemeBasics(); $this->set_basic_Layout(); $this->showAddForm(); break; case 3: //edit if ($this->unset_edit) { throw new Exception('You don\'t have permissions for this operation', 14); die; } if ($this->theme === null) { $this->set_theme($this->default_theme); } $this->setThemeBasics(); $this->set_basic_Layout(); $state_info = $this->getStateInfo(); $this->showEditForm($state_info); break; case 4: //delete if ($this->unset_delete) { throw new Exception('This user is not allowed to do this operation', 14); die; } $state_info = $this->getStateInfo(); $delete_result = $this->db_delete($state_info); $this->delete_layout($delete_result); break; case 5: //insert if ($this->unset_add) { throw new Exception('This user is not allowed to do this operation', 14); die; } $state_info = $this->getStateInfo(); $insert_result = $this->db_insert($state_info); $this->insert_layout($insert_result); break; case 6: //update if ($this->unset_edit) { throw new Exception('This user is not allowed to do this operation', 14); die; } $state_info = $this->getStateInfo(); $update_result = $this->db_update($state_info); $this->update_layout($update_result, $state_info); break; case 7: //ajax_list //die('HERE'); if ($this->unset_list) { throw new Exception('You don\'t have permissions for this operation', 14); die; } if ($this->theme === null) { $this->set_theme($this->default_theme); } $this->setThemeBasics(); $this->set_basic_Layout(); $state_info = $this->getStateInfo(); $this->set_ajax_list_queries($state_info); $this->showList(true); break; case 8: //ajax_list_info if ($this->theme === null) { $this->set_theme($this->default_theme); } $this->setThemeBasics(); $this->set_basic_Layout(); $state_info = $this->getStateInfo(); $this->set_ajax_list_queries($state_info); $this->showListInfo(); break; case 9: //insert_validation $validation_result = $this->db_insert_validation(); $this->validation_layout($validation_result); break; case 10: //update_validation $validation_result = $this->db_update_validation(); $this->validation_layout($validation_result); break; case 11: //upload_file $state_info = $this->getStateInfo(); $upload_result = $this->upload_file($state_info); $this->upload_layout($upload_result, $state_info->field_name); break; case 12: //delete_file $state_info = $this->getStateInfo(); $state_info->file_name = base64_decode($state_info->file_name); // print_r($state_info->file_name); // die(); if ($_REQUEST['no_delete']) { $delete_file_result = array('success' => true, 'no_delete' => true); $ci =& get_instance(); $last_deleted_files = $ci->session->userdata('gc_last_deleted_files'); if (!is_array($last_deleted_files)) { $last_deleted_files = array(); } $subject_cls = underscorize($this->subject); if (!is_array($last_deleted_files[$subject_cls])) { $last_deleted_files[$subject_cls] = array(); } if (!in_array($state_info->file_name, $last_deleted_files[$subject_cls])) { $last_deleted_files[$subject_cls][] = $state_info->file_name; $ci->session->set_userdata('gc_last_deleted_files', $last_deleted_files); } // print_r($_REQUEST['no_delete']); // die(); } else { $delete_file_result = $this->delete_file($state_info); } $this->delete_file_layout($delete_file_result); break; /* case 13: //ajax_relation $state_info = $this->getStateInfo(); $ajax_relation_result = $this->ajax_relation($state_info); $ajax_relation_result[""] = ""; echo json_encode($ajax_relation_result); die(); break; case 14: //ajax_relation_n_n echo json_encode(array("34" => 'Johnny' , "78" => "Test")); die(); break; */ /* case 13: //ajax_relation $state_info = $this->getStateInfo(); $ajax_relation_result = $this->ajax_relation($state_info); $ajax_relation_result[""] = ""; echo json_encode($ajax_relation_result); die(); break; case 14: //ajax_relation_n_n echo json_encode(array("34" => 'Johnny' , "78" => "Test")); die(); break; */ case 16: //export to excel //a big number just to ensure that the table characters will not be cutted. $this->character_limiter = 1000000; if ($this->unset_export) { throw new Exception('You don\'t have permissions for this operation', 15); die; } if ($this->theme === null) { $this->set_theme($this->default_theme); } $this->setThemeBasics(); $this->set_basic_Layout(); $state_info = $this->getStateInfo(); $this->set_ajax_list_queries($state_info); $this->exportToExcel($state_info); break; case 17: //print //a big number just to ensure that the table characters will not be cutted. $this->character_limiter = 1000000; if ($this->unset_print) { throw new Exception('You don\'t have permissions for this operation', 15); die; } if ($this->theme === null) { $this->set_theme($this->default_theme); } $this->setThemeBasics(); $this->set_basic_Layout(); $state_info = $this->getStateInfo(); $this->set_ajax_list_queries($state_info); $this->print_webpage($state_info); break; case 18: //read if ($this->unset_read) { throw new Exception('You don\'t have permissions for this operation', 14); die; } if ($this->theme === null) { $this->set_theme($this->default_theme); } $this->setThemeBasics(); $this->set_basic_Layout(); $state_info = $this->getStateInfo(); $this->showReadForm($state_info); break; } return $this->get_layout(); }
function __echoAdminCSS() { $folder = underscorize(strtolower($this->name)); $adminCSS = 'wp-content/duperrific/tropes/' . $folder . '/css/admin.css'; echo '<link rel="stylesheet" type="text/css" href="' . get_option('siteurl') . "/" . $adminCSS . '"/>' . "\n"; }