Ejemplo n.º 1
0
 private function getQuestion()
 {
     if (!$this->question) {
         ctools_include('object-cache');
         $this->question = ctools_object_cache_get('ctools_ajax_sample', $this->getQuestionId());
     }
     if (!$this->question) {
         module_load_include('class.php', 'chgk_db', 'classes/DbQuestionFactory');
         $factory = new DbQuestionFactory();
         $this->question = $factory->getQuestionFromTextId($this->getQuestionId());
     }
     return $this->question;
 }
 /**
  * Retrieve the item currently being edited from the object cache.
  */
 function edit_cache_get($item, $op = 'edit')
 {
     ctools_include('object-cache');
     if (is_string($item)) {
         $name = $item;
     } else {
         $name = $this->edit_cache_get_key($item, $op);
     }
     $cache = ctools_object_cache_get('ctui_' . $this->plugin['name'], $name);
     if ($cache) {
         $cache->export_ui_item_is_cached = TRUE;
         return $cache;
     }
 }
 /**
  * Main entry point to edit an item.
  */
 function edit_page($js, $input, $item, $step = NULL)
 {
     ctools_include('object-cache');
     drupal_set_title($this->get_page_title('edit', $item));
     $cached = ctools_object_cache_get('finder', $item->name);
     if (!empty($cached)) {
         $item = $cached;
     }
     $form_state = array('plugin' => $this->plugin, 'object' => &$this, 'ajax' => $js, 'item' => $item, 'op' => 'edit', 'form type' => 'edit', 'rerender' => TRUE, 'no_redirect' => TRUE, 'step' => $step, 'function args' => func_get_args());
     $output = $this->edit_execute_form($form_state);
     if (!empty($form_state['executed'])) {
         $export_key = $this->plugin['export']['key'];
         drupal_goto(str_replace('%ctools_export_ui', $form_state['item']->{$export_key}, $this->plugin['redirect']['edit']));
     }
     return $output;
 }
