Zend link helper exists? - php

Some other frameworks have a link helper like output_link('anchor', 'destination'); to replace the need to type into the template. Does Zend have something similar? and do I have to declare the link in the action first before I can use it in the viewer?

Zend_View_Helper_Url can generate URL in view, take a look on its API doc
http://framework.zend.com/apidoc/core/Zend_View/Helper/Zend_View_Helper_Url.html

I am not sure if Zend has this, but all you would need to do is create your own outputLink in the View Helper (applications/views/helpers/) and set it up how you want to, should be pretty trivial.
class Zend_View_Helper_OutputLink extends Zend_View_Helper_Abstract
{
public function outputLink($anchor, $description)
{
return '' . $description . '';
}
}
Just modify it how you want to. And you would call it in your view like below:
<span><?php $this->outputLink('test.html', 'Test Me!'); ?> </span>

Here's my anchor element view helper for zend. You need to use my image element view helper or remove the part of the code that uses it in case you don't like it. Of course, you're free to modify name and whatever else you wish.
require_once 'Zend/View/Helper/HtmlElement.php';
class Ecoweb_View_Helper_AnchorElement extends Zend_View_Helper_HtmlElement {
/**
*
* #param string $url
* #param string $content
* #param array|string $attribs
* #return string
*/
public function anchorElement($url, $content = '', $attribs = null)
{
if (is_array($url)) {
$reset = isset($url[2]) ? $url[2] : false;
$encode = isset($url[3]) ? $url[3] : false;
$url = $this->view->url($url[0], $url[1], $reset, $encode);
} else {
$url = $this->view->baseUrl($url);
}
if (is_array($attribs)) {
$attribs = $this->_htmlAttribs($attribs);
} else {
$attribs = empty($attribs) ? '' : ' '.$attribs;
}
if (is_array($content) && isset($content['src'])) {
$src = $content['src'];
$alt = isset($content['alt']) ? $content['alt'] : null;
$imgAttribs = isset($content['attribs']) ? $content['attribs'] : array();
$content = $this->view->imgElement($src, $alt, $imgAttribs);
}
$content = empty($content) ? $url : $this->view->escape($content);
$xhtml = '<a '
. 'href="'.$url.'"'
. $attribs
. '>'
. $content
. '</a>';
return $xhtml;
}
}
Here's the image element view helper:
<?php
require_once 'Zend/View/Helper/HtmlElement.php';
class Ecoweb_View_Helper_ImgElement extends Zend_View_Helper_HtmlElement {
/**
*
* #param string $src
* #param string $alt
* #param array|string $attribs
* #return string
*/
public function imgElement($src, $alt = '', $attribs = null)
{
$src = $this->view->baseUrl($src);
if (is_array($attribs)) {
$attribs = $this->_htmlAttribs($attribs);
} else {
$attribs = empty($attribs) ? '' : ' '.$attribs;
}
$alt = $this->view->escape($alt);
$xhtml = '<img '
. 'src="'.$src.'" '
. 'alt="'.$alt.'"'
. $attribs
. $this->getClosingBracket();
return $xhtml;
}
}
Use cases:
echo $this->anchor('/mycontroller/myaction');
// output: /mycontroller/myaction
echo $this->anchor('/mycontroller/myaction', 'My anchor content', 'rel="nofollow"');
// output: My anchor content
echo $this->anchor('/mycontroller/myaction', 'My anchor content', 'rel="nofollow"');
// output: My anchor content
// when baseUrl is http://mydomain.com
echo $this->anchor(array(array('controller' => 'mycontroller', 'action' => 'myaction'), 'myroute'), 'My anchor content', array('rel' => 'nofollow'));
// output: My anchor content
echo $this->anchor('/mycontroller/myaction', array('src' => '/uploads/myimag.png'));
// output: <img src="/uploads/myimag.png" alt="">
// when you have an html doctype
echo $this->anchor('/mycontroller/myaction', array('src' => '/uploads/myimag.png', 'alt'=>'My alt text', array('width' => '100')));
// output: <img src="/uploads/myimag.png" alt="My alt text" width="100" />
// when you have an xhtml doctype

Well, Zend's url helper kind of thing kinda sucks. This is the only thing that pains me while developing apps in zend. In Codeigniter url helper used to come very handy. Zend has very limited resources in case of this. I had to port CI's url helper to use in my Zend Apps. And moreover, Symfony doesn't have that many helper methods like CI has and I'm not sure why.

No, you have to make one.

Related

Set CSS class on second level UL with Zend framework and bootstrap

