public static function sendEmailer($to, $emailer, $debug = false)
 {
     if (!$to) {
         return false;
     }
     if (!Arr::iterable($emailer)) {
         return false;
     }
     $mail = new PHPMailer();
     $mail->Port = 1025;
     $mail->setFrom($emailer['from']);
     $mail->addReplyTo($emailer['from']);
     $mail->addAddress($to);
     $mail->isHTML(true);
     $mail->Subject = $emailer['subject'];
     $mail->Body = $emailer['rendered_template'];
     $did_it_send = $mail->send();
     if ($debug) {
         if ($did_it_send) {
             echo 'Message could not be sent.';
             echo 'Mailer Error: ' . $mail->ErrorInfo;
         } else {
             echo 'Message has been sent';
         }
         exit;
     }
 }
/**
 * Enqueue the JS
 * @param bool $is_admin
 * @param array $scripts
 */
function app_enqueue_script($is_admin = false)
{
    $scripts = $is_admin ? app_admin_get_js() : app_get_js();
    if (!Arr::iterable($scripts)) {
        return;
    }
    $template_directory = get_template_directory_uri();
    foreach ($scripts as $key => $script) {
        $path = preg_match('/^(https?\\:|\\/\\/)/', $script) ? $script : $template_directory . '/' . $script;
        wp_deregister_script($key);
        wp_register_script($key, $path, false, THEME_VERSION, true);
        wp_enqueue_script($key);
    }
}
Example #3
0
 /**
  * Include file with scoped variables
  * @param string $path
  * @param array $variables
  * @param bool $include_once
  * @param bool $die_on_error
  */
 public static function make($path, $variables = [], $include_once = false, $die_on_error = false)
 {
     $view_path = self::find($path, $die_on_error);
     if (Arr::iterable($variables)) {
         extract($variables);
     }
     ob_start();
     if ($include_once) {
         include_once $view_path;
     } else {
         include $view_path;
     }
     return ob_get_clean();
 }
Example #4
0
 /**
  * Get a select list
  * @param array $options
  * @param string $selected
  * @param array $attribs
  * @return string
  */
 public static function selecty($options, $selected = null, $attribs = array())
 {
     $htmls = array();
     $htmls[] = self::select(null, $attribs, false);
     if (Arr::iterable($options)) {
         foreach ($options as $value => $title) {
             $option_attribs = array('value' => $value);
             if ((string) $selected === (string) $value) {
                 $option_attribs['selected'] = 'selected';
             }
             $htmls[] = self::option($title, $option_attribs);
         }
     }
     $htmls[] = '</select>';
     return join("\n", $htmls);
 }
/**
 * Get edit link when admin is logged in
 * @param int $id (post ID or term ID)
 * @param string $edit_type (post type or taxonomy slug)
 * @param string $label (optional admin-facing name for $edit_type)
 * @param bool $display_inline (omit wrapping paragraph)
 * @return string (HTML)
 */
