/**
    * Makes an HTML element specified by the DOM ID +field_id+ become an in-place
    * editor of a property.
    *
    * A form is automatically created and displayed when the user clicks the element,
    * something like this:
    * <form id="myElement-in-place-edit-form" target="specified url">
    *   <input name="value" text="The content of myElement"/>
    *   <input type="submit" value="ok"/>
    *   <a onclick="javascript to cancel the editing">cancel</a>
    * </form>
    * 
    * The form is serialized and sent to the server using an AJAX call, the action on
    * the server should process the value and return the updated value in the body of
    * the reponse. The element will automatically be updated with the changed value
    * (as returned from the server).
    * 
    * Required +options+ are:
    * <tt>url</tt>::       Specifies the url where the updated value should
    *                       be sent after the user presses "ok".
    * 
    * Addtional +options+ are:
    * <tt>rows</tt>::              Number of rows (more than 1 will use a TEXTAREA)
    * <tt>cancel_text</tt>::       The text on the cancel link. (default: "cancel")
    * <tt>save_text</tt>::         The text on the save link. (default: "ok")
    * <tt>external_control</tt>::  The id of an external control used to enter edit mode.
    * <tt>options</tt>::           Pass through options to the AJAX call (see prototype's Ajax.Updater)
    * <tt>with</tt>::              JavaScript snippet that should return what is to be sent
    *                               in the AJAX call, +form+ is an implicit parameter
    * @deprecated 
    */
    function in_place_editor($field_id, $options = array())
    {
        $function =  "new Ajax.InPlaceEditor(";
        $function .= "'{$field_id}', ";
        $function .= "'".UrlHelper::url_for($options['url'])."'";

        $js_options = array();
        if (!empty($options['cancel_text'])){
            $js_options['cancelText'] = AK::t("{$options['cancel_text']}");
        }
        if (!empty($options['save_text'])){
            $js_options['okText'] = AK::t("{$options['save_text']}");
        }
        if (!empty($options['rows'])){
            $js_options['rows'] = $options['rows'];
        }
        if (!empty($options['external_control'])){
            $js_options['externalControl'] = $options['external_control'] ;
        }
        if (!empty($options['options'])){
            $js_options['ajaxOptions'] = $options['options'];
        }
        if (!empty($options['with'])){
            $js_options['callback'] = "function(form) { return {$options['with']} }" ;
        }
        if (!empty($js_options)) {
            $function .= (', ' . JavaScriptHelper::_options_for_javascript($js_options));
        }
        $function .= ')';

        return JavaScriptHelper::javascript_tag($function);
    }