The following code will set the class nav on the first level UL
$mainNav = public_nav_main();
$mainNav->setUlClass('nav')->setUlId('main-menu-left');
However im using bootstrap and so want the second level ul to have the class 'dropdown-menu'
I cant seem to find a reference to get this sorted.
Zend is being used as the base structure in the software im using, Omeka. Unfortunately Omeka doesnt have a way to do this natively so I am having to dive into the underlying Zend FW although I dont want to modify that too much as it might be changed.
You might just want to write a totally new View Helper based off Zend_View_Helper_Navigation_HelperAbstract.
Looking on GitHub for a bootstrap compatible helper based on that abstract I did encounter this: https://github.com/michaelmoussa/zf1-navigation-view-helper-bootstrap/blob/master/library/ZFBootstrap/View/Helper/Navigation/Menu.php which takes an interesting approach, post processing the markup generated from the out-of-the-box helpers.
I took a slightly different approach recently and just hacked the heck out of Zend_View_Helper_Navigation_Menu. Here is a unified diff summarizing those changes: http://pastebin.com/mrJG8QCt Better though to extend the class...
I didn't deal with sub-menus, however the issues I ran into were...
Way to add aria-role to <li> elements.
Avoid collision when rendering the menu twice - two representations - collapsed bootstrap style and traditional one for larger viewports. -Maybe ZF already offered something to work around this? Didn't jump out at me if there was.
This code shows the methods you need to tweak:
class MyMenu extends Zend_View_Helper_Navigation_Menu
{
/**
* Want a way to set aria role on menu li elements because its 2015 yo
*
* #var string
*/
protected $_liRole = '';
/**
* Workaround so I can render the damn thing twice on the same page and not collide IDs on the <a>'s
* Issue arose when adopting bootstrap and rendering both full page nav and collapsed nav bar
*
* #var string
*/
protected $_idAlias = '';
public function setLiRole($liRole)
{
if (is_string($liRole)) {
$this->_liRole = $liRole;
}
return $this;
}
public function getLiRole()
{
return $this->_liRole;
}
public function setIdAlias($alias)
{
$this->_idAlias = $alias;
return $this;
}
public function getIdAlias()
{
return $this->_idAlias;
}
public function renderMenu(Zend_Navigation_Container $container = null, array $options = array())
{
$this->setLiRole($options['liRole']);
$this->setIdAlias($options['idAlias']);
return parent::renderMenu($container, $options);
}
/**
* Returns an HTML string containing an 'a' element for the given page if
* the page's href is not empty, and a 'span' element if it is empty
*
* Overrides {#link Zend_View_Helper_Navigation_Abstract::htmlify()}.
*
* #param Zend_Navigation_Page $page page to generate HTML for
* #return string HTML string for the given page
*/
public function htmlify(Zend_Navigation_Page $page)
{
// get label and title for translating
$label = $page->getLabel();
$title = $page->getTitle();
// translate label and title?
if ($this->getUseTranslator() && $t = $this->getTranslator()) {
if (is_string($label) && !empty($label)) {
$label = $t->translate($label);
}
if (is_string($title) && !empty($title)) {
$title = $t->translate($title);
}
}
// get attribs for element
$attribs = array(
'id' => $this->getIdAlias() . $page->getId(),
'title' => $title,
'class' => $page->getClass()
);
// does page have a href?
if ($href = $page->getHref()) {
$element = 'a';
$attribs['href'] = $href;
$attribs['target'] = $page->getTarget();
} else {
$element = 'span';
}
return '<' . $element . $this->_htmlAttribs($attribs) . '><span class="span-nav-icon"></span><span>'
. str_replace(chr(32), ' ', $this->view->escape($label))
. '</span></' . $element . '>';
}
/**
* Normalizes given render options
*
* #param array $options [optional] options to normalize
* #return array normalized options
*/
protected function _normalizeOptions(array $options = array())
{
if (isset($options['indent'])) {
$options['indent'] = $this->_getWhitespace($options['indent']);
} else {
$options['indent'] = $this->getIndent();
}
if (isset($options['ulClass']) && $options['ulClass'] !== null) {
$options['ulClass'] = (string) $options['ulClass'];
} else {
$options['ulClass'] = $this->getUlClass();
}
if (isset($options['liRole']) && $options['liRole'] !== null) {
$options['liRole'] = (string) $options['liRole'];
} else {
$options['liRole'] = $this->getLiRole();
}
if (isset($options['idAlias']) && $options['idAlias'] !== null) {
$options['idAlias'] = (string) $options['idAlias'];
} else {
$options['idAlias'] = '';
}
if (array_key_exists('minDepth', $options)) {
if (null !== $options['minDepth']) {
$options['minDepth'] = (int) $options['minDepth'];
}
} else {
$options['minDepth'] = $this->getMinDepth();
}
if ($options['minDepth'] < 0 || $options['minDepth'] === null) {
$options['minDepth'] = 0;
}
if (array_key_exists('maxDepth', $options)) {
if (null !== $options['maxDepth']) {
$options['maxDepth'] = (int) $options['maxDepth'];
}
} else {
$options['maxDepth'] = $this->getMaxDepth();
}
if (!isset($options['onlyActiveBranch'])) {
$options['onlyActiveBranch'] = $this->getOnlyActiveBranch();
}
if (!isset($options['renderParents'])) {
$options['renderParents'] = $this->getRenderParents();
}
return $options;
}
/**
* Renders the deepest active menu within [$minDepth, $maxDeth], (called
* from {#link renderMenu()})
*
* #param Zend_Navigation_Container $container container to render
* #param array $active active page and depth
* #param string $ulClass CSS class for first UL
* #param string $indent initial indentation
* #param int|null $minDepth minimum depth
* #param int|null $maxDepth maximum depth
* #return string rendered menu
*/
protected function _renderDeepestMenu(Zend_Navigation_Container $container,
$ulClass,
$indent,
$minDepth,
$maxDepth)
{
if (!$active = $this->findActive($container, $minDepth - 1, $maxDepth)) {
return '';
}
// special case if active page is one below minDepth
if ($active['depth'] < $minDepth) {
if (!$active['page']->hasPages()) {
return '';
}
} else if (!$active['page']->hasPages()) {
// found pages has no children; render siblings
$active['page'] = $active['page']->getParent();
} else if (is_int($maxDepth) && $active['depth'] +1 > $maxDepth) {
// children are below max depth; render siblings
$active['page'] = $active['page']->getParent();
}
$ulClass = $ulClass ? ' class="' . $ulClass . '"' : '';
$html = $indent . '<ul' . $ulClass . '>' . self::EOL;
$liRole = (! empty($this->getLiRole())) ? "role=\"{$this->getLiRole()}\"" : "";
foreach ($active['page'] as $subPage) {
if (!$this->accept($subPage)) {
continue;
}
$liClass = $subPage->isActive(true) ? ' class="active"' : '';
$html .= $indent . ' <li' . $liClass . ' ' . $liRole . '>' . self::EOL;
$html .= $indent . ' ' . $this->htmlify($subPage) . self::EOL;
$html .= $indent . ' </li>' . self::EOL;
}
$html .= $indent . '</ul>';
return $html;
}
/**
* Renders a normal menu (called from {#link renderMenu()})
*
* #param Zend_Navigation_Container $container container to render
* #param string $ulClass CSS class for first UL
* #param string $indent initial indentation
* #param int|null $minDepth minimum depth
* #param int|null $maxDepth maximum depth
* #param bool $onlyActive render only active branch?
* #return string
*/
protected function _renderMenu(Zend_Navigation_Container $container,
$ulClass,
$indent,
$minDepth,
$maxDepth,
$onlyActive)
{
$html = '';
// find deepest active
if ($found = $this->findActive($container, $minDepth, $maxDepth)) {
$foundPage = $found['page'];
$foundDepth = $found['depth'];
} else {
$foundPage = null;
}
// create iterator
$iterator = new RecursiveIteratorIterator($container,
RecursiveIteratorIterator::SELF_FIRST);
if (is_int($maxDepth)) {
$iterator->setMaxDepth($maxDepth);
}
// iterate container
$prevDepth = -1;
foreach ($iterator as $page) {
$depth = $iterator->getDepth();
$isActive = $page->isActive(true);
if ($depth < $minDepth || !$this->accept($page)) {
// page is below minDepth or not accepted by acl/visibilty
continue;
} else if ($onlyActive && !$isActive) {
// page is not active itself, but might be in the active branch
$accept = false;
if ($foundPage) {
if ($foundPage->hasPage($page)) {
// accept if page is a direct child of the active page
$accept = true;
} else if ($foundPage->getParent()->hasPage($page)) {
// page is a sibling of the active page...
if (!$foundPage->hasPages() ||
is_int($maxDepth) && $foundDepth + 1 > $maxDepth) {
// accept if active page has no children, or the
// children are too deep to be rendered
$accept = true;
}
}
}
if (!$accept) {
continue;
}
}
$liRole = (! empty($this->getLiRole())) ? "role=\"{$this->getLiRole()}\"" : "";
// make sure indentation is correct
$depth -= $minDepth;
$myIndent = $indent . str_repeat(' ', $depth);
if ($depth > $prevDepth) {
// start new ul tag
if ($ulClass && $depth == 0) {
$ulClass = ' class="' . $ulClass . '"';
} else {
$ulClass = '';
}
$html .= $myIndent . '<ul' . $ulClass . '>' . self::EOL;
} else if ($prevDepth > $depth) {
// close li/ul tags until we're at current depth
for ($i = $prevDepth; $i > $depth; $i--) {
$ind = $indent . str_repeat(' ', $i);
$html .= $ind . ' </li>' . self::EOL;
$html .= $ind . '</ul>' . self::EOL;
}
// close previous li tag
$html .= $myIndent . ' </li>' . self::EOL;
} else {
// close previous li tag
$html .= $myIndent . ' </li>' . self::EOL;
}
// render li tag and page
$liClass = $isActive ? ' class="active"' : '';
$html .= $myIndent . ' <li' . $liClass . ' ' . $liRole . '>' . self::EOL
. $myIndent . ' ' . $this->htmlify($page) . self::EOL;
// store as previous depth for next iteration
$prevDepth = $depth;
}
if ($html) {
// done iterating container; close open ul/li tags
for ($i = $prevDepth+1; $i > 0; $i--) {
$myIndent = $indent . str_repeat(' ', $i-1);
$html .= $myIndent . ' </li>' . self::EOL
. $myIndent . '</ul>' . self::EOL;
}
$html = rtrim($html, self::EOL);
}
return $html;
}
}
Admittedly a lot of code. Might be good to diff the class you have now against this http://pastebin.com/qiD2ULsz - and then seeing what the touch points are, creating a new extending class. Really just the new properties and some "tweaks" to the string concatenation it does to render the markup.
I don't specifically address class on "second level ul's" but passing in an additional property would be trivial and follow the same changes I did make.
Hope this helps some. ZF 1.x shows its age a bit and these view helpers were never that great. The underlying Nav code isn't too bad, so again, maybe just start from scratch and write your own code to render a Zend Nav Container. Good luck.
This is admittedly an ugly hack, but you could do it by processing the output of public_nav_main() with a regular expression. So in the header.php file you would replace:
echo public_nav_main();
with
echo preg_replace( "/(?<!\/)ul(?!.*?nav)/", 'ul class="dropdown-menu"', public_nav_main() );
This will only work if you only have 2 levels in your menu, since the above regular expression will also add the class="dropdown-menu" to all ul elements below the top level ul.
Benefits
Simple
Achieves what you want to do
Doesn't require writing helpers or modifying the underlying framework
Should not break when the underlying framework is updated unless the update renders something other than a string from public_nav_main()
Downsides
Won't work if your menu has more than two levels
Will result in having two class attributes in your 2nd and lower level ul elements in the event that they already have a class attribute

