[ Index ]

PHP Cross Reference of PageLines Framework

title

Body

[close]

/admin/ -> actions.admin.php (source)

   1  <?php
   2  /**
   3   * actions.admin.php
   4   */
   5  
   6  // *********************************************
   7  // MOVE USERS TO FRONT END EDITOR
   8  // *********************************************
   9  
  10  define( 'PL_ACTIVATE_URL' , apply_filters('pl_activate_url', home_url().'?tablink=account&tabsublink=welcome'));
  11  
  12  global $pagenow;
  13  if( is_admin() && isset($_GET['activated'] ) && $pagenow == "themes.php" )
  14      wp_redirect( PL_ACTIVATE_URL );
  15  
  16  
  17  add_action( 'admin_init', 'pagelines_check_customizer' );
  18  function pagelines_check_customizer() {
  19      
  20      global $pagenow;
  21      
  22      if($pagenow == 'customize.php')
  23          wp_redirect( PL_ACTIVATE_URL );
  24  }
  25  
  26  
  27  /**
  28   * Add Javascript for Layout Controls from the Layout UI class
  29   *
  30   */
  31  $layout_control_js = new PageLinesLayoutControl();
  32  add_action( 'pagelines_admin_head', array(&$layout_control_js, 'layout_control_javascript' ) );
  33  
  34  
  35  /**
  36   * Admin Body Class
  37   *
  38   * Adds the 'pagelines_ui' class
  39   *
  40   * @package PageLines DMS
  41   * @since   ...
  42   *
  43   * @param   $class
  44   *
  45   * @return  string
  46   */
  47  function pagelines_admin_body_class( $class ){
  48  
  49      $class = $class.'pagelines_ui';
  50  
  51      return $class;
  52  }
  53  /**
  54   * Checks if PHP5
  55   *
  56   * Tests for installed version of PHP higher than 5.0 and prints message if version is found to be lower.
  57   *
  58   * @package PageLines DMS
  59   * @subpackage Functions Library
  60   * @since 4.0.0
  61   */
  62  add_action( 'pagelines_before_optionUI', 'pagelines_check_php' );
  63  function pagelines_check_php(){
  64      if( floatval( phpversion() ) < 5.0 ){
  65          printf( __( "<div class='config-error'><h2>PHP Version Problem</h2>Looks like you are using PHP version: <strong>%s</strong>. To run this framework you will need PHP <strong>5.0</strong> or better...<br/><br/> Don't worry though! Just check with your host about a quick upgrade.</div>", 'pagelines' ), phpversion() );
  66      }
  67  }
  68  
  69  
  70  /**
  71   * Ajax Callback
  72   *
  73   * AJAX OPTION SAVING
  74   * Used to save via AJAX theme options and image uploads
  75   *
  76   * @package PageLines DMS
  77   * @since 1.2.0
  78   */
  79  add_action( 'wp_ajax_pagelines_ajax_post_action', 'pagelines_ajax_callback' );
  80  function pagelines_ajax_callback() {
  81      /** This is how you get access to the database */
  82      global $wpdb;
  83  
  84      $save_type = ( $_POST['type'] ) ? $_POST['type'] : null;
  85  
  86      $setting = $_POST['setting'];
  87      $button_id = $_POST['oid'];
  88  
  89      $pieces = explode( 'OID', $_POST['oid'] );
  90      $oid = $pieces[0];
  91      $parent_oid = ( isset($pieces[1]) ) ? $pieces[1] : null;
  92  
  93      // Uploads
  94      if( $save_type == 'upload' ) {
  95  
  96  
  97          $arr_file_type = wp_check_filetype( basename( $_FILES[$button_id]['name'] ));
  98  
  99          $uploaded_file_type = $arr_file_type['type'];
 100  
 101          // Set an array containing a list of acceptable formats
 102          $allowed_file_types = array( 'image/jpg','image/jpeg','image/gif','image/png', 'image/x-icon');
 103  
 104          if( in_array( $uploaded_file_type, $allowed_file_types ) ) {
 105  
 106              $filename = $_FILES[ $button_id ];
 107              $filename['name'] = preg_replace( '/[^a-zA-Z0-9._\-]/', '', $filename['name'] );
 108  
 109              $override['test_form'] = false;
 110              $override['action'] = 'wp_handle_upload';
 111  
 112              $uploaded_file = wp_handle_upload( $filename, $override );
 113  
 114              $upload_tracking[] = $button_id;
 115  
 116              plupop( $oid, $uploaded_file['url'], array( 'setting' => $setting, 'parent' => $parent_oid ) );
 117  
 118              $name = 'PageLines- ' . addslashes( $filename['name'] );
 119  
 120              $attachment = array(
 121                              'guid' => $uploaded_file['url'],
 122                              'post_mime_type'    => $uploaded_file_type,
 123                              'post_title'        => $name,
 124                              'post_content'        => '',
 125                              'post_status'        => 'inherit'
 126                          );
 127  
 128              $attach_id = wp_insert_attachment( $attachment, $uploaded_file['file'] );
 129              $attach_data = wp_generate_attachment_metadata( $attach_id, $uploaded_file['file'] );
 130              wp_update_attachment_metadata( $attach_id,  $attach_data );
 131  
 132          } else
 133              $uploaded_file['error'] = __( 'Unsupported file type!', 'pagelines' );
 134  
 135          if( !empty( $uploaded_file['error'] ) )
 136              echo sprintf( __('Upload Error: %s', 'pagelines' ) , $uploaded_file['error'] );
 137          else{
 138              //print_r($r);
 139              echo $uploaded_file['url']; // Is the Response
 140  
 141          }
 142      } elseif( $save_type == 'image_reset' ){
 143          plupop( $oid, null, array( 'setting' => $setting, 'parent' => $parent_oid ) );
 144      }
 145  
 146      die();
 147  }
 148  
 149  /**
 150   * (AJAX) Save Template Map
 151   *
 152   * Used to save via AJAX theme options and image uploads
 153   *
 154   * @package PageLines DMS
 155   * @since   ...
 156   *
 157   * @uses save_tempalte_map
 158   */
 159  add_action( 'wp_ajax_pagelines_save_sortable', 'ajax_save_template_map' );
 160  function ajax_save_template_map() {
 161      /** This is how you get access to the database */
 162      global $wpdb;
 163  
 164      /** Full Template Map */
 165      $templatemap = get_option( PAGELINES_TEMPLATE_MAP );
 166  
 167      /** Order of the sections */
 168      $section_order =  $_GET['orderdata'];
 169  
 170      /** Get array / variable format */
 171      parse_str( $section_order );
 172  
 173      /** Selected Template */
 174      $selected_template = esc_attr( $_GET['template'] );
 175  
 176      /** Explode by hyphen to get heirarchy */
 177      $template_heirarchy = explode( '-', $selected_template );
 178  
 179      if( isset($template_heirarchy[1]) )
 180          $templatemap[$template_heirarchy[0]]['templates'][$template_heirarchy[1]]['sections'] = urlencode_deep( $section );
 181      else
 182          $templatemap[$selected_template]['sections'] = $section;
 183  
 184      save_template_map( $templatemap );
 185  
 186      PageLinesRenderCSS::flush_version( false );
 187  
 188      echo true;
 189  
 190      die();
 191  }
 192  
 193  /**
 194   * Ajax Save Options Callback
 195   *
 196   * @package PageLines DMS
 197   * @since   ...
 198   *
 199   */
 200  add_action( 'wp_ajax_pagelines_ajax_save_option', 'pagelines_ajax_save_option_callback' );
 201  function pagelines_ajax_save_option_callback() {
 202      /** This is how you get access to the database */
 203      global $wpdb;
 204  
 205      $option_name = $_POST['option_name'];
 206      $option_value = $_POST['option_value'];
 207  
 208      update_option( $option_name, $option_value );
 209  
 210      die();
 211  }
 212  
 213  /**
 214   * Inline Help
 215   *
 216   * Load Inline help system.
 217   *
 218   * @package PageLines DMS
 219   * @since   ...
 220   *
 221   * @uses    PageLines_Inline_Help
 222   */
 223  add_action( 'admin_init', 'pagelines_inline_help' );
 224  function pagelines_inline_help() {
 225  
 226      $pl_help = new PageLines_Inline_Help;
 227  }
 228  
 229  /**
 230   * Page Columns
 231   *
 232   * Add custom columns to page/post views.
 233   *
 234   * @package PageLines DMS
 235   * @since   2.1.3
 236   *
 237   * @param   $columns
 238   * @return  array
 239   */
 240  add_filter('manage_edit-page_columns', 'pl_page_columns');
 241  function pl_page_columns($columns) {
 242  
 243          $columns['template'] = 'PageLines Template';
 244  
 245      return $columns;
 246  }
 247  
 248  /**
 249   * Post Columns
 250   *
 251   * @package PageLines DMS
 252   * @since   2.1.3
 253   *
 254   * @param   $columns
 255   * @return  array
 256   */
 257  add_filter('manage_edit-post_columns', 'pl_post_columns');
 258  function pl_post_columns($columns) {
 259  
 260          $columns['feature'] = 'Featured Image';
 261      return $columns;
 262  }
 263  
 264  /**
 265   * Posts Show Columns
 266   *
 267   * @package PageLines DMS
 268   * @since   ...
 269   *
 270   * @param   $name
 271   *
 272   */
 273  add_action('manage_posts_custom_column',  'pl_posts_show_columns');
 274  function pl_posts_show_columns($name) {
 275      global $post;
 276      switch ($name) {
 277  
 278          case 'feature':
 279              if( has_post_thumbnail( $post->ID )) {
 280                  the_post_thumbnail( array(48,48) );
 281              }
 282  
 283          break;
 284      }
 285  }
 286  
 287  /**
 288   * Page Show Columns
 289   *
 290   * @package PageLines DMS
 291   * @since   2.1.3
 292   *
 293   * @param   $name
 294   *
 295   * @uses    pl_file_get_contents
 296   */
 297  add_action( 'manage_pages_custom_column', 'pl_page_show_columns' );
 298  function pl_page_show_columns($name) {
 299      global $post;
 300      switch ($name) {
 301          case 'template':
 302              $template = get_post_meta( $post->ID, '_wp_page_template', true );
 303  
 304              if ( 'default' == $template ) {
 305                  _e( 'Default', 'pagelines' );
 306                  break;
 307              }
 308  
 309              $file = sprintf( '%s/%s', PL_PARENT_DIR, $template );
 310  
 311              if ( !is_file( $file ) )
 312                  $file = sprintf( '%s/%s', CHILD_DIR, $template );
 313  
 314              if ( !is_file( $file ) ) {
 315                  printf( '<a href="%s">%s</a>', admin_url( sprintf( 'post.php?post=%s&action=edit', $post->ID ) ), __( 'No Template Assigned', 'pagelines' ) ) ;
 316                  break;
 317              }
 318  
 319              $data = get_file_data( $file, array( 'name' => 'Template Name' ) );
 320  
 321              if ( is_array( $data ) && isset( $data['name'] ) )
 322                  $template = $data['name'];
 323              else
 324                  $template = __( 'Default', 'pagelines' );
 325  
 326              echo $template;
 327          break;
 328  
 329          case 'feature':
 330              if( has_post_thumbnail( $post->ID )) {
 331                  the_post_thumbnail( array(48,48) );
 332              }
 333  
 334          break;
 335      }
 336  }
 337  
 338  /**
 339   * Setup Versions and flush caches.
 340   *
 341   * @package PageLines DMS
 342   * @since   2.2
 343   */
 344  add_action( 'admin_init', 'pagelines_set_versions' );
 345  function pagelines_set_versions() {
 346      if ( current_user_can( 'edit_themes' ) ) {
 347          if( defined( 'PL_LESS_DEV' ) && PL_LESS_DEV ) {
 348              PageLinesRenderCSS::flush_version( false );
 349              delete_transient( 'pagelines_sections_cache' );
 350          }
 351      }
 352      set_theme_mod( 'pagelines_version', pl_get_theme_data( get_template_directory(), 'Version' ) );
 353      set_theme_mod( 'pagelines_child_version', pl_get_theme_data( get_stylesheet_directory(), 'Version' ) );
 354  }
 355  
 356  // make sure were running out of 'pagelines' folder.
 357  add_action( 'admin_notices', 'pagelines_check_folders' );
 358  function pagelines_check_folders() {
 359  
 360          $folder = basename( get_template_directory() );
 361  
 362          if( 'dms' == $folder )
 363              return;
 364  
 365          echo '<div class="updated">';
 366          printf( "<p><h3>Install Error!</h3><br />PageLines DMS must be installed in a folder called 'dms' to work with child themes and extensions.<br /><br />Current path: %s<br /></p>", get_template_directory() );
 367          echo '</div>';
 368  }
 369  
 370  add_action( 'activate_plugin', 'pagelines_purge_sections_cache' );
 371  add_action( 'deactivate_plugin', 'pagelines_purge_sections_cache' );
 372  function pagelines_purge_sections_cache() {
 373      delete_transient( 'pagelines_sections_cache' );
 374  }


Generated: Fri Aug 30 18:26:24 2013 Cross-referenced by PHPXref 0.7.1