Example #2
0
function autoThumbnail($context, $article, $params = null)
{
    JHtml::_('behavior.modal');
    $minimal = 30;
    $es = AKEasyset::getInstance();
    $es->getFunction('dom.simple_html_dom');
    $html = str_get_html($article->text);
    $imgs = $html->find('img');
    foreach ($imgs as $img) {
        $classes = explode(' ', $img->class);
        $imgUrl = AK::_('uri.pathAddHost', $img->src);
        if (in_array('nothumb', $classes)) {
            continue;
        }
        // Has class nothumb, skip to next.
        if ($img->parent->tag == 'a') {
            continue;
        }
        // If is anchor already, skip to next.
        if (!$img->width && !$img->height) {
            continue;
        }
        // If img tag has no width and height attrs, skip.
        if (!strpos('-' . $imgUrl, JURI::root()) && $es->params->get('onlyLocalhostThumb', 1)) {
            continue;
        }
        // If not localhost image, skip.
        // get img path and size
        $imgPath = JPath::clean(str_replace(JURI::root(), JPATH_ROOT . DS, $imgUrl));
        $size = getimagesize($imgPath);
        // manul size
        $imgW = $img->width;
        $imgH = $img->height;
        // original size
        $oriW = $size[0];
        $oriH = $size[1];
        if ($oriW <= $minimal || $oriH <= $minimal) {
            continue;
        }
        // if too small, skip.
        if ($oriW <= $imgW || $oriW <= $imgW) {
            continue;
        }
        // If large ten origin, skip.
        $img->src = AK::_('thumb.resize', $imgUrl, $imgW, $imgH, 0);
        // get thumb url
        $imgtext = $img->outertext;
        $imgtext = <<<ANCHOR
\t\t<a class="modal" href="{$imgUrl}">{$imgtext}</a>
ANCHOR;
        $img->outertext = $imgtext;
        $classes = null;
    }
    $article->text = $html->save();
}
Example #3
0
function addFbLikeButton($context, $article)
{
    $context;
    $context = explode('.', $context);
    if ($context[0] != 'com_content') {
        return;
    }
    // set Route
    $uri = AK::_('jcontent.getArticleLink', "{$article->id}:{$article->alias}", $article->catid, 1);
    // set like
    $es = AKEasyset::getInstance();
    $position = $es->params->get('fbLikePosition', 1);
    $like = <<<LIKE
\t<div class="asikart-fb-like">
\t\t<div id="fb-root"></div>
\t\t<script>(function(d, s, id) {
\t\t  var js, fjs = d.getElementsByTagName(s)[0];
\t\t  if (d.getElementById(id)) {return;}
\t\t  js = d.createElement(s); js.id = id;
\t\t  js.src = "//connect.facebook.net/zh_TW/all.js#xfbml=1";
\t\t  fjs.parentNode.insertBefore(js, fjs);
\t\t}(document, 'script', 'facebook-jssdk'));</script>
\t\t
\t\t<fb:like href="{$uri}" send="false" show_faces="false"></fb:like>
\t</div>
LIKE;
    $get = JRequest::get();
    if (JRequest::getVar('view') == 'featured' || JRequest::getVar('layout') == 'blog') {
        if ($es->params->get('fbLikeOnBlog', 0)) {
            $article->introtext = $like . $article->introtext;
        }
    } elseif ($get['view'] == 'article') {
        switch ($position) {
            // After Title
            case 1:
                $article->text = $like . $article->text;
                break;
                // After Content
            // After Content
            case 2:
                $article->text = $article->text . $like;
                break;
                // Both
            // Both
            case 3:
                $article->text = $like . $article->text . $like;
                break;
        }
    }
}
Example #4
0
function setOpenGraph($context, $article, $es)
{
    $view = JRequest::getVar('view');
    if (empty($article->id)) {
        return;
    }
    if ('article' == $view) {
        $images = new JRegistry($article->images);
        $img = $images->get('image_fulltext', $images->get('image_intro'));
        if (!$img) {
            $es = AKEasyset::getInstance();
            $es->getFunction('dom.simple_html_dom');
            // If first image = main image, delete this paragraph.
            $html = str_get_html($article->text);
            $imgs = $html->find('img');
            if (!empty($imgs[0])) {
                $img = $imgs[0]->src;
            }
        }
        $cat = JTable::getInstance('category');
        $cat->load($article->catid);
        $cat->params = new JRegistry($cat->params);
        $catimg = $cat->params->get('image');
        if (isset($img)) {
            $es->ogImage = $img;
        } elseif ($catimg) {
            $es->ogImage = AK::_('uri.pathAddHost', $catimg);
        } else {
            if (!$es->params->get('ogDefaultImageOnlyFrontPage', 1)) {
                $es->ogImage = AK::_('uri.pathAddHost', $es->params->get('ogDefaultImage'));
            }
        }
    } elseif ('category' == $view) {
        static $once = 1;
        if ($once) {
            $cat = JTable::getInstance('category');
            $cat->load(JRequest::getVar('id'));
            $cat->params = new JRegistry($cat->params);
            $img = $cat->params->get('image');
            if ($img) {
                $es->ogImage = $img;
            } elseif (!$es->params->get('ogDefaultImageOnlyFrontPage', 1)) {
                $es->ogImage = $es->params->get('ogDefaultImage');
            }
            $es->ogImage = AK::_('uri.pathAddHost', $es->ogImage);
        }
        $once = 0;
    }
}
Example #5
0
 function _deleteTestingModelDatabases()
 {
     $db =& AK::db();
     foreach ($this->_testing_model_databases_to_delete as $table_name){
         $db->Execute('DROP TABLE '.$table_name);
         $db->DropSequence('seq_'.$table_name);
     }
 }