Gravatar Image Still Not Loading Open Cart Admin

Hi I am trying to get my gravatar api working with my open cart admin/controller/common/header.php and my admin/view/template/common/header.tpl
Still not working gave it ago before that some one gave me advice on but now not working? So thought give it ago another way but nothing.
admin / controller/ header. php
This is just trimmed down version
<?php
class ControllerCommonHeader extends Controller {
protected function index($get_gravatar) {
}
function get_gravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array() ) {
$url = 'http://www.gravatar.com/avatar/';
$url .= md5( strtolower( trim( $email ) ) );
$url .= "?s=$s&d=$d&r=$r";
if ( $img ) {
$url = '<img src="' . $url . '"';
foreach ( $atts as $key => $val )
$url .= ' ' . $key . '="' . $val . '"';
$url .= ' />';
}
return $url;
}
admin / view / template / common / header.tpl
<?php
$email = $user_info['email']; // Not Working "Need it to pick up who ever logins"
$email = "your#rmail.com"; // Works
$default = "http://www.somewhere.com/homestar.jpg";
$size = 150;
?>
<li>
<a href="" class="text-center">
<img src="<?php echo $grav_url = "http://www.gravatar.com/avatar/" . md5( strtolower( trim( $email ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size;; ?>" alt="" />
</a>
</li>
Changes for getting gravatar image in header.tpl
Update system/library/user.php as below:
After: $this->username = $user_query->row['username'];
Add: $this->email = $user_query->row['email'];
Before: public function getUserName() {
Add:
public function getUserEmail() {
return $this->email;
}
Update admin/controller/common/header.php as below:
After: $this->data['logged'] = sprintf($this->language->get('text_logged'), $this->user->getUserName());
Add: $this->data['email'] = $this->user->getUserEmail();
Update admin/view/template/common/header.tpl as below:
<div class="img-circle">
<img src="http://www.gravatar.com/avatar/<?php echo md5(strtolower(trim($email))); ?>">
</div>
Please let me know the result of these changes.
Note: In opencart, you need to assign values to variables like: $this->data['variable_name'] in controller files and use them template files like: $variable_name.
Have you tried adding an extension to your url => www.gravatar.com/avatar/far512q3tgfqwe*.jpg* for example, a quick google search and i came up with this url, check it for further info:
http://en.gravatar.com/site/implement/images/
Try this piece of code in your header.php to get the email of the current logged in user:
$this->load->model('user/user');
$email_data = $this->model_user_user->getUser($this->user->getId());
$email = $email_data['email'];
if you want to get emails for all users it need to be handled differently.

Add class to this line... php/css

I have this line in php
<a title="'.htmlspecialchars($User->Name).'" href="'.$Href.'"'.$LinkClass.'>
I need to add another class which is known called tip
The code above generates something like this:
<a class="ProfileLink" href="/respond/profile/2/422" title="422">
As you can see $LinkClass gives me the class "ProfileLink" which is great
But I need to parse the class like "ProfileLink tip"
So just not sure how to amend $LinkClass above to something like $LinkClass tip
This is probably so basic I just cant see the wood for the trees
//
Edit: to add
Final html output needs to be :
<a class="ProfileLink tip" href="/respond/profile/2/422" title="422">
//
Added:
Entire php output for this function is:
if (!function_exists('UserPhoto')) {
function UserPhoto($User, $Options = array()) {
$User = (object)$User;
if (is_string($Options))
$Options = array('LinkClass' => $Options);
$LinkClass = GetValue('LinkClass', $Options, 'ProfileLink');
$ImgClass = GetValue('ImageClass', $Options, 'ProfilePhotoMedium');
$LinkClass = $LinkClass == '' ? '' : ' class="'.$LinkClass.'"';
$Photo = $User->Photo;
if (!$Photo && function_exists('UserPhotoDefaultUrl'))
$Photo = UserPhotoDefaultUrl($User);
if ($Photo) {
if (!preg_match('`^https?://`i', $Photo)) {
$PhotoUrl = Gdn_Upload::Url(ChangeBasename($Photo, 'n%s'));
} else {
$PhotoUrl = $Photo;
}
$Href = Url(UserUrl($User));
return '<a title="'.htmlspecialchars($User->Name).'" href="'.$Href.'"'.$LinkClass.'>'
.Img($PhotoUrl, array('alt' => htmlspecialchars($User->Name), 'class' => $ImgClass))
.'</a>';
} else {
return '';
}
}
}
How about using an array for the class attribute? Like this:
$LinkClass= array();
$LinkClassVal = GetValue('LinkClass', $Options, 'ProfileLink');
if($LinkClassVal){
$LinkClass[] = $LinkClassVal;
}
$LinkClass[] = "tip";
and then on return :
return '<a title="'.htmlspecialchars($User->Name).'" href="'.$Href.'"'.implode(" ",$LinkClass).'>'
.Img($PhotoUrl, array('alt' => htmlspecialchars($User->Name), 'class' => $ImgClass))
.'</a>';

Email Search and replace email templates(.html) Looping

I have a question regarding loops within an email template. My current email library gets passed an array of data and a template(.html) to search and replace. This works fine if I just need to replace any element wrapped in a square bracket [variable] . My library however can not deal with arrays of data(looping) and I need a more elegant solution than the ugly approach below
Cheers.
Email Library
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
require_once('phpmailer/phpmailer.php');
class Mailer{
protected static $mailer;
protected static $CI;
public function __construct()
{
self::$mailer = new PHPMailer();
self::$CI =& get_instance();
self::$CI->load->helper('file');
}
/**
*
* #param type $data
* #param type $template
* #return type
*/
public static function prepIt($data, $template)
{
$callback = function ($matches) use ($data){
return ( isset($data[$matches[1]]) )
? $data[$matches[1]]
: $matches[0];
};
return preg_replace_callback(
'/\[(.*?)\]/',
$callback,
read_file(EMAIL_TEMPLATES . $template));
}
/**
*
* #param type $data
* #param type $template
* #param type $to
* #param type $subject
* #param type $prep
* #return type
*/
public static function sendIt($data, $template='', $to, $subject, $prep=false)
{
self::$mailer->CharSet = 'utf-8';
if(self::$CI->config->item('email_smtp') === TRUE){
self::$mailer->SMTPSecure = "ssl";
self::$mailer->Host= self::$CI->config->item('email_host');
self::$mailer->Port= self::$CI->config->item('email_port');
self::$mailer->Username = self::$CI->config->item('email_user');
self::$mailer->Password = self::$CI->config->item('email_passw');
self::$mailer->SMTPKeepAlive = true;
self::$mailer->Mailer = "smtp";
self::$mailer->IsSMTP();
self::$mailer->SMTPAuth = true;
self::$mailer->SMTPDebug = 0;
}
if($prep)
{
self::$mailer->Body = self::prepIt($data, $template);
}
else
{
self::$mailer->Body = $data;
}
self::$mailer->IsHTML(true);
self::$mailer->Subject = $subject;
self::$mailer->AddAddress($to);
self::$mailer->FromName = self::$CI->config->item('email_from');
self::$mailer->From = self::$CI->config->item('email_primary');
try{
if(self::$mailer->Send()){
return true;
}else{
throw new phpmailerException(self::$mailer->ErrorInfo);
}
}catch(phpmailerException $e){
log_message('error', $e->getMessage());
}
}
return false;
}
Ugly Approach for non-defined templates
Note: sorry about poor formating here...
Instead of using a pre-made template, I have to pass a template on the fly so I can run a foreach loop with the data
if ($order->update_attributes($update_order)) {
$output ='<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type"content="text/html; charset=utf-8"/><title>Reciept</title><style type="text/css">#outlook a{padding:0;}
body{width:100%!important;}.ReadMsgBody{width:100%;}.ExternalClass{width:100%;}emails at full width*/body{-webkit-text-size-adjust:none;-ms-text-size-adjust:none;}
body{margin:0;padding:0;font:normal 14px tahoma,sans-serif;color:#515151;line-height:1.6em;}
img{height:auto;line-height:100%;outline:none;text-decoration:none;}
a img{border:none;}#backgroundTable{margin:0;padding:0;width:100%!important;}
p{margin-bottom:18px;line-height:1.6;color:#767676;}
h1,h2,h3,h4,h5,h6{color:black!important;line-height:100%!important;}
h1 a,h2 a,h3 a,h4 a,h5 a,h6 a{color:blue!important;}
h1 a:active,h2 a:active,h3 a:active,h4 a:active,h5 a:active,h6 a:active{color:red!important;}
h1 a:visited,h2 a:visited,h3 a:visited,h4 a:visited,h5 a:visited,h6 a:visited{color:purple!important;}
table td{border-collapse:collapse;}
table th{text-align:left;padding:25px;}.yshortcuts,.yshortcuts a,.yshortcuts a:link,.yshortcuts a:visited,.yshortcuts a:hover,.yshortcuts a span{color:black;text-decoration:none!important;border-bottom:none!important;background:none!important;}
table#product{border-spacing:0;width:100%;}
table#product th{padding:8px;}
table#product td{padding:8px;border-bottom:1px solid#b1b1b1;}</style></head><body><table width="100%" style="background:#e3e3e3;text-align:center;padding:10px;width:100%;"cellpadding="0"cellspacing="0"border="0"id="backgroundTable"><tr><td><table cellpadding="0"cellspacing="0"border="0"width="650"style="text-align:left;padding:8px;background:#ffffff;border:1px solid #b1b1b1;"><thead><tr><th style="text-align:left;font-size:30px;padding:0;">Philip Kavanagh</th><th style="text-align:right;"><img src="http://localhost/crack_ie/assets/front/img/logo.png"alt=""/></th></tr></thead><tbody><tr><td colspan="2"><h2>Reciept</h2><p>Thank you for your recent purchase(s)from the store.<br>The Order has been proccessed by paypal successfully!</p></td></tr><tr><td colspan="2"><h3>Purchase Information</h3><p>Below you will find links to your digital downloads</p></td></tr><tr><td colspan="2"><table class="product"id="product"><thead><tr><td> </td><td>Title</td><td>Price</td><td>Download</td></tr></thead><tbody>';
foreach ($email_data as $out) {
$output .= '
<tr><td><img src="'.site_url(MEDIA . 'products/' . $out['img']).'" alt=""/></td><td>'.$out['title'].'</td><td>€'.$out['price'].'</td><td>Download</td></tr>
';
}
$output .= '
</tbody></table></td></tr><tr><td style="width:70%;"> </td><td style="width:30%;text-align:right;"><table style="text-align:right;border-spacing:0;"><tbody><tr><td style="width:100%;padding:5px;">Order#</td><td style="margin-left:30px;"><strong>7782tgh5</strong></td></tr><tr><td style="width:100%;padding:5px;">Items</td><td style="margin-left:30px;">'.$email_additional['items'].'</td></tr><tr><td>Tax</td><td>€0.00</td></tr><tr style="background:#d53015;color:#fafafa;width:100%;"><td>Total Amount</td><td style="font-size: 30px; padding: 8px;">€'.$email_additional['total'].'</td></tr></tbody></table></td></tr></tbody></table></td></tr></table></body></html>
';
if (Mailer::sendIt($output, '', $user->email, 'Purchase Confirmation: #' . $order->order_sku . '', false)) {
return true;
}
Edit: Answer Thanks to landons,
if ($order->update_attributes($update_order)) {
$output = $this->load->view('orders/email', array(
'data' => $somedata
), true);
if (Mailer::sendIt($output, '', $user->email, 'Purchase Confirmation: #' . $order->order_sku . '', false)) {
return true;
}
}
Have you considered simply passing data to a view (and returning the content, rather than displaying it)?

CKEditor -> CodeIgniter

I am trying to configure CKEditor but I get the following in my source, it seems that the helper is not being sent any of the $data from my index function, My helper is located application/helpers
This is my code:
Helper:
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
/*
* CKEditor helper for CodeIgniter
*
* #author Samuel Sanchez <samuel.sanchez.work#gmail.com> - http://kromack.com/
* #package CodeIgniter
* #license http://creativecommons.org/licenses/by-nc-sa/3.0/us/
* #tutorial http://kromack.com/developpement-php/codeigniter/ckeditor-helper-for-codeigniter/
* #see http://codeigniter.com/forums/viewthread/127374/
* #version 2010-08-28
*
*/
/**
* This function adds once the CKEditor's config vars
* #author Samuel Sanchez
* #access private
* #param array $data (default: array())
* #return string
*/
function cke_initialize($data = array()) {
$return = '';
if(!defined('CI_CKEDITOR_HELPER_LOADED')) {
define('CI_CKEDITOR_HELPER_LOADED', TRUE);
$return = '<script type="text/javascript" src="'.base_url(). $data['path'] . '/ckeditor.js"></script>';
$return .= "<script type=\"text/javascript\">CKEDITOR_BASEPATH = '" . base_url() . $data['path'] . "/';</script>";
}
return $return;
}
/**
* This function create JavaScript instances of CKEditor
* #author Samuel Sanchez
* #access private
* #param array $data (default: array())
* #return string
*/
function cke_create_instance($data = array()) {
$return = "<script type=\"text/javascript\">
CKEDITOR.replace('" . $data['id'] . "', {";
//Adding config values
if(isset($data['config'])) {
foreach($data['config'] as $k=>$v) {
// Support for extra config parameters
if (is_array($v)) {
$return .= $k . " : [";
$return .= config_data($v);
$return .= "]";
}
else {
$return .= $k . " : '" . $v . "'";
}
if($k !== end(array_keys($data['config']))) {
$return .= ",";
}
}
}
$return .= '});</script>';
return $return;
}
/**
* This function displays an instance of CKEditor inside a view
* #author Samuel Sanchez
* #access public
* #param array $data (default: array())
* #return string
*/
function display_ckeditor($data = array())
{
// Initialization
$return = cke_initialize($data);
// Creating a Ckeditor instance
$return .= cke_create_instance($data);
// Adding styles values
if(isset($data['styles'])) {
$return .= "<script type=\"text/javascript\">CKEDITOR.addStylesSet( 'my_styles_" . $data['id'] . "', [";
foreach($data['styles'] as $k=>$v) {
$return .= "{ name : '" . $k . "', element : '" . $v['element'] . "', styles : { ";
if(isset($v['styles'])) {
foreach($v['styles'] as $k2=>$v2) {
$return .= "'" . $k2 . "' : '" . $v2 . "'";
if($k2 !== end(array_keys($v['styles']))) {
$return .= ",";
}
}
}
$return .= '} }';
if($k !== end(array_keys($data['styles']))) {
$return .= ',';
}
}
$return .= ']);';
$return .= "CKEDITOR.instances['" . $data['id'] . "'].config.stylesCombo_stylesSet = 'my_styles_" . $data['id'] . "';
</script>";
}
return $return;
}
/**
* config_data function.
* This function look for extra config data
*
* #author ronan
* #link http://kromack.com/developpement-php/codeigniter/ckeditor-helper-for-codeigniter/comment-page-5/#comment-545
* #access public
* #param array $data. (default: array())
* #return String
*/
function config_data($data = array())
{
$return = '';
foreach ($data as $key)
{
if (is_array($key)) {
$return .= "[";
foreach ($key as $string) {
$return .= "'" . $string . "'";
if ($string != end(array_values($key))) $return .= ",";
}
$return .= "]";
}
else {
$return .= "'".$key."'";
}
if ($key != end(array_values($data))) $return .= ",";
}
return $return;
}
**.htaccess:**
# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|css|js|images|files|scripts|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
Source
<script type="text/javascript" src="http://house.dev.local//ckeditor.js"></script><script type="text/javascript">CKEDITOR_BASEPATH = 'http://house.dev.local//';</script><script type="text/javascript">
View
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Editpage extends CI_Controller {
function __construct(){
parent::__construct();
}
function index($id){
if(!$this->session->userdata('logged_in'))redirect('admin/home');
$this->load->helper('ckeditor');
//Ckeditor's configuration
$this->data['ckeditor'] = array(
//ID of the textarea that will be replaced
'id' => 'content',
'path' => 'includes/js/ckedit',
//Optionnal values
'config' => array(
'toolbar' => "Full", //Using the Full toolbar
'width' => "550px", //Setting a custom width
'height' => '100px', //Setting a custom height
),
//Replacing styles from the "Styles tool"
'styles' => array(
//Creating a new style named "style 1"
'style 1' => array (
'name' => 'Blue Title',
'element' => 'h2',
'styles' => array(
'color' => 'Blue',
'font-weight' => 'bold'
)
),
//Creating a new style named "style 2"
'style 2' => array (
'name' => 'Red Title',
'element' => 'h2',
'styles' => array(
'color' => 'Red',
'font-weight' => 'bold',
'text-decoration' => 'underline'
)
)
)
);
if ($this->input->post('submit')){
#The User has submitted updates, lets begin!
#Set The validation Rules
$this->form_validation->set_rules('content', 'Content', 'trim|required|xss_clean');
#if the form_validation rules fail then load the login page with the errors. Otherwise continue validating the user/pass
if ($this->form_validation->run() == FALSE){
$data['cms_pages'] = $this->navigation_model->getCMSPages($id);
#connect to getCMSCotent and set the page info equal to the $data['page'] where the row is equal to the passed $id from the URL.
$data['page'] = $this->page_model->getCMSContent($id);
$data['content'] = $this->load->view('admin/editpage', $data, TRUE);
$this->load->view('admintemplate', $data);
}
#Form Validation passed, so lets continue updating.
#lets set some variables.
$content = $this->input->post('content', TRUE);
#Now if updatePage fails to update hte database then show "there was a problem", you could echo the db error itself
if($this->page_model->updatePage($id, $content)) {
$data['cms_pages'] = $this->navigation_model->getCMSPages($id);
#connect to getCMSContent and set the page info equal to the $data['page'] where the row is equal to the passed $id from the URL.
$data['page'] = $this->page_model->getCMSContent($id);
$data['success'] = TRUE;
$data['content'] = $this->load->view('admin/editpage', $data, TRUE);
$this->load->view('admintemplate', $data);
}//END if updatePage
}else{
$data['cms_pages'] = $this->navigation_model->getCMSPages($id);
#connect to getCMSCotent and set the page info equal to the $data['page'] where the row is equal to the passed $id from the URL.
$data['page'] = $this->page_model->getCMSContent($id);
$data['content'] = $this->load->view('admin/editpage', $data, TRUE);
$this->load->view('admintemplate', $data);
}//END if post submitted
} //END function index()
}
You do know that you can jst embed CK Editor with JS to a textarea, and not much around with all this.
http://ckeditor.com/demo
Hows you exactly how.. 3 second job.
One issue may be the double slash in your JS paths;
CKEDITOR_BASEPATH = 'http://house.dev.local//';
Also, is .htaccess blocking access to your CKEditor files ?
Where is your helper functions? what does it do ?
If that is the issue, please post it.
Also, your own helpers should NOT going in to 'system/helpers', they go in to your 'application/helpers', system helpers are for core helpers only.

Categories