Ejemplo n.º 1
0
 /**
  * 
  * The linkpicker method renders a linkpicker element that allows you to select a link to a post type or taxonomy type of your choice
  * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  * @return string $output the string returned contains the html code generated within the method
  */
 static function linkpicker($element)
 {
     $original = $element;
     $new_std = explode(',', $element['std'], 2);
     $pt = array_flip(AviaHelper::public_post_types());
     $ta = array_flip(AviaHelper::public_taxonomies(false, true));
     if (isset($new_std[1])) {
         $original['std'] = $new_std[1];
     }
     $allowed_pts = isset($original['posttype']) ? $original['posttype'] : $pt;
     $allowed_tas = isset($original['taxtype']) ? $original['taxtype'] : $ta;
     if (in_array('single', $element['subtype'])) {
         foreach ($pt as $key => $type) {
             if (in_array($type, $allowed_pts)) {
                 $original['subtype'] = $type;
                 $html = self::select($original);
                 if ($html) {
                     AviaHelper::register_template($type, $html);
                 } else {
                     unset($pt[$key]);
                 }
             } else {
                 unset($pt[$key]);
             }
         }
     }
     if (in_array('taxonomy', $element['subtype'])) {
         foreach ($ta as $key => $type) {
             if (in_array($type, $allowed_tas)) {
                 $original['subtype'] = 'cat';
                 $original['taxonomy'] = $type;
                 $html = self::select($original);
                 if ($html) {
                     AviaHelper::register_template($type, $html);
                 } else {
                     unset($ta[$key]);
                 }
             } else {
                 unset($ta[$key]);
             }
         }
     }
     if (isset($new_std[1])) {
         $element['std'] = $new_std[1];
     }
     $original['subtype'] = "";
     foreach ($element['subtype'] as $value => $key) {
         switch ($key) {
             case "manually":
                 if ($new_std[0] != $key) {
                     $element['std'] = "http://";
                 }
                 $original['subtype'][$value] = $key;
                 $html = self::input($element);
                 AviaHelper::register_template($key, $html);
                 break;
             case "single":
                 $original['subtype'][$value] = $pt;
                 break;
             case "taxonomy":
                 $original['subtype'][$value] = $ta;
                 break;
             default:
                 $original['subtype'][$value] = $key;
                 break;
         }
     }
     if (!empty($element['ajax'])) {
         AviaHelper::print_templates();
     }
     $original['std'] = $new_std[0];
     unset($original['multiple']);
     $output = self::select($original);
     return $output;
 }
Ejemplo n.º 2
0
 /**
  * 
  * The linkpicker method renders a linkpicker element that allows you to select a link to a post type or taxonomy type of your choice
  * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  * @return string $output the string returned contains the html code generated within the method
  *
  * @todo: currently only one linkpicker per modal window possible
  */
 static function linkpicker($element)
 {
     //fallback for previous default input link elements: convert a http://www.link.at value to a manually entry
     if (strpos($element['std'], 'http://') === 0) {
         $element['std'] = 'manually,' . $element['std'];
     }
     //necessary for installations with thousands of posts
     @ini_set("memory_limit", "256M");
     $original = $element;
     $new_std = explode(',', $element['std'], 2);
     $pt = array_flip(AviaHelper::public_post_types());
     $ta = array_flip(AviaHelper::public_taxonomies(false, true));
     if (isset($new_std[1])) {
         $original['std'] = $new_std[1];
     }
     $allowed_pts = isset($original['posttype']) ? $original['posttype'] : $pt;
     $allowed_tas = isset($original['taxtype']) ? $original['taxtype'] : $ta;
     if (in_array('single', $element['subtype'])) {
         foreach ($pt as $key => $type) {
             if (in_array($type, $allowed_pts)) {
                 $original['subtype'] = $type;
                 $html = self::select($original);
                 if ($html) {
                     AviaHelper::register_template($original['id'] . '-' . $type, $html);
                 } else {
                     unset($pt[$key]);
                 }
             } else {
                 unset($pt[$key]);
             }
         }
     }
     if (in_array('taxonomy', $element['subtype'])) {
         foreach ($ta as $key => $type) {
             if (in_array($type, $allowed_tas)) {
                 $original['subtype'] = 'cat';
                 $original['taxonomy'] = $type;
                 $html = self::select($original);
                 if ($html) {
                     AviaHelper::register_template($original['id'] . '-' . $type, $html);
                 } else {
                     unset($ta[$key]);
                 }
             } else {
                 unset($ta[$key]);
             }
         }
     }
     if (isset($new_std[1])) {
         $element['std'] = $new_std[1];
     }
     $original['subtype'] = "";
     foreach ($element['subtype'] as $value => $key) {
         switch ($key) {
             case "manually":
                 if ($new_std[0] != $key) {
                     $element['std'] = "http://";
                 }
                 $original['subtype'][$value] = $key;
                 $html = self::input($element);
                 AviaHelper::register_template($original['id'] . '-' . $key, $html);
                 break;
             case "single":
                 $original['subtype'][$value] = $pt;
                 break;
             case "taxonomy":
                 $original['subtype'][$value] = $ta;
                 break;
             default:
                 $original['subtype'][$value] = $key;
                 break;
         }
     }
     if (!empty($element['ajax'])) {
         AviaHelper::print_templates();
     }
     $original['std'] = $new_std[0];
     unset($original['multiple']);
     $output = self::select($original);
     return $output;
 }