Example #6
0
function blogViewClearly($context, $article, $params = null)
{
    if (JRequest::getVar('layout') != 'blog' && JRequest::getVar('view') != 'featured') {
        return;
    }
    $es = AKEasyset::getInstance();
    $imgW = $es->params->get('blogViewImgWidth', 150);
    $maxChar = $es->params->get('blogViewMaxChar', 250);
    $crop = $es->params->get('blogViewImgCrop', 1);
    $allowTags = $es->params->get('blogViewTagsAllow');
    $doc = JFactory::getDocument();
    $text = $article->introtext;
    $mainImg = null;
    if ($doc->getType() != 'html') {
        return;
    }
    // Clean Tags
    if ($es->params->get('blogViewCleanTags', 1)) {
        $es->getFunction('dom.simple_html_dom');
        // If first image = main image, delete this paragraph.
        $html = str_get_html($text);
        $imgs = $html->find('img');
        if ($imgs) {
            $mainImg = $imgs[0]->src;
            $p = $imgs[0]->parent();
            // is img in p tag?
            if ($p->tag != 'p') {
                $p = $p->parent();
            }
            // if image has anchor, get parent.
            $imgtext = $p->children[0]->outertext;
            $p->innertext = str_replace($imgtext, '', $p->innertext);
            if (!trim($p->innertext)) {
                $p->outertext = '';
            }
            $text = $html->save();
            $text = strip_tags($text, $allowTags);
            if (!$allowTags) {
                $text = JString::substr($text, 0, $maxChar);
            }
        }
    }
    // Handle Image
    if ($crop) {
        $imageUrl = AK::_('thumb.resize', $mainImg, $imgW, $imgW, $crop);
    } else {
        $imageUrl = AK::_('thumb.resize', $mainImg, $imgW, 999, 0);
    }
    // Article Link
    $link = AK::_('jcontent.getArticleLink', $article->id, $article->catid, 0);
    // Set layout
    $layout = <<<LAYOUT
\t\t<div class="ak_blog_layout">
\t\t\t<div class="ak_blog_img_wrap fltlft float-left">
\t\t\t\t<a class="ak_blog_img_link" href="{$link}">
\t\t\t\t\t<img class="ak_blog_img" src="{$imageUrl}" alt="{$article->title}" width="{$imgW}px" />
\t\t\t\t</a>
\t\t\t</div>
\t\t\t<div class="ak_blog_intro">
\t\t\t\t{$text}
\t\t\t</div>
\t\t\t<div class="clr clearfix"></div>
\t\t</div>
LAYOUT;
    $article->introtext = $layout;
}
Example #7
0
    $url = $xml->addChild('url');
    $url->addChild('loc', $link);
    $url->addChild('lastmod', $modified);
    $url->addChild('changefreq', 'weekly');
    $url->addChild('priority', '0.7');
    $exists_links[] = $link;
}
// build content map
$where = AK::_('query.publishingItems', '', 'state');
$q = $db->getQuery(true);
$q->select("*")->from("#__content")->where($where)->order('id DESC');
$db->setQuery($q);
$contents = $db->loadObjectList();
foreach ($contents as $content) {
    // get category link
    $link = AK::_('jcontent.getArticleLink', $content->id, $content->catid, true);
    if (in_array($link, $exists_links)) {
        continue;
    }
    // set some data
    $modified = $content->modified != '0000-00-00 00:00:00' ? $content->modified : $content->created;
    $modified = JFactory::getDate($modified, JFactory::getConfig()->get('offset'));
    $modified = $modified->format('Y-m-d');
    // set xml data
    $url = $xml->addChild('url');
    $url->addChild('loc', $link);
    $url->addChild('lastmod', $modified);
    $url->addChild('changefreq', 'weekly');
    $url->addChild('priority', '0.6');
    $exists_links[] = $link;
}
Example #8
0
 /**
  * Map API Response Filter Fields
  *
  * @param $filter_fields    array   Filter fields array.
  * @param $name             string  Class name.
  *
  * @return array Merged filter fields.
  */
 public static function mergeAPIFilterFields($filter_fields, $name)
 {
     $map = (array) AK::_('system.getConfig', 'keyMap.' . $name);
     $map = array_keys($map);
     $filter_fields = array_merge($filter_fields, $map);
     return $filter_fields;
 }
