Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    8
    Member #
    31337
    I'm sure that title is very vague, i'll explain more here. I'm working on an email newsletter in php, and i'm writing a script to go get the information from the database used by drupal and automatically put it in the areas I need it. I have the title and teasers of the news items, but I don't know how to generate the links for the titles. These will be used in an "In this issue" section of the newsletter, like so(Used on site, will be emailing newsletter):

    In This Issue currently on the site

    Views does it automatically with the "Link this field to its node", I think. It would be nice to get the link for each article/page with as few lines of code as possible. How does views generate that link? I have a backup plan that might work, will have to test it, but i'd rather not use it. I've attached an image of the view and the export code code is below, not sure if it will help or not. Let me know if more information is needed.

    PHP Code:
    $view = new view;
    $view->name 'SectionsInNewsletterTEST';
    $view->description 'Lists sections in this month\'s newsletter as a block on left sidebar';
    $view->tag 'list';
    $view->base_table 'node';
    $view->core 6;
    $view->api_version '2';
    $view->disabled FALSE/* Edit this to true to make a default view disabled initially */
    $handler $view->new_display('default''Defaults''default');
    $handler->override_option('fields', array(
      
    'title' => array(
        
    'label' => '',
        
    'alter' => array(
          
    'alter_text' => 0,
          
    'text' => '<li class="leaf">[title]</li>',
          
    'make_link' => 0,
          
    'path' => '',
          
    'link_class' => '',
          
    'alt' => '',
          
    'prefix' => '',
          
    'suffix' => '',
          
    'target' => '',
          
    'help' => '',
          
    'trim' => 0,
          
    'max_length' => '',
          
    'word_boundary' => 1,
          
    'ellipsis' => 1,
          
    'strip_tags' => 0,
          
    'html' => 0,
        ),
        
    'empty' => '',
        
    'hide_empty' => 0,
        
    'empty_zero' => 0,
        
    'link_to_node' => 1,
        
    'exclude' => 0,
        
    'id' => 'title',
        
    'table' => 'node',
        
    'field' => 'title',
        
    'relationship' => 'none',
      ),
    ));
    $handler->override_option('sorts', array(
      
    'title' => array(
        
    'order' => 'ASC',
        
    'id' => 'title',
        
    'table' => 'node',
        
    'field' => 'title',
        
    'override' => array(
          
    'button' => 'Override',
        ),
        
    'relationship' => 'none',
      ),
    ));
    $handler->override_option('arguments', array(
      
    'tid' => array(
        
    'default_action' => 'default',
        
    'style_plugin' => 'default_summary',
        
    'style_options' => array(),
        
    'wildcard' => 'all',
        
    'wildcard_substitution' => 'All',
        
    'title' => '',
        
    'breadcrumb' => '',
        
    'default_argument_type' => 'php',
        
    'default_argument' => '',
        
    'validate_type' => 'taxonomy_term',
        
    'validate_fail' => 'not found',
        
    'break_phrase' => 0,
        
    'add_table' => 0,
        
    'require_value' => 0,
        
    'reduce_duplicates' => 0,
        
    'set_breadcrumb' => 0,
        
    'id' => 'tid',
        
    'table' => 'term_node',
        
    'field' => 'tid',
        
    'validate_user_argument_type' => 'uid',
        
    'validate_user_roles' => array(
          
    => 0,
          
    => 0,
        ),
        
    'relationship' => 'none',
        
    'default_options_div_prefix' => '',
        
    'default_argument_user' => 0,
        
    'default_argument_fixed' => '',
        
    'default_argument_image_size' => '_original',
        
    'default_argument_php' => 'if (arg(2) != \'\') {
      return arg(2);
    }'
    ,
        
    'validate_argument_node_type' => array(
          
    'image' => 0,
          
    'panel' => 0,
          
    'newsletter' => 0,
          
    'page' => 0,
          
    'story' => 0,
          
    'video' => 0,
        ),
        
    'validate_argument_node_access' => 0,
        
    'validate_argument_nid_type' => 'nid',
        
    'validate_argument_vocabulary' => array(
          
    => 1,
          
    => 0,
          
    => 0,
          
    => 0,
        ),
        
    'validate_argument_type' => 'tid',
        
    'validate_argument_transform' => 0,
        
    'validate_user_restrict_roles' => 0,
        
    'image_size' => array(
          
    '_original' => '_original',
          
    'thumbnail' => 'thumbnail',
          
    'preview' => 'preview',
        ),
        
    'validate_argument_php' => '',
        
    'override' => array(
          
    'button' => 'Override',
        ),
      ),
    ));
    $handler->override_option('filters', array(
      
    'type' => array(
        
    'operator' => 'not in',
        
    'value' => array(
          
    'image' => 'image',
        ),
        
    'group' => '0',
        
    'exposed' => FALSE,
        
    'expose' => array(
          
    'operator' => FALSE,
          
    'label' => '',
        ),
        
    'id' => 'type',
        
    'table' => 'node',
        
    'field' => 'type',
        
    'relationship' => 'none',
      ),
      
    'tid' => array(
        
    'operator' => 'not',
        
    'value' => array(
          
    57 => '57',
          
    56 => '56',
        ),
        
    'group' => '0',
        
    'exposed' => FALSE,
        
    'expose' => array(
          
    'operator' => FALSE,
          
    'label' => '',
        ),
        
    'type' => 'select',
        
    'limit' => TRUE,
        
    'vid' => '3',
        
    'id' => 'tid',
        
    'table' => 'term_node',
        
    'field' => 'tid',
        
    'hierarchy' => 0,
        
    'override' => array(
          
    'button' => 'Override',
        ),
        
    'relationship' => 'none',
        
    'reduce_duplicates' => 0,
      ),
      
    'status_extra' => array(
        
    'operator' => '=',
        
    'value' => '',
        
    'group' => '0',
        
    'exposed' => FALSE,
        
    'expose' => array(
          
    'operator' => FALSE,
          
    'label' => '',
        ),
        
    'id' => 'status_extra',
        
    'table' => 'node',
        
    'field' => 'status_extra',
        
    'override' => array(
          
    'button' => 'Override',
        ),
        
    'relationship' => 'none',
      ),
    ));
    $handler->override_option('access', array(
      
    'type' => 'none',
    ));
    $handler->override_option('cache', array(
      
    'type' => 'none',
    ));
    $handler->override_option('title''In This Issue');
    $handler->override_option('header_format''2');
    $handler->override_option('header_empty'0);
    $handler->override_option('footer_format''2');
    $handler->override_option('footer_empty'0);
    $handler->override_option('items_per_page'0);
    $handler->override_option('style_plugin''list');
    $handler->override_option('style_options', array(
      
    'grouping' => '',
      
    'type' => 'ul',
    ));
    $handler $view->new_display('block''Block''block_1');
    $handler->override_option('block_description''');
    $handler->override_option('block_caching', -1); 
    Attached Images Attached Images

  2.  

  3. #2
    Junior Member
    Join Date
    Apr 2012
    Posts
    8
    Member #
    31337
    Lol. Nevermind, doing it another way. Thanks!

  4. #3
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    Quote Originally Posted by Shoguo, post: 233215
    Lol. Nevermind, doing it another way. Thanks!
    Since we were all stumped about how to do this, sharing your solution could be of help to others here.
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!

  5. #4
    Junior Member
    Join Date
    Apr 2012
    Posts
    8
    Member #
    31337
    It's not really a general solution, just a solution specific to my needs because of the way we have things setup here. I just wrote some php code to get the title from the node table then generated the link based on how the website taxonomy was setup.

  6. #5
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    Thanks - that could be of help - sometimes custom solutions are necessary, but having a hint as to how to go about it can be a good starting point.
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!

  7. #6
    Junior Member
    Join Date
    Apr 2012
    Posts
    8
    Member #
    31337
    Here's what I have so far to generate the newsletter. The part concerning this topic in particular I put in a giant commented block. Right now things are hard coded in, but the final version will have things retrieved from the database. Basically, I get the title from the database, format it so that it matches the url alias format of the site, and parse the month/year and put it all in a format that the link on the site is. Since the site will not be changing that will remain hard coded. "www.somesite.com/" and the 'newsletter' part of this will be retrieved from the vocab table in the drupal database.
    PHP Code:
    <?php
    $newsletter 
    'April 2012';
    $template "Email_Newsletter.html";
    $monthnumber = array("January" => "01""February" => "02""March" => "03""April" => "04""May" => "05""June" => "06""July" => "07""August" => "08""September" => "09""October" => "10""November" => "11""December" => "12");

    //Get the contents of the template file to start replacing
    $output file_get_contents($template);

    //Connect to the needed server or give an error
    $db mysql_connect("server""user""password") or die ("Error connecting to MySQL");
    //Select the database which contains the newsletter information
    mysql_select_db("drupaldev");

    // get data from the appropriate tables; title and teaser sections stored in node_revisions
    $result mysql_query("SELECT node_revisions.title, node_revisions.teaser FROM node_revisions
                          JOIN node ON node_revisions.nid = node.nid
                          JOIN term_node ON node.nid = term_node.nid
                          JOIN term_data ON term_node.tid = term_data.tid
                          WHERE term_data.name = 'April 2012' AND node.title != 'April Header'
                          ORDER BY node.created desc"
    );

    //Replace the filler "Month Year" in the template with the month and year of the newsletter
    if ($newsletter != NULL) {
      
    $output str_replace('Month Year',$newsletter,$output);
    }

    //Column to keep track of which item goes in the left or right column of the newsletter
    $column 1;
    while(
    $info mysql_fetch_array($result)) {
      
    //Variables which hold the corresponding placeholder in the template file to be replaced
      
    $left "<!-- L" $column " -->";
      
    $right "<!-- R" $column " -->";
      
    $issuenews "<!-- News Item " $column " -->";

      
    //Seperator used to seperate the news items from each other
      
    $seperator '"http://www.ibreastfeeding.com/sites/default/files/images/separator.jpg"';

      
    //**************************************************************************************
      //*************** CODE TO GENERATE LINKS TO ARTICLES PAGE ***************
      //**************************************************************************************
      
    $new_title strtolower(preg_replace('/ /','-',$info['title']));
      
    $month_year explode(" ",$newsletter);
      
    $year $month_year[1];
      
    $month $month_year[0];
      
    $newslink 'http://www.ibreastfeeding.com/newsletter/' $year '/' $monthnumber[$month] . '/' .       $new_title;
      
    //Contains the link for specific news content in the "In this Issue" section
      
    $thisissue "<li><a href=\"" $newslink "\">" $info['title'] . "</a>";
      
    //*************************************************************************************
      //**************** END OF CODE TO GENERATE LINKS ***************************
      //*************************************************************************************

      
    $output str_replace($issuenews,$thisissue,$output);
      
    //Contains and formats the title and teaser of the newsitems
      
    $newsitem '<tr mc:repeatable>'
                    
    '<td valign="top">'
                        
    '<div mc:edit="tiwc200_content03">'
                            
    '<h4 class="h4">' $info['title'] . '</h4>'
                            
    $info['teaser']
                        . 
    '</div>'
                        
    '<div>'
                        
    '<a href="' $newslink '">Read More</a>'
                        
    '</div>'
                    
    '</td>'
                
    '</tr>'
                
    '<tr>'
                    
    '<td align="center">'
                        
    '<img src=' $seperator 'class="separator-img" alt="separator">'
                      
    '</td>'
                
    '</tr>';

      
    //If column is an odd number, put the title and teaser in the left using the corresponding placeholder
      
    if($odd $column%2)
      {
        
    $output str_replace($left,$newsitem,$output);
      }
      else {
        
    $output str_replace($right,$newsitem,$output);
      }
      
    $column++;
    }

    mysql_close($db);
    echo 
    $output;
    ?>

  8. #7
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    Thanks - I knew you can embed images from a server in an e-mail, but was not aware that you could access a database that way. Very interesting.
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!

  9. #8
    Junior Member
    Join Date
    Apr 2012
    Posts
    8
    Member #
    31337
    Quote Originally Posted by AlphaMare, post: 233260
    Thanks - I knew you can embed images from a server in an e-mail, but was not aware that you could access a database that way. Very interesting.
    Funny that you bring that up, I have a header file that's an image. I thought I would be able to just generate the link and change the name of the file depending on the month of the article. It's always stored in the same place, but the name is not saved the same each time i.e. i'll have March2012Header.png for one month and January 2012 header.png for another. So i'm gonna have to do some magic with regular expressions or get with the graphic designer and say "hey, name them all in the same format, please."

  10. #9
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    In asp they now have an smtp function that allows you to send any page you desire as an HTML email...

    Depending on how you code the page... ( you need to embed all your JavaScript and CSS in the actual page ) not call them externally, and load whatever info from a DB into the page... Like any othe CMS system.

    Is best to only use some basic JavaScript(if any) and CSS, as not all mail clients can actually recognize JavaScript or advanced CSS components.

    So you do your layout, put your content into the DB, call the mail function, it calls the page, the page loads the data from the DB, and The page is sent as an HTML email, but Iif the users email is not setup to display HTML email, it will strip out all the HTML tags and just display the content as text.

  11. #10
    Junior Member
    Join Date
    Apr 2012
    Posts
    8
    Member #
    31337
    Quote Originally Posted by Webzarus, post: 233262
    In asp they now have an smtp function that allows you to send any page you desire as an HTML email...

    Depending on how you code the page... ( you need to embed all your JavaScript and CSS in the actual page ) not call them externally, and load whatever info from a DB into the page... Like any othe CMS system.

    Is best to only use some basic JavaScript(if any) and CSS, as not all mail clients can actually recognize JavaScript or advanced CSS components.

    So you do your layout, put your content into the DB, call the mail function, it calls the page, the page loads the data from the DB, and The page is sent as an HTML email, but Iif the users email is not setup to display HTML email, it will strip out all the HTML tags and just display the content as text.
    I don't have a lot of experience with or know much about asp. Is there a free compiler/IDE/etc to run and write code in(For Mac)? As I recall ASP is more for windows. Would I be able to take the html page generated and send it using a mailer?(We use Gammadyne Mailer). As for the actual html part, i've got a simple template made up, and i've noticed it displays drastically different in each of the different email clients. Not sure how to go about making it show as close as possible in each client(At least the main ones?Don't want a huge focus or i'll never finish). Some relevant links would be wonderful. Thanks.


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 01:53 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com