function get_edit_link($id = null, $edit_type = 'post', $label = null, $display_inline = false)
{
    if (!(is_user_logged_in() && current_user_can('manage_options'))) {
        return null;
    }
    $link_class = 'class="front-end-edit-link"';
    $link_tag = $display_inline ? 'span' : 'p';
    if (is_null($label)) {
        $label = Str::human(str_replace('-', ' ', $edit_type));
    }
    $subclasses = \Taco\Post\Loader::getSubclasses();
    $subclasses_machine = array_map(function ($el) {
        $el = substr($el, strrpos($el, '\\'));
        $el = Str::camelToHuman($el);
        $el = Str::machine($el, '-');
        return $el;
    }, $subclasses);
    if (in_array($edit_type, $subclasses_machine)) {
        // Edit post or display list of posts of this type
        $post_type_link = !is_null($id) ? get_edit_post_link($id) : '/wp-admin/edit.php?post_type=' . $edit_type;
        return sprintf('<%s %s><a href="%s">Edit %s</a></%s>', $link_tag, $link_class, $post_type_link, $label, $link_tag);
    }
    // Find an applicable post type for editing a custom term
    $post_type = null;
    $post_types_by_taxonomy = [];
    foreach ($subclasses as $subclass) {
        if (strpos($subclass, '\\') !== false) {
            $subclass = '\\' . $subclass;
        }
        $taxonomies = \Taco\Post\Factory::create($subclass)->getTaxonomies();
        if (Arr::iterable($taxonomies)) {
            foreach ($taxonomies as $key => $taxonomy) {
                $taxonomy_slug = is_array($taxonomy) ? $key : $taxonomy;
                $post_types_by_taxonomy[$taxonomy_slug][] = $subclass;
            }
        }
    }
    $post_types_by_taxonomy = array_unique($post_types_by_taxonomy);
    if (array_key_exists($edit_type, $post_types_by_taxonomy)) {
        $post_type = reset($post_types_by_taxonomy[$edit_type]);
        $post_type = substr($post_type, strrpos($post_type, '\\'));
        $post_type = Str::camelToHuman($post_type);
        $post_type = Str::machine($post_type, '-');
    } else {
        $post_type = 'post';
    }
    if (is_null($id)) {
        // View taxonomy term list
        return sprintf('<%s %s><a href="/wp-admin/edit-tags.php?taxonomy=%s&post_type=%s">View %ss</a></%s>', $link_tag, $link_class, $edit_type, $post_type, $label, $link_tag);
    }
    // Edit term
    return sprintf('<%s %s><a href="%s">Edit %s</a></%s>', $link_tag, $link_class, get_edit_term_link($id, $edit_type, $post_type), $label, $link_tag);
}
Example #6
0
 /**
  * Sanitize a list of numeric IDs, and return the same format
  * @param array/string $ids (array or comma-separated list)
  * @return array/string (same as input type)
  */
 public static function sanitizeIDs($ids)
 {
     if (!is_array($ids)) {
         $return_string = true;
         $ids = explode(',', $ids);
     }
     if (!Arr::iterable($ids)) {
         return false;
     }
     $ids = array_map('trim', $ids);
     $ids = array_filter($ids, 'strlen');
     $ids = array_map('intval', $ids);
     $ids = array_map('abs', $ids);
     return $return_string ? join(',', $ids) : $ids;
 }
/**
 * Enqueue the JS
 */
function app_enqueue_script()
{
    $scripts = app_get_js();
    if (!Arr::iterable($scripts)) {
        return;
    }
    foreach ($scripts as $k => $script) {
        wp_deregister_script($k);
        wp_register_script($k, get_template_directory_uri() . '/' . $script, false, THEME_VERSION, true);
        wp_enqueue_script($k);
    }
}
 /**
  * Get breadcrumbs HTML
  * @param \Taco\Post $post_obj
  * @return string HTML
  */
 public static function getBreadcrumbs(\Taco\Post $post_obj)
 {
     $separator = ' &raquo; ';
     $post_id = $post_obj->get('ID');
     $post_type = $post_obj->getPostType();
     $ancestor_links = array();
     $post_title = null;
     if (is_archive()) {
         // This is the blog archive, what to do for breadcrumbs here?
         return null;
     }
     if ($post_type == 'page') {
         $post_title = $post_obj->getTheTitle();
         $ancestors = get_post_ancestors($post_id);
         if (Arr::iterable($ancestors)) {
             $ancestors = array_reverse($ancestors);
             foreach ($ancestors as $ancestor_post_id) {
                 $ancestor = \Taco\Post\Factory::create($ancestor_post_id, false);
                 $single_post = get_post($post_id);
                 $ancestor_links[] = sprintf('<li><a href="%s">%s</a></li>', $ancestor->getPermalink(), $ancestor->getTheTitle());
             }
         }
     } elseif ($post_type == 'article') {
         $ancestor_links[] = '<li><a href="' . URL_NEWS . '">News</a></li>';
         $topics = $post_obj->getTerms('topic');
         if (Arr::iterable($topics)) {
             $topic = reset($topics);
             $ancestor_links[] = sprintf('<li><a href="%s">%s</a></li>', $topic->getPermalink(), $topic->get('name'));
         }
     }
     // Don't display breadcrumbs unless there's at least one ancestor
     if (!Arr::iterable($ancestor_links)) {
         return null;
     }
     return sprintf('<ul class="bread-crumbs">
     %s
     <li>%s</li>
   </ul>', join('', $ancestor_links), $post_title);
 }
                echo $t->slug;
                ?>
</li>
            <?php 
            }
            ?>
          </ul>
        <?php 
        }
        ?>

        <?php 
        $terms = $r->getTerms('resource-topic');
        ?>
        <?php 
        if (Arr::iterable($terms)) {
            ?>
          <strong>Resource Topic</strong><br>
          <ul>
            <?php 
            foreach ($terms as $t) {
                ?>
              <li><?php 
                echo $t->slug;
                ?>
</li>
            <?php 
            }
            ?>
          </ul>
        <?php