Example #9
0
function setDocument($easyset)
{
    if ($easyset->app->isAdmin()) {
        return;
    }
    $doc = JFactory::getDocument();
    if ($doc->getType() != 'html') {
        return;
    }
    $config = JFactory::getConfig();
    $siteName = $config->get('sitename');
    if ($easyset->params->get('getMeta')) {
        if (AKHelper::isHome()) {
            $doc->setDescription($config->get('MetaDesc'));
        } else {
            $doc->setDescription($easyset->_metaDesc);
        }
    }
    // SEO Title
    $easyset->getFunction('seo.setTitle');
    if ($easyset->params->get('titleFix') && $easyset->_siteTitle) {
        $doc->setTitle($easyset->_siteTitle);
    }
    //set Generator
    if ($easyset->params->get('generator')) {
        $doc->setGenerator($easyset->params->get('generator'));
    }
    // set Open Graph
    if ($easyset->params->get('openGraph', 1)) {
        $meta = array();
        // og:image
        if (AK::isHome()) {
            if ($easyset->params->get('ogDefaultImage')) {
                $meta[] = '<meta property="og:image" content="' . AK::_('uri.pathAddHost', $easyset->params->get('ogDefaultImage')) . '"/>';
            }
        } elseif ($easyset->ogImage) {
            $meta[] = '<meta property="og:image" content="' . $easyset->ogImage . '"/>';
        }
        // others
        $url = $doc->getBase() ? $doc->getBase() : AK::_('uri.current', true);
        $admin_id = $easyset->params->get('ogAdminId');
        $page_id = $easyset->params->get('ogPageId');
        $app_id = $easyset->params->get('ogAppId');
        $meta[] = '<meta property="og:title" content="' . $doc->getTitle() . '"/>';
        $meta[] = '<meta property="og:site_name" content="' . $siteName . '"/>';
        $meta[] = '<meta property="og:description" content="' . $easyset->_metaDesc . '"/>';
        $meta[] = '<meta property="og:url" content="' . $url . '"/>';
        // admin, page, user ids
        if ($admin_id) {
            $meta[] = '<meta property="fb:admins" content="' . $admin_id . '"/>';
        }
        if ($page_id) {
            $meta[] = '<meta property="fb:page_id" content="' . $page_id . '"/>';
        }
        if ($app_id) {
            $meta[] = '<meta property="fb:app_id" content="' . $app_id . '"/>';
        }
        foreach ($meta as $v) {
            $doc->addCustomTag($v);
        }
    }
}
Example #10
0
 function _deleteTestingModelDatabases()
 {
     $db =& AK::db();
     foreach ($this->_testing_model_databases_to_delete as $table_name){
         $db->Execute('DROP TABLE '.$table_name);
         strstr($db->databaseType,'sqlite') ? $db->DropSequence('seq_'.$table_name) : null;
     }
 }