Ejemplo n.º 4
0
 protected function __construct()
 {
     # Singleton Pattern: we don't permit an explicit call of the constructor!
     global $user;
     $this->tmp_storage_path = drupal_realpath('public://') . '/filedepot/';
     $this->tmp_incoming_path = drupal_realpath('public://') . '/filedepot/incoming/';
     $this->root_storage_path = 'private://filedepot/';
     /* @TODO: Need to add logic that will only be executed once to test
      * that the private filesystem has been setup and the filedepot folders
      * for the repository have been created - we can get the $private path.
      */
     $private = variable_get('file_private_path', '');
     $this->recordCountPass1 = variable_get('filedepot_pass1_recordcount', 2);
     $this->recordCountPass2 = variable_get('filedepot_pass2_recordcount', 10);
     $iconsettings = unserialize(variable_get('filedepot_extension_data', ''));
     if (!empty($iconsettings)) {
         $this->iconmap = array_merge($this->iconmap, $iconsettings);
     }
     $permsdata = variable_get('filedepot_default_perms_data', '');
     if (!empty($permsdata)) {
         $permsdata = unserialize($permsdata);
     } else {
         $permsdata = array('authenticated user' => array('view', 'upload'));
     }
     if (isset($permsdata['owner']) and count($permsdata['owner'] > 0)) {
         $this->defOwnerRights = $permsdata['owner'];
     } else {
         $this->defOwnerRights = array('view', 'admin');
     }
     if (isset($permsdata['owner'])) {
         unset($permsdata['owner']);
         // It has now been assigned to defOwnerRights variable
     }
     if (isset($permsdata['group']) and count($permsdata['group'] > 0)) {
         $this->defGroupRights = $permsdata['group'];
     } else {
         $this->defGroupRights = array('view');
     }
     if (isset($permsdata['group'])) {
         unset($permsdata['group']);
         // It has now been assigned to defGroupRights variable
     }
     $this->defRoleRights = $permsdata;
     // Remaining permissions are the role assignments
     // Is og enabled?
     if (module_exists('og') and module_exists('og_access')) {
         $this->ogenabled = TRUE;
     }
     if (user_is_logged_in()) {
         // This cached setting will really only benefit when there are many thousand access records like portal23
         // User setting (all users) is cleared each time a folder permission is updated.
         // But this library is also included for all AJAX requests
         $data = db_query("SELECT allowable_view_folders FROM {filedepot_usersettings} WHERE uid=:uid", array('uid' => $user->uid))->fetchField();
         if (empty($data)) {
             $this->allowableViewFolders = $this->getAllowableCategories('view', FALSE);
             $data = serialize($this->allowableViewFolders);
             if (db_query("SELECT count(uid) FROM {filedepot_usersettings} WHERE uid=:uid", array('uid' => $user->uid))->fetchField() == 0) {
                 /* Has a problem handling serialized data - we couldn't unserialize the data afterwards.
                  * The problem is the pre-constructed SQL statement. When we use the function "udate_sql($sql)",
                  * we construct the SQL statement without using any argument. A serialized data normally contains curly brackets.
                  * When you call update_sql($sql), it then hands your pre-constructed $sql to the function db_query($sql).
                  * Inside the function db_query(), it replace the curly bracket with table prefix blindly,
                  * even the curly bracket inside data string are converted.
                  * And thus you will not be able to unserialize the data from the table anymore.
                  * To get around this, instead of calling update_sql, call db_query($sql, $args).
                  * Put all the variables to be inserted into the table into the argument list.
                  * This way db_query will only convert the curly bracket surrounding the table name.
                  */
                 db_query("INSERT INTO {filedepot_usersettings} (uid, allowable_view_folders, notify_newfile, notify_changedfile, allow_broadcasts) VALUES (:uid, :view, :newfile, :changed, :broadcasts)", array(':uid' => $user->uid, ':view' => $data, ':newfile' => variable_get('filedepot_default_notify_newfile', 0), ':changed' => variable_get('filedepot_default_notify_filechange', 0), ':broadcasts' => variable_get('filedepot_default_allow_broadcasts', 0)));
             } else {
                 db_query("UPDATE {filedepot_usersettings} set allowable_view_folders=:view WHERE uid=:uid", array(':view' => $data, ':uid' => $user->uid));
             }
         }
         $this->allowableViewFolders = '';
         if ($this->ogenabled == TRUE) {
             if (variable_get('filedepot_organic_group_mode_enabled', 0) == 1) {
                 $this->ogmode_enabled = TRUE;
             }
             if (self::$ogmode_initialized === FALSE) {
                 self::$ogmode_initialized = TRUE;
                 // Only want to do this once.
                 // Using the ctools cache functionality to save which group the user has selected - set in filedepot_main()
                 ctools_include('object-cache');
                 $gid = ctools_object_cache_get('filedepot', 'grpid');
                 // Check if group context was passed into filedepot and if not check if OG was set by another site feature
                 if ($gid == 0 and isset($_SESSION['og_last']) and $_SESSION['og_last'] > 0) {
                     $gid = $_SESSION['og_last'];
                 } else {
                     if (module_exists('og_context') and isset($_SESSION['og_context']['gid'])) {
                         $gid = $_SESSION['og_context']['gid'];
                     }
                 }
                 if ($gid > 0) {
                     $this->ogrootfolder = db_query("SELECT cid FROM {filedepot_categories} WHERE group_nid=:gid AND pid=0", array(':gid' => $gid))->fetchfield();
                     if ($this->ogrootfolder !== FALSE and $this->ogrootfolder > 0) {
                         $this->allowableViewFolders = array();
                         array_push($this->allowableViewFolders, $this->ogrootfolder);
                         $folderlist = $this->getRecursiveCatIDs($this->allowableViewFolders, $this->ogrootfolder, 'view');
                         $this->allowableGroupViewFoldersSql = implode(',', $folderlist);
                         // Format to use for SQL statement - test for allowable categories
                     }
                 }
             }
         }
         if (empty($this->allowableViewFolders)) {
             $this->allowableViewFolders = unserialize($data);
         }
         $this->allowableViewFoldersSql = implode(',', $this->allowableViewFolders);
         // Format to use for SQL statement - test for allowable categories
     } else {
         $this->allowableViewFolders = $this->getAllowableCategories('view', FALSE);
         $this->allowableViewFoldersSql = implode(',', $this->allowableViewFolders);
         // Format to use for SQL statement - test for allowable categories
     }
 }
 /**
  * Retrieve a cached object
  *
  * @param $name
  *   A string name use for retrieval
  * @return the object that was cached
  */
 public function get()
 {
     ctools_include('object-cache');
     return ctools_object_cache_get($this->obj, $this->key);
 }