'Critical CSS', 'description' => 'Control critical css.', 'page callback' => 'drupal_get_form', 'page arguments' => array('advagg_critical_css_admin_settings_form'), 'type' => MENU_LOCAL_TASK, 'access arguments' => array('administer site configuration'), 'file path' => $file_path, 'file' => 'advagg_critical_css.admin.inc', 'weight' => 10, ); return $items; } /** * Implements hook_module_implements_alter(). */ function advagg_critical_css_module_implements_alter(&$implementations, $hook) { // Move critical_css_advagg_mod_critical_css_file_pre_alter to the bottom. if ($hook === 'critical_css_advagg_mod_critical_css_file_pre_alter' && array_key_exists('advagg_critical_css', $implementations)) { $item = $implementations['advagg_critical_css']; unset($implementations['advagg_critical_css']); $implementations['advagg_critical_css'] = $item; } } /** * @} End of "addtogroup hooks". */ /** * @addtogroup advagg_hooks * @{ */ /** * Implements hook_critical_css_advagg_mod_critical_css_file_pre_alter(). */ function advagg_critical_css_advagg_mod_critical_css_file_pre_alter(&$filename, &$params, &$inline_strings) { list($dirs, $front_page, $object) = $params; // Build query parameters. $lookup = array($dirs[6]); if ($front_page) { $lookup = array(''); } $lookup[] = $dirs[9]; $lookup[] = $dirs[10]; if (!empty($object->type)) { $lookup[] = $object->type; } $type = array(2, 8); $users = array(rtrim($dirs[2], '/\\'), rtrim($dirs[3], '/\\')); // Get Results. $result = advagg_critical_css_table_get($GLOBALS['theme'], $type, $lookup, $users); // Put into the inline strings array. if (!empty($result)) { // Set string values. $inline_strings[0] = $result['css']; $inline_strings[1] = $result['dns']; $inline_strings[2] = $result['pre']; // Disable file lookup. $dirs[0] = ''; $dirs[1] = ''; } // Repack the $params array. $params = array($dirs, $front_page, $object); } /** * @} End of "addtogroup advagg_hooks". */ /** * Get the db select return object. * * @param string $theme * Name of the current theme. * @param array $type * Array of int types to lookup. * @param array $lookup * The lookup value. * @param array $user * Array of user string values. * * @return SelectQuery * Return the SelectQuery object after it has been executed. */ function advagg_critical_css_table_get($theme, array $type, array $lookup, array $user) { $output = array(); try { $results = db_select('advagg_critical_css', 'acc') ->fields('acc') ->condition('theme', $theme) ->condition('type', $type, 'IN') ->condition('user', $user, 'IN') ->condition('lookup', $lookup, 'IN') ->orderBy('type', 'DESC') ->execute(); // Get first result. $output = $results->fetchAssoc(); // Check for a better match in other results if they exist. foreach ($results as $values) { $values = (array) $values; if ($values['type'] < $output['type']) { $output = $values; break; } if ($values['type'] = $output['type']) { if (($values['user'] === 'anonymous' || $values['user'] === 'authenticated') && $output['user'] === 'all' ) { $output = $values; break; } if (is_int($values['user'])) { $output = $values; break; } } } } catch (PDOException $e) { // Log the error if in development mode. if (variable_get('advagg_cache_level', ADVAGG_CACHE_LEVEL) < 0) { watchdog('advagg_critical_css', 'Development Mode - Caught PDO Exception: @info', array('@info' => $e)); } } return $output; } /** * Insert/Update data in the advagg_critical_css table. * * @param array $records * List of rows needed that need to be changed in the db. * * @return array * Return array of booleans if anything was written to the database. */ function advagg_critical_css_table_insert_update(array $records) { $return = array(); foreach ($records as $values) { list($keys, $record) = $values; if (!isset($record['settings'])) { $record['settings'] = ''; } try { $return[] = db_merge('advagg_critical_css') ->key(array( 'theme' => $keys['theme'], 'user' => $keys['user'], 'type' => $keys['type'], 'lookup' => $keys['lookup'], )) ->fields($record) ->execute(); } catch (PDOException $e) { // Log the error if in development mode. if (variable_get('advagg_cache_level', ADVAGG_CACHE_LEVEL) < 0) { watchdog('advagg_critical_css', 'Development Mode - Caught PDO Exception: @info', array('@info' => $e)); } } } return $return; } /** * Delete data in the advagg_critical_css table. * * @param array $records * List of rows needed that need to be removed from the db. * * @return array * Return array of booleans if anything was removed from the database. */ function advagg_critical_css_table_delete(array $records) { $return = array(); foreach ($records as $record) { try { $return[] = db_delete('advagg_critical_css') ->condition('theme', $record['theme']) ->condition('user', $record['user']) ->condition('type', $record['type']) ->condition('lookup', $record['lookup']) ->execute(); } catch (PDOException $e) { // Log the error if in development mode. if (variable_get('advagg_cache_level', ADVAGG_CACHE_LEVEL) < 0) { watchdog('advagg_critical_css', 'Development Mode - Caught PDO Exception: @info', array('@info' => $e)); } } } return $return; }